/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: dark;

  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --surface-2:       #201f1e;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --grid:            #2c2c2a;
  --axis:            #383835;
  --border:          rgba(255, 255, 255, 0.10);

  --good:            #0ca30c;
  --warning:         #fab219;
  --serious:         #ec835a;
  --critical:        #d03b3b;

  --long:            #3987e5;  /* trade markers: long  */
  --short:           #d95926;  /* trade markers: short */

  --radius:   10px;
  --radius-s: 6px;
  --gap:      16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f2f1ed;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --good:            #006300;
  --long:            #2a78d6;
  --short:           #eb6834;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --page:            #f9f9f7;
    --surface-1:       #fcfcfb;
    --surface-2:       #f2f1ed;
    --text-primary:    #0b0b0b;
    --text-secondary:  #52514e;
    --text-muted:      #898781;
    --grid:            #e1e0d9;
    --axis:            #c3c2b7;
    --border:          rgba(11, 11, 11, 0.10);
    --good:            #006300;
    --long:            #2a78d6;
    --short:           #eb6834;
  }
}

/* ------------------------------------------------------------------- base */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.05rem; }
h2 { font-size: 0.95rem; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-right: auto;
}

.brand .sub {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.pill--live    { color: var(--critical); border-color: var(--critical); }
.pill--demo    { color: var(--good); }
.pill--dry     { color: var(--warning); }
.pill--armed   { color: var(--critical); }
.pill--halted  { color: var(--critical); border-color: var(--critical); }
.pill--ok      { color: var(--good); }
.pill--idle    { color: var(--text-muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { border-color: var(--text-muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--danger { color: var(--critical); border-color: rgba(208, 59, 59, 0.45); }
.btn--danger:hover:not(:disabled) { border-color: var(--critical); }
.btn--tiny { font-size: 0.74rem; padding: 3px 8px; }

/* ------------------------------------------------------------------ layout */
main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel__head .spacer { margin-left: auto; }

.panel__body { padding: 14px 16px; }
.panel__body--flush { padding: 0; }

.cols { display: grid; gap: var(--gap); grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- stat tiles */
.kpis {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 92px;
}

.tile__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.tile__value {
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
}

.tile__note { font-size: 0.78rem; color: var(--text-secondary); }

.tile--hero .tile__value { font-size: 2.3rem; }

.value-pos { color: var(--good); }
.value-neg { color: var(--critical); }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-1);
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--grid);
  color: var(--text-secondary);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

td.strong { color: var(--text-primary); font-weight: 600; }
.num { text-align: right; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
}
.tag--buy  { color: var(--long);  border-color: color-mix(in srgb, var(--long) 45%, transparent); }
.tag--sell { color: var(--short); border-color: color-mix(in srgb, var(--short) 45%, transparent); }
.tag--open { color: var(--warning); }
.tag--closed { color: var(--text-muted); }
.tag--rejected, .tag--error { color: var(--critical); }
.tag--sim { color: var(--text-muted); }

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ------------------------------------------------------------------- chart */
.chart-host {
  height: 440px;
  width: 100%;
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }

.tab {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 16px 0;
  font-size: 0.76rem;
  color: var(--text-secondary);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i {
  width: 10px; height: 10px; border-radius: 2px; display: inline-block;
}
.swatch-long  { background: var(--long); }
.swatch-short { background: var(--short); }
.swatch-up    { background: var(--good); }
.swatch-down  { background: var(--critical); }

/* -------------------------------------------------------------- log lists */
.loglist { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }

.loglist li {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--grid);
  font-size: 0.82rem;
}
.loglist li:last-child { border-bottom: none; }
.loglist time { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.loglist .msg { color: var(--text-secondary); overflow-wrap: anywhere; }
.loglist .epic { color: var(--text-primary); font-weight: 600; }
.lvl-error .msg { color: var(--critical); }
.lvl-warn .msg  { color: var(--serious); }

/* ------------------------------------------------------------------- login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.login-card h1 { margin-bottom: 4px; }
.login-card p { margin: 0 0 20px; color: var(--text-muted); font-size: 0.85rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }

.field input {
  font: inherit;
  padding: 9px 11px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
}
.field input:focus { outline: 2px solid var(--long); outline-offset: 1px; }

.btn--block { width: 100%; padding: 10px; font-size: 0.9rem; }

.error {
  color: var(--critical);
  font-size: 0.82rem;
  margin: 12px 0 0;
  min-height: 1.2em;
}

.banner {
  padding: 10px 16px;
  font-size: 0.83rem;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
}
.banner--warn { border-color: color-mix(in srgb, var(--serious) 45%, transparent); color: var(--serious); }
.banner--bad  { border-color: color-mix(in srgb, var(--critical) 45%, transparent); color: var(--critical); }

.hidden { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
