:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --text: #1b1d20;
  --muted: #5d636b;
  --border: #dcd8d0;
  --accent: #1f5fd1;
  --accent-text: #ffffff;
  --route: #1f5fd1;
  --route-alt: #8a9099;
  --flock: #d0342c;
  --other: #b7791f;
  --start: #1d8a4e;
  --end: #d0342c;
  --focus: #1f5fd1;
  --kind-police: #2f4fb5;
  --kind-transport: #13806f;
  --kind-government: #7a4bb0;
  --kind-private: #b7791f;
  --kind-unknown: #8a9099;
  --shadow: 0 6px 24px rgba(20, 22, 25, 0.14), 0 1px 3px rgba(20, 22, 25, 0.1);
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --surface: #1f2226;
    --surface-2: #272b30;
    --text: #eceae6;
    --muted: #a3a8af;
    --border: #3a3f46;
    --accent: #6d9ef5;
    --accent-text: #0e1116;
    --route: #6d9ef5;
    --route-alt: #7d848d;
    --flock: #f0625a;
    --other: #e0a445;
    --start: #43c07e;
    --end: #f0625a;
    --focus: #8fb4f7;
    --kind-police: #7f9cf5;
    --kind-transport: #3cc3aa;
    --kind-government: #b58ae6;
    --kind-private: #e0a445;
    --kind-unknown: #7d848d;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #16181b;
  --surface: #1f2226;
  --surface-2: #272b30;
  --text: #eceae6;
  --muted: #a3a8af;
  --border: #3a3f46;
  --accent: #6d9ef5;
  --accent-text: #0e1116;
  --route: #6d9ef5;
  --route-alt: #7d848d;
  --flock: #f0625a;
  --other: #e0a445;
  --start: #43c07e;
  --end: #f0625a;
  --focus: #8fb4f7;
  --kind-police: #7f9cf5;
  --kind-transport: #3cc3aa;
  --kind-government: #b58ae6;
  --kind-private: #e0a445;
  --kind-unknown: #7d848d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body { overflow: hidden; font-size: 15px; line-height: 1.45; }

a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

#map { position: fixed; inset: 0; }

/* Panel */
.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 384px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  z-index: 2;
}

.sheet-handle { display: none; }

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
  font-weight: 750;
}
.brand h1 span { color: var(--flock); }
.brand p { margin: 4px 0 14px; color: var(--muted); font-size: 14px; }

/* Form */
#route-form { position: relative; display: grid; gap: 10px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.combo { position: relative; display: flex; align-items: center; }

.combo input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 40px 10px 30px;
  min-height: 44px;
}
.combo input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 30%, transparent); }
.combo input::placeholder { color: var(--muted); }

.dot {
  position: absolute;
  left: 11px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  pointer-events: none;
}
.dot-start { background: var(--start); }
.dot-end { background: var(--end); border-radius: 2px; }

.icon-btn {
  position: absolute;
  right: 4px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn svg, .swap-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn svg circle:first-child { fill: currentColor; stroke: none; }

.swap-btn {
  position: absolute;
  right: 48px;
  top: 58px;
  z-index: 1;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.swap-btn:hover { color: var(--text); }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
}
.suggestions li {
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
}
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--surface-2); }
.suggestions li.empty { color: var(--muted); cursor: default; }

.check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
  cursor: pointer;
}
.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }

button.primary, .primary {
  font: inherit;
  font-weight: 650;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  padding: 0 16px;
}
button.primary:disabled { opacity: 0.6; cursor: progress; }

.hint { margin: 0; font-size: 13px; color: var(--muted); }

/* Status */
.status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 14px;
}
.status.error { background: color-mix(in srgb, var(--flock) 14%, var(--surface)); color: var(--text); }
.status.loading::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  vertical-align: -1px;
  border: 2px solid var(--muted);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
#results { margin-top: 16px; }

.section-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.options { display: grid; gap: 8px; }

.option {
  font: inherit;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "label meta" "count meta";
  align-items: center;
  column-gap: 12px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.option[aria-checked="true"] { border-color: var(--route); background: color-mix(in srgb, var(--route) 8%, var(--surface)); }
.option-label { grid-area: label; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.option-count { grid-area: count; font-size: 13px; color: var(--muted); }
.option-count strong { font-size: 24px; line-height: 1.15; color: var(--text); font-variant-numeric: tabular-nums; }
.option-count strong.zero { color: var(--start); }
.option-meta { grid-area: meta; text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
.option-meta .delta { display: block; font-size: 12px; color: var(--muted); }

.watchers-section { margin-top: 16px; }
.watchers { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.watchers li { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; }
.watcher-name { flex: 1; display: grid; }
.watcher-kind { font-size: 12px; color: var(--muted); }
.watcher-count { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.kind-dot { flex: none; width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: var(--kind-unknown); }
.kind-police { background: var(--kind-police); }
.kind-transportation { background: var(--kind-transport); }
.kind-government { background: var(--kind-government); }
.kind-private { background: var(--kind-private); }

.warning {
  margin: 0 0 12px;
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 14px;
  background: color-mix(in srgb, var(--other) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--other) 45%, var(--surface));
}
#data-status.warn { color: var(--text); font-weight: 600; }

.note { font-size: 14px; margin: 10px 0 0; }
.note:empty { display: none; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.secondary {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.secondary:hover { border-color: var(--muted); }

.fine { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.directions { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.directions summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.directions ol { margin: 8px 0 0; padding-left: 20px; font-size: 14px; }
.directions li { padding: 5px 0; border-bottom: 1px solid var(--surface-2); }
.directions li .dist { color: var(--muted); font-size: 12px; margin-left: 6px; white-space: nowrap; }

.footer { margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.footer p { margin: 2px 0; }
button.link { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

/* About dialog */
dialog {
  max-width: min(560px, calc(100vw - 32px));
  max-height: calc(100svh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 12, 15, 0.45); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
dialog h3 { margin: 16px 0 6px; font-size: 15px; }
dialog p, dialog li { font-size: 14px; }
dialog ul { padding-left: 20px; }
dialog .primary { margin-top: 10px; }

/* Map popups */
.maplibregl-popup-content {
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--surface); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--surface); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface); }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 0 6px; }
.popup-title { font-weight: 650; margin-bottom: 2px; }
.popup-actions { display: flex; gap: 6px; margin-top: 6px; }
.popup-actions button { font: inherit; font-size: 13px; min-height: 32px; }

.pin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.pin-start { background: var(--start); }
.pin-end { background: var(--end); border-radius: 4px; }

/* Phones: panel becomes a bottom sheet */
@media (max-width: 720px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 72svh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    padding: 6px 16px calc(12px + env(safe-area-inset-bottom));
  }
  .panel.collapsed { max-height: 88px; overflow: hidden; }
  /* After routing, keep the sheet short so the route stays visible. */
  .panel.compact { max-height: 44svh; }
  .sheet-handle {
    display: block;
    width: 100%;
    height: 22px;
    border: 0;
    background: none;
    cursor: pointer;
    position: relative;
  }
  .sheet-handle::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 8px;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: var(--border);
  }
  .brand h1 { font-size: 19px; }
  .brand p { margin-bottom: 10px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .status.loading::before { animation: none; }
}

/* Camera changes page */
body.page { overflow: auto; }
.page-main { max-width: 720px; margin: 0 auto; padding: 24px 16px 48px; }
.page-main .brand h1 { font-size: 24px; }
.back { margin: 0 0 8px; font-size: 14px; }
.page-actions { margin: 10px 0 0; }
.filter { margin: 18px 0 4px; }
.day { margin-top: 22px; }
.day-title { font-size: 15px; margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.changes { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.change { display: flex; gap: 10px; align-items: flex-start; }
.change-tag {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 5px;
  margin-top: 2px;
  min-width: 72px;
  text-align: center;
}
.change-added .change-tag { background: color-mix(in srgb, var(--flock) 16%, var(--surface)); color: var(--flock); }
.change-removed .change-tag { background: var(--surface-2); color: var(--muted); }
.change-title { font-size: 15px; }
.change-meta { font-size: 13px; color: var(--muted); }
.footnote { margin-top: 32px; }
