/* DayTrade Engine - dashboard layout. Colors are tokens; canvas charts read them too. */
:root { color-scheme: light dark; }
[hidden] { display: none !important; }
* { box-sizing: border-box; }

:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #eceef4;
  --ink: #121521;
  --ink-2: #4a5263;
  --ink-3: #8a92a5;
  --line: #e4e7ee;
  --line-strong: #d0d5df;
  --accent: #6d5dfc;
  --accent-deep: #5745ec;
  --accent-soft: rgba(109, 93, 252, 0.12);
  --gold: #f59e0b;
  --gold-bg: #fff5de;
  --red: #e5484d;
  --red-bg: #fdecec;
  --pos: #0e9f6e;
  --pos-soft: rgba(14, 159, 110, 0.14);
  --neg: #e5484d;
  --neg-soft: rgba(229, 72, 77, 0.14);
  --candle-up: #12b886;
  --candle-dn: #f0506e;
  --s1: #6d5dfc; --s2: #f59e0b; --s3: #ec4899; --s4: #06b6d4; --s5: #84cc16; --s6: #a855f7;
  --shadow: 0 1px 2px rgba(18, 21, 33, 0.04), 0 4px 14px rgba(18, 21, 33, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 400px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --serif: var(--sans);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c11;
    --surface: #11141b;
    --surface-2: #161a23;
    --surface-3: #1d222d;
    --ink: #e9ecf3;
    --ink-2: #a4acbe;
    --ink-3: #6c7589;
    --line: #20242f;
    --line-strong: #2d3342;
    --accent: #8b7dff;
    --accent-deep: #a397ff;
    --accent-soft: rgba(139, 125, 255, 0.16);
    --gold: #fbbf24;
    --gold-bg: #2a2110;
    --red: #ff6b70;
    --red-bg: #2c1417;
    --pos: #34d399;
    --pos-soft: rgba(52, 211, 153, 0.14);
    --neg: #ff6b70;
    --neg-soft: rgba(255, 107, 112, 0.16);
    --candle-up: #2dd4a0;
    --candle-dn: #ff5c7a;
    --s1: #8b7dff; --s2: #fbbf24; --s3: #f472b6; --s4: #22d3ee; --s5: #a3e635; --s6: #c084fc;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0a0c11; --surface: #11141b; --surface-2: #161a23; --surface-3: #1d222d;
  --ink: #e9ecf3; --ink-2: #a4acbe; --ink-3: #6c7589; --line: #20242f; --line-strong: #2d3342;
  --accent: #8b7dff; --accent-deep: #a397ff; --accent-soft: rgba(139, 125, 255, 0.16);
  --gold: #fbbf24; --gold-bg: #2a2110; --red: #ff6b70; --red-bg: #2c1417;
  --pos: #34d399; --pos-soft: rgba(52, 211, 153, 0.14); --neg: #ff6b70; --neg-soft: rgba(255, 107, 112, 0.16);
  --candle-up: #2dd4a0; --candle-dn: #ff5c7a;
  --s1: #8b7dff; --s2: #fbbf24; --s3: #f472b6; --s4: #22d3ee; --s5: #a3e635; --s6: #c084fc;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- Form controls ---------- */
input[type="number"], input[type="text"], input[type="time"], select, textarea {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 6px 8px; width: 100%; min-width: 0; height: 32px;
}
input:hover, select:hover { border-color: var(--ink-3); }
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input:disabled { opacity: 0.45; }

button {
  font-family: var(--sans); font-size: 13px; font-weight: 600; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.ghost { background: transparent; }
button.sm { padding: 4px 10px; font-size: 12px; font-weight: 500; }
button.icon { width: 30px; padding: 3px 0; font-size: 17px; line-height: 1; }

/* ---------- Top bar ---------- */
.topbar {
  position: relative; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.brand svg { color: #fff; background: linear-gradient(135deg, var(--accent), var(--s3)); border-radius: 7px; padding: 3px; width: 26px; height: 26px; }
.controls { display: flex; align-items: flex-end; gap: 8px; flex: 1 1 auto; flex-wrap: wrap; }
.ctl { display: flex; flex-direction: column; gap: 3px; }
.ctl > span { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.ctl.sym { width: 112px; } .ctl.sym input { text-transform: uppercase; font-weight: 600; }
.ctl.prov { width: 96px; } .ctl.iv { width: 70px; } .ctl.n { width: 82px; } .ctl.cap { width: 100px; } .ctl.seed { width: 86px; }
button.run {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 16px; margin-left: 4px;
  background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 14px -6px var(--accent);
}
button.run:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }
button.run:disabled { opacity: 0.6; cursor: progress; }
.toplink { color: var(--ink-3); text-decoration: none; font-size: 13px; font-weight: 500; }
.toplink:hover { color: var(--accent); }

.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; }
.progress.busy > i { width: 30%; background: linear-gradient(90deg, transparent, var(--accent), var(--s3), transparent); animation: te-slide 1s ease-in-out infinite; }
@keyframes te-slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

.statusbar {
  display: flex; align-items: center; gap: 8px; padding: 5px 18px;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
  background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.statusbar .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 3px var(--pos-soft); flex: none; }
.statusbar b { color: var(--ink); font-weight: 600; }
.statusbar .err { color: var(--neg); }
.statusbar:has(.err) .dot { background: var(--neg); box-shadow: 0 0 0 3px var(--neg-soft); }

/* ---------- Layout ---------- */
body.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.layout { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar { overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); scrollbar-width: thin; }
.main { overflow-y: auto; padding: 18px 22px 10px; min-width: 0; scrollbar-width: thin; }

/* ---------- Sidebar sections ---------- */
.sect { border-bottom: 1px solid var(--line); }
.sect > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; user-select: none;
}
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary::before {
  content: ""; width: 7px; height: 7px; flex: none; margin: 0 2px 0 1px;
  border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(-45deg); transition: transform 0.15s ease;
}
.sect[open] > summary::before { transform: rotate(45deg); margin-top: -3px; }
.sect > summary:hover { background: var(--surface-2); }
.sect .t { font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.sect .meta {
  margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.sect-body { padding: 0 16px 16px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 7px 0; }
.row label { color: var(--ink-2); font-size: 13px; }
.row > select, .row > input { width: 150px; flex: none; }
.row .pair { display: flex; gap: 6px; flex: none; }
.row .pair select { width: 118px; }
.row .pair input { width: 64px; }
.hint { font-size: 12px; color: var(--ink-3); margin: 10px 0 0; line-height: 1.45; }
.hint.top { margin: 0 0 10px; }
.hint:empty { display: none; }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset {
  text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; font-weight: 500; color: var(--ink);
}
.preset b { display: block; font-size: 12.5px; font-weight: 600; }
.preset span {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 11px; color: var(--ink-3); font-weight: 400; line-height: 1.35; margin-top: 2px;
}
.preset:hover { color: var(--ink); border-color: var(--accent); }
.preset.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.lib { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.lib-btns { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }

/* rule builder */
.rules { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; margin-top: 8px; background: var(--surface); position: relative; }
.rules::before { content: ""; position: absolute; left: -1px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; }
.rules.long::before { background: var(--pos); }
.rules.short::before { background: var(--neg); }
.rules-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.rules-head .logic { width: auto; height: 28px; padding: 3px 6px; font-size: 11.5px; margin-left: auto; }
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; cursor: pointer; }
.toggle.sm { font-size: 12px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.toggle input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.cond-list { display: flex; flex-direction: column; gap: 6px; }
.cond-list.off { opacity: 0.4; pointer-events: none; }
.cond {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 7px;
}
.cond select, .cond input { width: auto; height: 28px; padding: 3px 6px; font-size: 11.5px; }
.cond .opnd { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.cond .opnd select.src { max-width: 170px; }
.cond .opnd input.p { width: 52px; }
.cond .opnd .pl { font-family: var(--mono); font-size: 10px; color: var(--ink-3); text-transform: uppercase; }
.cond .cmp { font-weight: 600; color: var(--accent); }
.cond .rm { border: none; background: transparent; color: var(--ink-3); font-size: 16px; line-height: 1; padding: 2px 6px; margin-left: auto; }
.cond .rm:hover { color: var(--neg); }
.rules .add { margin-top: 8px; padding: 4px 10px; font-size: 12px; font-weight: 500; background: transparent; border-style: dashed; }
.rules .empty { font-size: 12px; color: var(--ink-3); margin: 2px 0; }

.disclaim { padding: 16px; margin: 0; font-size: 11.5px; line-height: 1.55; color: var(--ink-3); }
.disclaim strong { color: var(--ink-2); }

/* ---------- Main: results ---------- */
.main-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.main-head h1 { font-size: 20px; }
.main-head .note { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; min-width: 0; box-shadow: var(--shadow); }
.tile .k { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.tile .v { font-family: var(--mono); font-size: 18px; font-weight: 600; margin-top: 1px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; white-space: nowrap; }
.tile .s { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.hero {
  grid-column: span 2; color: #fff; border: 0;
  background: linear-gradient(135deg, var(--accent) 0%, var(--s6) 55%, var(--s3) 100%);
  box-shadow: 0 10px 24px -14px var(--accent);
}
.tile.hero .v { font-size: 24px; }
.tile.hero { grid-row: span 2; display: flex; flex-direction: column; justify-content: center; }
.tile.hero .k, .tile.hero .s { color: rgba(255, 255, 255, 0.82); }
.v.pos { color: var(--pos); }
.v.neg { color: var(--neg); }

.msg, .warn { border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; line-height: 1.5; margin-bottom: 10px; border: 1px solid; }
.msg { grid-column: 1 / -1; background: var(--red-bg); border-color: var(--red); }
.warn { background: var(--gold-bg); border-color: color-mix(in srgb, var(--gold) 55%, transparent); }
.warn::before { content: "\26A0\FE0E  "; color: var(--gold); font-weight: 700; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 14px; }
.panel-head .csub { flex: 1 1 auto; margin: 0; }
.chart-panel .pane { padding: 10px 14px 12px; }
.pane-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 8px; }
.csub { font-size: 12px; color: var(--ink-3); margin: 0; }

.tabs { display: inline-flex; gap: 2px; background: var(--surface-3); border-radius: 9px; padding: 3px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; color: var(--ink-2); padding: 5px 12px; font-size: 12.5px; font-weight: 500; border-radius: 7px; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.tabs.small { margin-left: auto; }
.tabs.small button { padding: 3px 9px; font-size: 11.5px; }

.replay-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.replay-nav select { width: auto; height: 30px; }

.chart-holder { position: relative; width: 100%; }
canvas { display: block; width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; color: var(--ink-2); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ln { width: 16px; height: 0; border-top-width: 2px; border-top-style: solid; display: inline-block; }
.bx { width: 12px; height: 10px; border-radius: 2px; display: inline-block; }
.mk { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; display: inline-block; }
.mk.up { border-bottom: 8px solid var(--pos); }
.mk.dn { border-top: 8px solid var(--neg); }
.mk.x { width: 9px; height: 9px; border: 2px solid var(--ink-2); border-radius: 50%; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; opacity: 0; transition: opacity 0.08s;
  background: var(--ink); color: var(--bg); font-family: var(--mono); font-size: 11px; line-height: 1.5;
  padding: 6px 9px; border-radius: 7px; white-space: nowrap; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.mc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.mc-stats div { font-size: 11.5px; color: var(--ink-3); background: var(--surface-2); border-radius: var(--radius-sm); padding: 7px 10px; }
.mc-stats b { display: block; font-family: var(--mono); font-size: 14px; color: var(--ink); font-weight: 600; }

.bottom { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 14px; align-items: start; }
.bottom .panel { margin-bottom: 14px; }
.break-panel .pane { padding: 4px 6px 8px; overflow-x: auto; }

table.data { border-collapse: collapse; width: 100%; font-family: var(--mono); font-size: 12px; }
table.data th, table.data td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-3); font-family: var(--sans); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; background: var(--surface); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.pos { color: var(--pos); }
table.data td.neg { color: var(--neg); }
.tradewrap { max-height: 420px; overflow: auto; }
table.trades tbody tr { cursor: pointer; }
table.trades tbody tr:hover td { background: var(--accent-soft); }
table.trades th { cursor: pointer; user-select: none; }
table.trades th:hover { color: var(--accent); }

.foot { font-size: 11.5px; color: var(--ink-3); padding: 6px 0 12px; }
.foot a { color: var(--ink-2); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root { --sidebar: 360px; }
  .bottom { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  body.app { height: auto; overflow: visible; }
  .layout { display: block; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .main { overflow: visible; padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px 14px; }
  .statusbar { padding: 5px 16px; white-space: normal; }
}
@media (max-width: 560px) {
  .controls { display: grid; grid-template-columns: 1fr 1fr; }
  .ctl.prov, .ctl.sym, .ctl.iv, .ctl.n, .ctl.cap, .ctl.seed { width: auto; }
  button.run { grid-column: 1 / -1; justify-content: center; margin: 4px 0 0; }
  .tile.hero { grid-column: 1 / -1; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .row > select, .row > input { width: 132px; }
  .row .pair select { width: 104px; }
  .presets { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .progress.busy > i { animation: none; width: 100%; opacity: 0.5; }
}

/* ---------- Document pages (guide.html) ---------- */
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 20px; }
.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }
.masthead .wrap { padding-top: 22px; padding-bottom: 22px; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
h1.title { font-size: clamp(26px, 4vw, 36px); line-height: 1.15; letter-spacing: -0.02em; }
.title .of { color: var(--accent); }
.site-footer { border-top: 1px solid var(--line); }
.site-footer p { margin: 0; padding: 16px 0; font-size: 11.5px; color: var(--ink-3); }
.site-footer a { color: var(--ink-2); }
