/* ==========================================================================
   MedNova VR Rehabilitation Platform
   Design System v6 — "Aurora Clinical" premium refresh
   Same class/ID contract as v5 — drop-in replacement, no HTML changes needed.
   ========================================================================== */

:root {
    /* Brand palette — MedNova platform blue, single dominant accent colour */
    --primary: #1B84FF;
    --primary-dark: #056EE9;
    --primary-tint: #EFF6FF;
    --secondary: #63B3ED;
    --secondary-tint: #EBF8FF;
    --accent: #63B3ED;

    --success: #48BB78;
    --success-tint: #F0FFF4;
    --warning: #ED8936;
    --warning-tint: #FFFAF0;
    --danger: #F56565;
    --danger-tint: #FFF5F5;
    --info: #4299E1;
    --info-tint: #EBF8FF;
    --violet: #9F7AEA;
    --violet-tint: #FAF5FF;
    --orange: #ED8936;
    --orange-tint: #FFFAF0;
    --teal: #1B84FF;
    --teal-tint: #EFF6FF;

    --bg: #F7F9FC;
    --surface: #FFFFFF;
    --surface-alt: #FBFCFD;
    --sidebar-bg: #F2F5F9;
    --sidebar-bg-active: #EFF6FF;
    --header-bg: rgba(255, 255, 255, 0.85);
    --border: #E2E8F0;
    --card-border: #E2E8F0;

    --text-primary: #1F2937;
    --text-secondary: #4A5568;
    --text-muted: #718096;
    --text-disabled: #CBD5E0;
    --text-inverse: #FFFFFF;

    --hover: #EDF2F7;
    --selected: #EFF6FF;

    --primary-light: #63B3ED;

    --chart-blue: #63B3ED;
    --chart-emerald: #48BB78;
    --chart-amber: #ED8936;
    --chart-purple: #9F7AEA;
    --chart-cyan: #1B84FF;

    --grad-1: linear-gradient(135deg, #1B84FF, #63B3ED);
    --grad-2: linear-gradient(135deg, #9F7AEA, #B794F4);
    --grad-3: linear-gradient(135deg, #ED8936, #F6AD55);
    --grad-4: linear-gradient(135deg, #1B84FF, #63B3ED);

    --radius-card: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(31, 41, 55, 0.04);
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 10px 24px -8px rgba(31, 41, 55, 0.12);
    --shadow-lg: 0 20px 44px -18px rgba(31, 41, 55, 0.22);
    --shadow-glow-primary: 0 8px 20px -6px rgba(27, 132, 255, 0.4);

    /* Apple-style easing: a soft decelerate + a light overshoot spring */
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition: all 0.32s var(--ease);
    --space-unit: 8px;
}

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

html {
    scroll-behavior: smooth;
    /* Fluid base scale — keeps the shell from feeling oversized on
       typical 13"-15" laptop screens at 100% browser zoom, especially
       with Windows display scaling (125%/150%) already in play. */
    font-size: clamp(13px, 0.9vw + 8px, 15px);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(900px 500px at 100% -10%, rgba(27, 132, 255, 0.05), transparent 60%),
        radial-gradient(700px 400px at -10% 20%, rgba(99, 179, 237, 0.05), transparent 60%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
    transition: outline-offset 0.15s var(--ease);
}

h1, h2, h3, h4 { font-weight: 700; color: var(--text-primary); letter-spacing: -0.015em; }
.page-title    { font-size: 26px; font-weight: 800; letter-spacing: -0.025em; }
.section-title { font-size: 16px; font-weight: 600; }
.card-title    { font-size: 14.5px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }
.caption       { font-size: 12px; color: var(--text-muted); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CDD1E2; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #9A9DB0; background-clip: padding-box; }

.app-container { display: flex; min-height: 100vh; }

/* Shell spacing tokens — sidebar and top bar both float on the same canvas
   with matching insets/radii so they read as one shell, not two glued panels. */
:root {
    --shell-gap: 14px;
    --shell-radius: 22px;
}

.main-content {
    flex: 1;
    margin-left: calc(min(252px, 20vw) + (var(--shell-gap) * 2));
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin 0.32s var(--ease);
}

.content-area {
    padding: clamp(16px, 2vw, 22px) clamp(18px, 3vw, 32px) clamp(24px, 4vw, 40px);
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* ---------- Sidebar — "Recovery Rail" ----------
   Same light clinical surface as the rest of the app (reuses the existing
   --sidebar-bg / --border / --shadow-card tokens so it visually belongs
   with the cards and top bar around it). Signature element: a thin teal
   rail running behind the nav icons, like a vitals trace / the path a
   patient walks through their rehab program — the active page is a lit
   waypoint dot on that rail instead of a generic highlighted pill. */
.sidebar {
    position: fixed;
    top: var(--shell-gap);
    left: var(--shell-gap);
    bottom: var(--shell-gap);
    width: min(252px, 20vw);
    height: auto;
    display: flex;
    flex-direction: column;
    z-index: 100;
    border-radius: var(--shell-radius);
    /* Two-layer background trick for a gradient outline: the first layer
       (padding-box) is the actual fill, the second (border-box) shows
       through only in the border's thickness, painting a teal->blue
       brand-gradient ring instead of a flat --border line. */
    border: 1.5px solid transparent;
    background:
        linear-gradient(var(--sidebar-bg), var(--sidebar-bg)) padding-box,
        linear-gradient(165deg, var(--primary) 0%, var(--secondary) 65%, var(--violet) 100%) border-box;
    transition: transform 0.32s var(--ease);
    box-shadow: var(--shadow-card), 0 0 32px -14px rgba(27, 132, 255, 0.45);
    overflow: hidden;
}

.sidebar.glass-effect { backdrop-filter: none; }

.sidebar-header {
    padding: 24px 22px;
    border-bottom: 1px solid var(--divider, var(--border));
    position: relative; z-index: 1;
    /* Distinct tinted zone #1 — soft teal wash behind the logo. */
    background: radial-gradient(140px 100px at 24px -16px, var(--primary-tint), transparent 72%);
}

.logo-container { display: flex; align-items: center; gap: 12px; }
.logo-icon {
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: #fff;
    transition: transform 0.4s var(--ease-spring);
    box-shadow: 0 2px 8px rgba(31, 41, 55, 0.12);
}
.logo-container:hover .logo-icon { transform: scale(1.08) rotate(-3deg); }
.logo-text { display: flex; flex-direction: column; }
.logo-title { color: var(--text-primary); font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.logo-subtitle { color: var(--text-muted); font-size: 10.5px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }

.sidebar-nav {
    flex: 1;
    padding: 22px 0 18px 26px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    position: relative;
    z-index: 1;
    /* Distinct tinted zone #2 — a faint blue wash top-to-bottom, separate
       from the header's teal wash, so the nav reads as its own region. */
    background: linear-gradient(180deg, var(--secondary-tint) 0%, transparent 45%);
}

/* The rail: one continuous line behind every icon's center, in the
   brand teal at low opacity so it reads as a quiet thread rather than a
   hard rule - same accent color used everywhere else in the app (charts,
   active states, primary buttons), just toned down. */
.sidebar-nav::before {
    content: "";
    position: absolute;
    top: 22px; bottom: 22px; left: 39px;
    width: 1px;
    background: linear-gradient(180deg, transparent, rgba(27, 132, 255, 0.35) 12%, rgba(27, 132, 255, 0.35) 88%, transparent);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px 10px 0;
    margin-right: 14px;
    border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    transition: color 0.3s var(--ease), transform 0.3s var(--ease), background 0.3s var(--ease);
    position: relative;
    overflow: visible;
    isolation: isolate;
}
.nav-item:hover { color: var(--text-primary); background: var(--hover); transform: translateX(2px); }

.nav-item i {
    width: 26px; height: 26px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    box-shadow: 0 0 0 1px var(--border);
    position: relative;
    transition: transform 0.45s var(--ease-spring), background 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
}
.nav-item:hover i { transform: scale(1.1); color: var(--text-primary); }

/* Waypoint node — sits exactly on the rail (rail is left:39px in
   .sidebar-nav coordinates; icon center lands there too since
   padding-left:26px + icon half-width 13px = 39px). Only lit for the
   active item; everything else is just the quiet line passing behind. */
.nav-item::before {
    content: "";
    position: absolute;
    left: 13px; top: 50%;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    transform: translate(-50%, -50%) scale(0.9);
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.nav-item.active {
    background: var(--sidebar-bg-active);
    color: var(--primary-dark);
    font-weight: 700;
}
.nav-item.active:hover { transform: none; background: var(--sidebar-bg-active); }
.nav-item.active i {
    background: var(--surface);
    color: var(--primary-dark);
    box-shadow: 0 0 0 1px var(--primary), var(--shadow-glow-primary);
}
.nav-item.active:hover i { transform: scale(1.06); }
.nav-item.active::before {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-tint), 0 0 8px rgba(27, 132, 255, 0.6);
    animation: waypointPulse 2.2s ease-in-out infinite;
}
@keyframes waypointPulse {
    0%, 100% { box-shadow: 0 0 0 4px var(--primary-tint), 0 0 8px rgba(27, 132, 255, 0.6); }
    50%      { box-shadow: 0 0 0 7px rgba(27, 132, 255, 0.14), 0 0 12px rgba(27, 132, 255, 0.75); }
}

.sidebar-footer {
    padding: 16px 20px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative; z-index: 1;
    /* Distinct tinted zone #3 — footer reads as its own "status strip". */
    background: var(--violet-tint);
}


/* ---------- Status indicator ---------- */
.status-indicator, .status-badge, .conn-badge, .camera-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 500;
}
.status-indicator { color: var(--text-secondary); }
.status-dot, .badge-dot, .conn-dot, .rec-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-muted);
    box-shadow: 0 0 0 3px rgba(153, 156, 179, 0.15);
    flex-shrink: 0;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}
.status-dot.online, .badge-dot.online, .conn-dot.online,
.status-dot.connected, .badge-dot.connected {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(50, 215, 75, 0.2);
    animation: dotBreathe 2.2s ease-in-out infinite;
}
.status-dot.offline, .badge-dot.offline, .conn-dot.offline,
.status-dot.disconnected, .badge-dot.disconnected {
    background: var(--danger);
    box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.18);
}
@keyframes dotBreathe {
    0%, 100% { box-shadow: 0 0 0 3px rgba(50, 215, 75, 0.2); }
    50%      { box-shadow: 0 0 0 5px rgba(50, 215, 75, 0.08); }
}
.rec-dot { background: var(--danger); animation: pulse-dot 1.4s infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Top bar ---------- */
.top-bar {
    height: 68px;
    background: var(--header-bg);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border: 1px solid var(--border);
    border-radius: var(--shell-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: var(--shell-gap);
    z-index: 50;
    gap: 16px;
    margin: var(--shell-gap) 32px 0;
    transition: box-shadow 0.3s ease, margin 0.3s ease, border-radius 0.3s ease;
    box-shadow: var(--shadow-card);
}
.top-bar.scrolled { box-shadow: var(--shadow-hover); }

.top-bar-left { display: flex; align-items: center; gap: 18px; flex: 1; min-width: 0; }
.menu-toggle {
    background: var(--hover); border: none; color: var(--text-secondary);
    font-size: 15px; padding: 9px 11px; border-radius: var(--radius-md);
    display: none;
    transition: var(--transition);
}
.menu-toggle:hover { background: var(--selected); color: var(--primary); transform: translateY(-1px); }

.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.breadcrumb .active { color: var(--text-primary); font-weight: 600; }
.breadcrumb i { font-size: 10px; }

.top-search {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 9px 16px;
    max-width: 320px; width: 100%;
    color: var(--text-muted);
    transition: var(--transition);
}
.top-search:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(27, 132, 255, 0.18);
    background: var(--surface);
}
.top-search i { font-size: 13px; }
.top-search input {
    border: none; background: transparent; padding: 0; width: 100%;
    font-size: 13px; color: var(--text-primary);
}
.top-search input:focus { outline: none; box-shadow: none; }

.top-bar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.icon-btn {
    position: relative;
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 15px;
    transition: var(--transition);
}
.icon-btn:hover { background: var(--selected); color: var(--primary); transform: translateY(-2px) scale(1.05); box-shadow: var(--shadow-hover); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn .dot-badge {
    position: absolute; top: 7px; right: 8px;
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--danger); border: 1.5px solid #fff;
    animation: pulse-dot 1.8s infinite;
}
/* Bell rings on hover when there's an unread badge - purely CSS, no JS needed */
.icon-btn:hover:has(.dot-badge) .fa-bell { animation: bellRing 0.5s ease; }
@keyframes bellRing {
    0%, 100% { transform: rotate(0); }
    20% { transform: rotate(14deg); }
    40% { transform: rotate(-11deg); }
    60% { transform: rotate(7deg); }
    80% { transform: rotate(-4deg); }
}

/* ---------- Notification dropdown ---------- */
.notif-wrap { position: relative; }
.notif-panel {
    position: absolute; top: calc(100% + 10px); right: 0;
    width: 320px; max-height: 380px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow-lg);
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity 0.18s var(--ease), transform 0.18s var(--ease), visibility 0.18s;
    z-index: 500; overflow: hidden;
}
.notif-panel.open { opacity: 1; visibility: visible; transform: translateY(0); }
.notif-panel-header {
    padding: 14px 16px; font-weight: 700; font-size: 13px;
    border-bottom: 1px solid var(--border); color: var(--text-primary);
}
.notif-panel-body { max-height: 320px; overflow-y: auto; }
.notif-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.notif-item:last-child { border-bottom: none; }
.notif-item i { color: var(--primary); font-size: 12px; margin-top: 3px; }
.notif-title { color: var(--text-primary); font-weight: 600; }
.notif-time { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.notif-empty { padding: 20px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

.topbar-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary-tint);
    color: var(--primary-dark);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
    border: 1px solid var(--border);
    transition: var(--transition);
}
.topbar-avatar:hover { transform: scale(1.06); box-shadow: var(--shadow-glow-primary); }

.patient-selector, .glass-select, .form-input, select, input[type="text"], input[type="search"] {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 9px 14px;
    font-size: 13px;
    color: var(--text-primary);
    transition: var(--transition);
}
.glass-select:focus, .form-input:focus, select:focus, input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(27, 132, 255, 0.18);
}

.form-input:disabled, .form-input.editable-field:disabled {
    background: var(--bg);
    color: var(--text-secondary);
    border-color: transparent;
    cursor: default;
}

.logout-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    transition: var(--transition);
}
.logout-btn:hover { background: var(--danger-tint); color: var(--danger); border-color: #FEB2B2; transform: translateY(-2px); }
.logout-btn:active { transform: scale(0.94); }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-icon, .join-btn, .chart-btn, .filter-btn, .dur-btn, .ctrl-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
    transition: transform 0.2s var(--ease-spring), box-shadow 0.3s var(--ease), background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    position: relative;
    overflow: hidden;
}
.btn-primary, .join-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 6px 16px -4px rgba(27, 132, 255, 0.35);
}
.btn-primary:hover, .join-btn:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.btn-primary:active, .join-btn:active { transform: translateY(0) scale(0.97); }
.btn-secondary, .chart-btn, .filter-btn, .dur-btn, .ctrl-btn {
    background: var(--surface);
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-secondary:hover, .chart-btn:hover, .filter-btn:hover, .dur-btn:hover, .ctrl-btn:hover {
    background: var(--hover); color: var(--primary); border-color: var(--primary); transform: translateY(-2px);
}
.btn-secondary:active, .chart-btn:active, .filter-btn:active, .dur-btn:active, .ctrl-btn:active { transform: translateY(0) scale(0.97); }
.btn-danger { background: linear-gradient(135deg, var(--danger), #FF6B62); color: #fff; box-shadow: 0 6px 16px -4px rgba(255, 69, 58, 0.4); }
.btn-danger:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.btn-danger:active { transform: translateY(0) scale(0.97); }
.btn-icon {
    width: 38px; height: 38px; padding: 0;
    background: var(--surface); border-color: var(--border); color: var(--text-secondary);
}
.btn-icon:hover { background: var(--hover); color: var(--primary); transform: translateY(-2px); }
.btn-icon:active { transform: scale(0.92); }
.btn-icon-danger:hover { background: rgba(255, 69, 58, 0.12); color: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.chart-btn.active, .filter-btn.active, .dur-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; border-color: transparent;
    box-shadow: 0 6px 16px -6px rgba(27, 132, 255, 0.35);
}

/* Ripple feedback element injected by app.js on click (position:absolute, self-removes) */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    transform: scale(0);
    animation: rippleAnim 0.6s var(--ease) forwards;
    pointer-events: none;
}
.btn-secondary .ripple, .chart-btn .ripple, .filter-btn .ripple, .dur-btn .ripple, .btn-icon .ripple, .ctrl-btn .ripple {
    background: rgba(27, 132, 255, 0.18);
}

/* ---------- Skeleton loading placeholders ---------- */
.skeleton-card {
    padding: 22px; border-radius: 16px;
    background: var(--surface); border: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 12px;
}
.skeleton-line {
    height: 12px; border-radius: 6px;
    background: linear-gradient(90deg, var(--border) 25%, var(--selected) 37%, var(--border) 63%);
    background-size: 400% 100%;
    animation: skeletonShimmer 1.4s ease infinite;
}
.skeleton-line.skeleton-title { width: 55%; height: 10px; }
.skeleton-line.skeleton-value { width: 40%; height: 24px; }
.skeleton-line.skeleton-sub { width: 70%; height: 8px; }
@keyframes skeletonShimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) {
    .skeleton-line { animation: none; }
}
@keyframes rippleAnim { to { transform: scale(2.6); opacity: 0; } }

/* ---------- Cards ---------- */
.stat-card, .analytics-card, .patient-card, .result-card, .compare-card, .exercise-section,
.camera-section, .recommendations, .table-container, .report-history, .progress-summary,
.hero-section, .modal-content, .remote-card {
    background: var(--surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    transition: transform 0.4s var(--ease), box-shadow 0.4s var(--ease);
}
.stat-card:hover, .analytics-card:hover, .patient-card:hover, .result-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
}

.stats-grid, .analytics-grid, .patients-grid, .compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card { padding: 22px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.stat-card::before {
    content: "";
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--grad-1);
    opacity: 0; transform: scaleX(0); transform-origin: left;
    transition: opacity 0.3s ease, transform 0.5s var(--ease);
}
.stat-card:hover::before { opacity: 1; transform: scaleX(1); }
.stat-card.variant-blue::before    { background: var(--primary); }
.stat-card.variant-green::before   { background: var(--success); }
.stat-card.variant-warning::before { background: var(--warning); }
.stat-card.variant-danger::before  { background: var(--danger); }
.stat-card-top { display: flex; align-items: flex-start; justify-content: space-between; position: relative; z-index: 1; }
.stat-content { display: flex; align-items: flex-start; justify-content: space-between; }
.stat-icon {
    width: 42px; height: 42px; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-tint); color: var(--primary); font-size: 17px;
    position: relative; z-index: 1;
    box-shadow: 0 0 0 4px var(--primary-tint);
    transition: transform 0.4s var(--ease-spring);
}
.stat-card:hover .stat-icon { transform: scale(1.08) rotate(-3deg); }
.stat-icon.blue   { background: var(--primary-tint); color: var(--primary); box-shadow: 0 0 0 4px var(--primary-tint); }
.stat-icon.green  { background: var(--success-tint); color: var(--success); box-shadow: 0 0 0 4px var(--success-tint); }
.stat-icon.orange { background: var(--orange-tint); color: var(--orange); box-shadow: 0 0 0 4px var(--orange-tint); }
.stat-icon.warning { background: var(--warning-tint); color: var(--warning); box-shadow: 0 0 0 4px var(--warning-tint); }
.stat-icon.purple { background: var(--violet-tint); color: var(--violet); box-shadow: 0 0 0 4px var(--violet-tint); }
.stat-icon.danger { background: var(--danger-tint); color: var(--danger); box-shadow: 0 0 0 4px var(--danger-tint); }

.stat-value, .stat-number { font-size: 27px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.02em; position: relative; z-index: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; position: relative; z-index: 1; }
.stat-trend {
    font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px;
    padding: 3px 9px; border-radius: var(--radius-pill); position: relative; z-index: 1; width: fit-content;
}
.stat-trend.up   { color: var(--success); background: var(--success-tint); }
.stat-trend.down { color: var(--danger); background: var(--danger-tint); }

.stats-grid .stat-card:hover { transform: translateY(-4px); }

/* ---------- Section headers ---------- */
.section-header, .header-left, .patients-header, .reports-header, .analytics-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.header-subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

/* ---------- Tables ---------- */
.table-container { overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    background: #FAFBFE;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 13px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text-primary); }
tbody tr { transition: background 0.25s ease; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges / pills ---------- */
.pose-badge, .status-badge, .recommendation-badge, .metric-badge, .delta-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 11.5px;
    font-weight: 600;
    transition: transform 0.25s var(--ease-spring);
}
.status-badge.online, .status-badge.connected, .status-badge.success { background: var(--success-tint); color: #0E8A2E; }
.status-badge.offline, .status-badge.disconnected, .status-badge.danger { background: var(--danger-tint); color: #C4291E; }
.status-badge.warning, .status-badge.pending { background: var(--warning-tint); color: #9A5B00; }
.status-badge.info, .status-badge.running { background: var(--primary-tint); color: var(--primary-dark); }
.status-badge.cancelled, .status-badge.failed { background: #F1F1F6; color: var(--text-muted); }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.form-input, input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text-primary);
}
.search-box { display: flex; align-items: center; gap: 8px; }

/* ---------- Progress ---------- */
.progress-bar { width: 100%; height: 8px; border-radius: var(--radius-pill); background: #E7E9F4; overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--primary), var(--violet)); transition: width 0.6s var(--ease); }

/* ---------- Charts / containers ---------- */
.chart-container {
    padding: 22px;
    position: relative;
    overflow: hidden;
}
.chart-container::before {
    content: "";
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--grad-1);
    opacity: 0; transform: scaleX(0); transform-origin: left;
    transition: opacity 0.3s ease, transform 0.5s var(--ease);
}
.chart-container:hover::before { opacity: 1; transform: scaleX(1); }
.chart-container:hover { box-shadow: var(--shadow-hover); transform: translateY(-3px); }
.chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.charts-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.canvas-wrapper, .canvas-wrapper-lg { position: relative; width: 100%; }
.canvas-wrapper { height: 240px; }
.canvas-wrapper-lg { height: 340px; }

/* ---------- Radial gauge widget (circular score ring) ---------- */
.gauge-card {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px;
    text-align: center;
    position: relative;
}
.gauge-canvas-wrap {
    position: relative; width: 100%; height: 200px;
}
.gauge-canvas-wrap::before {
    content: "";
    position: absolute; inset: 18%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(27, 132, 255, 0.16), transparent 70%);
    animation: gaugeHalo 3s ease-in-out infinite;
    z-index: 0;
}
@keyframes gaugeHalo {
    0%, 100% { transform: scale(0.94); opacity: 0.7; }
    50%      { transform: scale(1.06); opacity: 1; }
}
.gauge-caption { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; margin-top: 2px; }
.gauge-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }

/* ---------- Hand usage — dual mini gauges (Right / Left, own colours) ---------- */
.hand-usage-dual { display: flex; align-items: center; justify-content: center; width: 100%; gap: 4px; }
.hand-usage-item { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.gauge-canvas-wrap-sm { position: relative; width: 100%; height: 130px; }
.hand-usage-tag {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 600; color: var(--text-secondary);
}
.hand-usage-tag i { font-size: 7px; }
.hand-usage-tag.right i { color: var(--primary); }
.hand-usage-tag.left  i { color: var(--violet); }

/* Right/left hand metrics anywhere in the app share the same two colours
   so a patient's bilateral balance reads consistently across every page. */
.stat-card[data-metric="right_hand"] .stat-value,
#rightHandValue { color: var(--primary); }
.stat-card[data-metric="left_hand"] .stat-value,
#leftHandValue { color: var(--violet); }

/* ---------- Activity / timeline ---------- */
.activity-list, .recommendations-list, .progress-timeline { display: flex; flex-direction: column; gap: 4px; }
.activity-item, .recommendation-item, .timeline-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.25s ease, transform 0.25s var(--ease);
}
.activity-item:hover, .recommendation-item:hover, .timeline-item:hover { background: var(--hover); transform: translateX(2px); }
.activity-item:last-child, .recommendation-item:last-child, .timeline-item:last-child { border-bottom: none; }
.activity-icon {
    width: 34px; height: 34px; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-tint); color: var(--primary); font-size: 13px; flex-shrink: 0;
}
.activity-icon.success { background: var(--success-tint); color: var(--success); }
.activity-icon.warning { background: var(--warning-tint); color: var(--warning); }
.activity-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.activity-meta { font-size: 12px; color: var(--text-muted); }
.activity-empty, .no-data-msg, .empty-sub {
    text-align: center; color: var(--text-muted); padding: 32px 16px; font-size: 13px;
}

/* ---------- Timeline bars (progress timeline on dashboard) ---------- */
.timeline-bars { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.timeline-bar {
    height: 22px; border-radius: var(--radius-sm);
    display: flex; align-items: center; padding: 0 10px;
    color: #fff; font-size: 11px; font-weight: 600;
    min-width: fit-content;
    transition: width 0.8s var(--ease);
    animation: barGrow 0.7s var(--ease) both;
}
@keyframes barGrow { from { transform: scaleX(0); transform-origin: left; } to { transform: scaleX(1); } }

/* ---------- Loading overlay ---------- */
.loading-overlay {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s var(--ease);
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loader-container { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.loader-ring {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--primary), var(--violet), var(--secondary), var(--primary));
    animation: spin 1s linear infinite;
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
    box-shadow: 0 0 24px rgba(27, 132, 255, 0.22);
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-secondary:hover .fa-sync, .chart-btn:hover .fa-sync, .ctrl-btn:hover .fa-sync { animation: spin 0.6s linear; }
.loader-text { color: var(--text-secondary); font-size: 13.5px; font-weight: 500; }

/* ---------- Modals ---------- */
.modal, .crop-modal-content, .remote-modal, .result-modal {
    position: fixed; inset: 0;
    background: rgba(15, 18, 36, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
    padding: 20px;
    animation: modalBackdropIn 0.25s ease both;
}
@keyframes modalBackdropIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content, .profile-modal-content {
    background: var(--surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    max-width: 560px; width: 92%;
    max-height: 88vh; overflow-y: auto;
    animation: modalPopIn 0.4s var(--ease-spring) both;
}
@keyframes modalPopIn {
    from { opacity: 0; transform: scale(0.94) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-footer {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 16px 22px; border-top: 1px solid var(--border);
}
.modal-close { background: transparent; border: none; color: var(--text-muted); font-size: 18px; transition: var(--transition); }
.modal-close:hover { color: var(--danger); transform: rotate(90deg); }

/* ---------- Profile picture crop editor ---------- */
.crop-editor-stage {
    position: relative;
    width: 280px; height: 280px;
    margin: 0 auto;
    border-radius: 50%;
    overflow: hidden;
    background: #14172a;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 0 0 3px var(--primary-tint), 0 0 0 4000px rgba(15, 18, 36, 0.35);
}
.crop-editor-stage:active { cursor: grabbing; }
.crop-editor-stage canvas { position: absolute; top: 0; left: 0; }
.crop-editor-zoom {
    width: 100%; margin-top: 18px;
    accent-color: var(--primary);
}
.crop-editor-hint {
    text-align: center; color: var(--text-muted); font-size: 12.5px; margin-top: 8px;
}
.avatar-delete-btn {
    position: absolute; top: -4px; right: -4px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--danger); color: #fff; border: 2px solid var(--surface);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.65rem; cursor: pointer; transition: var(--transition);
}
.avatar-delete-btn:hover { transform: scale(1.1); }

/* ---------- Toasts ---------- */
.toast {
    position: fixed;
    bottom: 28px; right: 28px;
    display: flex; align-items: center; gap: 10px;
    padding: 14px 18px;
    background: rgba(24, 26, 46, 0.92);
    backdrop-filter: blur(12px);
    color: #fff;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.35s var(--ease), transform 0.35s var(--ease-spring);
    max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast i { font-size: 15px; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.info i { color: var(--info); }

/* ---------- Animations ---------- */
.animate-slide-up { animation: slideUp 0.5s var(--ease) both; }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: translateY(0) scale(1); } }

.reveal-on-scroll { opacity: 0; transform: translateY(18px); transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); }
.reveal-on-scroll.in-view { opacity: 1; transform: translateY(0); }

/* ---------- Page transitions (butter-smooth navigation between pages) ----------
   Each page is a separate document, so a hard reload happens on every nav
   click. app.js fades the outgoing page out (.page-exit) before navigating,
   then this fade-in plays automatically once the next document paints —
   the net effect reads as one continuous crossfade instead of a flash-cut. */
body { animation: pageIn 0.45s var(--ease) both; }
@keyframes pageIn { from { opacity: 0; } to { opacity: 1; } }

body.page-exit {
    animation: pageOut 0.22s var(--ease) forwards !important;
    pointer-events: none;
}
@keyframes pageOut { to { opacity: 0; } }

/* Premium translate/scale fade moved to .main-content (not body) so it
   doesn't create a transform containing block on <body> — that was
   breaking .sidebar's position:fixed and making it scroll with the page.

   Bug fix: the "to" keyframe below used to end on translateY(0) scale(1)
   instead of the literal keyword "none". Per spec, ANY non-"none"
   transform value - even a resting identity transform like that - still
   establishes a fixed-positioning containing block, and animation:...both
   keeps that end-state applied forever after the animation finishes. That
   silently turned .main-content into a containing block for every
   position:fixed descendant, including .modal (End Session confirm,
   session summary popup, etc.) - the exact same class of bug as the
   sidebar issue above, just relocated instead of eliminated. Ending on
   transform:none keeps the same visual fade-in but doesn't leave a
   containing block behind afterward. */
.main-content { animation: contentIn 0.45s var(--ease) both; }
@keyframes contentIn { from { transform: translateY(6px) scale(0.997); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
    .animate-slide-up, .nav-item.active, .nav-item.active::before, .modal, .modal-content, .toast, .stat-card::before,
    .chart-container::before, .loader-ring, .gauge-canvas-wrap::before, .sidebar::before, .sidebar::after,
    .timeline-bar, body, body.page-exit, .main-content { animation: none !important; }
    * { transition: none !important; }
}

/* ---------- Hero stat card (featured highlight, gradient bg) ---------- */
.stat-card.stat-hero {
    grid-column: span 2;
    background: var(--grad-1);
    border: none;
    color: #fff;
    position: relative;
    overflow: hidden;
    padding: 26px 28px;
}
.stat-card.stat-hero::before { display: none; }
.stat-card.stat-hero:hover { transform: translateY(-4px); box-shadow: var(--shadow-glow-primary), var(--shadow-hover); }
.stat-card.stat-hero .stat-value,
.stat-card.stat-hero .stat-label { color: #fff; position: relative; z-index: 1; }
.stat-card.stat-hero .stat-label { color: rgba(255, 255, 255, 0.85); }
.stat-card.stat-hero .stat-icon {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    box-shadow: none;
    position: relative; z-index: 1;
}
.stat-hero-illustration {
    position: absolute;
    right: -12px; bottom: -16px;
    width: 130px; height: 130px;
    opacity: 0.16;
    pointer-events: none;
    z-index: 0;
}
.stat-hero-illustration svg { width: 100%; height: 100%; }

/* ---------- Avatar (colored initials) — used in patient/name table cells ---------- */
.name-cell { display: flex; align-items: center; gap: 10px; }
.avatar-circle {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff;
    flex-shrink: 0; letter-spacing: 0.01em;
}

/* ---------- Empty-state illustrations (replace plain "No data" text) ---------- */
.empty-illustration {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; padding: 30px 16px 26px; text-align: center;
}
.empty-illustration svg { width: 92px; height: 92px; animation: emptyFloat 3.6s ease-in-out infinite; }
.empty-illustration .empty-title { font-size: 13.5px; font-weight: 600; color: var(--text-secondary); }
.empty-illustration .empty-sub { font-size: 12px; color: var(--text-muted); max-width: 260px; }
.empty-illustration.is-error svg { opacity: 0.9; animation: none; }
.empty-illustration .retry-btn {
    margin-top: 4px;
    background: var(--primary-tint); color: var(--primary-dark);
    border: none; padding: 7px 16px; border-radius: var(--radius-pill);
    font-size: 12.5px; font-weight: 600; transition: var(--transition);
    display: inline-flex; align-items: center; gap: 6px;
}
.empty-illustration .retry-btn::before {
    content: "\f2f1"; font-family: "Font Awesome 6 Free"; font-weight: 900;
    font-size: 11px; transition: transform 0.5s ease;
}
.empty-illustration .retry-btn:hover { background: var(--selected); }
.empty-illustration .retry-btn:hover::before { transform: rotate(180deg); }
@keyframes emptyFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.no-patient  { color: var(--text-muted); font-style: italic; }

/* ---------- Responsive ---------- */
/* Intermediate laptop range: shrink the shell gradually instead of
   hard-hiding the sidebar the moment 1024px is crossed (e.g. Windows
   display scaling or browser zoom shrinking effective viewport width). */
@media (max-width: 1280px) and (min-width: 1025px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: calc(200px + (var(--shell-gap) * 2)); }
    .content-area { padding: 18px 20px 32px; }
    .top-search { max-width: 220px; }
}
@media (max-width: 1024px) {
    .menu-toggle { display: inline-flex; }
    .sidebar { transform: translateX(calc(-100% - 24px)); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .top-bar { margin: var(--shell-gap) 16px 0; }
    .top-search { display: none; }
}
@media (max-width: 640px) {
    .content-area { padding: 18px; }
    .top-bar { padding: 0 16px; margin: 10px 10px 0; border-radius: 16px; }
    .stats-grid, .analytics-grid { grid-template-columns: 1fr; }
    .stat-card.stat-hero { grid-column: span 1; }
    .setup-grid { grid-template-columns: 1fr !important; }
    .toast { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}

/* ==========================================================================
   Smooth cross-page navigation (native View Transitions API)
   Every page (dashboard/patients/session/reports/analytics) is still a
   separate server-rendered document - clicking a sidebar link does a real
   browser navigation. Without this, that navigation shows a blank white
   flash between the old and new page. This opts every same-origin
   navigation into the browser's built-in cross-document transition:
   it snapshots the outgoing page, snapshots the incoming page, and
   cross-fades between them automatically - no JS, no SPA rewrite needed.
   Supported in Chrome/Edge 126+ and Safari 18.2+; browsers without support
   (Firefox, as of writing) just navigate normally with no animation - so
   this is purely additive and can't break anything.
   ========================================================================== */
@view-transition {
    navigation: auto;
}

/* Sidebar is identical markup on every page (just the active nav-item
   differs). Give it a stable transition name so the browser treats it as
   the SAME element across the navigation instead of cross-fading it along
   with the rest of the page - it just stays put while the content area
   transitions, which avoids a flicker/ghosting effect on the nav. */
.sidebar {
    view-transition-name: app-sidebar;
}
::view-transition-group(app-sidebar) {
    animation: none;
}

/* Keep the content cross-fade quick and calm - the default browser timing
   (~0.25s ease) is close to this already, this just makes it explicit and
   slightly snappier so it reads as "instant" rather than as an animation. */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.18s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}