/* Strategy Tester -- stocks/backtester/web
   Light theme in the EOC portal's palette (~/eoc-portal/app/globals.css): cream background,
   sage borders, forest-green primary, navy secondary, burgundy for losses. The chart colors in
   app.js (THEME) mirror these. */
:root {
  --bg: #f3f4ec;
  --card: #fdfcf7;
  --card-2: #f6f8f1;
  --white: #ffffff;
  --line: #d4ddca;
  --line-2: #c3cfb6;
  --line-soft: #e7ecdf;
  --ink: #1d2518;
  --muted: #506046;
  --faint: #7d8a73;
  --primary: #1e5b34;
  --primary-hover: #17472a;
  --primary-soft: #e8f5eb;
  --primary-soft-line: #cbe6d0;
  --secondary: #2b4c7e;
  --green: #1e5b34;
  --red: #8c2f39;
  --amber: #b26a00;
  --th: #ecf2e3;
  --row-hover: #f1f6ea;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  color: var(--ink); font: 13px/1.45 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden;
  background:
    radial-gradient(circle at 15% -20%, #f7e9ca 0%, transparent 40%),
    radial-gradient(circle at 88% 0%, #d7e8f2 0%, transparent 35%),
    var(--bg);
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.num, td.n, .kpi .v { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------------ top bar */
.topbar {
  height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: rgba(253, 252, 247, 0.92); border-bottom: 1px solid var(--line);
  border-top: 3px solid var(--primary);
}
.brand { font-weight: 700; font-size: 14px; letter-spacing: .2px; white-space: nowrap; display: flex; align-items: center; gap: 9px; color: var(--ink); }
.brand .logo { width: 20px; height: 20px; border-radius: 6px; background: linear-gradient(135deg, var(--primary), #4f7a5c); display: inline-block; }
.brand .brand-sub { color: var(--muted); font-weight: 450; font-size: 12px; }
.tabs { display: flex; align-items: center; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tab {
  display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 8px 0 11px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card);
  color: var(--muted); cursor: pointer; white-space: nowrap; max-width: 270px;
}
.tab:hover { border-color: var(--primary); color: var(--ink); }
.tab .t { overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-soft-line); font-weight: 600; }
.tab .x { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0 2px; font-size: 15px; line-height: 1; }
.tab .x:hover { color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; }
.dot.queued { background: var(--amber); }
.dot.running { background: var(--secondary); animation: pulse 1s infinite ease-in-out; }
.dot.done { background: var(--green); }
.dot.error { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }
.addtab { height: 32px; width: 32px; border-radius: 999px; border: 1px dashed var(--line-2); background: none; color: var(--muted); cursor: pointer; font-size: 17px; flex: none; }
.addtab:hover { color: var(--primary); border-color: var(--primary); }
.top-right { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.workers { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; min-width: 150px; justify-content: flex-end; }

button.ghost, button.primary, button.small {
  height: 32px; padding: 0 13px; border-radius: 10px; cursor: pointer; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
}
button.ghost:hover, button.small:hover { border-color: var(--primary); }
button.ghost.on { background: var(--primary-soft); border-color: var(--primary-soft-line); color: var(--primary); font-weight: 600; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--primary-hover); }
button:disabled { opacity: .5; cursor: default; }
button.small { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 8px; }
button.link { background: none; border: 0; color: var(--secondary); cursor: pointer; padding: 0; font-size: 12px; }
button.link:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ main / tester layout */
main { height: calc(100% - 52px); position: relative; }
.tester { display: grid; grid-template-columns: 352px 1fr; height: 100%; }
.settings {
  background: var(--card); border-right: 1px solid var(--line); overflow-y: auto;
  padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 10px;
}
.settings label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 4px; font-weight: 500; }
.settings input:not([type=checkbox]), .settings select {
  width: 100%; height: 32px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--white); color: var(--ink); outline: none;
}
.settings input:hover, .settings select:hover { border-color: var(--line-2); }
.settings input:focus, .settings select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30, 91, 52, .12); }
.settings input[type=date] { padding-right: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.desc { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.desc.err { color: var(--red); }
.cov { margin: -4px 0 0; color: var(--muted); font-size: 12px; min-height: 17px; }
.ext-box { border: 1px solid var(--line); border-radius: 12px; padding: 8px 11px; background: var(--card-2); display: flex; flex-direction: column; gap: 8px; margin-top: -2px; }
.ext-box > .check { font-weight: 600; }
.ext-box.on { background: var(--primary-soft); border-color: var(--primary-soft-line); }
.ext-opts { display: flex; flex-direction: column; gap: 8px; padding-bottom: 2px; }
.ext-tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #fff4e0; border: 1px solid #f0d7a6; color: #8a5300; }
.presets { display: flex; gap: 4px; flex-wrap: wrap; margin-top: -4px; }
.presets button { height: 23px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--white); color: var(--muted); cursor: pointer; font-size: 11px; }
.presets button:hover { color: var(--primary); border-color: var(--primary); }
details.group { border: 1px solid var(--line); border-radius: 12px; padding: 0 11px; background: var(--card-2); }
details.group > summary { cursor: pointer; padding: 9px 0; font-weight: 600; font-size: 12.5px; color: var(--ink); list-style: none; display: flex; justify-content: space-between; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "+"; color: var(--muted); }
details.group[open] > summary::after { content: "–"; }
details.group > .body { padding: 2px 0 11px; display: flex; flex-direction: column; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink); cursor: pointer; text-transform: none !important; letter-spacing: 0 !important; }
.check input { accent-color: var(--primary); }
.hint { font-size: 11px; color: var(--faint); margin: -2px 0 0; }
.runbar { display: flex; gap: 8px; position: sticky; bottom: -16px; background: var(--card); padding: 8px 0 4px; }
.runbar .primary { flex: 1; height: 38px; font-size: 14px; }
.runbar .ghost { height: 38px; }
.status { font-size: 12px; color: var(--muted); min-height: 30px; }
.status .bar { height: 4px; background: var(--line-soft); border-radius: 2px; overflow: hidden; margin-bottom: 5px; }
.status .bar i { display: block; height: 100%; width: 0; background: var(--secondary); transition: width .25s; }
.status.error span { color: var(--red); }
.status.done .bar i { background: var(--green); }

.results { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.res-head { padding: 11px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 48px; background: rgba(253, 252, 247, .6); }
.res-head .title { font-weight: 700; font-size: 15px; }
.res-head .meta { color: var(--muted); font-size: 12px; }
.res-head .rid, .rid { font-family: var(--mono); font-size: 11px; color: var(--muted); cursor: pointer; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; background: #f8faf3; }
.rid:hover { border-color: var(--primary); color: var(--primary); }
.res-head .spacer { flex: 1; }
.subtabs { display: flex; gap: 2px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--card-2); }
.subtabs button { border: 0; background: none; padding: 10px 13px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; }
.subtabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.subtabs button:hover { color: var(--ink); }
.subviews { flex: 1; overflow: auto; position: relative; }
.sub { padding: 16px 18px 26px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ------------------------------------------------------------------ report */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: linear-gradient(180deg, #fdfcf7 0%, #f4f7ec 100%); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 21px; font-weight: 650; margin-top: 3px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.groups { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 12px; }
.groups.g4 { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
@media (min-width: 1700px) { .groups.g4 { grid-template-columns: repeat(4, minmax(220px, 1fr)); } }
.group-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 12px; }
.group-card h3 { font-size: 12px; margin: 2px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; text-align: right; }
.runinfo { margin-top: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.runinfo .settings-used { flex-basis: 100%; }
.runinfo a, .tbl-bar a { color: var(--secondary); text-decoration: none; }
.runinfo a:hover, .tbl-bar a:hover { text-decoration: underline; }
.warnbox { background: #fde9ec; border: 1px solid #e7adb8; color: #7b2030; border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }

/* ------------------------------------------------------------------ tables */
.tbl-wrap { border: 1px solid var(--line); border-radius: 12px; overflow: auto; background: var(--white); }
table.t { border-collapse: collapse; width: 100%; font-size: 12px; }
table.t th { position: sticky; top: 0; background: var(--th); color: var(--ink); font-weight: 600; text-align: right; padding: 8px 10px; white-space: nowrap; cursor: pointer; user-select: none; border-bottom: 1px solid var(--line); z-index: 1; }
table.t th:hover { background: #e1ecd2; }
table.t th.l, table.t td.l { text-align: left; }
table.t th.sorted { color: var(--primary); }
table.t td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
table.t tbody tr:hover { background: var(--row-hover); }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.open-trade td { background: #fff8ea; }
.tbl-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.tbl-bar .spacer { flex: 1; }
.pager { display: flex; gap: 6px; align-items: center; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid; }
.tag.long, .tag.BUY, .tag.COVER { background: #e8f5eb; border-color: #cbe6d0; color: #1e5b34; }
.tag.short, .tag.SELL, .tag.SHORT { background: #fde9ec; border-color: #f2bcc5; color: #7b2030; }

/* ------------------------------------------------------------------ plots */
.plot { width: 100%; height: 600px; background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 6px 4px 0; }
.chart-note { color: var(--muted); font-size: 12px; margin-bottom: 6px; min-height: 17px; }
pre.journal { font-family: var(--mono); font-size: 12px; line-height: 1.6; white-space: pre-wrap; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0; }

/* ------------------------------------------------------------------ optimize */
.opt-grid { display: grid; grid-template-columns: minmax(420px, 640px) 1fr; gap: 14px; align-items: start; }
.opt-form { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.opt-form table { width: 100%; border-collapse: collapse; font-size: 12px; }
.opt-form th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.opt-form td { padding: 3px 6px; }
.opt-form input:not([type=checkbox]), .opt-form select { width: 100%; height: 30px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--white); color: var(--ink); outline: none; }
.opt-form input:focus, .opt-form select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30, 91, 52, .12); }
.opt-form .row2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.opt-form label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.opt-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.opt-help { color: var(--muted); font-size: 12px; line-height: 1.55; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.opt-help b { color: var(--ink); }
.opt-summary { margin: 14px 0 10px; color: var(--muted); font-size: 12px; }
.opt-summary b { color: var(--ink); }

/* ------------------------------------------------------------------ compare / history views */
.view { position: absolute; inset: 0; overflow: auto; padding: 18px 20px 30px; }
.view h2 { font-size: 18px; margin: 0 0 4px; }
.view .lead { color: var(--muted); margin: 0 0 14px; font-size: 12.5px; }
table.cmp td.best { color: var(--green); font-weight: 700; background: #f1f8f0; }
table.cmp td:first-child, table.cmp th:first-child { text-align: left; color: var(--muted); position: sticky; left: 0; background: var(--white); }
table.cmp th:first-child { background: var(--th); }

@media (max-width: 1250px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .groups { grid-template-columns: 1fr 1fr; }
  .opt-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .tester { grid-template-columns: 1fr; height: auto; }
  .settings { border-right: 0; border-bottom: 1px solid var(--line); }
  .results { height: auto; }
  .groups, .groups.g4 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .brand .brand-sub, .workers { display: none; }
  main { height: auto; }
}
