/* Layout: sticky top bar + centered work area (max 1280px); dense trading tables, cards only where a block is its own object.
   Tokens: the default follows the device (Classic Light / Midnight); a theme picked in Appearance overrides them inline. */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --sunk: #f6f8fa;
  --text: #1f2328;
  --muted: #59636e;
  --border: #d0d7de;
  --line: #eaeef2;
  --accent: #0969da;
  --on-accent: #ffffff;
  --gain: #1a7f37;
  --loss: #cf222e;
  --warn: #9a6700;
  --danger: #cf222e;
  --on-danger: #ffffff;
  --hover: rgba(31, 35, 40, 0.05);
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.16);
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #161b22; --sunk: #0d1117; --text: #e6edf3; --muted: #9198a1;
    --border: #30363d; --line: #21262d; --accent: #4493f8; --on-accent: #0d1117;
    --gain: #3fb950; --loss: #f85149; --warn: #d29922; --danger: #da3633; --on-danger: #ffffff;
    --hover: rgba(230, 237, 243, 0.06); --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --sunk: #0d1117; --text: #e6edf3; --muted: #9198a1;
  --border: #30363d; --line: #21262d; --accent: #4493f8; --on-accent: #0d1117;
  --gain: #3fb950; --loss: #f85149; --warn: #d29922; --danger: #da3633; --on-danger: #ffffff;
  --hover: rgba(230, 237, 243, 0.06); --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
a { color: var(--accent); }
h1, h2, h3 { text-wrap: balance; margin: 0; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.flat { color: var(--text); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.top-in {
  max-width: 1328px; margin: 0 auto; display: flex; align-items: center; gap: 8px 18px;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand svg { flex: none; }
.nav { display: flex; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 6px;
  color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--hover); }
.nav a.on { color: var(--text); background: var(--sunk); box-shadow: inset 0 -2px 0 var(--accent); }
.top-right { display: flex; align-items: center; gap: 8px; flex: none; }
.clock { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gain); display: inline-block; }
.dot.off { background: var(--muted); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--loss); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--sunk);
  font-weight: 700; font-size: 12.5px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px;
}
.menu a, .menu button {
  display: flex; width: 100%; align-items: center; gap: 8px; min-height: 38px; padding: 0 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); text-decoration: none; cursor: pointer; text-align: left;
}
.menu a:hover, .menu button:hover { background: var(--hover); }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.subnav { border-bottom: 1px solid var(--border); background: var(--surface); }
.subnav .nav { max-width: 1328px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.subnav .nav a { min-height: 40px; font-size: 13.5px; }
.banner { background: var(--danger); color: var(--on-danger); }
.banner .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-block: 8px; font-weight: 600; }
.banner .btn { background: transparent; color: var(--on-danger); border-color: currentColor; }
.proto { background: var(--sunk); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.proto .wrap { padding-block: 5px; display: flex; gap: 6px 16px; flex-wrap: wrap; }

/* ---------- page ---------- */
.wrap {
  max-width: 1328px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
main.wrap { padding-block: 20px 56px; display: flex; flex-direction: column; gap: 16px; }
.page-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.page-h .t { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.page-h .sub { color: var(--muted); font-size: 13px; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.side-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .side-layout { grid-template-columns: minmax(0, 1fr); } }
.side { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 76px; }
@media (max-width: 820px) { .side { position: static; flex-direction: row; overflow-x: auto; } }
.side .hd { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
@media (max-width: 820px) { .side .hd { display: none; } }
.side a { display: flex; align-items: center; min-height: 38px; padding: 0 10px; border-radius: 6px; color: var(--text); text-decoration: none; white-space: nowrap; }
.side a:hover { background: var(--hover); }
.side a.on { background: var(--sunk); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.card > .pad, .pad { padding: 16px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 6px 14px 6px 6px; min-height: 52px; }
.sec-h.plain { padding: 12px 16px; }
.tog {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 10px; border: 0; border-radius: 6px;
  background: transparent; font-weight: 600; font-size: 15px; cursor: pointer; text-align: left;
}
.tog:hover { background: var(--hover); }
.tog svg { transition: transform 0.15s; }
.tog[aria-expanded="false"] svg { transform: rotate(-90deg); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 600; }
.body { border-top: 1px solid var(--border); }
.label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.big { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi .s { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 13.5px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.pri:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.ghost-danger { color: var(--loss); border-color: color-mix(in srgb, var(--loss) 45%, var(--border)); }
.btn.xs { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.lg { min-height: 44px; padding: 0 18px; font-size: 14.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.pills { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--sunk); border: 1px solid var(--border); flex-wrap: wrap; }
.pills button { min-height: 30px; min-width: 40px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer; }
.pills button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
select, input[type=text], input[type=email], input[type=number], input[type=password], input[type=time], input[type=date], textarea {
  min-height: 36px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; background: var(--surface); color: var(--text); font-size: 13.5px; max-width: 100%;
}
textarea { padding: 8px 10px; min-height: 80px; resize: vertical; width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .lab { font-size: 12.5px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.field input, .field select { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 16px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .tr { width: 38px; height: 22px; border-radius: 11px; background: var(--border); position: relative; transition: background 0.15s; flex: none; }
.switch .tr::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform 0.15s; }
.switch input:checked + .tr { background: var(--accent); }
.switch input:checked + .tr::after { transform: translateX(16px); }
.switch input:focus-visible + .tr { outline: 2px solid var(--accent); outline-offset: 2px; }
.chk { display: flex; align-items: center; gap: 10px; min-height: 34px; cursor: pointer; }
.chk input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---------- chips ---------- */
.mode { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; padding: 2px 6px; border-radius: 4px; line-height: 1.3; vertical-align: 1px; white-space: nowrap; }
.mode.live { background: var(--text); color: var(--bg); border: 1px solid var(--text); }
.mode.paper { background: transparent; color: var(--text); border: 1px solid var(--muted); }
button.mode-switch { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; font-weight: 600; font-size: 12.5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.chip.good { color: var(--gain); border-color: color-mix(in srgb, var(--gain) 40%, transparent); background: color-mix(in srgb, var(--gain) 9%, transparent); }
.chip.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.chip.bad { color: var(--loss); border-color: color-mix(in srgb, var(--loss) 40%, transparent); background: color-mix(in srgb, var(--loss) 9%, transparent); }

/* ---------- tables ---------- */
.tw { overflow-x: auto; position: relative; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th {
  font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; text-align: left;
  padding: 9px 10px 7px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: bottom; background: var(--sunk);
}
.tbl th .s { display: block; margin-top: 2px; font-weight: 500; text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.tbl th:first-child, .tbl td:first-child { padding-left: 16px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 16px; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--hover); }
.tbl .r { text-align: right; }
.tbl tfoot td { border-top: 1px solid var(--border); border-bottom: 0; background: var(--sunk); padding-block: 11px; }
.tbl.simple td { vertical-align: middle; }
.v1 { display: block; font-weight: 600; }
.v2 { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pnl1 { display: block; font-weight: 700; font-size: 14.5px; }
.pnl2 { display: block; font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.acts { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 18px 16px; color: var(--muted); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.flash { animation: flash 0.9s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 10%, transparent); } to { background: transparent; } }

/* ---------- charts ---------- */
.chart { width: 100%; height: 240px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-l { stroke: var(--line); }
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 4px; }
.heat div { aspect-ratio: 1; border-radius: 4px; max-width: 100%; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 200px) 1fr 90px; gap: 12px; align-items: center; }
.bar-track { height: 10px; background: var(--sunk); border-radius: 5px; position: relative; overflow: hidden; }
.bar-track span { position: absolute; top: 0; bottom: 0; border-radius: 5px; }

/* ---------- strategy cards ---------- */
.strat { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.strat-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.strat-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px 0; border-block: 1px solid var(--line); }
.strat-stats div { display: flex; flex-direction: column; gap: 2px; }
.strat-f { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.spark { width: 100%; height: 44px; display: block; }

/* ---------- theme tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 8px; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-align: left; }
.tile[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile .sw { display: block; height: 70px; border-radius: 6px; position: relative; padding: 8px; border: 1px solid rgba(127,127,127,.25); }
.tile .nm { display: flex; justify-content: space-between; font-size: 13px; }

/* ---------- modal / drawer / toast ---------- */
.scrim { position: fixed; inset: 0; background: rgba(1, 4, 9, 0.5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); color: var(--text); border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); width: min(520px, 100%); max-height: calc(100% - 32px); overflow: auto; }
.modal.wide { width: min(760px, 100%); }
.modal-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-b { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { width: 34px; height: 34px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; font-size: 20px; color: var(--muted); }
.x:hover { background: var(--hover); }
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; max-width: 360px; animation: up 0.2s ease-out; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.steps li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.tick { width: 22px; height: 22px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; border: 1.5px solid var(--border); color: var(--muted); }
.tick.ok { background: var(--gain); border-color: var(--gain); color: var(--bg); }
.progress { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.callout { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--sunk); font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.callout.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 860px) { .auth { grid-template-columns: minmax(0, 1fr); } .auth .art { display: none; } }
.auth .art { background: var(--sunk); border-right: 1px solid var(--border); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 24px; }
.auth .form { display: flex; align-items: center; justify-content: center; padding: 32px max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px)); }
.auth .box { width: min(400px, 100%); display: flex; flex-direction: column; gap: 16px; }
.code-in { display: flex; gap: 8px; }
.code-in input { width: 44px; height: 48px; text-align: center; font-size: 20px; font-weight: 600; padding: 0; }

@media (max-width: 900px) {
  .clock { display: none; }
  .top-in { flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; }
  .top-right { margin-left: auto; }
}
@media (max-width: 520px) {
  .kpi { border-right: 0; border-bottom: 1px solid var(--line); }
  .bar-row { grid-template-columns: minmax(0, 1fr) 80px; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
