/* The trader's dashboard. Colours are roles defined once per theme; nothing below uses a raw hex. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --hover: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;

  /* Series colours. A trader's own line (its net, its fair value) is the first. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --series-other: #898781;

  /* Status: always shown with an icon and a label, never as colour alone. */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --delta-up: #006300;
  --delta-down: #c22f2f;

  --radius: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --hover: rgba(255, 255, 255, 0.06);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --delta-up: #0ca30c;
    --delta-down: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --hover: rgba(255, 255, 255, 0.06);
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --delta-up: #0ca30c;
  --delta-down: #e66767;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 var(--font);
}

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--delta-up); }
.down { color: var(--delta-down); }

/* ---- top bar */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.brand .sub { color: var(--text-2); font-size: 13px; }
.trader-name { font-family: var(--mono); font-size: 14px; font-weight: 600; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.live { border-color: var(--critical); color: var(--text); }

.health { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--text-2); font-size: 13px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); white-space: nowrap; }
.status svg { width: 14px; height: 14px; flex: none; }
.status.good svg { color: var(--good); }
.status.warning svg { color: var(--warning); }
.status.critical svg { color: var(--critical); }
.status.idle svg { color: var(--muted); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-button:hover { background: var(--hover); }
.icon-button svg { width: 16px; height: 16px; }

/* ---- one tab per trader; each trader is a dashboard of its own */

.tabs { display: flex; gap: 2px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  padding: 9px 12px 7px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
}
.tabs button:hover { background: var(--hover); color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 650; border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
.tabs button .note { font-family: var(--font); font-size: 11.5px; font-weight: 400; color: var(--muted); }

.banner {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border: 1px solid var(--critical);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- page layout */

main { max-width: 1680px; margin: 0 auto; padding: 16px 20px 40px; display: grid; gap: var(--gap); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h3 { font-size: 14px; font-weight: 650; }
.card-head .sub { color: var(--text-2); font-size: 12.5px; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.text-button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  padding: 2px 9px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
}
.text-button:hover { background: var(--hover); }
.text-button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.text-button:disabled { opacity: 0.45; cursor: default; }

.empty { color: var(--muted); padding: 18px 2px; font-size: 13px; }

/* ---- range filter: one row, above everything it scopes */

.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; border-right: 1px solid var(--border); background: transparent; padding: 5px 12px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--hover); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* Data being refetched keeps its frame, a little dimmed. */
.stale { opacity: 0.55; transition: opacity 120ms; }

/* ---- current market */

.window-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.window-head .slug { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.countdown { margin-left: auto; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.countdown small { font-size: 12px; font-weight: 400; color: var(--text-2); margin-left: 4px; }

.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 8px 0 12px; }
.meter > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px 18px; margin-bottom: 12px; }
.fact .label { color: var(--text-2); font-size: 12px; }
.fact .value { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.fact .value small { font-size: 12px; font-weight: 400; color: var(--text-2); }
.fact .value .status { font-size: 15px; }
.fact .detail { color: var(--muted); font-size: 12px; }

.flags { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }

.charts-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 12px; }
@media (max-width: 760px) { .charts-2 { grid-template-columns: minmax(0, 1fr); } }
.chart-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }
/* A chart that follows a table in its card keeps its distance from it. */
.chart-title.after-table { margin-top: 14px; }

/* ---- tiles */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--gap); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: end; }
.tile .label { grid-column: 1 / -1; color: var(--text-2); font-size: 12.5px; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.tile .detail { grid-column: 1 / -1; color: var(--text-2); font-size: 12.5px; }
.tile .spark { position: relative; width: 96px; height: 34px; }
/* On a phone the net takes a row of its own and the other tiles pair up. */
@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile:first-child { grid-column: 1 / -1; }
}

/* ---- tables */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table-wrap.tall { max-height: 420px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 12px; z-index: 1; }
th:first-child, td:first-child, th.left, td.left { text-align: left; }
td { font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
tr.dim td { color: var(--muted); }
.table-note { color: var(--muted); font-size: 12px; margin-top: 8px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; line-height: 19px; color: var(--text-2); white-space: nowrap; }
.pill svg { width: 11px; height: 11px; flex: none; }
.pill.good { color: var(--text); } .pill.good svg { color: var(--good); }
.pill.warning { color: var(--text); } .pill.warning svg { color: var(--warning); }
.pill.critical { color: var(--text); } .pill.critical svg { color: var(--critical); }

.subhead { font-size: 12px; font-weight: 650; color: var(--text-2); margin: 2px 0 6px; }
.subhead:not(:first-child) { margin-top: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--mono); font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); }
details summary { cursor: pointer; color: var(--text-2); font-size: 12.5px; margin-top: 10px; }
pre { margin: 8px 0 0; padding: 10px; background: var(--surface-2); border-radius: 8px; font: 12px/1.5 var(--mono); overflow: auto; max-height: 340px; }

/* ---- charts (Chart.js canvases; their colours are read from the roles above when they draw) */

.chart-box { position: relative; }
.chart-box canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.chart-table { margin-top: 8px; max-height: 260px; overflow: auto; }

/* ---- explanations: anything that has one shows it as a tooltip (tooltip.js) */

/* Words that can be explained say so quietly; buttons keep their own look. */
[data-tip]:not(button, select) { cursor: help; }
:is(th, h2, h3, .label > span, .subhead > span, .chart-title > span, td > span:not(.pill))[data-tip] {
  text-decoration: underline dotted var(--muted) 1px;
  text-underline-offset: 3px;
}

.tooltip {
  position: fixed;
  z-index: 50;
  max-width: min(340px, calc(100vw - 16px));
  padding: 8px 10px;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.45;
  pointer-events: none;
}

/* ---- dialog and footer */

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 18px 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { font-size: 15px; margin-bottom: 6px; }
dialog p { color: var(--text-2); font-size: 13px; margin-bottom: 12px; }
dialog input { width: 100%; padding: 7px 9px; border: 1px solid var(--axis); border-radius: 8px; background: var(--page); }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.primary { border: 0; border-radius: 8px; background: var(--accent); color: #ffffff; padding: 6px 14px; font-weight: 600; cursor: pointer; }

footer { max-width: 1680px; margin: 0 auto; padding: 0 20px 28px; color: var(--muted); font-size: 12px; }
