:root {
  --bg: #f7f6f2; --panel: #ffffff; --ink: #1b1b1a; --ink2: #52514e; --muted: #7a7974; --line: #dcdbd6; --line2: #c9c8c2;
  --accent: #2a78d6; --accent-ink: #ffffff; --warn-bg: #fff4d6; --warn-ink: #6b4a00; --bad: #b3261e; --good: #1f7a3a;
  --flag-bg: #fde8e6; --chip: #eeede9; --shadow: 0 1px 3px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615; --panel: #1f1f1e; --ink: #ecebe7; --ink2: #b9b8b2; --muted: #8d8c86; --line: #353533; --line2: #4a4946;
    --accent: #5b9cf0; --accent-ink: #0b0b0b; --warn-bg: #3a3020; --warn-ink: #f2d38a; --bad: #ff8a80; --good: #7fd18f;
    --flag-bg: #43201d; --chip: #2a2a28; --shadow: 0 1px 3px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select { background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; padding: 4px 7px; min-width: 0; }
label { color: var(--ink2); font-size: 12.5px; }
.muted { color: var(--muted); font-size: 12.5px; }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 6px; padding: 7px 9px; font-size: 12.5px; }
.flag { background: var(--flag-bg); border-radius: 4px; padding: 0 3px; }
.tag { display: inline-block; font-size: 11.5px; border: 1px dashed var(--line2); border-radius: 10px; padding: 0 7px; color: var(--ink2); }
.badge { display: inline-block; min-width: 8px; padding: 0 6px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; margin-left: 4px; }
.hidden { display: none !important; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 4px 7px; border-bottom: 1px solid var(--line); vertical-align: top; }
/* header colours are explicit (not inherited), so headers stay readable inside third-party containers such as Leaflet popups */
th { background: var(--chip); color: var(--ink); font-weight: 600; font-size: 12.5px; position: sticky; top: 0; }
th abbr { text-decoration: none; cursor: help; border-bottom: 1px dotted var(--muted); }
td.n, th.n { text-align: right; }

/* ---------- map page */
#top { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#top h1 { font-size: 16px; margin: 0 8px 0 0; white-space: nowrap; }
#top .grow { flex: 1; }
#idq { width: 220px; }
#main { display: flex; height: calc(100% - 50px); }
#side { width: 300px; flex: none; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 10px 12px; }
#map { flex: 1; min-width: 0; }
#side h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink2); margin: 14px 0 6px; }
#side h2:first-child { margin-top: 0; }
.row { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
.row > * { flex: 1; }
.row > label { flex: 0 0 82px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 2px 0; cursor: pointer; }
.legend-item input { flex: none; }
.sw { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.35); flex: none; }
.legend-item .n { margin-left: auto; color: var(--muted); }
#count { font-weight: 600; }
#drawer { position: absolute; right: 12px; top: 62px; width: 420px; max-height: calc(100% - 80px); overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 12px 14px; z-index: 1000; }
#drawer h3 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
#drawer .close { border: 0; font-size: 18px; padding: 0 4px; }
.results li { margin: 3px 0; }
.results { padding-left: 18px; margin: 6px 0; }
.leaflet-popup-content { font: 13px/1.4 "Segoe UI", Arial, sans-serif; min-width: 290px; }
.leaflet-popup-content table td, .leaflet-popup-content table th { padding: 2px 5px; font-size: 12px; white-space: nowrap; }
/* theme Leaflet's popup (it defaults to a white box with #333 text) with the site's light/dark variables */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--ink); }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink2); }
.leaflet-popup-content a { color: var(--accent); }
.plain-bg { background: #e9eef0; }
@media (prefers-color-scheme: dark) { .plain-bg { background: #22292c; } }
.progress { height: 10px; background: var(--chip); border-radius: 5px; overflow: hidden; margin: 6px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
pre.log { max-height: 220px; overflow: auto; background: var(--chip); padding: 6px 8px; border-radius: 6px; font-size: 11.5px; white-space: pre-wrap; }
.tables-wrap { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.tables-wrap td, .tables-wrap th { font-size: 11.5px; padding: 2px 5px; }
.changed td { background: var(--warn-bg); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 2px 10px; font-size: 13px; margin: 6px 0; }
.kv div:nth-child(odd) { color: var(--ink2); }
.ok { color: var(--good); } .bad { color: var(--bad); }

/* ---------- plot page */
.page { max-width: 1280px; margin: 0 auto; padding: 14px 18px 40px; }
.page h1 { font-size: 22px; margin: 4px 0 2px; }
.page h2 { font-size: 17px; margin: 22px 0 8px; border-bottom: 2px solid var(--accent); padding-bottom: 3px; }
.page h3 { font-size: 14px; margin: 14px 0 6px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.timeline { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.tc { background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 9px; cursor: pointer; font-size: 12.5px; }
.tc.sel { border: 2px solid var(--accent); }
.tc.pred { border-style: dashed; cursor: default; background: transparent; }
.tc .d { font-weight: 650; font-size: 14px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0 8px; }
.tabs button { border-radius: 16px; padding: 3px 11px; font-size: 13px; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.scroll { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 8px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.kpi .l { font-size: 12px; color: var(--ink2); } .kpi .v { font-size: 20px; font-weight: 650; } .kpi .u { font-size: 11.5px; color: var(--muted); }
.chart { width: 100%; height: 360px; }
.fields { columns: 3 300px; column-gap: 18px; font-size: 12.5px; }
.fields div { break-inside: avoid; padding: 1px 0; border-bottom: 1px dotted var(--line); }
.fields b { color: var(--ink2); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
@media (max-width: 760px) {
  #main { flex-direction: column; height: auto; }
  #side { width: 100%; border-right: 0; }
  #map { height: 70vh; }
  #drawer { left: 8px; right: 8px; width: auto; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- static site additions: footer, mobile filter panel, print */
body.mapbody { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
body.mapbody #main { flex: 1; min-height: 0; height: auto; position: relative; }
.footer { font-size: 12px; color: var(--muted); padding: 5px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.footer a { color: var(--accent); }
.toplink { white-space: nowrap; }
.searchrow { display: flex; gap: 6px; align-items: center; }
.mobile-only { display: none; }
.popscroll { max-height: 220px; overflow: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.popscroll table { width: max-content; min-width: 100%; }
.prose { max-width: 820px; } .prose li { margin-bottom: 6px; }
.leaflet-container { font: inherit; }
@media (max-width: 760px) {
  .mobile-only { display: inline-block; }
  #top { gap: 6px; padding: 6px 8px; }
  #top h1 { font-size: 15px; flex: 1; }
  .searchrow { order: 5; width: 100%; }
  #idq { flex: 1; width: auto; font-size: 16px; }           /* 16px avoids iOS zoom on focus */
  #top button, #top .toplink { padding: 8px 10px; }
  body.mapbody #main { flex-direction: row; }
  body.mapbody #map { height: auto; flex: 1; }
  #side { position: absolute; z-index: 1100; top: 0; bottom: 0; left: 0; width: min(88vw, 340px); transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow); border-right: 1px solid var(--line); }
  body.side-open #side { transform: none; }
  #side h2 .close { float: right; border: 0; font-size: 20px; padding: 0 6px; }
  #side select, #side input, #drawer input, #drawer select { font-size: 16px; padding: 7px 8px; }
  #drawer { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 72vh; border-radius: 12px 12px 0 0; }
  .leaflet-popup-content { min-width: 240px; }
  .page { padding: 10px 10px 30px; }
  .timeline { grid-auto-columns: minmax(140px, 70vw); }
  .chart { height: 300px; }
  .fields { columns: 1; }
  .tabs button { padding: 6px 12px; }
}
@media print {
  .noprint, .footer, .modebar-container { display: none !important; }
  body { background: #fff; color: #000; }
  .page { max-width: none; padding: 0; }
  .scroll { max-height: none !important; overflow: visible !important; border: 0; }
  .chart, .card, table, .timeline .tc { break-inside: avoid; }
  .timeline { display: flex; flex-wrap: wrap; }
  .note { background: #fff; border: 1px solid #999; }
}

/* active vs historical plots */
.histbadge { display: inline-block; font-size: 12px; border: 1.5px solid var(--muted); color: var(--ink2); border-radius: 10px; padding: 0 8px; background: var(--chip); }
.toggle-row { display: flex; align-items: flex-start; gap: 8px; padding: 8px 9px; margin: 0 0 10px; border: 1px solid var(--line2); border-radius: 6px; background: var(--chip); }
.toggle-row input { margin-top: 3px; flex: none; width: 16px; height: 16px; }
.toggle-row label { color: var(--ink); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.toggle-row .muted { display: block; font-weight: 400; }
.sw.hollow { background: transparent !important; border: 2px solid #8a8984; }
.hist-cluster { background: transparent !important; }
.hist-cluster div { background: rgba(255,255,255,.75) !important; border: 2px dashed #7a7974; color: #52514e; width: 30px; height: 30px; margin: 5px 0 0 5px; border-radius: 15px; text-align: center; font: 12px/26px "Segoe UI", system-ui, sans-serif; box-sizing: border-box; }
details.histnear { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
details.histnear summary { cursor: pointer; color: var(--ink2); }
.filtnote { margin: 2px 0 6px; }
