/* ===== CSS Variables ===== */
:root {
    /* Colors - Light Theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --accent-primary: #0ea5e9;
    --accent-secondary: #06b6d4;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    
    /* Podium Colors */
    --gold: #fbbf24;
    --silver: #9ca3af;
    --bronze: #d97706;
    
    /* Typography */
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Dark Mode */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

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

/* ===== App Container ===== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 100%;
}

/* ===== Header ===== */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--accent-primary);
}

.logo-text {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

/* Hide logo text on very small screens */
@media (max-width: 380px) {
    .logo-text {
        display: none;
    }
}

.event-name {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

@media (min-width: 480px) {
    .event-name {
        font-size: 0.875rem;
    }
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.theme-toggle:hover,
.theme-toggle:active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.theme-toggle .moon-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: block;
}

/* Message Bar */
.message-bar {
    display: none;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
}

.message-bar.active {
    display: flex;
}

.message-icon {
    flex-shrink: 0;
}

.message-text {
    overflow: hidden;
    white-space: nowrap;
    animation: marquee 15s linear infinite;
}

@keyframes marquee {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

/* ===== Navigation Tabs ===== */
.nav-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: var(--space-md) var(--space-sm);
    min-height: 70px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    transition: var(--transition-fast);
    position: relative;
}

.tab svg {
    width: 24px;
    height: 24px;
}

.tab:hover {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.tab.active {
    color: var(--accent-primary);
    background: rgba(14, 165, 233, 0.05);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-primary);
}

.live-dot {
    position: absolute;
    top: 12px;
    right: 20%;
    width: 10px;
    height: 10px;
    background: var(--accent-danger);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* ===== Run Indicator ===== */
.run-indicator {
    display: flex;
    justify-content: center;
    padding: var(--space-sm);
    background: var(--bg-tertiary);
}

.run-indicator span {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

#currentRun {
    color: var(--accent-primary);
}

/* ===== Main Content ===== */
.content {
    flex: 1;
    padding: var(--space-md);
    padding-bottom: 80px; /* Space for status bar */
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

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

/* ===== Sections ===== */
.section {
    margin-bottom: var(--space-lg);
}

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

.section-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    font-size: 1rem;
}

.section-icon.start { background: #dbeafe; }
.section-icon.course { background: #fef3c7; }
.section-icon.finish { background: #d1fae5; }
.section-icon.podium { background: #fef3c7; }
.section-icon.results { background: #e0e7ff; }
.section-icon.startlist { background: #f3e8ff; }

.section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.category-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}

/* ===== Athlete Cards ===== */
.athletes-list, .ranking-list, .startlist-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.athlete-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--transition-fast);
}

.athlete-card:hover {
    box-shadow: var(--shadow-md);
}

.athlete-card.highlight {
    border-color: var(--accent-primary);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.05), rgba(6, 182, 212, 0.05));
    animation: highlightPulse 0.5s ease;
}

@keyframes highlightPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.01); }
}

/* Bib Number */
.bib {
    min-width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

/* Athlete Info */
.athlete-info {
    flex: 1;
    min-width: 0;
}

.athlete-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.athlete-details {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.athlete-club {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    color: var(--text-secondary);
    font-weight: 500;
}

.athlete-category {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    width: fit-content;
}

/* Time Display */
.time-display {
    text-align: right;
    flex-shrink: 0;
}

.time-value {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--text-primary);
}

.time-gap {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-danger);
}

/* Rank Display */
.rank-display {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: #422006;
    border-radius: 50%;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

/* On Course Card - Running Animation */
.athlete-card.on-course .bib {
    background: linear-gradient(135deg, var(--accent-warning), #f97316);
    color: white;
    animation: bibPulse 1.5s ease infinite;
}

@keyframes bibPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
}

/* ===== Podium Section ===== */
.podium-section {
    background: linear-gradient(135deg, #fefce8, #fef9c3);
    margin: 0 calc(-1 * var(--space-md));
    padding: var(--space-lg) var(--space-md);
    border-radius: 0;
}

.podium-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.podium-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.podium-card.gold {
    border-left: 4px solid var(--gold);
}

.podium-card.silver {
    border-left: 4px solid var(--silver);
}

.podium-card.bronze {
    border-left: 4px solid var(--bronze);
}

.podium-rank {
    font-size: 1.5rem;
    width: 40px;
    text-align: center;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ===== Biathlon Penalties ===== */
.penalties,
.penalties-live {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    flex-wrap: wrap;
}

/* Compact penalties for on-course and finished cards */
.penalties-compact {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.penalty-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: var(--accent-success);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: white;
}

.penalty-dot.has-penalty {
    background: var(--accent-danger);
    color: white;
}

.penalty-sum {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-danger);
    margin-left: 0.25rem;
}

/* Compact inter times for finished cards */
.inter-compact {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.inter-dot {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

/* On course status */
.on-course-status {
    font-size: 1.25rem;
}

.penalty-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.penalty-label {
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 0.625rem;
}

.penalty-value {
    color: var(--text-secondary);
    font-weight: 600;
}

.penalty-total {
    color: var(--accent-danger);
    font-weight: 700;
    margin-left: 0.25rem;
}

.penalty-box {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.penalty-box.has-penalty {
    background: var(--accent-danger);
    color: white;
}

.penalty-total-live {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Ski time (biathlon - time without penalties) */
.ski-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ===== Status Bar ===== */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
    z-index: 100;
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected {
    background: var(--accent-success);
}

.status-dot.error {
    background: var(--accent-danger);
}

.refresh-timer {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.refresh-timer svg {
    width: 14px;
    height: 14px;
}

/* ===== Responsive - Tablet and Desktop ===== */
@media (min-width: 640px) {
    .content {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .event-name {
        max-width: 300px;
    }
    
    .tab {
        flex-direction: row;
        gap: var(--space-sm);
        font-size: 1rem;
        min-height: 56px;
    }
    
    .nav-tabs {
        max-width: 600px;
        margin: 0 auto;
    }
}

@media (min-width: 1024px) {
    .content {
        max-width: 800px;
    }
    
    .header-content {
        max-width: 800px;
        margin: 0 auto;
    }
    
    .nav-tabs {
        max-width: 800px;
        margin: 0 auto;
    }
    
    .status-bar {
        max-width: 800px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
}

/* ===== Dark Mode Support (Optional) ===== */
@media (prefers-color-scheme: dark) {
    /* Uncomment to enable auto dark mode
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #64748b;
        --border-color: #334155;
    }
    */
}

/* ===== Intermediate Times ===== */
.inter-times {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    margin-top: 0.25rem;
    font-family: var(--font-mono);
    flex-wrap: wrap;
}

.inter-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.inter-label {
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 0.625rem;
}

.inter-time {
    color: var(--text-secondary);
}

.inter-gap {
    color: var(--accent-danger);
    font-size: 0.6875rem;
}

/* Inter time on course (large display) */
.inter-time-live {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--accent-warning);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.125rem;
}

.inter-time-live .inter-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.inter-time-live .inter-label {
    font-size: 0.625rem;
    color: var(--text-muted);
}

/* Run 1 info display */
.run1-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 0.25rem;
}

/* Run 2 time in results */
.run2-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ===== Run Selector ===== */
#runSelectorContainer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.run-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.run-badge:hover {
    color: var(--text-secondary);
    border-color: var(--accent-primary);
}

.run-badge.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* Hide run selector in live view, show in results */
.view#liveView .run-badge:not(.active) {
    display: none;
}

/* ===== Category Tabs ===== */
.category-tabs {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.category-tab {
    flex-shrink: 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.category-tab:hover {
    background: var(--border-color);
}

.category-tab.active {
    background: var(--accent-primary);
    color: white;
}

/* ===== Status Indicators ===== */
.status-dnf, .status-dns, .status-dsq {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
}

.status-dnf {
    background: #fef2f2;
    color: var(--accent-danger);
}

.status-dns {
    background: #fefce8;
    color: var(--accent-warning);
}

.status-dsq {
    background: #fef2f2;
    color: var(--accent-danger);
}

/* ===== Start Order Badge ===== */
.start-order {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.start-order::before {
    content: '#';
}
