:root {
  color-scheme: light;
  --page: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #161513;
  --ink-2: #52514e;
  --muted: #7d7b75;
  --line: #e6e2d9;
  --grid: #ebe8e1;
  --axis: #c3c2b7;
  --gold: #a98b5b;
  --gold-ink: #7d6440;
  --gold-soft: #f3ece0;
  --series: #2a78d6;
  --series-fill: rgba(42, 120, 214, 0.10);
  --pos: #006300;
  --neg: #c62f2f;
  --neg-mark: #d03b3b;
  --warn: #9a6a00;
  --div-pos: #2a78d6;
  --div-neg: #d03b3b;
  --div-mid: #f0efec;
  --shadow: 0 1px 2px rgba(20, 18, 14, .04), 0 4px 16px rgba(20, 18, 14, .05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Light is the default; dark only when chosen with the Licht/Donker switch (data-theme="dark"). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e; --surface: #1a1a19; --surface-2: #211f1d; --ink: #ffffff; --ink-2: #c3c2b7;
  --muted: #8f8d86; --line: #2f2d2a; --grid: #2a2927; --axis: #43413d;
  --gold: #c9a96e; --gold-ink: #d9bd87; --gold-soft: #2a241a;
  --series: #3987e5; --series-fill: rgba(57, 135, 229, 0.16);
  --pos: #2fbf2f; --neg: #ef7b7b; --neg-mark: #e66767; --warn: #f0b429;
  --div-pos: #3987e5; --div-neg: #e66767; --div-mid: #383835;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h2, h3, h4 { margin: 0; font-weight: 600; }
h3 { font-size: 15px; }
a { color: var(--gold-ink); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--gold);
  -webkit-mask: none; position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; left: 7px; right: 7px; bottom: 9px; height: 10px; background: #fff;
  clip-path: polygon(18% 0, 82% 0, 100% 100%, 0 100%);
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.tab { border: 0; background: none; color: var(--ink-2); font: inherit; font-weight: 500; padding: 6px 16px; border-radius: 8px; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--gold-soft); color: var(--gold-ink); font-weight: 600; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }
.tab-panel { display: flex; flex-direction: column; gap: 16px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.sub-h { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .5px; }

/* ---------- buttons ---------- */
.btn { font: inherit; font-weight: 500; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-danger { color: var(--neg); }
.btn-danger:hover:not(:disabled) { border-color: var(--neg); }
.btn-ghost { background: transparent; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; font-size: 12px; border: 0; background: none; color: var(--ink-2); padding: 4px 10px; cursor: pointer; }
.seg button.on { background: var(--gold-soft); color: var(--gold-ink); font-weight: 600; }

/* ---------- status bar ---------- */
.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; }
.status-left, .status-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.live .dot { background: #0ca30c; box-shadow: 0 0 0 3px rgba(12, 163, 12, .18); }
.pill.stale .dot { background: #fab219; }
.pill.off .dot { background: #d03b3b; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .6px; padding: 3px 8px; border-radius: 6px; background: var(--gold-soft); color: var(--gold-ink); }
.badge.real { background: #d03b3b; color: #fff; }

.empty h2 { font-size: 18px; margin-bottom: 6px; }
.empty ol { margin: 12px 0 0; padding-left: 20px; color: var(--ink-2); }
.empty li { margin: 4px 0; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
#btKpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 700px) { #btKpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 650; margin-top: 2px; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 12px; color: var(--ink-2); margin-top: 1px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- charts ---------- */
.chart { position: relative; height: 260px; }
.chart-sm { height: 110px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-fill); }
.chart .line.neg-line { stroke: var(--neg-mark); }
.chart .area.neg-area { fill: color-mix(in srgb, var(--neg-mark) 16%, transparent); }
.chart .line.muted-line { stroke: var(--muted); stroke-dasharray: 4 3; stroke-width: 1.5; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .empty-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .14); font-variant-numeric: tabular-nums; }
.tooltip b { font-weight: 650; }

/* ---------- checklist ---------- */
.verdict { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; margin-bottom: 10px; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.checklist li:last-child { border-bottom: 0; }
.checklist .val { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 12px; text-align: right; }
.ic { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; }
.ic.ok { background: #0ca30c; }
.ic.no { background: #d03b3b; }
.ic.na { background: var(--axis); color: var(--ink); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
.table-wrap.tall { max-height: 420px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .empty-row td { color: var(--muted); text-align: center; padding: 18px; }
.dir { font-weight: 700; font-size: 11px; padding: 2px 7px; border-radius: 5px; }
.dir.buy { background: color-mix(in srgb, var(--series) 14%, transparent); color: var(--series); }
.dir.sell { background: color-mix(in srgb, var(--neg-mark) 14%, transparent); color: var(--neg); }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; }
.settings-grid div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dashed var(--line); padding: 5px 0; font-size: 13px; }
.settings-grid span:first-child { color: var(--muted); }

/* ---------- backtest ---------- */
.bt-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.bt-form { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
.bt-results { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.fgroup { border: 0; padding: 0; margin: 0 0 14px; }
.fgroup legend { font-size: 11px; font-weight: 700; color: var(--gold-ink); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; padding: 0; }
.field { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
.field.wide { grid-template-columns: 1fr; }
.field label { color: var(--ink-2); }
.field input, .field select, .opt-form select, .opt-form input, .inline-num {
  font: inherit; font-size: 13px; width: 100%; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); min-width: 0;
}
.field input:focus, .field select:focus { outline: 2px solid color-mix(in srgb, var(--gold) 50%, transparent); outline-offset: 0; }
.field input[type="checkbox"] { width: 18px; height: 18px; justify-self: end; accent-color: var(--gold); }
.src-row { display: flex; gap: 6px; }
.src-row select { flex: 1; }
.form-actions { display: flex; flex-direction: column; gap: 8px; position: sticky; bottom: -16px; background: var(--surface); padding: 10px 0 4px; border-top: 1px solid var(--line); }
.form-actions .btn-primary { width: 100%; padding: 10px; font-size: 14px; }
.note { margin: 10px 0 0; }
.data-info { font-size: 13px; }

.heat { border-collapse: separate; border-spacing: 2px; font-size: 12px; font-variant-numeric: tabular-nums; width: 100%; }
.heat th { font-size: 11px; color: var(--muted); font-weight: 600; padding: 4px; }
.heat td { text-align: center; padding: 6px 4px; border-radius: 5px; min-width: 44px; cursor: default; }
.heat td.year { font-weight: 650; }
.heat td.none { color: var(--muted); }

.bd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.breakdown { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.breakdown > * { margin: 0 !important; }
.breakdown .bars-h .sub-h { margin-top: 0; }
@media (max-width: 1000px) { .breakdown { grid-template-columns: 1fr; } }
.bd-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.bd-box h4 { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.bd-row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.bars-h { margin-top: 12px; }
.bars-h .bar-row { display: grid; grid-template-columns: 80px 1fr 40px; gap: 8px; align-items: center; font-size: 12px; margin: 5px 0; }
.bars-h .bar-track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bars-h .bar-fill { height: 100%; background: var(--series); border-radius: 0 4px 4px 0; }

.opt-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.opt-axis { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.opt-axis .lbl { font-size: 11px; font-weight: 700; color: var(--gold-ink); text-transform: uppercase; letter-spacing: .6px; }
.opt-axis .range { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.opt-axis .range label { font-size: 11px; color: var(--muted); display: grid; gap: 2px; }
.opt-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.check input[type="checkbox"] { accent-color: var(--gold); }
.inline-num { width: 58px !important; display: inline-block; }
.progress { flex: 1; min-width: 120px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--gold); transition: width .1s; }
#optOut { margin-top: 14px; }
#optOut .heat td { cursor: pointer; }
#optOut .heat td.best { outline: 2px solid var(--ink); outline-offset: -2px; }
.opt-legend { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin: 6px 0 12px; }
.opt-legend .ramp { width: 160px; height: 8px; border-radius: 4px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 60; box-shadow: 0 8px 30px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .bt-layout { grid-template-columns: 1fr; }
  .bt-form { position: static; max-height: none; }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .brand-sub { display: none; }
  main { padding: 16px 16px 48px; }
  .kpi-value { font-size: 19px; }
  .bd-grid { grid-template-columns: 1fr; }
  .chart { height: 220px; }
}
