/* Layout: instrument-panel app — fixed control column on the left, charts stacked on the right; one column on phones. */
:root {
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --ink: #121412;
  --ink-2: #4f514d;
  --muted: #777972;
  --line: #deded9;
  --grid: #e9e9e5;
  --chip: #ecece8;
  --focus: #2a78d6;
  --good: #1b7f3a;
  --bad: #c2362f;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --font-display: "IBM Plex Sans Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111211; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8e8d85;
    --line: #2e2e2b; --grid: #262624; --chip: #252523; --focus: #6da7ec; --good: #4cc26f; --bad: #ef7a73;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111211; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8e8d85;
  --line: #2e2e2b; --grid: #262624; --chip: #252523; --focus: #6da7ec; --good: #4cc26f; --bad: #ef7a73;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 14px; line-height: 1.45;
}
a { color: inherit; text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; }

/* Header */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 900; background: var(--surface); border-bottom: 1px solid var(--line); }
.bar-in {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--ink);
  background: radial-gradient(circle, var(--ink) 0 3px, transparent 3.5px), conic-gradient(from 0deg, transparent 0 75%, color-mix(in srgb, var(--ink) 22%, transparent) 75% 100%);
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: 0.01em; }
.bar-point { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.mode-badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2);
}
.mode-badge.preview { border-color: var(--s4); color: var(--ink); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: var(--surface); }

.notice {
  background: color-mix(in srgb, var(--s4) 16%, var(--surface)); border-bottom: 1px solid var(--line);
  padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-size: 13px;
}

/* Layout */
.layout {
  display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start;
  padding-block: 16px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 1600px; margin: 0 auto;
}
.side {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 64px);
  max-height: calc(100vh - 80px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  display: flex; flex-direction: column;
}
.block { padding: 14px 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.block:last-child { border-bottom: 0; }
.block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; font-weight: 600; color: var(--ink-2); }
.map { height: 260px; border-radius: 4px; border: 1px solid var(--line); background: var(--chip); z-index: 0; }
.row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.row > * { min-width: 0; }
input[type="search"], input[type="number"], input[type="datetime-local"], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; min-width: 0;
}
input[type="search"] { flex: 1; }
.coords label { display: flex; flex-direction: column; font-size: 12px; color: var(--ink-2); flex: 1; }
.coords input { width: 100%; font-family: var(--font-mono); }
.btn {
  border: 1px solid var(--line); background: var(--chip); border-radius: 4px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled, select:disabled, input:disabled { opacity: 0.5; cursor: not-allowed; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); flex: 1; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; flex: none; }
.nudge { display: flex; gap: 6px; flex-wrap: wrap; }
.results { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 4px; }
.results li button { width: 100%; text-align: left; background: transparent; border: 0; padding: 6px 8px; cursor: pointer; }
.results li + li { border-top: 1px solid var(--line); }
.results li button:hover { background: var(--chip); }
.results small { color: var(--muted); }

.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.checks label { display: flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 7px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 12.5px; color: var(--ink-2);
}
.chip .sw { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.chip[aria-pressed="true"] { background: var(--chip); color: var(--ink); border-color: var(--muted); }
.chip[aria-pressed="true"] .sw { background: currentColor; }
.chip .sw { color: var(--c); }
.chip small { color: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.sources p { margin: 0; font-size: 12px; color: var(--ink-2); }

/* Main */
.main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.status { font-size: 12.5px; color: var(--ink-2); font-family: var(--font-mono); min-height: 1.4em; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: transparent; padding: 8px 12px; cursor: pointer; font-family: var(--font-display); font-weight: 500; font-size: 15px; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.stat { background: var(--surface); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat .v { font-family: var(--font-display); font-weight: 600; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--ink-2); font-family: var(--font-mono); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel-h { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: start; }
.panel-h > div:first-child { min-width: 0; flex: 1 1 360px; }
.panel h2 { font-size: 19px; font-weight: 600; }
.cap { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; max-width: 75ch; }
.cap.note { color: var(--ink); border-left: 3px solid var(--s4); padding-left: 8px; }
.verify-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; border-left-color: var(--ink); max-width: none; }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.num { width: 90px; font-family: var(--font-mono); }
.unit { font-size: 12.5px; color: var(--ink-2); }
.chart { width: 100%; height: 340px; min-width: 0; }
.chart.tall { height: 400px; }
.pair { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 12px; }

.table-wrap { overflow-x: auto; }
.tbl { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tbl th { font-weight: 500; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td { font-family: var(--font-mono); }
.tbl td:first-child { font-family: var(--font-body); }
.tbl .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.up { color: var(--bad); } .down { color: var(--focus); }
.foot { color: var(--muted); font-size: 12px; }
.foot p { margin: 0; max-width: 90ch; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 1000;
  background: var(--ink); color: var(--surface); padding: 8px 14px; border-radius: var(--r); font-size: 13px; max-width: calc(100% - 32px);
}

.leaflet-container { font: inherit; background: var(--chip); }
.leaflet-control-layers { color: #121412; font-size: 12.5px; }
.leaflet-control-attribution { font-size: 10px; max-width: 100%; white-space: normal; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; max-height: none; order: 2; }
  .main { order: 1; }
  .pair { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .bar-right { margin-left: 0; }
  .chart.tall { height: 360px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
