/* Layout: a top bar with section tabs over one scrolling work area; panels open beside lists on wide
   screens and stack under them on phones. Neutrals lean slightly toward the indigo accent of the iOS app. */
:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --line: #dde1ea;
  --fg: #171a23;
  --muted: #5d6475;
  --accent: #4f64a8;
  --accent-fg: #ffffff;
  --good: #1f8a52;
  --info: #2f6fd1;
  --teal: #11808a;
  --warn: #b86a08;
  --bad: #c2362f;
  --neutral: #7a8193;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a22; --surface-2: #1f2330; --line: #2b3040;
    --fg: #e8eaf1; --muted: #9aa1b2; --accent: #8a9de0; --accent-fg: #0f1117;
    --good: #4cc483; --info: #6aa5ff; --teal: #3fc1c9; --warn: #f0a23b; --bad: #ff6b62; --neutral: #8d94a6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a22; --surface-2: #1f2330; --line: #2b3040;
  --fg: #e8eaf1; --muted: #9aa1b2; --accent: #8a9de0; --accent-fg: #0f1117;
  --good: #4cc483; --info: #6aa5ff; --teal: #3fc1c9; --warn: #f0a23b; --bad: #ff6b62; --neutral: #8d94a6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
a { color: var(--accent); }
code, pre, .mono { font-family: var(--font-mono); font-size: 0.85em; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { font-variant-numeric: tabular-nums; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
textarea { width: 100%; font-family: var(--font-mono); font-size: 0.85rem; min-height: 5.5em; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost { background: transparent; }

/* Brand */
.brand { display: flex; align-items: center; gap: 8px; font: 700 1.05rem var(--font-display); letter-spacing: -0.01em; }
.brand-large { font-size: 1.5rem; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  /* Four bars of a bar chart, drawn with gradients so the mark follows the theme accent. */
  background:
    linear-gradient(var(--accent-fg), var(--accent-fg)) 22% 78% / 12% 45% no-repeat,
    linear-gradient(var(--accent-fg), var(--accent-fg)) 41% 78% / 12% 65% no-repeat,
    linear-gradient(var(--accent-fg), var(--accent-fg)) 60% 78% / 12% 30% no-repeat,
    linear-gradient(var(--accent-fg), var(--accent-fg)) 79% 78% / 12% 52% no-repeat,
    var(--accent);
}
.brand-large .brand-mark { width: 30px; height: 30px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%);
  display: grid; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px;
}
.login-card label { font-weight: 600; font-size: 0.85rem; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400 !important; color: var(--muted); }

/* Shell */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; }
.tabs a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 7px; white-space: nowrap; font-weight: 500;
}
.tabs a[aria-current="page"] { color: var(--fg); background: var(--surface-2); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: var(--surface); color: var(--muted); padding: 6px 10px; }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--fg); font-weight: 600; }
.segmented button[data-env="sandbox"][aria-pressed="true"] { color: var(--warn); }

.view { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; display: grid; gap: 24px; outline: none; }
.view-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; }
.view-head p { margin: 4px 0 0; }

/* Panels and grids */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; align-content: start; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.stat .label { color: var(--muted); font-size: 0.8rem; }
.stat .value { font: 600 1.6rem/1.2 var(--font-display); font-variant-numeric: tabular-nums; }
.section-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
td.right, th.right { text-align: right; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover, tbody tr.selected { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 13%, transparent); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--tone); }
.tone-good { --tone: var(--good); } .tone-info { --tone: var(--info); } .tone-teal { --tone: var(--teal); }
.tone-warn { --tone: var(--warn); } .tone-bad { --tone: var(--bad); } .tone-neutral { --tone: var(--neutral); }

/* Key/value */
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
pre.json { background: var(--surface-2); border-radius: 8px; padding: 12px; overflow: auto; max-height: 420px; margin: 0; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font: 11px var(--font-ui); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--tone); display: inline-block; }

/* Forms */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-weight: 600; font-size: 0.82rem; }
.field small { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row > .grow { flex: 1 1 160px; }
.variant-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px minmax(0, 1.4fr) auto; gap: 8px; align-items: center; }
@media (max-width: 560px) { .variant-row { grid-template-columns: minmax(0, 1fr) 70px; } }
.confirm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--bad) 10%, transparent); }

/* Switch */
.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-weight: 600; z-index: 20;
}
.sig { font-weight: 700; }
.sig.up { color: var(--good); } .sig.down { color: var(--bad); }

@media (max-width: 700px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .view { padding: 18px 16px 56px; }
  .tabs { order: 3; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
