:root {
  --bg: #f5f6f8; --card: #fff; --text: #14171c; --muted: #6b7280; --line: #e3e6ea;
  --green: #0f8a4a; --red: #c62828; --amber: #b26a00; --blue: #2563eb;
  --chip-bg: #eef0f3; --itm: #fbf7e6; --atm: #e7efff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b21; --text: #e8eaed; --muted: #9aa1ab; --line: #2a2f37;
    --green: #3ecf7a; --red: #ff6b6b; --amber: #f0b44c; --blue: #6ea2ff;
    --chip-bg: #252a32; --itm: #262315; --atm: #1b2740;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.err { color: var(--red); min-height: 1em; margin: 8px 0 0; font-size: 14px; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--chip-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--blue); color: #fff; border-color: var(--blue); width: 100%; }
button.danger { background: var(--red); color: #fff; border-color: var(--red); }
button.link { background: none; border: 0; color: var(--muted); padding: 8px; }
button.small-btn { padding: 6px 10px; font-size: 13px; }
select, input { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; }
input { width: 100%; font-size: 16px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 10px; }

main { max-width: 900px; margin: 0 auto; padding: 0 12px calc(24px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex;
  align-items: center; justify-content: space-between; padding: 10px 0 8px; }
.tabs { display: flex; gap: 6px; }
.tab { border-radius: 999px; padding: 8px 16px; }
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.summary { display: flex; justify-content: space-between; align-items: end; margin: 6px 2px 12px; }
.big { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); } .neg { color: var(--red); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 12px; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 10px; }

.run-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.run-name { font-weight: 650; font-size: 16px; }
.run-pnl { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip-bg); }
.chip.live { background: var(--red); color: #fff; font-weight: 600; }
.chip.ok { color: var(--green); } .chip.warn { color: var(--amber); } .chip.bad { color: var(--red); font-weight: 600; }
.legs { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0;
  font-variant-numeric: tabular-nums; }
.legs th, .legs td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.legs th:first-child, .legs td:first-child { text-align: left; word-break: break-all; }
.legs th, .legs td { padding: 5px 3px; }
.legs th { color: var(--muted); font-weight: 500; }
.run-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }
.why { font-size: 12px; color: var(--muted); flex: 1; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

.day { border-top: 1px solid var(--line); padding: 10px 0; }
.day:first-child { border-top: 0; padding-top: 0; }
.day-head { display: flex; justify-content: space-between; align-items: center; }
.idxrow { display: grid; grid-template-columns: 70px 1fr; gap: 4px; font-size: 13px; margin-top: 4px; }
.errs { font-size: 12px; color: var(--red); margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; align-items: center; }
.controls select { flex: 1 1 110px; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 7px 12px; background: var(--card); }
.seg button.on { background: var(--text); color: var(--bg); }
.chainhead { margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tablewrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 10px; }
#chainTable { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
#chainTable th, #chainTable td { padding: 6px 5px; text-align: right; white-space: nowrap; }
#chainTable thead th { position: sticky; top: 0; background: var(--card); color: var(--muted);
  font-weight: 500; border-bottom: 1px solid var(--line); z-index: 1; }
#chainTable td.k { text-align: center; font-weight: 650; background: var(--chip-bg); }
#chainTable th.k { text-align: center; }
#chainTable tr.atm td { background: var(--atm); }
#chainTable td.itm { background: var(--itm); }
#chainTable tbody tr { cursor: pointer; border-bottom: 1px solid var(--line); }
.side-label th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex;
  align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
@media (min-width: 600px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
.sheet .row { display: flex; gap: 10px; margin-top: 14px; }
.sheet .row button { flex: 1; }
.sheet label { display: block; margin: 12px 0 6px; font-weight: 600; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 14px;
  font-variant-numeric: tabular-nums; }
.kv div:nth-child(odd) { color: var(--muted); }
.warnbox { background: var(--chip-bg); border-left: 3px solid var(--red); padding: 8px 10px;
  border-radius: 6px; font-size: 14px; margin: 8px 0; }
#chainTable td .sub { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
#chainTable td.itm { background: var(--itm); }
