:root {
  color-scheme: dark;
  --bg: #08110f;
  --surface: #101c19;
  --surface-2: #152521;
  --line: #294039;
  --text: #f2f5ed;
  --muted: #9bada6;
  --accent: #91e6bd;
  --accent-strong: #38c88b;
  --warning: #f1c66b;
  --danger: #ff8f85;
  --shadow: 0 24px 70px rgb(0 0 0 / 28%);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -10%, rgb(56 200 139 / 15%), transparent 33rem),
    radial-gradient(circle at -10% 30%, rgb(55 124 102 / 11%), transparent 28rem),
    var(--bg);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 20; padding: .7rem 1rem; color: #07100e; background: var(--accent); border-radius: .5rem; }
.skip-link:focus { top: 1rem; }
.topbar { height: 74px; padding: 0 max(1.25rem, calc((100vw - 1240px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgb(8 17 15 / 82%); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; color: #07100e; background: var(--accent); border-radius: 11px; font-weight: 900; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 1.05rem; letter-spacing: .02em; }
.brand div span { color: var(--muted); font-size: .75rem; }
.mode { display: flex; align-items: center; gap: .6rem; color: var(--accent); font-size: .82rem; font-weight: 650; }
.mode > span { width: 7px; height: 7px; background: var(--accent-strong); border-radius: 50%; box-shadow: 0 0 0 5px rgb(56 200 139 / 12%); }

.shell { width: min(1240px, calc(100% - 2.5rem)); margin: 0 auto; padding: 3.5rem 0 2rem; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { max-width: 700px; margin-bottom: .55rem; font-size: clamp(2.1rem, 5vw, 4.2rem); line-height: 1.02; letter-spacing: -.055em; }
h2 { margin-bottom: 0; font-size: 1.25rem; letter-spacing: -.02em; }
.intro { max-width: 680px; margin-bottom: 0; color: var(--muted); }
.health-card { min-width: 285px; padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .22rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.health-card > span { color: var(--muted); font-size: .78rem; }
.health-line { display: flex; align-items: center; gap: .55rem; }
.status-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; }
.status-dot.ok { background: var(--accent-strong); box-shadow: 0 0 0 5px rgb(56 200 139 / 12%); }
.status-dot.waiting { background: var(--warning); box-shadow: 0 0 0 5px rgb(241 198 107 / 12%); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 5px rgb(255 143 133 / 12%); }
.alert { margin-bottom: 1rem; padding: .9rem 1rem; display: flex; gap: .5rem; flex-wrap: wrap; color: #ffd5d1; background: rgb(141 53 47 / 25%); border: 1px solid rgb(255 143 133 / 38%); border-radius: 10px; }

.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: .8rem; margin-bottom: .8rem; }
.metric { min-width: 0; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; }
.metric.primary { background: linear-gradient(145deg, #19372d, #10211c); border-color: #386953; }
.metric > span { display: block; overflow: hidden; color: var(--muted); font-size: .72rem; white-space: nowrap; text-overflow: ellipsis; }
.metric strong { display: block; margin: .38rem 0 .16rem; overflow-wrap: anywhere; font-size: clamp(1.08rem, 1.6vw, 1.48rem); letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.metric small { display: block; overflow: hidden; color: var(--muted); font-size: .7rem; white-space: nowrap; text-overflow: ellipsis; }
.positive { color: var(--accent); }
.negative { color: var(--danger); }

.panel { min-width: 0; padding: 1.25rem; background: rgb(16 28 25 / 94%); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); }
.chart-panel { margin-bottom: .8rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.tag { padding: .28rem .58rem; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; font-size: .7rem; white-space: nowrap; }
.tag-ok { color: var(--accent); border-color: rgb(56 200 139 / 45%); }
.tag-error { color: var(--danger); border-color: rgb(255 143 133 / 45%); }
#pnl-chart { width: 100%; min-height: 190px; display: block; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-zero { stroke: #81928c; stroke-width: 1; stroke-dasharray: 5 6; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#chart-gradient); }
.chart-point { fill: var(--bg); stroke: var(--accent); stroke-width: 3; }
.chart-label { fill: var(--muted); font-size: 12px; }
.chart-summary, .caption { color: var(--muted); font-size: .75rem; }
.chart-summary { margin: .25rem 0; }
.caption { margin: .4rem 0 0; }
.lower-grid { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(260px, .9fr); gap: .8rem; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
table { width: 100%; border-collapse: collapse; font-size: .76rem; font-variant-numeric: tabular-nums; }
th, td { padding: .7rem .75rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { color: var(--muted); background: var(--surface-2); font-size: .66rem; letter-spacing: .04em; text-transform: uppercase; }
th:first-child, td:first-child, th:nth-child(3), td:nth-child(3) { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 2rem; color: var(--muted); text-align: center !important; }
.side { display: inline-block; padding: .18rem .4rem; border-radius: 5px; font-size: .67rem; font-weight: 800; text-transform: uppercase; }
.side.buy { color: var(--accent); background: rgb(56 200 139 / 11%); }
.side.sell { color: var(--warning); background: rgb(241 198 107 / 11%); }
.strategy dl { margin: 0; }
.strategy dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .62rem 0; border-bottom: 1px solid var(--line); }
.strategy dt { color: var(--muted); }
.strategy dd { margin: 0; text-align: right; font-weight: 650; }
.operations { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; margin-top: 1rem; }
.operations span { min-width: 0; padding: .55rem; color: var(--muted); text-align: center; background: var(--surface-2); border-radius: 8px; font-size: .65rem; }
.operations b { display: block; overflow: hidden; color: var(--text); font-size: .85rem; text-overflow: ellipsis; }
.ops-panel { margin-bottom: .8rem; }
.ops-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: .6rem; }
.ops-item { display: flex; flex-direction: column; gap: .25rem; padding: .65rem .75rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; }
.ops-label { color: var(--muted); font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; }
.ops-value { font-size: .82rem; font-weight: 650; }
.badge { display: inline-block; padding: .2rem .45rem; border-radius: 6px; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.badge-sim { color: var(--warning); background: rgb(241 198 107 / 12%); border: 1px solid rgb(241 198 107 / 30%); }
.badge-live { color: var(--accent); background: rgb(56 200 139 / 12%); border: 1px solid rgb(56 200 139 / 30%); }
.badge-ok { color: var(--accent); background: rgb(56 200 139 / 12%); border: 1px solid rgb(56 200 139 / 30%); }

footer { display: flex; justify-content: space-between; gap: 1rem; padding-top: 1.4rem; color: var(--muted); font-size: .72rem; }
.ledger-section { margin-top: 2.5rem; padding-top: 2rem; border-top: 1px solid var(--line); }
.ledger-heading { margin-bottom: .8rem; }
.ledger-notice { margin-bottom: .8rem; padding: .9rem 1rem; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.ledger-cards { margin-bottom: .8rem; }
.ledger-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: .8rem; margin-bottom: .8rem; }
.ledger-history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.capability-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .6rem; }
.capability-grid article { padding: .8rem; display: flex; flex-direction: column; gap: .3rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; }
.capability-grid strong { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.capability-grid span { color: var(--muted); font-size: .72rem; }

@media (max-width: 1050px) { .cards { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) {
  .topbar { height: auto; min-height: 68px; padding: .8rem 1rem; }
  .mode { max-width: 145px; text-align: right; }
  .shell { width: min(100% - 1.25rem, 1240px); padding-top: 2rem; }
  .hero { align-items: stretch; flex-direction: column; gap: 1.25rem; }
  .health-card { min-width: 0; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .ops-grid { grid-template-columns: repeat(3, 1fr); }
  .lower-grid { grid-template-columns: 1fr; }
  .ledger-grid, .ledger-history-grid { grid-template-columns: 1fr; }
  .capability-grid { grid-template-columns: 1fr; }
  footer { flex-direction: column; }
}
@media (max-width: 420px) { .cards, .ops-grid { grid-template-columns: 1fr; } .brand div span { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }
