:root {
  --bg: #ffffff; --surface: #ffffff; --fg: #1d2330; --muted: #6b7484; --line: #e4e7ec;
  --accent: #0f766e; --accent-soft: #e3f3f1; --shadow: 0 2px 10px rgba(20, 30, 50, .14); --panel-w: 320px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161d; --surface: #1a2029; --fg: #e7ebf2; --muted: #98a2b3; --line: #2b3340;
          --accent: #4fd1c5; --accent-soft: #17332f; --shadow: 0 2px 12px rgba(0, 0, 0, .5); }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--fg); }
button, input, select { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--surface); flex: none; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 16px; }
#basemap { padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }

/* layout */
#stage { flex: 1; min-height: 0; display: flex; }
#mapwrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }
.float { position: absolute; z-index: 800; background: var(--surface); box-shadow: var(--shadow); border-radius: 12px; }

/* search pill */
#search { top: 14px; left: 56px; right: 150px; max-width: 520px; display: flex; align-items: center; gap: 8px; padding: 0 6px 0 14px; height: 44px; border-radius: 999px; }
#search .glass { color: var(--muted); font-size: 18px; }
#q { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; height: 100%; }
button.link { border: 0; background: transparent; color: var(--accent); font-weight: 600; padding: 6px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
button.link:hover { background: var(--accent-soft); }

/* tools */
#tools { top: 14px; right: 14px; padding: 4px; border-radius: 999px; }
#btn-layers { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; font-weight: 600; cursor: pointer; }
#btn-layers:hover, #btn-layers[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }

#status { top: 66px; left: 56px; max-width: 520px; margin: 0; padding: 7px 12px; font-size: 12.5px; color: var(--muted); }
#status.warn { color: #b25e00; }
#zoomhint { bottom: 22px; left: 50%; transform: translateX(-50%); margin: 0; padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }

/* legend card */
#legend { left: 14px; bottom: 22px; width: 250px; max-height: 60%; overflow-y: auto; padding: 12px 14px; font-size: 12.5px; }
#legend strong.t { display: block; margin-bottom: 6px; font-size: 13px; }
#legend .sw { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
#legend .sw i { width: 20px; height: 12px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .2); flex: none; }
#legend img { max-width: 100%; display: block; margin: 4px 0; background: #fff; border-radius: 4px; }
#legend label.check { display: flex; gap: 8px; align-items: center; margin: 4px 0; cursor: pointer; }
#legend select { width: 100%; margin: 6px 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
#legend-options:not(:empty) { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
#legend-note { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
#legend-note:empty { display: none; }

/* layers panel */
#panel { width: var(--panel-w); flex: none; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--surface); }
#panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); flex: none; }
.panel-head h2 { margin: 0; font-size: 17px; }
#panel-close { border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 6px; }
#panel-body { flex: 1; overflow-y: auto; }
.group-title { margin: 0; padding: 16px 16px 6px; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.group-title span { text-transform: none; letter-spacing: 0; font-weight: 400; }
.group + .group { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; }
.row:hover { background: rgba(127, 127, 127, .09); }
.row .ico { width: 22px; text-align: center; flex: none; font-size: 16px; }
.row .txt { flex: 1; min-width: 0; font-weight: 500; }
.row .txt small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; }
.row.on { background: var(--accent-soft); }
.row.on .txt { color: var(--accent); font-weight: 600; }
.row.off { cursor: default; opacity: .5; }
.row.off:hover { background: transparent; }
.tag { font-size: 10.5px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.row input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0; }
/* toggle switch */
.row input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 999px; background: #c9ced6; position: relative; flex: none; margin: 0; cursor: pointer; transition: background .15s; }
.row input[type=checkbox]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.row input[type=checkbox]:checked { background: var(--accent); }
.row input[type=checkbox]:checked::after { left: 16px; }
.src { margin: 0; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; flex: none; }

/* loading: chip on the map + spinner on the panel row */
.spin { display: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(127, 127, 127, .3); border-top-color: var(--accent); flex: none; animation: spin .8s linear infinite; }
.spin.on, .row.busy .spin { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading { top: 66px; left: 50%; transform: translateX(-50%); margin: 0; padding: 7px 14px; border-radius: 999px; display: flex; align-items: center; gap: 9px; font-size: 12.5px; font-weight: 600; white-space: nowrap; max-width: 80%; overflow: hidden; text-overflow: ellipsis; }
#loading[hidden] { display: none; }
#loading { position: absolute; }
#loading-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--accent); transition: width .2s; }
.pop .loc { margin-bottom: 10px; padding-bottom: 9px; border-bottom: 1px solid #e4e7ec; }
.pop .loc .place { font-size: 15px; font-weight: 700; margin-top: 1px; }
.pop .chip { display: inline-block; margin: 0 0 8px; padding: 3px 10px; border-radius: 999px; background: #e3f3f1; color: #0f766e; font-size: 12px; font-weight: 600; }
.pop .progress { height: 3px; border-radius: 2px; background: #eef0f3; margin-top: 8px; overflow: hidden; }
.pop .progress i { display: block; height: 100%; width: 0; background: #0f766e; transition: width .2s; }

/* popups (Leaflet popups are always on white, so colours here are fixed, not themed) */
.leaflet-popup-content { margin: 14px 16px; }
.pop { color: #1d2330; font-size: 13px; line-height: 1.4; max-height: 420px; overflow-y: auto; padding-right: 2px; }
.pop h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: #55606f; }
.pop .k { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #6b7484; font-weight: 700; }
.pop .big { font-size: 30px; font-weight: 700; line-height: 1.15; margin: 2px 0; }
.pop .big span { font-size: 14px; font-weight: 500; color: #6b7484; margin-left: 2px; }
.pop .sub { color: #55606f; font-size: 12.5px; margin: 2px 0; }
.pop .sect { margin: 12px 0 5px; padding-top: 9px; border-top: 1px solid #e4e7ec; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #6b7484; font-weight: 700; }
.pop .bar { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 3px 0 6px; }
.pop .bar b { font-weight: 600; }
.pop .bar i { position: absolute; left: 0; bottom: 1px; height: 3px; border-radius: 2px; background: #0f766e; min-width: 0; }
.pop .bar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 1px; height: 3px; border-radius: 2px; background: #eef0f3; z-index: -1; }
.pop .bar { z-index: 0; }
.pop dl { margin: 6px 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.pop dt { color: #6b7484; } .pop dd { margin: 0; font-weight: 600; text-align: right; }
.pop .tip { margin-top: 9px; padding: 8px 10px; border-radius: 8px; background: #f3f6f8; font-size: 12.5px; }
.pop .tip b { display: block; margin-bottom: 1px; }
.pop .foot { margin-top: 10px; padding-top: 7px; border-top: 1px solid #e4e7ec; color: #8a93a2; font-size: 11.5px; }
.pop .hint { color: #6b7484; font-size: 12px; margin-top: 8px; }
.pop .trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.pop .trio div { background: #f3f6f8; border-radius: 8px; padding: 6px 4px; text-align: center; }
.pop .trio small { display: block; color: #6b7484; font-size: 10.5px; } .pop .trio b { font-size: 17px; }
.pop .scale { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; margin: 6px 0; }
.pop .scale i { font-style: normal; text-align: center; font-size: 10.5px; color: #fff; padding: 2px 0; border-radius: 3px; opacity: .45; }
.pop .scale i.me { opacity: 1; outline: 2px solid #1d2330; outline-offset: 1px; font-weight: 700; }
.pop .wait { display: flex; align-items: center; gap: 9px; color: #55606f; padding: 4px 0; }
.pop a { color: #0f766e; }

/* location report: covers the map; always light so it prints as it looks */
.pop .report-btn { display: block; width: 100%; margin-top: 12px; padding: 8px 10px; border: 1px solid #0f766e; border-radius: 8px; background: #fff; color: #0f766e; font: inherit; font-weight: 600; cursor: pointer; }
.pop .report-btn:hover { background: #e3f3f1; }
#report { position: absolute; inset: 0; z-index: 1000; display: flex; flex-direction: column; background: #f4f6f8; color: #1d2330; }
#report[hidden] { display: none; }
.rhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 16px 22px 12px; background: #fff; border-bottom: 1px solid #e4e7ec; flex: none; }
.rhead .k { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #6b7484; font-weight: 700; }
.rhead h2 { margin: 2px 0; font-size: 20px; }
#report-sub { color: #55606f; font-size: 13px; }
.ractions { display: flex; gap: 8px; align-items: center; flex: none; }
#report-print { padding: 8px 14px; border: 0; border-radius: 8px; background: #0f766e; color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
#report-close { border: 0; background: transparent; font-size: 26px; line-height: 1; color: #6b7484; cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.rprogress { height: 3px; background: #e4e7ec; flex: none; } .rprogress i { display: block; height: 100%; width: 0; background: #0f766e; transition: width .25s; }
#report-status { margin: 0; padding: 6px 22px; font-size: 12px; color: #6b7484; background: #fff; border-bottom: 1px solid #e4e7ec; flex: none; }
#report-body { flex: 1; overflow-y: auto; padding: 6px 22px 28px; }
.rsec h3 { margin: 22px 0 10px; font-size: 15px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; align-items: start; }
.card { background: #fff; border: 1px solid #e4e7ec; border-radius: 12px; padding: 14px 16px; break-inside: avoid; }
.card h4 { margin: 0 0 8px; font-size: 13px; color: #0f766e; }
.card .pop { max-height: none; overflow: visible; }
.card .pop .report-btn { display: none; }
.rfoot { margin: 22px 0 0; color: #6b7484; font-size: 12px; max-width: 900px; }

@media print {
  @page { margin: 12mm; }
  html, body { height: auto; display: block; background: #fff; }
  #topbar, #panel, #map, .float, .ractions, .rprogress, #report-status { display: none !important; }
  #stage, #mapwrap { display: block; position: static; }
  #report { position: static; display: block; background: #fff; }
  #report[hidden] { display: none; }
  .rhead { padding: 0 0 8px; border-bottom: 1px solid #999; }
  #report-body { overflow: visible; padding: 0; }
  .cards { display: block; column-count: 2; column-gap: 12px; }
  .card { margin: 0 0 10px; border-color: #bbb; padding: 10px 12px; }
  .pop .bar i { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pop .scale i, .pop .tip, .pop .trio div { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 760px) {
  #stage { flex-direction: column; }
  #panel { width: 100%; height: 46%; border-left: 0; border-top: 1px solid var(--line); }
  #search { left: 54px; right: 112px; padding-left: 10px; }
  #search .glass, #near { display: none; }
  #status { left: 12px; right: 12px; top: 64px; }
  #legend { left: 8px; bottom: 26px; width: 190px; max-height: 40%; padding: 8px 10px; }
  .brand { font-size: 15px; }
  .src { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
