:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --forest-950: #102d27;
  --forest-900: #173f35;
  --forest-700: #26715d;
  --forest-100: #e4f0eb;
  --cream: #f7f4ed;
  --ink: #17221f;
  --muted: #64716d;
  --white: #fff;
  --danger: #a64035;
  --shadow: 0 10px 30px rgb(16 45 39 / 18%);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body, .app-shell, #map { width: 100%; height: 100%; margin: 0; }

body { overflow: hidden; background: var(--cream); color: var(--ink); }

button, input { font: inherit; }
button { cursor: pointer; }

#map { z-index: 0; background: #d9e2d7; }

.topbar {
  position: fixed;
  z-index: 500;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand, .icon-button {
  pointer-events: auto;
  background: rgb(255 255 255 / 94%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px 8px 9px;
  border-radius: 15px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 11px;
  background: var(--forest-900);
  color: white;
  font-size: 25px;
}

.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { font-size: 14px; letter-spacing: -.01em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }

.icon-button, .round-button {
  display: grid;
  place-items: center;
  border: 0;
  color: var(--forest-900);
}

.icon-button { width: 46px; height: 46px; border-radius: 15px; font-size: 23px; }

.focus-toggle {
  position: fixed;
  z-index: 600;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 13px;
  border: 1px solid rgb(255 255 255 / 60%);
  border-radius: 14px;
  background: rgb(255 255 255 / 95%);
  color: var(--forest-950);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px);
  transition: opacity .2s ease, transform .2s ease;
}

.focus-toggle svg { width: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }

.topbar,
.search-card,
.map-actions,
.result-card,
.history-panel {
  transition: opacity .2s ease, transform .25s ease, visibility .2s ease;
}

.app-shell.map-focus .topbar,
.app-shell.map-focus .search-card,
.app-shell.map-focus .map-actions,
.app-shell.map-focus .result-card,
.app-shell.map-focus .history-panel {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.app-shell.map-focus .topbar,
.app-shell.map-focus .search-card { transform: translateY(-18px); }
.app-shell.map-focus .map-actions { transform: translateX(18px); }
.app-shell.map-focus .result-card,
.app-shell.map-focus .history-panel { transform: translateY(24px); }
.app-shell.map-focus .focus-toggle { opacity: 1; pointer-events: auto; transform: none; }

.search-card {
  position: fixed;
  z-index: 500;
  top: calc(max(14px, env(safe-area-inset-top)) + 64px);
  left: 16px;
  width: min(430px, calc(100% - 32px));
  padding: 14px;
  border: 1px solid rgb(255 255 255 / 55%);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 95%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.search-card label { display: block; margin: 0 0 8px 2px; color: var(--forest-950); font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.input-row { display: flex; gap: 8px; }

input {
  min-width: 0;
  flex: 1;
  height: 48px;
  padding: 0 13px;
  border: 1.5px solid #ced8d4;
  outline: 0;
  border-radius: 12px;
  background: white;
  color: var(--ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  transition: border-color .2s, box-shadow .2s;
}

input:focus { border-color: var(--forest-700); box-shadow: 0 0 0 3px rgb(38 113 93 / 13%); }

.primary-button, .secondary-button {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  font-weight: 750;
}

.primary-button { border: 0; background: var(--forest-900); color: white; box-shadow: 0 5px 14px rgb(23 63 53 / 25%); }
.primary-button:hover { background: var(--forest-700); }
.primary-button:disabled { cursor: wait; opacity: .65; }
.secondary-button { border: 1px solid #cad5d1; background: white; color: var(--ink); }
.secondary-button.danger { color: var(--danger); }
.wide { min-width: 155px; }

.hint, .error { margin: 7px 2px 0; font-size: 11px; }
.hint { color: var(--muted); }
.error { color: var(--danger); font-weight: 650; }

.map-actions {
  position: fixed;
  z-index: 500;
  right: 16px;
  top: 45%;
  display: grid;
  gap: 10px;
}

.round-button {
  width: 48px;
  height: 48px;
  border: 1px solid rgb(255 255 255 / 60%);
  border-radius: 15px;
  background: rgb(255 255 255 / 95%);
  box-shadow: var(--shadow);
}

.round-button svg { width: 23px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.9; }
.round-button.is-active { background: var(--forest-900); color: white; }

.result-card {
  position: fixed;
  z-index: 500;
  left: 16px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex;
  width: min(430px, calc(100% - 32px));
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: rgb(16 45 39 / 96%);
  color: white;
  box-shadow: 0 14px 35px rgb(16 45 39 / 32%);
}

.eyebrow { display: block; margin-bottom: 4px; color: #b8d4c9; font-size: 10px; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.result-card strong { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.result-status { display: block; margin-top: 3px; color: #c9dad4; font-size: 11px; }
.result-actions { display: flex; gap: 2px; }
.text-button { padding: 8px 7px; border: 0; background: transparent; color: #e8f2ee; font-size: 11px; font-weight: 700; }

.history-panel {
  position: fixed;
  z-index: 480;
  top: 16px;
  right: 16px;
  width: 290px;
  max-height: calc(45% - 34px);
  padding: 15px;
  overflow: auto;
  border-radius: var(--radius);
  background: rgb(255 255 255 / 94%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-heading h2 { margin: 0; font-size: 14px; }
.quiet-button { padding: 3px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.history-list { display: grid; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.history-list button { width: 100%; padding: 9px 10px; border: 0; border-radius: 10px; background: #edf3f0; color: var(--forest-950); text-align: left; font-size: 13px; font-variant-numeric: tabular-nums; }
.history-list button:hover { background: var(--forest-100); }
.empty-state { margin: 13px 0 2px; color: var(--muted); font-size: 12px; line-height: 1.4; }

.toast {
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: calc(105px + env(safe-area-inset-bottom));
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #17221f;
  color: white;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 650;
  text-align: center;
}

.offline-dialog { width: min(500px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 23px; color: var(--ink); box-shadow: 0 24px 80px rgb(0 0 0 / 35%); }
.offline-dialog::backdrop { background: rgb(5 24 20 / 58%); backdrop-filter: blur(4px); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 22px 22px 12px; }
.dialog-header h2 { margin: 0; font-size: 23px; letter-spacing: -.03em; }
.dialog-header .eyebrow { color: var(--forest-700); }
.dialog-close { width: 34px; height: 34px; border: 0; border-radius: 50%; background: #edf2f0; color: var(--ink); font-size: 23px; line-height: 1; }
.dialog-content { padding: 0 22px 20px; }
.dialog-content > p { color: #485551; font-size: 14px; line-height: 1.5; }
.offline-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 18px 0; }
.offline-facts div { padding: 14px; border-radius: 14px; background: var(--forest-100); }
.offline-facts strong, .offline-facts span { display: block; }
.offline-facts strong { color: var(--forest-950); font-size: 17px; }
.offline-facts span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.storage-note { padding: 11px 12px; border-left: 3px solid #c7963d; border-radius: 6px; background: #fff6e4; font-size: 12px !important; }
.download-progress { margin: 16px 0; }
.progress-copy { display: flex; justify-content: space-between; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.progress-copy strong { color: var(--forest-900); }
progress { width: 100%; height: 10px; overflow: hidden; border: 0; border-radius: 10px; accent-color: var(--forest-700); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.offline-dialog footer { padding: 12px 22px; background: #f0f3f1; color: var(--muted); font-size: 10px; text-align: center; }

.current-pin { position: relative; width: 38px; height: 48px; }
.current-pin::before { content: ''; position: absolute; z-index: -1; top: 5px; left: 3px; width: 32px; height: 32px; border-radius: 50%; background: rgb(215 67 54 / 30%); animation: pulse 1.8s ease-out infinite; }
.pin-head { position: absolute; top: 1px; left: 5px; display: grid; width: 29px; height: 29px; place-items: center; border: 3px solid white; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: #d74336; box-shadow: 0 4px 10px rgb(0 0 0 / 28%); }
.pin-head::after { content: ''; width: 7px; height: 7px; border-radius: 50%; transform: rotate(45deg); background: white; }
@keyframes pulse { 0% { transform: scale(.55); opacity: 1; } 100% { transform: scale(1.65); opacity: 0; } }

.leaflet-control-attribution { max-width: 75vw; font-size: 9px !important; }
.leaflet-control-zoom { margin-top: 210px !important; border: 0 !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { color: var(--forest-900) !important; }

@media (max-width: 760px) {
  .history-panel { top: auto; right: 16px; bottom: calc(22px + env(safe-area-inset-bottom)); width: min(290px, calc(100% - 32px)); max-height: 190px; transform: translateY(calc(100% + 40px)); }
  .history-panel.is-open { transform: none; }
  .app-shell.map-focus .history-panel { transform: translateY(calc(100% + 40px)); }
  .result-card { right: 16px; width: auto; }
  .result-card.history-visible { bottom: calc(220px + env(safe-area-inset-bottom)); }
  .map-actions { top: auto; bottom: calc(115px + env(safe-area-inset-bottom)); }
}

@media (min-width: 761px) {
  .history-button { display: none; }
}

@media (max-width: 430px) {
  .primary-button { padding: 0 14px; }
  .result-card { align-items: flex-start; }
  .result-card strong { font-size: 15px; }
  .result-actions { flex-direction: column; }
  .offline-facts { grid-template-columns: 1fr; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
