/* ==========================================================================
   Pregut Live Monitoring Dashboard — Design System
   Dark-glass medical IoT UI. RTL Arabic. Vanilla CSS, no framework.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700;800&family=Noto+Sans+Arabic:wght@400;500;600;700;800&display=swap');

:root {
    color-scheme: dark;

    /* ---- surfaces ---- */
    --bg-void: #05070f;
    --bg-base: #080b18;
    --bg-elevated: #0d1120;
    --glass-bg: rgba(255, 255, 255, 0.045);
    --glass-bg-strong: rgba(255, 255, 255, 0.075);
    --glass-bg-hover: rgba(255, 255, 255, 0.09);
    --glass-border: rgba(255, 255, 255, 0.09);
    --glass-border-strong: rgba(255, 255, 255, 0.18);
    --blur: 20px;
    --shadow-glass: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);

    /* ---- text ---- */
    --text-primary: #f4f6fc;
    --text-secondary: #aab2c9;
    --text-muted: #6b7290;

    /* ---- accents ---- */
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --accent-soft: rgba(56, 189, 248, 0.16);
    --violet: #8b7bf7;
    --violet-soft: rgba(139, 123, 247, 0.18);
    --teal: #14b8a6;
    --teal-soft: rgba(20, 184, 166, 0.18);
    --pink: #f472b6;

    /* ---- risk / status scale (0-29 / 30-59 / 60-79 / 80-100) ---- */
    --risk-normal: #10b981;
    --risk-normal-soft: rgba(16, 185, 129, 0.16);
    --risk-mild: #f59e0b;
    --risk-mild-soft: rgba(245, 158, 11, 0.16);
    --risk-high: #fb7f16;
    --risk-high-soft: rgba(251, 127, 22, 0.18);
    --risk-critical: #ef4444;
    --risk-critical-soft: rgba(239, 68, 68, 0.18);

    --status-connected: #10b981;
    --status-delayed: #f59e0b;
    --status-stale: #fb7f16;
    --status-offline: #64748b;

    /* ---- geometry ---- */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-full: 999px;

    /* ---- motion ---- */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --dur-fast: 150ms;
    --dur-med: 260ms;
    --dur-slow: 420ms;

    --font-ar: 'Noto Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
    --font-num: 'Figtree', 'Noto Sans Arabic', 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-ar);
    font-size: 15px;
    line-height: 1.6;
    overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

a { color: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); }

svg { display: block; }

/* ==========================================================================
   Ambient background
   ========================================================================== */

.orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.35;
    z-index: 0;
    pointer-events: none;
}
.orb-one {
    width: 46vw; height: 46vw; max-width: 620px; max-height: 620px;
    top: -18%; left: -10%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.5), transparent 70%);
}
.orb-two {
    width: 40vw; height: 40vw; max-width: 560px; max-height: 560px;
    bottom: -20%; right: -8%;
    background: radial-gradient(circle, rgba(139, 123, 247, 0.4), transparent 70%);
}

.shell {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: 18px clamp(14px, 3vw, 32px) 60px;
}

/* ==========================================================================
   Glass primitives
   ========================================================================== */

.glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    box-shadow: var(--shadow-glass);
}

.card {
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.card-title-wrap {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.card-icon {
    width: 38px; height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
}
.card-icon svg { width: 19px; height: 19px; }

.card-title {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}
.card-subtitle {
    margin: 0;
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.65;
}

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
    position: sticky;
    top: 12px;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 18px;
    margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand .logo {
    width: 40px; height: 40px; flex: none;
    display: grid; place-items: center;
    border-radius: var(--radius-sm);
    background: linear-gradient(145deg, var(--accent-soft), var(--violet-soft));
    color: var(--accent);
}
.brand .logo svg { width: 21px; height: 21px; }
.brand h1 {
    margin: 0; font-size: 15.5px; font-weight: 800; color: var(--text-primary);
    white-space: nowrap;
}
.brand p { margin: 1px 0 0; font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }

.topbar-status {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

.status-chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 12px;
    border-radius: var(--radius-full);
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-border);
    font-size: 12px; font-weight: 600; color: var(--text-secondary);
    white-space: nowrap;
}
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--status-offline);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
    flex: none;
}
.status-chip[data-state="connected"] .status-dot,
.status-chip[data-state="up"] .status-dot { background: var(--status-connected); animation: pulseDot 2s var(--ease-out) infinite; }
.status-chip[data-state="temporarily_delayed"] .status-dot { background: var(--status-delayed); }
.status-chip[data-state="stale"] .status-dot { background: var(--status-stale); }
.status-chip[data-state="disconnected"] .status-dot,
.status-chip[data-state="never_seen"] .status-dot,
.status-chip[data-state="down"] .status-dot { background: #ef4444; }

@keyframes pulseDot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
    50% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
}

.platform-clock { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Emergency banner
   ========================================================================== */

.emergency-banner {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 20px;
    margin: 0 0 16px;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.22), rgba(239, 68, 68, 0.1));
    border: 1px solid rgba(239, 68, 68, 0.45);
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.12), 0 12px 34px rgba(239, 68, 68, 0.22);
    animation: bannerGlow 1.8s ease-in-out infinite, fadeSlideIn var(--dur-slow) var(--ease-out);
}
.emergency-banner[hidden] { display: none; }

@keyframes bannerGlow {
    0%, 100% { box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.12), 0 12px 34px rgba(239, 68, 68, 0.22); }
    50% { box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.28), 0 16px 46px rgba(239, 68, 68, 0.4); }
}

.emergency-banner-icon {
    width: 34px; height: 34px; flex: none;
    display: grid; place-items: center;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.25);
    color: #fecaca;
}
.emergency-banner-icon svg { width: 18px; height: 18px; }
.emergency-banner-body { flex: 1; min-width: 0; }
.emergency-banner-title { font-weight: 800; font-size: 14px; color: #fecaca; }
.emergency-banner-text { font-size: 12.5px; color: rgba(254, 226, 226, 0.85); margin-top: 1px; }
.emergency-banner-score {
    font-family: var(--font-num);
    font-weight: 800; font-size: 20px; color: #fff;
    flex: none;
}
.emergency-banner-close {
    flex: none;
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    display: grid; place-items: center;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out);
}
.emergency-banner-close:hover { background: rgba(255, 255, 255, 0.18); }

/* ==========================================================================
   Layout grid
   ========================================================================== */

.section { margin-top: 22px; }
.section-heading {
    display: flex; align-items: center; gap: 9px;
    margin: 0 0 12px;
    font-size: 14px; font-weight: 700; color: var(--text-secondary);
}
.section-heading svg { width: 17px; height: 17px; color: var(--accent); }

.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
}
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }
.is-hidden { display: none !important; }

@media (max-width: 1100px) {
    .col-8, .col-6, .col-4, .col-3 { grid-column: span 6; }
}
@media (max-width: 720px) {
    .col-8, .col-6, .col-4, .col-3 { grid-column: span 12; }
}

.disclaimer {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 11px 16px;
    border-radius: var(--radius-md);
    background: var(--violet-soft);
    border: 1px solid rgba(139, 123, 247, 0.3);
    color: #d9d4ff;
    font-size: 12.5px;
    line-height: 1.6;
    margin-bottom: 16px;
}
.disclaimer svg { width: 16px; height: 16px; flex: none; margin-top: 2px; color: var(--violet); }

/* ==========================================================================
   Hero diagnosis card (Triad AI Engine)
   ========================================================================== */

.hero-card {
    grid-column: span 12;
    padding: 26px 28px;
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 26px;
    align-items: center;
    position: relative;
    overflow: hidden;
    transition: border-color var(--dur-med) var(--ease-out), box-shadow var(--dur-med) var(--ease-out);
}
@media (max-width: 860px) {
    .hero-card { grid-template-columns: 1fr; text-align: center; }
    .hero-lag { justify-content: center; }
}

.hero-card::before {
    content: "";
    position: absolute; inset: 0;
    background: radial-gradient(600px 240px at 15% 0%, var(--risk-glow-soft, transparent), transparent 60%);
    pointer-events: none;
    transition: background var(--dur-slow) var(--ease-out);
}

.hero-card[data-risk="normal"] { border-color: rgba(16, 185, 129, 0.35); --risk-glow-soft: rgba(16, 185, 129, 0.12); }
.hero-card[data-risk="mild"] { border-color: rgba(245, 158, 11, 0.35); --risk-glow-soft: rgba(245, 158, 11, 0.12); }
.hero-card[data-risk="high"] { border-color: rgba(251, 127, 22, 0.4); --risk-glow-soft: rgba(251, 127, 22, 0.14); box-shadow: var(--shadow-glass), 0 0 40px rgba(251, 127, 22, 0.12); }
.hero-card[data-risk="critical"] {
    border-color: rgba(239, 68, 68, 0.5);
    --risk-glow-soft: rgba(239, 68, 68, 0.18);
    box-shadow: var(--shadow-glass), 0 0 55px rgba(239, 68, 68, 0.22);
    animation: heroCriticalPulse 2.2s ease-in-out infinite;
}
@keyframes heroCriticalPulse {
    0%, 100% { box-shadow: var(--shadow-glass), 0 0 40px rgba(239, 68, 68, 0.18); }
    50% { box-shadow: var(--shadow-glass), 0 0 64px rgba(239, 68, 68, 0.34); }
}

.hero-top-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

.hero-eyebrow {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 10px;
}
.hero-eyebrow .status-dot { background: var(--accent); animation: pulseDot 2s infinite; }

.mode-toggle {
    display: inline-flex; padding: 3px; gap: 2px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    margin-bottom: 10px;
}
.mode-toggle-btn {
    border: none; background: transparent; color: var(--text-secondary);
    font-family: inherit; font-size: 11.5px; font-weight: 700;
    padding: 6px 16px; border-radius: var(--radius-full); cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.mode-toggle-btn:hover { color: var(--text-primary); }
.mode-toggle-btn.is-active {
    background: linear-gradient(145deg, rgba(56,189,248,0.32), rgba(139,123,247,0.24));
    color: #e0f2fe; box-shadow: 0 2px 10px rgba(56,189,248,0.2);
}

.hero-diagnosis {
    font-size: clamp(21px, 2.4vw, 30px);
    font-weight: 800;
    line-height: 1.3;
    margin: 0 0 8px;
    color: var(--diagnosis-color, var(--risk-normal));
    transition: color var(--dur-med) var(--ease-out);
}

.hero-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.risk-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-full);
    font-size: 11.5px; font-weight: 700;
    background: var(--risk-badge-bg, var(--risk-normal-soft));
    color: var(--risk-badge-fg, var(--risk-normal));
    border: 1px solid color-mix(in srgb, var(--risk-badge-fg, var(--risk-normal)) 40%, transparent);
}
.category-tag {
    font-family: var(--font-num);
    font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
}
.confidence-tag { font-size: 11.5px; color: var(--text-secondary); }

.hero-lag {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    max-width: 480px;
}
.lag-node { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); flex: none; }
.lag-node-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--text-muted); border: 2px solid rgba(255,255,255,0.15); }
.lag-track { flex: 1; height: 2px; background: var(--glass-border); position: relative; border-radius: 2px; overflow: hidden; min-width: 40px; }
.lag-track-fill { position: absolute; inset: 0; width: 0; background: linear-gradient(90deg, var(--violet), var(--accent)); transition: width var(--dur-slow) var(--ease-out); }
.lag-label { font-size: 11.5px; color: var(--text-secondary); white-space: nowrap; }

.hero-lag[data-origin="stress_first"] .lag-node.stress .lag-node-dot { background: var(--violet); border-color: var(--violet); }
.hero-lag[data-origin="stress_first"] .lag-track-fill { width: 100%; }
.hero-lag[data-origin="gut_first"] .lag-node.gut .lag-node-dot { background: var(--accent); border-color: var(--accent); }
.hero-lag[data-origin="gut_first"] .lag-track-fill { width: 100%; background: linear-gradient(90deg, var(--accent), var(--violet)); }
.hero-lag[data-origin="simultaneous"] .lag-track-fill { width: 100%; background: var(--risk-mild); }
.hero-lag[data-origin="simultaneous"] .lag-node .lag-node-dot { background: var(--risk-mild); border-color: var(--risk-mild); }

/* risk gauge ring */
.risk-gauge {
    position: relative;
    width: 220px; height: 220px;
    margin: 0 auto;
    display: grid; place-items: center;
}
.risk-gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.risk-gauge circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.risk-gauge .track { stroke: rgba(255, 255, 255, 0.07); }
.risk-gauge .fill {
    stroke: var(--gauge-color, var(--risk-normal));
    stroke-dasharray: 534;
    stroke-dashoffset: 534;
    transition: stroke-dashoffset var(--dur-slow) var(--ease-out), stroke var(--dur-med) var(--ease-out);
    filter: drop-shadow(0 0 10px var(--gauge-color, var(--risk-normal)));
}
.risk-gauge-center {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
}
.risk-gauge-value {
    font-family: var(--font-num);
    font-size: 44px; font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.risk-gauge-unit { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.risk-gauge-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ==========================================================================
   State pills / badges (shared)
   ========================================================================== */

.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 11px;
    border-radius: var(--radius-full);
    font-size: 11.5px; font-weight: 700;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    white-space: nowrap;
}
.pill .status-dot { width: 7px; height: 7px; }
.pill[data-tone="good"] { background: var(--risk-normal-soft); color: var(--risk-normal); border-color: rgba(16,185,129,0.35); }
.pill[data-tone="warn"] { background: var(--risk-mild-soft); color: var(--risk-mild); border-color: rgba(245,158,11,0.35); }
.pill[data-tone="bad"] { background: var(--risk-critical-soft); color: var(--risk-critical); border-color: rgba(239,68,68,0.35); }
.pill[data-tone="neutral"] { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.pill[data-tone="info"] { background: var(--accent-soft); color: var(--accent); border-color: rgba(56,189,248,0.35); }

/* gut pattern badge colors */
.pattern-badge[data-pattern="silent"] { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.pattern-badge[data-pattern="baseline"] { background: var(--risk-normal-soft); color: var(--risk-normal); }
.pattern-badge[data-pattern="mild_spikes"] { background: var(--accent-soft); color: var(--accent); }
.pattern-badge[data-pattern="digestive_spikes"] { background: var(--risk-mild-soft); color: var(--risk-mild); }
.pattern-badge[data-pattern="chaotic"] { background: var(--risk-critical-soft); color: var(--risk-critical); }

/* ==========================================================================
   Triad telemetry cards
   ========================================================================== */

.triad-card { min-height: 240px; }
.triad-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.triad-main-value {
    display: flex; align-items: baseline; gap: 6px; margin-top: 4px;
}
.triad-main-value .value {
    font-family: var(--font-num);
    font-size: 34px; font-weight: 800; color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.triad-main-value .unit { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }

.triad-bar-track {
    height: 7px; border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
    margin-top: 4px;
}
.triad-bar-fill {
    height: 100%; border-radius: var(--radius-full);
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--violet));
    transition: width var(--dur-med) var(--ease-out);
}

.triad-mini-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 8px; margin-top: 8px;
}
.triad-mini-stat {
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid var(--glass-border);
    text-align: center;
}
.triad-mini-stat .mini-value {
    font-family: var(--font-num);
    font-size: 16px; font-weight: 700; color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.triad-mini-stat .mini-label { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

.triad-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.triad-row + .triad-row { margin-top: 6px; }


/* motion split bar (stationary/light/clear) */
.motion-split { display: flex; height: 9px; border-radius: var(--radius-full); overflow: hidden; margin-top: 8px; background: rgba(255,255,255,0.05); }
.motion-split span { height: 100%; transition: width var(--dur-med) var(--ease-out); }
.motion-split .seg-stationary { background: var(--risk-normal); }
.motion-split .seg-light { background: var(--accent); }
.motion-split .seg-clear { background: var(--risk-mild); }
.motion-legend { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.motion-legend span { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-muted); }
.motion-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.motion-legend .c-stationary { background: var(--risk-normal); }
.motion-legend .c-light { background: var(--accent); }
.motion-legend .c-clear { background: var(--risk-mild); }

/* ==========================================================================
   Charts
   ========================================================================== */

.chart-card { min-height: 250px; }
.chart-wrapper { position: relative; flex: 1; min-height: 170px; }
.chart-wrapper canvas { width: 100%; height: 100%; display: block; }
.chart-legend { position: absolute; top: 0; left: 0; display: flex; gap: 12px; z-index: 2; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-secondary); }
.chart-legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.chart-value-badge {
    position: absolute; top: 0; right: 0; text-align: end; z-index: 2;
}
.chart-value-badge .v { font-family: var(--font-num); font-size: 20px; font-weight: 800; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.chart-value-badge .u { font-size: 10.5px; color: var(--text-muted); }

.chart-tabs { display: flex; gap: 6px; }
.chart-tab-btn {
    font-size: 11px; font-weight: 700;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.chart-tab-btn:hover { background: rgba(255,255,255,0.06); color: var(--text-secondary); }
.chart-tab-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: rgba(56,189,248,0.4); }

/* ==========================================================================
   Episode tracker
   ========================================================================== */

.episode-card { }
.episode-state-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.episode-progress { height: 10px; border-radius: var(--radius-full); background: rgba(255,255,255,0.06); overflow: hidden; position: relative; margin-top: 6px; }
.episode-progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--risk-normal), var(--risk-mild), var(--risk-high), var(--risk-critical));
    background-size: 400% 100%;
    transition: width var(--dur-med) var(--ease-out);
}
.episode-progress-peak {
    position: absolute; top: -3px; bottom: -3px; width: 2px;
    background: #fff; opacity: 0.7; left: 0%;
    transition: left var(--dur-med) var(--ease-out);
}
.episode-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }

/* ==========================================================================
   Explanation lists
   ========================================================================== */

.factor-list, .rec-list, .timeline-list, .corr-list {
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 7px;
}
.factor-list li {
    font-size: 12px; line-height: 1.55; color: var(--text-secondary);
    padding: 8px 12px 8px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.03);
    border-inline-start: 3px solid var(--glass-border);
}
.factor-list.raising li { border-inline-start-color: var(--risk-high); }
.factor-list.lowering li { border-inline-start-color: var(--risk-normal); }

.rec-list li {
    font-size: 12.5px; color: var(--text-primary);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid rgba(56,189,248,0.25);
}
.rec-list li .reason { display: block; margin-top: 3px; font-size: 11px; color: var(--text-muted); }
.empty-note { color: var(--text-muted); font-size: 12px; padding: 6px 2px; }

.subheading { font-size: 11.5px; font-weight: 700; margin: 4px 0 0; }
.subheading.raise { color: var(--risk-high); }
.subheading.lower { color: var(--risk-normal); }
.subheading.rec { color: var(--accent); }

/* ==========================================================================
   Calibration ring (reused pattern for hero-adjacent calibration card)
   ========================================================================== */

.cal-body { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.cal-ring {
    --pct: 0;
    width: 108px; height: 108px; flex: none;
    border-radius: 50%;
    display: grid; place-items: center;
    background: conic-gradient(var(--accent) calc(var(--pct) * 1%), rgba(255,255,255,0.07) 0);
    position: relative;
    font-family: var(--font-num); font-weight: 800; font-size: 18px;
}
.cal-ring::before {
    content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--bg-elevated);
}
.cal-ring span { position: relative; z-index: 1; }
.cal-info p { margin: 0 0 6px; font-size: 12.5px; color: var(--text-secondary); }
.cal-info b { color: var(--text-primary); font-family: var(--font-num); }
.badge-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.badge {
    font-size: 11px; font-weight: 600; padding: 5px 10px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    color: var(--text-secondary);
}
.badge.ok { background: var(--risk-normal-soft); color: var(--risk-normal); border-color: rgba(16,185,129,0.3); }

.baseline-progress { height: 8px; border-radius: var(--radius-full); background: rgba(255,255,255,0.06); overflow: hidden; }
.baseline-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--teal)); transition: width var(--dur-med) var(--ease-out); }

/* ==========================================================================
   Buttons / forms
   ========================================================================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(56, 189, 248, 0.4);
    background: linear-gradient(145deg, rgba(56,189,248,0.22), rgba(139,123,247,0.16));
    color: #e0f2fe;
    font-family: inherit; font-size: 12.5px; font-weight: 700;
    cursor: pointer;
    transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.btn:hover { background: linear-gradient(145deg, rgba(56,189,248,0.32), rgba(139,123,247,0.24)); box-shadow: 0 4px 18px rgba(56,189,248,0.2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: rgba(255,255,255,0.05); border-color: var(--glass-border); color: var(--text-secondary); }
.btn.secondary:hover { background: rgba(255,255,255,0.09); box-shadow: none; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); padding: 8px 12px; }
.btn.ghost:hover { background: rgba(255,255,255,0.06); color: var(--text-secondary); box-shadow: none; }
.btn.danger { border-color: rgba(239,68,68,0.4); background: var(--risk-critical-soft); color: #fecaca; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.form-row input, .form-row select, .form-row textarea {
    font-family: inherit; font-size: 13px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.04);
    color: var(--text-primary);
    transition: border-color var(--dur-fast) var(--ease-out);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--accent); }
.form-row textarea { resize: vertical; min-height: 60px; }
.form-row input[type="range"] { padding: 0; accent-color: var(--accent); }

.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
    font-family: inherit; font-size: 12px; font-weight: 600;
    padding: 7px 13px;
    border-radius: var(--radius-full);
    border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.04);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--dur-fast) var(--ease-out);
}
.tag-chip:hover { background: rgba(255,255,255,0.08); }
.tag-chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: rgba(56,189,248,0.5); }
.severity-value { font-family: var(--font-num); color: var(--accent); font-weight: 800; }

/* ==========================================================================
   FAB + drawers
   ========================================================================== */

.fab-stack {
    position: fixed; bottom: 22px; inset-inline-start: 22px; z-index: 50;
    display: flex; flex-direction: column; gap: 12px;
}
.fab {
    width: 54px; height: 54px; border-radius: 50%;
    display: grid; place-items: center;
    background: linear-gradient(145deg, var(--accent), var(--violet));
    color: #06111f;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(56,189,248,0.35);
    transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
    position: relative;
}
.fab:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(56,189,248,0.45); }
.fab svg { width: 22px; height: 22px; }
.fab-label {
    position: absolute; inset-inline-end: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    background: var(--bg-elevated); border: 1px solid var(--glass-border);
    padding: 5px 10px; border-radius: var(--radius-sm);
    font-size: 11.5px; white-space: nowrap; color: var(--text-secondary);
    opacity: 0; pointer-events: none;
    transition: opacity var(--dur-fast) var(--ease-out);
}
.fab:hover .fab-label, .fab:focus-visible .fab-label { opacity: 1; }
.fab.secondary { background: linear-gradient(145deg, var(--teal), var(--accent)); }

.drawer-backdrop {
    position: fixed; inset: 0; z-index: 70;
    background: rgba(2, 4, 10, 0.6);
    backdrop-filter: blur(4px);
    opacity: 0; pointer-events: none;
    transition: opacity var(--dur-med) var(--ease-out);
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 71;
    width: min(400px, 92vw);
    background: var(--bg-elevated);
    border-inline-end: 1px solid var(--glass-border);
    box-shadow: 30px 0 60px rgba(0,0,0,0.5);
    padding: 22px;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform var(--dur-slow) var(--ease-out);
}
[dir="rtl"] .drawer { transform: translateX(105%); }
.drawer.is-open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.drawer-head h3 { margin: 0; font-size: 16px; font-weight: 800; }
.drawer-close {
    width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.05); color: var(--text-secondary);
    display: grid; place-items: center; cursor: pointer;
}
.drawer-close:hover { background: rgba(255,255,255,0.1); }

/* ==========================================================================
   Alerts / timeline / correlations
   ========================================================================== */

.alert-item {
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.03);
    border-inline-start: 3px solid var(--glass-border);
    font-size: 12.5px; color: var(--text-primary);
}
.alert-item[data-severity="high"] { border-inline-start-color: var(--risk-critical); }
.alert-item[data-severity="notable"] { border-inline-start-color: var(--risk-high); }
.alert-item[data-severity="mild"] { border-inline-start-color: var(--risk-mild); }
.alert-item[data-severity="info"] { border-inline-start-color: var(--accent); }
.alert-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 11px; color: var(--text-muted); }

.timeline-list li { display: flex; align-items: flex-start; gap: 10px; font-size: 12px; color: var(--text-secondary); }
.tl-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--accent); flex: none; }
.tl-time { display: block; font-size: 10.5px; color: var(--text-muted); font-family: var(--font-num); }

.corr-list li { font-size: 12px; color: var(--text-secondary); padding: 8px 10px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.03); }
.corr-list li.insufficient { color: var(--text-muted); font-style: italic; }

/* ==========================================================================
   Guide accordion
   ========================================================================== */

details.guide-details { }
details.guide-details > summary {
    cursor: pointer; list-style: none;
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 700; font-size: 14px; color: var(--text-primary);
}
details.guide-details > summary::-webkit-details-marker { display: none; }
details.guide-details > summary .chev { transition: transform var(--dur-fast) var(--ease-out); color: var(--text-muted); }
details.guide-details[open] > summary .chev { transform: rotate(180deg); }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 14px; }
.guide-item { padding: 12px 14px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.03); border: 1px solid var(--glass-border); }
.guide-item-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.guide-term { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; color: var(--text-primary); }
.guide-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.guide-code { font-family: var(--font-num); font-size: 10.5px; color: var(--text-muted); }
.guide-desc { margin: 0; font-size: 11.5px; color: var(--text-secondary); line-height: 1.6; }

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
    margin-top: 30px;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
    font-size: 11.5px; color: var(--text-muted);
    padding-top: 16px;
    border-top: 1px solid var(--glass-border);
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeSlideIn var(--dur-slow) var(--ease-out); }

@keyframes flashPulse {
    0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.35); }
    100% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
}
.flash-pulse { animation: flashPulse 700ms var(--ease-out); }

.waiting-dots { display: inline-flex; gap: 4px; margin-inline-end: 6px; }
.waiting-dots span {
    width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
    animation: waitingBounce 1.1s ease-in-out infinite;
}
.waiting-dots span:nth-child(2) { animation-delay: 0.15s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes waitingBounce {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    .risk-gauge { width: 180px; height: 180px; }
    .risk-gauge-value { font-size: 36px; }
}

@media (max-width: 768px) {
    .shell { padding-top: 10px; }
    .topbar { position: static; flex-direction: column; align-items: stretch; }
    .brand { justify-content: center; text-align: center; flex-direction: column; }
    .topbar-status { justify-content: center; }
    .hero-card { padding: 20px; }
    .fab-stack { bottom: 14px; inset-inline-start: 14px; }
    .fab { width: 48px; height: 48px; }
}

@media (max-width: 480px) {
    body { font-size: 14px; }
    .card { padding: 16px; }
    .risk-gauge { width: 160px; height: 160px; }
    .risk-gauge-value { font-size: 30px; }
    .drawer { width: 100vw; }
}
