:root {
  --bg: #ffffff;
  --fg: #131722;
  --muted: #5d6475;
  --line: #e0e3eb;
  --panel: #f8f9fd;
  --btn: #eef0f6;
  --btn-on: #2962ff;
  --btn-on-fg: #ffffff;
  --paper: #ff9800;
  --up: #26a69a;
  --down: #ef5350;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131722;
    --fg: #d1d4dc;
    --muted: #8a91a5;
    --line: #2a2e39;
    --panel: #1e222d;
    --btn: #2a2e39;
    --btn-on: #2962ff;
    --btn-on-fg: #ffffff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131722;
  --fg: #d1d4dc;
  --muted: #8a91a5;
  --line: #2a2e39;
  --panel: #1e222d;
  --btn: #2a2e39;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
header { padding: 6px 10px 2px; border-bottom: 1px solid var(--line); flex: none; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.brand { font-size: 15px; }
.spacer { flex: 1; }
.badge { background: var(--paper); color: #000; border-radius: 4px; padding: 0 6px; font-size: 11px; font-weight: 700; letter-spacing: .5px; }
.live { color: var(--muted); font-size: 11px; }
.live.on { color: var(--up); }
button, select {
  background: var(--btn); color: var(--fg); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 9px; font: inherit; font-size: 13px; cursor: pointer; min-height: 28px;
}
button.on { background: var(--btn-on); color: var(--btn-on-fg); border-color: var(--btn-on); }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.chk { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; user-select: none; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip.off { opacity: .45; }
.chip .num { color: var(--muted); }
.legend { font-size: 12px; color: var(--muted); padding: 3px 10px; flex: none; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend b { color: var(--fg); font-weight: 600; }
.legend .warn { color: var(--paper); }
main#chart { flex: 1; min-height: 220px; position: relative; }
.eqbar { flex: none; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 3px 10px 6px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.eqbar .k { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; }
.eqbar .sw { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.eqbar .sw.dash { border-top-style: dashed; }
.eqbar .sw.dot { border-top-style: dotted; }
.msg { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; max-width: 90vw; box-shadow: var(--shadow); text-align: center; z-index: 5; }
.panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(440px, 100vw); background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); padding: 14px 16px 24px; overflow-y: auto; z-index: 10;
}
.panel h2 { margin: 0 0 6px; font-size: 17px; }
.panel h3 { margin: 14px 0 4px; font-size: 14px; }
.panel p { margin: 6px 0; }
.panel ul { padding-left: 18px; margin: 4px 0; }
.panel a { color: var(--btn-on); }
.panel .close { position: absolute; right: 10px; top: 8px; font-size: 18px; line-height: 1; padding: 2px 8px; }
.panel .kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; }
.panel .kv span:nth-child(odd) { color: var(--muted); }
.panel .dec { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; margin: 6px 0; cursor: pointer; }
.panel .dec:hover { border-color: var(--btn-on); }
.panel .src { font-size: 12px; color: var(--muted); }
.panel input[type="url"], .panel input[type="text"] { width: 100%; padding: 6px; font: inherit; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; }
@media (max-width: 520px) {
  body { font-size: 13px; }
  .brand { font-size: 14px; }
  button, select { padding: 3px 7px; font-size: 12px; }
  .legend, .eqbar { padding-left: 6px; padding-right: 6px; }
}
