/* ==========================================================================
   HOTEL INTELLIGENCE PLATFORM — Production Design System
   Anti-AI: conservative radius, no glow, tight tracking, asymmetric spacing
   References: Stripe, Linear, Vercel design systems
   ========================================================================== */

/* --- Light Theme (Default) --- */
:root {
    --bg-primary: #fafbfc;
    --bg-card: #ffffff;
    --bg-section: #f6f8fa;
    --bg-input: #ffffff;
    --bg-tertiary: #f1f3f5;
    --bg-glass: rgba(255,255,255,0.92);
    --text-primary: #0a1628;
    --text-secondary: #3b4c63;
    --text-muted: #7d8a9a;
    --border-color: #e2e8f0;
    --accent-blue: #4f46e5;
    --accent-green: #059669;
    --accent-yellow: #d97706;
    --accent-red: #dc2626;
    --accent-teal: #0d9488;
    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    /* Stripe: blue-tinted multi-layer shadows */
    --shadow-sm: 0 1px 2px rgba(50,50,93,0.08), 0 1px 1px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(50,50,93,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 20px -5px rgba(50,50,93,0.12), 0 4px 8px -4px rgba(0,0,0,0.08);
    --shadow-glow: none;
    --glass-blur: blur(12px);
    --glass-border: 1px solid #e2e8f0;
    /* Conservative radius — nothing pill-shaped (Stripe: 4-8px) */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: 0.15s ease-out;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
    --bg-primary: #0c0f1a;
    --bg-card: #151926;
    --bg-section: #1a1f30;
    --bg-input: #1e2538;
    --bg-tertiary: #232a3e;
    --bg-glass: rgba(21,25,38,0.95);
    --text-primary: #e4e8ee;
    --text-secondary: #98a4b8;
    --text-muted: #586474;
    --border-color: rgba(148,163,184,0.1);
    --glass-border: 1px solid rgba(148,163,184,0.1);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3), 0 1px 1px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.35), 0 2px 4px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.4), 0 4px 8px rgba(0,0,0,0.25);
    --shadow-glow: none;
}

/* --- Semantic Spacing & Typography --- */
:root {
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --font-xs: 0.65rem;
    --font-sm: 0.8rem;
    --font-md: 0.9rem;
    --font-lg: 1.1rem;
    --font-xl: 1.5rem;
    --font-hero: 1.8rem;
    --sidebar-width: 220px;
    --sidebar-collapsed: 56px;
    --topbar-height: 50px;
    /* Tabular numerals for financial data */
    --font-numeric: "Tabular Lining";
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    transition: background 0.15s ease-out, color 0.15s ease-out;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "tnum";
    font-weight: 400;
    letter-spacing: -0.011em;
}
body.has-sidebar {
    overflow: hidden; /* Main-area handles scrolling when sidebar layout is active */
    height: 100vh;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ======================================================================
   SIDEBAR LAYOUT SYSTEM
   ====================================================================== */

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform 0.15s ease-out, width 0.15s ease-out;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
    min-height: var(--topbar-height);
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.logo-icon {
    width: 28px; height: 28px;
    background: var(--accent-blue);
    color: #fff;
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.logo-text {
    font-weight: 700;
    font-size: var(--font-md);
    white-space: nowrap;
}
.sidebar-close {
    display: none;
    background: none; border: none;
    font-size: 1.5rem; cursor: pointer;
    color: var(--text-secondary);
}

/* Sidebar Nav */
.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-sm);
    font-weight: 500;
    border-radius: 8px;
    margin: 2px 8px;
    transition: all var(--transition);
    border-left: none;
    white-space: nowrap;
    letter-spacing: -0.01em;
}
.nav-item:hover {
    background: var(--bg-section);
    color: var(--text-primary);
}
.nav-item.active {
    background: rgba(91,93,240,0.1);
    color: var(--accent-blue);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent-blue);
}
.nav-icon {
    font-size: 1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}
.nav-label { white-space: nowrap; }
.nav-divider {
    padding: 0.6rem 1rem 0.3rem;
    font-size: var(--font-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.nav-divider span { opacity: 0.7; }

.sidebar-footer {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border-color);
}
.sidebar-version {
    font-size: var(--font-xs);
    color: var(--text-muted);
    text-align: center;
}

/* Main Area (right of sidebar) — this is the scroll container */
.main-area {
    margin-left: var(--sidebar-width);
    height: 100vh;
    overflow-y: auto;
    transition: margin-left 0.3s ease;
}

/* Top Bar */
.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1.2rem;
    z-index: 100;
    gap: 1rem;
}
.hamburger {
    display: none;
    background: none; border: none; cursor: pointer;
    width: 28px; height: 20px;
    position: relative;
    flex-shrink: 0;
}
.hamburger span {
    display: block;
    position: absolute;
    height: 2px; width: 100%;
    background: var(--text-primary);
    border-radius: 2px;
    transition: 0.2s;
}
.hamburger span:nth-child(1){ top:0 }
.hamburger span:nth-child(2){ top:9px }
.hamburger span:nth-child(3){ top:18px }

.topbar-title {
    flex: 1;
    font-size: var(--font-sm);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-title strong { color: var(--text-primary); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-shrink: 0;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    user-select: none;
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    background: var(--bg-section);
    border: 1px solid var(--border-color);
}
.mode-label {
    font-size: var(--font-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #10b981;
    min-width: 32px;
    text-align: center;
}
.mode-track {
    width: 40px; height: 20px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    position: relative;
    border: 1px solid var(--border-color);
}
.mode-thumb {
    width: 16px; height: 16px;
    background: var(--accent-blue);
    border-radius: 50%;
    position: absolute;
    top: 1px; left: 1px;
    transition: transform 0.2s ease;
}

/* Theme Button */
.theme-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-section);
    cursor: pointer;
    font-size: 1rem;
    display: grid;
    place-items: center;
    transition: 0.2s;
}
.theme-btn:hover { background: var(--bg-tertiary); }

/* Content Area */
.content-area {
    padding: 1.2rem;
    max-width: 1400px;
    animation: fadeIn 0.3s ease;
}

/* ======================================================================
   MODE VISIBILITY
   ====================================================================== */
[data-mode="executive"] [data-mode-hide="exec"] { display: none !important; }
[data-mode="operations"] [data-mode-hide="ops"] { display: none !important; }
/* Show-only variants */
[data-mode="executive"] [data-mode-show="ops"] { display: none !important; }
[data-mode="operations"] [data-mode-show="exec"] { display: none !important; }

/* ======================================================================
   RESPONSIVE — Mobile (tablet ≤1023, phone ≤768, narrow ≤480)
   ====================================================================== */

/* Sidebar backdrop — covers content area when sidebar is open on mobile */
.sidebar-backdrop {
    display: none;
    pointer-events: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    z-index: 150;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.open {
    display: block;
    pointer-events: auto;
    animation: fadeIn 0.15s ease;
}

@media (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(280px, 86vw);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.25);
    }
    .sidebar-close {
        display: grid;
        place-items: center;
        width: 40px; height: 40px;
        font-size: 1.6rem;
        border-radius: 8px;
    }
    .sidebar-close:hover { background: var(--bg-section); }
    .hamburger {
        display: block;
        width: 44px; height: 44px;
        padding: 12px 8px;
    }
    .hamburger span:nth-child(1){ top: 12px }
    .hamburger span:nth-child(2){ top: 21px }
    .hamburger span:nth-child(3){ top: 30px }
    .main-area { margin-left: 0; }
    /* Larger touch targets for nav items on mobile (iOS HIG: 44px min) */
    .nav-item {
        padding: 0.75rem 0.85rem;
        font-size: 0.88rem;
        margin: 1px 6px;
    }
    .nav-icon { font-size: 1.15rem; }
    .topbar { padding: 0 0.6rem; gap: 0.5rem; }
    .topbar-title { font-size: 0.78rem; }
    .content-area { padding: 0.8rem 0.7rem; }
}

/* Phone — hide non-essential topbar bits, scale page title */
@media (max-width: 640px) {
    :root { --topbar-height: 54px; }
    .topbar { gap: 0.35rem; padding: 0 0.5rem; }
    .topbar-title {
        font-size: 0.72rem;
        flex: 1 1 0;
        min-width: 0;
    }
    .topbar-actions { gap: 0.35rem; }
    .mode-toggle { display: none; }  /* exec/ops toggle hidden on phones — set in localStorage if needed */
    .theme-btn { width: 36px; height: 36px; }
    .page-title { font-size: 1.15rem; line-height: 1.25; padding: 0 0.4rem; }
    .page-subtitle { font-size: 0.74rem; }
    .glass-card { padding: 0.7rem; }
    .glass-card h3 { font-size: 0.85rem; }
    .hero-card { padding: 0.55rem 0.4rem; }
    .hero-card .value { font-size: 1.05rem; }
    .hero-card .label { font-size: 0.55rem; }
    /* Force hero grid to a max of 3 cols on phones, ignoring inline 6-col layouts */
    .hero-grid { grid-template-columns: repeat(3, 1fr) !important; gap: 0.4rem; }
}

/* Narrow phone (iPhone SE / small Android) */
@media (max-width: 420px) {
    .hero-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .topbar-title strong { font-size: 0.78rem; }
    .content-area { padding: 0.6rem 0.5rem; }
    .guest-chip-label { display: none !important; }
    .guest-chip-short { display: inline !important; }
    .user-name { max-width: 60px !important; }
    /* Hide property switcher on very narrow screens — use sidebar instead */
    .property-switcher { font-size: 0.66rem !important; padding: 0.25rem 0.35rem !important; }
}

/* Universal table wrapper — any direct child .table-scroll wraps tables in horizontal scroll */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.2rem;
    padding: 0 0.2rem;
    max-width: 100%;
}
.table-scroll table {
    display: table !important;
    min-width: max-content;
    white-space: normal;
}

/* Make raw tables inside glass-cards scroll horizontally on small screens —
   but skip tables that are already wrapped in .table-scroll (those use the wrapper instead). */
@media (max-width: 768px) {
    .glass-card > table,
    .glass-card > div:not(.table-scroll) > table,
    .chart-box > table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    /* Preserve cell wrapping for cells with explicit widths */
    .glass-card td, .glass-card th { white-space: normal; }
}

/* Shared glass card (used across all pages) */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    transition: box-shadow 0.2s ease;
}
.glass-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.06); }
.glass-card h3 { font-size: var(--font-md); margin-bottom: 0.3rem; }

/* Shared hero grid */
.hero-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.6rem;
    margin-bottom: var(--spacing-md);
}
.hero-grid-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1023px) {
    .hero-grid-6 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
    .hero-grid-6 { grid-template-columns: repeat(2, 1fr); }
}
.hero-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 0.7rem;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: transform 0.2s;
}
.hero-card:hover { transform: translateY(-2px); }
.hero-card .value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-card .label { font-size: var(--font-xs); color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.15rem; }

/* Shared narrative boxes */
.narrative { border-left: 4px solid; padding: 0.6rem 0.9rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-bottom: 0.8rem; font-size: var(--font-sm); line-height: 1.5; }
.narrative.blue { border-color: #6366f1; background: rgba(99,102,241,.06); }
.narrative.green { border-color: #10b981; background: rgba(16,185,129,.06); }
.narrative.amber { border-color: #f59e0b; background: rgba(245,158,11,.06); }
.narrative.red { border-color: #ef4444; background: rgba(239,68,68,.06); }

/* Shared chart container */
.chart-container { position: relative; height: 260px; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--spacing-md); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--spacing-md); }
@media (max-width: 768px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .hero-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Page titles */
.page-title {
    font-size: var(--font-xl);
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.2rem;
}
.page-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--font-sm);
    margin-bottom: var(--spacing-md);
}

/* --- Header --- */
.header {
    text-align: center;
    margin-bottom: 2rem;
}
.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 0.3rem;
}
.header .subtitle {
    color: #636e72;
    font-size: 1rem;
}
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- Upload Form --- */
.upload-form {
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.form-section {
    margin-bottom: 1.8rem;
}
.form-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #f0f0f0;
}

.file-group {
    margin-bottom: 1rem;
}
.file-group.optional {
    opacity: 0.85;
}
.file-label {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    cursor: pointer;
    margin-bottom: 0.4rem;
}
.file-label.required strong::after {
    content: " *";
    color: #e74c3c;
}
.file-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: #4a69bd;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}
.file-label small {
    color: #636e72;
    font-size: 0.82rem;
}
input[type="file"] {
    display: block;
    width: 100%;
    padding: 0.6rem;
    border: 2px dashed #ddd;
    border-radius: 8px;
    background: #fafafa;
    cursor: pointer;
    font-size: 0.9rem;
}
input[type="file"]:hover {
    border-color: #4a69bd;
    background: #f8f9ff;
}
.file-name {
    font-size: 0.82rem;
    color: #999;
    margin-top: 0.2rem;
}
.file-name.selected {
    color: #27ae60;
    font-weight: 500;
}

.field-row {
    display: flex;
    gap: 1.5rem;
}
.field {
    flex: 1;
}
.field label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}
.field input[type="date"],
.field input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
}
.field input:focus {
    outline: none;
    border-color: #4a69bd;
    box-shadow: 0 0 0 3px rgba(74,105,189,0.15);
}

.submit-btn {
    display: block;
    width: 100%;
    padding: 1rem;
    background: #4a69bd;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.submit-btn:hover:not(:disabled) {
    background: #3c55a0;
}
.submit-btn:disabled {
    background: #95a5a6;
    cursor: wait;
}

.footer {
    text-align: center;
    margin-top: 2rem;
    color: #999;
    font-size: 0.85rem;
}
.footer p { margin-bottom: 0.3rem; }

/* --- Results Page --- */
.results-page .header { text-align: left; }

.back-link {
    color: #4a69bd;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
}
.back-link:hover { text-decoration: underline; }

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat {
    flex: 1;
    background: #fff;
    border-radius: 10px;
    padding: 1rem 1.2rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    text-align: center;
}
.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #1a1a2e;
}
.stat-label {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.2rem;
}
.stat-good .stat-value { color: #27ae60; }
.stat-warn .stat-value { color: #f39c12; }
.stat-bad .stat-value { color: #e74c3c; }

/* Sections */
.section {
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 6px rgba(0,0,0,0.05);
    margin-bottom: 1.2rem;
}
.section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 0.3rem;
}
.section-hint {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 1rem;
}

/* Triage */
.triage-group {
    margin-bottom: 1rem;
    padding: 0.8rem 1rem;
    border-radius: 8px;
}
.triage-group h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.triage-confirmed { background: #f0faf4; border-left: 4px solid #27ae60; }
.triage-review { background: #fef9ed; border-left: 4px solid #f39c12; }
.triage-investigate { background: #fdf0f0; border-left: 4px solid #e74c3c; }

.triage-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.triage-item:last-child { border-bottom: none; }
.triage-text {
    font-size: 0.9rem;
    font-weight: 500;
}
.triage-action {
    font-size: 0.85rem;
    color: #555;
    margin-top: 0.2rem;
    padding-left: 1rem;
    border-left: 2px solid #ddd;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-green { background: #d4edda; color: #155724; }
.badge-yellow { background: #fff3cd; color: #856404; }
.badge-red { background: #f8d7da; color: #721c24; }

/* Bucket Summary */
.bucket-list {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.85rem;
}
.bucket-row {
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    margin-bottom: 0.3rem;
}
.bucket-balanced { color: #27ae60; background: #f8fcf9; }
.bucket-excess { background: #fafafa; }
.bucket-header { font-weight: 600; }
.bucket-detail {
    padding-left: 1.5rem;
    color: #666;
    font-size: 0.82rem;
}

/* Investigation Order */
.investigation-list {
    padding-left: 1.5rem;
}
.investigation-list li {
    padding: 0.4rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid #f5f5f5;
}
.investigation-list li:last-child { border-bottom: none; }

/* RCA Case Cards */
.case-card {
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    margin-bottom: 0.8rem;
    overflow: hidden;
    transition: box-shadow 0.2s;
}
.case-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.case-card[open] { box-shadow: 0 2px 12px rgba(0,0,0,0.1); }

.case-confirmed { border-left: 4px solid #27ae60; }
.case-review { border-left: 4px solid #f39c12; }
.case-investigate { border-left: 4px solid #e74c3c; }

.case-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    list-style: none;
    flex-wrap: wrap;
}
.case-header::-webkit-details-marker { display: none; }
.case-header::before {
    content: "\25B6";
    font-size: 0.7rem;
    color: #999;
    transition: transform 0.2s;
}
.case-card[open] .case-header::before {
    transform: rotate(90deg);
}

.case-id {
    font-weight: 600;
    font-family: "SF Mono", monospace;
    font-size: 0.82rem;
    color: #4a69bd;
}
.case-label {
    color: #666;
    font-size: 0.82rem;
}
.case-confidence {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
    font-size: 0.8rem;
    color: #999;
}
.confidence-bar {
    width: 60px;
    height: 6px;
    background: #eee;
    border-radius: 3px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    background: #4a69bd;
    border-radius: 3px;
    transition: width 0.3s;
}

.case-body {
    padding: 0 1rem 1rem 2rem;
    font-size: 0.88rem;
}
.case-detail {
    margin-bottom: 0.6rem;
    line-height: 1.5;
}
.case-detail strong {
    color: #333;
}
.case-why {
    background: #f8f9ff;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    border-left: 3px solid #4a69bd;
}
.case-action {
    background: #fff8ed;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    border-left: 3px solid #f39c12;
}
.case-grouped {
    background: #f0faf4;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    font-family: "SF Mono", monospace;
    font-size: 0.82rem;
}
.case-crossdate {
    background: #fff3cd;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    color: #856404;
}
.case-projected {
    background: #d4edda;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    color: #155724;
    font-weight: 500;
}

.case-branches {
    padding-left: 1rem;
    margin: 0.4rem 0;
}
.branch {
    font-size: 0.85rem;
    color: #555;
    padding: 0.2rem 0;
}

.case-steps ol {
    padding-left: 1.5rem;
    margin-top: 0.3rem;
}
.case-steps li {
    padding: 0.2rem 0;
    font-size: 0.85rem;
}

.case-causes {
    margin-top: 0.5rem;
    padding: 0.5rem 0.8rem;
    background: #fafafa;
    border-radius: 6px;
}
.cause-line {
    font-size: 0.82rem;
    padding: 0.15rem 0;
    font-family: "SF Mono", monospace;
}

/* Actions */
.actions-section {
    display: flex;
    gap: 1rem;
    background: transparent;
    box-shadow: none;
    padding: 0;
}
.action-btn {
    flex: 1;
    display: block;
    text-align: center;
    padding: 0.8rem;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    background: #4a69bd;
    color: #fff;
    transition: background 0.2s;
}
.action-btn:hover { background: #3c55a0; }
.action-btn-secondary {
    background: #fff;
    color: #4a69bd;
    border: 2px solid #4a69bd;
}
.action-btn-secondary:hover {
    background: #f8f9ff;
}

/* Error */
.error-box {
    background: #fdf0f0;
    border: 1px solid #e74c3c;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}
.error-box h2 { color: #e74c3c; margin-bottom: 0.5rem; }
.error-box pre {
    background: #fff;
    padding: 1rem;
    border-radius: 6px;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    max-height: 300px;
}

/* ═══ MICRO-INTERACTIONS & POLISH (2026) ═══ */

/* Page fade-in */
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
body { animation: pageIn 0.4s ease; }

/* Card hover lift */
.glass-card, .hero-card, [class*="card"] {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.glass-card:hover, .hero-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

/* Tabular numbers for all data */
.amt, .value, .hero-num, [class*="amount"], td:nth-child(n+2) {
    font-variant-numeric: tabular-nums;
}

/* Table enhancements */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.data-table th { position: sticky; top: 0; background: var(--bg-card); z-index: 2; cursor: pointer; padding: 0.5rem 0.6rem; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); border-bottom: 2px solid var(--border-color); user-select: none; }
.data-table th:hover { color: var(--accent-blue); }
.data-table td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border-color); }
.data-table tr:hover td { background: rgba(99,102,241,0.04); }
.data-table .amt { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .pos { color: var(--accent-green); }
.data-table .neg { color: var(--accent-red); }

/* CSV export button */
.export-btn { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.3rem 0.7rem; border-radius: 6px; border: 1px solid var(--border-color); background: transparent; color: var(--text-muted); font-size: 0.7rem; cursor: pointer; transition: 0.2s; float: right; margin-bottom: 0.3rem; }
.export-btn:hover { border-color: var(--accent-blue); color: var(--accent-blue); }

/* Badge system */
.badge { display: inline-block; padding: 0.12rem 0.5rem; border-radius: 99px; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.02em; }
.badge-green { background: rgba(16,185,129,0.12); color: #10b981; }
.badge-orange { background: rgba(245,158,11,0.12); color: #f59e0b; }
.badge-red { background: rgba(239,68,68,0.12); color: #ef4444; }
.badge-blue { background: rgba(99,102,241,0.12); color: #6366f1; }
.stat-badge { font-size: 0.65rem; padding: 0.1rem 0.5rem; border-radius: 99px; background: rgba(99,102,241,0.1); color: #6366f1; font-weight: 600; margin-left: 0.3rem; vertical-align: middle; }

/* Alert system */
.alert { padding: 0.6rem 0.8rem; border-radius: 8px; font-size: 0.78rem; margin-bottom: 0.35rem; border-left: 4px solid; line-height: 1.5; }
.alert-high, .alert-critical { background: rgba(239,68,68,0.08); border-color: #ef4444; }
.alert-medium { background: rgba(245,158,11,0.08); border-color: #f59e0b; }
.alert-low { background: rgba(16,185,129,0.08); border-color: #10b981; }
.alert-info { background: rgba(99,102,241,0.08); border-color: #6366f1; }

/* Skeleton loading shimmer */
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skeleton { background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-section) 50%, var(--bg-card) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 8px; }

/* Stagger fade-in for cards */
@keyframes staggerIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.hero-grid > * { animation: staggerIn 0.3s ease both; }
.hero-grid > *:nth-child(1) { animation-delay: 0.05s; }
.hero-grid > *:nth-child(2) { animation-delay: 0.1s; }
.hero-grid > *:nth-child(3) { animation-delay: 0.15s; }
.hero-grid > *:nth-child(4) { animation-delay: 0.2s; }
.hero-grid > *:nth-child(5) { animation-delay: 0.25s; }
.hero-grid > *:nth-child(6) { animation-delay: 0.3s; }
.hero-grid > *:nth-child(7) { animation-delay: 0.35s; }

/* Chart container fade */
.chart-container { animation: staggerIn 0.5s ease 0.3s both; }

/* Fallback / empty state */
.fallback { text-align: center; padding: 3rem 1rem; background: var(--bg-card); border-radius: var(--radius-md); border: 1px dashed var(--border-color); }
.fallback h3 { color: var(--accent-blue); font-size: 1rem; margin-bottom: 0.5rem; }
.fallback p { color: var(--text-muted); font-size: 0.85rem; max-width: 500px; margin: 0 auto; line-height: 1.6; }

/* Focus visible for accessibility */
:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; border-radius: 4px; }

/* Screen reader only */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
    /* Sidebar must not animate at all when reduced-motion is set —
       a 0.01ms transition leaves a pending Web Animation that can pin
       the sidebar in its starting transform on first interaction. */
    .sidebar, .sidebar-backdrop { transition: none !important; }
}

/* ==========================================================================
   PREMIUM DESIGN ENHANCEMENTS (Stripe-inspired)
   ========================================================================== */

/* Numeric values — tabular lining for financial data */
.num, .amount, [data-numeric], .prof-stat .num, .onq-stat .n {
    font-variant-numeric: tabular-nums lining-nums;
    letter-spacing: -0.02em;
}

/* Premium card style with multi-layer shadow */
.premium-card, .section, .section-box, .prof-stat, .onq-stat {
    transition: box-shadow var(--transition), transform var(--transition);
}
.premium-card:hover, .section:hover {
    box-shadow: var(--shadow-md);
}

/* Smooth scroll in main content */
.main-area { scroll-behavior: smooth; }

/* Better link underlines */
a { text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* Subtle text selection */
::selection { background: rgba(91,93,240,0.15); color: inherit; }

/* Premium button base */
button, .sbtn, .btn {
    font-family: inherit;
    letter-spacing: -0.01em;
    transition: all var(--transition);
}
button:active, .sbtn:active { opacity: 0.85; }

/* Smoother scrollbars (webkit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Data table premium styling */
.data-table, .onq-table {
    border-collapse: separate;
    border-spacing: 0;
}
.data-table th, .onq-table th {
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.65rem;
}
.data-table tr:hover td, .onq-table tr:hover td {
    background: rgba(91,93,240,0.03);
}

/* KPI stat cards — bigger impact */
.hero-grid .stat-card, .prof-stats .prof-stat, .onq-stats .onq-stat {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}
.hero-grid .stat-card:hover, .prof-stats .prof-stat:hover {
    box-shadow: var(--shadow-md);
}

/* Badge improvements */
.sp-badge, .badge-channel, .badge-bucket {
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: opacity var(--transition);
}

/* Page entry — subtle, no bouncy slide */
.main-content { animation: fadeIn 0.2s ease-out both; }
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Nav divider refinement */
.nav-divider span {
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 700;
    opacity: 0.5;
}

/* Dark theme card hover — no glow, just deeper shadow */
[data-theme="dark"] .section:hover,
[data-theme="dark"] .premium-card:hover {
    box-shadow: var(--shadow-lg);
}

/* Logo refinement */
.logo-text {
    letter-spacing: -0.02em;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 600px) {
    .container { padding: 1rem; }
    .field-row { flex-direction: column; gap: 0.8rem; }
    .stats-bar { flex-direction: column; }
    .case-header { font-size: 0.82rem; }
    .actions-section { flex-direction: column; }
    .hero-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .data-table { font-size: 0.7rem; }
    .data-table th, .data-table td { padding: 0.35rem 0.4rem; }
}

/* ─────────────────────────────────────────────────────────────────────
   Property-health badge (topbar)
   Shows connected/total data sources; only renders when < green.
   ───────────────────────────────────────────────────────────────────── */
.health-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-decoration: none;
    flex-shrink: 0;
    min-height: 30px;
    transition: background 0.15s, transform 0.15s;
    cursor: pointer;
}
.health-badge:hover { transform: translateY(-1px); }
.health-badge:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.health-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    animation: health-pulse 2s ease-in-out infinite;
}
@keyframes health-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
.health-amber {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.health-amber .health-dot { background: #f59e0b; }
.health-red {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.health-red .health-dot { background: #ef4444; }
@media (max-width: 600px) {
    .health-badge .health-label { display: none; }
    .health-badge { padding: 0.28rem 0.4rem; }
}

/* ─────────────────────────────────────────────────────────────────────
   Shared empty-state component (see templates/_empty_state.html)
   ───────────────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    max-width: 460px;
    margin: 2.5rem auto;
    border: 1px dashed var(--border, rgba(148, 163, 184, 0.35));
    border-radius: 14px;
    background: var(--card, #fff);
}
[data-theme="dark"] .empty-state {
    background: var(--card, #1e293b);
    border-color: rgba(255, 255, 255, 0.1);
}
.empty-icon {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 1rem;
    opacity: 0.6;
}
.empty-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 0.4rem 0;
    color: var(--text, #0f172a);
}
[data-theme="dark"] .empty-title { color: var(--text, #e2e8f0); }
.empty-body {
    color: var(--text2, #64748b);
    font-size: 0.92rem;
    line-height: 1.5;
    margin: 0 auto 1.2rem auto;
    max-width: 360px;
}
.empty-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}
.empty-cta {
    padding: 0.55rem 1.2rem;
    background: var(--accent, #6366f1);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.15s;
}
.empty-cta:hover {
    background: var(--accent-hover, #4f46e5);
}
.empty-cta:focus-visible {
    outline: 2px solid var(--accent, #6366f1);
    outline-offset: 3px;
}
.empty-skip {
    color: var(--text2, #64748b);
    font-size: 0.85rem;
    text-decoration: underline;
}
.empty-skip:hover { color: var(--text, #0f172a); }
[data-theme="dark"] .empty-skip:hover { color: var(--text, #e2e8f0); }
