/* optlab on Operator Desk's design system (app.css is OD's pwa/css/app.css, v1.60.3, copied unchanged).
   This file only adds what optlab needs on top: chart series tokens, the card head/body pair, form grid, KPI grid,
   sortable table states, page intro, notes and small utilities. Tokens only: no colour is written here twice. */

:root, :root[data-theme="light"] { --s1: #2c5f8a; --s2: #b4612a; --s3: #1d7a5f; --s4: #9a7400; }
:root[data-theme="dark"] { --s1: #7fb0de; --s2: #e08a5a; --s3: #6fb9a2; --s4: #e0c060; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s1: #7fb0de; --s2: #e08a5a; --s3: #6fb9a2; --s4: #e0c060; } }

/* ---------- utilities ---------- */
.mt-s { margin-top: var(--sp-4); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.bold { font-weight: 650; }
.col { display: flex; flex-direction: column; gap: 6px; }
.right { margin-left: auto; }
.warn { color: var(--warn); }
.flat { color: var(--text-3); }
.spin { animation: spin 1s linear infinite; }
@media (max-width: 767px) { .hide-sm { display: none !important; } }
:root[data-mode="beginner"] .x-only { display: none !important; }
:root[data-mode="expert"] .g-only { display: none !important; }
.wrap { flex-wrap: wrap; }

/* ---------- layout grids ---------- */
.g-main-side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
@media (max-width: 1279px) { .g-main-side { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 899px) { .g-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .g-4 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- cards: a head and a body, each with its own padding ---------- */
.card:has(> .card-h), .card:has(> .card-b), details.card { padding: 0; }
.card-h { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) 0; min-width: 0; flex-wrap: wrap; row-gap: 8px; }
.card-h h3 { font-size: var(--fs-lg); letter-spacing: -.015em; display: flex; align-items: center; gap: 8px; margin: 0; }
.card-h h3 svg { color: var(--accent); }
.card-h .sub { color: var(--text-3); font-size: var(--fs-sm); }
.card-h .right { margin-left: auto; display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.card-b { padding: var(--sp-4) var(--sp-5) var(--sp-5); }
.card-b.flush { padding: var(--sp-3) 0 0; }
.card-b.flush > .table-wrap, .card .table-wrap { border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; box-shadow: none; background: transparent; }
.card-b:not(.flush) .table-wrap { border: 1px solid var(--border); border-radius: var(--r); }
details.card > summary { list-style: none; cursor: pointer; padding-bottom: var(--sp-5); }
details.card[open] > summary { padding-bottom: 0; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: ""; width: 8px; height: 8px; margin-left: auto; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3);
  transform: rotate(45deg); transition: transform var(--dur) var(--ease); }
details.card[open] > summary::after { transform: rotate(-135deg); }
details > summary.small { color: var(--text-2); }
details > summary.small:hover { color: var(--text); }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-4) var(--sp-4); align-items: start; }
.field .field-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.field .input, .field .select { min-height: 38px; }
.field .switch { min-height: 38px; }
.input.sm, .select.sm { min-height: 32px; height: 32px; font-size: var(--fs-sm); padding: 0 10px; }
.select.sm { padding-right: 30px; background-position: right 10px center; }
.group-t { font-size: var(--fs-sm); font-weight: 650; margin: var(--sp-5) 0 var(--sp-3); display: flex; gap: 8px; align-items: center; color: var(--text); }
.group-t svg { color: var(--accent); }
.group-t:first-child { margin-top: 0; }
.actions { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; margin-top: var(--sp-5); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .chip { min-height: 30px; padding: 4px 11px; font-size: var(--fs-sm); }
.chip .count { font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; }
.chip[aria-pressed="true"] .count { color: inherit; opacity: .8; }
.seg.sm button { min-height: 26px; padding: 0 10px; font-size: var(--fs-xs); }

/* ---------- KPIs (OD .kpi, laid out as a grid) ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: var(--sp-5) var(--sp-4); }
.kpi .value { font-size: var(--fs-xl); }
.kpi .value.up { color: var(--up); } .kpi .value.down { color: var(--down); } .kpi .value.warn { color: var(--warn); }
.kpi .meta { line-height: 1.4; }

/* ---------- tables (OD .table plus sorting and selection) ---------- */
.table td { white-space: nowrap; }
.table td.wrap { white-space: normal; min-width: 220px; }
.table td.up { color: var(--up); } .table td.down { color: var(--down); } .table td.warn { color: var(--warn); } .table td.muted { color: var(--text-3); }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th.sortable:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.table th.sorted { color: var(--accent); }
.table th .arrow { display: inline-block; margin-left: 4px; font-size: 9px; }
.table tbody tr.sel td { background: var(--accent-soft); }
.table tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--led); }
.table-wrap.scroll { overflow: auto; }
.table-wrap.scroll .table th { z-index: 2; }
.table-wrap.scroll .table-foot { position: sticky; bottom: 0; left: 0; background: var(--surface-1); }
.table-foot { display: flex; align-items: center; gap: var(--sp-2); padding: 8px 12px; border-top: 1px solid var(--divider); }
.table.dense td { padding: 7px 12px; }

/* ---------- page intro: the one-sentence answer at the top of each page ---------- */
.page-intro { display: flex; align-items: center; gap: 12px; padding: 14px 18px; margin-bottom: var(--sp-5); border-radius: var(--r-lg);
  background: var(--sheen), var(--surface-1); border: 1px solid var(--border); box-shadow: var(--e1); font-size: var(--fs-md); line-height: 1.5; color: var(--text);
  border-left: 3px solid var(--accent); }
.page-intro.t-up { border-left-color: var(--up); } .page-intro.t-down { border-left-color: var(--down); } .page-intro.t-warn { border-left-color: var(--warn); }
.page-intro > svg { flex: none; color: var(--text-3); }
.page-intro .btn { flex: none; }
:root[data-mode="expert"] .page-intro { padding: 9px 14px; font-size: var(--fs-sm); }
:root[data-mode="expert"] .page-intro > svg { display: none; }
@media (max-width: 767px) { .page-intro { flex-wrap: wrap; font-size: var(--fs); } .page-intro > svg { display: none; } }
.read-hint > div { margin-top: 8px; color: var(--text-2); line-height: 1.6; }

/* ---------- notes, empty states, toasts ---------- */
.note { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--r); background: var(--info-soft); color: var(--text-2); font-size: var(--fs-sm); line-height: 1.5; }
.note svg { color: var(--info); flex: none; margin-top: 2px; }
.note.warn { background: var(--warn-soft); color: var(--text-2); }
.note.warn svg { color: var(--warn); }
.empty { padding: var(--sp-10) var(--sp-5); text-align: center; color: var(--text-3); display: grid; justify-items: center; gap: 10px; }
.empty svg { opacity: .7; }
.empty b { color: var(--text-2); font-size: var(--fs-md); }
.empty .small { max-width: 60ch; line-height: 1.5; }
.toast { cursor: pointer; }

/* ---------- top status: data date and live job ---------- */
.top-status .job { color: var(--text-3); font-weight: 500; }
.top-progress { position: absolute; left: 28px; right: 20px; bottom: 6px; height: 2px; border-radius: 2px; overflow: hidden; background: var(--divider); }
.top-progress span { display: block; width: 30%; height: 100%; background: linear-gradient(90deg, var(--cta-a), var(--cta-b)); animation: boot 1.3s var(--ease) infinite; }

/* ---------- optlab pieces ---------- */
.scorebar { display: inline-flex; align-items: center; gap: 8px; min-width: 92px; }
.scorebar .bar { width: 52px; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.scorebar .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cta-a), var(--cta-b)); border-radius: 3px; }
.scorebar b { font-weight: 700; min-width: 28px; text-align: right; }
.heat { border-collapse: separate; border-spacing: 2px; font-size: var(--fs-xs); width: 100%; }
.heat th { color: var(--text-3); font-weight: 600; padding: 2px 4px; text-align: center; background: none; position: static; border: 0; }
.heat td { text-align: center; padding: 6px 2px; border-radius: 4px; font-variant-numeric: tabular-nums; min-width: 40px; border: 0; }
.heat td.y { font-weight: 700; color: var(--text-2); background: none; text-align: left; }
.heat-wrap { overflow-x: auto; }
.jobbar { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; margin-top: 10px; }
.jobbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cta-a), var(--cta-b)); transition: width .4s var(--ease); }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 650;
  background: var(--neutral-soft); color: var(--text-2); white-space: nowrap; }
.pill.acc { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.rule-list { display: grid; gap: 0; }
.rule { display: grid; grid-template-columns: 190px 1fr; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--divider); }
.rule:last-child { border-bottom: 0; }
.rule b { font-size: var(--fs-sm); }
.rule div { font-size: var(--fs-sm); color: var(--text-2); line-height: 1.55; }
@media (max-width: 767px) { .rule { grid-template-columns: 1fr; gap: 4px; } }
.log { font: 12px/1.5 var(--mono); background: var(--surface-sunken); border-radius: var(--r-sm); padding: 8px 10px; color: var(--text-2);
  white-space: pre-wrap; max-height: 140px; overflow: auto; }
.scan-ctl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-3); margin-top: var(--sp-4); }
.scan-ctl .full { grid-column: 1 / -1; }
.scan-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.diag { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--fs-xs); color: var(--text-3); }
.diag b { color: var(--text-2); }
.setup-list { max-height: 232px; overflow-y: auto; padding: 2px; }

/* ---------- compact filter bar (Edge finder) ---------- */
.filterbar { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 12px; align-items: end; }
.filterbar .field { gap: 4px; }
.filterbar .field .input, .filterbar .field .select { min-height: 32px; }
.filterbar.more { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--divider); }
.filterbar .switch { min-height: 32px; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.linkish:hover { text-decoration: underline; }

/* ---------- drawer: side panel on wide screens, bottom sheet on phones ---------- */
.drawer { position: fixed; z-index: var(--z-dialog); top: 0; right: 0; bottom: 0; width: min(520px, 100vw); display: flex; flex-direction: column;
  background: var(--surface-1); border-left: 1px solid var(--border-strong); box-shadow: var(--e3); animation: drawer-in var(--dur-panel, .24s) var(--ease-out, ease-out) both; }
.drawer-h { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--divider); font-size: var(--fs-md); }
.drawer-b { overflow-y: auto; padding: 0 0 var(--sp-5); flex: 1; }
.drawer .scan-panel .card-h { padding-top: var(--sp-4); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
@media (max-width: 767px) { .drawer { top: auto; left: 0; width: auto; max-height: 88vh; border-left: 0; border-top: 1px solid var(--border-strong); border-radius: var(--r-xl) var(--r-xl) 0 0; } }

/* ---------- sticky run bar (Backtest, Robustness, Replay) ---------- */
.runbar { position: sticky; top: calc(var(--top-h, 64px) + 8px); z-index: 5; padding: 12px 16px; }
.runbar-in { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.runbar-in > .field { min-width: 130px; gap: 4px; }
.runbar-in > .field.grow { flex: 1 1 220px; }
.runbar-in .input, .runbar-in .select { min-height: 32px; }
.runbar-in > .btn-primary { margin-left: auto; min-height: 36px; }
.runbar-pick { width: 100%; justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 32px; }
.runbar-why { margin-top: 6px; text-align: right; }
@media (max-width: 767px) { .runbar { position: static; } .runbar-in > .btn-primary { width: 100%; } }

/* ---------- Rules contents and Coverage status tiles ---------- */
.toc { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.toc a { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--r-pill); background: var(--neutral-soft); color: var(--text-2); font-size: var(--fs-sm); text-decoration: none; }
.toc a:hover { color: var(--text); background: var(--accent-soft); }
.toc a svg { color: var(--accent); }
.toc a.dim { opacity: .45; }
.anchor { scroll-margin-top: calc(var(--top-h, 64px) + 12px); }
.kpi-btn { text-align: left; background: none; border: 1px solid transparent; border-radius: var(--r); padding: 8px 10px; margin: -8px -10px; cursor: pointer; font: inherit; color: inherit; }
.kpi-btn:hover { border-color: var(--border); }
.kpi-btn.on { border-color: var(--accent); background: var(--accent-soft); }
.intro-detail { display: block; margin-top: 3px; color: var(--text-3); font-size: var(--fs-xs); }
