/* asoshka design system. Colours are named by meaning, not by place: a state looks the same on
   every screen. Contrast is held by ThemeContrastTest - change a colour, run it. */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #dde1e6;
    --text: #1d2127;
    --text-muted: #5b6470;
    --accent: #2f5bd3;
    --ok: #176b30;
    --ok-bg: #e3f4e6;
    --warn: #7f5200;
    --warn-bg: #fdf1d6;
    --fail: #b42318;
    --fail-bg: #fde8e6;
    --agent: #0b5f9e;
    --agent-bg: #e1f0fb;
    --stuck: #7a3fa8;
    --stuck-bg: #f1e6fa;
    --neutral: #515964;
    --neutral-bg: #eceef1;
    --series-own: #2f5bd3;
    --series-rival-1: #b4531c;
    --series-rival-2: #177a6e;
    --series-rival-3: #8a3fa8;
    --series-rival-4: #9a7a00;
    --series-rival-5: #5b6470;
    --series-bucket-top3: #176b30;
    --series-bucket-top10: #4f9b5f;
    --series-bucket-top30: #9fbf5a;
    --series-bucket-top100: #d8b04a;
    --series-bucket-deep: #c98a5a;
    --series-bucket-absent: #b4bcc6;
    --series-bucket-none: #eceef1;
    --marker-release: #176b30;
    --marker-window: #7f5200;
    --marker-verdict: #7a3fa8;
    --marker-universe: #515964;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 1px rgba(0, 0, 0, .04);
    --font-s: 12px;
    --font-m: 14px;
    --font-l: 18px;
    --font-xl: 28px;
    --sidebar: 220px;
    --sidebar-collapsed: 56px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #111418;
        --surface: #1a1e24;
        --surface-2: #222730;
        --border: #2e343d;
        --text: #e6e9ee;
        --text-muted: #9aa3ae;
        --accent: #7aa2ff;
        --ok: #6fd48a;
        --ok-bg: #173323;
        --warn: #f0c060;
        --warn-bg: #3a2e12;
        --fail: #ff8a80;
        --fail-bg: #3d1a18;
        --agent: #6cb8f0;
        --agent-bg: #13304a;
        --stuck: #c9a0f0;
        --stuck-bg: #2e1f40;
        --neutral: #9fb0c4;
        --neutral-bg: #2a2f37;
        --series-own: #7aa2ff;
        --series-rival-1: #f0a070;
        --series-rival-2: #5fd0bf;
        --series-rival-3: #c9a0f0;
        --series-rival-4: #e6cc5a;
        --series-rival-5: #9aa3ae;
        --series-bucket-top3: #6fd48a;
        --series-bucket-top10: #4f9b5f;
        --series-bucket-top30: #7d9440;
        --series-bucket-top100: #9a7a2a;
        --series-bucket-deep: #7a5236;
        --series-bucket-absent: #3a4048;
        --series-bucket-none: #222730;
        --marker-release: #6fd48a;
        --marker-window: #f0c060;
        --marker-verdict: #c9a0f0;
        --marker-universe: #9fb0c4;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #222730;
    --border: #2e343d;
    --text: #e6e9ee;
    --text-muted: #9aa3ae;
    --accent: #7aa2ff;
    --ok: #6fd48a;
    --ok-bg: #173323;
    --warn: #f0c060;
    --warn-bg: #3a2e12;
    --fail: #ff8a80;
    --fail-bg: #3d1a18;
    --agent: #6cb8f0;
    --agent-bg: #13304a;
    --stuck: #c9a0f0;
    --stuck-bg: #2e1f40;
    --neutral: #9fb0c4;
    --neutral-bg: #2a2f37;
    --series-own: #7aa2ff;
    --series-rival-1: #f0a070;
    --series-rival-2: #5fd0bf;
    --series-rival-3: #c9a0f0;
    --series-rival-4: #e6cc5a;
    --series-rival-5: #9aa3ae;
    --series-bucket-top3: #6fd48a;
    --series-bucket-top10: #4f9b5f;
    --series-bucket-top30: #7d9440;
    --series-bucket-top100: #9a7a2a;
    --series-bucket-deep: #7a5236;
    --series-bucket-absent: #3a4048;
    --series-bucket-none: #222730;
    --marker-release: #6fd48a;
    --marker-window: #f0c060;
    --marker-verdict: #c9a0f0;
    --marker-universe: #9fb0c4;
    color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--font-m)/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1 { font-size: var(--font-xl); margin: 0 0 var(--space-4); }
h2 { font-size: var(--font-l); margin: 0 0 var(--space-3); }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); flex: none; background: var(--surface); border-right: 1px solid var(--border); padding: var(--space-3); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: var(--space-3); }
.nav-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2); border-radius: var(--radius); color: var(--text); text-decoration: none; white-space: nowrap; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.on { background: var(--surface-2); font-weight: 600; }
.nav-item .ico { width: 24px; text-align: center; flex: none; }
.nav-group { margin: var(--space-4) var(--space-2) var(--space-1); color: var(--text-muted); font-size: var(--font-s); text-transform: uppercase; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { background: none; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: var(--space-1) var(--space-2); cursor: pointer; }
:root[data-nav="collapsed"] .sidebar { width: var(--sidebar-collapsed); }
:root[data-nav="collapsed"] .sidebar .lbl, :root[data-nav="collapsed"] .nav-group { display: none; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-6); background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-spacer { flex: 1; }
.content, .main > main { display: block; max-width: 1440px; padding: var(--space-6); }

/* App switcher */
.switcher { position: relative; }
.switcher summary { list-style: none; display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.switcher summary::-webkit-details-marker { display: none; }
.switcher ul { position: absolute; z-index: 10; top: 100%; left: 0; min-width: 260px; margin: var(--space-1) 0 0; padding: var(--space-1); list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.switcher li a { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.switcher li a:hover { background: var(--surface-2); }

/* Cards and grids */
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: var(--space-6); }
.grid-wide { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-4); min-width: 0; }
.card + .card { margin-top: var(--space-4); }
.grid > .card + .card { margin-top: 0; }
.card.muted { opacity: .72; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.card-head h2, .card-head h3 { margin: 0; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--border); padding: var(--space-2) var(--space-3); text-align: left; }
th { font-weight: 600; color: var(--text-muted); }

/* KPI tiles */
.kpi-head { display: flex; align-items: center; gap: var(--space-1); color: var(--text-muted); }
.kpi-value { font-size: var(--font-xl); font-weight: 600; margin: var(--space-1) 0; }
.kpi-secondary { color: var(--text-muted); font-size: var(--font-s); }
.kpi-foot { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); color: var(--text-muted); }
.kpi.has-top { position: relative; cursor: default; }
.kpi-top { display: none; position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% - var(--space-2));
    max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-2) var(--space-3); }
.kpi.has-top:hover .kpi-top, .kpi.has-top:focus-within .kpi-top { display: block; }
.kpi-top ol { list-style: none; margin: 0; padding: 0; }
.kpi-top li { display: flex; gap: var(--space-2); padding: 2px 0; }
.kpi-top-place { min-width: 2.5em; text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sparkline { width: 100px; height: 24px; color: var(--series-own); }

/* Values in their three states */
.value-none { color: var(--text-muted); cursor: help; }
.value-stale { opacity: .6; }
.stale-mark { display: block; font-size: var(--font-s); font-weight: normal; color: var(--warn); }

/* Changes */
.delta-good { color: var(--ok); }
.delta-bad { color: var(--fail); }
.delta-neutral { color: var(--text-muted); }

/* Badges */
.badge { display: inline-block; padding: 1px var(--space-2); border-radius: 999px; font-size: var(--font-s); font-weight: 600; }
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }
.badge-fail { color: var(--fail); background: var(--fail-bg); }
.badge-agent { color: var(--agent); background: var(--agent-bg); }
.badge-stuck { color: var(--stuck); background: var(--stuck-bg); }
.badge-neutral { color: var(--neutral); background: var(--neutral-bg); }

/* Help: a quiet button next to a heading, the text in a panel on the right. */
.help-button { margin-left: var(--space-2); padding: 0 var(--space-2); border-radius: 999px; background: none; color: var(--text-muted); font-size: var(--font-s); font-weight: normal; vertical-align: middle; }
.help-button:hover, .help-button:focus-visible { color: var(--accent); border-color: var(--accent); }
.help-icon { margin-left: var(--space-1); padding: 0 var(--space-1); border: none; }
.help-panel { position: fixed; z-index: 20; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); overflow-y: auto; padding: var(--space-6) var(--space-6) var(--space-6); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -4px 0 16px rgba(0, 0, 0, .12); color: var(--text); }
.help-panel:focus { outline: none; }
.help-close { position: absolute; top: var(--space-3); right: var(--space-3); }
.help-body h2 { margin: 0 var(--space-6) var(--space-3) 0; font-size: var(--font-l); }
.help-body h3 { margin: var(--space-4) 0 var(--space-1); font-size: var(--font-m); }
.help-body p, .help-body li { line-height: 1.5; }
.help-body ul { padding-left: var(--space-4); }
.help-body dt { font-weight: 600; margin-top: var(--space-2); }
.help-body dd { margin: 0 0 var(--space-1); }

/* App icon: the letter sits under the image and shows when the image is removed on error. */
.app-icon { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 22%; overflow: hidden; background: var(--surface-2); color: var(--text-muted); font-weight: 600; }
.app-icon img { position: absolute; inset: 0; width: 100%; height: 100%; }
.app-icon-s { width: 24px; height: 24px; font-size: 12px; }
.app-icon-m { width: 40px; height: 40px; font-size: 18px; }
.app-icon-l { width: 64px; height: 64px; font-size: 28px; }

/* Charts */
.chart { width: 100%; }
.chart-loading, .chart-empty { color: var(--text-muted); }
.chart-error { color: var(--fail); }

/* Sign-in page: layout only, colours come from the tokens. */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.login .card { width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: var(--space-3); }
.login h1 { margin: 0; }
.login label { display: flex; flex-direction: column; gap: var(--space-1); color: var(--text-muted); }
.login input[type="text"], .login input[type="password"] { font: inherit; padding: var(--space-2); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.login .login-remember { flex-direction: row; align-items: center; gap: var(--space-2); }
.topbar-signout { margin: 0; }

/* Empty states and actions */
.empty { padding: var(--space-6); text-align: center; color: var(--text-muted); }
.action { display: inline; }
button, .button { font: inherit; padding: var(--space-1) var(--space-3); border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
.button-primary { background: var(--accent); border-color: var(--accent); color: #ffffff; }

/* Legacy pages rendered inside the new shell keep their state backgrounds, now from the tokens. */
.none { color: var(--text-muted); }
.degraded, .blocking { background: var(--fail-bg); }
.waiting { background: var(--warn-bg); }
.pending { background: var(--agent-bg); }
.stuck { background: var(--stuck-bg); }
.shared, .shared-legend { background: var(--ok-bg); }
.flash { background: var(--neutral-bg); }
.blocking, .waiting, .pending, .stuck, .flash { padding: var(--space-2) var(--space-3); }
p.hint { color: var(--text-muted); max-width: 46rem; }
.added { color: var(--ok); }
.removed { color: var(--fail); }
code.field { word-break: break-all; }

/* Narrow screens: the panel hides, cards stack; tables scroll inside their card. */
@media (max-width: 800px) {
    .sidebar { display: none; }
    .topbar, .content, .main > main { padding-left: var(--space-4); padding-right: var(--space-4); }
    .topbar { flex-wrap: wrap; row-gap: var(--space-2); }
    .grid, .grid-wide { grid-template-columns: 1fr; }
}

/* Stage 2: attention list, the day's timeline, the connection checklist. */
.indicator { text-decoration: none; }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); padding: var(--space-1) 0; }
.timeline-day h3 { margin: var(--space-3) 0 var(--space-1); }
.timeline-line { display: grid; grid-template-columns: minmax(120px, 280px) 1fr; gap: var(--space-2); align-items: center; padding: 2px 0; }
.timeline-name { color: var(--text-muted); font-size: var(--font-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-bar { position: relative; height: 14px; background: var(--surface-2); border-radius: var(--radius);
    background-image: repeating-linear-gradient(90deg, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%); }
.timeline-mark { position: absolute; top: 2px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; border: 1px solid currentColor; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-3); }
.step .card-head { margin-bottom: var(--space-1); flex-wrap: wrap; }

/* Stage 3: the keyword table's filters and pages, the heatmap. */
.filter-states { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-3); }
.filter-states a, .pages a { text-decoration: none; padding: 2px var(--space-2); border-radius: var(--radius); }
.filter-states a.on, .pages a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-bottom: var(--space-3); }
.pages { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-top: var(--space-3); }
.keywords td form { display: inline; }
.heatmap td.cell { width: 10px; min-width: 10px; padding: 0; height: 18px; }
.heatmap td.cell-top3 { background: var(--series-bucket-top3); }
.heatmap td.cell-top10 { background: var(--series-bucket-top10); }
.heatmap td.cell-top30 { background: var(--series-bucket-top30); }
.heatmap td.cell-top100 { background: var(--series-bucket-top100); }
.heatmap td.cell-deep { background: var(--series-bucket-deep); }
.heatmap td.cell-absent { background: var(--series-bucket-absent); }
.heatmap td.cell-none { background: var(--series-bucket-none); }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--font-s); color: var(--text-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.serp-own { background: var(--agent-bg); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); padding: 3px 0; }

/* Decisions (dashboard stage 5): the lean card, the timeline, the effect chart. */
.decision-top { margin: var(--space-1) 0; }
.proposal .card-head { gap: var(--space-2); }
.diff { margin: var(--space-2) 0; line-height: 1.8; }
.diff-arrow { color: var(--text-muted); margin: 0 var(--space-2); }
.diff-removed { color: var(--fail); text-decoration: line-through; }
.diff-added { color: var(--ok); background: var(--ok-bg); border-radius: 3px; padding: 0 2px; font-weight: 600; }
.diff-kept { color: var(--text); }
.expected, .when { margin: var(--space-1) 0; }
.when { color: var(--text-muted); }
.warnings { padding: var(--space-2) var(--space-3); }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-3) 0; }
.actions form { display: inline; }
details.more { margin-top: var(--space-2); }
details.more > summary, .journal-more summary { cursor: pointer; color: var(--accent); }
.journal-more td { border-top: none; padding-top: 0; }

.timeline { display: flex; flex-direction: column; gap: var(--space-1); }
.timeline-axis, .timeline-row { display: grid; grid-template-columns: minmax(8rem, 16rem) 1fr 7rem; align-items: center; gap: var(--space-2); }
.timeline-axis { position: relative; font-size: var(--font-s); color: var(--text-muted); height: 1.2rem; }
.timeline-axis { grid-template-columns: 1fr; margin-left: calc(min(16rem, 30%) + var(--space-2)); margin-right: calc(7rem + var(--space-2)); }
.timeline-from { position: absolute; left: 0; }
.timeline-to { position: absolute; right: 0; }
.timeline-tick { position: absolute; transform: translateX(-50%); }
.timeline-label { font-size: var(--font-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-track { position: relative; height: 14px; background: var(--neutral-bg); border-radius: 3px; }
.timeline-seg { position: absolute; top: 2px; bottom: 2px; border-radius: 2px; }
.seg-pending { background: var(--agent); }
.seg-written { background: var(--warn); }
.seg-window { background: var(--accent); }
.seg-awaiting { background: var(--stuck); }
.seg-open { opacity: .55; }
.timeline-verdict { position: absolute; top: -2px; width: 10px; height: 18px; margin-left: -5px; border-radius: 3px; border: 1px solid var(--surface); }
.tone-good { background: var(--ok); }
.tone-bad { background: var(--fail); }
.tone-neutral, .tone-muted, .tone-none { background: var(--neutral); }
.timeline-status { font-size: var(--font-s); color: var(--text-muted); }

.effect { margin: var(--space-2) 0; max-width: 46rem; }
.effect-row { display: grid; grid-template-columns: 12rem 1fr 5rem; gap: var(--space-2); align-items: center; }
.effect-term { font-size: var(--font-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.effect-track { position: relative; height: 14px; }
.effect-zero { position: absolute; left: 50%; top: 0; bottom: 0; border-left: 1px solid var(--text-muted); }
.effect-bar-line { position: absolute; top: -2px; bottom: -2px; border-left: 1px dashed var(--stuck); }
.effect-bar { position: absolute; top: 3px; bottom: 3px; border-radius: 2px; opacity: .55; }
.effect-up { background: var(--ok); }
.effect-down { background: var(--fail); }
.effect-beyond { opacity: 1; }
.effect-value { font-size: var(--font-s); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
    .timeline-row { grid-template-columns: 1fr; }
    .timeline-axis { margin: 0; }
    .effect-row { grid-template-columns: 7rem 1fr 4rem; }
}

/* Analytics (dashboard stage 5). */
.funnel { display: flex; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-2); }
.funnel-step { display: flex; flex-direction: column; gap: var(--space-1); min-width: 10rem; }
.funnel-conv { font-size: var(--font-s); color: var(--text-muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: var(--space-1); vertical-align: middle; }

/* Pipeline: health first, then a tile per stage, then the plumbing. */
.page-head { display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.page-head h1 { margin-bottom: var(--space-3); }
.section-title { margin: var(--space-6) 0 var(--space-3); }
.calm { color: var(--ok); margin: 0; }
table.compact th, table.compact td { padding: var(--space-1) var(--space-2); font-size: var(--font-s); }

.health { --tone: var(--ok); --tone-bg: var(--ok-bg); background: var(--surface); border: 1px solid var(--border);
    border-left: 4px solid var(--tone); border-radius: 0; box-shadow: var(--shadow);
    padding: var(--space-4) var(--space-6); margin-bottom: var(--space-4);
    display: grid; gap: var(--space-4); grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr); }
.health-warn { --tone: var(--warn); --tone-bg: var(--warn-bg); }
.health-fail { --tone: var(--fail); --tone-bg: var(--fail-bg); }
.health-verdict { display: flex; align-items: center; gap: var(--space-4); }
.health-verdict h2 { margin: 0 0 var(--space-1); font-size: 22px; }
.health-verdict p { margin: 0; color: var(--text-muted); }
.health-mark { flex: none; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 24px; font-weight: 700; color: var(--tone); background: var(--tone-bg); }
.health-kpis { display: grid; gap: var(--space-3); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.health-kpi { --line: var(--border); display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3);
    background: var(--surface-2); border-radius: var(--radius); border-top: 3px solid var(--line); min-width: 0; }
.health-kpi-name { font-size: var(--font-s); color: var(--text-muted); }
.health-kpi-value { font-size: var(--font-l); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.health-kpi-note { font-size: var(--font-s); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tone-line-ok { --line: var(--ok); }
.tone-line-warn { --line: var(--warn); }
.tone-line-fail { --line: var(--fail); }
.tone-line-agent { --line: var(--agent); }
.tone-line-neutral { --line: var(--border); }
.day-strips { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; }
.day-strip { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: var(--space-2); }
.day-strip-label { font-size: var(--font-s); color: var(--text-muted); }
.day-strip-bar { position: relative; height: 14px; background: var(--surface-2); border-radius: var(--radius);
    background-image: repeating-linear-gradient(90deg, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%); }
.day-strip-bar .timeline-mark { background: currentColor; border-color: var(--surface); }
.day-strip-now { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--accent); border-radius: 1px; }
.day-strip-hours { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }

#attention .attention li { padding: var(--space-1) 0; }
.attention-app { margin-top: var(--space-2); border-top: 1px solid var(--border); padding-top: var(--space-2); }
.attention-app > summary { cursor: pointer; display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
.attention-app .attention { margin: var(--space-2) 0 0 var(--space-4); }

.tiles { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; scroll-margin-top: var(--space-6); }
.tile:has(.tile-more[open]) { grid-column: 1 / -1; }
.tile:target { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-head { display: flex; align-items: center; gap: var(--space-2); }
.tile-head h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; }
.tile-icon { flex: none; width: 32px; height: 32px; border-radius: var(--radius); display: flex; align-items: center;
    justify-content: center; background: var(--surface-2); color: var(--accent); font-size: 18px; }
.tile-dot { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--neutral-bg); border: 2px solid var(--neutral); }
.dot-ok { background: var(--ok); border-color: var(--ok); }
.dot-warn { background: var(--warn); border-color: var(--warn); }
.dot-fail { background: var(--fail); border-color: var(--fail); }
.dot-agent { background: var(--agent); border-color: var(--agent); }
.tile-status { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.tile-next, .tile-attention { font-size: var(--font-s); }
.tile-metric { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px var(--space-1); padding: var(--space-2) var(--space-3);
    background: var(--surface-2); border-radius: var(--radius); font-size: var(--font-s); color: var(--text-muted); min-height: 2.4em; }
.tile-metric strong { color: var(--text); font-size: var(--font-m); margin-right: var(--space-2); }
.metric-label { flex-basis: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.chip { display: inline-flex; align-items: baseline; gap: 4px; padding: 1px var(--space-2); border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.chip span { color: var(--text); font-weight: 600; }
.chip small { font-size: 11px; }
.chip-warn { border-color: var(--warn); }
.tile-run { white-space: nowrap; background: transparent; border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tile-run:hover { background: var(--accent); color: #ffffff; }
.tile-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: auto; }
.tile-actions form, .tile-buttons form { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); }
.tile-buttons button { white-space: nowrap; }
.tile-actions select, .tile-buttons select { font: inherit; padding: var(--space-1); border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.tile-result { font-size: var(--font-s); flex-basis: 100%; }
.tile-result:empty { display: none; }
.tile-result.ok { color: var(--ok); }
.tile-result.fail { color: var(--fail); }
.tile-result.busy { color: var(--text-muted); }
button[aria-busy="true"] { opacity: .6; cursor: progress; }
.tile-more > summary { cursor: pointer; color: var(--accent); font-size: var(--font-s); }
.tile-more[open] > summary { margin-bottom: var(--space-3); }
.tile-about { margin: 0 0 var(--space-3); color: var(--text-muted); }
.tile-jobs { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: grid; gap: var(--space-2);
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.tile-jobs li { display: flex; gap: var(--space-2); align-items: baseline; padding: var(--space-2) var(--space-3);
    background: var(--surface-2); border-radius: var(--radius); }
.tile-job { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: var(--font-s); }
.tile-job-name { font-weight: 600; font-size: var(--font-m); }
.tile-section h4 { margin: var(--space-3) 0 var(--space-2); }
.tile-section p { margin: 0 0 var(--space-2); }
.tile-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }

.run-grid td { white-space: nowrap; }
.run-part { display: flex; align-items: center; gap: 4px; }
.run-part .tile-dot { width: 8px; height: 8px; }
.infra { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.infra .card + .card { margin-top: 0; }
.budget { margin-bottom: var(--space-3); }
.budget-head { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--font-s); margin-bottom: 4px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.meter-high span { background: var(--warn); }
.meter-full span { background: var(--fail); }
.dead-letters { font-size: var(--font-s); padding-left: var(--space-4); }
.timeline-details { margin-top: var(--space-4); }
.timeline-details > summary { cursor: pointer; }
.timeline-details > summary h3 { display: inline; margin: 0; font-size: var(--font-m); }

@media (max-width: 1000px) {
    .health { grid-template-columns: 1fr; padding: var(--space-4); }
    .health-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Decisions: a field's before and after side by side, an experiment's way, the journal list. */
.field-diffs { display: flex; flex-direction: column; gap: var(--space-3); margin: var(--space-3) 0; }
.field-diff { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); background: var(--surface); }
.field-diff-head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2); }
.field-diff-sides { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: var(--space-2); align-items: stretch; }
.field-diff-side { background: var(--surface-2); border-radius: var(--radius); padding: var(--space-2) var(--space-3); min-width: 0; }
.field-diff-caption { display: flex; justify-content: space-between; font-size: var(--font-s); color: var(--text-muted); margin-bottom: var(--space-1); font-variant-numeric: tabular-nums; }
.field-diff-text { margin: 0; font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.field-diff-arrow { align-self: center; color: var(--text-muted); font-size: var(--font-l); }
.field-diff-text .diff-removed { background: var(--fail-bg); border-radius: 3px; padding: 0 2px; }
.field-diff-list .field-diff-text { display: flex; flex-wrap: wrap; gap: 4px; line-height: 1.4; }
.field-diff-list .field-diff-text > span:not(.none) { padding: 1px var(--space-2); border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); font-size: var(--font-s); }
.field-diff-list .field-diff-text > .diff-added { border-color: var(--ok); background: var(--ok-bg); }
.field-diff-list .field-diff-text > .diff-removed { border-color: var(--fail); background: var(--fail-bg); }

.stages { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; }
.stage { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-top: 18px; font-size: var(--font-s); }
.stage::before { content: ""; position: absolute; top: 5px; left: 0; right: 0; height: 2px; background: var(--border); }
.stage:first-child::before { left: 6px; }
.stage:last-child::before { right: auto; width: 6px; }
.stage-dot { position: absolute; top: 0; left: 0; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); }
.stage-label { color: var(--text); padding-right: var(--space-2); }
.stage-date { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.stage-done::before { background: var(--ok); }
.stage-done .stage-dot { background: var(--ok); border-color: var(--ok); }
.stage-current .stage-dot { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--agent-bg); }
.stage-current .stage-label { font-weight: 600; }
.stage-stopped .stage-dot { background: var(--neutral); border-color: var(--neutral); }
.stage-todo .stage-label { color: var(--text-muted); }
.window-progress { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
.window-progress .meter { flex: 1; max-width: 360px; }
.window-progress .meter span { background: var(--accent); }

.current-experiment { border-left: 4px solid var(--accent); border-radius: 0; margin: var(--space-4) 0; }
.current-experiment h2 { margin: 0 0 var(--space-1); }
.current-experiment h2 a { color: var(--text); text-decoration: none; }
.current-experiment .stages { margin: var(--space-3) 0; }
.eyebrow { font-size: var(--font-s); text-transform: uppercase; letter-spacing: .05em; color: var(--accent); font-weight: 600; }

.journal-section { margin-top: var(--space-6); }
.journal-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.journal-item + .journal-item { border-top: 1px solid var(--border); }
.journal-link { display: grid; grid-template-columns: 3rem minmax(0, 1fr) auto auto 1rem; gap: var(--space-3); align-items: center;
    padding: var(--space-3) var(--space-4); color: var(--text); text-decoration: none; }
.journal-link:hover { background: var(--surface-2); }
.journal-id { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.journal-main { display: flex; flex-direction: column; min-width: 0; }
.journal-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.journal-changes { font-size: var(--font-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.journal-dates { font-size: var(--font-s); white-space: nowrap; }
.journal-badges { display: flex; gap: var(--space-1); flex-wrap: wrap; justify-content: flex-end; }
.journal-chevron { color: var(--text-muted); font-size: var(--font-l); }
.journal-current { box-shadow: inset 4px 0 0 var(--accent); }
.journal-stopped .journal-link { opacity: .7; }
.journal-item:target { background: var(--agent-bg); }

/* Apps page: one card per connected app, short key-value rows, the long texts behind "Подробнее". */
.app-card-name { display: flex; flex-direction: column; }
.app-card-name strong { font-size: var(--font-l); }
.app-facts { display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: var(--space-3) var(--space-4); align-items: center;
    border-top: 1px solid var(--border); padding-top: var(--space-3); }
.app-fact-key { color: var(--text-muted); font-size: var(--font-s); align-self: start; padding-top: 2px; }
.app-fact-value { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); min-width: 0; }
.app-fact-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--space-2); min-width: 0; }
.country-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.country-chip { display: inline-flex; align-items: center; gap: var(--space-2); padding: 2px var(--space-2); border: 1px solid var(--border); border-radius: var(--radius); }
.chip-remove { padding: 0 var(--space-1); border: none; background: none; color: var(--text-muted); line-height: 1; }
.chip-remove:hover { color: var(--fail); }
.app-edit summary { list-style: none; cursor: pointer; }
.app-edit summary::-webkit-details-marker { display: none; }
.app-edit-link { margin-left: var(--space-2); color: var(--accent); font-size: var(--font-s); }
.app-edit[open] .app-edit-link { display: none; }
.app-edit p { margin: var(--space-2) 0 0; }
.app-edit-body { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-2); }
.app-facts .badge { border-radius: var(--radius); }
.app-edit input[type="text"], .app-card select { max-width: 100%; font: inherit; padding: var(--space-1) var(--space-2); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.app-more { margin-top: var(--space-3); }
.app-more > summary { cursor: pointer; color: var(--text-muted); margin-bottom: var(--space-3); }
.app-more-lines { display: flex; flex-direction: column; gap: var(--space-1); }
.app-more-list { margin: 0; padding-left: 1.1rem; }
.apps-section { margin-top: var(--space-6); color: var(--text-muted); font-size: var(--font-s); text-transform: uppercase; letter-spacing: .04em; }
.apps-free { padding: var(--space-1) var(--space-4); }
.apps-free-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; }
.apps-free-row + .apps-free-row { border-top: 1px solid var(--border); }

.experiment-head h1 { margin-bottom: var(--space-2); }
.experiment-badges { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3); }
.experiment-hypothesis { color: var(--text-muted); max-width: 52rem; margin: 0 0 var(--space-4); }
.verdict-line { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; font-size: var(--font-l); }

@media (max-width: 700px) {
    .field-diff-sides { grid-template-columns: 1fr; }
    .field-diff-arrow { transform: rotate(90deg); justify-self: center; }
    .stages { grid-auto-flow: row; gap: var(--space-2); }
    .stage { padding: 0 0 0 20px; }
    .stage::before { display: none; }
    .journal-link { grid-template-columns: 2.5rem minmax(0, 1fr) 1rem; }
    .journal-dates, .journal-badges { grid-column: 2; justify-content: flex-start; }
    .journal-chevron { grid-column: 3; grid-row: 1; }
    .app-facts { grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
    .app-fact-key:not(:first-child) { margin-top: var(--space-3); }
}
