/* marketlab: the tokens of docs/design-system.md (Genesis, insights-exploring) as custom properties, then the components.
   Indigo is for interactive elements only; cards are 12px, controls 6px; shadows on hover and focus only; the 4px grid;
   two font weights a screen (400 and 500 for the body, 600 for display). Fonts are self-hosted: static/fonts/. */

@font-face { font-family: "General Sans"; font-weight: 600; font-display: swap; src: url(/static/fonts/GeneralSans-Semibold.woff2) format("woff2"); }
@font-face { font-family: "General Sans"; font-weight: 700; font-display: swap; src: url(/static/fonts/GeneralSans-Bold.woff2) format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 400 500; font-display: swap; src: url(/static/fonts/DMSans.woff2) format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url(/static/fonts/JetBrainsMono-Regular.woff2) format("woff2"); }

:root {
  color-scheme: light dark;
  --color-primary: #6366F1;
  --color-primary-hover: #4F46E5;
  --color-neutral: #9C9C9C;
  --color-bg: #FAFAFA;
  --color-surface: #FFFFFF;
  --color-surface-alt: #F3F3F5;
  --color-text: #0A0A0A;
  --color-text-2: #6B6B6B;
  --color-border: #E8E8EC;
  --color-success: #10B981;
  --color-warning: #F59E0B;
  --color-error: #EF4444;
  --color-success-text: #047857;
  --color-warning-text: #B45309;
  --color-error-text: #B91C1C;
  --color-primary-text: #6366F1;
  --font-display: "General Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --text-section: 32px;
  --text-subhead: 24px;
  --text-body: 15px;
  --text-small: 13px;
  --text-caption: 12px;
  --text-overline: 11px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px; --space-16: 64px;
  --radius-chip: 4px;
  --radius-control: 6px;
  --radius-panel: 8px;
  --radius-card: 12px;
  --radius-pill: 9999px;
  --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.08);
  --shadow-button: 0 4px 12px rgba(99, 102, 241, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --ring: 0 0 0 3px rgba(99, 102, 241, 0.12);
  --nav-height: 56px;
  --container: 1280px;
  --gutter: 24px;
  --chart-up: #10B981;
  --chart-down: #EF4444;
  --chart-grid: #E8E8EC;
  --chart-text: #6B6B6B;
  --chart-series-1: #0A0A0A;
  --chart-series-2: #0D9488;
  --chart-series-3: #D97706;
  --chart-series-4: #DB2777;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0F0F11;
    --color-surface: #17171A;
    --color-surface-alt: #1F1F24;
    --color-text: #F2F2F3;
    --color-text-2: #A1A1AA;
    --color-border: #2A2A30;
    --color-neutral: #6B6B75;
    --color-success-text: #34D399;
    --color-warning-text: #FBBF24;
    --color-error-text: #F87171;
    --color-primary-text: #818CF8;
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.4);
    --chart-grid: #2A2A30;
    --chart-text: #A1A1AA;
    --chart-series-1: #F2F2F3;
    --chart-series-2: #2DD4BF;
    --chart-series-3: #FBBF24;
    --chart-series-4: #F472B6;
  }
}

/* ---- base --------------------------------------------------------------------------------------------------- */

* { box-sizing: border-box; }
html { background: var(--color-bg); }
body { margin: 0; color: var(--color-text); background: var(--color-bg); font: 400 var(--text-body)/1.5 var(--font-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.03em; margin: 0; }
h2 { font-size: var(--text-subhead); line-height: 1.2; }
h3 { font-size: 17px; line-height: 1.3; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--color-text-2); }
.small { font-size: var(--text-small); }
.caption { font-size: var(--text-caption); color: var(--color-text-2); }
.overline { font-size: var(--text-overline); text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-2); font-weight: 500; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.input:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--color-primary); }
[hidden] { display: none !important; }

/* ---- the nav -------------------------------------------------------------------------------------------------- */

.nav { position: sticky; top: 0; z-index: 10; height: var(--nav-height); display: flex; align-items: center; gap: var(--space-6); padding: 0 var(--gutter); border-bottom: 1px solid var(--color-border); background: color-mix(in srgb, var(--color-surface) 82%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.nav .brand { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.03em; text-decoration: none; }
.nav nav { display: flex; gap: var(--space-1); }
.nav nav a { font-size: 14px; font-weight: 500; text-decoration: none; padding: 6px 10px; border-radius: var(--radius-control); color: var(--color-text-2); }
.nav nav a:hover { background: var(--color-surface-alt); color: var(--color-text); }
.nav nav a[aria-current="page"] { color: var(--color-text); background: var(--color-surface-alt); }
.nav .data-to { margin-left: auto; font-size: var(--text-small); color: var(--color-text-2); white-space: nowrap; }
.nav .data-to .num { color: var(--color-text); }

/* ---- layout --------------------------------------------------------------------------------------------------- */

.container { max-width: var(--container); margin: 0 auto; padding: var(--space-6) var(--gutter) var(--space-16); }
.screen-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.station { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-5); align-items: start; }
@media (max-width: 960px) { .station { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: var(--space-4); }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-5); }

/* ---- cards, chips, controls ----------------------------------------------------------------------------------- */

.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-card); padding: var(--space-4); overflow: hidden; }
.card.is-interactive { cursor: pointer; transition: transform 200ms, box-shadow 200ms; }
.card.is-interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.card.is-active { border-color: var(--color-primary); box-shadow: var(--ring); }
.panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-panel); padding: var(--space-3) var(--space-4); }
.chips { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip { border: 1px solid var(--color-border); background: var(--color-surface-alt); color: var(--color-text-2); border-radius: var(--radius-pill); padding: 4px 12px; font-size: var(--text-caption); font-weight: 500; cursor: pointer; line-height: 1.4; }
.chip:hover { color: var(--color-text); }
.chip[aria-pressed="true"] { background: var(--color-primary); border-color: var(--color-primary); color: #FFFFFF; }
.chip[disabled] { opacity: 0.5; cursor: not-allowed; }
.status { display: inline-block; border-radius: var(--radius-pill); padding: 2px 10px; font-size: var(--text-overline); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; border: 1px solid transparent; }
.status.ok { color: var(--color-success-text); border-color: color-mix(in srgb, var(--color-success) 40%, transparent); }
.status.warn { color: var(--color-warning-text); border-color: color-mix(in srgb, var(--color-warning) 40%, transparent); }
.status.error { color: var(--color-error-text); border-color: color-mix(in srgb, var(--color-error) 40%, transparent); }
.status.off { color: var(--color-text-2); border-color: var(--color-border); }
.seg { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; font-size: var(--text-small); font-weight: 500; color: var(--color-text-2); cursor: pointer; }
.seg button:first-child { border-radius: 5px 0 0 5px; }
.seg button:last-child { border-radius: 0 5px 5px 0; }
.seg button + button { border-left: 1px solid var(--color-border); }
.seg button[aria-pressed="true"] { color: var(--color-primary-text); background: color-mix(in srgb, var(--color-primary) 10%, transparent); }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--color-border); background: transparent; font-size: var(--text-small); font-weight: 500; cursor: pointer; transition: transform 150ms, box-shadow 150ms; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--color-primary); border-color: var(--color-primary); color: #FFFFFF; }
.btn.primary:hover { background: var(--color-primary-hover); box-shadow: var(--shadow-button); }
.btn.ghost { border-color: transparent; color: var(--color-text-2); }
.btn.ghost:hover { color: var(--color-text); background: var(--color-surface-alt); }
.btn.danger { color: var(--color-error-text); border-color: color-mix(in srgb, var(--color-error) 50%, transparent); }
.btn.sm { height: 28px; padding: 0 10px; font-size: var(--text-caption); }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--color-border); background: var(--color-surface); border-radius: var(--radius-control); padding: 10px 14px; font-size: 14px; }
.input::placeholder { color: var(--color-neutral); }
.input.is-error { border-color: var(--color-error); }
label.field { display: grid; gap: 4px; font-size: var(--text-caption); color: var(--color-text-2); }
.list { display: flex; flex-direction: column; }
.list > * { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); }
.list > :first-child { border-top: 0; }
.list .item { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); cursor: pointer; }
.list .item:hover { background: var(--color-surface-alt); }
.list .item.is-active { background: color-mix(in srgb, var(--color-primary) 8%, transparent); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-small); }
table.data th { text-align: left; font-weight: 500; color: var(--color-text-2); padding: 8px 12px 8px 0; border-bottom: 1px solid var(--color-border); font-size: var(--text-caption); }
table.data td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--color-border); vertical-align: top; }
table.data td.num { white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.notice { padding: var(--space-3) var(--space-4); border-radius: var(--radius-panel); border: 1px solid var(--color-border); background: var(--color-surface); font-size: var(--text-small); }
.notice.warn { border-color: color-mix(in srgb, var(--color-warning) 40%, transparent); }
.notice.error { border-color: color-mix(in srgb, var(--color-error) 40%, transparent); }

/* ---- the Station ---------------------------------------------------------------------------------------------- */

.toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar .spacer { flex: 1; }
.vitals { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.vital { padding: var(--space-3) var(--space-4); }
.vital .feed { font-weight: 500; font-size: var(--text-small); display: flex; align-items: center; gap: 8px; }
.vital .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.vital .close { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -0.02em; margin-top: 2px; }
.vital .change { font-size: var(--text-small); }
.vital .change.up { color: var(--color-success-text); }
.vital .change.down { color: var(--color-error-text); }
.vital .range { font-size: var(--text-caption); color: var(--color-text-2); }
.chart-card { padding: 0; }
.chart-holder { position: relative; height: clamp(360px, 62vh, 720px); }
.chart-holder canvas { display: block; }
.readout { display: flex; gap: var(--space-4); flex-wrap: wrap; padding: var(--space-2) var(--space-4); border-top: 1px solid var(--color-border); min-height: 36px; font-size: var(--text-caption); color: var(--color-text-2); }
.readout .num { color: var(--color-text); }
.side h3 { margin-bottom: var(--space-2); }
.chapter { display: grid; gap: 4px; }
.chapter .when { font-size: var(--text-caption); color: var(--color-text-2); }
.chapter .text { font-size: var(--text-small); }
.chapter .tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: var(--text-overline); border-radius: var(--radius-chip); padding: 1px 6px; background: var(--color-surface-alt); color: var(--color-text-2); }
.event-card { display: grid; gap: 4px; padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); font-size: var(--text-small); }
.event-card .swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.popover { position: absolute; z-index: 5; min-width: 240px; max-width: 320px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-panel); box-shadow: var(--shadow-lg); padding: var(--space-3) var(--space-4); font-size: var(--text-small); }
.popover .close { float: right; }
.empty { padding: var(--space-8); text-align: center; color: var(--color-text-2); }

/* ---- the Studies screen --------------------------------------------------------------------------------------- */

.study-card h3 { margin-bottom: 4px; }
.study-card .meta { font-size: var(--text-caption); color: var(--color-text-2); margin-bottom: var(--space-3); }
.study-card .actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.editor { display: grid; gap: var(--space-4); }
.editor .two { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
@media (max-width: 640px) { .editor .two { grid-template-columns: 1fr; } }
.editor .sub { border: 1px solid var(--color-border); border-radius: var(--radius-panel); padding: var(--space-3); display: grid; gap: var(--space-2); }
.editor .sub .head { display: flex; justify-content: space-between; align-items: center; }
.problems { color: var(--color-error-text); font-size: var(--text-caption); }

/* ---- the Collector -------------------------------------------------------------------------------------------- */

.feed-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }
.feed-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: var(--text-small); }
.feed-card dt { color: var(--color-text-2); }
.feed-card dd { margin: 0; }
.progress { height: 4px; border-radius: 2px; background: var(--color-surface-alt); overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--color-success); }

/* ---- series swatches (the chart's colours, by position) --------------------------------------------------------- */

.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; vertical-align: middle; }
.swatch.round { border-radius: 50%; margin-right: 6px; }
.swatch.s1 { background: var(--chart-series-1); }
.swatch.s2 { background: var(--chart-series-2); }
.swatch.s3 { background: var(--chart-series-3); }
.swatch.s4 { background: var(--chart-series-4); }
