
:root {
  color-scheme: dark;
  --bg: #0e0f13;            /* page */
  --panel: #15171d;         /* cards, table frames, raised surfaces */
  --fg: #edeef0;
  --muted: #9aa0ab;
  --line: #262a33;
  --accent: #f97316;        /* orange: positive values, primary action, active nav */
  --accent-ink: #0e0f13;    /* text on orange */
  --bad: #e15b5b;           /* muted red: losses and errors ONLY */
  --warn: #d99a3d;          /* stale / suspect / ungradable */
  --accent-soft: color-mix(in oklab, var(--accent) 12%, var(--panel));
  --bad-soft: color-mix(in oklab, var(--bad) 10%, var(--panel));
  --warn-soft: color-mix(in oklab, var(--warn) 12%, var(--panel));
  --line-soft: color-mix(in oklab, var(--line) 55%, var(--panel));
  --panel-raised: color-mix(in oklab, var(--panel) 94%, var(--fg) 6%);
  --radius: 8px;
  --shadow: 0 1px 2px color-mix(in oklab, var(--accent-ink) 70%, transparent), 0 4px 14px color-mix(in oklab, var(--accent-ink) 45%, transparent);
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--fg); background: var(--bg); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }
a { color: var(--accent); }

/* ---------- Shell: sticky topbar + grouped nav ---------- */
.topbar, header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in oklab, var(--panel) 92%, var(--fg) 8%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
/* header (interim markup) is the whole bar: full-width, content padded.
   .topbar is the full-width bar; .topbar-inner is its constrained inner row. */
.topbar-inner, header {
  display: flex; align-items: center; gap: var(--sp-5); min-height: 52px; padding: 0 var(--sp-4);
}
.topbar .topbar-inner { max-width: 1240px; margin: 0 auto; }
.brand { font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; color: var(--fg); text-decoration: none; font-size: 15px; }
.brand .brand-mark {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  background: var(--accent); margin-right: 8px; transform: rotate(45deg);
}
.nav, nav { display: flex; gap: var(--sp-1); flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nav::-webkit-scrollbar, nav::-webkit-scrollbar { display: none; }
.nav a, nav a {
  color: var(--muted); text-decoration: none; font-size: 14px;
  padding: 6px 10px; border-radius: 6px; white-space: nowrap;
  border-bottom: 2px solid transparent; line-height: 1.4;
}
.nav a:hover, nav a:hover { color: var(--fg); background: var(--line-soft); }
.nav a[aria-current="page"], nav a[aria-current="page"] {
  color: var(--accent); font-weight: 600;
  border-bottom-color: var(--accent); border-radius: 6px 6px 0 0;
}
.nav .nav-group { display: flex; gap: var(--sp-1); }
.nav .nav-sep, nav .nav-sep { width: 1px; background: var(--line); margin: 4px 6px; flex: none; }
.topbar .account, header .account { display: flex; align-items: center; gap: var(--sp-3); flex: none; color: var(--muted); font-size: 13px; margin-left: auto; }
.shell, main { max-width: 1240px; margin: 0 auto; padding: var(--sp-5) var(--sp-4) 48px; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4); }
h1, .page-head h1 { font-size: 20px; margin: 0 0 var(--sp-4); letter-spacing: -0.01em; }
.page-head h1 { margin: 0; }
h2 { font-size: 15px; margin: var(--sp-5) 0 var(--sp-3); }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; align-items: center; gap: var(--sp-2); }
.freshness { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.freshness .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.freshness.stale { color: var(--warn); }
.freshness.stale .dot { background: var(--warn); }

/* ---------- Buttons & controls ---------- */
button, .button {
  font: inherit; font-size: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg);
  border-radius: var(--radius); padding: 7px 14px; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary, button[class="primary"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}
button.primary:hover, .button.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.button.quiet { border-color: transparent; color: var(--accent); padding: 7px 8px; background: none; }
.button.quiet:hover { background: var(--accent-soft); border-color: transparent; }
.link, .link-quiet { border: 0; background: none; color: var(--muted); font-size: 13.5px; padding: 0; cursor: pointer; }
.link:hover, .link-quiet:hover { color: var(--accent); }
input, select {
  font: inherit; font-size: 14px; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 10px;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--accent) 55%, transparent);
  outline-offset: 1px; border-color: var(--accent);
}
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }

/* Segmented control (View toggle) */
.segmented { position: relative; display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; padding: 7px 14px; font-size: 13.5px; color: var(--muted);
  cursor: pointer; background: var(--panel); border-right: 1px solid var(--line);
}
.segmented label:last-child span { border-right: none; }
.segmented input:checked + span { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Filters: chip bar + collapsible panel ---------- */
.filters-bar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px;
  color: var(--fg); background: var(--panel);
}
.chip b { font-weight: 600; }
.chip .x { color: var(--muted); text-decoration: none; font-size: 12px; margin-left: 2px; }
.chip .x:hover { color: var(--fg); }
.filters-toggle { margin-left: auto; }
details.filters summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--accent); padding: 7px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); user-select: none; background: var(--panel);
}
details.filters summary::-webkit-details-marker { display: none; }
details.filters summary::after { content: "\25BE"; font-size: 11px; color: var(--muted); }
details.filters[open] summary::after { content: "\25B4"; }
.filters-panel {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: var(--sp-4); margin: var(--sp-2) 0 var(--sp-4);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow);
}
.filters-panel .filter-actions {
  grid-column: 1 / -1; display: flex; align-items: center; gap: var(--sp-3);
  border-top: 1px solid var(--line-soft); padding-top: var(--sp-3); margin-top: var(--sp-1);
}
.field-tip { font-size: 12px; color: var(--muted); margin-top: 2px; }
form.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
form.filters label { display: grid; gap: .2rem; }

/* ---------- Stat area: hero card + strip ---------- */
.stat-hero { display: grid; grid-template-columns: minmax(220px, 1.1fr) 2fr; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.hero-card, .card {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: var(--sp-4) var(--sp-5); box-shadow: var(--shadow); min-width: 11rem;
}
.hero-card .label, .card .label { font-size: 13px; color: var(--muted); }
.hero-card .value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-top: 2px; }
.card .value { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.hero-card .value.pos, .pos-val { color: var(--accent); font-weight: 600; }
.hero-card .value.neg, .neg-val { color: var(--bad); font-weight: 600; }
.hero-card .value.pending { color: var(--muted); font-weight: 500; }
.hero-card .note { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); overflow: hidden;
}
.stat-strip .cell { padding: var(--sp-3) var(--sp-4); border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.stat-strip .cell .k { font-size: 12px; color: var(--muted); }
.stat-strip .cell .v { font-size: 16.5px; font-weight: 600; margin-top: 1px; font-variant-numeric: tabular-nums; }
.stat-strip .cell .v.na, .na-val { color: var(--muted); font-weight: 400; } /* unavailable is never styled like a real zero */
.cards { display: flex; gap: .8rem; flex-wrap: wrap; }
.cards .card { box-shadow: none; }

/* ---------- Sections & tables ---------- */
section { margin-bottom: var(--sp-6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.section-head h2 { margin: 0; }
.section-head .meta { font-size: 12.5px; color: var(--muted); }
.table-wrap {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  overflow: auto; max-height: 72vh; box-shadow: var(--shadow);
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th, th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel-raised); white-space: nowrap; position: sticky; top: 0;
}
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td, td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; white-space: nowrap; text-align: left; }
/* A wide text column (e.g. a combo's picks) wraps instead of stretching the table. */
td.cell-wrap { white-space: normal; min-width: 230px; max-width: 380px; }
tbody tr.main:hover, tbody tr.main.open { background: var(--accent-soft); }
td .sub-line { color: var(--muted); font-size: 12px; margin-top: 1px; white-space: normal; }
.expand-btn {
  border: none; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px;
  font-size: 11px; border-radius: 4px;
}
.expand-btn:hover { color: var(--accent); background: var(--line-soft); }
tr.detail td {
  background: color-mix(in oklab, var(--accent-soft) 55%, var(--panel));
  border-bottom: 1px solid var(--line);
}
tr.detail[hidden] { display: none; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-2) var(--sp-5); padding: var(--sp-2) 0; }
.detail-grid .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-grid .v { font-size: 13px; margin-top: 1px; white-space: normal; }
.detail-grid .v.na { color: var(--muted); }
tr.detail .pre-wrap { white-space: pre-wrap; margin: 4px 0 0; font-size: 12px; }
tr.detail .spaced { margin-top: var(--sp-3); }
summary { cursor: pointer; }

/* ---------- Pills ---------- */
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 9px;
  border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.pill.pending { color: var(--muted); background: var(--line-soft); }
.pill.won { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in oklab, var(--accent) 30%, transparent); }
.pill.lost { color: var(--bad); background: var(--bad-soft); border-color: color-mix(in oklab, var(--bad) 30%, transparent); }
.pill.push { color: var(--fg); background: var(--panel); border-color: var(--line); }
.pill.void { color: var(--muted); background: none; border-color: var(--line); }
.pill.ungradable { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in oklab, var(--warn) 35%, transparent); }
.pill.stale { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in oklab, var(--warn) 35%, transparent); }
.pill.info { color: var(--accent); background: var(--accent-soft); }
.code-chip {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--line); border-radius: 5px; padding: 0 5px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ---------- Notices, empty, loading ---------- */
.notice, .notice.info {
  border: 1px solid color-mix(in oklab, var(--accent) 25%, var(--line));
  background: var(--accent-soft); color: var(--fg);
  border-radius: var(--radius); padding: 10px 14px; font-size: 13.5px; margin-bottom: var(--sp-4);
}
.notice.warn { border-color: color-mix(in oklab, var(--warn) 35%, var(--line)); background: var(--warn-soft); }
.notice.error, .error {
  border-color: color-mix(in oklab, var(--bad) 35%, var(--line)); background: var(--bad-soft);
}
.notice b { font-weight: 600; }
.empty { text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--muted); }
.empty .empty-title { font-size: 15px; font-weight: 600; color: var(--fg); margin-bottom: 4px; }
.empty p { margin: 4px 0; font-size: 13.5px; }
.skel {
  border-radius: 5px;
  background: linear-gradient(100deg, var(--line-soft) 40%, var(--line) 50%, var(--line-soft) 60%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-row td { padding: 12px; }
.skel .bar { height: 12px; }

/* ---------- Per-page footer ---------- */
footer, footer.page-foot {
  margin-top: var(--sp-6); padding: var(--sp-4) 0 0; border-top: 1px solid var(--line-soft);
  color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
}

/* ---------- Legacy page pieces (kept until page templates migrate) ---------- */
.yes { color: var(--accent); font-weight: 700; }
.no { color: var(--muted); }
.bad { color: var(--bad); }
.inline { display: inline; }
.chart { max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.login { max-width: 26rem; margin: 3rem auto; }
.login label { margin-bottom: .7rem; }
.login input { width: 100%; }

/* ---------- Mobile <=720px ---------- */
@media (max-width: 720px) {
  .topbar-inner, header { padding: 0 var(--sp-3); gap: var(--sp-3); }
  .topbar .account .who, header .account .who { display: none; }
  .shell, main { padding: var(--sp-4) var(--sp-3) 48px; }
  h1, .page-head h1 { font-size: 18px; }
  .nav, nav { -webkit-overflow-scrolling: touch; }
  .stat-hero { grid-template-columns: 1fr; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .stat-strip .cell:nth-child(2n) { border-right: none; }
  .hero-card, .card { padding: var(--sp-4); }
  .hero-card .value { font-size: 28px; }

  /* Table rows become labeled cards: label left from data-label, value right */
  .table-cards thead { display: none; }
  .table-cards tr.main { display: block; border-bottom: 1px solid var(--line); }
  .table-cards tbody td {
    display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3);
    padding: 6px 14px; border-bottom: none; font-size: 13.5px; white-space: normal; text-align: right;
  }
  .table-cards tbody td.num { text-align: right; }
  .table-cards tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; flex: none; text-align: left;
  }
  .table-cards tbody td.cell-title {
    display: block; padding-top: 12px; font-weight: 600; font-size: 14.5px; text-align: left;
  }
  .table-cards tbody td.cell-title::before { content: none; }
  .table-cards .sub-line { margin-top: 0; }
  .table-cards tr.detail td { display: block; padding: 10px 14px 14px; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-2) var(--sp-3); }
}
