/* Dodo Map core styles — mobile first. Tokens at the top; modules never need to touch this file. */
:root {
  --bg: #eef1f5;
  --surface: rgba(255, 255, 255, 0.95);
  --surface-solid: #ffffff;
  --fg: #111827;
  --muted: #5b6575;
  --line: rgba(17, 24, 39, 0.12);
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --danger: #d93636;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.2);
  --radius: 14px;
  --ctl: 44px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --panel-w: 380px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: rgba(25, 31, 41, 0.95);
    --surface-solid: #191f29;
    --fg: #e8edf4;
    --muted: #9aa6b6;
    --line: rgba(255, 255, 255, 0.13);
    --accent: #6ea0ff;
    --accent-fg: #0b1220;
    --danger: #ff6b6b;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--bg); touch-action: none; }
.maplibregl-canvas { outline: none; }
.maplibregl-ctrl-bottom-left { margin-bottom: var(--safe-b); margin-left: var(--safe-l); }

button { font: inherit; color: inherit; }
.ico { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }

/* ------------------------------------------------------------------ splash */
#splash {
  position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--bg); transition: opacity 0.3s;
}
#splash .splash-logo { font-size: 42px; letter-spacing: -0.02em; font-weight: 700; }
#splash .splash-text { color: var(--muted); max-width: 80vw; text-align: center; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
#splash .spinner { width: 30px; height: 30px; }
#splash.failed .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ on-map controls */
.ctl-stack {
  position: absolute; z-index: 5; display: flex; flex-direction: column; gap: 8px;
  top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px);
  transition: right 0.25s ease;
}
.ctl-btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  width: var(--ctl); height: var(--ctl); border-radius: 12px; padding: 0;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  user-select: none; touch-action: manipulation;
}
.ctl-btn:active, .icon-btn:active { transform: scale(0.96); }
.ctl-btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.compass-needle { display: inline-flex; transition: transform 0.05s linear; }

button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.view-switcher {
  position: absolute; z-index: 5; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 40px); display: flex; gap: 2px; padding: 4px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.seg {
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; touch-action: manipulation;
  transition: background 0.15s, color 0.15s;
}
.seg.on { background: var(--accent); color: var(--accent-fg); }
.seg:disabled { opacity: 0.6; }

.loadbar { position: absolute; z-index: 6; left: 0; right: 0; top: 0; height: 3px; overflow: hidden; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.loadbar.on { opacity: 1; }
.loadbar::before { content: ''; position: absolute; inset: 0; width: 35%; background: var(--accent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }

.net-badge {
  position: absolute; z-index: 6; top: calc(var(--safe-t) + 12px); left: calc(var(--safe-l) + 12px);
  display: inline-flex; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); max-width: calc(100vw - 100px);
}

.attr {
  position: absolute; z-index: 4; right: calc(var(--safe-r) + 8px); bottom: calc(var(--safe-b) + 6px);
  display: flex; align-items: center; gap: 4px; max-width: calc(100vw - 16px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: var(--muted);
}
.attr-text { display: none; padding-left: 10px; white-space: normal; line-height: 1.25; }
.attr.open .attr-text { display: inline; max-width: calc(100vw - 72px); }
.attr-btn { width: 28px; height: 28px; border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex: none; }

/* ------------------------------------------------------------------ toasts */
.toasts {
  position: absolute; z-index: 30; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center;
  top: calc(var(--safe-t) + 64px); width: min(480px, calc(100vw - 24px)); pointer-events: none;
}

/* detail sheet: left card on desktop, bottom sheet on phones */
.sheet {
  position: absolute; z-index: 18; left: calc(var(--safe-l) + 12px); top: calc(var(--safe-t) + 12px); bottom: calc(var(--safe-b) + 12px);
  width: min(460px, calc(100vw - 24px)); display: flex; flex-direction: column; background: var(--surface-solid); color: var(--fg);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  transform: translateX(calc(-105% - 24px)); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
.sheet.dragging { transition: none; }
.sheet .grabber { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 18px; flex: none; touch-action: none; }
.sheet-head h2 { margin: 0; font-size: 18px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-head .icon-btn { box-shadow: none; background: transparent; border-color: transparent; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 14px 16px; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; }
@media (max-width: 719px) {
  .sheet {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: min(82dvh, 720px); border-radius: 20px 20px 0 0; padding-bottom: var(--safe-b);
    transform: translateY(calc(105% + var(--drag, 0px)));
  }
  .sheet.open { transform: translateY(var(--drag, 0px)); }
  .sheet .grabber { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; touch-action: none; }
}

/* floating widgets (timeline, legends) */
.overlays {
  position: absolute; z-index: 6; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: stretch;
  bottom: calc(var(--safe-b) + 92px); width: min(560px, calc(100vw - 24px)); pointer-events: none;
}
.overlay {
  pointer-events: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); padding: 8px 12px;
}
.overlay:empty, .overlay[hidden] { display: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow); animation: pop 0.2s ease; max-width: 100%;
}
.toast.out { opacity: 0; transition: opacity 0.2s; }
.toast-warn { background: #b45309; color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-action { border: 0; background: rgba(255, 255, 255, 0.2); color: inherit; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ panel (bottom sheet on phones) */
.scrim { position: absolute; z-index: 19; inset: 0; background: rgba(8, 12, 20, 0.35); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
.panel-open .scrim { opacity: 1; pointer-events: auto; }

.panel {
  position: absolute; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column;
  max-height: min(80dvh, 680px); border-radius: 20px 20px 0 0; background: var(--surface-solid); color: var(--fg);
  border: 1px solid var(--line); box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  padding-bottom: var(--safe-b);
  transform: translateY(calc(105% + var(--drag, 0px))); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  visibility: hidden;
}
.panel-open .panel { transform: translateY(var(--drag, 0px)); visibility: visible; }
.panel.dragging { transition: none; }
.grabber { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; touch-action: none; cursor: grab; flex: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 18px; touch-action: none; flex: none; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head .icon-btn { box-shadow: none; background: transparent; border-color: transparent; }
.panel-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 14px 16px; -webkit-overflow-scrolling: touch; }

@media (min-width: 720px) {
  .scrim { display: none; }
  .panel {
    left: auto; top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px); bottom: calc(var(--safe-b) + 12px);
    width: min(var(--panel-w), calc(100vw - 24px)); max-height: none; border-radius: 18px; padding-bottom: 0;
    transform: translateX(calc(105% + 24px)); box-shadow: var(--shadow);
  }
  .panel-open .panel { transform: none; }
  .grabber { display: none; }
  .panel-head { padding-top: 12px; }
  .panel-open .ctl-stack { right: calc(var(--safe-r) + var(--panel-w) + 24px); }
  .attr-text { display: inline; }
  .attr { max-width: 60vw; }
  .view-switcher { bottom: calc(var(--safe-b) + 36px); }
  .overlays { bottom: calc(var(--safe-b) + 88px); }
}

/* accordion sections */
.sec { border-top: 1px solid var(--line); }
.sec:first-child { border-top: 0; }
.sec-head {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 0 4px; border: 0; background: transparent;
  cursor: pointer; text-align: left; touch-action: manipulation; border-radius: 10px;
}
.sec-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.sec-hint { font-size: 12px; color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sec-title { min-width: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.sec.open .sec-title { color: var(--fg); }
.sec-badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: var(--accent-fg);
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; max-width: 45%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sec-head .ico { color: var(--muted); transition: transform 0.2s; flex: none; }
.sec.open .sec-head .ico { transform: rotate(180deg); }
.sec-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.25s ease; }
.sec.open .sec-panel { grid-template-rows: 1fr; }
.sec-inner { overflow: hidden; min-height: 0; visibility: hidden; transition: visibility 0.25s; }
.sec.open .sec-inner { visibility: visible; }
.sec-body { padding: 0 2px 10px; }
.sec h4 { margin: 14px 0 6px; font-size: 13px; }
.active-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 2px 2px 12px; }
.active-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-right: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 30px; padding: 0 10px; border: 0; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--fg); font: 600 13px system-ui, sans-serif; cursor: pointer; touch-action: manipulation;
}
.chip span { opacity: 0.6; font-size: 15px; line-height: 1; }
.chip:hover span { opacity: 1; }
.group-title { font-size: 12px; color: var(--muted); margin: 10px 2px 2px; font-weight: 600; }

.row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 2px 0; border-radius: 10px; }
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.row-text { display: flex; flex-direction: column; min-width: 0; }
.row-text b { font-weight: 600; }
.row-text small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-text small.err, .problem small { color: var(--danger); }
.row.failed .row-main { cursor: default; }
.row-settings { flex-basis: 100%; padding: 4px 4px 12px 52px; }
.gear { box-shadow: none !important; background: transparent !important; border-color: transparent !important; color: var(--muted); }
.gear.open { color: var(--accent); }

input.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 42px; height: 26px; border-radius: 999px; margin: 0;
  background: var(--line); position: relative; cursor: pointer; transition: background 0.15s;
}
input.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { transform: translateX(16px); }
input.switch:disabled, input.radio:disabled { opacity: 0.5; cursor: default; }
input.radio {
  appearance: none; -webkit-appearance: none; flex: none; width: 24px; height: 24px; margin: 0; border-radius: 50%;
  border: 2px solid var(--muted); cursor: pointer; display: grid; place-content: center;
}
input.radio::after { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); transform: scale(0); transition: transform 0.12s; }
input.radio:checked { border-color: var(--accent); }
input.radio:checked::after { transform: scale(1); }

.settings-form { display: grid; gap: 10px; }
.st-row { display: grid; gap: 4px; }
.st-label { font-size: 13px; color: var(--muted); }
.st-control { display: flex; align-items: center; gap: 10px; }
.st-control input[type='range'] { flex: 1; min-width: 0; height: 28px; accent-color: var(--accent); }
.st-value { min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.st-toggle { grid-template-columns: 1fr auto; align-items: center; }
select, input[type='text'] {
  min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-solid); color: var(--fg); font: inherit; max-width: 100%;
}

.kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14px; }
.kv span { color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-solid); font-weight: 600; margin-top: 8px; touch-action: manipulation;
}
.btn.danger { color: var(--danger); }
.problem { display: flex; gap: 10px; padding: 8px 0; align-items: flex-start; color: var(--danger); }
.problem div { display: flex; flex-direction: column; min-width: 0; }
.problem b { color: var(--fg); word-break: break-all; }

/* popups sit above floating widgets (timeline, legend) */
.maplibregl-popup { z-index: 7; }

/* maplibre popup polish */
.maplibregl-popup-content { border-radius: 12px; padding: 12px 14px; font: 14px/1.4 system-ui, sans-serif; color: #111827; }
.maplibregl-popup-close-button { font-size: 20px; padding: 4px 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* panel search */
.panel-searchbar { flex: none; padding: 0 14px 8px; }
.panel-search { width: 100%; box-sizing: border-box; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-solid); color: var(--fg); padding: 0 12px; font: 15px system-ui, sans-serif; }
.panel-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.panel-results-title { font-size: 12px; color: var(--muted); padding: 2px 2px 8px; }
.panel-empty { padding: 20px 4px; color: var(--muted); font-size: 14px; }
.result { border-top: 1px solid var(--line); padding-top: 4px; }
.result-cat { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; padding: 4px 2px 0; }

/* tiles: every topic of the panel looks like the weather-map picker */
.tiles { margin-top: 2px; }
.tile-group { margin: 14px 0 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.tile-group:first-child { margin-top: 2px; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.tile-wrap { position: relative; }
.tile { width: 100%; border: 2px solid transparent; background: transparent; color: inherit; padding: 0; border-radius: 14px; text-align: left; cursor: pointer; font: inherit; touch-action: manipulation; }
.tile-thumb { position: relative; height: 62px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; overflow: hidden; }
.tile-ico { display: inline-flex; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55)); }
.tile-ico svg { width: 26px; height: 26px; }
.tile-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 12px; font-weight: 600; line-height: 1.2; margin: 5px 2px 4px; }
.tile.on { border-color: var(--accent); }
.tile.on .tile-name { color: var(--accent); }
.tile.on .tile-thumb::before {
  content: '✓'; position: absolute; left: 5px; top: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: var(--accent-fg);
  font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.tile.failed .tile-thumb { filter: grayscale(1); opacity: 0.6; }
.tile.busy .tile-thumb { opacity: 0.7; }
.tile-spin { position: absolute; right: 6px; bottom: 6px; width: 16px; height: 16px; }
.tile-info {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.55); color: #fff; cursor: pointer; touch-action: manipulation;
}
.tile-info svg { width: 16px; height: 16px; }
.tile-info.open { background: var(--accent); color: var(--accent-fg); }
.tile-detail { margin: 10px 0 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-solid); }
.tile-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-detail-head .icon-btn { box-shadow: none; background: transparent; border-color: transparent; width: 32px; height: 32px; }
.tile-detail-text { margin: 6px 0 4px; font-size: 13px; line-height: 1.4; }
.tile-detail-attr { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.tile-detail-on { margin-top: 6px; width: 100%; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-fg); padding: 10px; font: 600 14px system-ui, sans-serif; cursor: pointer; }
