/* Paper-trading dashboard.
   Palette: dataviz reference instance, validated for light and dark.
   Categorical slots 1 (blue) and 2 (orange) carry the two sleeves. */

:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --series-1:    #2a78d6;   /* TSMOM */
  --series-2:    #eb6834;   /* XSMOM */
  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --up-text:     #006300;
  --down-text:   #b02a2a;
  --radius:      10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:     #0d0d0d;
    --surface:  #1a1a19;
    --ink:      #f0efec;
    --ink-2:    #c3c2b7;
    --muted:    #898781;
    --grid:     #2c2c2a;
    --axis:     #383835;
    --border:   rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --up-text:  #0ca30c;
    --down-text:#e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:     #0d0d0d;
  --surface:  #1a1a19;
  --ink:      #f0efec;
  --ink-2:    #c3c2b7;
  --muted:    #898781;
  --grid:     #2c2c2a;
  --axis:     #383835;
  --border:   rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --up-text:  #0ca30c;
  --down-text:#e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 20px;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
}

.wrap { max-width: 1440px; margin: 0 auto; }

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h1 small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 8px; }

.header-right { display: flex; align-items: center; gap: 12px; }

.conn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--good); }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--critical); }

button {
  font: inherit; font-size: 12px;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
button:hover { border-color: var(--axis); }
button:active { transform: translateY(1px); }
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- stat tiles ---- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tile .label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.tile .value {
  font-size: 21px; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.tile .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.up { color: var(--up-text); }
.down { color: var(--down-text); }

/* ---- panels ---- */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
@media (max-width: 1000px) { .grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  min-width: 0;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 10px; gap: 12px;
}
.panel-head h2 { font-size: 13px; font-weight: 600; margin: 0; }
.panel-head .hint { font-size: 11px; color: var(--muted); }

/* ---- chart ---- */

.chart-host { position: relative; width: 100%; }
.chart-host svg { display: block; width: 100%; overflow: visible; }
.chart-empty {
  height: 160px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 11px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 10;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tooltip.show { opacity: 1; }
.tooltip .t-row { display: flex; gap: 8px; justify-content: space-between; }
.tooltip .t-key { color: var(--ink-2); }
.tooltip .t-val { font-weight: 600; }
.tooltip .t-head { font-weight: 600; margin-bottom: 3px; }

.legend {
  display: flex; gap: 14px; font-size: 11px; color: var(--ink-2);
  margin-top: 6px; flex-wrap: wrap;
}
.legend .item { display: inline-flex; align-items: center; gap: 5px; }
.legend .swatch { width: 9px; height: 9px; border-radius: 2px; }

/* ---- tables ---- */

.table-wrap { overflow: auto; max-height: 420px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  text-align: right; font-weight: 500; color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 6px 8px; border-bottom: 1px solid var(--grid);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
td {
  padding: 6px 8px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
tbody tr:hover { background: color-mix(in srgb, var(--series-1) 5%, transparent); }
tbody tr:last-child td { border-bottom: none; }
.mono { font-family: var(--mono); font-size: 11px; }

.pill {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.02em;
}
.pill.long  { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--up-text); }
.pill.short { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--down-text); }
.pill.rej   { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--ink); }
.pill.part  { background: color-mix(in srgb, var(--serious) 22%, transparent); color: var(--ink); }

.bar-cell { display: inline-flex; align-items: center; gap: 6px; }
.bar-track {
  width: 54px; height: 4px; border-radius: 2px;
  background: var(--grid); overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 2px; background: var(--series-1); }

.empty { color: var(--muted); font-size: 12px; padding: 24px 0; text-align: center; }

/* ---- log ---- */

#log {
  font-family: var(--mono); font-size: 11px;
  max-height: 150px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  color: var(--ink-2); line-height: 1.6;
}
#log .l-error { color: var(--critical); }
#log .l-warn  { color: var(--serious); }
#log .l-info  { color: var(--ink-2); }
#log .ts { color: var(--muted); margin-right: 8px; }
