/* ==========================================================================
   CL options dashboard - plain CSS, no build step.
   Colour tokens come from a validated palette (light + dark are both selected,
   not an automatic flip).
   ========================================================================== */

:root {
  color-scheme: light;

  --plane:          #f9f9f7;   /* page background */
  --surface:        #fcfcfb;   /* cards, chart surface */
  --surface-2:      #f2f1ed;   /* table stripes, insets */
  --ink:            #0b0b0b;
  --ink-2:          #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);

  /* categorical series (fixed order, never cycled) */
  --series-1:       #2a78d6;   /* price */
  --series-2:       #eb6834;   /* Book A entries */
  --series-3:       #1baf7a;   /* Book E entries */

  /* status - reserved, always paired with an icon or a label */
  --good:           #0ca30c;
  --warning:        #fab219;
  --serious:        #ec835a;
  --critical:       #d03b3b;
  --good-ink:       #006300;
  --critical-ink:   #a52a2a;

  --radius:         10px;
  --radius-sm:      6px;
  --gap:            16px;
  --shadow:         0 1px 2px rgba(11, 11, 11, 0.06);
  --font:           system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:           ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:        #0d0d0d;
    --surface:      #1a1a19;
    --surface-2:    #232322;
    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --ink-muted:    #898781;
    --grid:         #2c2c2a;
    --axis:         #383835;
    --border:       rgba(255, 255, 255, 0.10);
    --series-1:     #3987e5;
    --series-2:     #d95926;
    --series-3:     #199e70;
    --good-ink:     #0ca30c;
    --critical-ink: #e66767;
    --shadow:       none;
  }
}

* { box-sizing: border-box; }

/* Author rules such as `.row { display: flex }` would otherwise beat the user
   agent's `[hidden] { display: none }`. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 0 48px;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
code, .mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px; max-width: 1280px; margin: 0 auto;
}
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--ink-muted); font-weight: 500; }
nav.main { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
nav.main a {
  padding: 6px 12px; border-radius: var(--radius-sm); text-decoration: none;
  color: var(--ink-2); font-weight: 550; font-size: 14px;
}
nav.main a:hover { background: var(--surface-2); color: var(--ink); }
nav.main a.active { background: var(--series-1); color: #fff; }

/* ---------- disclaimer + banners ---------- */
.disclaimer {
  background: var(--surface-2); color: var(--ink-2);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px; padding: 7px 20px; text-align: center;
}
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; margin: 14px 0 0; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px;
}
.banner .icon { flex: none; font-weight: 700; }
.banner.critical { border-color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, var(--surface)); }
.banner.warning  { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, var(--surface)); }
.banner.good     { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--surface)); }
.banner.info     { border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 8%, var(--surface)); }
.banner.hidden { display: none; }

.flashes { margin-top: 14px; }

/* ---------- price header ---------- */
.pricebar {
  display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 20px; margin-top: 16px;
}
.hero { display: flex; align-items: baseline; gap: 14px; }
.hero .figure { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.hero .delta { font-size: 17px; font-weight: 650; }
.up    { color: var(--good-ink); }
.down  { color: var(--critical-ink); }
.flat  { color: var(--ink-2); }
.meta { font-size: 12.5px; color: var(--ink-muted); line-height: 1.6; }
.meta strong { color: var(--ink-2); font-weight: 600; }
.pricebar .meta-group { margin-left: auto; text-align: right; }

/* ---------- layout ---------- */
.grid { display: grid; gap: var(--gap); margin-top: var(--gap); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 960px) { .grid.two, .grid.three { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.card > header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: -2px 0 12px;
}
.card > header h2 { margin: 0; }
.card > header .spacer { margin-left: auto; }
.card-note { font-size: 12.5px; color: var(--ink-muted); }

/* ---------- badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.02em;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge.signal  { background: var(--good); border-color: var(--good); color: #fff; }
.badge.watch   { background: var(--warning); border-color: var(--warning); color: #1a1a19; }
.badge.none    { background: var(--surface-2); color: var(--ink-2); }
.badge.pass    { background: color-mix(in srgb, var(--good) 18%, var(--surface)); color: var(--good-ink); border-color: var(--good); }
.badge.fail    { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); color: var(--critical-ink); border-color: var(--critical); }
.badge.tp      { background: var(--good); border-color: var(--good); color: #fff; }
.badge.ghost   { background: transparent; }
.badge.a       { background: color-mix(in srgb, var(--series-2) 18%, var(--surface)); border-color: var(--series-2); color: var(--ink); }
.badge.e       { background: color-mix(in srgb, var(--series-3) 18%, var(--surface)); border-color: var(--series-3); color: var(--ink); }

/* ---------- stat rows ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 0 0 14px; }
.stat { min-width: 92px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted); }
.stat .value { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--ink-muted); }

/* ---------- move gauge ---------- */
.gauge { margin: 4px 0 16px; }
.gauge-track {
  position: relative; height: 34px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--critical) 22%, var(--surface)) 0%,
    color-mix(in srgb, var(--critical) 22%, var(--surface)) var(--down-stop, 15%),
    var(--surface-2) calc(var(--down-stop, 15%) + 0.6%),
    var(--surface-2) var(--up-stop, 85%),
    color-mix(in srgb, var(--good) 22%, var(--surface)) calc(var(--up-stop, 85%) + 0.6%),
    color-mix(in srgb, var(--good) 22%, var(--surface)) 100%);
  border: 1px solid var(--border);
}
.gauge-tick {
  position: absolute; top: -2px; bottom: -2px; width: 2px;
  background: var(--axis);
}
.gauge-needle {
  position: absolute; top: -5px; bottom: -5px; width: 3px; border-radius: 2px;
  background: var(--ink); transform: translateX(-1px);
}
.gauge-needle.live { background: var(--series-1); width: 2px; opacity: 0.85; }
.gauge-labels {
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: var(--ink-muted); margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.gauge-legend { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th.l, td.l { text-align: left; }
thead th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-muted); font-weight: 650;
  border-bottom: 1px solid var(--axis);
}
tbody tr { border-bottom: 1px solid var(--grid); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td { font-variant-numeric: tabular-nums; }
tr.closed-row td { color: var(--ink-2); }
tr.tp-row { background: color-mix(in srgb, var(--good) 10%, var(--surface)); }
.empty { padding: 18px 4px; color: var(--ink-muted); font-size: 13.5px; }

/* ---------- progress ---------- */
.bar {
  position: relative; height: 8px; min-width: 70px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border); overflow: hidden;
}
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--series-1); }
.bar.good > i { background: var(--good); }
.bar.bad  > i { background: var(--critical); }
.bar-wrap { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

/* ---------- proposals ---------- */
.proposal {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 10px; background: var(--surface-2);
}
.proposal h4 { margin: 0 0 8px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.proposal .legs { font-family: var(--mono); font-size: 13px; margin-bottom: 8px; }
.proposal dl {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px 14px; margin: 0;
}
.proposal dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); }
.proposal dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.reasons { margin: 10px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.reasons li { margin-bottom: 3px; }

/* ---------- charts ---------- */
.chart-box { position: relative; height: 300px; }
.chart-box.short { height: 190px; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin: 2px 0 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .key { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart-legend .key.line { height: 3px; border-radius: 2px; }
details.data-table { margin-top: 12px; }
details.data-table summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
details.data-table .table-scroll { max-height: 280px; overflow-y: auto; margin-top: 10px; }

/* ---------- forms ---------- */
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 150px; min-width: 130px; }
.field.wide { flex: 1 1 100%; }
label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
label .hint { display: block; font-weight: 400; color: var(--ink-muted); font-size: 11.5px; margin-top: 2px; }
input[type="text"], input[type="number"], input[type="date"], input[type="password"],
input[type="email"], select, textarea {
  font: inherit; font-variant-numeric: tabular-nums;
  padding: 7px 9px; border: 1px solid var(--axis); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: 1px; border-color: var(--series-1); }
textarea { min-height: 62px; resize: vertical; }
.check { display: flex; align-items: flex-start; gap: 8px; flex: 1 1 220px; }
.check input { width: 16px; height: 16px; margin-top: 2px; flex: none; }
.check label { font-weight: 550; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--series-1); background: var(--series-1); color: #fff;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.secondary, .btn.secondary {
  background: var(--surface); color: var(--ink); border-color: var(--axis);
}
button.danger, .btn.danger { background: var(--critical); border-color: var(--critical); }
button.small, .btn.small { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }

fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 16px;
}
legend { font-weight: 700; font-size: 13px; padding: 0 6px; }
.fieldset-note { font-size: 12.5px; color: var(--ink-muted); margin: -4px 0 12px; }

/* ---------- misc ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.footer { margin-top: 28px; font-size: 12px; color: var(--ink-muted); text-align: center; }
.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;
}
.tag { font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.source-tag {
  font-size: 10.5px; padding: 1px 5px; border-radius: 3px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-muted);
}

/* ---------- strategy tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--ink-2); font: inherit; font-weight: 600; cursor: pointer;
}
.tab:hover { background: var(--surface); color: var(--ink); }
.tab.active {
  background: var(--series-1); border-color: var(--series-1); color: #fff;
}
.tab.active .badge { background: rgba(255,255,255,.22); border-color: transparent; color: #fff; }
.view-header { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.view-header h2 { margin: 0; }
.view-header .card-note { margin: 2px 0 0; }
.proposal.preview { opacity: .72; }
.gauge-zone { position: absolute; top: 0; bottom: 0; }
.zone-critical { background: color-mix(in srgb, var(--critical) 22%, var(--surface)); }
.zone-good     { background: color-mix(in srgb, var(--good) 22%, var(--surface)); }
.zone-warning  { background: color-mix(in srgb, var(--warning) 22%, var(--surface)); }
.zone-neutral  { background: var(--surface-2); }
.muted { color: var(--ink-muted); }
.accent { color: var(--series-1); }
.warn { color: var(--warning); }

/* Instrument switcher in the top bar.  A plain form that submits on change, so
   it works without JavaScript too - the noscript button is the fallback. */
.symbol-switch { margin-left: 14px; display: flex; align-items: center; gap: 6px; }
.symbol-switch select {
  font: inherit; font-size: 13px; padding: 3px 8px; border-radius: 6px;
  border: 1px solid var(--grid); background: var(--surface); color: var(--ink);
  max-width: 230px;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Settings
   ---------------------------------------------------------------------------
   One grid, so every field is the same width and rows line up.  The previous
   version wrote a pixel width into each of forty field calls, which is what
   made the page look ragged: no two boxes the same, nothing aligned.
   --------------------------------------------------------------------------- */
.grid-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 18px;
  margin-bottom: 14px;
  align-items: start;
}
.grid-fields .field { min-width: 0; }
.grid-fields .field.span2 { grid-column: span 2; }
.grid-fields .check { grid-column: 1 / -1; }
.field .hint { display: block; margin-top: 3px; }

/* Checkboxes read as a list, not as columns of unequal width. */
.grid-fields.checks { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-fields.checks .check { grid-column: auto; }

fieldset {
  border: 1px solid var(--grid); border-radius: 10px;
  padding: 16px 18px 6px; margin: 0 0 18px; background: var(--surface);
}
legend {
  font-size: 13px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-2); padding: 0 8px;
}
.fieldset-note { font-size: 12.5px; color: var(--ink-muted); margin: 0 0 14px; line-height: 1.5; }

/* Folded away because they are set once and then never touched again. */
details.settings-extra { margin: 0 0 18px; }
details.settings-extra > summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2);
  padding: 9px 12px; border: 1px solid var(--grid); border-radius: 8px;
  background: var(--surface); list-style: none;
}
details.settings-extra > summary::-webkit-details-marker { display: none; }
details.settings-extra > summary::before { content: "\25b8 "; color: var(--ink-muted); }
details.settings-extra[open] > summary::before { content: "\25be "; }
details.settings-extra[open] > summary { border-radius: 8px 8px 0 0; margin-bottom: -1px; }
details.settings-extra > fieldset { border-radius: 0 0 8px 8px; margin: 0; }

/* Save without scrolling to the bottom of forty fields. */
.settings-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 10px; align-items: center;
  padding: 12px 0; margin-top: 4px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* --- Sign-in page ------------------------------------------------------- */
/* Its own page rather than a modal over the dashboard: there is nothing
   behind it to see, and a login form layered over real numbers invites
   clicking through to them. */
.login-page      { display: flex; min-height: 100vh; align-items: center;
                   justify-content: center; padding: 24px; }
.login-card      { width: 100%; max-width: 22rem; background: var(--surface);
                   border: 1px solid var(--border); border-radius: 10px;
                   padding: 28px 24px; }
.login-card h1   { margin: 0 0 20px; font-size: 1.15rem; }
.login-form      { display: grid; gap: 8px; }
.login-form label{ font-size: .8rem; color: var(--muted); }
.login-form input{ padding: 9px 10px; font: inherit; border-radius: 6px;
                   border: 1px solid var(--border); background: var(--bg);
                   color: var(--text); }
.login-form button { margin-top: 8px; }
.login-card .disclaimer { margin: 20px 0 0; font-size: .75rem; }
.logout-form     { display: inline; margin-left: 10px; }
.linklike        { background: none; border: 0; padding: 0; font: inherit;
                   color: var(--muted); cursor: pointer; }
.linklike:hover  { color: var(--text); text-decoration: underline; }
