/* ══════════════════════════════════════════════════════════════════════════
   Markets OS — One Global Markets — design system

   Chrome  : Google Material tokens (surfaces, elevation, type, shape). The brand
             accent is a deep indigo (#3538CD family) with a teal secondary
             (#0E7C86) — a Global-Markets identity distinct from the sister
             Transaction Banking house, sharing the same bones.
   Data     : the pre-validated dataviz reference palette. Slot ORDER is the
              colourblind-safety mechanism — never reorder or cycle past 8. These
              --series-* / --seq-* variables are load-bearing; the server-rendered
              SVG charts read them directly, so they are ported unchanged.

   The chart surface (--surface-1) keeps the palette's own validated values
   rather than Material's, because the dark series steps were chosen for >=3:1
   against #1a1a19; Material's lighter #292a2d would erode that margin.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
    /* ── Material chrome (light) ─────────────────────────────────────────── */
    --md-bg: #f8f9fa;
    --md-surface: #ffffff;
    --md-surface-2: #f1f3f4;
    --md-surface-3: #e8eaed;
    --md-outline: #dadce0;
    --md-outline-soft: #e8eaed;
    --md-primary: #3538cd;
    --md-primary-wash: rgba(53, 56, 205, 0.08);
    --md-on-primary: #ffffff;
    --md-secondary: #0e7c86;
    --md-secondary-wash: rgba(14, 124, 134, 0.10);

    --md-text: #202124;
    --md-text-2: #5f6368;
    --md-text-3: #80868b;

    --md-shadow-1: 0 1px 2px 0 rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
    --md-shadow-2: 0 1px 3px 0 rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    --font: 'Google Sans', 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'Roboto Mono', ui-monospace, 'Cascadia Code', monospace;

    /* ── Chart surface & ink (validated values) ──────────────────────────── */
    --surface-1: #fcfcfb;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --gridline: #e1e0d9;
    --baseline: #c3c2b7;

    /* ── Categorical: fixed order, never cycled ──────────────────────────── */
    --series-1: #2a78d6;
    --series-2: #1baf7a;
    --series-3: #eda100;
    --series-4: #008300;
    --series-5: #4a3aa7;
    --series-6: #e34948;
    --series-7: #e87ba4;
    --series-8: #eb6834;

    /* ── Sequential: one hue, light -> dark ──────────────────────────────── */
    --seq-100: #cde2fb;
    --seq-150: #b7d3f6;
    --seq-200: #9ec5f4;
    --seq-250: #86b6ef;
    --seq-300: #6da7ec;
    --seq-350: #5598e7;
    --seq-400: #3987e5;
    --seq-450: #2a78d6;
    --seq-500: #256abf;
    --seq-550: #1c5cab;
    --seq-600: #184f95;
    --seq-650: #104281;
    --seq-700: #0d366b;

    /* ── Status: reserved, never used as a series colour ─────────────────── */
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
    --status-neutral: #898781;
}

:root[data-theme="dark"],
html.dark {
    --md-bg: #202124;
    --md-surface: #292a2d;
    --md-surface-2: #303134;
    --md-surface-3: #3c4043;
    --md-outline: #3c4043;
    --md-outline-soft: #303134;
    --md-primary: #a5a6f6;
    --md-primary-wash: rgba(165, 166, 246, 0.14);
    --md-on-primary: #1a1b2e;
    --md-secondary: #3fbfca;
    --md-secondary-wash: rgba(63, 191, 202, 0.16);

    --md-text: #e8eaed;
    --md-text-2: #9aa0a6;
    --md-text-3: #80868b;

    --md-shadow-1: 0 1px 2px 0 rgba(0, 0, 0, .3), 0 1px 3px 1px rgba(0, 0, 0, .15);
    --md-shadow-2: 0 1px 3px 0 rgba(0, 0, 0, .3), 0 4px 8px 3px rgba(0, 0, 0, .15);

    /* Validated dark surface — deliberately deeper than --md-surface. */
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
    --series-5: #9085e9;
    --series-6: #e66767;
    --series-7: #d55181;
    --series-8: #d95926;

    --seq-100: #0d366b;
    --seq-150: #104281;
    --seq-200: #184f95;
    --seq-250: #1c5cab;
    --seq-300: #256abf;
    --seq-350: #2a78d6;
    --seq-400: #3987e5;
    --seq-450: #5598e7;
    --seq-500: #6da7ec;
    --seq-550: #86b6ef;
    --seq-600: #9ec5f4;
    --seq-650: #b7d3f6;
    --seq-700: #cde2fb;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--md-bg);
    color: var(--md-text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

.visually-hidden {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── App shell ───────────────────────────────────────────────────────────── */

.app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }

.rail {
    background: var(--md-surface);
    border-right: 1px solid var(--md-outline);
    padding: 12px 8px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.rail-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px 20px;
    font-size: 1.05rem; font-weight: 500; letter-spacing: -0.2px;
}
.rail-brand .mark {
    width: 40px; height: 32px; border-radius: 8px; flex: none;
    background: var(--md-primary); color: var(--md-on-primary);
    display: grid; place-items: center; font-weight: 700; font-size: .75rem; letter-spacing: .5px;
}

.rail-group { margin-bottom: 4px; }
.rail-heading {
    padding: 14px 16px 6px; font-size: .6875rem; font-weight: 500;
    letter-spacing: .8px; text-transform: uppercase; color: var(--md-text-3);
}

.rail-item {
    display: flex; align-items: center; gap: 14px;
    padding: 9px 16px; margin: 1px 4px;
    border-radius: var(--radius-pill);
    color: var(--md-text-2); font-size: .875rem; font-weight: 500;
    text-decoration: none; transition: background .15s, color .15s;
}
.rail-item:hover { background: var(--md-surface-2); color: var(--md-text); text-decoration: none; }
.rail-item.active { background: var(--md-primary-wash); color: var(--md-primary); }
.rail-item .ico { width: 18px; text-align: center; flex: none; }
.rail-item .count {
    margin-left: auto; font-size: .75rem; font-weight: 500;
    background: var(--md-surface-3); color: var(--md-text-2);
    border-radius: var(--radius-pill); padding: 1px 8px;
}
.rail-item.active .count { background: var(--md-primary); color: var(--md-on-primary); }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 28px;
    background: var(--md-surface);
    border-bottom: 1px solid var(--md-outline);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.25rem; font-weight: 400; margin: 0; letter-spacing: -.2px; }
.topbar .spacer { flex: 1; }

.persona {
    display: flex; align-items: center; gap: 10px;
    padding: 5px 6px 5px 14px; border: 1px solid var(--md-outline);
    border-radius: var(--radius-pill); background: transparent;
    color: var(--md-text-2); font: inherit; font-size: .8125rem; cursor: pointer;
}
.persona:hover { background: var(--md-surface-2); }
.avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: none;
    background: var(--md-primary); color: var(--md-on-primary);
    display: grid; place-items: center; font-size: .75rem; font-weight: 500;
}

.icon-btn {
    width: 36px; height: 36px; border-radius: 50%; border: none;
    background: transparent; color: var(--md-text-2); cursor: pointer;
    display: grid; place-items: center; font-size: 1rem;
}
.icon-btn:hover { background: var(--md-surface-2); color: var(--md-text); }

.content { padding: 24px 28px 64px; max-width: 1600px; width: 100%; }

/* ── Cards & grid ────────────────────────────────────────────────────────── */

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.split { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.card {
    background: var(--md-surface);
    border: 1px solid var(--md-outline-soft);
    border-radius: var(--radius-lg);
    padding: 20px;
    min-width: 0;
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card.elevated { box-shadow: var(--md-shadow-1); border-color: transparent; }

.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.card-head h2, .card-head h3 {
    margin: 0; font-size: .9375rem; font-weight: 500; letter-spacing: -.1px;
}
.card-head .sub { margin: 2px 0 0; font-size: .8125rem; color: var(--md-text-2); }
.card-head .spacer { flex: 1; }

/* Charts render on the validated chart surface, not the Material card surface. */
.chart-surface {
    background: var(--surface-1);
    border-radius: var(--radius);
    padding: 12px 8px 4px;
}

/* ── Stat tiles & hero ───────────────────────────────────────────────────── */

.stat {
    background: var(--md-surface);
    border: 1px solid var(--md-outline-soft);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.stat .label { font-size: .8125rem; color: var(--md-text-2); }
/* Proportional figures: tabular-nums makes 121 look loose at display sizes. */
.stat .value { font-size: 1.75rem; font-weight: 500; letter-spacing: -.5px; line-height: 1.15; }
.stat .foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }
.stat .delta { font-size: .8125rem; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.stat .delta.up { color: var(--status-good); }
.stat .delta.down { color: var(--status-critical); }
.stat .delta.flat { color: var(--md-text-2); }

.hero-figure { font-size: 3rem; font-weight: 500; letter-spacing: -1.5px; line-height: 1; }
.hero-sub { color: var(--md-text-2); font-size: .875rem; margin-top: 6px; }

/* ── Badges, chips, pills ────────────────────────────────────────────────── */

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: var(--radius-pill);
    font-size: .75rem; font-weight: 500; white-space: nowrap;
}
/* Status never rides on colour alone — every badge carries an icon and a label. */
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.good     { color: #0a7d0a; background: rgba(12, 163, 12, .12); }
.badge.warning  { color: #8a5b00; background: rgba(250, 178, 25, .16); }
.badge.serious  { color: #a64b22; background: rgba(236, 131, 90, .16); }
.badge.critical { color: #b32626; background: rgba(208, 59, 59, .12); }
.badge.neutral  { color: var(--md-text-2); background: var(--md-surface-3); }

:root[data-theme="dark"] .badge.good     { color: #6dd36d; }
:root[data-theme="dark"] .badge.warning  { color: #fdd663; }
:root[data-theme="dark"] .badge.serious  { color: #f2a181; }
:root[data-theme="dark"] .badge.critical { color: #f28b82; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: var(--radius-pill);
    border: 1px solid var(--md-outline); background: transparent;
    color: var(--md-text-2); font: inherit; font-size: .8125rem; cursor: pointer;
    text-decoration: none;
}
.chip:hover { background: var(--md-surface-2); text-decoration: none; }
.chip.active { background: var(--md-primary-wash); border-color: transparent; color: var(--md-primary); }

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }

.tier { font-size: .6875rem; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; }
.tier.PLATINUM { color: #5f6368; }
.tier.GOLD { color: #b8860b; }
.tier.SILVER { color: #7d8085; }
.tier.BRONZE { color: #a1662f; }
.tier.UNRATED { color: var(--md-text-3); }

/* ── Buttons & forms ─────────────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 24px; border-radius: var(--radius-pill);
    border: 1px solid transparent; font: inherit; font-size: .875rem; font-weight: 500;
    cursor: pointer; text-decoration: none; transition: box-shadow .15s, background .15s;
}
.btn:hover { text-decoration: none; }
.btn-filled { background: var(--md-primary); color: var(--md-on-primary); }
.btn-filled:hover { box-shadow: var(--md-shadow-1); }
.btn-tonal { background: var(--md-primary-wash); color: var(--md-primary); }
.btn-outlined { border-color: var(--md-outline); color: var(--md-primary); background: transparent; }
.btn-text { color: var(--md-primary); background: transparent; padding: 9px 12px; }
.btn-danger { background: var(--status-critical); color: #fff; }
.btn:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
.btn-sm { padding: 6px 16px; font-size: .8125rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field label { font-size: .8125rem; color: var(--md-text-2); font-weight: 500; }
.field input, .field select, .field textarea {
    padding: 11px 14px; border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
    background: var(--md-surface); color: var(--md-text); font: inherit; font-size: .875rem;
    width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--md-primary); box-shadow: 0 0 0 1px var(--md-primary);
}
.field .hint { font-size: .75rem; color: var(--md-text-3); }
.field.error input, .field.error textarea { border-color: var(--status-critical); }
.field .err { font-size: .75rem; color: var(--status-critical); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: .8125rem; }
table.data caption { text-align: left; padding: 0 20px 12px; color: var(--md-text-2); }
table.data th {
    text-align: left; font-weight: 500; color: var(--md-text-2);
    padding: 12px 16px; border-bottom: 1px solid var(--md-outline);
    white-space: nowrap; font-size: .75rem; letter-spacing: .3px; text-transform: uppercase;
}
table.data td {
    padding: 13px 16px; border-bottom: 1px solid var(--md-outline-soft);
    vertical-align: middle;
}
table.data tbody tr:hover { background: var(--md-surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
/* Columns of numbers align; standalone display figures do not use tabular-nums. */
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.mono { font-family: var(--font-mono); font-size: .75rem; color: var(--md-text-2); }
table.data .row-link { color: var(--md-text); font-weight: 500; }

.empty-state { padding: 56px 20px; text-align: center; color: var(--md-text-2); }
.empty-state .ico { font-size: 2rem; color: var(--md-text-3); margin-bottom: 12px; }

/* ── Charts ──────────────────────────────────────────────────────────────── */
/* Class prefix stays tb-* on purpose: the server-rendered SVG chart, help and
   tooltip helpers are ported verbatim from the shared framework and emit these
   exact names, so the styles must match them 1:1. */

.tb-chart { display: block; overflow: visible; }
.tb-chart text { font-family: var(--font); }
.tb-axis-label { font-size: 10.5px; fill: var(--text-muted); }
.tb-axis-tick { font-size: 10.5px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.tb-axis-value { font-size: 11px; fill: var(--text-secondary); font-weight: 500; }
.tb-donut-value { font-size: 20px; font-weight: 500; fill: var(--text-primary); }
.tb-gauge-value { font-size: 22px; font-weight: 500; fill: var(--text-primary); }

.tb-mark { cursor: pointer; transition: opacity .12s; }
.tb-mark:hover, .tb-mark:focus-visible { opacity: .82; outline: none; }
.tb-sparkline .tb-mark { cursor: default; }

.tb-legend {
    list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px;
    margin: 12px 0 0; padding: 0 8px; font-size: .75rem; color: var(--md-text-2);
}
.tb-legend li { display: flex; align-items: center; gap: 7px; }
.tb-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.tb-table-view { margin-top: 12px; font-size: .8125rem; }
.tb-table-view summary {
    cursor: pointer; color: var(--md-text-2); font-size: .75rem;
    padding: 6px 8px; border-radius: var(--radius-sm); list-style-position: inside;
}
.tb-table-view summary:hover { background: var(--md-surface-2); }
.tb-table-view table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.tb-table-view th, .tb-table-view td {
    padding: 6px 10px; border-bottom: 1px solid var(--md-outline-soft); text-align: left;
}
.tb-table-view th { color: var(--md-text-2); font-weight: 500; }
.tb-table-view td { font-variant-numeric: tabular-nums; }

/* Tooltips enhance; they never gate a value. Every chart also has a table view. */
#tb-tooltip {
    position: fixed; z-index: 100; pointer-events: none; opacity: 0;
    transform: translate(-50%, -130%); transition: opacity .1s;
    background: var(--md-text); color: var(--md-surface);
    padding: 6px 10px; border-radius: 6px; font-size: .75rem; white-space: nowrap;
    box-shadow: var(--md-shadow-2);
}
#tb-tooltip.show { opacity: 1; }

/* ── Flash messages ──────────────────────────────────────────────────────── */

.flash {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 18px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: .875rem;
}
.flash.success { background: rgba(12, 163, 12, .12); color: #0a7d0a; }
.flash.error { background: rgba(208, 59, 59, .12); color: #b32626; }
.flash.info { background: var(--md-primary-wash); color: var(--md-primary); }

/* ── Timeline / detail panes ─────────────────────────────────────────────── */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 14px; padding: 10px 0; }
.timeline .node {
    width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 6px;
    background: var(--md-primary); box-shadow: 0 0 0 3px var(--md-primary-wash);
}
.timeline .body { min-width: 0; }
.timeline .when { font-size: .75rem; color: var(--md-text-3); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; font-size: .8125rem; }
.kv dt { color: var(--md-text-2); }
.kv dd { margin: 0; font-weight: 500; }

.sla-cell { display: flex; align-items: center; gap: 8px; }
.sla-cell .t { font-variant-numeric: tabular-nums; font-size: .75rem; min-width: 34px; }

/* ── App DAG canvas ──────────────────────────────────────────────────────── */
/* Champions compose an app as a directed graph: data sources flow through
   transforms and decisions, past controls, into sinks. The canvas is a scrollable
   surface; nodes are positioned by the view (inline-flow or absolute) and edges are
   drawn as SVG paths underneath. Node type is carried by a class so the accent rail
   reads at a glance without relying on colour alone — every node also shows a type
   label. */

.dag-canvas {
    position: relative;
    background: var(--surface-1);
    border: 1px solid var(--md-outline-soft);
    border-radius: var(--radius-lg);
    padding: 20px;
    overflow: auto;
    min-height: 260px;
}
/* Edges live in an SVG layer stretched behind the nodes. */
.dag-canvas > svg.dag-edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.dag-node {
    position: relative;
    display: inline-flex; flex-direction: column; gap: 4px;
    padding: 12px 16px;
    min-width: 148px; max-width: 240px;
    border: 1px solid var(--md-outline);
    border-left: 3px solid var(--md-text-3);
    border-radius: var(--radius);
    background: var(--md-surface);
    box-shadow: var(--md-shadow-1);
    font-size: .8125rem;
}
.dag-node .title { font-weight: 600; letter-spacing: -.1px; }
.dag-node .meta {
    font-size: .625rem; color: var(--md-text-3);
    text-transform: uppercase; letter-spacing: .5px;
}
.dag-node:hover { border-color: var(--md-primary); }

/* Node types — the left rail colour is a secondary cue to the type label. */
.dag-node.source    { border-left-color: var(--md-secondary); }
.dag-node.transform { border-left-color: var(--md-primary); }
.dag-node.decision  { border-left-color: var(--status-warning); }
.dag-node.control   { border-left-color: var(--status-critical); }
.dag-node.sink      { border-left-color: var(--status-good); }
.dag-node.selected  { outline: 2px solid var(--md-primary); outline-offset: 1px; }

/* A small pill in the node corner: run state, count, or type glyph. */
.dag-node-badge {
    position: absolute; top: -8px; right: 10px;
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: var(--radius-pill);
    font-size: .625rem; font-weight: 600; letter-spacing: .3px;
    background: var(--md-primary-wash); color: var(--md-primary);
    border: 1px solid var(--md-surface);
}
.dag-node-badge.ok       { background: rgba(12, 163, 12, .14); color: #0a7d0a; }
.dag-node-badge.warning  { background: rgba(250, 178, 25, .18); color: #8a5b00; }
.dag-node-badge.error    { background: rgba(208, 59, 59, .14); color: #b32626; }
:root[data-theme="dark"] .dag-node-badge.ok      { color: #6dd36d; }
:root[data-theme="dark"] .dag-node-badge.warning { color: #fdd663; }
:root[data-theme="dark"] .dag-node-badge.error   { color: #f28b82; }

.dag-edge { stroke: var(--baseline); stroke-width: 1.5; fill: none; }
.dag-edge.active { stroke: var(--md-primary); stroke-width: 2; }
.dag-edge.muted  { stroke: var(--gridline); stroke-dasharray: 4 4; }

/* ── Governance pipeline strip ───────────────────────────────────────────── */
/* An app's path from draft to production, shown as an ordered strip of stages.
   done / active / pending communicate progress with an icon and label as well as
   the fill — status is never colour alone. Chevrons imply direction of travel. */

.gov-pipeline { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.gov-stage {
    position: relative;
    display: flex; flex-direction: column; gap: 2px;
    padding: 10px 20px 10px 26px;
    background: var(--md-surface-2);
    border: 1px solid var(--md-outline-soft);
    border-radius: var(--radius-sm);
    min-width: 132px;
    font-size: .8125rem;
}
.gov-stage .step { font-size: .625rem; color: var(--md-text-3); text-transform: uppercase; letter-spacing: .5px; }
.gov-stage .name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.gov-stage .name i { font-size: .75rem; }

.gov-stage.done {
    background: var(--md-secondary-wash);
    border-color: transparent; color: var(--md-secondary);
}
.gov-stage.done .step { color: var(--md-secondary); opacity: .85; }
.gov-stage.active {
    background: var(--md-primary-wash);
    border-color: var(--md-primary); color: var(--md-primary);
}
.gov-stage.active .step { color: var(--md-primary); opacity: .85; }
.gov-stage.pending { color: var(--md-text-3); }
.gov-stage.blocked {
    background: rgba(208, 59, 59, .10);
    border-color: var(--status-critical); color: #b32626;
}
:root[data-theme="dark"] .gov-stage.blocked { color: #f28b82; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1200px) {
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }
    .rail { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--md-outline); }
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .content { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media print {
    .rail, .topbar, .tb-table-view summary, .mos-copilot-launch, .mos-copilot { display: none; }
    .card { break-inside: avoid; }
}

/* ── Inline help: info dots and self-explaining terms ─────────────────────── */
/* Prefix stays tb-* to match the verbatim-ported Help helper's output. */

.tb-tip {
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: 5px; color: var(--md-text-3); font-size: .8125rem;
    cursor: help; vertical-align: middle; line-height: 1;
}
.tb-tip:hover, .tb-tip:focus-visible { color: var(--md-primary); outline: none; }

.tb-term {
    border-bottom: 1px dotted var(--md-text-3); cursor: help;
    text-decoration: none; color: inherit;
}
.tb-term:hover, .tb-term:focus-visible { border-bottom-color: var(--md-primary); color: var(--md-primary); outline: none; }

.tb-help-link {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: .75rem; color: var(--md-text-2); text-decoration: none;
}
.tb-help-link:hover { color: var(--md-primary); text-decoration: none; }

/* ── Markets Copilot ─────────────────────────────────────────────────────── */
/* The floating pair-programmer for app builders. Own prefix (mos-copilot-*) since
   it is bespoke to this platform and referenced only by copilot.php and app.js. */

.mos-copilot-launch {
    position: fixed; right: 24px; bottom: 24px; z-index: 60;
    display: inline-flex; align-items: center; gap: 9px;
    padding: 12px 20px; border: none; border-radius: var(--radius-pill);
    background: var(--md-primary); color: var(--md-on-primary);
    font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer;
    box-shadow: var(--md-shadow-2);
}
.mos-copilot-launch i { font-size: 1rem; }
.mos-copilot-launch:hover { filter: brightness(1.05); }

.mos-copilot {
    position: fixed; right: 24px; bottom: 24px; z-index: 61;
    width: 380px; max-width: calc(100vw - 32px);
    height: 560px; max-height: calc(100vh - 48px);
    display: none; flex-direction: column;
    background: var(--md-surface); border: 1px solid var(--md-outline);
    border-radius: var(--radius-lg); box-shadow: var(--md-shadow-2); overflow: hidden;
}
.mos-copilot.open { display: flex; }

.mos-copilot-head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; border-bottom: 1px solid var(--md-outline-soft);
}
.mos-copilot-title { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.mos-copilot-mark {
    width: 34px; height: 34px; border-radius: 9px; flex: none;
    background: var(--md-primary-wash); color: var(--md-primary);
    display: grid; place-items: center; font-size: .9rem;
}
.mos-copilot-title strong { display: block; font-size: .9375rem; }
.mos-copilot-tag { display: block; font-size: .6875rem; color: var(--md-text-3); }
.mos-copilot-close {
    width: 32px; height: 32px; border-radius: 50%; border: none; flex: none;
    background: transparent; color: var(--md-text-2); cursor: pointer;
}
.mos-copilot-close:hover { background: var(--md-surface-2); color: var(--md-text); }

.mos-copilot-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.mos-copilot-msg { max-width: 88%; font-size: .8125rem; line-height: 1.55; }
.mos-copilot-msg.user {
    align-self: flex-end; background: var(--md-primary); color: var(--md-on-primary);
    padding: 9px 14px; border-radius: 14px 14px 4px 14px;
}
.mos-copilot-msg.bot {
    align-self: flex-start; background: var(--md-surface-2); color: var(--md-text);
    padding: 11px 14px; border-radius: 14px 14px 14px 4px;
}
.mos-copilot-answer strong { font-weight: 600; }
.mos-copilot-answer a { color: var(--md-primary); }

.mos-copilot-msg.typing { display: flex; gap: 4px; align-items: center; }
.mos-copilot-msg.typing span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--md-text-3);
    animation: mos-copilot-blink 1.2s infinite both;
}
.mos-copilot-msg.typing span:nth-child(2) { animation-delay: .2s; }
.mos-copilot-msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes mos-copilot-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.mos-copilot-suggest { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 16px 8px; }
.mos-copilot-chip {
    border: 1px solid var(--md-outline); background: transparent;
    color: var(--md-text-2); font: inherit; font-size: .75rem; cursor: pointer;
    padding: 6px 12px; border-radius: var(--radius-pill); text-align: left;
}
.mos-copilot-chip:hover { background: var(--md-primary-wash); border-color: transparent; color: var(--md-primary); }

.mos-copilot-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--md-outline-soft); }
.mos-copilot-form input {
    flex: 1; min-width: 0; padding: 10px 14px; font: inherit; font-size: .8125rem;
    border: 1px solid var(--md-outline); border-radius: var(--radius-pill);
    background: var(--md-surface); color: var(--md-text);
}
.mos-copilot-form input:focus { outline: none; border-color: var(--md-primary); box-shadow: 0 0 0 1px var(--md-primary); }
.mos-copilot-form button {
    width: 40px; height: 40px; flex: none; border: none; border-radius: 50%;
    background: var(--md-primary); color: var(--md-on-primary); cursor: pointer;
}
.mos-copilot-form button:hover { filter: brightness(1.05); }

@media (max-width: 600px) {
    .mos-copilot { right: 8px; bottom: 8px; height: calc(100vh - 16px); }
    .mos-copilot-launch { right: 12px; bottom: 12px; }
    .mos-copilot-launch span { display: none; }
}

/* ══════════════════════════════════════════════════════════════════════════
   App Studio — visual workflow designer (builder.js)

   A real low-code editor: a palette of draggable node-type chips, a scrollable
   canvas of positioned .dag-node boxes wired by SVG bezier edges, and a right-
   hand inspector that edits the selected node's label and config. Everything is
   painted from the existing design tokens so the builder reads as one system
   with the read-only canvas it replaces.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Toolbar & status ────────────────────────────────────────────────────── */
.builder-toolbar {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; flex-wrap: wrap;
}
.builder-toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }
.builder-toolbar .spacer { flex: 1; min-width: 8px; }

.builder-status {
    font-size: .8125rem; color: var(--md-text-2);
    padding: 9px 14px; margin-bottom: 12px;
    border: 1px solid var(--md-outline-soft); border-left: 3px solid var(--md-text-3);
    border-radius: var(--radius-sm); background: var(--md-surface);
}
.builder-status.ok { border-left-color: var(--status-good); color: var(--md-text); }
.builder-status.error { border-left-color: var(--status-critical); color: #b32626; }
:root[data-theme="dark"] .builder-status.error { color: #f28b82; }

/* ── Three-column workbench ──────────────────────────────────────────────── */
.builder-shell {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr) 300px;
    gap: 12px; align-items: start;
}

/* ── Palette ─────────────────────────────────────────────────────────────── */
.builder-palette { padding: 16px; position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; }
.builder-palette-group { margin-bottom: 14px; }
.builder-palette-heading {
    display: flex; align-items: center; gap: 6px;
    font-size: .625rem; text-transform: uppercase; letter-spacing: .6px;
    color: var(--md-text-3); margin-bottom: 7px;
}
.palette-chip {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 8px 11px; margin-bottom: 5px;
    font: inherit; font-size: .78rem; text-align: left;
    background: var(--md-surface); color: var(--md-text);
    border: 1px solid var(--md-outline); border-left: 3px solid var(--md-text-3);
    border-radius: var(--radius-sm);
    cursor: grab; touch-action: none; user-select: none;
    transition: background .12s, box-shadow .12s;
}
.palette-chip:hover { background: var(--md-surface-2); box-shadow: var(--md-shadow-1); }
.palette-chip:active { cursor: grabbing; }
.palette-chip i { width: 15px; text-align: center; flex: none; }

/* A lightweight cursor-following ghost while dragging a palette chip. */
.builder-ghost {
    position: fixed; z-index: 80; pointer-events: none;
    transform: translate(10px, 10px);
    padding: 7px 12px; font-size: .78rem; font-weight: 500;
    background: var(--md-primary); color: var(--md-on-primary);
    border-radius: var(--radius-sm); box-shadow: var(--md-shadow-2);
    opacity: .92;
}

/* ── Canvas ──────────────────────────────────────────────────────────────── */
.builder-canvas-card { padding: 0; overflow: hidden; }
.builder-canvas {
    position: relative;
    height: 620px; max-height: calc(100vh - 150px);
    overflow: auto;
    background: var(--surface-1);
    background-image:
        linear-gradient(var(--gridline) 1px, transparent 1px),
        linear-gradient(90deg, var(--gridline) 1px, transparent 1px);
    background-size: 22px 22px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.builder-surface { position: relative; width: 100%; height: 100%; min-width: 640px; min-height: 360px; }
.builder-surface > svg.builder-edges {
    position: absolute; top: 0; left: 0; overflow: visible;
}
.builder-edges-layer, .builder-edges { pointer-events: none; }

.builder-hint {
    margin: 0; padding: 10px 16px; font-size: .75rem; color: var(--md-text-3);
    border-top: 1px solid var(--md-outline-soft); background: var(--md-surface);
}
.builder-hint i { margin-right: 5px; }

/* Edges: a visible bezier plus a wide transparent hit path for easy selection. */
.builder-edge { stroke: var(--baseline); stroke-width: 1.6; fill: none; transition: stroke .12s; }
.builder-edge.selected { stroke: var(--md-primary); stroke-width: 2.4; }
.builder-edge-hit { stroke: transparent; stroke-width: 14; fill: none; pointer-events: stroke; cursor: pointer; }
.builder-edge-label {
    font-size: 10.5px; fill: var(--md-text-2);
    paint-order: stroke; stroke: var(--surface-1); stroke-width: 3px; stroke-linejoin: round;
}
.builder-rubber {
    stroke: var(--md-primary); stroke-width: 2; stroke-dasharray: 5 4; fill: none; pointer-events: none;
}

/* Nodes on the editable canvas: draggable, selectable, with I/O ports. */
.builder-node {
    position: absolute;
    cursor: grab; touch-action: none; user-select: none;
    box-shadow: var(--md-shadow-1);
    transition: box-shadow .12s, outline-color .12s;
}
.builder-node:active { cursor: grabbing; }
.builder-node .title { pointer-events: none; }
.builder-node .meta { pointer-events: none; }
.builder-node.selected { outline: 2px solid var(--md-primary); outline-offset: 2px; box-shadow: var(--md-shadow-2); }
.builder-node.connect-target { outline: 2px dashed var(--status-good); outline-offset: 2px; }

.builder-node-del {
    position: absolute; top: -9px; left: -9px;
    width: 20px; height: 20px; border-radius: 50%;
    border: 1px solid var(--md-outline); background: var(--md-surface);
    color: var(--md-text-2); font-size: .7rem; line-height: 1;
    display: none; place-items: center; cursor: pointer; z-index: 3;
}
.builder-node:hover .builder-node-del,
.builder-node.selected .builder-node-del { display: grid; }
.builder-node-del:hover { background: var(--status-critical); color: #fff; border-color: transparent; }

/* Ports: input on the left edge, output on the right edge. */
.builder-port {
    position: absolute; top: 50%; width: 13px; height: 13px;
    border-radius: 50%; background: var(--md-surface);
    border: 2px solid var(--md-text-3); transform: translate(-50%, -50%);
    z-index: 2;
}
.builder-port.port-in { left: 0; }
.builder-port.port-out { left: 100%; cursor: crosshair; }
.builder-node:hover .builder-port { border-color: var(--md-primary); }
.builder-port.port-out:hover { background: var(--md-primary); border-color: var(--md-primary); transform: translate(-50%, -50%) scale(1.25); }

/* ── Inspector ───────────────────────────────────────────────────────────── */
.builder-inspector-card { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; }
.builder-inspector-empty { font-size: .8125rem; color: var(--md-text-3); line-height: 1.55; margin: 0; }
.builder-inspector-title {
    display: flex; align-items: center; gap: 8px;
    font-size: .875rem; font-weight: 600; margin-bottom: 12px;
    padding-bottom: 8px; border-bottom: 1px solid var(--md-outline-soft);
}
.builder-inspector-title i { color: var(--md-primary); }

.builder-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.builder-field > label { font-size: .75rem; font-weight: 500; color: var(--md-text-2); }
.builder-field input, .builder-field select, .builder-field textarea {
    padding: 8px 11px; border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
    background: var(--md-surface); color: var(--md-text); font: inherit; font-size: .8125rem; width: 100%;
}
.builder-field input:focus, .builder-field select:focus, .builder-field textarea:focus {
    outline: none; border-color: var(--md-primary); box-shadow: 0 0 0 1px var(--md-primary);
}
.builder-readonly { color: var(--md-text-2); background: var(--md-surface-2); cursor: default; }

.builder-config-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: .75rem; font-weight: 600; color: var(--md-text-2);
    text-transform: uppercase; letter-spacing: .5px;
    margin: 16px 0 8px;
}
.builder-config { display: flex; flex-direction: column; gap: 10px; }
.builder-config-row {
    padding: 9px 10px; border: 1px solid var(--md-outline-soft);
    border-radius: var(--radius-sm); background: var(--md-surface-2);
}
.builder-config-keyline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.builder-config-key {
    font-family: var(--font-mono); font-size: .72rem; color: var(--md-text);
    font-weight: 500; word-break: break-all;
}
.builder-config-del {
    width: 20px; height: 20px; flex: none; border-radius: 50%;
    border: none; background: transparent; color: var(--md-text-3);
    cursor: pointer; font-size: .72rem; display: grid; place-items: center;
}
.builder-config-del:hover { background: var(--status-critical); color: #fff; }
.builder-config-row input, .builder-config-row select, .builder-config-row textarea {
    width: 100%; padding: 7px 10px; font: inherit; font-size: .8rem;
    border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
    background: var(--md-surface); color: var(--md-text);
}
.builder-json-value { font-family: var(--font-mono); font-size: .72rem; resize: vertical; }
.builder-json-value.error { border-color: var(--status-critical); box-shadow: 0 0 0 1px var(--status-critical); }
.builder-bool { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--md-text-2); cursor: pointer; }
.builder-bool input { width: auto; }

.builder-addkey { display: flex; gap: 8px; margin: 12px 0 16px; }
.builder-addkey-input { flex: 1; min-width: 0; padding: 7px 10px; font: inherit; font-size: .8rem;
    border: 1px solid var(--md-outline); border-radius: var(--radius-sm);
    background: var(--md-surface); color: var(--md-text); }
.builder-inspector-delete { width: 100%; }

/* ── Responsive: stack the workbench on narrow viewports ─────────────────── */
@media (max-width: 1200px) {
    .builder-shell { grid-template-columns: 180px minmax(0, 1fr); }
    .builder-inspector-card { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 960px) {
    .builder-shell { grid-template-columns: minmax(0, 1fr); }
    .builder-palette { position: static; max-height: none; }
    .builder-palette-group { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
    .builder-palette-heading { grid-column: 1 / -1; }
}
