:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-soft: #edf3ee;
  --text: #172019;
  --muted: #66736b;
  --line: #dce3dd;
  --primary: #1d714a;
  --primary-strong: #145c3b;
  --accent: #df5b4c;
  --danger: #bd3e35;
  --telegram-bg: var(--tg-theme-bg-color, var(--bg));
  --telegram-text: var(--tg-theme-text-color, var(--text));
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-width: 320px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--telegram-text);
  background: #e8ece8;
  letter-spacing: 0;
}
button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.app-shell {
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  color: var(--text);
  background: var(--telegram-bg);
  box-shadow: 0 0 40px rgba(31, 45, 35, .08);
}

.topbar {
  height: 76px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: relative;
  z-index: 50;
}
.topbar h1 { margin: 1px 0 0; font-size: 19px; line-height: 1.2; font-weight: 750; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 650; }

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  color: #3d4d43;
  background: var(--surface-soft);
}
.icon-button.subtle { background: transparent; }
.icon-button svg { width: 20px; height: 20px; stroke-width: 2; }
.icon-button:active, .nav-button:active { background: #e3ebe5; }

.main-content { height: calc(100dvh - 76px - 64px - var(--safe-bottom)); position: relative; }
.view { height: 100%; }
#list-view { padding: 0 16px 96px; overflow-y: auto; }

.date-toolbar {
  min-height: 78px;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 4px;
}
.date-summary { padding: 6px; border: 0; background: transparent; text-align: center; color: var(--text); }
.date-summary strong { display: block; font-size: 18px; line-height: 1.35; }
.date-summary span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.day-summary-row {
  min-height: 36px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.day-summary { min-width: 0; color: var(--muted); font-size: 13px; }
.copy-reviews-button {
  min-height: 32px;
  flex: 0 0 auto;
  padding: 0 9px;
  border: 1px solid #bfd0c4;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--primary);
  background: #f5f9f6;
  font-size: 12px;
  font-weight: 750;
}
.copy-reviews-button svg { width: 15px; height: 15px; }

.appointment-list { display: grid; gap: 10px; }
.appointment-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.card-main {
  min-height: 90px;
  padding: 14px 12px;
  display: grid;
  grid-template-columns: 48px 1fr 28px;
  align-items: center;
  gap: 10px;
}
.appointment-card.completed { background: #f6f9f6; }
.appointment-card.completed .contact-name { color: var(--muted); text-decoration: line-through; }
.appointment-time { color: var(--primary); font-size: 14px; font-weight: 800; }
.contact-name { margin: 0; font-size: 15px; font-weight: 750; }
.appointment-meta { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.appointment-address { display: block; }
.contact-chat-link {
  max-width: 100%;
  padding: 0;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #176d9b;
  background: transparent;
  text-align: left;
  font-weight: 750;
}
.contact-chat-link.contact-value { margin-top: 2px; font-size: 12px; font-weight: 650; }
.contact-chat-link svg { width: 14px; height: 14px; flex: 0 0 auto; }
.contact-chat-link:active { color: #0f5275; }
.review-preview {
  margin: 7px 0 0;
  overflow: hidden;
  display: -webkit-box;
  color: #4d5c53;
  font-size: 12px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.card-actions {
  min-height: 44px;
  padding: 6px 8px;
  border-top: 1px solid #e7ebe8;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.number-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 800;
}
.card-action-button, .edit-button {
  min-height: 32px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: #647168;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}
.card-action-button:active, .edit-button:active { background: #e9efea; }
.completion-button.completed {
  color: var(--primary);
  background: var(--surface-soft);
}
.review-button { color: #495d73; }
.edit-button {
  width: 32px;
  padding: 0;
}
.card-action-button svg, .edit-button svg { width: 16px; height: 16px; }

.empty-state { padding: 68px 24px 0; text-align: center; }
.empty-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--surface-soft);
}
.empty-icon svg { width: 25px; height: 25px; }
.empty-state h2 { margin: 0; font-size: 17px; }
.empty-state p { margin: 8px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }

.map-view { position: relative; overflow: hidden; }
.overview-map { position: absolute; inset: 0; z-index: 1; background: #dfe7df; }
.map-toolbar { position: absolute; z-index: 20; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; }
.map-date-button {
  height: 42px;
  min-width: 0;
  flex: 1;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  background: rgba(255,255,255,.96);
  box-shadow: 0 3px 12px rgba(35, 48, 39, .12);
  font-size: 13px;
  font-weight: 750;
}
.map-date-button svg { width: 18px; height: 18px; }
.map-control { flex: 0 0 42px; width: 42px; height: 42px; color: var(--primary); background: rgba(255,255,255,.96); box-shadow: 0 3px 12px rgba(35,48,39,.12); }
.map-empty {
  position: absolute;
  z-index: 15;
  left: 50%;
  top: 50%;
  min-width: 210px;
  padding: 16px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  background: rgba(255,255,255,.95);
  box-shadow: 0 6px 20px rgba(35,48,39,.13);
}
.map-empty strong, .map-empty span { display: block; }
.map-empty strong { font-size: 14px; }
.map-empty span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.marker-details {
  position: absolute;
  z-index: 20;
  left: 10px;
  right: 10px;
  bottom: 10px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255,255,255,.97);
  box-shadow: 0 8px 24px rgba(29, 42, 33, .18);
}
.detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-heading strong, .detail-heading span { display: block; }
.detail-heading strong { font-size: 15px; }
.detail-heading span { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.detail-heading time { flex: 0 0 auto; color: var(--primary); font-size: 14px; font-weight: 800; }
.detail-actions { display: flex; gap: 8px; margin-top: 12px; }

.marker-pin {
  width: 32px;
  height: 32px;
  border: 3px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(36, 44, 39, .32);
  font-size: 12px;
  font-weight: 800;
}
.marker-pin.completed { background: #77827b; }
.user-pin {
  width: 18px;
  height: 18px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: #2182f2;
  box-shadow: 0 0 0 8px rgba(33,130,242,.2);
}

.floating-button {
  position: absolute;
  z-index: 45;
  right: 18px;
  bottom: calc(76px + var(--safe-bottom));
  width: 54px;
  height: 54px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(29,113,74,.28);
}
.floating-button:active { background: var(--primary-strong); }
.floating-button svg { width: 24px; height: 24px; }
.map-view:not([hidden]) ~ .floating-button { display: none; }

.bottom-nav {
  height: calc(64px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.nav-button {
  border: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: #7a867f;
  background: transparent;
  font-size: 10px;
}
.nav-button svg { width: 20px; height: 20px; stroke-width: 2; }
.nav-button.active { color: var(--primary); font-weight: 750; }

.overlay {
  position: absolute;
  z-index: 100;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(17, 26, 20, .42);
}
.overlay[hidden], [hidden] { display: none !important; }
.form-sheet {
  width: 100%;
  height: min(94dvh, 820px);
  overflow: hidden;
  border-radius: 8px 8px 0 0;
  background: var(--bg);
  animation: sheet-up .2s ease-out;
}
.copy-reviews-sheet {
  width: 100%;
  max-height: min(82dvh, 680px);
  overflow: hidden;
  border-radius: 8px 8px 0 0;
  background: var(--bg);
  animation: sheet-up .2s ease-out;
}
.copy-reviews-content { padding: 16px; overflow-y: auto; }
.copy-date-range .field { border-bottom: 1px solid var(--line); }
.copy-date-range .field:first-child { border-radius: 8px 0 0 8px; }
.copy-date-range .field:last-child { border-left: 0; border-radius: 0 8px 8px 0; }
.copy-preview-heading {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.copy-preview-heading span { color: var(--muted); font-size: 12px; }
.copy-review-preview {
  min-height: 180px;
  max-height: 280px;
  margin: 0;
  padding: 13px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #344239;
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.copy-reviews-footer {
  min-height: 66px;
  padding: 11px 16px calc(11px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  background: var(--surface);
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: .5; } to { transform: translateY(0); opacity: 1; } }
.sheet-header {
  height: 58px;
  padding: 0 14px;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sheet-header h2 { margin: 0; text-align: center; font-size: 17px; }
.header-spacer { width: 40px; }
#appointment-form { height: calc(100% - 58px); position: relative; }
.form-scroll { height: calc(100% - 70px); padding: 16px 16px 24px; overflow-y: auto; }
fieldset { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
legend { margin-bottom: 9px; color: var(--muted); font-size: 12px; font-weight: 750; }
.field {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-bottom: 0;
  display: block;
  background: var(--surface);
}
.field:first-of-type { border-radius: 8px 8px 0 0; }
.field:last-child { border-bottom: 1px solid var(--line); border-radius: 0 0 8px 8px; }
.field:only-child { border: 1px solid var(--line); border-radius: 8px; }
.field-row { display: grid; grid-template-columns: 1.35fr 1fr; }
.field-row .field { border-radius: 0; border-bottom: 0; }
.field-row .field + .field { border-left: 0; }
.field > span, .field > label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.field input, .field textarea {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  resize: none;
}
.field input { height: 25px; }
.field input::placeholder, .field textarea::placeholder { color: #9aa49e; font-weight: 400; }
.address-control { display: flex; align-items: center; gap: 8px; }
.address-control input { min-width: 0; flex: 1; }
.locate-address-button {
  height: 32px;
  flex: 0 0 auto;
  padding: 0 10px;
  border: 1px solid #b8cfc0;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--primary);
  background: #f2f8f4;
  font-size: 12px;
  font-weight: 750;
}
.locate-address-button:disabled { cursor: wait; opacity: .65; }
.locate-address-button svg { width: 16px; height: 16px; }
.locate-address-button.loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.field-help { margin: -2px 0 9px; color: var(--muted); font-size: 12px; }
.picker-map { height: 225px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #dfe7df; }
.location-status { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.location-status.selected { color: var(--primary); font-weight: 650; }
.form-footer {
  height: 70px;
  padding: 11px 16px calc(11px + var(--safe-bottom));
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.primary-button, .secondary-button, .danger-button, .danger-filled-button {
  min-height: 43px;
  padding: 0 16px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 750;
}
.primary-button { border: 1px solid var(--primary); color: #fff; background: var(--primary); }
.primary-button:active { background: var(--primary-strong); }
.secondary-button { border: 1px solid var(--line); color: #415047; background: var(--surface); }
.danger-button { border: 1px solid #ecd0cc; color: var(--danger); background: #fff6f5; }
.danger-filled-button { border: 1px solid var(--danger); color: #fff; background: var(--danger); }
.primary-button.compact, .secondary-button.compact { min-height: 34px; padding: 0 12px; font-size: 12px; }
.primary-button svg, .secondary-button svg, .danger-button svg { width: 17px; height: 17px; }
.grow { flex: 1; }

.confirm-overlay { align-items: center; justify-content: center; padding: 24px; }
.confirm-dialog { width: min(100%, 330px); padding: 20px; border-radius: 8px; background: var(--surface); }
.confirm-dialog h2 { margin: 0; font-size: 18px; }
.confirm-dialog p { margin: 8px 0 20px; color: var(--muted); font-size: 13px; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast {
  position: absolute;
  z-index: 200;
  left: 50%;
  bottom: calc(82px + var(--safe-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  transform: translateX(-50%);
  border-radius: 8px;
  color: #fff;
  background: rgba(25, 32, 27, .92);
  font-size: 13px;
  white-space: nowrap;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.leaflet-control-attribution { font-size: 8px !important; }
.leaflet-control-zoom { border: 0 !important; box-shadow: 0 3px 12px rgba(35,48,39,.14) !important; }
.leaflet-control-zoom a { color: var(--text) !important; }

@media (max-height: 690px) {
  .form-sheet { height: 98dvh; }
  .picker-map { height: 180px; }
}

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app-shell { min-height: calc(100dvh - 36px); height: calc(100dvh - 36px); border: 1px solid #d5ddd6; border-radius: 8px; }
  .main-content { height: calc(100% - 76px - 64px); }
  .form-sheet { border-radius: 8px 8px 0 0; }
}
