/* KK-OZEC web app. Tokens first; dark mode follows the OS. Chart series colours: dataviz reference palette
   (categorical slots 1-8, light/dark steps), status colours separate from series colours. */
:root {
  color-scheme: light;
  --bg: #f4f5f3; --surface: #fcfcfb; --surface-2: #eef0ec; --line: #d9dcd5;
  --text: #0b0b0b; --text-2: #52514e; --muted: #6f6e69;
  --accent: #1f6fb2; --accent-text: #ffffff; --focus: #2a78d6;
  --ok: #1a7f37; --warn: #9a6700; --bad: #c62828; --ok-bg: #e6f4ea; --warn-bg: #fff4d6; --bad-bg: #fdecea;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #34342f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f;
    --accent: #3987e5; --accent-text: #0b0b0b; --focus: #3987e5;
    --ok: #4cc06a; --warn: #e0b040; --bad: #ef6b6b; --ok-bg: #16301e; --warn-bg: #33290d; --bad-bg: #3a1716;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* header */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .04em; color: var(--text); text-decoration: none; }
.brand.big { font-size: 1.35rem; }
.brand { display: inline-flex; flex-direction: column; line-height: 1.15; }
.brand .version { font-size: .7rem; font-weight: 400; letter-spacing: 0; color: var(--muted); }
.brand.big .version { font-size: .75rem; }
/* versions of server, gateway and stations, on every signed-in page (the web's "settings", lead 2026-11-27) */
footer.versions { display: flex; flex-wrap: wrap; gap: .25rem 1rem; justify-content: center; padding: 1rem 16px 1.5rem;
  font-size: .75rem; color: var(--muted); }

/* parameter chips with their (i): what the measurement is */
.chip-wrap { display: inline-flex; align-items: center; gap: 2px; }
.info-btn { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  color: var(--text-2); font: italic 700 .75rem/1 Georgia, "Times New Roman", serif; cursor: pointer; padding: 0;
  display: inline-grid; place-items: center; }
.info-btn:hover { background: var(--surface-2); color: var(--text); }
.info-dlg { max-width: 560px; }
.info-dlg h2 { margin-bottom: .5rem; }
.info-dlg p { margin: 0 0 .7rem; line-height: 1.5; }
.nav { display: flex; gap: 4px; }
.nav a, .tabs a { padding: 6px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; }
.nav a[aria-current], .tabs a[aria-current] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.langs a { padding: 2px 6px; border-radius: 6px; color: var(--text-2); text-decoration: none; font-size: .9rem; }
.langs a[aria-current] { background: var(--surface-2); color: var(--text); font-weight: 600; }
form.inline { display: inline; margin: 0; }

/* buttons, chips */
.btn, button.primary, .btn.primary { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; min-height: 36px; }
.btn:hover { background: var(--surface-2); }
.primary, button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 3px 8px; min-height: 28px; font-size: .85rem; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.btn[aria-pressed="true"] { background: var(--surface-2); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2); cursor: pointer; font: inherit; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }

/* analytics */
.controls, .advanced { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row .label { color: var(--muted); font-size: .85rem; min-width: 7.5em; }
.timeline { justify-content: flex-start; }
.stepper { display: flex; align-items: center; gap: 6px; }
.range-label { min-width: 13em; text-align: center; font-variant-numeric: tabular-nums; color: var(--text); }
.custom { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#export-open { margin-left: auto; }
.charts { display: grid; gap: 12px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 4px; }
.chart-card h3 { margin: 0; font-size: .95rem; color: var(--text); }
.chart-card h3 .unit { color: var(--muted); font-weight: 400; }
.chart-card .chart-note { margin: .15rem 0 0; font-size: .78rem; color: var(--muted); }
.chart { width: 100%; height: 240px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--text-2); margin: 4px 0; }
.legend .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.legend .sw.dashed { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); }
table.stats, table.list { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.stats th, table.stats td, table.list th, table.list td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.stats td.n { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 460px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
fieldset { border: 1px solid var(--line); border-radius: 8px; }
.summary { color: var(--text-2); }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* notes, status */
.note { margin: .5rem 0; color: var(--text-2); }
.note.ok { color: var(--ok); } .note.err { color: var(--bad); } .note.warn { color: var(--warn); background: var(--warn-bg); padding: 6px 8px; border-radius: 6px; }
ul.note { padding-left: 1.2em; }
.st { display: inline-flex; gap: 4px; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: .85rem; font-weight: 600; }
.st-ok { color: var(--ok); background: var(--ok-bg); } .st-warn, .st-wait { color: var(--warn); background: var(--warn-bg); }
.st-bad, .st-off { color: var(--bad); background: var(--bad-bg); }
.st-ign { color: var(--muted); background: var(--surface-2); font-weight: 400; }   /* an ignored warning: still shown, greyed */
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; font-size: .8rem; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
td.actions { white-space: nowrap; }
td.actions form { margin-right: 4px; }
label.check { display: inline-flex; align-items: center; gap: 6px; }
label.check.small { font-size: .8rem; color: var(--text-2); }
th .unit { color: var(--muted); font-weight: 400; }
table.list td.n { font-variant-numeric: tabular-nums; }

/* admin configuration (ADM-4/5) */
.cfg-card h2 { margin-bottom: .2rem; }
.cfg-card .hint { margin-bottom: .5rem; }
table.cfg input, table.cfg select { font: inherit; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); width: 9em; max-width: 100%; }
table.cfg tr.bad td { background: var(--bad-bg); }
table.cfg td.hint { white-space: nowrap; }
.cfg-card .actions { margin-top: 10px; }

/* login and account pages: the lead's splash fills the screen, the card sits on it (AUTH-2) */
body.auth { background: #0d1a26; }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; }
.splash { position: fixed; inset: 0; background: url("/static/login-splash.jpg") center / cover no-repeat; }
.auth-card { position: relative; width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 22px 22px 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.auth-head { display: flex; align-items: center; justify-content: space-between; }
.tagline { color: var(--text-2); margin: .2rem 0 1rem; font-size: .9rem; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: .9rem; color: var(--text-2); }
.form label.check { display: flex; gap: 8px; align-items: center; }
.form label.check input { width: auto; }
.form input, .form textarea { font: inherit; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); width: 100%; }
.pw { display: flex; gap: 8px; align-items: center; }
.links { font-size: .9rem; margin-top: 12px; }
.hint { font-size: .85rem; color: var(--muted); margin: 0; }
.rules { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; font-size: .85rem; color: var(--muted); }
.rules li::before { content: "○ "; }
.rules li.met { color: var(--ok); } .rules li.met::before { content: "✓ "; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

@media (max-width: 640px) {
  .row .label { min-width: 100%; }
  #export-open { margin-left: 0; }
  .range-label { min-width: 0; flex: 1; }
  .chart { height: 200px; }
  .top { gap: 8px; }
  /* settings: one block per setting, the column names beside the values */
  table.cfg thead { display: none; }
  table.cfg tr { display: grid; grid-template-columns: 1fr; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.cfg td { border: 0; padding: 2px 0; text-align: left; white-space: normal; }
  table.cfg td:first-child { font-weight: 600; }
  table.cfg td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  table.cfg td.hint { white-space: normal; }
}

/* admin firmware (docs/09 §5) */
.fw-mon { border-top: 1px solid var(--line); padding: 10px 0; }
.fw-mon h3 { margin: 0 0 6px; font-size: .95rem; }
.fw-mon .row { margin: 6px 0; }

/* admin calibration (CAL-*) */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 14px; margin: 8px 0; }
.form-grid label { display: grid; gap: 4px; font-size: .9rem; color: var(--text-2); }
.form-grid label.check { display: flex; gap: 8px; align-items: center; grid-column: 1 / -1; }
.form-grid input, .form-grid select { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); width: 100%; min-width: 0; }
.form-grid label.check input { width: auto; }
details.confirm summary { list-style: none; cursor: pointer; display: inline-block; }
details.confirm summary::-webkit-details-marker { display: none; }
details.confirm[open] form { margin-top: 6px; }
.cal-chart { width: 100%; height: 320px; }
.cal-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--text-2); } dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
#timezone .form-grid { max-width: 420px; }

/* external data API (server/API-PLAN.md): registration key page and admin tab */
code.apikey { display: block; word-break: break-all; padding: 10px; background: var(--surface-2); border-radius: 8px;
  font-size: .9rem; user-select: all; }
.subnav { margin-bottom: 12px; }
table.kv th { text-align: left; width: 11em; color: var(--muted); font-weight: 400; vertical-align: top; }
td.pre { white-space: pre-wrap; }
.spark { width: 100%; max-width: 520px; height: 48px; display: block; margin: 4px 0 10px; }
.spark rect { fill: var(--accent); }
.station-map { max-width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); display: block; }
/* ADM-8: the interactive map on Admin -> Stations (stations.js); large enough to drag on comfortably */
.station-edit-map { width: 100%; height: clamp(380px, 70vh, 720px); margin: 10px 0 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); z-index: 0; }
.stn-point { background: #1f6fb2; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 1px 4px rgba(0,0,0,.4); cursor: move; }
.stn-handle { background: #fff; border: 3px solid #1f6fb2; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: ew-resize; }
.station-edit-map .leaflet-control-attribution, .station-edit-map .leaflet-control-scale-line { color: #282828; }
