/* HKJC FF owner research dashboard — race-card ledger.
   One family (Archivo, variable weight + width): condensed width for dense numbers, wide width for race headlines.
   The memorable element is the saddle-cloth combination chip; everything else stays quiet. */

@font-face {
  font-family: "Archivo";
  src: url("/static/vendor/archivo-latin-wdth-normal.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #eef1ef;
  --surface: #fbfcfb;
  --surface-2: #f3f6f4;
  --surface-3: #e7ece9;
  --ink: #14201a;
  --ink-2: #47544d;
  --muted: #6f7c75;
  --hair: #dde3df;
  --hair-2: #c9d2cc;
  --turf: #1d5b3c;
  --turf-soft: #dcebe2;
  --focus: #1d5b3c;
  --pos: #2a78d6;
  --pos-bg: #e3eefb;
  --neg: #e34948;
  --neg-bg: #fbe6e5;
  --neutral-bg: #f0efec;
  --warn: #fab219;
  --crit: #d03b3b;
  --good: #0ca30c;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --chip-win-bg: #1d5b3c;
  --chip-win-ink: #ffffff;
  --shadow: 0 1px 0 rgba(20, 32, 26, 0.04);
  --radius: 6px;
  --font: "Archivo", system-ui, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0e1411; --surface: #151c18; --surface-2: #1b241f; --surface-3: #232e28;
    --ink: #edf3ef; --ink-2: #b7c3bc; --muted: #83918a; --hair: #26312b; --hair-2: #34413a;
    --turf: #5fb58a; --turf-soft: #1f3a2c; --focus: #7fd1a6;
    --pos: #3987e5; --pos-bg: #172a40; --neg: #e66767; --neg-bg: #3a1c1c; --neutral-bg: #383835;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --chip-win-bg: #5fb58a; --chip-win-ink: #0e1411;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0e1411; --surface: #151c18; --surface-2: #1b241f; --surface-3: #232e28;
  --ink: #edf3ef; --ink-2: #b7c3bc; --muted: #83918a; --hair: #26312b; --hair-2: #34413a;
  --turf: #5fb58a; --turf-soft: #1f3a2c; --focus: #7fd1a6;
  --pos: #3987e5; --pos-bg: #172a40; --neg: #e66767; --neg-bg: #3a1c1c; --neutral-bg: #383835;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --chip-win-bg: #5fb58a; --chip-win-ink: #0e1411;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--hair-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--turf); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; font-stretch: 88%; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--hair);
}
.brand { display: flex; flex-direction: column; line-height: 1.1; text-decoration: none; }
.brand b { font-stretch: 118%; font-weight: 720; font-size: 17px; letter-spacing: 0.01em; }
.brand span { font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 2px; }
.nav a { padding: 6px 10px; border-radius: var(--radius); text-decoration: none; color: var(--ink-2); font-weight: 520; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--turf-soft); color: var(--turf); }
.topbar .spacer { flex: 1; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); display: inline-block; }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--crit); }
.dot.busy { background: var(--pos); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .dot.busy { animation: none; } }
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--hair-2); background: var(--surface); padding: 6px 12px; border-radius: var(--radius);
  font-weight: 560; font-size: 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--turf); border-color: var(--turf); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
:root[data-theme="dark"] .btn.primary { color: #0e1411; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { width: 34px; height: 20px; appearance: none; background: var(--surface-3); border-radius: 10px; position: relative;
  cursor: pointer; border: 1px solid var(--hair-2); }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 0 0 1px var(--hair-2); transition: left 0.12s; }
.toggle input:checked { background: var(--turf); border-color: var(--turf); }
.toggle input:checked::after { left: 16px; }

/* ---------------------------------------------------------------- filter row */
.filters {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 24px; border-bottom: 1px solid var(--hair); background: var(--surface-2);
}
.filters label { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.filters input[type="date"], .filters select, .filters input[type="number"], .filters input[type="search"] {
  border: 1px solid var(--hair-2); background: var(--surface); border-radius: var(--radius); padding: 5px 8px; font-size: 14px;
}
.filters .sep { width: 1px; align-self: stretch; background: var(--hair-2); margin: 0 4px; }
.seg { display: inline-flex; border: 1px solid var(--hair-2); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 10px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--hair-2); }
.seg button[aria-pressed="true"] { background: var(--turf-soft); color: var(--turf); font-weight: 620; }

/* ---------------------------------------------------------------- layout */
main { padding: 20px 24px 60px; max-width: 1680px; margin: 0 auto; }
.block { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); margin-bottom: 18px; }
.block > header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 14px 16px 8px; }
.block > header h2 { margin: 0; font-size: 17px; font-weight: 650; }
.block > header .aside { color: var(--muted); font-size: 13px; }
.block > header .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.block .body { padding: 4px 16px 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
@media (max-width: 720px) {
  main, .topbar, .filters { padding-left: 16px; padding-right: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

/* race-card headline: wide type */
.headline { display: flex; align-items: flex-end; gap: 22px; flex-wrap: wrap; margin: 4px 0 16px; }
.headline h1 { margin: 0; font-size: 34px; line-height: 1.05; font-stretch: 118%; font-weight: 720; letter-spacing: -0.005em; }
.headline .sub { color: var(--ink-2); font-size: 15px; padding-bottom: 3px; }
.headline .navpair { margin-left: auto; display: flex; gap: 6px; }
.notice { border-left: 3px solid var(--warn); background: var(--surface); padding: 8px 12px; margin: 0 0 14px; font-size: 14px; border-radius: 0 var(--radius) var(--radius) 0; }
.notice.info { border-left-color: var(--pos); }
.notice.err { border-left-color: var(--crit); }

/* ---------------------------------------------------------------- badges & chips */
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; font-stretch: 85%; padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--hair-2); color: var(--ink-2); background: var(--surface-2); white-space: nowrap; letter-spacing: 0.01em;
}
.badge.ev-HISTORICAL_EXPLORATORY { background: var(--surface-2); }
.badge.ev-HISTORICAL_POSTHOC { border-style: dashed; }
.badge.ev-HISTORICAL_REPLAY { background: var(--surface-3); }
.badge.ev-HISTORICAL_ACTUAL { background: var(--turf-soft); border-color: var(--turf); color: var(--turf); }
.badge.ev-BRIDGE_REPLAY { background: var(--neg-bg); border-color: var(--neg); color: var(--ink); }
.badge.ev-PROSPECTIVE_SHADOW { background: var(--pos-bg); border-color: var(--pos); color: var(--ink); }
.badge.ev-DATA_QUALITY_ONLY, .badge.ev-UNRESOLVED { border-color: var(--warn); }
.badge.st-SETTLED { border-color: var(--turf); color: var(--turf); }
.badge.st-UNKNOWN { border-color: var(--warn); color: var(--ink); }
.badge.st-VOID, .badge.st-NO_FF_DIVIDEND { border-color: var(--muted); }
.badge.exposed { background: transparent; border-color: var(--pos); color: var(--pos); }
/* V1.1 stake basis */
.basis { display: inline-flex; align-items: center; gap: 6px; }
.basis .seg button { padding: 5px 9px; }
.badge.basis-x1 { background: var(--turf-soft); border-color: var(--turf); color: var(--turf); }
.badge.basis-source { background: var(--surface-3); border-color: var(--warn); color: var(--ink); }
.badge.x1na { border-color: var(--warn); background: transparent; color: var(--ink); cursor: help; }

/* strategy chip: who also bought this */
.chips { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.schip {
  font-size: 11.5px; font-weight: 640; font-stretch: 80%; padding: 0 5px; border-radius: 3px; line-height: 18px;
  background: var(--surface-3); color: var(--ink); white-space: nowrap; border-left: 3px solid var(--slot, transparent);
}
.schip.focus { background: var(--turf-soft); color: var(--turf); }

/* the saddle-cloth combination: four numbered cloths; winning horses filled */
.combo { display: inline-flex; gap: 3px; vertical-align: middle; }
.combo i {
  font-style: normal; display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 3px; border-radius: 4px 4px 7px 7px;
  border: 1.5px solid var(--ink); background: var(--surface); color: var(--ink);
  font-weight: 720; font-stretch: 78%; font-size: 13px; font-variant-numeric: tabular-nums;
}
.combo.sm i { min-width: 20px; height: 20px; font-size: 12px; border-width: 1px; }
.combo i.w { background: var(--chip-win-bg); border-color: var(--chip-win-bg); color: var(--chip-win-ink); }
.combo.win i { background: var(--chip-win-bg); border-color: var(--chip-win-bg); color: var(--chip-win-ink); }
.result-line { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.result-line .div { font-stretch: 110%; font-weight: 700; font-size: 20px; }

/* ---------------------------------------------------------------- tables */
.tablewrap { overflow: auto; max-width: 100%; }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
table.t th, table.t td { padding: 6px 10px; border-bottom: 1px solid var(--hair); text-align: left; vertical-align: middle; }
table.t th { font-weight: 600; font-size: 12.5px; color: var(--ink-2); background: var(--surface); position: sticky; top: 0; z-index: 2; white-space: nowrap; }
table.t th.sortable { cursor: pointer; }
table.t th.sortable:hover { color: var(--ink); }
table.t th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
table.t th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
table.t td.r, table.t th.r { text-align: right; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; font-stretch: 88%; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t tr.pinned td:first-child { box-shadow: inset 3px 0 0 var(--turf); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.na { color: var(--muted); font-stretch: 85%; }
.strat-cell { display: flex; flex-direction: column; line-height: 1.2; min-width: 200px; }
.strat-cell .name { font-weight: 600; }
.strat-cell .id { font-size: 11.5px; color: var(--muted); font-stretch: 85%; word-break: break-all; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; background: var(--slot, transparent); border: 1px solid var(--hair-2); }
.swatch.has { border-color: transparent; }
.inline-bar { position: relative; height: 6px; background: var(--surface-3); border-radius: 3px; min-width: 70px; }
.inline-bar b { position: absolute; top: 0; height: 6px; border-radius: 3px; }

/* ---------------------------------------------------------------- race x strategy matrix */
.matrix { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--hair); border-right: 1px solid var(--hair); }
.matrix thead th { position: sticky; top: 0; z-index: 3; background: var(--surface); padding: 6px 8px; font-weight: 640;
  font-stretch: 82%; font-size: 12.5px; min-width: 92px; vertical-align: bottom; }
.matrix thead th .full { display: block; font-weight: 450; color: var(--muted); font-size: 11px; max-width: 110px; white-space: normal; line-height: 1.15; }
.matrix tbody th { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; padding: 6px 10px;
  min-width: 190px; font-weight: 500; }
.matrix thead th:first-child { left: 0; z-index: 4; }
.matrix td { padding: 0; min-width: 92px; }
.matrix td a, .matrix td .empty { display: block; padding: 6px 8px; text-decoration: none; text-align: right; height: 100%; }
.matrix td a:hover { outline: 2px solid var(--focus); outline-offset: -2px; }
.matrix .v { font-weight: 650; font-variant-numeric: tabular-nums; font-stretch: 86%; font-size: 14px; }
.matrix .c { color: var(--ink-2); font-size: 11.5px; font-variant-numeric: tabular-nums; font-stretch: 84%; }
.matrix .hit { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); margin-right: 4px; vertical-align: 1px; }
.matrix tfoot td, .matrix tfoot th { background: var(--surface-2); font-weight: 650; position: sticky; bottom: 0; }
.cell-pos { background: color-mix(in srgb, var(--pos) calc(var(--mag, 0) * 26%), var(--surface)); }
.cell-neg { background: color-mix(in srgb, var(--neg) calc(var(--mag, 0) * 26%), var(--surface)); }
.cell-zero { background: var(--surface); }
.cell-unk { background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 5px, var(--surface-2) 5px, var(--surface-2) 7px); }

/* ---------------------------------------------------------------- stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0; background: var(--surface);
  border: 1px solid var(--hair); border-radius: var(--radius); overflow: hidden; }
.tile { background: var(--surface); padding: 10px 12px; box-shadow: inset -1px -1px 0 var(--hair); }
.tile .l { font-size: 12.5px; color: var(--ink-2); }
.tile .v { font-size: 22px; font-weight: 650; font-stretch: 95%; }
.tile .v.hero { font-size: 34px; }
.tile .s { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- cards per strategy (meeting summary) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 10px; }
.nowrap { white-space: nowrap; }
.card { border: 1px solid var(--hair); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); border-top: 3px solid var(--slot, var(--hair)); }
.card .t1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .t1 b { font-size: 14px; }
.card .big { font-size: 24px; font-weight: 680; font-stretch: 92%; margin: 2px 0; }
.card dl { display: grid; grid-template-columns: auto auto auto auto; gap: 1px 8px; margin: 6px 0 0; font-size: 12px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-stretch: 88%; }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: var(--hair); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; font-stretch: 88%; }
.chart .zero { stroke: var(--hair-2); stroke-width: 1; }
.chart .label { fill: var(--ink-2); font-size: 11.5px; font-family: var(--font); font-stretch: 85%; }
.chart .xhair { stroke: var(--ink-2); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; cursor: default; }
.legend .key { width: 14px; height: 2px; background: var(--c); border-radius: 1px; }
.legend .key.box { height: 10px; width: 10px; border-radius: 2px; }
.tooltip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--surface); border: 1px solid var(--hair-2);
  border-radius: var(--radius); padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); min-width: 160px;
}
.tooltip .h { color: var(--muted); margin-bottom: 4px; }
.tooltip .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .row .k { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .row .k i { width: 12px; height: 2px; background: var(--c); display: inline-block; }
.tooltip .row b { font-variant-numeric: tabular-nums; font-stretch: 88%; }

/* ---------------------------------------------------------------- drawers / dialogs */
dialog { border: 1px solid var(--hair-2); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(920px, 96vw); max-height: 88vh; }
dialog::backdrop { background: rgba(10, 16, 13, 0.35); }
dialog > header { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--hair); position: sticky; top: 0; background: var(--surface); z-index: 2; }
dialog > header h2 { margin: 0; font-size: 18px; }
dialog > header .right { margin-left: auto; display: flex; gap: 8px; }
dialog .dbody { padding: 12px 18px 18px; overflow: auto; max-height: calc(88vh - 60px); }
.picker-group h3 { font-size: 13.5px; margin: 14px 0 6px; color: var(--ink-2); font-weight: 650; }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2px 14px; }
.picker-item { display: flex; gap: 8px; align-items: flex-start; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.picker-item:hover { background: var(--surface-2); }
.picker-item input { margin-top: 3px; }
.picker-item .nm { font-weight: 560; font-size: 13.5px; }
.picker-item .id { font-size: 11.5px; color: var(--muted); font-stretch: 85%; word-break: break-all; }
.kv { display: grid; grid-template-columns: minmax(150px, max-content) 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; word-break: break-word; }
.detail-row td { background: var(--surface-2); }
.detail-box { padding: 8px 4px 12px; }
.expander { cursor: pointer; border: 0; background: transparent; padding: 2px 6px; color: var(--ink-2); font-size: 14px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 8px 0 0; font-size: 13px; }
.compare3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--hair); border: 1px solid var(--hair); border-radius: var(--radius); overflow: hidden; }
.compare3 > div { background: var(--surface); padding: 12px; }
.compare3 h3 { margin: 0 0 6px; font-size: 14px; }
@media (max-width: 720px) { .compare3 { grid-template-columns: 1fr; } }
.loading { opacity: 0.55; transition: opacity 0.1s; }
.empty-state { padding: 26px 16px; color: var(--ink-2); }
.foot { color: var(--muted); font-size: 12px; padding: 18px 24px 30px; text-align: left; max-width: 1680px; margin: 0 auto; }
code, .mono-id { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
