/* NARAD Console v2 — professional dark SaaS console (Linear/Vercel-style restraint)
   Palette: near-black navy, cyan primary + violet secondary (both visibly used),
   emerald/amber/rose reserved for status. One spacing scale, one type scale. */

:root {
    /* Design tokens */
    --bg: #070b12;
    --bg-primary: #070b12;
    --bg-panel: #0b1120;
    --bg-card: #0e1626;
    --bg-elevated: #121c30;
    --bg-input: #0a101d;
    --border: #1b2740;
    --border-color: #1b2740;
    --border-strong: #2a3858;
    --text: #e8edf5;
    --text-primary: #e8edf5;
    --text-secondary: #9aa7bd;
    --text-muted: #66738c;
    --accent-cyan: #22d3ee;
    --accent-violet: #8b5cf6;
    --accent-violet-soft: rgba(139, 92, 246, 0.14);
    --accent-cyan-soft: rgba(34, 211, 238, 0.12);
    --accent-emerald: #34d399;
    --accent-amber: #fbbf24;
    --accent-rose: #fb7185;
    --accent-ruby: #f43f5e;
    --danger-bg: rgba(244, 63, 94, 0.12);
    --danger-border: rgba(244, 63, 94, 0.45);
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    --radius: 12px;
    --radius-sm: 8px;
    --topbar-h: 58px;
    --sidebar-w: 264px;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-violet); }
code { font-family: var(--font-mono); font-size: 0.85em; }
button { font-family: var(--font-sans); }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

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

main {
    flex: 1;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 28px 48px;
    min-width: 0;
}

section.tab-pane { scroll-margin-top: calc(var(--topbar-h) + 16px); }
h2, h3, h4 { scroll-margin-top: calc(var(--topbar-h) + 16px); }
/* Belt-and-braces: no scroll target (section, heading, or anchor jump) may ever
   land hidden underneath the sticky topbar. Mirrored in the media queries below. */
html { scroll-padding-top: calc(var(--topbar-h) + 16px); }

/* ---------- Sidebar (desktop) / drawer (mobile) ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 60;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border);
}

.brand-logo { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; }

.brand-text h1 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.06em;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-violet));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    line-height: 1.2;
}

.brand-text h1 span { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }

.brand-tagline { font-size: 10.5px; color: var(--text-muted); margin-top: 2px; }

.drawer-close { display: none; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 16px;
}

.nav-group-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 16px 10px 6px;
}
.nav-group-label:first-child { padding-top: 4px; }

.tab-btn {
    display: flex;
    align-items: center;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    border-left: 3px solid transparent;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    padding: 9px 10px;
    margin: 1px 0;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }

.tab-btn.active {
    background: linear-gradient(90deg, var(--accent-violet-soft), var(--accent-cyan-soft));
    border-left-color: var(--accent-violet);
    color: var(--text);
    font-weight: 600;
}

.sidebar-foot {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    line-height: 1.6;
    color: var(--text-muted);
}
.sidebar-foot strong { color: var(--text-secondary); }

.nav-backdrop { display: none; }

/* ---------- Topbar (sticky, solid — never overlaps content) ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    /* min-height (not fixed height) + wrap: the header is ONE sticky unit whose
       box grows to contain every row, so wrapped chips / the EMERGENCY STOP
       button can never overflow the solid background and cover page content. */
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 8px;
    gap: 14px;
    padding: 8px 28px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.topbar-title { font-size: 14px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.topbar-title span { color: var(--text-muted); font-weight: 500; }

.header-status { margin-left: auto; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 38px;
    height: 38px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 1px; }

/* ---------- Dots / badges ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.dot.online { background: var(--accent-emerald); box-shadow: 0 0 8px rgba(52, 211, 153, 0.7); }
.dot.warn { background: var(--accent-amber); box-shadow: 0 0 8px rgba(251, 191, 36, 0.6); }
.dot.offline { background: var(--accent-rose); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.badge.pending, .badge.running { background: rgba(251, 191, 36, 0.13); color: var(--accent-amber); border-color: rgba(251, 191, 36, 0.35); }
.badge.completed, .badge.success, .badge.verified, .badge.approved, .badge.applied { background: rgba(52, 211, 153, 0.12); color: var(--accent-emerald); border-color: rgba(52, 211, 153, 0.35); }
.badge.failed, .badge.rejected { background: var(--danger-bg); color: var(--accent-rose); border-color: var(--danger-border); }
.badge.warn, .badge.unverified { background: rgba(251, 191, 36, 0.13); color: var(--accent-amber); border-color: rgba(251, 191, 36, 0.35); }
.badge.paused, .badge.idle { background: rgba(139, 92, 246, 0.14); color: #c4b5fd; border-color: rgba(139, 92, 246, 0.4); }
.badge.proposed { background: var(--accent-violet-soft); color: #c4b5fd; border-color: rgba(139, 92, 246, 0.4); }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .emergency-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
    text-decoration: none;
}
.btn-primary:active, .btn-secondary:active, .emergency-btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent-violet);
    color: #fff;
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.35);
}
.btn-primary:hover { background: #7c3aed; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); }

.emergency-btn {
    background: var(--danger-bg);
    color: var(--accent-rose);
    border-color: var(--danger-border);
    font-weight: 700;
    letter-spacing: 0.04em;
}
.emergency-btn:hover { background: rgba(244, 63, 94, 0.22); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ---------- Tabs / sections ---------- */
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fade-in 0.18s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.page-head { margin-bottom: 20px; }
.page-head h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.page-head p { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

.section-title { font-size: 15px; font-weight: 700; margin: 28px 0 12px; }
.section-title.accent { color: var(--accent-violet); }
h3 { font-size: 15px; font-weight: 700; }
h4 { font-size: 14px; font-weight: 700; }

.card-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; color: var(--text); }
.card-text { color: var(--text-secondary); font-size: 13.5px; line-height: 1.65; }
.card-text.small { font-size: 12.5px; }
.muted { color: var(--text-muted); font-size: 13px; }
.ok { color: var(--accent-emerald); }
.accent-text { color: var(--accent-cyan); }
.empty-cell { text-align: center; color: var(--text-muted); padding: 18px 12px !important; }
.noscript-banner {
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.4);
    color: var(--accent-amber);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 20px;
    font-size: 13px;
}

/* ---------- Cards & grids ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 0;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.grid-cards.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-cards.grid-1-1 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cards.roles-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-cards.metrics-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.metric-card { position: relative; overflow: hidden; }
.metric-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
}
.metric-card.accent-cyan::before { background: linear-gradient(90deg, var(--accent-cyan), transparent); }
.metric-card.accent-violet::before { background: linear-gradient(90deg, var(--accent-violet), transparent); }
.metric-card.accent-cyan .metric-value { color: var(--accent-cyan); }
.metric-card.accent-violet .metric-value { color: #a78bfa; }

.metric-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.metric-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.metric-value.plain { font-size: 17px; line-height: 1.4; }
.metric-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 999px;
    margin-top: 14px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-violet));
    transition: width 0.4s ease;
}

/* ---------- Lists, forms, tables ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }

.field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.chat-input, select.chat-input, textarea.chat-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13.5px;
    font-family: var(--font-sans);
    padding: 10px 12px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-input:focus {
    border-color: var(--accent-violet);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}
.chat-input::placeholder { color: var(--text-muted); }

.guardrails { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.guardrails li { font-size: 13px; color: var(--text-secondary); padding-left: 16px; position: relative; }
.guardrails li::before {
    content: "";
    position: absolute;
    left: 0; top: 8px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent-violet);
}
.guardrails li strong { color: var(--text); font-weight: 600; }

.kv-list { display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; color: var(--text-secondary); }
.kv-list strong { color: var(--text); }

.monitor-meta { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 14px; font-size: 13px; color: var(--text-secondary); }

/* Bounded scroll region: table rows scroll INSIDE the card, so they can never
   slide underneath the sticky topbar and get sliced in half while reading.
   The thead sticks to the top of this region (top: 0), so the column headers
   stay visible for as long as any row is visible.
   NOTE: overflow-x:auto alone makes overflow-y compute to auto, turning the
   wrap into a scroll container whose height grows with content — a sticky
   thead then has nowhere to stick and scrolls away with the page (the old
   bug). The explicit max-height + overflow: auto is what makes the header
   actually stick. */
.table-wrap { overflow: auto; max-height: 420px; max-width: 100%; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; scroll-snap-type: y proximity; scroll-padding-top: 34px; }
/* Visible scrollbar so a scrollable table is recognisable as scrollable
   (mobile browsers hide overlay scrollbars until the user tries to scroll). */
.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
/* border-collapse: separate + border-spacing: 0 is required for sticky <th>
   backgrounds to paint reliably over scrolling rows (with collapse, the
   header background can fail and row text shows through). */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 560px; }
th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
    /* Sticky header: stays pinned to the top of the .table-wrap scroll region.
       Solid background is mandatory — without it, scrolling rows show through
       the header. box-shadow keeps the divider visible while stuck. */
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--bg-card);
    box-shadow: 0 1px 0 var(--border-strong);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-secondary); vertical-align: top; overflow-wrap: anywhere; }
tbody tr { scroll-snap-align: start; }
td strong { color: var(--text); }
tr:last-child td { border-bottom: 0; }

/* Short tables whose wrap never scrolls — plus the Tools Registry, which is
   always full-height on the page (see syncTableStick in app.js): the wrap
   stops being a scroll container (overflow:visible), so the thead's nearest
   scrolling ancestor becomes the viewport and it pins just below the sticky
   topbar. (With overflow:auto the wrap itself is the nearest scrolling
   ancestor, so a top offset would merely displace the header inside the
   wrap.) The offset is --stick-top, measured live from the topbar by JS:
   the topbar wraps to two rows on narrower viewports and its chip texts
   change with login state, so no fixed 74/128/168px value is right at every
   width. Fallback 74px = desktop single-row topbar (58px) + 16px. */
.table-wrap.page-stick { overflow: visible; max-height: none; }
.table-wrap.page-stick th { top: var(--stick-top, 74px); }

/* ---------- Chat / logs / roles ---------- */
.chat-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    height: 560px;
    overflow: hidden;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg {
    max-width: 82%;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.6;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    align-self: flex-start;
}
.msg.user { align-self: flex-end; background: var(--accent-violet-soft); border-color: rgba(139, 92, 246, 0.4); }
.msg .author { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; color: var(--accent-violet); margin-bottom: 4px; }
.msg.assistant .author { color: var(--accent-cyan); }
.chat-input-bar { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.chat-input-bar .chat-input { flex: 1; }

.log-stream {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--text-secondary);
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
.log-stream.short { max-height: 220px; }
.log-stream.tall { max-height: 480px; min-height: 200px; }

.task-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.task-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }

.role-card { text-align: center; padding: 22px 14px; }
.role-glyph {
    width: 44px; height: 44px;
    margin: 0 auto 10px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    font-size: 14px; font-weight: 700; letter-spacing: 0.03em;
}
.role-glyph.accent-cyan { background: var(--accent-cyan-soft); color: var(--accent-cyan); border: 1px solid rgba(34, 211, 238, 0.35); }
.role-glyph.accent-violet { background: var(--accent-violet-soft); color: #c4b5fd; border: 1px solid rgba(139, 92, 246, 0.4); }
.role-name { color: var(--accent-cyan); font-size: 14px; }
.role-desc { color: var(--text-secondary); font-size: 12px; margin: 4px 0 10px; }

.scroll-box { max-height: 350px; overflow-y: auto; font-size: 13px; line-height: 1.6; }
.scroll-box.tall { max-height: 400px; }
.lessons-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.result-box { margin-top: 14px; padding: 14px; background: rgba(0, 0, 0, 0.25); border-radius: var(--radius-sm); border: 1px solid var(--accent-cyan); }
.json-block {
    background: var(--bg-primary);
    padding: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 12.5px;
    overflow-x: auto;
    max-height: 300px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Auth modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(3, 6, 12, 0.72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.modal {
    width: 100%;
    max-width: 440px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 24px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-head h3 { font-size: 17px; }
.modal-close {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.modal-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.modal-sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 16px; }
.modal-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--accent-rose);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}
.modal-error[hidden] { display: none; }
.modal-note { margin-top: 16px; font-size: 11.5px; color: var(--text-muted); line-height: 1.6; }
.modal-skip {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    font-size: 12.5px;
    cursor: pointer;
    padding: 6px;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.modal-skip:hover { color: var(--text-secondary); }

/* Login screen mode: full branded login screen when logged out (not a small popup). */
.login-brand { display: none; }
.modal-overlay.auth-screen .login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    text-align: left;
    padding: 6px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}
.modal-overlay.auth-screen .login-brand .brand-logo { width: 46px; height: 46px; }
.modal-overlay.auth-screen .modal-close { display: none; }
.modal-overlay.auth-screen .modal { max-width: 460px; padding: 28px; }
.modal-overlay.auth-screen .modal-sub { text-align: center; }
.modal-overlay.auth-screen #auth-modal-title { font-size: 19px; }
.modal-overlay.auth-screen .modal-head { justify-content: center; }
.modal-overlay.auth-screen .modal-head h3 { width: 100%; text-align: center; }

/* ---------- Responsive ---------- */
/* The topbar wraps to two rows below ~1210px viewport (sidebar 264px + chips).
   A two-row header is ~92px tall, so anchor/scroll targets need a larger
   top offset than the 58px single-row header, or headings slide underneath it. */
@media (max-width: 1400px) {
    html { scroll-padding-top: 128px; }
    /* NOTE: .table-wrap.page-stick th has NO top override here any more —
       its offset is --stick-top, measured live from the topbar by JS. */
    section.tab-pane { scroll-margin-top: 128px; }
    h2, h3, h4 { scroll-margin-top: 128px; }
}

@media (max-width: 1180px) {
    .grid-cards.metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-cards.roles-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1023px) {
    /* Sidebar becomes an off-canvas drawer: same grouped nav, all 16 sections reachable. */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .drawer-close {
        display: block;
        margin-left: auto;
        background: transparent;
        border: 0;
        color: var(--text-muted);
        font-size: 24px;
        line-height: 1;
        cursor: pointer;
        padding: 2px 6px;
    }
    .nav-toggle { display: flex; }
    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(3, 6, 12, 0.6);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }
    .nav-backdrop.show { opacity: 1; pointer-events: auto; }
    .topbar { padding: 8px 16px; gap: 10px; }
    .topbar-title span { display: none; }
    main { padding: 20px 16px 40px; }
    .grid-cards.grid-2-1, .grid-cards.grid-1-1 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    /* Phones: header-status itself can wrap to two rows, so the header can
       reach ~130px tall — keep the scroll offset above it. (The sticky table
       header offset is still --stick-top, measured live by JS.) */
    html { scroll-padding-top: 168px; }
    section.tab-pane { scroll-margin-top: 168px; }
    h2, h3, h4 { scroll-margin-top: 168px; }
    .grid-cards.metrics-grid { grid-template-columns: minmax(0, 1fr); }
    .grid-cards.roles-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .header-status .status-chip:nth-child(3) { display: none; }
    .topbar-title { font-size: 13px; }
    .metric-value { font-size: 26px; }
    .msg { max-width: 94%; }
    .chat-container { height: 480px; }
    .row-between { flex-direction: column; align-items: flex-start; }
    .modal { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Streaming chat cursor: blinks while the reply is being generated. */
.stream-cursor {
    display: inline-block;
    animation: stream-blink 1s steps(1) infinite;
}
@keyframes stream-blink {
    50% { opacity: 0; }
}
