/* ACDG portal - shared styles for every page of the site.
 *
 * Colours are tokens on <html data-theme="..."> so the dark, light and slate
 * themes all work; nothing below should hard-code a background or text colour.
 * The interactive map (/map/) uses the same palette, see
 * frontend/stylesheets/site-theme.css.
 */

/* ---------------------------------------------------------------- tokens */
:root,
html[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --inset: #0f172a;
  --border: #334155;
  --text: #f8fafc;
  --text-soft: #cbd5e1;
  --muted: #94a3b8;
  --control: #334155;
  --control-hover: #475569;
  --shadow: 0 10px 25px -10px rgba(0, 0, 0, 0.5);
  --tile-filter: invert(100%) hue-rotate(180deg) brightness(88%) contrast(92%) saturate(75%);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --inset: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;
  --control: #e2e8f0;
  --control-hover: #cbd5e1;
  --shadow: 0 10px 25px -12px rgba(15, 23, 42, 0.18);
  --tile-filter: none;
  color-scheme: light;
}

html[data-theme="slate"] {
  --bg: #1e293b;
  --panel: #334155;
  --inset: #273449;
  --border: #475569;
  --text: #f1f5f9;
  --text-soft: #e2e8f0;
  --muted: #cbd5e1;
  --control: #475569;
  --control-hover: #64748b;
  --shadow: 0 10px 25px -10px rgba(0, 0, 0, 0.45);
  --tile-filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(88%) saturate(70%);
  color-scheme: dark;
}

:root {
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --green: #34d399;
  --teal: #2dd4bf;
  --amber: #fb923c;
  --yellow: #facc15;
  --red: #f43f5e;
  --purple: #c084fc;
  --pink: #f472b6;
  --cold: #06b6d4;
  --radius: 12px;
  --radius-sm: 8px;
  --gutter: 20px;
  --content-width: 1320px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* ------------------------------------------------------------------ base */
*,
*::before,
*::after { box-sizing: border-box; }

/* Anchors and scrollIntoView land below the sticky header, not under it */
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 96px; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.2s, color 0.2s;
}

img, video { max-width: 100%; }
a { color: var(--accent); }
a:hover { color: var(--text); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; }
p { margin: 0 0 1em; }
button, input, select, textarea { font: inherit; color: inherit; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.page {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--gutter) 40px;
}

/* ---------------------------------------------------------------- header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 1100;
}

.site-header-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
  flex-shrink: 0;
}

.brand-logo {
  width: 52px;
  height: 54px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #0f172a;   /* the logo is white on transparent */
  padding: 3px;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.02em; }
.brand-sub {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 0.82rem; color: var(--muted);
}
.brand-sub img { width: 15px; height: 20px; border-radius: 2px; }
.brand-group { color: var(--accent); font-weight: 600; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.site-nav a {
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.site-nav a:hover { background: var(--control); color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.header-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn-map {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-strong);
  color: #fff !important;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.88rem;
  text-decoration: none;
  white-space: nowrap;
}
.btn-map:hover { background: #0369a1; }
.btn-map svg { width: 16px; height: 16px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--control);
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--control-hover); }
.icon-btn svg { width: 18px; height: 18px; }

.nav-toggle { display: none; }

@media (max-width: 1520px) {
  .brand-sub .brand-dept, .brand-sub .brand-sep { display: none; }
}

@media (max-width: 1240px) {
  .site-header-inner { flex-wrap: wrap; }
  .nav-toggle { display: inline-flex; }
  .header-tools { margin-left: auto; }
  .site-nav {
    order: 3;
    width: 100%;
    margin: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    padding-bottom: 6px;
  }
  .site-header.nav-open .site-nav { display: flex; }
}

@media (max-width: 560px) {
  .brand { flex-shrink: 1; }
  .brand-sub { white-space: normal; }
  .brand-logo { width: 40px; height: 42px; }
  .brand-title { font-size: 0.95rem; }
  .brand-sub .brand-dept, .brand-sub .brand-sep { display: none; }
  .btn-map .btn-map-label { display: none; }
  .btn-map { padding: 9px 10px; }
}

/* ------------------------------------------------------------ page title */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px 20px;
  margin: 26px 0 18px;
}
.page-head h1 {
  margin: 0;
  font-size: 1.6rem;
  border-left: 4px solid var(--accent);
  padding-left: 12px;
}
.page-head .lead { margin: 6px 0 0 16px; color: var(--muted); max-width: 760px; }

/* ---------------------------------------------------------------- panels */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: var(--gutter);
  min-width: 0;
}
.card.highlight { border-color: var(--accent); }
.card > h2, .card-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.1rem;
  margin: 0 0 14px;
}
.card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 1.15rem; color: var(--accent); display: flex; gap: 10px; align-items: center; }

.inset {
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  min-width: 0;
}

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8rem;
  color: var(--accent);
  background: var(--inset);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
.card-head .badge, .page-head .badge { white-space: normal; max-width: 100%; overflow-wrap: anywhere; }
.badge.ok { color: var(--green); }
.badge.warn { color: var(--amber); }
.badge.muted { color: var(--muted); }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
@media (max-width: 1024px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--control);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--control-hover); color: var(--text); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover { background: #0369a1; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.segmented button {
  border: 0; background: none; cursor: pointer;
  padding: 6px 12px; border-radius: 6px;
  font-size: 0.85rem; font-weight: 600; color: var(--muted);
}
.segmented button:hover { color: var(--text); background: var(--control); }
.segmented button[aria-pressed="true"] { background: var(--accent-strong); color: #fff; }

select, input[type="search"], input[type="text"] {
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: 38px;
  max-width: 100%;
}
select:focus, input:focus { border-color: var(--accent); outline: none; }

label.field { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; flex-wrap: wrap; }

/* ----------------------------------------------------------------- stats */
.stat {
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-width: 0;
}
.stat-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
  display: flex; justify-content: space-between; gap: 8px;
}
.stat-value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; line-height: 1.2; }
.stat-sub { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.stat.accent { border-color: var(--accent); }

.stat.wide { grid-column: span 2; }
@media (max-width: 400px) { .stat.wide { grid-column: auto; } }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 10px; font-size: 0.8rem; margin-top: 6px; color: var(--muted); }
.levels b { color: var(--text); }

.t-cold { color: var(--cold); }
.t-mild { color: var(--yellow); }
.t-warm { color: var(--red); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th {
  background: var(--inset); color: var(--muted);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  position: sticky; top: 0;
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--accent-soft); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.wrap { white-space: normal; min-width: 220px; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: 340px; }
.chart.tall { height: 560px; }
.chart.short { height: 260px; }
.chart-note { font-size: 0.8rem; color: var(--muted); margin: 8px 0 0; }

/* -------------------------------------------------------------- messages */
.notice {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  text-align: center;
  color: var(--muted);
}
.notice.error { border-color: var(--red); color: var(--red); }

.loader {
  width: 34px; height: 34px;
  border: 4px solid var(--control);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; background: var(--accent); }
.dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2); }
.dot.stale { background: var(--muted); }

/* ------------------------------------------------------------- image viewer */
.viewer {
  position: relative;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 420px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.viewer img { display: block; max-width: 100%; height: auto; }
.viewer .loader { position: absolute; }
.viewer .notice { margin: 20px; }

.timebar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  margin-bottom: 16px;
}
.timebar input[type="range"] { flex: 1 1 220px; accent-color: var(--accent); min-width: 0; }
.timebar .valid { font-weight: 600; background: var(--inset); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; }
.timebar .step { font-family: var(--mono); background: var(--control); border-radius: 6px; padding: 6px 10px; min-width: 64px; text-align: center; }

/* ------------------------------------------------------- sidebar layouts */
.with-sidebar { display: flex; gap: var(--gutter); align-items: flex-start; }
.with-sidebar > .sidebar {
  width: 280px; flex-shrink: 0;
  position: sticky; top: 96px;
  max-height: calc(100vh - 116px);
  overflow-y: auto;
}
.with-sidebar > .main { flex: 1; min-width: 0; }
@media (max-width: 1024px) {
  .with-sidebar { flex-direction: column; align-items: stretch; }
  .with-sidebar > .sidebar { width: auto; position: static; max-height: none; }
}

.menu-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 700;
  margin: 16px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.menu-title:first-child { margin-top: 0; }
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 7px 10px; text-align: left; cursor: pointer;
  font-size: 0.88rem; font-weight: 500;
}
.menu button:hover { background: var(--control); }
.menu button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.menu .tag {
  font-family: var(--mono); font-size: 0.7rem; font-weight: 700;
  padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); color: var(--muted);
}
.menu button[aria-pressed="true"] .tag { border-color: var(--accent); color: var(--accent); }
@media (max-width: 1024px) {
  .menu { flex-direction: row; flex-wrap: wrap; }
  .menu button { width: auto; }
}

/* ------------------------------------------------------------------- map */
.leaflet-container { font-family: var(--font); background: var(--inset); }
.map-tiles-themed .leaflet-tile-pane { filter: var(--tile-filter); }
.station-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 22px; padding: 0 6px;
  border-radius: 5px;
  background: #0f172a; color: #f8fafc;
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  border: 2px solid var(--badge, var(--accent));
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  transition: transform 0.12s ease;
}
.station-badge:hover { transform: scale(1.15); }
.station-badge.stale { opacity: 0.55; border-style: dashed; }
.leaflet-marker-icon.station-icon { display: flex; align-items: center; justify-content: center; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 0.85rem; line-height: 1.45; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.popup-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 2px; }
.popup-rows { display: grid; grid-template-columns: auto auto; gap: 1px 12px; margin: 6px 0; }
.popup-rows span:nth-child(odd) { color: var(--muted); }
.map-legend {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 0.75rem;
  display: flex; align-items: center; gap: 8px;
}
.map-legend .ramp { width: 120px; height: 8px; border-radius: 4px; }

/* ---------------------------------------------------------------- footer */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 30px;
  background: var(--panel);
}
.site-footer-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 18px var(--gutter) 26px;
  font-size: 0.8rem;
  color: var(--muted);
}
.site-footer details summary { cursor: pointer; font-weight: 700; color: var(--text-soft); }
.site-footer details p { text-align: justify; line-height: 1.5; margin: 10px 0 0; }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.footer-row a { color: var(--muted); }

/* ------------------------------------------------------------ prose pages */
.prose { max-width: 900px; }
.prose p { text-align: justify; color: var(--text-soft); }
.prose figure { margin: 18px 0; text-align: center; }
.prose figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.prose figure img { border-radius: var(--radius-sm); border: 1px solid var(--border); }
.figure-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin: 18px 0; }
.figure-row figure { margin: 0; flex: 1 1 260px; max-width: 600px; }
.figure-row.narrow figure { flex: 0 1 220px; }
.references { font-size: 0.85rem; color: var(--muted); }
.references p { margin-bottom: 0.6em; text-align: left; }
