/* SmartInk engine console. One stylesheet, no build step. The colours and the look (gradient app
   bar, rounded cards, icon navigation) are the ones the SmartInk dashboard uses (smartink_app, modern.css);
   the chart colours (viz-*) are validated separately and sit at the end of this file. Dark mode
   follows the system setting unless the page sets data-theme="light". */
:root {
  --bg: #eef1f8; --surface: #ffffff; --surface-2: #f6f8fc; --surface-3: #edf1f9;
  --fg: #0f172a; --fg-2: #334155; --muted: #64748b; --line: #e2e8f0; --line-strong: #cbd5e1;
  --brand: #4f46e5; --brand-hover: #4338ca; --brand-ink: #3730a3; --brand-soft: #eef2ff;
  --brand-2: #7c3aed;
  --ok: #059669; --ok-soft: #e8f8f1; --ok-line: #a7f3d0;
  --bad: #e11d48; --bad-soft: #fff0f3; --bad-line: #fecdd3;
  --warn: #c2410c; --warn-soft: #fff7ed; --warn-line: #fed7aa;
  --info: #2563eb; --info-soft: #eff6ff; --info-line: #bfdbfe;
  --violet: #7c3aed; --violet-soft: #f5f3ff;
  --appbar: linear-gradient(100deg, #1e1b4b 0%, #312e81 40%, #4c1d95 75%, #155e75 100%);
  --code-bg: #0f172a; --code-fg: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 14px rgba(15, 23, 42, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1e; --surface: #111a2e; --surface-2: #162039; --surface-3: #1c2744;
    --fg: #e2e8f0; --fg-2: #cbd5e1; --muted: #8fa0bb; --line: #223052; --line-strong: #2f3f66;
    --brand: #818cf8; --brand-hover: #a5b4fc; --brand-ink: #c7d2fe; --brand-soft: rgba(129, 140, 248, .14);
    --brand-2: #a78bfa;
    --ok: #34d399; --ok-soft: rgba(52, 211, 153, .12); --ok-line: rgba(52, 211, 153, .35);
    --bad: #fb7185; --bad-soft: rgba(251, 113, 133, .12); --bad-line: rgba(251, 113, 133, .35);
    --warn: #fb923c; --warn-soft: rgba(251, 146, 60, .12); --warn-line: rgba(251, 146, 60, .35);
    --info: #60a5fa; --info-soft: rgba(96, 165, 250, .12); --info-line: rgba(96, 165, 250, .35);
    --violet: #a78bfa; --violet-soft: rgba(167, 139, 250, .13);
    --appbar: linear-gradient(100deg, #0b0f24 0%, #1e1b4b 45%, #2e1065 80%, #083344 100%);
    --code-bg: #020617; --code-fg: #e2e8f0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0f1e; --surface: #111a2e; --surface-2: #162039; --surface-3: #1c2744;
  --fg: #e2e8f0; --fg-2: #cbd5e1; --muted: #8fa0bb; --line: #223052; --line-strong: #2f3f66;
  --brand: #818cf8; --brand-hover: #a5b4fc; --brand-ink: #c7d2fe; --brand-soft: rgba(129, 140, 248, .14);
  --brand-2: #a78bfa;
  --ok: #34d399; --ok-soft: rgba(52, 211, 153, .12); --ok-line: rgba(52, 211, 153, .35);
  --bad: #fb7185; --bad-soft: rgba(251, 113, 133, .12); --bad-line: rgba(251, 113, 133, .35);
  --warn: #fb923c; --warn-soft: rgba(251, 146, 60, .12); --warn-line: rgba(251, 146, 60, .35);
  --info: #60a5fa; --info-soft: rgba(96, 165, 250, .12); --info-line: rgba(96, 165, 250, .35);
  --violet: #a78bfa; --violet-soft: rgba(167, 139, 250, .13);
  --appbar: linear-gradient(100deg, #0b0f24 0%, #1e1b4b 45%, #2e1065 80%, #083344 100%);
  --code-bg: #020617; --code-fg: #e2e8f0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--sans); color: var(--fg); background: var(--bg); }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; color: var(--fg-2); }
p { margin: 0 0 8px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: 12px; }

/* ---------- top bar (the smartink_app app bar: gradient, white icons and labels) ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--appbar); color: #fff; box-shadow: 0 2px 10px rgba(15, 23, 42, .18); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 18px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: block; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: rgba(255, 255, 255, .7); letter-spacing: 0.04em; text-transform: uppercase; }
.nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { display: inline-flex; align-items: center; gap: 6px; color: rgba(255, 255, 255, .82); padding: 7px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
.nav a:hover { background: rgba(255, 255, 255, .1); text-decoration: none; color: #fff; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }
.nav .nav-short { display: none; }
.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.account { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .25); display: grid; place-items: center; font-size: 13px; font-weight: 650; color: #fff; }
.account .who { font-size: 13px; line-height: 1.2; color: #fff; }
.account .who span { display: block; color: rgba(255, 255, 255, .7); font-size: 12px; }
.topbar button.ghost-light { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .3); color: #fff; }
.topbar button.ghost-light:hover { background: rgba(255, 255, 255, .22); }

/* ---------- layout ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 24px 20px 48px; }
main.narrow { max-width: 440px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 6px; max-width: 760px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; align-items: center; }

/* two independent columns of cards: each card sits right under the one above it, so a tall card never
   leaves a gap beside it. On a phone the columns dissolve into one list, in the order of .ord-N. */
.cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.cols > .col { display: contents; }
.cols .card { margin-bottom: 0; }
@media (min-width: 1000px) {
  .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols > .col { display: grid; gap: 16px; align-content: start; min-width: 0; }
}
.ord-1 { order: 1; } .ord-2 { order: 2; } .ord-3 { order: 3; } .ord-4 { order: 4; }
.ord-5 { order: 5; } .ord-6 { order: 6; } .ord-7 { order: 7; } .ord-8 { order: 8; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.card-body.flush .table-wrap { border: 0; border-radius: 0; }
.card > .card-body + .card-body { border-top: 1px solid var(--line); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .card-head { border-bottom: 0; }
details.card[open] > summary .card-head { border-bottom: 1px solid var(--line); }
details.card > summary .card-head::after { content: "+"; font-size: 20px; color: var(--muted); line-height: 1; margin-left: auto; }
details.card[open] > summary .card-head::after { content: "\2212"; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--fg-2); border: 1px solid var(--line); white-space: nowrap; line-height: 1.6; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.plain { padding-left: 9px; }
.badge.plain::before { display: none; }
.state { font-weight: 700; }
.state.running { color: var(--ok); } .state.crashed { color: var(--bad); } .state.stopped { color: var(--fg-2); }
.pnl.pos { color: var(--ok); font-weight: 600; } .pnl.neg { color: var(--bad); font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: var(--surface-2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data td.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
table.data .sub { display: block; color: var(--muted); font-size: 12px; }
table.data td.col-actions { white-space: nowrap; }
tr.bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
tr.ok td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
tr.warn td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 550; line-height: 1.2; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--fg); text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
button.danger, .btn.danger { color: var(--bad); border-color: var(--bad-line); background: var(--bad-soft); }
button.danger:hover, .btn.danger:hover { filter: brightness(0.97); }
button.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost, .btn.ghost { border-color: transparent; background: transparent; color: var(--brand); padding-left: 8px; padding-right: 8px; }
button.ghost:hover, .btn.ghost:hover { background: var(--brand-soft); }
button.sm, .btn.sm { padding: 5px 10px; font-size: 13px; }
button.icon { padding: 5px 8px; min-width: 30px; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions-bar form { margin: 0; display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; }

/* ---------- forms ---------- */
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; max-width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); padding: 0; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
input:read-only:not([type="checkbox"]):not([type="radio"]) { background: var(--surface-2); color: var(--muted); }
textarea { width: 100%; font-family: var(--mono); font-size: 13px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span.label, label.field > span:first-child { font-size: 13px; font-weight: 600; color: var(--fg-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field > label > span:first-child { font-size: 13px; font-weight: 600; color: var(--fg-2); }
.field > span:first-child .mono { font-weight: 400; }
.field-label { font-weight: 600; }
.field.end { justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--fg-2); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px 18px; align-items: start; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-actions .muted { margin-left: auto; font-size: 13px; }
.form-actions.bare { margin-top: 0; padding-top: 0; border-top: 0; }
.span-all { grid-column: 1 / -1; }
.search { min-width: 260px; max-width: 100%; }
.row input.grow { flex: 1; min-width: 160px; }
.mt-3 { margin-top: 14px; }
.mt-2 { margin-top: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }

/* ---------- flash and notices ---------- */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); margin: 0 0 12px; font-size: 14px; }
.flash::before { content: "i"; flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--info-soft); color: var(--info); margin-top: 1px; }
.flash.ok { border-color: var(--ok-line); background: var(--ok-soft); }
.flash.ok::before { content: "\2713"; background: var(--ok); color: #fff; }
.flash.error { border-color: var(--bad-line); background: var(--bad-soft); }
.flash.error::before { content: "!"; background: var(--bad); color: #fff; }
.flash.warn { border-color: var(--warn-line); background: var(--warn-soft); }
.flash.warn::before { content: "!"; background: var(--warn); color: #fff; }
.notice { padding: 12px 14px; border-radius: 6px; background: var(--surface-2); border: 1px dashed var(--line-strong); color: var(--fg-2); font-size: 14px; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--fg-2); margin-bottom: 4px; font-size: 15px; }

/* ---------- code blocks ---------- */
pre.log, pre.diff, pre.clause, pre.code { background: var(--code-bg); color: var(--code-fg); padding: 12px 14px; border-radius: 6px; overflow: auto; margin: 0; font: 13px/1.55 var(--mono); white-space: pre; }
pre.log { max-height: 380px; }
pre.clause { white-space: pre-wrap; word-break: break-word; }
.diff .add { color: #86efac; } .diff .del { color: #fca5a5; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 0px); display: grid; place-items: center; padding: 40px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; }
.login-card .brand-mark { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; margin-bottom: 14px; }
.login-card h1 { font-size: 20px; }
.login-card p.muted { margin-bottom: 18px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card button { width: 100%; }

/* ---------- error page ---------- */
.error-page { text-align: center; padding: 64px 16px; }
.error-page .error-code { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.error-page h1 { margin-bottom: 8px; }
.error-page p { max-width: 520px; margin: 0 auto 20px; color: var(--fg-2); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; border-radius: 0; padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { background: transparent; color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 650; }
.tabs .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--surface-2); color: var(--fg-2); font-size: 12px; line-height: 18px; }
.tabs .count.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- settings list ---------- */
.setting { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(200px, 260px) minmax(0, 1.4fr); gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); align-items: start; }
.setting:last-child { border-bottom: 0; }
.setting .name { font-family: var(--mono); font-size: 13px; color: var(--fg); word-break: break-all; }
.setting .help { font-size: 13px; color: var(--muted); }
.setting .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.setting.changed { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.setting select, .setting input { width: 100%; }

/* ---------- strategy cards ---------- */
.strategy-list { display: flex; flex-direction: column; gap: 10px; }
.strategy { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.strategy .order { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; color: var(--fg-2); }
.strategy .order.off { color: var(--muted); }
.strategy h3 { font-size: 15px; color: var(--fg); }
.strategy .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.strategy .actions-bar { justify-content: flex-end; }
.strategy.off { opacity: 0.8; }

/* ---------- accounts ---------- */
.secret-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- builder ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.builder-main, .builder-aside { min-width: 0; }
.builder-main > * + * { margin-top: 16px; }
.builder-aside { position: sticky; top: 76px; }
.step { display: flex; gap: 10px; align-items: center; }
.step-no { width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; }
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.template { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; height: 100%; white-space: normal; background: var(--surface); }
.template strong { font-size: 14px; color: var(--fg); }
.template span { font-size: 12px; color: var(--muted); font-weight: 400; line-height: 1.4; }
.side-sentence { font-size: 14px; color: var(--fg-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
.side-sentence strong { color: var(--fg); }
.side-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.side-toolbar label { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--fg-2); }
.cond-list { display: flex; flex-direction: column; gap: 10px; }
.cond { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.cond.has-error { border-color: var(--bad-line); }
.cond-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.cond-head .cond-title { font-size: 13px; font-weight: 650; color: var(--fg-2); display: flex; align-items: center; gap: 8px; }
.cond-head .cond-sentence { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: right; }
.cond-tools { display: flex; gap: 2px; flex: none; }
.cond-body { display: grid; grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1fr); gap: 10px; padding: 12px; align-items: start; }
.cond-error { margin: 0 12px 12px; }
.cond-body .side-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.operator select { font-weight: 600; width: 100%; }
.operand { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.operand-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.operand-row > .lead { font-size: 12px; color: var(--muted); font-weight: 600; }
.operand-nested { border-left: 3px solid var(--line-strong); padding: 6px 0 2px 10px; margin-top: 2px; display: flex; flex-direction: column; gap: 6px; }
.operand-nested .operand-nested { border-left-color: var(--brand); }
.operand select, .operand input { min-width: 0; }
.operand .tf { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.operand .tf input { width: 64px; }
.operand .tf .offset { width: 56px; }
.operand input.number { width: 110px; }
.cond-error .flash { margin: 0; }
.summary-line { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.summary-line:last-child { border-bottom: 0; }
.summary-line .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--muted); }
.summary-line.ok .dot { background: var(--ok); }
.summary-line.bad .dot { background: var(--bad); }
.summary-line small { display: block; color: var(--muted); font-size: 13px; }
.save-panel { display: flex; flex-direction: column; gap: 10px; }
.save-panel button.primary { width: 100%; padding: 10px 14px; }
.save-panel .hint { font-size: 13px; color: var(--muted); }
.clause-table td { font-size: 13px; }
.clause-table td:nth-child(2) { font-family: var(--mono); font-size: 12px; word-break: break-word; }
.token { display: inline-block; font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin: 1px 2px 1px 0; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder-aside { position: static; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .topbar-inner { flex-wrap: wrap; padding: 10px 16px; gap: 8px 14px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .nav .sep { display: none; }
  main { padding: 16px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .setting { grid-template-columns: 1fr; gap: 8px; }
  .strategy { grid-template-columns: 1fr; }
  .strategy .order { display: none; }
  .strategy .actions-bar { justify-content: flex-start; }
  .cond-body { grid-template-columns: 1fr; }
  .cond-head .cond-sentence { display: none; }
}
@media (max-width: 480px) {
  h1 { font-size: 21px; }
  .account .who { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- settings help and sections ---------- */
.toolbar { margin-bottom: 12px; }
.toolbar h2 { font-size: 16px; }
.setting-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.setting-label { font-weight: 650; color: var(--fg); }
.help-text { font-size: 13px; color: var(--fg-2); line-height: 1.45; }
.help-chip { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line-strong); font-size: 11px; font-weight: 700; color: var(--muted); }

details.help { position: relative; display: inline-block; }
details.help > summary { list-style: none; cursor: help; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700; line-height: 1; user-select: none; }
details.help > summary::-webkit-details-marker { display: none; }
details.help > summary:hover, details.help[open] > summary { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
details.help > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
details.help .help-body { position: absolute; z-index: 30; top: 24px; left: -6px; width: min(380px, 84vw); background: var(--surface); color: var(--fg); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14); padding: 12px 14px; font-size: 13px; font-weight: 400; line-height: 1.5; text-align: left; }
details.help .help-body p { margin: 0 0 8px; }
details.help .help-body p:last-child { margin-bottom: 0; }
.file-list { margin: 4px 0 8px; padding-left: 18px; font-size: 12px; }
.file-list li { margin: 2px 0; word-break: break-all; }
.file-list code { font-size: 12px; }

/* ---------- exit strategy page ---------- */
ol.plan { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
ol.plan li { font-size: 14px; color: var(--fg-2); line-height: 1.5; }
ol.plan li strong { color: var(--fg); }
.guide { font-size: 14px; color: var(--fg-2); line-height: 1.6; }
.guide ol, .guide ul { margin: 0 0 10px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.guide li strong { color: var(--fg); }
.guide .file-list { font-size: 13px; }
details.card > summary { padding: 0; }

/* ---------- backtest charts (admin_ui/charts.py) ----------
   Categorical slots s1..s8 follow the strategy, never its rank. Validated for colour-vision
   deficiency on this surface in both modes; every chart has a legend or title and a table beside
   it, so no value depends on colour alone. Profit and loss use a blue/red diverging pair. */
:root {
  --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a; --viz-4: #eda100;
  --viz-5: #e87ba4; --viz-6: #008300; --viz-7: #6250d6; --viz-8: #e34948;
  --viz-pos: #2a78d6; --viz-neg: #e34948;
  --viz-grid: #edf0f4; --viz-axis: #94a3b8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-4: #c98500;
    --viz-5: #d55181; --viz-6: #008300; --viz-7: #9085e9; --viz-8: #e66767;
    --viz-pos: #3987e5; --viz-neg: #e66767;
    --viz-grid: #1a2640; --viz-axis: #475569;
  }
}
:root[data-theme="dark"] {
  --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-4: #c98500;
  --viz-5: #d55181; --viz-6: #008300; --viz-7: #9085e9; --viz-8: #e66767;
  --viz-pos: #3987e5; --viz-neg: #e66767;
  --viz-grid: #1a2640; --viz-axis: #475569;
}
.viz { margin: 0; }
.viz + .viz { margin-top: 18px; }
.viz figcaption { font-size: 13px; font-weight: 600; color: var(--fg-2); margin-bottom: 6px; }
.viz-svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-zero { stroke: var(--viz-axis); stroke-width: 1; }
.viz-tick { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.viz-label { fill: var(--fg-2); font: 12px var(--sans); }
.viz-value { fill: var(--fg); font: 600 12px var(--sans); font-variant-numeric: tabular-nums; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-dot { stroke: var(--surface); stroke-width: 2; }
.viz-bar.viz-pos { fill: var(--viz-pos); }
.viz-bar.viz-neg { fill: var(--viz-neg); }
.viz-hit { fill: transparent; }
/* hover crosshair on the contract price chart: guides, axis labels, a dot and a box beside the mouse */
.viz-guide { stroke: var(--fg-2); stroke-width: 1; stroke-dasharray: 4 3; }
.viz-probe-dot { fill: var(--surface); stroke: var(--viz-1); stroke-width: 2.5; }
.viz-pill { fill: var(--fg); }
.viz-pill-text { fill: var(--surface); font: 600 11px var(--sans); font-variant-numeric: tabular-nums; }
.viz-tip-box { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1; filter: drop-shadow(0 2px 4px rgba(15, 23, 42, .25)); }
.viz-tip-time { fill: var(--fg); font: 700 12px var(--sans); font-variant-numeric: tabular-nums; }
.viz-tip-price { fill: var(--fg-2); font: 600 11px var(--sans); font-variant-numeric: tabular-nums; }
.viz-hit:hover { fill: var(--fg); fill-opacity: 0.05; }
.viz-bar:hover { opacity: 0.85; }
.viz-line.s1 { stroke: var(--viz-1); } .viz-dot.s1, .viz-bar.s1, .swatch.s1 { fill: var(--viz-1); background: var(--viz-1); }
.viz-line.s2 { stroke: var(--viz-2); } .viz-dot.s2, .viz-bar.s2, .swatch.s2 { fill: var(--viz-2); background: var(--viz-2); }
.viz-line.s3 { stroke: var(--viz-3); } .viz-dot.s3, .viz-bar.s3, .swatch.s3 { fill: var(--viz-3); background: var(--viz-3); }
.viz-line.s4 { stroke: var(--viz-4); } .viz-dot.s4, .viz-bar.s4, .swatch.s4 { fill: var(--viz-4); background: var(--viz-4); }
.viz-line.s5 { stroke: var(--viz-5); } .viz-dot.s5, .viz-bar.s5, .swatch.s5 { fill: var(--viz-5); background: var(--viz-5); }
.viz-line.s6 { stroke: var(--viz-6); } .viz-dot.s6, .viz-bar.s6, .swatch.s6 { fill: var(--viz-6); background: var(--viz-6); }
.viz-line.s7 { stroke: var(--viz-7); } .viz-dot.s7, .viz-bar.s7, .swatch.s7 { fill: var(--viz-7); background: var(--viz-7); }
.viz-line.s8 { stroke: var(--viz-8); } .viz-dot.s8, .viz-bar.s8, .swatch.s8 { fill: var(--viz-8); background: var(--viz-8); }
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 12px; padding: 0; list-style: none; font-size: 13px; color: var(--fg-2); }
.viz-legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 14px; height: 4px; border-radius: 2px; }
.swatch.pos { background: var(--viz-pos); } .swatch.neg { background: var(--viz-neg); }
.viz-figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px 24px; }
.kpi .value.good { color: var(--ok); } .kpi .value.poor { color: var(--bad); }
table.data td.nowrap { white-space: nowrap; }
.viz.narrow { max-width: 520px; }
@media (max-width: 600px) { .viz { overflow-x: auto; } .viz-svg.viz-wide { min-width: 640px; } }
fieldset.field { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }

/* ---------- popup dialogs (strategy explanations) ---------- */
dialog.detail-dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--fg); box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3); }
dialog.detail-dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.dialog-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 14px 18px 18px; overflow-y: auto; max-height: calc(100vh - 140px); font-size: 14px; }
.explanation h3 { margin: 16px 0 6px; font-size: 13px; color: var(--fg-2); letter-spacing: 0.02em; }
.explanation h3:first-child { margin-top: 0; }
.explanation p { margin: 0 0 8px; line-height: 1.55; }
.explanation ul { margin: 0 0 6px; padding-left: 20px; }
.explanation li { margin: 0 0 6px; line-height: 1.5; }

/* ---------- phones: the navigation becomes a bottom tab bar (as in the installed dashboard) ---------- */
@media (max-width: 760px) {
  .topbar { position: sticky; }
  .topbar-inner { padding: 0 14px; min-height: 52px; gap: 10px; }
  .account .who { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex: none; flex-wrap: nowrap;
    overflow-x: auto; gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--appbar); box-shadow: 0 -4px 16px rgba(15, 23, 42, .25);
  }
  .nav a { flex: 0 0 auto; flex-direction: column; gap: 2px; min-width: 58px; padding: 5px 6px; font-size: 11px; text-align: center; }
  .nav a .ico { width: 20px; height: 20px; }
  .nav .nav-long { display: none; }
  .nav .nav-short { display: inline; }
  main { padding-bottom: 92px; }
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
table.data td.col-actions > a, table.data td.col-actions > form { vertical-align: middle; }

/* ---------- the Tools menu (a details element: works without script) ---------- */
.tools-menu { position: relative; }
.tools-menu summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: rgba(255, 255, 255, .82); padding: 7px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
.tools-menu summary::-webkit-details-marker { display: none; }
.tools-menu summary:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.tools-menu summary.is-active, .tools-menu[open] summary { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }
.tools-menu summary .nav-short { display: none; }
.tools-panel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 280px; display: grid; gap: 2px; padding: 6px; background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 14px 40px rgba(15, 23, 42, .25); }
.tools-panel a { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; color: var(--fg); }
.tools-panel a:hover { background: var(--surface-2); text-decoration: none; }
.tools-panel a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.tools-panel a .ico { margin-top: 2px; color: var(--muted); }
.tools-panel a[aria-current="page"] .ico { color: var(--brand); }
.tools-panel strong { display: block; font-size: 14px; }
.tools-panel small { display: block; font-size: 12px; color: var(--muted); }
@media (max-width: 760px) {
  .tools-menu summary .nav-long { display: none; }
  .tools-menu summary .nav-short { display: inline; }
  .tools-menu summary { flex: 0 0 auto; flex-direction: column; gap: 2px; min-width: 58px; padding: 5px 6px; font-size: 11px; }
  .tools-panel { position: fixed; left: 8px; right: 8px; top: auto; bottom: 74px; min-width: 0; }
}


/* ---------- System monitor ---------- */
.inline-details { display: inline-block; position: relative; }
.inline-details > summary { list-style: none; cursor: pointer; }
.inline-details > summary::-webkit-details-marker { display: none; }
.inline-details[open] > .restore-form { position: absolute; right: 0; z-index: 20; width: 320px; margin-top: 6px; padding: 12px; display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 14px 40px rgba(15, 23, 42, .2); text-align: left; white-space: normal; }
.table-list { margin-top: 6px; line-height: 1.6; }

/* Exit strategies (D70): a radio group laid out as a field. */
fieldset.field { border: 0; margin: 0; padding: 0; }
fieldset.field > legend { padding: 0; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--fg-2); }

/* Accounts form: one block of secret fields per broker (D76). */
.broker-secrets { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 14px; margin-left: 0; margin-right: 0; min-width: 0; }
.broker-secrets legend { padding: 0 6px; font-weight: 600; color: var(--fg-2); }

/* Delete an entry strategy (session 126): a details box whose summary looks like a small button. */
details.delete-strategy > summary { list-style: none; cursor: pointer; display: inline-block; }
details.delete-strategy > summary::-webkit-details-marker { display: none; }
details.delete-strategy[open] { flex-basis: 100%; max-width: 28rem; }

/* StrategyBot (D86): a server-rendered chat. */
.bot-log { display: flex; flex-direction: column; gap: 0.75rem; max-height: 65vh; overflow-y: auto; }
.bot-msg { max-width: 52rem; padding: 0.6rem 0.8rem; border-radius: 10px; border: 1px solid var(--line, #ddd); }
.bot-bot { align-self: flex-start; background: var(--panel, #fff); }
.bot-you { align-self: flex-end; background: var(--info-soft, #eef5ff); }
.bot-who { font-size: 0.75rem; opacity: 0.7; margin-bottom: 0.2rem; }
.bot-text { white-space: pre-wrap; }
.bot-list { margin: 0.4rem 0 0 1.1rem; }
.bot-box { margin-top: 0.5rem; padding: 0.4rem 0.6rem; border-left: 3px solid var(--line, #ccc); }
.bot-code { margin-top: 0.4rem; }
.bot-code pre { max-height: 24rem; overflow: auto; }
.warn-list li { color: var(--warn, #8a5a00); }
.bot-options { flex-wrap: wrap; }
fieldset.ai-fields { border: 1px solid var(--line, #ddd); border-radius: 8px; margin: 0.75rem 0; padding: 0.5rem 0.9rem; }
fieldset.ai-fields[hidden] { display: none; }
