@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Operator theme: warm neutrals, flat green brand, mono numerics ──────── */
:root {
  --page: #FAF8F4; --card: #FFFEFB; --container: #F2EDE5; --container-high: #E8E2D8;
  --hover: #F2EDE5; --border: #DDD5C8; --border-ghost: rgba(200,192,178,.30);
  /* --muted carries real content (timestamps, headers, empty states) at 11-12px,
     so it must clear WCAG AA 4.5:1 on --page — #9A9186 was ~2.9:1 */
  --ink: #1A1712; --text-2: #6E665C; --muted: #7D7466;
  --brand: #179A5F; --brand-active: #22B573; --brand-hover: #0F7347; --brand-50: #EDFAF4;
  --green: #179A5F; --red: #E0444A; --orange: #DD8A0B; --purple: #8E4EC6; --gray: #9A9186;
  --blue: #4C90D6;
  --shadow: 0 1px 0 rgba(26,23,18,.04), 0 4px 16px -4px rgba(26,23,18,.06);
  --navbar-bg: rgba(250,248,244,.85);
}
[data-theme="dark"] {
  --page: #0B0F1C; --card: #131A2C; --container: #1B2540; --container-high: #243153;
  --hover: #1B2540; --border: rgba(255,255,255,.10); --border-ghost: rgba(255,255,255,.07);
  --ink: #E9ECF3; --text-2: #A9B0C0; --muted: #7E8699;
  --brand: #22B573; --brand-active: #2CCB82; --brand-hover: #34d399; --brand-50: rgba(34,181,115,.12);
  --green: #34d399; --red: #f87171; --orange: #fbbf24; --purple: #c084fc; --gray: #8b93a3;
  --blue: #60a5fa;
  --shadow: none;
  --navbar-bg: rgba(11,15,28,.80);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.5 'Plus Jakarta Sans', system-ui, sans-serif;
  letter-spacing: -0.01em; font-feature-settings: 'ss01', 'cv11';
}
h1, h2, h3 { letter-spacing: -0.02em; }
.mono, .ev, .price, .bal, .bonus, .stats, #pnl, .fig, .jump, .count {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
a { color: var(--brand); }
*:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(23,154,95,.28); border-color: var(--brand-active); }

/* ── App shell ──────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; }

.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--card);
  border-right: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; gap: 18px;
}
.sidebar .brand {
  font-weight: 700; font-size: 18px; color: var(--ink); letter-spacing: -0.03em;
  display: flex; align-items: center; gap: 8px; padding: 2px 6px;
}
.sidebar .brand::before {
  content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--brand-active);
}
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 8px 6px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 8px; text-decoration: none;
  color: var(--text-2); font-weight: 500; padding: 8px 10px; border-radius: 8px;
  border-left: 3px solid transparent; transition: background .12s;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--hover); color: var(--ink); font-weight: 600; border-left-color: var(--brand-active); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 0 6px; }

.navbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 9px 20px; background: var(--navbar-bg); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.user { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 500; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.theme-toggle { background: none; border: 1px solid var(--border); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; color: var(--text-2); font-size: 15px; }
.theme-toggle:hover { background: var(--hover); }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: var(--text-2); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }
button.link:hover { color: var(--ink); }

.mode { font-size: 11px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600; color: var(--text-2); }
.mode-live { color: var(--red); border-color: var(--red); }
.mode-demo { color: var(--orange); border-color: var(--orange); }

.content { padding: 16px 20px; }

/* ── Cards / panes ──────────────────────────────────────────────────────── */
.pane, .controls {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow);
}
.pane { padding: 14px 16px; }
.pane-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pane h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 12px; }
.status { color: var(--text-2); font-size: 13px; font-weight: 500; }
.stats { font-size: 12px; color: var(--muted); }

.btn {
  background: var(--brand); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 18px; font: inherit; font-weight: 500; letter-spacing: -.005em;
  cursor: pointer; transition: background .12s, transform .12s;
}
.btn:hover { background: var(--brand-hover); }
.btn:active { transform: translateY(.5px); }
.btn.danger { background: var(--red); }
.btn[disabled] { opacity: .5; cursor: default; }

.pill { font-size: 11px; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--border);
  font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--text-2); }
.pill.amber { color: var(--orange); border-color: var(--orange); background: rgba(221,138,11,.06); }
.pill.red { color: var(--red); border-color: var(--red); background: rgba(224,68,74,.06); }

/* segmented filter */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.seg button { background: transparent; border: 0; border-right: 1px solid var(--border); padding: 4px 12px;
  font: inherit; font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--brand); color: #fff; font-weight: 600; }

/* ── Dashboard 3-pane ───────────────────────────────────────────────────── */
/* min-width:0 on the panes lets grid items shrink below their content's
   min-width — without it the fixed accounts column blew the grid out and the
   page scrolled horizontally between ~980 and 1200px */
/* races is the primary feed — give it the widest fr; accounts is capped, history
   takes what's left. min-width:0 lets the columns shrink instead of overflowing. */
.layout3 { display: grid; grid-template-columns: minmax(220px, 280px) 1.5fr 1fr; gap: 12px; }
.layout3 > .pane { min-width: 0; }
.scroll { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 200px);
  overflow-y: auto; overflow-x: hidden; }
/* the 3-pane console needs room — below this each pane stacks full-width, where
   runner names + numbers all fit without truncation (rather than a 3-way squeeze);
   stacked panes flow with the page instead of each holding its own scroll box */
@media (max-width: 1200px) {
  .layout3 { grid-template-columns: 1fr; }
  .scroll { max-height: none; }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  /* sidebar becomes a compact horizontal strip — the stacked vertical nav used
     to consume the entire first screen on a phone */
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: 10px; padding: 10px 14px;
    border-right: 0; border-bottom: 1px solid var(--border); }
  .nav-group { display: none; }
  .side-nav { flex-direction: row; gap: 2px; flex-wrap: wrap; }
  .nav-item { padding: 6px 10px; border-left: 0; border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0; }
  .nav-item.active { border-left: 0; border-bottom-color: var(--brand-active); }
  .side-foot { margin-top: 0; margin-left: auto; }
  .scroll { max-height: none; }
}

/* accounts — proper columns: Account | Token | Cash | Bonus */
.acct-head, .acct, .acct-total {
  display: grid; grid-template-columns: 1fr 50px 66px 52px; gap: 8px; align-items: baseline;
}
.acct-head { padding: 2px 8px 5px; font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border-ghost); }
.acct-group { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 600; padding: 8px 8px 3px; }
.acct-group .book-ico { display: block; height: 18px; width: 18px; border-radius: 4px; }
.acct { padding: 4px 8px; border-radius: 6px; position: relative; }
.acct:hover { background: var(--hover); }
.acct .name { font-weight: 500; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; font-size: 12px; }
.acct .tok { color: var(--green); }
.acct .bal { color: var(--ink); font-weight: 600; }
.acct .bonus { color: var(--orange); }
.dash { color: var(--muted); }
.acct-total { padding: 6px 8px 2px; margin-top: 3px; border-top: 1px solid var(--border-ghost); }
.acct-total > span:first-child { font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; }
.acct-total .bal { color: var(--ink); font-weight: 600; }
.icon-btn { background: none; border: 0; color: var(--text-2); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px; }
.icon-btn:hover { color: var(--ink); }
.acct-pop { display: none; position: absolute; top: 100%; right: 8px; z-index: 30;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 7px 10px; margin-top: 2px;
  font-size: 12px; color: var(--text-2); white-space: nowrap; min-width: 150px; }
.acct-pop .ap-head { font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 3px; }
.acct:hover .acct-pop { display: block; }

/* race feed */
.race { border: 1px solid var(--border-ghost); border-radius: 10px; padding: 8px 10px;
  background: var(--card); animation: in .22s ease; }
.race:hover { background: var(--hover); }
.race.hide { display: none; }
.race.orphan { border-left: 3px solid var(--border); opacity: .9; }
.race.orphan .head .title { color: var(--text-2); }
.race.done { opacity: .55; }
.race .ts { font-size: 11px; color: var(--muted); margin-right: 8px; }
.race .head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; min-width: 0; }
/* the name grows into the free space and truncates with … when long (instead of
   wrapping the row and knocking the number columns out of alignment); it plays
   the spacer's role, so the explicit .spacer isn't needed in these rows */
.race .head .spacer, .race .sel .spacer { display: none; }
.race .title { flex: 1 1 auto; font-weight: 600; color: var(--ink);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race .rtype { font-size: 11px; color: var(--muted); font-weight: 500; }
.race .jump { font-size: 12px; color: var(--text-2); }
.race .jump.soon { color: var(--orange); font-weight: 600; }
.race .sel { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; font-size: 13px; min-width: 0; }
.race .tick { font-weight: 700; width: 12px; display: inline-block; flex-shrink: 0; }
.race .tick.y { color: var(--green); }
.race .tick.n { color: var(--muted); }
.race .horse { flex: 1 1 auto; font-weight: 500;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race .ev { font-weight: 600; }
.race .ev.pos { color: var(--green); }
.race .ev.neg { color: var(--red); }
.race .price { color: var(--ink); font-weight: 600; }
.race .bookie { color: var(--muted); font-size: 12px; }

.logline { color: var(--muted); font-size: 12px; padding: 2px 4px; }
.feed-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.feed-dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(23,154,95,.18); }
.feed-dot.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(224,68,74,.18); }

/* per-race outcome (engine decision detail) */
.outcome { margin-top: 7px; padding: 6px 0 2px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 1px; }
.outcome .oc { font-size: 12px; color: var(--text-2); }
.outcome .oc.leg { padding-left: 14px; font-weight: 400; }
.outcome .oc.ok { color: var(--green); font-weight: 500; }
.outcome .oc.skip { color: var(--muted); }
.outcome .oc.err { color: var(--red); }
.outcome .oc .muted { color: var(--muted); }

@keyframes in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }

/* bet history — dense rows with status edge stripe */
.bet { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; border-radius: 8px;
  border-left: 3px solid var(--gray); background: var(--card); font-size: 13px; animation: in .2s; }
.bet:hover { background: var(--hover); }
.bet .tag { font-size: 11px; font-weight: 600; letter-spacing: .03em; }
.bet .b-race { flex-shrink: 0; }
.bet .b-runner { color: var(--text-2);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bet .fig { margin-left: auto; font-weight: 600; }
.bet .fig.pos { color: var(--green); }
.bet .fig.neg { color: var(--red); }
.bet .fig.soft { color: var(--muted); font-weight: 400; font-size: 12px; }
.bet .fig.pot { color: var(--muted); font-weight: 400; font-size: 12px; }
.ev.pos { color: var(--green); }
.ev.neg { color: var(--red); }
.bet .b-stake { font-size: 12px; color: var(--muted); margin-left: auto; padding-left: 8px; }
.bet .b-ts { font-size: 11px; color: var(--muted); padding-left: 8px; }
.bet .b-stake ~ .b-ts, .bet .b-ts ~ .fig, .bet .b-stake ~ .fig { margin-left: 8px; }
.bet.clickable { cursor: pointer; }
.bet .recon { color: var(--muted); font-size: 11px; cursor: help; }
.bet-legs { padding: 2px 10px 6px 26px; font-size: 12px; color: var(--text-2);
  display: flex; flex-direction: column; gap: 1px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 0; }
.actions button { margin-right: 8px; }

/* ── Reports page ─────────────────────────────────────────────────────────── */
.report { display: flex; flex-direction: column; gap: 12px; }
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px 16px; }
.sc-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.sc-net { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums;
  font-size: 26px; font-weight: 600; margin: 6px 0 2px; letter-spacing: -0.02em; }
.sc-net.pos { color: var(--green); }
.sc-net.neg { color: var(--red); }
.sc-sub { font-size: 12px; color: var(--text-2); }

.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 820px) { .report-grid { grid-template-columns: 1fr; } }
.table .num { text-align: right; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
.table td.num { color: var(--ink); }

/* daily-net bars (up = green, down = red around a centre baseline) */
.bars { display: flex; gap: 4px; align-items: stretch; height: 130px; }
.bar-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.bar-up { flex: 1; display: flex; align-items: flex-end; }
.bar-dn { flex: 1; display: flex; align-items: flex-start; }
.bar { width: 100%; min-height: 1px; }
.bar.pos { background: var(--green); border-radius: 3px 3px 0 0; }
.bar.neg { background: var(--red); border-radius: 0 0 3px 3px; }
.bar-col:hover .bar { filter: brightness(1.1); }
.bar-lbl { font-size: 10px; text-align: center; color: var(--muted);
  font-family: 'JetBrains Mono', monospace; padding-top: 3px; }
.st-won { border-left-color: var(--green); background: rgba(23,154,95,.05); }
.st-won .tag { color: var(--green); }
.st-bonus { border-left-color: var(--purple); }
.st-bonus .tag { color: var(--purple); }
.st-loss { border-left-color: var(--red); }
.st-loss .tag, .st-loss .b-runner, .st-loss .b-race { color: var(--muted); }
.st-void { border-left-color: var(--gray); }
.st-void .tag { color: var(--muted); }
.st-pending { border-left-color: var(--blue); }
.st-pending .tag { color: var(--blue); }

/* ── Forms (settings / admin) ───────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 820px) { .settings-grid { grid-template-columns: 1fr; } }
.form { display: flex; flex-direction: column; gap: 10px; max-width: 540px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; }
.form input, .form select, .form textarea {
  background: var(--card); border: 1px solid var(--border); color: var(--ink);
  border-radius: 8px; padding: 9px 10px; font: inherit;
}
.form input:hover, .form select:hover { border-color: var(--text-2); }
.form h3 { margin: 10px 0 0; font-size: 14px; }
.inline-form { flex-direction: row; flex-wrap: wrap; align-items: center; max-width: none; }
.msg { font-size: 12px; }
.msg.good { color: var(--green); }
.msg.bad, .error { color: var(--red); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
code { background: var(--container); padding: 1px 5px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ── Login ──────────────────────────────────────────────────────────────── */
.center { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login { width: 320px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0 0 4px; color: var(--ink); letter-spacing: -0.03em; }
.login label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.login input { background: var(--card); border: 1px solid var(--border); color: var(--ink); border-radius: 8px; padding: 10px; font: inherit; }
.login button { background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 11px; font: inherit; font-weight: 500; cursor: pointer; }
.login button:hover { background: var(--brand-hover); }
