/* ==========================================================================
   COMMAND CENTER DASHBOARD - MAIN STYLESHEET
   Version: 1.0.0

   TABLE OF CONTENTS
   ==========================================================================

   0. FONT FACES
   1. DESIGN TOKENS (CSS Custom Properties)
   2. RESET & BASE
   3. LAYOUT COMPONENTS
   4. NAVIGATION
   5. CARDS
   6. DATA DISPLAY
   7. UI PRIMITIVES
   8. STATE COMPONENTS (Skeletons, Errors, Empty)
   9. UTILITIES
   10. RESPONSIVE

   ========================================================================== */


/* ==========================================================================
   0. FONT FACES
   ========================================================================== */

/* Industry - Brand Font */
@font-face {
    font-family: 'Industry';
    src: url('../assets/fonts/IndustryTest-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
}

/* Muli - Primary Font */
@font-face {
    font-family: 'Muli';
    src: url('../assets/fonts/Muli.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: 'Muli';
    src: url('../assets/fonts/Muli-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}
@font-face {
    font-family: 'Muli';
    src: url('../assets/fonts/Muli-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
}
@font-face {
    font-family: 'Muli';
    src: url('../assets/fonts/Muli-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

/* Timeout B - Secondary Headline / Accent Font */
@font-face {
    font-family: 'Timeout';
    src: url('../assets/fonts/timeout-b.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
}


/* ==========================================================================
   1. DESIGN TOKENS
   ========================================================================== */

:root {
    /* Core palette - Deep slate with red accent (Nexus brand) */
    --bg-primary: #0a0c10;
    --bg-secondary: #12151c;
    --bg-tertiary: #1a1e28;
    --bg-elevated: #222836;
    --bg-hover: #2a303e;

    /* Accent colors (synced with department colors) */
    --accent-primary: #ef4444;      /* Brand - Red */
    --accent-secondary: #10b981;    /* HR - Emerald */
    --accent-success: #06b6d4;      /* Support - Cyan */
    --accent-warning: #f59e0b;      /* Operations - Amber */
    --accent-danger: #ef4444;
    --accent-info: #8b5cf6;         /* Maintenance - Purple */

    /* Semantic colors for data visualization */
    --color-positive: #22c55e;      /* Green - positive changes/deltas */
    --color-negative: #ef4444;      /* Red - negative changes/deltas */
    --color-positive-rgb: 34, 197, 94;
    --color-negative-rgb: 239, 68, 68;

    /* RGB variants for alpha blending */
    --accent-primary-rgb: 239, 68, 68;
    --accent-secondary-rgb: 16, 185, 129;
    --accent-success-rgb: 6, 182, 212;
    --accent-warning-rgb: 245, 158, 11;
    --accent-danger-rgb: 239, 68, 68;
    --accent-info-rgb: 139, 92, 246;

    /* Text hierarchy */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0a0c10;

    /* Borders & Dividers */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.15);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(239, 68, 68, 0.15);

    /* Typography */
    --font-display: 'Industry', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-body: 'Muli', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-accent: 'Timeout', cursive;

    /* Spacing scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;

    /* Animation Timing Standards */
    --transition-card-expand: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --easing-standard: cubic-bezier(0.4, 0, 0.2, 1);

    /* Grid Standards */
    --grid-card-min-width: 281px;
    --grid-gap-cards: var(--space-lg);

    /* Z-Index Scale */
    --z-dropdown: 200;
    --z-sticky: 20;
    --z-header: 50;
    --z-sidebar: 100;
    --z-modal: 200;
    --z-toast: 300;
}


/* ==========================================================================
   2. RESET & BASE
   ========================================================================== */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Subtle background texture */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(ellipse at 20% 20%, rgba(239, 68, 68, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(59, 130, 246, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}


/* ==========================================================================
   3. LAYOUT COMPONENTS
   ========================================================================== */

/* Dashboard Wrapper */
/* Page Entry Animation */
@keyframes pageEnter {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.dashboard-wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
    animation: pageEnter 350ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: var(--z-sidebar);
    transition: width 0.25s ease, transform var(--transition-base);
    overflow: hidden;
}

.sidebar-header {
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
}

.logo-drop {
    height: 52px;
    width: auto;
    object-fit: contain;
}

.logo-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.logo-text {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    line-height: 1;
}

.logo-tagline {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    margin-top: 2px;
}

.logo-image {
    height: 44px;
    width: auto;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-lg) var(--space-md);
    overflow-y: auto;
}

.sidebar-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease;
}

/* Collapsed Sidebar (desktop) */
.dashboard-wrapper.sidebar-collapsed .sidebar {
    width: 60px;
}
.dashboard-wrapper.sidebar-collapsed .main-content {
    margin-left: 60px;
}
.dashboard-wrapper.sidebar-collapsed .logo-brand {
    display: none;
}
.dashboard-wrapper.sidebar-collapsed .logo-drop {
    height: 32px;
}
.dashboard-wrapper.sidebar-collapsed .sidebar-header {
    padding: 0.75rem;
    display: flex;
    justify-content: center;
}
.dashboard-wrapper.sidebar-collapsed .sidebar-header .logo {
    justify-content: center;
}
.dashboard-wrapper.sidebar-collapsed .nav-section-label {
    display: none;
}
.dashboard-wrapper.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 0.6rem;
    font-size: 0;
    gap: 0;
}
.dashboard-wrapper.sidebar-collapsed .nav-icon {
    font-size: 1rem;
}
.dashboard-wrapper.sidebar-collapsed .nav-badge {
    display: none;
}
.dashboard-wrapper.sidebar-collapsed .sidebar-footer {
    padding: 0.5rem;
    display: flex;
    justify-content: center;
}
.dashboard-wrapper.sidebar-collapsed .user-info {
    justify-content: center;
}
.dashboard-wrapper.sidebar-collapsed .user-details {
    display: none;
}
.dashboard-wrapper.sidebar-collapsed .user-logout-btn {
    display: none;
}
.dashboard-wrapper.sidebar-collapsed .sidebar-version-link,
.dashboard-wrapper.sidebar-collapsed .sidebar-footer-row {
    display: none;
}

/* Header */
.header {
    height: var(--header-height);
    background: rgba(18, 21, 28, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-xl);
    position: sticky;
    top: 0;
    z-index: var(--z-header);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.page-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: -0.02em;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.breadcrumb-separator {
    opacity: 0.5;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb a:hover {
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex: 1;
    margin-left: var(--space-xl);
}

/* Search Box */
.search-box {
    position: relative;
    flex: 1;
}

.search-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    padding-left: 38px;
    font-size: 0.875rem;
    color: var(--text-primary);
    width: 100%;
    min-width: 160px;
    transition: all var(--transition-fast);
    font-family: var(--font-body);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    width: 100%;
    margin-top: var(--space-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}

.search-results--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.search-results__empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.search-results__divider {
    padding: 6px 16px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-top: 1px solid var(--border-subtle);
    margin-top: 2px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-subtle);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover,
.search-result-item--selected {
    background: var(--bg-hover);
}

.search-result__icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
}

.search-result__content {
    flex: 1;
    min-width: 0;
}

.search-result__name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result__name mark {
    background: rgba(var(--accent-primary-rgb), 0.3);
    color: var(--accent-primary);
    padding: 0 2px;
    border-radius: 2px;
}

.search-result__dept {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.search-result__value {
    flex-shrink: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.sidebar-toggle-btn {
    display: flex;
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all var(--transition-fast);
}

.header-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.header-btn .badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: var(--accent-danger);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

/* Dashboard Content */
.dashboard-content {
    flex: 1;
    padding: var(--space-xl);
}


/* ==========================================================================
   4. NAVIGATION
   ========================================================================== */

.nav-section {
    margin-bottom: var(--space-xl);
}

.nav-section-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 0 var(--space-md);
    margin-bottom: var(--space-sm);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    cursor: pointer;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(var(--page-accent-rgb, 239, 68, 68), 0.1);
    color: var(--page-accent, var(--accent-primary));
    transition: background 0.3s ease, color 0.3s ease;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--page-accent, var(--accent-primary));
    border-radius: 0 2px 2px 0;
    transition: background 0.3s ease;
}

.nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    flex-shrink: 0;
}

.nav-external-icon {
    margin-left: auto;
    opacity: 0.4;
    flex-shrink: 0;
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
    opacity: 1;
}

.nav-badge {
    margin-left: auto;
    background: var(--accent-danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
}

/* User Profile */
.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-info:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-info));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.user-logout-btn:hover {
    color: var(--accent-danger);
    background: rgba(239, 68, 68, 0.1);
}

.user-logout-btn svg {
    width: 18px;
    height: 18px;
}

/* Version Badge in Sidebar Footer */
.sidebar-version-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.6rem;
    margin-top: 0.5rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    width: fit-content;
}

.sidebar-version-link:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.sidebar-version-icon {
    flex-shrink: 0;
    opacity: 0.6;
}

.sidebar-version-link:hover .sidebar-version-icon {
    opacity: 1;
}

.sidebar-footer-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding-left: 0.6rem;
    margin-top: 2px;
}

.sidebar-sw-version {
    font-size: 0.6rem;
    color: var(--text-muted);
    opacity: 0.5;
}

.sidebar-made-in {
    font-size: 0.55rem;
    color: var(--text-muted);
    opacity: 0.4;
}


/* ==========================================================================
   5. CARDS
   ========================================================================== */

/* Department Tabs */
.department-tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-xl);
    background: var(--bg-secondary);
    padding: var(--space-xs);
    border-radius: var(--radius-md);
    width: fit-content;
}

.dept-tab {
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dept-tab:hover {
    color: var(--text-primary);
}

.dept-tab.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--grid-card-min-width), 1fr));
    gap: var(--grid-gap-cards);
    margin-bottom: var(--space-xl);
}

/* Full KPI Grid - for department pages with dense packing */
.kpi-grid--full {
    grid-template-columns: repeat(auto-fit, minmax(var(--grid-card-min-width), 1fr));
    grid-auto-flow: dense;
}

/* KPI Card */
.kpi-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-top: 3px solid var(--kpi-color, var(--accent-primary));
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    position: relative;
    overflow: visible;
    transition: all var(--transition-base);
    display: flex;
    flex-direction: column;
}

.kpi-card:hover {
    border-color: var(--border-default);
    border-top-color: var(--kpi-color, var(--accent-primary));
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.kpi-header__left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.kpi-header__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kpi-header__text .kpi-category {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 4px;
    width: fit-content;
}

.kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kpi-color, var(--accent-primary));
    flex-shrink: 0;
}

.kpi-body {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.kpi-footer {
    margin-top: auto;
}

.kpi-trend {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 20px;
}

.kpi-trend.up,
.kpi-trend--up {
    color: var(--color-positive);
}

.kpi-trend.down,
.kpi-trend--down {
    color: var(--color-negative);
}

/* Semantic coloring based on favorable/unfavorable (overrides direction color) */
.kpi-trend.favorable {
    background: rgba(var(--color-positive-rgb), 0.1);
    color: var(--color-positive);
}

.kpi-trend.unfavorable {
    background: rgba(var(--color-negative-rgb), 0.1);
    color: var(--color-negative);
}

.kpi-trend.flat-trend {
    background: rgba(148, 163, 184, 0.1);
    color: #94a3b8;
}

/* Trend Popover */
.kpi-trend {
    position: relative;
    cursor: pointer;
}

.trend-popover {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-sm);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
    pointer-events: none;
    text-align: left;
    white-space: nowrap;
}

.trend-popover::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--bg-tertiary);
}

.kpi-trend:hover .trend-popover {
    opacity: 1;
    visibility: visible;
}

/* Elevate card z-index when popover is shown so it appears above adjacent cards */
.kpi-card:has(.kpi-trend:hover) {
    z-index: var(--z-dropdown);
}

/* Pop-under for top row cards (first 4 cards) - popover appears below instead of above */
.kpi-card-wrapper:nth-child(-n+4) .trend-popover {
    bottom: auto;
    top: calc(100% + 8px);
}

.kpi-card-wrapper:nth-child(-n+4) .trend-popover::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--bg-tertiary);
}

.trend-popover__header {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-xs);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.trend-popover__row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    padding: 2px 0;
}

.trend-popover__label {
    color: var(--text-secondary);
}

.trend-popover__value {
    color: var(--text-primary);
    font-weight: 500;
}

.trend-popover__dates {
    margin-top: var(--space-xs);
    padding-top: var(--space-xs);
    border-top: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    white-space: normal;
    line-height: 1.4;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.kpi-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.kpi-label--link {
    text-decoration: none;
    color: inherit;
    transition: color 0.15s ease;
}

.kpi-label--link:hover {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.kpi-sparkline {
    width: 100%;
    height: 40px;
    max-height: 40px;
    overflow: visible;
}

/* Hide sparkline canvas initially to prevent flash before animation */
.kpi-sparkline canvas {
    transition: opacity 0.1s ease;
}

/* KPI header actions container (info + export buttons) */
.kpi-header__actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* KPI Info Button */
.kpi-info-btn {
    position: relative;
    padding: 4px 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s ease, color 0.15s ease;
    line-height: 1;
    border-radius: var(--radius-sm);
}

.kpi-info-btn:hover {
    opacity: 1;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

/* KPI Info Popover */
.kpi-info-popover {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    width: 280px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-sm) var(--space-md);
    z-index: calc(var(--z-sidebar) + 10);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
    pointer-events: none;
    text-align: left;
    white-space: normal;
}

.kpi-info-btn:hover .kpi-info-popover {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Elevate card z-index when info popover is shown — above expanded cards and sidebar */
.kpi-card:has(.kpi-info-btn:hover) {
    z-index: calc(var(--z-sidebar) + 5);
}

.kpi-info-popover__desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin-bottom: var(--space-sm);
}

.kpi-info-popover__meta {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.kpi-info-popover__type {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 4px;
}

.kpi-info-popover__type--source {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.kpi-info-popover__type--calculated {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.kpi-info-popover__type--global {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.kpi-info-popover__source {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

.kpi-info-popover__formula {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-subtle);
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.kpi-info-popover__formula-kpi {
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.15s ease;
}

.kpi-info-popover__formula-kpi:hover {
    opacity: 0.8;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.kpi-info-popover__formula-op {
    color: var(--text-muted);
    font-weight: 400;
}

/* Pop-under for first row info buttons (avoid clipping above viewport) */
.kpi-card-wrapper:nth-child(-n+4) .kpi-info-popover {
    bottom: auto;
    top: calc(100% + 8px);
}

/* Expandable KPI Card */
.kpi-card {
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.kpi-card__summary {
    display: flex;
    flex-direction: column;
    flex: 1;
    transition: opacity 0.2s ease;
}

.kpi-card__details {
    display: none;
    opacity: 0;
}

.kpi-card--expanded {
    grid-column: span 2;
    cursor: default;
    transform: scale(1);
}

.kpi-card--expanded .kpi-card__summary {
    display: none;
}

.kpi-card--expanded .kpi-card__details {
    display: block;
    animation: kpiSlideDown 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Expand/Collapse animations */
@keyframes kpiSlideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* KPI Card — Restricted State */
.kpi-card--restricted {
    opacity: 0.75;
    border-color: rgba(245, 158, 11, 0.3);
}
.kpi-card__restricted {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 0;
    min-height: 60px;
}
.kpi-card__restricted-icon {
    color: #f59e0b;
    font-size: 22px;
}
.kpi-card__restricted-msg {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
}

/* Coming Soon KPI Cards */
.kpi-card--coming-soon {
    position: relative;
    cursor: default;
}
.kpi-card--coming-soon .kpi-card__summary .kpi-header {
    pointer-events: none;
}
.kpi-card--coming-soon .kpi-card__summary .kpi-header__actions {
    filter: blur(4px);
    opacity: 0.15;
}
.kpi-card--coming-soon .kpi-card__summary .kpi-body,
.kpi-card--coming-soon .kpi-card__summary .kpi-footer {
    filter: blur(6px);
    opacity: 0.2;
    pointer-events: none;
    user-select: none;
}
.kpi-card--coming-soon .kpi-card__details {
    display: none !important;
}
.kpi-card__coming-soon-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 5;
    border-radius: inherit;
    pointer-events: none;
}
.kpi-card__coming-soon-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-primary);
}
.kpi-card__coming-soon-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

/* Coming Soon KPI Detail Page */
.kpi-detail--coming-soon {
    position: relative;
}
.kpi-detail--coming-soon .kpi-detail-content {
    filter: blur(8px);
    opacity: 0.2;
    pointer-events: none;
    user-select: none;
}
.kpi-detail__coming-soon-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 40;
    pointer-events: none;
}
.kpi-detail__coming-soon-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 48px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    max-width: 400px;
    text-align: center;
}
.kpi-detail__coming-soon-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-primary);
}
.kpi-detail__coming-soon-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.kpi-detail__coming-soon-kpi-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
}
.kpi-detail__coming-soon-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}
.kpi-detail__coming-soon-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease;
    cursor: pointer;
    margin-top: 4px;
}
.kpi-detail__coming-soon-back:hover {
    background: var(--bg-hover);
    border-color: var(--border-secondary);
}

/* KPI Card Loading State (for date range refresh) */
.kpi-card.refreshing {
    pointer-events: none;
}

.kpi-card.refreshing .kpi-card__summary {
    opacity: 0.4;
}

.kpi-card.refreshing::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.08),
        transparent
    );
    background-size: 200% 100%;
    animation: kpiShimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-lg);
    pointer-events: none;
}

@keyframes kpiShimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Contracting animation for collapse - scales from expanded to collapsed size */
.kpi-card-wrapper.contracting {
    transition: transform var(--transition-card-expand);
}

.kpi-card__close {
    position: absolute;
    top: var(--space-lg);
    right: var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-xs);
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    z-index: 10;
}

.kpi-card__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-default);
}

/* Top actions wrapper - trend badge + close button together */
.kpi-card__top-actions {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    z-index: 10;
}

/* Override close button positioning when inside top-actions */
.kpi-card__top-actions .kpi-card__close {
    position: static;
}

.kpi-card__details-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.kpi-card__details-header > .kpi-icon {
    margin-top: 4px;
    flex-shrink: 0;
}

.kpi-card__metrics-row {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: var(--space-lg);
    padding-right: 40px;
}

.kpi-card__current .kpi-value {
    font-size: 1.5rem;
}

.kpi-card__current .kpi-label {
    margin-top: 2px;
}

.kpi-card__comparison-top {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.kpi-card__prior {
    display: flex;
    flex-direction: column;
}

.kpi-card__prior-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.kpi-card__prior-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Responsible party section */
.kpi-card__owner {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
}

.kpi-card__owner-label {
    color: var(--text-muted);
    font-weight: 500;
}

.kpi-card__owner-value {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-secondary);
}

.kpi-card__owner-value svg {
    color: var(--text-muted);
}

.kpi-card__chart-container {
    height: 260px;
    margin-bottom: var(--space-xl);
}

.chart-type-toggle {
    display: flex;
    gap: var(--space-xs);
    justify-content: flex-end;
    margin-bottom: var(--space-sm);
}

.chart-type-toggle .control-btn {
    padding: var(--space-xs) var(--space-md);
    font-size: 0.8125rem;
}

.kpi-detailed-chart {
    width: 100%;
    height: 100%;
}

.kpi-card__table-container {
    max-height: 200px;
    overflow-y: auto;
}

.kpi-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.kpi-data-table th,
.kpi-data-table td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.kpi-data-table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
}

.kpi-data-table td {
    color: var(--text-primary);
}

.table-prior-date {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 1px;
}

.kpi-data-table td:last-child {
    text-align: right;
}

.kpi-data-table .change-up,
.kpi-data-table .change-favorable {
    color: var(--color-positive);
}

.kpi-data-table .change-down,
.kpi-data-table .change-unfavorable {
    color: var(--color-negative);
}

.kpi-data-table .change-neutral {
    color: #eab308;
}

/* KPI Card Footer with Department Link */
.kpi-card__footer {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-subtle);
}

.kpi-card__dept-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--kpi-color, var(--accent-primary));
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.kpi-card__dept-link:hover {
    gap: var(--space-sm);
}

.kpi-card__dept-link svg {
    transition: transform var(--transition-fast);
}

.kpi-card__dept-link:hover svg {
    transform: translateX(4px);
}

/* KPI Header Actions (export button + trend) */
.kpi-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    align-self: flex-start;
    margin-top: var(--space-md);
}

/* Export Button Styles */
.kpi-export-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.kpi-export-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.kpi-export-btn:active {
    transform: scale(0.98);
}

/* Small export button for summary view */
.kpi-export-btn--small {
    padding: 4px 6px;
    background: transparent;
    border: none;
    opacity: 0.5;
}

.kpi-export-btn--small:hover {
    background: var(--bg-tertiary);
    opacity: 1;
}

/* Export section in expanded card footer */
.kpi-card__export-section {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.kpi-card__export-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-card__export-buttons {
    display: flex;
    gap: var(--space-xs);
}

/* Links section in expanded card footer */
.kpi-card__links {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
}

/* Export Dropdown (for small button click) */
.export-dropdown {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    min-width: 180px;
    animation: dropdownFadeIn 0.15s ease;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.export-dropdown__header {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.export-dropdown__option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    text-align: left;
}

.export-dropdown__option:hover {
    background: var(--bg-tertiary);
}

.export-dropdown__option svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.export-dropdown__desc {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* KPI Card Wrapper (for dashboard) */
.kpi-card-wrapper {
    position: relative;
    align-self: start;
}

/* FLIP animation for grid reflow */
.kpi-card-wrapper.animating {
    transition: transform var(--transition-card-expand);
}

/* Smooth wrapper transition when expanding */
.kpi-card-wrapper {
    transition: none;
}

/* Z-index management for expansion */
.kpi-card-wrapper:has(.kpi-card--expanded) {
    grid-column: span 2;
    z-index: 20; /* Keep above other cards */
}

.kpi-card-wrapper.animating {
    z-index: 30; /* Highest priority during animation */
    transform-origin: top left;
    will-change: transform;
}

/* Responsive: Collapse to single column on smaller screens */
@media (max-width: 768px) {
    .kpi-card--expanded {
        grid-column: span 1;
    }
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

/* Chart Card */
.chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    overflow: hidden;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.chart-actions {
    display: flex;
    gap: var(--space-xs);
}

.chart-action-btn {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.chart-action-btn:hover,
.chart-action-btn.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.chart-container {
    position: relative;
    height: 280px;
    max-height: 280px;
    overflow: hidden;
}

.chart-container canvas {
    max-height: 100% !important;
}

/* Table Section */
.table-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

/* Table Card */
.table-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.table-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Activity Card */
.activity-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.activity-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}


/* ==========================================================================
   6. DATA DISPLAY
   ========================================================================== */

/* Data Table */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: var(--space-sm) var(--space-lg);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: var(--space-md) var(--space-lg);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

/* Activity Feed */
.activity-list {
    padding: var(--space-md);
    max-height: 320px;
    overflow-y: auto;
}

.activity-item {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.activity-item:hover {
    background: var(--bg-hover);
}

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}

.activity-dot.blue { background: var(--accent-secondary); }
.activity-dot.green { background: var(--color-positive); }
.activity-dot.amber { background: var(--accent-warning); }
.activity-dot.red { background: var(--accent-danger); }

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.activity-text strong {
    color: var(--text-primary);
    font-weight: 500;
}

.activity-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}


/* ==========================================================================
   7. UI PRIMITIVES
   ========================================================================== */

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-badge.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-success);
}

.status-badge.active::before {
    background: var(--accent-success);
}

.status-badge.pending {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-warning);
}

.status-badge.pending::before {
    background: var(--accent-warning);
}

.status-badge.inactive {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
}

.status-badge.inactive::before {
    background: var(--text-muted);
}

/* Progress Bars */
.progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width var(--transition-slow);
}

.progress-fill.primary { background: var(--accent-primary); }
.progress-fill.success { background: var(--accent-success); }
.progress-fill.info { background: var(--accent-info); }
.progress-fill.warning { background: var(--accent-warning); }

/* Progress Inline */
.progress-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-inline .progress-bar {
    width: 80px;
}


/* ==========================================================================
   8. STATE COMPONENTS
   ========================================================================== */

/* Skeleton Base */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        var(--bg-hover) 50%,
        var(--bg-tertiary) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* KPI Skeleton */
.skeleton-kpi {
    padding: var(--space-lg);
}

.skeleton-kpi .skeleton-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.skeleton-kpi .skeleton-icon {
    width: 40px;
    height: 40px;
}

.skeleton-kpi .skeleton-badge {
    width: 60px;
    height: 24px;
    border-radius: 20px;
}

.skeleton-kpi .skeleton-value {
    width: 120px;
    height: 32px;
    margin-bottom: var(--space-xs);
}

.skeleton-kpi .skeleton-label {
    width: 100px;
    height: 16px;
}

.skeleton-kpi .skeleton-sparkline {
    width: 100%;
    height: 40px;
    margin-top: var(--space-md);
}

/* Chart Skeleton */
.skeleton-chart {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 280px;
}

.skeleton-chart-area {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
}

/* Table Skeleton */
.skeleton-table .skeleton-th {
    width: 80%;
    height: 12px;
}

.skeleton-table .skeleton-td {
    width: 60%;
    height: 16px;
}

/* Activity Skeleton */
.skeleton-activity-item {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-md);
}

.skeleton-activity-item .skeleton-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}

.skeleton-activity-item .skeleton-text {
    width: 80%;
    height: 16px;
    margin-bottom: var(--space-xs);
}

.skeleton-activity-item .skeleton-time {
    width: 60px;
    height: 12px;
}

/* ============================
   KPI GRID SKELETON
   ============================ */

.kpi-grid-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

.skeleton-kpi-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    animation: skeletonFadeIn 0.3s ease-out both;
}

.skeleton-kpi-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.skeleton-kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
}

.skeleton-kpi-export {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
}

.skeleton-kpi-card__body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
}

.skeleton-kpi-value {
    width: 100px;
    height: 36px;
    border-radius: var(--radius-sm);
}

.skeleton-kpi-trend {
    width: 60px;
    height: 24px;
    border-radius: var(--radius-full);
}

.skeleton-kpi-card__footer {
    margin-top: auto;
}

.skeleton-kpi-sparkline {
    width: 100%;
    height: 48px;
    border-radius: var(--radius-sm);
}

/* KPI Grid wrapper for fade-in animation */
.kpi-grid-content {
    position: relative;
}

.kpi-grid-content .kpi-grid {
    opacity: 0;
}

.kpi-grid-content .kpi-grid.visible {
    opacity: 1;
}

/* KPI Skeleton Card (inline loading state) */
.kpi-card--skeleton {
    animation: kpiCardFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.kpi-card--skeleton .kpi-icon {
    background: var(--bg-tertiary);
}

/* KPI Card Fade In Animation */
.kpi-card-wrapper.fade-in {
    animation: kpiCardFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes kpiCardFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Skeleton fade out */
.kpi-grid-skeleton.fade-out {
    animation: skeletonFadeOut 0.3s ease-out forwards;
}

/* ============================
   KPI DETAIL PAGE SKELETON
   ============================ */

.kpi-detail-skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

/* Detail Header Skeleton */
.skeleton-detail-header {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    position: relative;
    overflow: hidden;
}

.skeleton-detail-header__indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--bg-tertiary);
}

.skeleton-detail-header__content {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.skeleton-detail-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.skeleton-detail-header__info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.skeleton-detail-title {
    width: 200px;
    height: 24px;
    border-radius: var(--radius-sm);
}

.skeleton-detail-description {
    width: 300px;
    height: 16px;
    border-radius: var(--radius-sm);
}

.skeleton-detail-header__metrics {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.skeleton-detail-value {
    width: 80px;
    height: 32px;
    border-radius: var(--radius-sm);
}

.skeleton-detail-trend {
    width: 60px;
    height: 24px;
    border-radius: var(--radius-full);
}

/* Detail Controls Skeleton */
.skeleton-detail-controls {
    display: flex;
    gap: var(--space-xl);
    flex-wrap: wrap;
}

.skeleton-control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.skeleton-control-label {
    width: 50px;
    height: 12px;
    border-radius: var(--radius-sm);
}

.skeleton-control-buttons {
    width: 200px;
    height: 36px;
    border-radius: var(--radius-md);
}

/* Detail Chart Skeleton */
.skeleton-detail-chart {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    height: 350px;
}

.skeleton-detail-chart .skeleton-chart-area {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
}

/* Detail Table Skeleton */
.skeleton-detail-table {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.skeleton-detail-table__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.skeleton-table-title {
    width: 60px;
    height: 20px;
    border-radius: var(--radius-sm);
}

.skeleton-table-actions {
    display: flex;
    gap: var(--space-sm);
}

.skeleton-export-btn {
    width: 60px;
    height: 32px;
    border-radius: var(--radius-sm);
}

.skeleton-table-container {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.skeleton-table-row {
    width: 100%;
    height: 40px;
    border-radius: var(--radius-sm);
}

/* Detail content fade in */
.kpi-detail-content {
    opacity: 0;
}

.kpi-detail-content.visible {
    opacity: 1;
}

.kpi-detail-content.fade-in > * {
    animation: kpiDetailFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.kpi-detail-content.fade-in > *:nth-child(1) { animation-delay: 0s; }
.kpi-detail-content.fade-in > *:nth-child(2) { animation-delay: 0.1s; }
.kpi-detail-content.fade-in > *:nth-child(3) { animation-delay: 0.2s; }
.kpi-detail-content.fade-in > *:nth-child(4) { animation-delay: 0.3s; }
.kpi-detail-content.fade-in > *:nth-child(5) { animation-delay: 0.4s; }

@keyframes kpiDetailFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive skeleton adjustments */
@media (max-width: 768px) {
    .skeleton-detail-header__content {
        flex-direction: column;
        align-items: flex-start;
    }

    .skeleton-detail-header__metrics {
        width: 100%;
        justify-content: flex-start;
    }

    .skeleton-detail-title {
        width: 150px;
    }

    .skeleton-detail-description {
        width: 200px;
    }
}

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    text-align: center;
    min-height: 120px;
}

.error-state__icon {
    color: var(--accent-danger);
    margin-bottom: var(--space-md);
}

.error-state__message {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--space-md);
}

.error-state__retry {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.error-state__retry:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Context-specific error sizing */
.error-state--chart { min-height: 280px; }
.error-state--kpi { min-height: 150px; }
.error-state--table { min-height: 200px; }

/* ==================== KPI Detail Loading Overlay ==================== */
.kpi-hero,
.kpi-detail-chart,
.kpi-detail-table {
    position: relative;
}

.kpi-detail-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(10, 12, 16, 0.75);
    backdrop-filter: blur(2px);
    z-index: 10;
    border-radius: var(--radius-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.kpi-detail-loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.kpi-detail-loading-overlay__spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: detailSpinner 0.7s linear infinite;
}

@keyframes detailSpinner {
    to { transform: rotate(360deg); }
}

.kpi-detail-loading-overlay__message {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: var(--space-sm);
    text-align: center;
    max-width: 240px;
}

/* ==================== KPI Card Expanded Loading States ==================== */
.kpi-card__chart-container,
.kpi-card__table-container {
    position: relative;
}

.kpi-card__chart-container.is-loading .kpi-detailed-chart,
.kpi-card__table-container.is-loading .kpi-data-table {
    opacity: 0.15;
    transition: opacity 0.2s ease;
}

.kpi-card__chart-container.is-loading::after,
.kpi-card__table-container.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    background-size: 200% 100%;
    animation: kpiShimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    pointer-events: none;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    text-align: center;
}

.empty-state__icon {
    color: var(--text-muted);
    margin-bottom: var(--space-lg);
    opacity: 0.5;
}

.empty-state__message {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.empty-state__action {
    margin-top: var(--space-lg);
}

/* Component State Modifiers */
.kpi-card--loading .kpi-content,
.kpi-card--error .kpi-content {
    display: none;
}

.kpi-card--loading .skeleton-kpi,
.kpi-card--error .error-state {
    display: flex;
}

.chart-card--loading .chart-container canvas,
.chart-card--error .chart-container canvas {
    display: none;
}


/* ==========================================================================
   9. TOAST NOTIFICATIONS
   ========================================================================== */

/* Toast Container */
.toast-container {
    position: fixed;
    top: calc(var(--space-lg) + env(safe-area-inset-top, 0px));
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
    max-width: 400px;
    width: calc(100vw - var(--space-xl) * 2);
}

/* Individual Toast */
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease forwards;
    overflow: hidden;
    position: relative;
}

.toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--toast-color, var(--accent-info));
}

.toast.toast--exiting {
    animation: toastSlideOut 0.3s ease forwards;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Toast Icon */
.toast__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--toast-color, var(--accent-info));
}

/* Toast Content */
.toast__content {
    flex: 1;
    min-width: 0;
}

.toast__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.toast__message {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Toast Close Button */
.toast__close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    margin: -4px -8px -4px 0;
}

.toast__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Toast Progress Bar */
.toast__progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--toast-color, var(--accent-info));
    opacity: 0.5;
    animation: toastProgress var(--toast-duration, 5s) linear forwards;
}

@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

/* Toast Variants */
.toast--success {
    --toast-color: var(--accent-success);
}

.toast--error {
    --toast-color: var(--accent-danger);
}

.toast--warning {
    --toast-color: var(--accent-warning);
}

.toast--info {
    --toast-color: var(--accent-info);
}

/* Toast with action button */
.toast__action {
    margin-top: var(--space-sm);
}

.toast__action-btn {
    padding: var(--space-xs) var(--space-sm);
    background: rgba(var(--accent-primary-rgb), 0.1);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent-primary);
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toast__action-btn:hover {
    background: rgba(var(--accent-primary-rgb), 0.2);
}


/* ==========================================================================
   10. NOTIFICATION CENTER
   ========================================================================== */

/* Notification Panel */
.notification-panel {
    position: absolute;
    top: 100%;
    right: 0;
    width: calc(240px + 136px);
    margin-top: var(--space-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow: hidden;
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
}

.notification-panel--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Panel Header */
.notification-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.notification-panel__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.notification-panel__clear-btn {
    padding: var(--space-xs) var(--space-sm);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.notification-panel__clear-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
    color: var(--text-secondary);
}

/* Notification List */
.notification-panel__list {
    flex: 1;
    overflow-y: auto;
    max-height: 320px;
}

/* Empty State */
.notification-panel__empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    text-align: center;
    color: var(--text-muted);
}

.notification-panel__empty svg {
    opacity: 0.4;
    margin-bottom: var(--space-md);
}

.notification-panel__empty p {
    font-size: 0.875rem;
    margin: 0;
}

/* Notification Item */
.notification-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
    position: relative;
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item:hover {
    background: var(--bg-hover);
}

/* Unread indicator */
.notification-item--unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-info);
}

/* Type-specific colors for unread indicator */
.notification-item--success.notification-item--unread::before {
    background: var(--accent-success);
}

.notification-item--error.notification-item--unread::before {
    background: var(--accent-danger);
}

.notification-item--warning.notification-item--unread::before {
    background: var(--accent-warning);
}

/* Notification Icon */
.notification-item__icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
}

.notification-item--success .notification-item__icon {
    color: var(--accent-success);
}

.notification-item--error .notification-item__icon {
    color: var(--accent-danger);
}

.notification-item--warning .notification-item__icon {
    color: var(--accent-warning);
}

.notification-item--info .notification-item__icon {
    color: var(--accent-info);
}

/* Notification Content */
.notification-item__content {
    flex: 1;
    min-width: 0;
}

.notification-item__title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-item__message {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notification-item__time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* Notification Actions */
.notification-item__actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.notification-item:hover .notification-item__actions {
    opacity: 1;
}

.notification-item__action-btn,
.notification-item__dismiss-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.notification-item__action-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.notification-item__dismiss-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--accent-danger);
    color: var(--accent-danger);
}

/* Active state for notification button */
.header-btn--active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .notification-panel {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        width: 100%;
        max-height: calc(100vh - var(--header-height));
        border-radius: 0;
        margin-top: 0;
    }
}


/* ==========================================================================
   11. DATE RANGE PICKER
   ========================================================================== */

/* Date Range Display in Header */
.date-range-display {
    margin-left: var(--space-xs);
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.header-btn[aria-label="Date Range"] {
    width: auto;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    min-width: auto;
    gap: var(--space-xs);
}

.header-btn[aria-label="Date Range"]:hover .date-range-display {
    color: var(--text-primary);
}

.header-btn--active .date-range-display {
    color: var(--accent-primary);
}

/* Date Range Panel */
.date-range-panel {
    position: absolute;
    top: 100%;
    right: 0;
    width: 520px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    margin-top: var(--space-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}

.date-range-panel--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Panel Header */
.date-range-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.date-range-panel__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.date-range-panel__close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.date-range-panel__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Presets Section */
.date-range-panel__presets {
    padding: 12px var(--space-lg);
}

.date-range-panel__preset-group {
    margin-bottom: 12px;
}

.date-range-panel__preset-group:last-child {
    margin-bottom: 0;
}

.date-range-panel__preset-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-sm);
}

.date-range-panel__preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

/* Preset Button */
/* Shared toggle button style for date range panel (presets, granularity, comp mode) */
.dr-toggle-btn {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dr-toggle-btn:hover:not(:disabled):not(.active) {
    background: var(--bg-hover);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.dr-toggle-btn.active {
    background: rgba(var(--accent-primary-rgb), 0.15);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.dr-toggle-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Legacy class aliases */
.preset-btn {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.preset-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.preset-btn.active {
    background: rgba(var(--accent-primary-rgb), 0.15);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.preset-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.preset-btn:disabled:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-subtle);
    color: var(--text-secondary);
}

/* Divider */
.date-range-panel__divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 0 var(--space-lg);
}

/* Custom Range Section */
.date-range-panel__custom {
    padding: 12px var(--space-lg);
}

.date-range-panel__custom-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-sm);
}

.date-range-panel__custom-inputs {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.date-input-group {
    flex: 1;
    position: relative;
}

.date-input-group label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.date-input {
    width: 100%;
    padding: var(--space-xs) var(--space-sm);
    padding-right: 32px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: var(--font-body);
    /* Calendar icon */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
}

.date-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(var(--accent-primary-rgb), 0.2);
}

/* Hide native date input picker indicator when using Flatpickr */
.date-input::-webkit-calendar-picker-indicator {
    display: none;
}

.date-input::-webkit-inner-spin-button,
.date-input::-webkit-clear-button {
    display: none;
}

.date-range-panel__separator {
    color: var(--text-muted);
    font-size: 0.75rem;
    padding-bottom: var(--space-xs);
}

.date-range-panel__apply-btn {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-inverse);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.date-range-panel__apply-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.date-range-panel__apply-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Granularity Section */
.date-range-panel__granularity {
    padding: 12px var(--space-lg);
}

.date-range-panel__granularity-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-sm);
}

.date-range-panel__granularity-buttons {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.granularity-btn {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.granularity-btn:hover:not(:disabled):not(.active) {
    background: var(--bg-hover);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.granularity-btn.active {
    background: rgba(var(--accent-primary-rgb), 0.15);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.granularity-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Compare Mode Section */
.date-range-panel__comp-mode {
    padding: 12px var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

.date-range-panel__comp-mode-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-sm);
}

.date-range-panel__comp-mode-buttons {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.date-range-panel__comp-custom {
    padding: 12px var(--space-lg);
    padding-top: 0;
}

.date-range-panel__comp-apply-btn {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-inverse);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.date-range-panel__comp-apply-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.date-range-panel__comp-apply-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Current Selection Display */
.date-range-panel__current {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px var(--space-lg);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.75rem;
    position: sticky;
    bottom: 82px;
    z-index: 1;
}

.date-range-panel__current svg {
    color: var(--accent-primary);
    flex-shrink: 0;
}

.date-range-panel__current-label {
    color: var(--text-primary);
    font-weight: 500;
}

.date-range-panel__current-days {
    color: var(--text-muted);
}

/* Comparison Summary Display */
.date-range-panel__comp-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px var(--space-lg);
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    position: sticky;
    bottom: 52px;
    z-index: 1;
}

.date-range-panel__comp-summary svg {
    flex-shrink: 0;
    opacity: 0.6;
}

.date-range-panel__comp-days {
    opacity: 0.7;
}

/* Footer with Apply/Cancel buttons */
.date-range-panel__footer {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    position: sticky;
    bottom: 0;
    z-index: 1;
}

.date-range-panel__cancel-btn,
.date-range-panel__confirm-btn {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.date-range-panel__cancel-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.date-range-panel__cancel-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.date-range-panel__confirm-btn {
    background: var(--accent-primary);
    border: none;
    color: var(--text-inverse);
}

.date-range-panel__confirm-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.date-range-panel__confirm-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Visual indicator for pending changes */
.date-range-panel.has-pending-changes .date-range-panel__current {
    background: rgba(var(--accent-primary-rgb, 239, 68, 68), 0.1);
    border-left: 3px solid var(--accent-primary);
}

/* Adjust current section when footer is present */
.date-range-panel__current {
    border-radius: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .date-range-panel {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        width: 100%;
        max-height: calc(100vh - var(--header-height));
        border-radius: 0;
        margin-top: 0;
        overflow-y: auto;
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 20px));
    }

    .date-range-display {
        display: none;
    }
}

/* Flatpickr Custom Dark Theme Overrides */
.flatpickr-calendar {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    width: 307px;
}

.flatpickr-calendar.arrowTop::before,
.flatpickr-calendar.arrowTop::after {
    border-bottom-color: var(--bg-elevated);
}

.flatpickr-calendar.arrowBottom::before,
.flatpickr-calendar.arrowBottom::after {
    border-top-color: var(--bg-elevated);
}

.flatpickr-months {
    background: var(--bg-elevated);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: var(--space-xs) 0;
}

.flatpickr-months .flatpickr-month {
    background: transparent;
    color: var(--text-primary);
    height: 34px;
}

.flatpickr-current-month {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 2px 4px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.flatpickr-current-month .flatpickr-monthDropdown-months:hover,
.flatpickr-current-month .flatpickr-monthDropdown-months:focus {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

/* Style the month dropdown options */
.flatpickr-current-month .flatpickr-monthDropdown-months option {
    background: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
}

.flatpickr-current-month .flatpickr-monthDropdown-months option:hover {
    background: var(--bg-hover) !important;
}

.flatpickr-current-month input.cur-year {
    color: var(--text-primary);
    font-weight: 600;
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
    color: var(--text-secondary);
    fill: var(--text-secondary);
    padding: var(--space-xs);
}

.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
    color: var(--text-primary);
}

.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
    fill: var(--text-primary);
}

.flatpickr-innerContainer {
    background: var(--bg-elevated);
}

.flatpickr-weekdays {
    background: var(--bg-elevated);
}

.flatpickr-weekday {
    background: transparent !important;
    color: var(--text-secondary) !important;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

span.flatpickr-weekday {
    color: var(--text-secondary) !important;
}

.flatpickr-days {
    background: var(--bg-elevated);
    border: none;
}

.dayContainer {
    padding: var(--space-xs);
}

.flatpickr-day {
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    height: 34px;
    line-height: 34px;
    border: 1px solid transparent;
}

.flatpickr-day:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
}

.flatpickr-day.today {
    border-color: var(--accent-primary);
}

.flatpickr-day.today:hover {
    background: rgba(var(--accent-primary-rgb), 0.1);
    color: var(--text-primary);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.flatpickr-day.inRange {
    background: rgba(var(--accent-primary-rgb), 0.15);
    border-color: transparent;
    box-shadow: none;
}

.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
    color: var(--text-muted);
}

.flatpickr-day.prevMonthDay:hover,
.flatpickr-day.nextMonthDay:hover {
    background: var(--bg-hover);
    border-color: var(--border-subtle);
}

.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover {
    color: var(--text-muted);
    opacity: 0.4;
    cursor: not-allowed;
}

/* Position flatpickr inline within panel (static mode) */
.date-input-group {
    position: relative;
}

.date-input-group .flatpickr-wrapper {
    width: 100%;
}

.date-input-group .flatpickr-calendar.static {
    position: absolute;
    top: 100%;
    left: 0;
    transform: none;
    margin-top: var(--space-xs);
    z-index: 100;
}

.date-input-group--end .flatpickr-calendar.static {
    left: auto;
    right: 0;
}

/* Ensure calendar doesn't overflow panel */
.date-range-panel__custom {
    position: relative;
    overflow: visible;
}

.date-range-panel__comp-custom {
    position: relative;
    overflow: visible;
}


/* ==========================================================================
   12. UTILITIES
   ========================================================================== */

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-fade-in {
    animation: fadeInUp 0.5s ease forwards;
}

/* Staggered animation delays */
.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }

.chart-card { animation: fadeInUp 0.5s ease 0.25s forwards; opacity: 0; }
.table-card { animation: fadeInUp 0.5s ease 0.35s forwards; opacity: 0; }
.activity-card { animation: fadeInUp 0.5s ease 0.4s forwards; opacity: 0; }

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* Hide scrollbar on mobile */
@media (max-width: 768px) {
    ::-webkit-scrollbar { display: none; }
    * { scrollbar-width: none; }
}


/* ==========================================================================
   10. RESPONSIVE
   ========================================================================== */

@media (max-width: 1200px) {
    .charts-section {
        grid-template-columns: 1fr;
    }

    .table-section {
        grid-template-columns: 1fr;
    }
}

/* Mobile Nav Bar (Separate from Sidebar) */
.mobile-nav-bar {
    display: none;
}

@media (max-width: 768px) {
    /* Native app feel */
    html {
        -webkit-tap-highlight-color: transparent;
        overscroll-behavior-y: none;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1001;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    /* Backdrop overlay when sidebar is open */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-backdrop.active {
        display: block;
        opacity: 1;
    }

    .mobile-nav-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        /* Height is 60px content + safe area padding */
        height: calc(60px + env(safe-area-inset-bottom, 20px));
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-subtle);
        border-radius: 20px 20px 0 0;
        z-index: 1000;
        justify-content: space-around;
        align-items: flex-start;
        padding-top: 8px;
        padding-bottom: env(safe-area-inset-bottom, 20px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
        box-sizing: border-box;
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 44px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 10px;
        font-weight: 500;
        transition: color 0.2s ease, opacity 0.05s ease;
        -webkit-user-select: none;
        user-select: none;
    }

    .mobile-nav-item {
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav-item:active,
    .mobile-nav-item.tapped {
        transform: scale(0.90);
        opacity: 0.6;
        transition: transform 0.1s ease, opacity 0.1s ease;
    }

    .mobile-nav-item.active {
        color: var(--text-primary);
        /* Use accent color for active icon */
    }

    .mobile-nav-item.active .mobile-nav-icon {
        color: var(--accent-primary);
    }

    .mobile-nav-icon {
        width: 24px;
        height: 24px;
        margin-bottom: 4px;
    }

    /* Main Content Adjustments */
    .main-content {
        margin-left: 0;
        /* Padding bottom = Nav height (60px) + Safe Area + Extra breathing room (20px) */
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 20px));
    }

    .header {
        padding: env(safe-area-inset-top, 0px) 16px 0 16px;
        height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    }

    .sidebar-toggle-btn {
        display: none !important;
    }

    .search-box {
        display: none; /* Hide search on mobile for now */
    }

    .dashboard-content {
        padding: 16px;
    }

    /* Force single column grid */
    .kpi-grid, .charts-section, .table-section {
        grid-template-columns: 1fr !important;
    }
    
    /* Hide elements not suitable for mobile */
    .desktop-only {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
}


/* ==========================================================================
   KPI DETAIL PAGE
   ========================================================================== */

/* ==================== KPI Detail Hero ==================== */
.kpi-hero {
    position: relative;
    display: flex;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-xl);
    overflow: hidden;
}

.kpi-hero__accent {
    width: 6px;
    background: var(--dept-accent);
    flex-shrink: 0;
}

.kpi-hero__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    padding: var(--space-lg) var(--space-xl);
    min-width: 0;
}

/* Row 1 — identity */
.kpi-hero__identity {
    display: flex;
    gap: var(--space-md);
    align-items: flex-start;
}

.kpi-hero__icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    display: grid;
    place-items: center;
    color: var(--kpi-color);
    flex-shrink: 0;
}

.kpi-hero__headings {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.kpi-hero__title-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.kpi-hero__title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary);
    font-family: var(--font-display);
    letter-spacing: 0.01em;
    margin: 0;
    line-height: 1.1;
}

.kpi-hero__description {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 0;
    max-width: 820px;
}

.kpi-hero__badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.kpi-hero__badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid transparent;
}

.kpi-hero__badge--calculated {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.25);
}

.kpi-hero__badge--source {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.25);
}

.kpi-hero__badge--global {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.25);
}

.kpi-hero__badge--source-name {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border-subtle);
    font-style: italic;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
}

.kpi-hero__used-by {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.kpi-hero__used-by a {
    color: var(--text-secondary);
    text-decoration: none;
}

.kpi-hero__used-by a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* Row 2 — stats strip */
.kpi-hero__stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

.kpi-hero__stat {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.kpi-hero__stat--current {
    background: linear-gradient(135deg, rgba(var(--page-accent-rgb), 0.08), rgba(255, 255, 255, 0.01));
    border-color: rgba(var(--page-accent-rgb), 0.25);
}

.kpi-hero__stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.kpi-hero__stat-value-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.kpi-hero__stat-value {
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

.kpi-hero__stat--prior .kpi-hero__stat-value,
.kpi-hero__stat--budget .kpi-hero__stat-value {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 700;
}

.kpi-hero__stat-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.kpi-hero__stat--empty {
    opacity: 0.55;
}

.kpi-hero__stat-placeholder {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

.kpi-hero__stat--current .kpi-trend {
    font-size: 0.85rem;
    padding: 4px 10px;
}

/* Row 3 — MathJax formula panel */
.kpi-hero__formula {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    padding: 0 var(--space-lg);
    transition:
        max-height 0.3s ease-in-out,
        opacity 0.25s ease-in-out,
        padding 0.3s ease-in-out,
        border-color 0.2s ease-in-out;
}

.kpi-hero__formula--visible {
    max-height: 200px;
    opacity: 1;
    padding: var(--space-lg) var(--space-lg);
    border-color: var(--border-subtle);
    background: linear-gradient(135deg, rgba(255,255,255,0.02), rgba(var(--page-accent-rgb, 239,68,68), 0.03));
}

.kpi-hero__formula-inner {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 44px;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-family: 'Muli', var(--font-sans);
}

/* MathJax CHTML theming — \text{} inherits Muli; \href links muted for dark theme */
.kpi-hero__formula mjx-container[jax="CHTML"] {
    color: var(--text-primary);
}

.kpi-hero__formula mjx-container[jax="CHTML"] a {
    color: var(--text-secondary) !important;
    text-decoration: none;
    transition: color 0.15s ease;
}

.kpi-hero__formula mjx-container[jax="CHTML"] a:hover {
    color: var(--text-primary) !important;
}

/* ── Table Fraction (inline, compact) ── */
.calc-cell {
    white-space: nowrap;
}

.table-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    line-height: 1.2;
    font-size: 0.8rem;
    padding: 2px 0;
}

.table-fraction__num,
.table-fraction__den {
    font-variant-numeric: tabular-nums;
    padding: 1px 6px;
    font-weight: 500;
}

.table-fraction__bar {
    width: 100%;
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
    margin: 1px 0;
}

.table-fraction__mult {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.75rem;
    margin-left: 6px;
    vertical-align: middle;
}

/* Offset denominator — dotted underline + ? hint */
.calc-offset-den {
    text-decoration: underline dotted rgba(255, 255, 255, 0.35);
    text-underline-offset: 2px;
    cursor: help;
    position: relative;
}

.calc-offset-den sup {
    font-size: 0.6em;
    color: rgba(255, 255, 255, 0.35);
    margin-left: 1px;
    vertical-align: super;
}

/* Prior period calc cell — slightly muted */
.calc-cell--prior {
    opacity: 0.55;
}

/* KPI Detail Controls */
.kpi-detail-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.control-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.control-selector {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.control-btn {
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.control-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.control-btn.active {
    background: rgba(var(--page-accent-rgb, 239, 68, 68), 0.15);
    border-color: var(--page-accent);
    color: var(--page-accent);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* KPI Detail Chart */
.kpi-detail-chart {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
    height: 400px;
    contain: layout style;
    /* Ensure the chart (and its tooltip) sits above the Data table card below it */
    z-index: 20;
}

/* KPI Detail Table */
.kpi-detail-table {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-xl);
}

.kpi-detail-table__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.kpi-detail-table__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.kpi-detail-table__actions {
    display: flex;
    gap: var(--space-xs);
}

.kpi-detail-table__container {
    max-height: 400px;
    overflow-y: auto;
}

.kpi-detail-table .kpi-data-table {
    width: 100%;
    border-collapse: collapse;
}

.kpi-detail-table .kpi-data-table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.kpi-detail-table .kpi-data-table td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.kpi-detail-table .kpi-data-table tr:hover td {
    background: var(--bg-hover);
}

.kpi-detail-table .kpi-data-table .change-favorable {
    color: var(--color-positive);
    font-weight: 600;
}

.kpi-detail-table .kpi-data-table .change-unfavorable {
    color: var(--color-negative);
    font-weight: 600;
}

.kpi-detail-table .kpi-data-table .change-neutral {
    color: #eab308;
    font-weight: 600;
}

/* Back Link */
.back-link-container {
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color var(--transition-fast);
}

.back-link:hover {
    color: var(--text-primary);
}

/* KPI Card Detail Link */
.kpi-card__detail-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--kpi-color, var(--accent-primary));
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.kpi-card__detail-link:hover {
    gap: var(--space-sm);
}

.kpi-card__detail-link svg {
    transition: transform var(--transition-fast);
}

.kpi-card__detail-link:hover svg {
    transform: translateX(4px);
}

/* Responsive adjustments for KPI detail */
@media (max-width: 768px) {
    .kpi-hero__body {
        padding: var(--space-md);
        gap: var(--space-md);
    }

    .kpi-hero__stats {
        grid-template-columns: 1fr;
    }

    .kpi-hero__title {
        font-size: 1.35rem;
    }

    .kpi-hero__stat-value {
        font-size: 1.75rem;
    }

    .kpi-hero__stat--prior .kpi-hero__stat-value,
    .kpi-hero__stat--budget .kpi-hero__stat-value {
        font-size: 1.25rem;
    }

    .kpi-hero__formula-inner {
        font-size: 0.95rem;
    }

    .kpi-detail-controls {
        flex-direction: column;
    }

    .control-selector {
        overflow-x: auto;
    }

    .kpi-detail-chart {
        height: 360px;
        padding: var(--space-md);
    }

    /* Stack legend above toolbar on mobile so they don't collide */
    .kpi-detail-chart .apexcharts-legend {
        padding: 0 !important;
        margin-bottom: 4px !important;
    }

    .kpi-detail-chart .apexcharts-toolbar {
        top: 0 !important;
        right: 4px !important;
    }

    /* Ensure x-axis labels are visible */
    .kpi-detail-chart .apexcharts-xaxis-texts-g text {
        font-size: 9px !important;
    }

    .table-fraction {
        font-size: 0.7rem;
    }
}


/* ==========================================================================
   13. PERIOD SELECTOR
   ========================================================================== */

.period-selector {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-xl);
    background: var(--bg-secondary);
    padding: var(--space-xs);
    border-radius: var(--radius-md);
    width: fit-content;
}

.period-btn {
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.period-btn:hover {
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--bg-elevated);
    color: var(--page-accent, var(--text-primary));
    box-shadow: var(--shadow-sm);
}

/* Department-specific accent color for period selector */
.period-btn.active[style*="--dept-accent"] {
    color: var(--dept-accent, var(--page-accent, var(--text-primary)));
    border-bottom: 2px solid var(--dept-accent, var(--page-accent, var(--accent-primary)));
}


/* ==========================================================================
   14. DEPARTMENT HEADER
   ========================================================================== */

.dept-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.dept-header__indicator {
    width: 6px;
    height: 36px;
    background: var(--dept-accent, var(--page-accent, var(--accent-primary)));
    border-radius: 3px;
}

.dept-header__title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}


/* ==========================================================================
   15. SECTION TITLE
   ========================================================================== */

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
    margin-top: var(--space-xl);
}


/* ==========================================================================
   16. DEPARTMENT CARDS
   ========================================================================== */

.dept-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-md);
}

.dept-card-container {
    position: relative;
}

.dept-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: var(--space-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    text-decoration: none;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.dept-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--dept-color);
}

.dept-card:hover {
    border-color: var(--border-default);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.dept-card[aria-expanded="true"] {
    border-color: var(--dept-color);
    box-shadow: var(--shadow-md);
}

.dept-card__name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.dept-card__desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.dept-card__arrow {
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.dept-card:hover .dept-card__arrow {
    color: var(--dept-color);
}

.dept-card[aria-expanded="true"] .dept-card__arrow {
    color: var(--dept-color);
    transform: translateY(-50%) rotate(180deg);
}

/* Department Dropdown */
.dept-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all var(--transition-base);
    margin-top: var(--space-xs);
}

.dept-dropdown--open {
    max-height: 400px;
    overflow-y: auto;
    opacity: 1;
}

.dept-dropdown__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.dept-dropdown__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.dept-dropdown__view-all {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.dept-dropdown__view-all:hover {
    color: var(--accent-primary);
}

.dept-dropdown__list {
    max-height: 320px;
    overflow-y: auto;
}

.dept-dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}

.dept-dropdown__item:last-child {
    border-bottom: none;
}

.dept-dropdown__item:hover {
    background: var(--bg-secondary);
}

.dept-dropdown__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.dept-dropdown__info {
    flex: 1;
    min-width: 0;
}

.dept-dropdown__label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dept-dropdown__value {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dept-dropdown__item .kpi-trend {
    font-size: 0.7rem;
    flex-shrink: 0;
}


/* ==========================================================================
   17. BACK LINK
   ========================================================================== */

.back-link-container {
    margin-top: var(--space-2xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color var(--transition-fast);
}

.back-link:hover {
    color: var(--text-primary);
}


/* ==========================================================================
   CHANGELOG TIMELINE
   ========================================================================== */

.changelog-page {
    max-width: 800px;
}

.changelog-header {
    margin-bottom: var(--space-xl);
}

.changelog-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.changelog-subtitle {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

/* Timeline Container */
.timeline {
    position: relative;
    padding-left: var(--space-md);
}

.timeline-loading,
.timeline-error {
    padding: var(--space-xl);
    text-align: center;
    color: var(--text-muted);
}

/* Timeline Item */
.timeline-item {
    display: flex;
    gap: var(--space-lg);
    position: relative;
    padding-bottom: var(--space-lg);
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item:last-child .timeline-line {
    display: none;
}

/* Timeline Marker (dot + line) */
.timeline-marker {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: 20px;
}

.timeline-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    border: 3px solid var(--accent-primary);
    z-index: 1;
    transition: all 0.2s ease;
}

.timeline-item.expanded .timeline-dot {
    background: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

.timeline-line {
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: calc(100% - 4px);
    background: var(--border-subtle);
}

/* Timeline Content */
.timeline-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.timeline-item.expanded .timeline-content {
    border-color: var(--accent-primary);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* Timeline Header (clickable) */
.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    cursor: pointer;
    transition: background 0.2s ease;
}

.timeline-header:hover {
    background: var(--bg-hover);
}

.timeline-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.timeline-version {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-primary);
    background: rgba(239, 68, 68, 0.1);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

.timeline-title-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.timeline-meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.timeline-date {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.timeline-chevron {
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.timeline-item.expanded .timeline-chevron {
    transform: rotate(180deg);
}

/* Timeline Details (expandable) */
.timeline-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.timeline-item.expanded .timeline-details {
    max-height: 5000px;
}

/* Timeline Categories */
.timeline-category {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

.timeline-category-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.timeline-category-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.timeline-category--features .timeline-category-dot {
    background: var(--color-positive);
}

.timeline-category--improvements .timeline-category-dot {
    background: var(--accent-info);
}

.timeline-category--fixes .timeline-category-dot {
    background: var(--color-negative);
}

.timeline-category-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.timeline-category--features .timeline-category-title {
    color: var(--color-positive);
}

.timeline-category--improvements .timeline-category-title {
    color: var(--accent-info);
}

.timeline-category--fixes .timeline-category-title {
    color: var(--color-negative);
}

/* Timeline List */
.timeline-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline-list li {
    position: relative;
    padding-left: var(--space-lg);
    margin-bottom: var(--space-xs);
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.timeline-list li:last-child {
    margin-bottom: 0;
}

.timeline-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.5em;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 600px) {
    .timeline-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }

    .timeline-meta {
        width: 100%;
        justify-content: space-between;
    }

    .timeline-info {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-xs);
    }
}

/* ============================
   TIMELINE SKELETON LOADING
   ============================ */

.timeline-skeleton {
    display: flex;
    flex-direction: column;
}

.skeleton-timeline-item {
    display: flex;
    gap: var(--space-lg);
    padding-bottom: var(--space-xl);
    opacity: 1;
    animation: skeletonFadeIn 0.3s ease-out both;
}

.skeleton-timeline-item .timeline-marker {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.skeleton-timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bg-tertiary);
}

.skeleton-timeline-item .timeline-line {
    width: 2px;
    flex: 1;
    min-height: 60px;
    background: var(--border-subtle);
    margin-top: var(--space-sm);
}

.skeleton-timeline-item:last-child .timeline-line {
    display: none;
}

.skeleton-timeline-content {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    min-height: 70px;
}

.skeleton-timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
}

.skeleton-timeline-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.skeleton-timeline-version {
    width: 60px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
}

.skeleton-timeline-title {
    width: 180px;
    height: 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}

.skeleton-timeline-date {
    width: 100px;
    height: 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}

/* Skeleton Shimmer Animation */
.skeleton-timeline-dot.skeleton,
.skeleton-timeline-version.skeleton,
.skeleton-timeline-title.skeleton,
.skeleton-timeline-date.skeleton {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Staggered animation for skeleton items */
.skeleton-timeline-item:nth-child(1) .skeleton {
    animation-delay: 0s;
}

.skeleton-timeline-item:nth-child(2) .skeleton {
    animation-delay: 0.15s;
}

.skeleton-timeline-item:nth-child(3) .skeleton {
    animation-delay: 0.3s;
}

/* Fade out animation for skeleton */
.timeline-skeleton.fade-out {
    animation: skeletonFadeOut 0.3s ease-out forwards;
}

@keyframes skeletonFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes skeletonFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Timeline item fade in animation */
.timeline-item.fade-in {
    animation: timelineItemFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes timelineItemFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive skeleton */
@media (max-width: 600px) {
    .skeleton-timeline-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }

    .skeleton-timeline-title {
        width: 140px;
    }
}


/* ==========================================================================
   18. APEXCHARTS OVERRIDES
   ========================================================================== */

.apexcharts-menu {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-default) !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-lg) !important;
    border-radius: var(--radius-md) !important;
    padding: var(--space-xs) !important;
    min-width: 140px !important;
}

.apexcharts-menu-item {
    color: var(--text-secondary) !important;
    font-family: var(--font-body) !important;
    font-size: 0.8rem !important;
    transition: all var(--transition-fast);
    padding: var(--space-sm) var(--space-md) !important;
    border-radius: var(--radius-sm);
}

.apexcharts-menu-item:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

/* Toolbar icons */
.apexcharts-toolbar {
    z-index: 10 !important;
}

.apexcharts-toolbar svg {
    fill: var(--text-muted) !important;
    transition: fill var(--transition-fast);
}

.apexcharts-toolbar svg:hover {
    fill: var(--text-primary) !important;
}

.apexcharts-toolbar .apexcharts-menu-icon:hover svg,
.apexcharts-toolbar .apexcharts-reset-icon:hover svg,
.apexcharts-toolbar .apexcharts-zoom-icon:hover svg,
.apexcharts-toolbar .apexcharts-zoomin-icon:hover svg,
.apexcharts-toolbar .apexcharts-zoomout-icon:hover svg,
.apexcharts-toolbar .apexcharts-pan-icon:hover svg,
.apexcharts-toolbar .apexcharts-selection-icon:hover svg {
    fill: var(--text-primary) !important;
}

/* Active state for toolbar icons */
.apexcharts-toolbar .apexcharts-pan-icon.apexcharts-selected svg,
.apexcharts-toolbar .apexcharts-selection-icon.apexcharts-selected svg,
.apexcharts-toolbar .apexcharts-zoom-icon.apexcharts-selected svg {
    fill: var(--accent-primary) !important;
}

/* Tooltip customization to match theme */
.apexcharts-tooltip {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-default) !important;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    pointer-events: none !important;
    will-change: transform !important;
    transform: translateZ(0);
    contain: layout paint;
    max-height: min(80vh, 900px);
    overflow-y: auto;
    /* Stand above sibling cards (Data table) when the tooltip extends outside the chart bounds */
    z-index: 1000 !important;
}

.apexcharts-tooltip-title {
    background: var(--bg-tertiary) !important;
    border-bottom: 1px solid var(--border-subtle) !important;
    font-family: var(--font-body) !important;
    font-size: 0.8rem !important;
    padding: var(--space-xs) var(--space-sm) !important;
}

.apexcharts-tooltip-text {
    color: var(--text-primary) !important;
    font-family: var(--font-body) !important;
    font-size: 0.8rem !important;
    display: flex !important;
    align-items: center !important;
}

.apexcharts-tooltip-series-group {
    padding: 4px var(--space-sm) !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    justify-content: flex-start !important;
    text-align: left !important;
}

.apexcharts-tooltip-marker {
    width: 10px !important;
    height: 10px !important;
    margin-right: 0 !important;
    flex-shrink: 0 !important;
    border-radius: 50% !important;
    align-self: center !important;
}

.apexcharts-tooltip-y-group {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
}

/* X-axis tooltip */
.apexcharts-xaxistooltip {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-default) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    font-family: var(--font-body) !important;
    font-size: 0.75rem !important;
}

.apexcharts-xaxistooltip:after,
.apexcharts-xaxistooltip:before {
    border-bottom-color: var(--bg-elevated) !important;
}


/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .dashboard-wrapper {
        animation: none;
    }
}


/* ==========================================================================
   19. DASHBOARD CUSTOMIZATION
   ========================================================================== */

/* Dashboard Toolbar */
.dashboard-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.dashboard-toolbar__left,
.dashboard-toolbar__right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.dashboard-toolbar__btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dashboard-toolbar__btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.dashboard-toolbar__btn.active {
    background: rgba(var(--accent-primary-rgb), 0.15);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.dashboard-toolbar__btn--primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.dashboard-toolbar__btn--primary:hover {
    filter: brightness(1.1);
    color: white;
}

/* Responsive button labels - show full by default, short on mobile */
.dashboard-toolbar__label--short {
    display: none;
}

/* Layout Switcher */
.layout-switcher {
    position: relative;
}

.layout-switcher__btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 180px;
    justify-content: space-between;
}

.layout-switcher__btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
}

.layout-switcher__btn svg {
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.layout-switcher__dropdown.open + .layout-switcher__btn svg,
.layout-switcher__btn[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.layout-switcher__dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 250px;
    margin-top: var(--space-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}

.layout-switcher__dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.layout-switcher__list {
    padding: var(--space-xs);
    overflow: visible;
}

.layout-switcher__item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.layout-switcher__item:hover {
    background: var(--bg-hover);
}

.layout-switcher__item.active {
    background: rgba(var(--accent-primary-rgb), 0.1);
}

.layout-switcher__item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    min-width: 0;
}

.layout-switcher__item-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout-switcher__item-meta {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.layout-switcher__item-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.layout-switcher__badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 6px;
    background: rgba(var(--accent-primary-rgb), 0.15);
    color: var(--accent-primary);
    border-radius: var(--radius-full);
}

/* More button */
.layout-switcher__more-btn {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
}

.layout-switcher__item:hover .layout-switcher__more-btn {
    opacity: 1;
}

.layout-switcher__more-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Context Menu */
.layout-context-menu {
    position: absolute;
    top: 100%;
    right: var(--space-xs);
    z-index: var(--z-modal);
    min-width: 160px;
    padding: var(--space-xs);
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.95);
    transform-origin: top right;
    transition: all 0.15s ease;
}

.layout-context-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(4px) scale(1);
}

.layout-context-menu__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-sm);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: var(--font-body);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.layout-context-menu__item:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.layout-context-menu__item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.layout-context-menu__item--danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.layout-context-menu__divider {
    height: 1px;
    margin: var(--space-xs) 0;
    background: var(--border-subtle);
}

/* Layout Modal */
.layout-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 1000);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.layout-modal.open {
    opacity: 1;
    visibility: visible;
}

.layout-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.layout-modal__content {
    position: relative;
    width: 90%;
    max-width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.98);
    transition: transform 0.2s ease;
}

.layout-modal.open .layout-modal__content {
    transform: translateY(0) scale(1);
}

.layout-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-default);
}

.layout-modal__header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.layout-modal__close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.layout-modal__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.layout-modal__body {
    padding: var(--space-lg);
}

.layout-modal__label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.layout-modal__input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.15s;
}

.layout-modal__input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.layout-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-default);
}

.layout-modal__btn {
    padding: var(--space-sm) var(--space-lg);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.layout-modal__btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.layout-modal__btn--primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.layout-modal__btn--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.layout-modal__btn--danger {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
}

.layout-modal__btn--danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

/* Toast Notification */
.layout-toast {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: var(--space-sm) var(--space-lg);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    opacity: 0;
    visibility: hidden;
    z-index: 9999;
    transition: all 0.3s ease;
}

.layout-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Export Menu */
.export-menu {
    position: relative;
}

.export-menu__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 200;
    min-width: 260px;
    margin-top: var(--space-xs);
    padding: var(--space-xs);
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.95);
    transform-origin: top right;
    transition: all 0.15s ease;
}

.export-menu__dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.export-menu__header {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.export-menu__option {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    text-align: left;
    text-decoration: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.export-menu__option:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.export-menu__option svg {
    flex-shrink: 0;
    margin-top: 2px;
}

.export-menu__option-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.export-menu__option-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.export-menu__option-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.export-menu__option:hover .export-menu__option-desc {
    color: var(--text-secondary);
}

.export-menu__divider {
    height: 1px;
    margin: var(--space-xs) 0;
    background: var(--border-subtle);
}

.export-menu__option--link {
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-xs);
    padding-top: var(--space-sm);
}

/* Site Selector */
.header-btn[aria-label="Site Filter"] {
    width: auto;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    min-width: auto;
    gap: var(--space-xs);
}

.site-selector-display {
    margin-left: var(--space-xs);
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-btn[aria-label="Site Filter"]:hover .site-selector-display {
    color: var(--text-primary);
}

.site-selector {
    position: relative;
}

.site-selector__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 200;
    min-width: 300px;
    max-width: 360px;
    margin-top: var(--space-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}

.site-selector__dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.site-selector__search {
    position: relative;
    padding: var(--space-xs);
    border-bottom: 1px solid var(--border-subtle);
}

.site-selector__search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.site-selector__search-input {
    width: 100%;
    padding: 6px 8px 6px 28px;
    font-size: 0.8rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.site-selector__search-input:focus {
    border-color: var(--accent-primary);
}

.site-selector__body {
    max-height: 320px;
    overflow-y: auto;
    padding: var(--space-xs) 0;
}

.site-selector__section-header {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.site-selector__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 5px var(--space-sm);
    background: none;
    border: none;
    text-align: left;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.82rem;
}

.site-selector__item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.site-selector__item--all {
    padding: var(--space-xs) var(--space-sm);
    font-weight: 500;
}

.site-selector__item--active {
    color: var(--accent-primary);
}

.site-selector__item--active .site-selector__item-label {
    font-weight: 500;
}

.site-selector__check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--accent-primary);
}

.site-selector__checkbox {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    border: 1.5px solid var(--border-default);
    border-radius: 3px;
    transition: all var(--transition-fast);
}

.site-selector__checkbox--checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.site-selector__checkbox--partial {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.site-selector__checkbox-dash {
    font-size: 10px;
    line-height: 1;
    font-weight: 700;
}

.site-selector__item-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-selector__item-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.site-selector__org-group {
    margin-bottom: 2px;
}

.site-selector__org-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 6px var(--space-sm);
    background: none;
    border: none;
    text-align: left;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    transition: background var(--transition-fast);
}

.site-selector__org-header:hover {
    background: var(--bg-hover);
}

.site-selector__org-name {
    flex: 1;
}

.site-selector__org-group > .site-selector__item {
    padding-left: calc(var(--space-sm) + 24px);
}

.site-selector__group-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.site-selector__group-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
    padding: 5px var(--space-sm);
    background: none;
    border: none;
    text-align: left;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.82rem;
    transition: background var(--transition-fast);
}

.site-selector__group-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.site-selector__group-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.site-selector__group-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.site-selector__group-action--danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.site-selector__divider {
    height: 1px;
    margin: var(--space-xs) 0;
    background: var(--border-subtle);
}

.site-selector__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) var(--space-sm);
}

.site-selector__footer-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.site-selector__count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.site-selector__clear {
    font-size: 0.75rem;
    color: var(--accent-primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.site-selector__clear:hover {
    background: rgba(var(--accent-primary-rgb, 59, 130, 246), 0.1);
}

.site-selector__new-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.site-selector__new-group:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Site Selector Apply/Cancel Actions */
.site-selector__actions {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.site-selector__cancel-btn,
.site-selector__apply-btn {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.site-selector__cancel-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.site-selector__cancel-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.site-selector__apply-btn {
    background: var(--accent-primary);
    border: none;
    color: var(--text-inverse);
}

.site-selector__apply-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.site-selector__apply-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .site-selector__dropdown {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        min-width: unset;
        max-width: unset;
        width: 100%;
        max-height: calc(100vh - var(--header-height));
        border-radius: 0;
        margin-top: 0;
    }

    .site-selector-display {
        display: none;
    }
}

/* Site Selector Modal (for custom groups) */
.site-selector-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.site-selector-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.site-selector-modal__content {
    position: relative;
    width: 90%;
    max-width: 420px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.site-selector-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}

.site-selector-modal__header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.site-selector-modal__close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.site-selector-modal__close:hover {
    color: var(--text-primary);
}

.site-selector-modal__body {
    padding: var(--space-md);
}

.site-selector-modal__label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.site-selector-modal__input {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.85rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.site-selector-modal__input:focus {
    border-color: var(--accent-primary);
}

.site-selector-modal__sites {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-xs);
}

.site-selector-modal__site-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 4px var(--space-xs);
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.site-selector-modal__site-row:hover {
    background: var(--bg-hover);
}

.site-selector-modal__site-row input[type="checkbox"] {
    accent-color: var(--accent-primary);
}

.site-selector-modal__site-org {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.site-selector-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-top: 1px solid var(--border-subtle);
}

.site-selector-modal__btn {
    padding: 6px 16px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.site-selector-modal__btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.site-selector-modal__btn--primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.site-selector-modal__btn--primary:hover {
    opacity: 0.9;
}

/* Orchestrator site card org badge */
.orch-site-card__org {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.layout-switcher__actions {
    padding: var(--space-xs);
    border-top: 1px solid var(--border-subtle);
}

.layout-switcher__action {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.layout-switcher__action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* KPI Grid Edit Mode */
.kpi-grid--edit-mode .kpi-card-wrapper {
    cursor: grab;
}

.kpi-grid--edit-mode .kpi-card-wrapper:active {
    cursor: grabbing;
}

.kpi-grid--edit-mode .kpi-card {
    border-style: dashed;
    position: relative;
}

.kpi-grid--edit-mode .kpi-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(var(--accent-primary-rgb), 0.03);
    pointer-events: none;
    border-radius: inherit;
}

.kpi-card-wrapper.dragging {
    opacity: 0.5;
}

.kpi-card-wrapper.drag-over {
    transform: scale(1.02);
}

.kpi-card-placeholder {
    background: rgba(var(--accent-primary-rgb), 0.1);
    border: 2px dashed var(--accent-primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    color: var(--accent-primary);
    font-size: 0.875rem;
    font-weight: 500;
}

/* ==========================================================================
   20. KPI PICKER MODAL
   ========================================================================== */

.kpi-picker-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.kpi-picker-modal.open {
    opacity: 1;
    visibility: visible;
}

.kpi-picker-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.kpi-picker-modal__content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 95%;
    max-width: 1100px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: translateY(20px) scale(0.98);
    transition: transform var(--transition-base);
}

.kpi-picker-modal.open .kpi-picker-modal__content {
    transform: translateY(0) scale(1);
}

.kpi-picker-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
}

.kpi-picker-modal__header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.kpi-picker-modal__close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.kpi-picker-modal__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.kpi-picker-modal__body {
    display: grid;
    grid-template-columns: 200px 1fr 280px;
    flex: 1;
    overflow: hidden;
}

/* KPI Picker Sidebar */
.kpi-picker__sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
}

.kpi-picker__search {
    position: relative;
}

.kpi-picker__search-icon {
    position: absolute;
    left: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.kpi-picker__search-input {
    width: 100%;
    padding: var(--space-sm) var(--space-sm) var(--space-sm) 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-body);
}

.kpi-picker__search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(var(--accent-primary-rgb), 0.2);
}

.kpi-picker__dept-tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kpi-picker__dept-tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.kpi-picker__dept-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.kpi-picker__dept-tab.active {
    background: var(--bg-secondary);
    color: var(--dept-color, var(--text-primary));
    font-weight: 600;
    border-left: 3px solid var(--dept-color, var(--accent-primary));
}

.kpi-picker__dept-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-full);
}

/* KPI Picker Main Grid */
.kpi-picker__main {
    padding: var(--space-md);
    overflow-y: auto;
}

.kpi-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-sm);
}

.kpi-picker__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.kpi-picker__item:hover {
    border-color: var(--border-default);
    background: var(--bg-hover);
}

.kpi-picker__item.selected {
    border-color: var(--kpi-color, var(--accent-primary));
    background: rgba(var(--accent-primary-rgb), 0.1);
}

.kpi-picker__item-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    color: var(--kpi-color, var(--text-secondary));
    flex-shrink: 0;
}

.kpi-picker__item-content {
    flex: 1;
    min-width: 0;
}

.kpi-picker__item-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-picker__item-dept {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.kpi-picker__item-toggle {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.kpi-picker__item-toggle:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.kpi-picker__item.selected .kpi-picker__item-toggle {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.kpi-picker__empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

/* KPI Picker Selected Panel */
.kpi-picker__selected {
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
}

.kpi-picker__selected-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}

.kpi-picker__selected-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.kpi-picker__selected-count {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb), 0.15);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.kpi-picker__selected-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.kpi-picker__selected-empty {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

.kpi-picker__selected-empty p {
    margin: 0 0 var(--space-xs) 0;
}

.kpi-picker__selected-hint {
    font-size: 0.75rem;
}

.kpi-picker__selected-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-secondary);
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xs);
    transition: transform 0.15s ease, opacity 0.15s ease,
                border-color 0.15s ease, background 0.15s ease;
}

.kpi-picker__selected-grip {
    color: var(--text-muted);
    cursor: grab;
    flex-shrink: 0;
}

.kpi-picker__selected-grip:active {
    cursor: grabbing;
}

/* Drag and drop states */
.kpi-picker__selected-item.dragging {
    opacity: 0.4;
    transform: scale(0.98);
    background: var(--bg-hover);
    border-color: var(--border-default);
}

.kpi-picker__selected-item.drop-above {
    border-top-color: var(--accent-primary);
    border-top-width: 2px;
}

.kpi-picker__selected-item.drop-below {
    border-bottom-color: var(--accent-primary);
    border-bottom-width: 2px;
}

.kpi-picker__selected-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-picker__selected-label {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-picker__selected-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.kpi-picker__move-btn,
.kpi-picker__remove-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.kpi-picker__move-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.kpi-picker__move-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.kpi-picker__remove-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
}

/* KPI Picker Footer */
.kpi-picker-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
}

.kpi-picker__btn {
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.kpi-picker__btn--secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.kpi-picker__btn--secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.kpi-picker__btn--primary {
    background: var(--accent-primary);
    border: none;
    color: white;
}

.kpi-picker__btn--primary:hover {
    filter: brightness(1.1);
}

/* ==========================================================================
   21. SETUP WIZARD
   ========================================================================== */

.setup-wizard {
    position: fixed;
    inset: 0;
    z-index: 1100; /* Must be above mobile nav (1000) and sidebar (1001) */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.setup-wizard.open {
    opacity: 1;
    visibility: visible;
}

.setup-wizard__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

.setup-wizard__container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 95%;
    max-width: 700px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: translateY(30px) scale(0.95);
    transition: transform var(--transition-base);
}

.setup-wizard.open .setup-wizard__container {
    transform: translateY(0) scale(1);
}

/* Progress Steps */
.setup-wizard__progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: var(--space-lg);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
}

.setup-wizard__progress-step {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 2px solid var(--border-default);
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.setup-wizard__progress-step.active {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.setup-wizard__progress-step.current {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.setup-wizard__progress-line {
    width: 40px;
    height: 2px;
    background: var(--border-default);
}

/* Wizard Content */
.setup-wizard__content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
}

.setup-wizard__step {
    animation: fadeInUp 0.3s ease;
}

.setup-wizard__title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 var(--space-sm) 0;
    text-align: center;
}

.setup-wizard__subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0 0 var(--space-lg) 0;
    text-align: center;
}

.setup-wizard__count {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Welcome Step */
.setup-wizard__step--welcome {
    text-align: center;
    padding: var(--space-xl) 0;
}

.setup-wizard__welcome-icon {
    color: var(--accent-primary);
    margin-bottom: var(--space-lg);
}

.setup-wizard__hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: var(--space-md);
}

/* Presets Step */
.setup-wizard__presets {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.setup-wizard__preset {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: var(--bg-tertiary);
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    width: 100%;
}

.setup-wizard__preset:hover {
    border-color: var(--border-default);
    background: var(--bg-hover);
}

.setup-wizard__preset.selected {
    border-color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb), 0.1);
}

.setup-wizard__preset-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    flex-shrink: 0;
}

.setup-wizard__preset.selected .setup-wizard__preset-icon {
    color: var(--accent-primary);
}

.setup-wizard__preset-content {
    flex: 1;
}

.setup-wizard__preset-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.setup-wizard__preset-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.setup-wizard__preset-count {
    font-size: 0.75rem;
    color: var(--accent-primary);
    margin-top: var(--space-xs);
}

.setup-wizard__preset-check {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-default);
    border-radius: 50%;
    color: transparent;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.setup-wizard__preset.selected .setup-wizard__preset-check {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* KPI Selection Step */
.setup-wizard__kpi-groups {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.setup-wizard__kpi-group {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.setup-wizard__group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    border-left: 3px solid var(--dept-color, var(--accent-primary));
}

.setup-wizard__group-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.setup-wizard__group-toggle {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.setup-wizard__group-toggle:hover {
    color: var(--accent-primary);
}

.setup-wizard__group-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--space-xs);
    padding: var(--space-sm);
}

.setup-wizard__kpi-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.setup-wizard__kpi-item:hover {
    background: var(--bg-hover);
}

.setup-wizard__kpi-item.selected {
    border-color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb), 0.1);
}

.setup-wizard__kpi-item input {
    display: none;
}

.setup-wizard__kpi-icon {
    flex-shrink: 0;
}

.setup-wizard__kpi-label {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.setup-wizard__kpi-check {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: transparent;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.setup-wizard__kpi-item.selected .setup-wizard__kpi-check {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* Review Step */
.setup-wizard__name-input {
    margin-bottom: var(--space-lg);
}

.setup-wizard__name-input label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.setup-wizard__name-input input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-body);
}

.setup-wizard__name-input input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(var(--accent-primary-rgb), 0.2);
}

.setup-wizard__review-list {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
}

.setup-wizard__review-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}

.setup-wizard__review-item:last-child {
    border-bottom: none;
}

.setup-wizard__review-num {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.setup-wizard__review-icon {
    flex-shrink: 0;
}

.setup-wizard__review-label {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.setup-wizard__review-dept {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.setup-wizard__review-empty {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

/* Wizard Footer */
.setup-wizard__footer {
    display: flex;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
}

.setup-wizard__btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.setup-wizard__btn--secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.setup-wizard__btn--secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.setup-wizard__btn--primary {
    background: var(--accent-primary);
    border: none;
    color: white;
}

.setup-wizard__btn--primary:hover:not(:disabled) {
    filter: brightness(1.1);
}

.setup-wizard__btn--primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Setup Wizard — Mobile */
@media (max-width: 768px) {
    .setup-wizard__container {
        width: 100%;
        max-width: 100%;
        max-height: calc(100vh - 80px - env(safe-area-inset-bottom, 20px));
        margin-top: env(safe-area-inset-top, 0px);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        align-self: flex-end;
    }

    .setup-wizard__progress {
        padding: var(--space-md);
    }

    .setup-wizard__content {
        padding: var(--space-md);
    }

    .setup-wizard__title {
        font-size: 1.25rem;
    }

    .setup-wizard__step--welcome {
        padding: var(--space-md) 0;
    }

    .setup-wizard__preset-icon {
        width: 40px;
        height: 40px;
    }

    .setup-wizard__preset {
        padding: var(--space-md);
    }

    .setup-wizard__group-kpis {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .setup-wizard__review-list {
        max-height: 200px;
    }

    .setup-wizard__footer {
        padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
    }
}

/* ==========================================================================
   20. SEARCH PAGE
   ========================================================================== */

.search-page {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 160px);
}

.search-page__input-wrap {
    position: relative;
    padding: var(--space-md) 0;
}

.search-page__icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-page__input {
    width: 100%;
    padding: var(--space-md) var(--space-md) var(--space-md) 44px;
    font-size: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    -webkit-appearance: none;
}

.search-page__input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Override dropdown behavior — results are inline on the search page */
.search-page .search-results {
    position: static;
    width: 100%;
    margin-top: var(--space-sm);
    max-height: none;
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    border: none;
    border-radius: 0;
    background: transparent;
}

.search-page .search-result-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    padding: var(--space-md);
}

.search-page .search-result-item:hover {
    background: var(--bg-elevated);
    border-color: var(--border-default);
}

.search-page .search-result-item:last-child {
    border-bottom: 1px solid var(--border-subtle);
}

.search-page .search-results__empty {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.search-page__empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-xl) var(--space-md);
    text-align: center;
    color: var(--text-muted);
    flex: 1;
}

.search-page__empty-state svg {
    opacity: 0.3;
}

.search-page__empty-state p {
    font-size: 0.875rem;
    max-width: 240px;
}

@media (min-width: 769px) {
    .search-page {
        max-width: 640px;
        margin: 0 auto;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard-toolbar {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .dashboard-toolbar__left,
    .dashboard-toolbar__right {
        width: 100%;
        justify-content: center;
    }

    /* Export dropdown: fixed full-width panel on mobile */
    .export-menu {
        position: static;
    }

    .export-menu__dropdown {
        position: fixed;
        top: auto;
        left: var(--space-md);
        right: var(--space-md);
        min-width: unset;
        max-height: calc(100vh - 220px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transform-origin: top center;
        z-index: 1000;
    }

    .export-menu__dropdown.open {
        transform: translateY(0) scale(1);
    }

    .export-menu__option {
        padding: var(--space-md);
        gap: var(--space-md);
    }

    .site-selector__dropdown {
        position: fixed;
        top: auto;
        left: var(--space-md);
        right: var(--space-md);
        min-width: unset;
        max-width: unset;
        max-height: calc(100vh - 220px);
        -webkit-overflow-scrolling: touch;
        transform-origin: top center;
        z-index: 1000;
    }

    .site-selector__dropdown.open {
        transform: translateY(0) scale(1);
    }

    .site-selector__body {
        max-height: calc(100vh - 380px);
    }

    .site-selector-display {
        display: none;
    }

    .export-menu__option-label {
        font-size: 0.95rem;
    }

    .export-menu__option-desc {
        font-size: 0.8rem;
    }

    .export-menu__header {
        padding: var(--space-sm) var(--space-md);
    }

    /* Show short label on mobile, hide full label */
    .dashboard-toolbar__label--full {
        display: none;
    }

    .dashboard-toolbar__label--short {
        display: inline;
    }

    .kpi-picker-modal__body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .kpi-picker__sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }

    .kpi-picker__dept-tabs {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .kpi-picker__selected {
        border-left: none;
        border-top: 1px solid var(--border-subtle);
        max-height: 200px;
    }

    .setup-wizard__group-kpis {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   PWA Install Prompt — Bottom Sheet
   ============================================================ */

.install-prompt {
    position: fixed;
    inset: 0;
    z-index: 1100;
    pointer-events: none;
}

.install-prompt.open {
    pointer-events: auto;
}

.install-prompt__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 300ms ease;
}

.install-prompt.open .install-prompt__overlay {
    opacity: 1;
}

.install-prompt__sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-sm) var(--space-lg) var(--space-xl);
    transform: translateY(100%);
    transition: transform 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.install-prompt.open .install-prompt__sheet {
    transform: translateY(0);
}

.install-prompt__handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-default);
    margin: 0 auto var(--space-md);
}

.install-prompt__header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.install-prompt__icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.install-prompt__title-group {
    flex: 1;
    min-width: 0;
}

.install-prompt__title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.install-prompt__subtitle {
    margin: 2px 0 0;
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

.install-prompt__close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.install-prompt__close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.install-prompt__description {
    margin: 0 0 var(--space-lg);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* iOS instruction steps */

.install-prompt__steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.install-prompt__step {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.install-prompt__step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.install-prompt__step-text {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
}

.install-prompt__inline-icon {
    display: inline-block;
    vertical-align: middle;
    color: var(--accent-primary);
    flex-shrink: 0;
}

/* Action buttons */

.install-prompt__actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    padding-top: var(--space-md);
}

.install-prompt__btn {
    padding: var(--space-sm) var(--space-lg);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.install-prompt__btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.install-prompt__btn--primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.install-prompt__btn--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* Responsive — mobile adjustments */

@media (max-width: 768px) {
    .install-prompt__sheet {
        max-width: none;
        border-radius: 16px 16px 0 0;
        padding-bottom: calc(var(--space-xl) + 70px + env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 769px) {
    .install-prompt__sheet {
        bottom: var(--space-lg);
        border-radius: var(--radius-lg);
    }
}

/* ===================================================================
   Scheduled Exports
   =================================================================== */

/* Schedule card list */
.sched-list { display: flex; flex-direction: column; gap: var(--space-sm); }

.sched-empty {
    padding: var(--space-xl);
    text-align: center;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.sched-empty--error { color: #fca5a5; }

/* Schedule card */
.sched-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    transition: border-color 0.2s ease;
}
.sched-card:hover { border-color: var(--border-default); }
.sched-card--inactive { opacity: 0.5; }
.sched-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}
.sched-card__info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sched-card__clickable { cursor: pointer; }
.sched-card__title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.sched-card__name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sched-card__type {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.sched-card__owner {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.sched-card__meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.6875rem;
    color: var(--text-muted);
}
.sched-card__id {
    font-family: var(--font-mono, monospace);
    font-size: 0.625rem;
    color: var(--text-muted);
    opacity: 0.7;
}
.sched-card__actions { display: flex; gap: 4px; flex-shrink: 0; }
.sched-card__btn {
    background: none;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.sched-card__btn:hover { border-color: var(--border-default); color: var(--text-primary); }
.sched-card__btn--danger:hover { border-color: rgba(239,68,68,0.5); color: #fca5a5; }
.sched-card__details {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
}
.sched-card__divider { color: var(--border-default); }

/* Status badges */
.sched-status {
    display: inline-flex;
    align-items: center;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
}
.sched-status--success { background: rgba(16,185,129,0.1); color: #6ee7b7; }
.sched-status--error { background: rgba(239,68,68,0.15); color: #fca5a5; }
.sched-status--pending { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* Schedule modal (reused by exports, reports, admin) */
.sched-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.sched-modal.active { display: flex; }
.sched-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}
.sched-modal__content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    animation: schedModalIn 0.2s ease;
}
.sched-modal__content--sm { max-width: 400px; }
.sched-modal__content--lg { max-width: 600px; }
@keyframes schedModalIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.sched-modal__header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0 4px;
    padding: var(--space-lg) var(--space-xl) var(--space-md);
}
.sched-modal__header .sched-modal__close { margin-left: auto; }
.sched-modal__title {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.sched-modal__subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: var(--space-sm);
}
.sched-modal__close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease;
}
.sched-modal__close:hover { color: var(--text-primary); }
.sched-modal__body { padding: 0 var(--space-xl) var(--space-lg); }
.sched-modal__text { font-size: 0.875rem; color: var(--text-secondary); margin: 0 0 var(--space-sm); line-height: 1.5; }
.sched-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border-top: 1px solid var(--border-subtle);
}
.sched-modal__btn {
    padding: 8px 16px;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid var(--border-default);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    transition: all 0.15s ease;
}
.sched-modal__btn:hover { border-color: var(--accent-primary); color: var(--text-primary); }
.sched-modal__btn--primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}
.sched-modal__btn--primary:hover { opacity: 0.9; }
.sched-modal__btn--primary:disabled { opacity: 0.6; cursor: not-allowed; }
.sched-btn-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: em-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}
.sched-modal__btn--danger {
    background: rgba(239,68,68,0.15);
    border-color: rgba(239,68,68,0.3);
    color: #fca5a5;
}
.sched-modal__btn--danger:hover { background: rgba(239,68,68,0.25); border-color: #ef4444; }

/* Schedule form fields */
.sched-form-group { margin-bottom: var(--space-md); }
.sched-form-group--half { flex: 1; min-width: 0; }
.sched-form-row { display: flex; gap: var(--space-md); }
.sched-form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sched-form-input,
.sched-form-select {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s ease;
    color-scheme: dark;
}
.sched-form-input:focus,
.sched-form-select:focus { border-color: var(--accent-primary); }
.sched-form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 4px 0 0;
}
.sched-form-hint code {
    font-size: 0.6875rem;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-subtle);
    border-radius: 3px;
    padding: 1px 5px;
    font-family: var(--font-mono, monospace);
    color: var(--text-secondary);
}

/* File name preview */
.sched-filename-preview {
    color: var(--accent-primary);
    font-family: var(--font-mono, monospace);
    font-size: 0.6875rem;
    padding: 4px 8px;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

/* Clickable tag buttons for file name template */
.sched-filename-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.sched-filename-tag {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 3px 10px;
    font-size: 0.6875rem;
    font-family: var(--font-mono, monospace);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sched-filename-tag:hover {
    background: rgba(255,255,255,0.12);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}
.sched-filename-tag:active {
    transform: translateY(1px);
}

/* Form divider */
.sched-form-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-md) 0;
}

/* Date mode radio group */
.sched-form-radio-group {
    display: flex;
    gap: var(--space-md);
    margin-top: 4px;
}
.sched-form-radio__label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.sched-form-radio__label input[type="radio"] {
    accent-color: var(--accent-primary);
    margin: 0;
}

/* Comparison checkbox */
.sched-form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.sched-form-check input[type="checkbox"] {
    accent-color: var(--accent-primary);
    margin: 0;
}

/* KPI picker in schedule modal */
.sched-kpi-picker-container {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}
.sched-kpi-picker { padding: var(--space-xs) 0; }
.sched-kpi-dept { border-bottom: 1px solid var(--border-subtle); }
.sched-kpi-dept:last-child { border-bottom: none; }
.sched-kpi-dept__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px var(--space-sm);
    background: rgba(255,255,255,0.02);
}
.sched-kpi-dept__label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}
.sched-kpi-dept__label input[type="checkbox"] { accent-color: var(--accent-primary); }
.sched-kpi-dept__count {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 500;
}
.sched-kpi-dept__list { padding: 0 var(--space-sm) var(--space-xs) 28px; }
.sched-kpi-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    cursor: pointer;
}
.sched-kpi-item__cb { accent-color: var(--accent-primary); }
.sched-kpi-item__label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.sched-kpi-total {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Site picker in schedule modal */
.sched-site-picker-container {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}
.sched-site-picker { padding: var(--space-xs) 0; }
.sched-site-picker__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px var(--space-sm);
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(255,255,255,0.03);
    position: sticky;
    top: 0;
    z-index: 1;
}
.sched-site-picker__select-all {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
}
.sched-site-picker__select-all input[type="checkbox"] { accent-color: var(--accent-primary); }
.sched-site-picker__count {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 500;
}
.sched-site-org { border-bottom: 1px solid var(--border-subtle); }
.sched-site-org:last-child { border-bottom: none; }
.sched-site-org__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px var(--space-sm);
    background: rgba(255,255,255,0.02);
}
.sched-site-org__label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}
.sched-site-org__label input[type="checkbox"] { accent-color: var(--accent-primary); }
.sched-site-org__count {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 500;
}
.sched-site-org__list { padding: 0 var(--space-sm) var(--space-xs) 28px; }
.sched-site-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    cursor: pointer;
}
.sched-site-item__cb { accent-color: var(--accent-primary); }
.sched-site-item__label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.sched-site-total {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Email tag editor in schedule modal */
.sched-tag-editor {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    min-height: 42px;
    cursor: text;
    transition: border-color 0.2s ease;
}
.sched-tag-editor:focus-within { border-color: var(--accent-primary); }
.sched-tag-editor__input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.8125rem;
    min-width: 120px;
    flex: 1;
    padding: 2px 0;
}
.sched-tag-editor__input::placeholder { color: var(--text-muted); }
.sched-tag-chip {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 16px;
    padding: 4px 8px 4px 12px;
    font-size: 0.8125rem;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    animation: tagIn 0.15s ease;
}
.sched-tag-chip__remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}
.sched-tag-chip__remove:hover {
    color: var(--accent-primary);
    background: rgba(239,68,68,0.15);
}

/* Inline error in schedule modal */
.sched-modal__error {
    margin: var(--space-md) 0 0;
    padding: var(--space-sm) var(--space-md);
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.25);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: #fca5a5;
    line-height: 1.5;
}
.sched-modal__error strong { color: #fecaca; }
.sched-error__domains {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.sched-error__domain {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-default);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-primary);
    font-family: var(--font-mono, monospace);
}

/* Schedule section on pages */
.sched-section {
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}
.sched-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}
.sched-section__title {
    font-family: var(--font-display);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.sched-section__count {
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
}

/* Schedule button (inline with other action buttons) */
.sched-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.sched-btn:hover { border-color: var(--accent-primary); color: var(--text-primary); }
.sched-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Admin scheduled exports table */
.sched-admin-table {
    width: 100%;
    border-collapse: collapse;
}
.sched-admin-table th {
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}
.sched-admin-table td {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}
.sched-admin-table tr:hover td { background: rgba(255,255,255,0.02); }
.sched-admin-table .sched-inactive td { opacity: 0.5; }

@media (max-width: 768px) {
    .sched-form-row { flex-direction: column; gap: 0; }
    .sched-modal__content { width: 95%; max-height: 90vh; }
    .sched-admin-table { font-size: 0.75rem; }
    .sched-admin-table th, .sched-admin-table td { padding: var(--space-xs) var(--space-sm); }
}

/* ── Landscape orientation lock (phones only, not tablets) ── */
.landscape-lock-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--bg-primary);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-primary);
}

@media (orientation: landscape) and (max-height: 500px) {
    .landscape-lock-overlay {
        display: flex;
    }
}

/* ======================================================================== */
/* Exports Manager Panel (header dropdown — global, loaded on every page)   */
/* ======================================================================== */

.em-panel {
    position: fixed;
    z-index: 200;
    width: 380px;
    max-height: 480px;
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}

.em-panel--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.em-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.em-panel__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.em-panel__close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.em-panel__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.em-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.em-panel__empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.em-panel__footer {
    padding: var(--space-sm) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    text-align: center;
}

.em-panel__link {
    color: var(--page-accent);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
}

.em-panel__link:hover {
    text-decoration: underline;
}

.em-section {
    padding: 0 0.5rem;
}

.em-section__label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.5rem 0.5rem 0.25rem;
}

.em-job {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    margin: 0 0.25rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.em-job:hover {
    background: var(--bg-hover);
}

.em-job__info {
    flex: 1;
    min-width: 0;
}

.em-job__title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.em-job__meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.2rem;
    font-size: 0.7rem;
}

.em-job__type { color: var(--text-muted); }
.em-job__size { color: var(--text-muted); }
.em-job__time { color: var(--text-muted); }

.em-job__error {
    font-size: 0.7rem;
    color: #ef4444;
    margin-top: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.em-job__actions {
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.em-status {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
}

.em-status--pending { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.em-status--active { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.em-status--success { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.em-status--error { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.em-status--cancelled { background: rgba(100, 116, 139, 0.12); color: #64748b; }

.em-spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: em-spin 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes em-spin { to { transform: rotate(360deg); } }

.em-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s;
}

.em-btn--download {
    color: #fff;
    background: var(--page-accent);
}

.em-btn--download:hover {
    background: #b91c1c;
}

.em-btn--cancel {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.em-btn--cancel:hover {
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .em-panel {
        width: calc(100vw - 2rem);
        right: 1rem !important;
        max-height: 70vh;
    }
}


/* ==========================================================================
   DEMAND HEAT-MAP (/demand)
   ========================================================================== */

.demand { --demand-accent: #f59e0b; position: relative; min-width: 0; }

/* .main-content is a flex item, so it defaults to min-width:auto and refuses
   to shrink below its content's min-content width. The heat-map grid is wider
   than a phone, so without this the whole page scrolls sideways instead of the
   grid scrolling inside its own container. Scoped to this page rather than
   applied app-wide, so no other layout shifts as a side effect. */
.main-content:has(.demand) { min-width: 0; }
.main-content:has(.demand) > .content-area,
.main-content:has(.demand) > * { min-width: 0; }

/* Components below set an explicit `display`, which outranks the [hidden]
   attribute's UA `display:none` — without this a hidden drill-down panel
   stays invisible but keeps swallowing clicks across the whole page. */
.demand [hidden],
.demand-drill[hidden],
.demand-drill__backdrop[hidden] { display: none !important; }

.demand__intro { max-width: 780px; margin-bottom: var(--space-lg); }
.demand__lede {
    font-size: 0.95rem; line-height: 1.62; color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}
.demand__freshness {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.78rem; color: var(--text-muted);
}

/* --- Controls ----------------------------------------------------------- */

.demand-controls {
    display: flex; flex-wrap: wrap; align-items: flex-start;
    gap: var(--space-lg) var(--space-xl);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-secondary); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md); margin-bottom: var(--space-lg);
}
.demand-controls__group { display: flex; flex-direction: column; gap: 7px; }
.demand-controls__label {
    font-size: 0.625rem; font-weight: 600; letter-spacing: 0.14em;
    text-transform: uppercase; color: var(--text-muted);
}
.demand-controls__btns { display: flex; flex-wrap: wrap; gap: 6px; }
.demand-controls__group--wedge { margin-left: auto; }

.demand .control-btn.active--neutral {
    background: rgba(148, 163, 184, 0.14);
    border-color: #94a3b8; color: #e2e8f0;
}
.demand-ramp-chip {
    display: block; width: 24px; height: 9px;
    border-radius: 2px; margin-right: 2px;
}

.demand-wedge { display: flex; align-items: center; gap: 6px; }
.demand-wedge__step {
    width: 26px; height: 26px; border-radius: var(--radius-sm);
    background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
    color: var(--text-secondary); cursor: pointer; font-size: 0.95rem;
    line-height: 1; transition: all var(--transition-fast);
}
.demand-wedge__step:hover { background: var(--bg-hover); color: var(--text-primary); }
.demand-wedge__value {
    min-width: 40px; text-align: center; font-weight: 700;
    font-size: 0.82rem; color: var(--text-primary);
}
.demand-wedge__count {
    font-size: 0.66rem; font-weight: 600; padding: 3px 7px;
    border-radius: 4px; white-space: nowrap;
    background: rgba(148, 163, 184, 0.12); color: var(--text-secondary);
}
/* Turns red when the marker fires on so many cells it reads as texture
   rather than signal — the failure mode that moved the default to 1.7x. */
.demand-wedge__count.is-noisy {
    background: rgba(239, 68, 68, 0.13); color: #f87171;
}

/* --- Scope readout ------------------------------------------------------ */
/* Site selection lives in the app-wide header selector; this only reports
   what the page is currently showing. */

.demand-scope {
    display: flex; align-items: center; gap: 7px;
    height: 30px; padding: 0 11px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}
.demand-scope__label {
    font-size: 0.8rem; font-weight: 600; color: var(--text-primary);
    white-space: nowrap;
}
.demand-scope__hint {
    font-size: 0.68rem; color: var(--text-muted); white-space: nowrap;
    padding-left: 7px; border-left: 1px solid var(--border-subtle);
}

/* --- States ------------------------------------------------------------- */

.demand-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: var(--space-md); min-height: 380px;
    text-align: center; padding: var(--space-xl);
    background: var(--bg-secondary); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg); color: var(--text-muted);
}
.demand-state__msg { max-width: 460px; font-size: 0.85rem; line-height: 1.6; }
.demand-skeleton {
    width: 100%; max-width: 900px; height: 220px; border-radius: var(--radius-md);
    background: repeating-linear-gradient(90deg,
        var(--bg-tertiary) 0 62px, transparent 62px 68px),
        repeating-linear-gradient(180deg,
        var(--bg-tertiary) 0 40px, transparent 40px 46px);
    animation: demand-shimmer 1.6s ease-in-out infinite;
}
@keyframes demand-shimmer { 0%,100% { opacity: 0.35; } 50% { opacity: 0.7; } }

/* --- Cards -------------------------------------------------------------- */

.demand-card {
    background: var(--bg-secondary); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg); padding: var(--space-lg);
    margin-bottom: var(--space-lg); min-width: 0; max-width: 100%;
}
.demand-card__head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: var(--space-lg); margin-bottom: var(--space-md); flex-wrap: wrap;
}
.demand-card__title {
    font-family: var(--font-display); font-size: 0.95rem; font-weight: 700;
    color: var(--text-primary); margin-bottom: 4px;
}
.demand-card__sub {
    font-size: 0.78rem; line-height: 1.55; color: var(--text-muted);
    max-width: 62ch;
}
.demand-card__meta { font-size: 0.72rem; color: var(--text-muted); }

.demand-banner {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; margin-bottom: var(--space-md);
    border-radius: var(--radius-md);
    background: linear-gradient(90deg,
        rgba(239, 68, 68, 0.07), rgba(34, 197, 94, 0.07));
    border: 1px solid rgba(148, 163, 184, 0.22);
}
.demand-banner__tag {
    flex: 0 0 auto; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.13em;
    text-transform: uppercase; color: #cbd5e1;
    padding: 4px 8px; border-radius: 4px; background: rgba(148, 163, 184, 0.16);
}
.demand-banner__text { font-size: 0.78rem; color: var(--text-secondary); }

/* --- Legend ------------------------------------------------------------- */

.demand-legend { display: flex; flex-direction: column; gap: 6px; }
.demand-legend__title {
    font-size: 0.64rem; font-weight: 600; letter-spacing: 0.1em;
    text-transform: uppercase; color: var(--text-muted); text-align: right;
}
.demand-legend__scale { display: flex; gap: 3px; }
.demand-legend__item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.demand-legend__swatch {
    display: block; width: 38px; height: 13px; border-radius: 3px;
}
.demand-legend__item:first-child .demand-legend__swatch {
    border: 1px solid var(--border-subtle);
}
.demand-legend__label { font-size: 0.6rem; color: var(--text-muted); }

/* --- "How to read this grid" -------------------------------------------- */
/* The colour ramp legend covers magnitude. This covers the other four
   encodings — dashed edges, corner wedges, hatching, empty cells — which are
   meaningless without a key. */

.demand-guide { margin-bottom: var(--space-md); }
.demand-guide__toggle {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 5px 11px; border-radius: var(--radius-sm);
    background: transparent; border: 1px solid var(--border-subtle);
    color: var(--text-secondary); cursor: pointer;
    font-size: 0.72rem; font-weight: 600;
    transition: all var(--transition-fast);
}
.demand-guide__toggle:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.demand-guide.is-open .demand-guide__toggle {
    background: var(--bg-tertiary); border-color: var(--border-default);
    color: var(--text-primary);
}
.demand-guide__body {
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: var(--space-lg); margin-top: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    background: var(--bg-primary); border: 1px solid var(--border-subtle);
}

.demand-guide__terms { display: flex; flex-direction: column; gap: var(--space-md); }
.demand-guide__term { display: flex; align-items: flex-start; gap: 11px; }
.demand-guide__chip {
    position: relative; flex: 0 0 auto;
    width: 46px; height: 38px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700;
}
.demand-guide__chip-wedge {
    position: absolute; top: 0; right: 0; width: 0; height: 0;
    border-top: 13px solid rgba(255, 255, 255, 0.3);
    border-left: 13px solid transparent;
    border-radius: 0 var(--radius-sm) 0 0;
}
.demand-guide__term-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.demand-guide__term-name {
    font-size: 0.78rem; font-weight: 600; color: var(--text-primary);
}
.demand-guide__term-def {
    font-size: 0.72rem; line-height: 1.55; color: var(--text-muted);
}

.demand-guide__states { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.demand-guide__states-title {
    font-size: 0.62rem; font-weight: 600; letter-spacing: 0.12em;
    text-transform: uppercase; color: var(--text-muted);
}
.demand-guide__states-grid { display: flex; flex-direction: column; gap: 8px; }
.demand-guide__state { display: flex; align-items: center; gap: 10px; }
.demand-guide__demo {
    position: relative; flex: 0 0 auto; width: 46px; height: 34px;
    border-radius: 5px; display: flex; align-items: center;
    justify-content: center; cursor: default;
}
/* The demo swatches reuse the real cell classes, so they cannot drift out of
   sync with the grid — but they must not inherit its hover lift. */
.demand-guide__demo.demand-cell--filled:hover { transform: none; box-shadow: none; }
.demand-guide__demo-num { font-size: 0.85rem; font-weight: 700; line-height: 1; }
.demand-guide__state-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.demand-guide__state-name {
    font-size: 0.74rem; font-weight: 600; color: var(--text-primary);
}
.demand-guide__state-desc {
    font-size: 0.68rem; line-height: 1.5; color: var(--text-muted);
}

/* --- Grid --------------------------------------------------------------- */

.demand-grid-scroll { overflow: visible; }
.demand-grid-scroll.is-scrolling {
    max-height: 540px; overflow-y: auto; padding-right: 4px;
}
.demand-grid { display: flex; flex-direction: column; gap: 4px; min-width: 780px; }
.demand-grid__row { display: flex; align-items: stretch; gap: 4px; }
.demand-grid__rowlabel {
    flex: 0 0 96px; display: flex; align-items: center;
    font-size: 0.78rem; font-weight: 600; color: #cbd5e1;
}
.demand-grid__rowlabel.is-peak { color: var(--text-primary); font-weight: 700; }
.demand-grid__hourhead {
    flex: 1 1 0; min-width: 0; text-align: center;
    font-size: 0.68rem; font-weight: 600; color: var(--text-muted);
}
.demand-grid__hourhead.is-peak { color: var(--demand-accent); font-weight: 700; }
.demand-grid__rowtotal {
    flex: 0 0 78px; display: flex; flex-direction: column;
    align-items: flex-end; justify-content: center; gap: 3px;
    font-size: 0.8rem; font-weight: 600; color: #cbd5e1;
}
.demand-grid__rowtotal.is-peak { color: var(--demand-accent); font-weight: 700; }
.demand-grid__rowbar {
    display: block; height: 3px; border-radius: 2px; background: #475569;
}
.demand-grid__rowtotal.is-peak .demand-grid__rowbar { background: var(--demand-accent); }
.demand-grid__row--foot { margin-top: 2px; }
.demand-grid__hourtotal {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: flex-end; gap: 3px;
}
.demand-grid__hourbar {
    display: block; width: 13px; border-radius: 2px 2px 0 0; background: #3f4757;
}
.demand-grid__hourbar.is-peak { background: var(--demand-accent); }
.demand-grid__hournum { font-size: 0.6rem; color: var(--text-muted); }
.demand-grid__hourtotal.is-peak .demand-grid__hournum {
    color: var(--demand-accent); font-weight: 700;
}

/* --- Cells -------------------------------------------------------------- */
/* Three distinct facts, three distinct treatments: a site that was closed,
   an open hour with zero demand, and an hour we have no data for. */

.demand-cell {
    position: relative; flex: 1 1 0; min-width: 0; height: 62px;
    border-radius: 5px; display: flex; align-items: center;
    justify-content: center; transition: transform 120ms ease;
}
.demand-cell--closed {
    background: transparent; border: 1px dashed rgba(255, 255, 255, 0.07);
}
.demand-cell--nodata {
    background: repeating-linear-gradient(45deg,
        #161a22 0 5px, #1e2430 5px 10px);
    border: 1px solid var(--border-subtle);
}
.demand-cell--nodata .demand-cell__num { font-size: 14px; color: #475569; }
.demand-cell--filled {
    border: 1px solid rgba(255, 255, 255, 0.04); cursor: pointer;
}
.demand-cell--filled:hover, .demand-cell--filled:focus-visible {
    z-index: 30; transform: scale(1.045); outline: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4),
                0 0 0 1.5px rgba(248, 250, 252, 0.55);
}
/* Low-confidence: fewer than 3 contributing days, or a conversion cell with
   a denominator too small to be stable. */
.demand-cell--low {
    border: 1px dashed rgba(248, 250, 252, 0.42); opacity: 0.78;
}
.demand-cell__num { font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
.demand-cell__wedge {
    position: absolute; top: 0; right: 0; width: 0; height: 0;
    border-top-style: solid; border-left-style: solid;
    border-left-color: transparent; border-radius: 0 5px 0 0;
}
.demand-cell__thin {
    position: absolute; left: 4px; bottom: 3px; width: 12px; height: 2px;
    border-radius: 1px; background: rgba(248, 250, 252, 0.55);
}

/* --- Callouts ----------------------------------------------------------- */

.demand-callouts {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-sm);
}
.demand-callout {
    display: flex; align-items: center; gap: 11px; padding: 11px 14px;
    border-radius: var(--radius-md); background: var(--bg-primary);
    border: 1px solid var(--border-subtle); cursor: pointer;
    transition: all var(--transition-fast);
}
.demand-callout:hover { background: var(--bg-tertiary); }
.demand-callout.is-top { border-color: rgba(245, 158, 11, 0.3); }
.demand-callout.is-bad { border-color: rgba(239, 68, 68, 0.22); }
.demand-callout__rank {
    flex: 0 0 auto; width: 26px; height: 26px; border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700;
    background: rgba(148, 163, 184, 0.12); color: var(--text-secondary);
}
.demand-callout.is-top .demand-callout__rank {
    background: rgba(245, 158, 11, 0.2); color: var(--demand-accent);
}
.demand-callout.is-bad .demand-callout__rank {
    background: rgba(239, 68, 68, 0.16); color: #ef4444;
}
.demand-callout__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.demand-callout__when {
    font-size: 0.8rem; font-weight: 600; color: var(--text-primary);
}
.demand-callout__detail { font-size: 0.7rem; color: var(--text-muted); }

/* --- Site comparison ---------------------------------------------------- */

.demand-minis {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
    gap: var(--space-sm);
}
.demand-mini {
    background: var(--bg-primary); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md); padding: 11px 12px 9px; cursor: pointer;
    transition: all var(--transition-fast);
}
.demand-mini:hover { border-color: var(--demand-accent); }
.demand-mini__head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 6px; margin-bottom: 8px;
}
.demand-mini__name {
    font-size: 0.76rem; font-weight: 600; color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.demand-mini__idx {
    flex: 0 0 auto; font-size: 0.62rem; font-weight: 600;
    padding: 1px 5px; border-radius: 3px;
    background: rgba(148, 163, 184, 0.08); color: var(--text-muted);
}
.demand-mini__idx.is-high { background: rgba(245, 158, 11, 0.15); color: var(--demand-accent); }
.demand-mini__idx.is-low { background: rgba(148, 163, 184, 0.12); color: var(--text-secondary); }
.demand-mini__grid { display: flex; flex-direction: column; gap: 2px; }
.demand-mini__row { display: flex; gap: 2px; }
.demand-mini__dot { display: block; flex: 1 1 0; height: 7px; border-radius: 1.5px; }
.demand-mini__dot.is-closed {
    background: transparent; border: 1px dashed rgba(255, 255, 255, 0.05);
}
.demand-mini__foot {
    display: flex; justify-content: space-between; margin-top: 7px;
    font-size: 0.6rem; color: var(--text-muted);
}

/* --- Drill-down --------------------------------------------------------- */

.demand-drill {
    position: fixed; top: var(--header-height); right: 0; bottom: 0;
    width: 436px; max-width: 92vw; background: var(--bg-secondary);
    border-left: 1px solid var(--border-default);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.55);
    display: flex; flex-direction: column; z-index: var(--z-modal);
}
.demand-drill__backdrop {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4);
    z-index: calc(var(--z-modal) - 1);
}
.demand-drill__head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: var(--space-md); padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}
.demand-drill__title {
    font-family: var(--font-display); font-size: 0.95rem; font-weight: 700;
    color: var(--text-primary);
}
.demand-drill__sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; }
.demand-drill__close {
    flex: 0 0 auto; width: 30px; height: 30px; border-radius: var(--radius-sm);
    background: none; border: none; color: var(--text-muted); cursor: pointer;
}
.demand-drill__close:hover { background: var(--bg-hover); color: var(--text-primary); }
.demand-drill__body { flex: 1 1 auto; overflow-y: auto; padding: var(--space-lg); }
.demand-drill__value {
    font-family: var(--font-display); font-size: 2.1rem; font-weight: 700;
    color: var(--text-primary); line-height: 1;
}
.demand-drill__unit { font-size: 0.72rem; color: var(--text-muted); margin-top: 5px; }
.demand-drill__conf {
    display: inline-block; margin-top: 9px; padding: 2px 6px; border-radius: 3px;
    font-size: 0.6rem; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(148, 163, 184, 0.12); color: var(--text-secondary);
}
.demand-drill__conf.is-thin {
    background: rgba(245, 158, 11, 0.14); color: var(--demand-accent);
}
.demand-drill__scope {
    margin-top: var(--space-md); padding: 8px 11px;
    border-radius: var(--radius-sm); background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    font-size: 0.68rem; line-height: 1.5; color: var(--text-muted);
}
.demand-drill__spark { display: block; width: 100%; height: 96px; margin-top: var(--space-lg); }
.demand-drill__axis {
    display: flex; justify-content: space-between;
    font-size: 0.62rem; color: var(--text-muted); margin-top: 4px;
}
.demand-drill__stats {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-sm);
    margin-top: var(--space-lg);
}
.demand-drill__stat {
    display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
    background: var(--bg-primary); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}
.demand-drill__statk {
    font-size: 0.6rem; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-muted);
}
.demand-drill__statv { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.demand-drill__statn { font-size: 0.6rem; color: var(--text-muted); }
.demand-drill__verdict {
    margin-top: var(--space-lg); padding: 11px 13px;
    border-radius: var(--radius-sm); background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    font-size: 0.72rem; line-height: 1.55; color: var(--text-secondary);
}
.demand-drill__list { margin-top: var(--space-lg); display: flex; flex-direction: column; gap: 4px; }
.demand-drill__listrow { display: flex; align-items: center; gap: 9px; }
.demand-drill__listdate { flex: 0 0 52px; font-size: 0.68rem; color: var(--text-muted); }
.demand-drill__listtrack { flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--bg-tertiary); }
.demand-drill__listbar { display: block; height: 100%; border-radius: 3px; background: #8a611a; }
.demand-drill__listbar.is-peak { background: var(--demand-accent); }
.demand-drill__listbar.is-low { background: #475569; }
.demand-drill__listval {
    flex: 0 0 44px; text-align: right; font-size: 0.7rem;
    font-weight: 600; color: var(--text-secondary);
}


/* --- Demand heat-map: mobile -------------------------------------------- */

@media (max-width: 768px) {
    .demand-controls {
        gap: var(--space-md); padding: var(--space-md);
    }
    .demand-controls__group--wedge { margin-left: 0; }
    .demand-controls__btns { gap: 5px; }
    .demand-controls .control-btn { font-size: 0.72rem; padding: 5px 9px; }
    /* Label plus hint are far wider than a phone on one line, and the pair
       would push the whole page into horizontal scroll. Stack them instead. */
    .demand-controls__group--scope { width: 100%; min-width: 0; }
    .demand-scope {
        width: 100%; min-width: 0; height: auto;
        align-items: flex-start; flex-direction: column; gap: 3px;
        padding: 7px 11px;
    }
    .demand-scope > svg { display: none; }
    .demand-scope__label { white-space: normal; }
    .demand-scope__hint {
        white-space: normal; padding-left: 0; border-left: none;
    }

    /* The grid scrolls horizontally rather than shrinking: a cell that cannot
       hold its number is not a cell. The day label column stays pinned so a
       scrolled row is still identifiable.

       width/min-width are both pinned: without them the scroller grows to fit
       its content and the overflow lands on the page body instead, which is
       exactly the horizontal-scrolling page this is meant to prevent. */
    .demand-grid-scroll {
        overflow-x: auto; overflow-y: visible;
        width: 100%; max-width: 100%; min-width: 0;
        -webkit-overflow-scrolling: touch;
    }
    .demand-grid-scroll.is-scrolling { max-height: none; overflow-y: visible; }
    .demand-grid { min-width: 0; width: max-content; }

    .demand-grid__rowlabel {
        position: sticky; left: 0; z-index: 20;
        flex: 0 0 52px; padding-right: 6px;
        background: var(--bg-secondary); font-size: 0.7rem;
    }
    .demand-grid__row--head .demand-grid__rowlabel,
    .demand-grid__row--foot .demand-grid__rowlabel { background: var(--bg-secondary); }
    /* Abbreviate day names to keep the sticky column narrow */
    .demand-grid__rowname { display: inline-block; max-width: 46px;
        overflow: hidden; text-overflow: clip; white-space: nowrap; }

    .demand-cell { flex: 0 0 54px; height: 54px; }
    .demand-cell__num { font-size: 16px !important; }
    .demand-grid__hourhead { flex: 0 0 54px; }
    .demand-grid__hourtotal { flex: 0 0 54px; }
    .demand-grid__rowtotal { flex: 0 0 56px; font-size: 0.72rem; }

    .demand-guide__body { grid-template-columns: 1fr; gap: var(--space-md); }
    .demand-legend { width: 100%; }
    .demand-legend__title { text-align: left; }
    .demand-legend__scale { flex-wrap: wrap; }
    .demand-legend__swatch { width: 30px; }

    .demand-card { padding: var(--space-md); }
    .demand-callouts { grid-template-columns: 1fr; }
    .demand-minis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

    /* Drill-down becomes a bottom sheet — a 436px side rail does not fit */
    .demand-drill {
        top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: 100%;
        max-height: 86vh; border-left: none;
        border-top: 1px solid var(--border-default);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .demand-drill__stats { grid-template-columns: repeat(2, 1fr); }
}
