:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --field: #ffffff;
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --banner: #eef4fc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --grid: #2c2c2a;
    --ring: rgba(255, 255, 255, 0.10); --accent: #3987e5; --field: #111110; --banner: #14233a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --grid: #2c2c2a;
  --ring: rgba(255, 255, 255, 0.10); --accent: #3987e5; --field: #111110; --banner: #14233a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

/* Header: one compact row plus a scrollable section nav */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--page);
  border-bottom: 1px solid var(--grid);
  padding: calc(8px + env(safe-area-inset-top, 0px)) 20px 0;
}
.bar { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 650; white-space: nowrap; }
.asof { color: var(--ink2); font-size: 13px; }
.actions { display: flex; gap: 8px; flex: none; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 6px 0 8px; margin: 0 -4px; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--ink2); text-decoration: none; font-size: 13px; white-space: nowrap;
  padding: 4px 8px; border-radius: 6px;
}
.nav a:hover { color: var(--ink); background: var(--ring); }

.btn {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--ring); border-radius: 7px; padding: 6px 12px; cursor: pointer; min-height: 34px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:disabled { opacity: 0.6; cursor: progress; }
.btn.icon { width: 34px; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { max-width: 1400px; margin: 0 auto; padding: 10px 20px 60px; }
section { margin-top: 30px; scroll-margin-top: 100px; }
h2 { font-size: 18px; margin: 0 0 8px; text-wrap: balance; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
h3.sub { margin: 18px 0 8px; }
.note { color: var(--ink2); font-size: 12.5px; margin: 6px 0 10px; max-width: 80ch; }
.status { color: var(--ink2); font-size: 12.5px; margin: 0; min-height: 1.4em; }
.banner {
  background: var(--banner); border: 1px solid var(--ring); border-radius: 8px;
  padding: 8px 12px; margin: 10px 0 0; font-size: 13px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 14px; }
.minis { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 10px;
  padding: 14px; min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.chart { width: 100%; min-height: 200px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 4px 0 14px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 10px 12px; }
.tl { color: var(--ink2); font-size: 12px; }
.tv { font-size: 22px; font-weight: 600; margin: 2px 0; }
.ts { color: var(--ink2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chip { font-size: 12px; margin-top: 6px; color: var(--ink2); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.good .dot { background: var(--good); }
.chip.warn .dot { background: var(--warn); }
.chip.crit .dot { background: var(--crit); }

ul.talk { margin: 4px 0 0; padding-left: 18px; }
ul.talk li { margin: 5px 0; max-width: 95ch; }

.tbl { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 12.5px; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
thead th { color: var(--ink2); font-weight: 600; }
thead th:first-child, tbody th, tfoot th { text-align: left; }
tbody th { font-weight: 500; }
tfoot th, tfoot td { font-weight: 600; border-bottom: 0; }

/* Book setup form */
.form { display: grid; grid-template-columns: 1fr 120px; gap: 10px 12px; align-items: center; }
.form label { color: var(--ink2); font-size: 13px; }
input[type=number], input[type=text], textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--field);
  border: 1px solid var(--ring); border-radius: 6px; padding: 6px 8px; width: 100%;
  font-variant-numeric: tabular-nums;
}
table.krd input { width: 88px; text-align: right; }
textarea { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; resize: vertical; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.msg { color: var(--ink2); font-size: 12.5px; }

footer { color: var(--ink2); font-size: 12px; margin-top: 40px; max-width: 110ch; }

@media (max-width: 640px) {
  .top { padding-left: 16px; padding-right: 16px; }
  .brand { display: block; }
  .brand h1 { font-size: 15px; }
  .asof { font-size: 12px; }
  main { padding: 8px 16px 40px; }
  .grid, .minis { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tv { font-size: 19px; }
  .card { padding: 12px; }
  section { scroll-margin-top: 110px; }
  .form { grid-template-columns: 1fr 100px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
html { scroll-behavior: smooth; }
