/* One stylesheet, no framework, no external fonts.
 *
 * The Content-Security-Policy this is served under forbids every external
 * origin, which is deliberate: a research interface that reaches out to a CDN
 * tells that CDN when its operator is looking at their trading data.
 *
 * Colour is used for one purpose only — the sign of a number — so that a table
 * of returns can be read at a glance without reading any of it closely. */

:root {
  color-scheme: light dark;

  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --border: #e2e2dd;
  --border-strong: #c9c9c2;
  --text: #1c1c1a;
  --text-muted: #6b6b64;
  --accent: #1f5f8b;
  --accent-soft: #e8f0f6;
  --gain: #1a6b3c;
  --loss: #a02c2c;
  --warn: #8a5a00;
  --warn-soft: #fdf3e0;
  --bad-soft: #fbecec;
  --good-soft: #eaf4ee;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1d1f23;
    --surface-2: #24272c;
    --border: #32363d;
    --border-strong: #454b54;
    --text: #e6e6e3;
    --text-muted: #9a9c9f;
    --accent: #6fb3dd;
    --accent-soft: #1b2c38;
    --gain: #5bbd84;
    --loss: #e0736e;
    --warn: #d9a441;
    --warn-soft: #2e2718;
    --bad-soft: #2f1e1e;
    --good-soft: #1a2a20;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout --------------------------------------------------------------- */

header.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.masthead .brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 12px 0;
  white-space: nowrap;
}

.masthead .brand span { color: var(--text-muted); font-weight: 400; }

nav.primary { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }

nav.primary a {
  padding: 12px 10px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

nav.primary a:hover { color: var(--text); text-decoration: none; }

nav.primary a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

.masthead .session { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }

h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--text-muted); }

.subtitle { color: var(--text-muted); margin: 0 0 20px; }

.grid { display: grid; gap: 16px; margin-bottom: 20px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* --- Cards ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  min-width: 0;
}

.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 14px 16px 10px; margin: 0; }

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .label { color: var(--text-muted); font-size: 12px; }
.metric .note { color: var(--text-muted); font-size: 12px; margin: 0; }

/* --- Tables --------------------------------------------------------------- */

.scroll { overflow-x: auto; }

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

th, td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}

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

td.num, th.num { text-align: right; font-family: var(--mono); font-size: 13px; }
td.mono { font-family: var(--mono); font-size: 12px; }
td.wrap, th.wrap { white-space: normal; }

table.kv td:first-child { color: var(--text-muted); width: 45%; }
table.kv td { border-bottom: 1px solid var(--border); }

.empty { padding: 24px 16px; color: var(--text-muted); text-align: center; }

/* --- Semantic colour ------------------------------------------------------ */

.gain { color: var(--gain); }
.loss { color: var(--loss); }
.flat, .muted { color: var(--text-muted); }

.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.pill.ok { background: var(--good-soft); color: var(--gain); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--loss); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* --- Bars ----------------------------------------------------------------- */

/* Drawn as SVG so the per-row length is an attribute rather than an inline
 * style, which the Content-Security-Policy forbids. */
.bar { display: block; width: 100%; height: 8px; }
.bar rect.track { fill: var(--surface-2); }
.bar rect.fill { fill: var(--accent); }
.bar rect.fill.long { fill: var(--loss); }
.bar rect.fill.short { fill: var(--gain); }

.spark { display: block; width: 100%; height: 120px; }
.spark rect.long { fill: var(--loss); }
.spark rect.short { fill: var(--gain); }
.spark line.axis { stroke: var(--border-strong); stroke-width: 1; }
.spark text { fill: var(--text-muted); font-size: 9px; font-family: var(--sans); }

/* --- Forms ---------------------------------------------------------------- */

form.filters {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
}

.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11px; color: var(--text-muted); text-transform: uppercase;
                letter-spacing: 0.04em; }

input, select, button {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

input[type="date"] { font-family: var(--mono); font-size: 13px; }

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 500;
}

button:hover { filter: brightness(1.08); }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px;
         color: var(--text-muted); font-size: 13px; }

/* --- Login ---------------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.login-card h1 { margin-bottom: 2px; }
.login-card p.subtitle { margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; padding: 8px; }

.notice {
  padding: 9px 12px;
  border-radius: 4px;
  margin-bottom: 14px;
  font-size: 13px;
}

.notice.error { background: var(--bad-soft); color: var(--loss); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent); }

/* --- Details -------------------------------------------------------------- */

details {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  padding: 10px 14px;
  margin-bottom: 16px;
}

details > summary { cursor: pointer; font-weight: 600; font-size: 13px; }

pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 10px;
  overflow-x: auto;
  margin: 10px 0 0;
}

/* --- Utilities -------------------------------------------------------------
 *
 * These exist because the Content-Security-Policy forbids inline style
 * attributes. Every one of them replaces a `style="..."` that would otherwise
 * have been written in a template. */

.inline { display: inline; }
.tight { margin: 0; }
.normal { font-weight: 400; }
.mt { margin-top: 10px; }
.mb { margin-bottom: 8px; }

.btn-mini { padding: 2px 8px; font-size: 12px; }
.link-inline { padding: 6px 4px; }

.note {
  color: var(--text-muted);
  font-size: 12px;
  margin: 4px 0 0;
}

/* A note that sits inside a `.card.flush`, so it lines up with the table
 * above it rather than with the card edge. */
.note.inset { padding: 8px 16px; margin: 0; }
.note.footnote { margin: 10px 0 0; }

.grid.nested { margin: 0; }

.col-wide { width: 35%; }
.col-mid { width: 25%; }
.col-narrow { width: 14%; }

.pad-inset { padding: 0 16px 16px; }

footer.colophon {
  padding: 24px 20px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}
