/* LiveStats Viewer - Matches Input Console Design */

/* Theme Variables - Default (Light Theme) */
:root {
    /* Light Theme Colors (from Landing Page) */
    --primary: #2563eb;
    --on-primary: #ffffff;
    --primary-soft: #e0f2fe;
    --primary-bright: #3b82f6;
    --primary-dark: #1e40af;
    --primary-shadow: rgba(37, 99, 235, 0.2);
    
    --bg: #f1f5f9; /* Slightly darker than pure white for contrast */
    --bg-soft: rgba(255, 255, 255, 0.8); /* Semi-transparent for glass effect */
    --card: #ffffff;
    --muted: #64748b;
    --border: #cbd5e1; /* Slightly darker border for definition */
    --text-primary: #0f172a;
    --text-secondary: #334155;
    
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Console Theme Colors */
    --brand-red: #dc2626;
    --accent-green: #10b981;
    --accent-blue: #3b82f6;
    --accent-amber: #f59e0b;
    --accent-purple: #a855f7;
    --accent-teal: #14b8a6;
}

/* Dark Theme Override */
[data-theme="dark"] {
    --primary: #475569; /* darker neutral */
    --on-primary: #ffffff;
    --primary-soft: #32405a;
    --primary-bright: #7b8aa1;
    --primary-dark: #1f2b3a;
    --primary-shadow: rgba(71, 85, 105, 0.45);
    --bg: #020617;
    --bg-soft: #0f172a;
    --card: #1e293b;
    --muted: #94a3b8;
    --border: rgba(55, 65, 81, 0.8);
    --text-primary: #f9fafb;
    --text-secondary: #94a3b8;
    
    --shadow-sm: none;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    min-height: 100%;
    margin: 0;
    overscroll-behavior-y: none; /* Prevent rubber-banding/bounce on mobile */
}

html {
    background-color: var(--bg); /* Ensure background color fills viewport */
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    /* Subtle dot pattern for character in light mode */
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    transition: background-color 0.3s, color 0.3s;
}

body[data-theme="dark"] {
    background-image: none; /* Remove pattern in dark mode */
    background-color: var(--bg);
    position: relative; /* Ensure pseudo-element positioning context if needed, though fixed is viewport relative */
}

body[data-theme="dark"]::before {
    content: "";
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100vh;
    background: radial-gradient(circle at top left, var(--primary-soft), var(--bg));
    z-index: -1;
    pointer-events: none;
    transform: translateZ(0);
    will-change: transform;
}

/* Header Styles Update for Light Theme */
header {
    background: rgba(248, 250, 252, 0.85); /* Semi-transparent for glass effect */
    backdrop-filter: blur(12px); /* Glassmorphism */
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 0.5rem 2rem;
    transition: background-color 0.3s, border-color 0.3s;
    position: sticky;
    top: 0;
    z-index: 100;
}

[data-theme="dark"] header {
    background: #1e293b; /* Keep original dark header */
    backdrop-filter: none;
    border-bottom: 1px solid var(--brand-red);
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.15);
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand img {
    height: 90px;
    width: auto;
    max-height: 100%;
}

.brand-text h1 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.1;
    margin: 0;
}

.brand-text p {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin: 0;
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Card Styles Update */
.org-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 2rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    gap: 1rem;
}

.org-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.org-logo-img {
    height: 80px;
    width: auto;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

.org-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

[data-theme="dark"] .org-card, 
[data-theme="dark"] .event-card, 
[data-theme="dark"] .class-card,
[data-theme="dark"] .stat-box {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.app-shell { flex:1; display:flex; flex-direction:column; }

.app-footer { margin-top:auto; }

/* Header - Removed duplicate styles */
header > div {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

@media (max-width: 1024px) {
    header {
        position: relative;
        box-shadow: none;
        border-bottom-width: 1px;
        background: var(--bg);
        border-bottom-color: var(--border);
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        transform: translateZ(0);
    }
    header:before {
        display: none;
    }
}
header:before {
    content: "";
    position: absolute;
    inset: 0 0 0 0;
    pointer-events: none;
    background: radial-gradient(circle at 8% 50%, rgba(220,38,38,0.25), transparent 70%);
    mix-blend-mode: overlay;
}

header > div {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand img {
    height: 32px;
    width: auto;
    display: block;
}

.header-context {
    margin-top: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--brand-red);
    background: rgba(220,38,38,0.1);
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid rgba(220,38,38,0.35);
    box-shadow: 0 0 0 1px rgba(220,38,38,0.25) inset, 0 2px 6px -2px rgba(0,0,0,0.6);
    max-width: 420px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

header h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--on-primary);
}

header p {
    margin: 3px 0 0;
    font-size: 0.85rem;
    opacity: 0.95;
    color: var(--on-primary);
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.btn-icon {
    background: rgba(15,23,42,0.3);
    border: 1px solid rgba(248,250,252,0.2);
    color: var(--on-primary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-icon:hover {
    background: rgba(15,23,42,0.5);
    transform: translateY(-1px);
}

/* Main Layout */
.app-shell {
    max-width: 1840px;
    margin: 0 auto;
    padding: 20px 32px 48px;
    width: 100%;
    flex: 1;
    transform: translateZ(0);
    will-change: transform;
}

/* Search & Filters */
.controls {
    background: var(--card);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.search-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.1);
}

.filter-tabs {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-tab {
    padding: 10px 20px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s;
    min-width: 100px;
    text-align: center;
}

.filter-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(71, 85, 105, 0.1);
}

.filter-tab.active {
    background: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(71, 85, 105, 0.4);
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
    font-weight: 600;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-sublabel {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
}

/* Color Utilities */
.text-green { color: var(--accent-green) !important; }
.text-amber { color: var(--accent-amber) !important; }
.text-red { color: var(--brand-red) !important; }
.text-blue { color: var(--accent-blue) !important; }
.text-purple { color: var(--accent-purple) !important; }
.text-teal { color: var(--accent-teal) !important; }

/* Page Header */
.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Event Grid */
.event-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.event-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.event-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--primary-bright));
    opacity: 0;
    transition: opacity 0.3s;
}

.event-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 12px 24px var(--primary-shadow);
}

.event-card:hover::before {
    opacity: 1;
}

.event-status {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Class Grid */
.class-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.class-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.status-live { 
    background: rgba(239, 68, 68, 0.2); 
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.status-upcoming { 
    background: rgba(59, 130, 246, 0.2); 
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.4);
}

.status-completed { 
    background: rgba(16, 185, 129, 0.2); 
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.event-org {
    font-size: 0.8rem;
    color: var(--primary-bright);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.event-name {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.3;
    color: var(--text-primary);
}

.event-date {
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.event-date span {
    font-size: 1rem;
}

/* Event Detail View */
.event-detail-container {
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.event-detail-header {
    background: linear-gradient(135deg, var(--primary-soft), var(--primary));
    padding: 32px;
    border-bottom: 1px solid var(--border);
}

.event-detail-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--on-primary);
}

.event-detail-meta {
    display: flex;
    gap: 24px;
    color: rgba(255,255,255,0.9);
    font-size: 0.95rem;
}

.event-detail-meta span {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 16px 24px;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 0.95rem;
}

.tab:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.02);
}

.tab.active {
    color: var(--primary-bright);
    border-bottom-color: var(--primary);
    background: rgba(100, 116, 139, 0.05);
}

.tab-content {
    display: none;
    padding: 24px;
}

.tab-content.active {
    display: block;
}

/* Data Table */
.table-container {
    overflow-x: auto;
    margin-top: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table thead {
    background: var(--bg-soft);
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th {
    text-align: left;
    padding: 14px 16px;
    color: var(--text-secondary);
    font-weight: 700;
    border-bottom: 2px solid var(--border);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.data-table tbody tr {
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: rgba(100, 116, 139, 0.05);
}

/* Place Badge */
.place-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.9rem;
}

.place-1 {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #78350f;
}

.place-2 {
    background: linear-gradient(135deg, #cbd5e1, #94a3b8);
    color: #1e293b;
}

.place-3 {
    background: linear-gradient(135deg, #fb923c, #ea580c);
    color: #7c2d12;
}

.place-other {
    background: var(--bg-soft);
    color: var(--text-secondary);
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Back Button */
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    margin-bottom: 24px;
    cursor: pointer;
}

.btn-back:hover {
    background: var(--card);
    border-color: var(--primary);
    transform: translateX(-4px);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

/* Results Grid - 2 columns */
.results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-top: 24px;
}

.class-result-card {
    background: linear-gradient(145deg, rgba(30,41,59,1) 0%, rgba(15,23,42,1) 60%) padding-box;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 26px 18px 26px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    position: relative;
    transition: border-color .18s, background .18s, transform .18s, box-shadow .18s;
    overflow: hidden;
}
.class-result-card:before {
    content:"";
    position:absolute; left:0; top:0; bottom:0; width:5px;
    background:linear-gradient(to bottom, var(--brand-red), #7f1d1d);
    box-shadow:0 0 10px rgba(220,38,38,0.45);
}
.class-result-card:hover {
    border-color: var(--primary-bright);
    transform: translateY(-4px);
    box-shadow: 0 10px 28px -6px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.03);
}
.class-result-card.dq {
    border-color: var(--brand-red);
    background: linear-gradient(145deg, rgba(60,8,8,0.9) 0%, rgba(120,20,20,0.35) 55%, rgba(15,23,42,0.85) 100%);
}

/* Footer */
.app-footer {
    width:100%;
    background: var(--card); /* White background to stand out */
    border-top: 1px solid var(--border);
    padding: 32px 0; /* More breathing room */
    box-shadow: 0 -4px 20px rgba(0,0,0,0.03); /* Subtle lift */
    margin-top: 40px;
    transition: background-color 0.3s, border-color 0.3s;
    position: relative;
}

/* Add a colorful top border strip */
.app-footer::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary), var(--primary));
    opacity: 0.7;
}

[data-theme="dark"] .app-footer {
    background: linear-gradient(135deg,#0f172a,#1e293b);
    border-top: none; /* The pseudo-element handles the top border visual */
    box-shadow: 0 -6px 18px -4px rgba(0,0,0,0.6);
}

[data-theme="dark"] .app-footer::before {
    background: linear-gradient(90deg, var(--brand-red), #7f1d1d, var(--brand-red));
    height: 2px;
}

.footer-inner {max-width:1600px;margin:0 auto;padding:0 24px;display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:16px;}
.footer-brand {display:flex;flex-direction:column;gap:4px;}
.footer-logo {font-weight:700;letter-spacing:.5px;color:var(--primary-bright);}
.footer-tag {font-size:.7rem;text-transform:uppercase;letter-spacing:1.5px;color:var(--muted);}
.footer-links {display:flex;align-items:center;gap:8px;font-size:.75rem;color:var(--muted);}
.footer-links a {color:var(--text-primary);text-decoration:none;font-weight:600;}
.footer-links a:hover {color:var(--primary-bright);}
.footer-links .sep {opacity:.5;}

.entry-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-card .data-table {
    font-size: 0.85rem;
}

.result-card .data-table th {
    padding: 10px 12px;
    font-size: 0.75rem;
}

.result-card .data-table td {
    padding: 10px 12px;
}

/* --- Navigation & Tree View Styles --- */

.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--muted);
}
.breadcrumbs a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 3px 7px;
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(2px);
    transition: all 0.15s;
    display:inline-flex;
    align-items:center;
    gap:4px;
}
.breadcrumbs a:hover {
    background: rgba(220,38,38,0.15);
    color: var(--text-primary);
    border-color: var(--brand-red);
}
.header-breadcrumbs { margin-top:8px; }
.header-breadcrumbs .crumb-active { background: var(--brand-red); color:#fff; border-color: var(--brand-red); }

.search-container {
    position: relative;
    min-width: 250px;
}

.search-container input {
    width: 100%;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.search-container input:focus {
    outline: none;
    border-color: var(--primary-bright);
    box-shadow: 0 0 0 3px rgba(123, 138, 161, 0.2);
    background: var(--card);
}

.search-container::after {
    content: '🔍';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    opacity: 0.5;
    pointer-events: none;
}

.crumb.link {
    color: var(--primary-bright);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.crumb.link:hover {
    color: var(--on-primary);
}

.crumb.active {
    color: var(--text-primary);
    font-weight: 600;
}

.separator {
    opacity: 0.5;
}

/* Org Grid */
.org-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 18px;
}

.org-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.org-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.org-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
}

.org-logo-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 16px;
    border-radius: 8px;
}

.org-card h3 {
    margin: 0 0 8px;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.org-card-hint {
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

/* Org Detail */
.org-header, .event-header, .results-header {
    margin-bottom: 32px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 24px;
}

.org-header h2, .event-header h2, .results-header h2 {
    font-size: 2rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}


/* Latest Event Bar - Discrete Navigation */
.latest-event-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 20px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.latest-event-bar:hover {
    border-color: var(--text-muted);
    background: var(--bg-soft);
}
.leb-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 0.7;
}
.leb-name {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}
.leb-date {
    font-size: 13px;
    color: var(--text-secondary);
}
.leb-arrow {
    font-size: 18px;
    color: var(--text-secondary);
    opacity: 0.6;
    transition: transform 0.2s, opacity 0.2s;
}
.latest-event-bar:hover .leb-arrow {
    opacity: 1;
    transform: translateX(3px);
}
@media (max-width: 600px) {
    .latest-event-bar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
    .leb-label { width: 100%; margin-bottom: 2px; }
}
.org-meta, .event-header p, .results-header p {
    color: var(--muted);
    display: flex;
    gap: 16px;
    font-size: 1rem;
}

.section-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-bright);
    margin: 32px 0 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.section-lede {
    margin: 32px 0 12px;
}

.section-lede h2 {
    margin: 0;
    font-size: 1.4rem;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.section-lede p {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.event-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.event-item:hover {
    background: var(--bg-soft);
    border-color: var(--primary);
}

.event-item.canceled {
    border-color: rgba(220, 38, 38, 0.4);
    background: rgba(220, 38, 38, 0.08);
    cursor: default;
}

.event-item.canceled:hover {
    background: rgba(220, 38, 38, 0.12);
    border-color: rgba(220, 38, 38, 0.6);
}

.event-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 18px;
}

.event-chip.canceled {
    background: rgba(220, 38, 38, 0.18);
    border-color: rgba(220, 38, 38, 0.4);
    color: #fca5a5;
}

.event-item.canceled .event-action {
    color: rgba(220, 38, 38, 0.9);
}

.event-date {
    font-family: monospace;
    color: var(--primary-bright);
    font-weight: 600;
    min-width: 100px;
}

.event-info h4 {
    margin: 0 0 4px;
    color: var(--text-primary);
}

.event-info p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.event-action {
    margin-left: auto;
    opacity: 0.5;
}

.event-chip {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    border-radius: 999px;
    padding: 2px 8px;
    margin-left: 8px;
    font-weight: 700;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.event-card, .class-card, .stat-box {
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: var(--text-primary);
}

.class-card:hover {
    background: var(--primary-dark);
    border-color: var(--primary);
}

.class-card h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.class-card p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--primary-bright);
}

/* Empty States */
.empty-state, .empty-msg {
    color: var(--muted);
    font-style: italic;
    padding: 20px;
    text-align: center;
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
}

/* --- Stats Dashboard Styles --- */

.stats-dashboard {
    background: var(--card); /* Use theme card background */
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 28px;
    box-shadow: var(--shadow);
    /* Add a subtle top accent for character */
    border-top: 4px solid var(--primary);
}

[data-theme="dark"] .stats-dashboard {
    background: #0f172a; /* Darker background for stats area in dark mode */
    box-shadow: 0 15px 30px rgba(0,0,0,0.35);
    border-top: none; /* Remove accent in dark mode if preferred, or keep it */
}

.global-stats-wrapper {
    margin-bottom: 30px;
}

.stat-section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.25em;
    color: var(--muted);
    margin: 16px 0 8px;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
}

.stats-title-group {
    display: flex;
    flex-direction: column;
}

.stats-title-group h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-title-group .subtitle {
    color: var(--primary-bright);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 4px;
}

.stats-logo {
    height: 60px;
    width: auto;
    opacity: 0.8;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.stat-box {
    background: var(--bg-soft); /* Contrast against white dashboard */
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-box:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--primary-light);
}

.stat-box::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px; /* Slightly thicker accent */
    background: linear-gradient(90deg, transparent, var(--primary), transparent); /* Use primary color */
    opacity: 0.5;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-sublabel {
    font-size: 0.65rem;
    color: var(--muted);
    margin-top: 4px;
}

/* Highlight Box (e.g. Winner) */
.stat-box.highlight {
    grid-column: span 2; /* Make it wider if grid allows */
    background: var(--card);
    border-left: 4px solid var(--brand-red); /* Red accent */
    align-items: flex-start;
    text-align: left;
    padding-left: 24px;
}

.stat-box.highlight .stat-label {
    color: #ef4444;
    margin-bottom: 4px;
}

.stat-box.highlight .stat-value {
    font-size: 2rem;
}

.stat-box.highlight .stat-sublabel {
    font-size: 1rem;
    color: #fff;
}

/* Responsive adjustments for stats */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .stat-box.highlight {
        grid-column: span 2;
    }
    .stat-value {
        font-size: 2rem;
    }
}

/* Vehicle Card */
.vehicle-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
}

.vehicle-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-bright);
}

.vehicle-card-header {
    background: linear-gradient(to right, var(--bg-soft), var(--card));
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.vehicle-rank {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--muted);
    opacity: 0.3;
    position: absolute;
    top: 12px;
    right: 16px;
}

.vehicle-card-body {
    padding: 12px;
}

.vehicle-name-large {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
    padding-right: 40px; /* Space for rank */
}

.vehicle-driver-large {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.vehicle-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    background: var(--bg-soft);
    border-radius: 8px;
    padding: 12px;
}

[data-theme="dark"] .vehicle-stats-row {
    background: rgba(0,0,0,0.2);
}

.v-stat {
    text-align: center;
    padding: 4px 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.v-stat-val {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.v-stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--muted);
    margin-top: 2px;
    line-height: 1;
}

/* Log Card Styling */
.log-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.log-card:hover {
    background: var(--bg-soft);
}

.log-info h4 {
    margin: 0 0 4px 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.log-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    gap: 8px;
    align-items: center;
}

.log-stats {
    text-align: right;
}

.log-dist {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-bright);
}

.log-place {
    font-size: 0.75rem;
    background: var(--bg-soft);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--muted);
    display: var(--muted);
    margin-top: 4px;
}

/* =====================================================
   Class Result Row Cards (full-width, flex layout)
   ===================================================== */
.class-results-grid { /* override only for class results */
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.class-result-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 22px 16px 22px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    position: relative;
    transition: border-color .15s, background .15s;
}

.class-result-card:hover {
    border-color: var(--primary-bright);
    background: var(--bg-soft);
}

.class-result-card.dq {
    border-color: var(--brand-red);
    background: linear-gradient(90deg, rgba(220,38,38,0.12), rgba(220,38,38,0.05) 55%, transparent 100%);
}

/* Rank column */
.cr-left { width: 70px; flex: 0 0 70px; display:flex; justify-content:center; }
.cr-rank {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -1px;
    color: var(--text-muted);
    opacity: .45;
}
.class-result-card.dq .cr-rank { color: var(--brand-red); opacity: .55; text-decoration: line-through; }

/* Main info */
.cr-main { flex: 1 1 auto; display:flex; flex-direction:column; gap:4px; }
.cr-vehicle { font-size: 1.35rem; font-weight: 800; letter-spacing: -.5px; color: var(--text-primary); }
.cr-make { font-size:.65rem; font-weight:700; letter-spacing:1.5px; text-transform:uppercase; color: var(--text-secondary); }
.cr-driver { font-size:.85rem; color: var(--text-secondary); display:flex; align-items:center; gap:6px; }

/* Stats cluster */
.cr-stats { flex: 0 0 auto; min-width:220px; display:flex; flex-direction:column; align-items:flex-end; gap:6px; text-align:right; }
.cr-dist { font-size:1.55rem; font-weight:800; color: var(--primary-bright); line-height:1; }
.class-result-card.dq .cr-dist { color: var(--text-secondary); text-decoration: line-through; opacity:.6; }
.cr-speed { font-size:.8rem; font-weight:600; color: var(--accent-blue); letter-spacing:.5px; }
.cr-points { font-size:.75rem; font-weight:700; color: var(--accent-green); background: rgba(16,185,129,.12); padding:4px 8px; border-radius:6px; }

/* Podium tweak (color accent) */
.class-result-card .cr-rank.rank-1 { color:#FFD700; opacity:.7; text-shadow:0 0 12px rgba(255,215,0,.35); }
.class-result-card .cr-rank.rank-2 { color:#C0C0C0; opacity:.65; }
.class-result-card .cr-rank.rank-3 { color:#CD7F32; opacity:.65; }

@media (max-width: 900px) {
  .class-result-card { flex-direction: column; align-items: flex-start; }
  .cr-left { width:auto; flex:none; }
  .cr-rank { font-size:1.8rem; margin-bottom:6px; }
  .cr-stats { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; min-width:unset; width:100%; gap:14px; margin-top:8px; }
  .cr-stats > div { text-align:left; }
}


/* Responsive */
@media (max-width: 1024px) {
    /* Slim down header for tablets */
    header {
        padding: 10px 0 8px;
    }
    header h1 {
        font-size: 1.15rem;
    }
    header p {
        font-size: 0.8rem;
    }
    .header-context {
        font-size: 0.68rem;
        padding: 3px 7px;
    }
    .brand img {
        height: 26px;
    }
}

@media (max-width: 768px) {
    /* Slim down header for mobile */
    header {
        padding: 8px 0 6px;
        border-bottom-width: 1px;
    }
    header > div {
        flex-direction: column;
        gap: 6px;
        text-align: center;
        padding: 0 12px;
    }
    header h1 {
        font-size: 1rem;
    }
    header p {
        font-size: 0.7rem;
        margin-top: 1px;
    }
    .header-context {
        font-size: 0.6rem;
        padding: 2px 5px;
        margin-top: 3px;
        max-width: 260px;
        letter-spacing: 0.5px;
    }
    .brand {
        justify-content: center;
        gap: 6px;
    }
    .brand img {
        height: 20px;
    }
    .header-actions {
        gap: 6px;
    }
    .btn-icon {
        padding: 5px 10px;
        font-size: 0.75rem;
    }
    
    .app-shell {
        padding: 16px;
    }
    
    .event-grid {
        grid-template-columns: 1fr;
    }
    
    .results-grid, .class-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-bar {
        grid-template-columns: 1fr;
    }
    
    .filter-tabs {
        justify-content: center;
    }
}

/* Event About / Countdown Page */
.event-about-container {
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease-out;
}

.event-about-header {
    text-align: center;
    margin-bottom: 2rem;
}

.event-about-header .org-badge {
    display: inline-block;
    background: var(--primary-soft);
    color: var(--primary-dark);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.event-about-header h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    line-height: 1.2;
    background: linear-gradient(135deg, var(--text-primary), var(--primary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.event-meta-large {
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.event-about-body {
    display: grid;
    gap: 2rem;
}

.status-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: var(--shadow);
}

.status-card h2 {
    font-size: 1.8rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.countdown-box {
    background: var(--bg);
    border: 2px solid var(--primary);
    border-radius: 1rem;
    padding: 2rem;
    display: inline-block;
    min-width: 200px;
}

.countdown-val {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 0.5rem;
}

.countdown-label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-secondary);
    font-weight: 600;
}

.info-box {
    background: var(--bg-soft);
    padding: 2rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
}

.about-details {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
}

.about-details h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-item .label {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}

.detail-item .value {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.ad-placeholder {
    margin-top: 3rem;
    text-align: center;
    opacity: 0.5;
}

/* Footer from Home Page */
.footer {
    margin-top: auto;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}

