/* ============================================
   DTTime - Public Live Results Styles
   ============================================ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --accent: #f59e0b;
    --danger: #ef4444;
    
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1a2e 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

a {
    color: var(--primary-light);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary);
}

/* Layout */
.public-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.public-header {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-md) var(--spacing-xl);
}

.public-header .header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.header-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    padding-left: var(--spacing-lg);
    border-left: 1px solid var(--border-color);
}

/* Main Content */
.public-main {
    flex: 1;
    padding: var(--spacing-xl);
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Race Selection */
.race-selection {
    text-align: center;
}

.race-selection h1 {
    font-size: 2rem;
    margin-bottom: var(--spacing-xl);
}

.race-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    margin-top: var(--spacing-xl);
}

.race-card {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    transition: all var(--transition-normal);
    color: var(--text-primary);
}

.race-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.race-card-icon {
    font-size: 2.5rem;
    opacity: 0.8;
}

.race-card-content h3 {
    font-size: 1.125rem;
    margin-bottom: var(--spacing-xs);
}

.race-org {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.race-date {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: var(--spacing-xs);
}

/* Results Container */
.results-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.back-link {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.back-link:hover {
    color: var(--primary-light);
}

.results-header h1 {
    font-size: 1.25rem;
    margin-bottom: 0;
    line-height: 1.2;
}

.race-meta {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Live Indicator */
.live-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.live-indicator .status-time {
    margin-left: var(--spacing-xs);
    font-family: 'Courier New', monospace;
}

.live-indicator.status-stopped {
    background: rgba(158, 158, 158, 0.15);
    border-color: #9e9e9e;
    color: #9e9e9e;
}

.live-indicator.status-stopped .live-dot {
    background: #9e9e9e;
    animation: none;
}

.live-indicator.status-warmup {
    background: rgba(156, 39, 176, 0.15);
    border-color: #9c27b0;
    color: #9c27b0;
}

.live-indicator.status-warmup .live-dot {
    background: #9c27b0;
}

.live-indicator.status-running {
    background: rgba(76, 175, 80, 0.15);
    border-color: #4caf50;
    color: #4caf50;
}

.live-indicator.status-running .live-dot {
    background: #4caf50;
}

.live-indicator.status-yellow {
    background: rgba(251, 192, 45, 0.15);
    border-color: #fbc02d;
    color: #fbc02d;
}

.live-indicator.status-yellow .live-dot {
    background: #fbc02d;
}

.live-indicator.status-red {
    background: rgba(244, 67, 54, 0.15);
    border-color: #f44336;
    color: #f44336;
}

.live-indicator.status-red .live-dot {
    background: #f44336;
}

.live-indicator.status-finished {
    background: rgba(255, 255, 255, 0.1);
    border-color: #ffffff;
    color: #ffffff;
}

.live-indicator.status-finished .live-dot {
    background: #ffffff;
    animation: none;
}

.live-dot {
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Heat Tabs */
.heat-tabs {
    display: flex;
    gap: var(--spacing-xs);
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.heat-tab {
    padding: var(--spacing-sm) var(--spacing-lg);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.heat-tab:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}

.heat-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Results Table */
.results-table-container {
    overflow-x: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
}

.results-table th {
    background: var(--bg-dark);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: var(--spacing-md) var(--spacing-lg);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

.results-table td {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table tr:hover td {
    background: rgba(99, 102, 241, 0.05);
}

.results-table .pos {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--primary-light);
    width: 50px;
}

.results-table tr:nth-child(1) .pos { color: #ffd700; }
.results-table tr:nth-child(2) .pos { color: #c0c0c0; }
.results-table tr:nth-child(3) .pos { color: #cd7f32; }

.results-table .number {
    font-weight: 700;
    font-size: 1rem;
    background: var(--bg-hover);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    display: inline-block;
    min-width: 40px;
    text-align: center;
}

.results-table .name {
    font-weight: 600;
}

.results-table .time {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
}

.results-table .time.best {
    color: var(--secondary);
    font-weight: 600;
}

.results-table .laps {
    font-weight: 600;
    font-size: 1rem;
}

.class-badge {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-light);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

/* Empty Message */
.empty-message {
    text-align: center;
    padding: var(--spacing-2xl);
    color: var(--text-muted);
}

/* Footer */
.public-footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-lg) var(--spacing-xl);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    .public-header .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }
    
    .header-subtitle {
        border-left: none;
        padding-left: 0;
    }
    
    .public-main {
        padding: var(--spacing-md);
    }
    
    .race-grid {
        grid-template-columns: 1fr;
    }
    
    .results-header {
        flex-direction: column;
        gap: var(--spacing-md);
    }
    
    .results-table th,
    .results-table td {
        padding: var(--spacing-sm);
    }
    
    .heat-tabs,
    .stage-tabs {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* ============================================
   Stage Tabs
   ============================================ */
.stage-tabs {
    display: flex;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-lg);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    flex-wrap: wrap;
}

.stage-tab {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-md);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.stage-tab:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}

.stage-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.status-badge {
    font-size: 0.625rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-badge.running {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
    animation: pulse 1.5s ease-in-out infinite;
}

.status-badge.finished {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* ============================================
   Race Status Bar
   ============================================ */
.race-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-lg);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

.race-status-bar.status-running {
    background: linear-gradient(90deg, rgba(76, 175, 80, 0.15) 0%, var(--bg-card) 100%);
    border-left: 4px solid #4caf50;
}

.race-status-bar.status-yellow {
    background: linear-gradient(90deg, rgba(251, 192, 45, 0.15) 0%, var(--bg-card) 100%);
    border-left: 4px solid #fbc02d;
}

.race-status-bar.status-red {
    background: linear-gradient(90deg, rgba(244, 67, 54, 0.15) 0%, var(--bg-card) 100%);
    border-left: 4px solid #f44336;
}

.race-status-bar.status-finished {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0%, var(--bg-card) 100%);
    border-left: 4px solid #ffffff;
}

.status-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-indicator.running {
    background: #4caf50;
    animation: pulse 1.5s ease-in-out infinite;
}

.status-indicator.yellow {
    background: #fbc02d;
    animation: pulse 1s ease-in-out infinite;
}

.status-indicator.red {
    background: #f44336;
}

.status-indicator.finished {
    background: #ffffff;
}

.status-text {
    font-weight: 600;
    font-size: 1rem;
}

.status-time {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ============================================
   Enhanced Results Table
   ============================================ */
.result-row {
    transition: background var(--transition-fast);
}

.result-row:hover {
    background: rgba(99, 102, 241, 0.05);
}

.result-row.pos-first td:first-child {
    color: #ffd700;
    font-weight: 700;
}

.result-row.pos-second td:first-child {
    color: #c0c0c0;
    font-weight: 700;
}

.result-row.pos-third td:first-child {
    color: #cd7f32;
    font-weight: 700;
}

.col-pos {
    width: 60px;
    font-weight: 700;
    font-size: 1.125rem;
}

.col-num {
    width: 60px;
    font-weight: 700;
}

.col-name {
    font-weight: 600;
    min-width: 200px;
    white-space: nowrap;
}

.col-class {
    min-width: 100px;
}

.col-laps {
    width: 60px;
    text-align: left;
    font-weight: 600;
}

.col-last,
.col-total {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
    min-width: 100px;
}

.col-gap {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 100px;
}

.empty-cell {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

/* Live indicator error state */
.live-indicator.error {
    background: rgba(100, 100, 100, 0.15);
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.live-indicator.error .live-dot {
    background: var(--text-muted);
    animation: none;
}

/* Race type badge */
.race-type-badge {
    display: inline-block;
    margin-top: var(--spacing-sm);
    padding: 2px 8px;
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-light);
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* ============================================
   Class-based Results Layout
   ============================================ */
.results-by-class {
    padding: var(--spacing-md);
}

.class-section {
    margin-bottom: var(--spacing-xl);
}

.class-header {
    background: linear-gradient(90deg, #2d5016 0%, transparent 100%);
    color: #9acd32;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0;
    border-left: 4px solid #9acd32;
}

.class-table-container {
    overflow-x: auto;
    background: rgba(0, 20, 0, 0.3);
}

.lap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    table-layout: fixed;
}

.lap-table th {
    background: rgba(0, 30, 0, 0.5);
    color: #9acd32;
    font-weight: 600;
    text-align: left;
    padding: var(--spacing-sm) var(--spacing-sm);
    font-size: 0.7rem;
    text-transform: uppercase;
    border-bottom: 1px solid #2d5016;
    white-space: nowrap;
}

.lap-table td {
    padding: var(--spacing-xs) var(--spacing-sm);
    border-bottom: 1px solid rgba(45, 80, 22, 0.3);
    color: #c5e063;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lap-table tr:hover td {
    background: rgba(154, 205, 50, 0.1);
}

.lap-table .col-pos {
    width: 35px;
    font-weight: 700;
    color: #ffffff;
}

.lap-table .col-num {
    width: 45px;
    font-weight: 600;
    color: #9acd32;
}

.lap-table .col-name {
    width: 200px;
    font-weight: 500;
    color: #c5e063;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
}

.lap-table .col-name .name-text {
    vertical-align: middle;
}

.lap-table .col-club {
    width: 100px;
    color: #888;
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
}

.lap-table .col-laps-header,
.lap-table .col-laps {
    width: auto;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.75rem;
    color: #c5e063;
}

.lap-table th.col-gap,
.lap-table td.col-gap {
    width: 110px;
    min-width: 110px;
    text-align: right;
    color: #888;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
}

.lap-table th.col-total,
.lap-table td.col-total {
    width: 110px;
    min-width: 110px;
    text-align: right;
    font-weight: 600;
    color: #9acd32;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
}

.lap-table .col-lap {
    min-width: 80px;
    color: #c5e063;
}

.lap-table .pos-first .col-pos { color: #ffd700; }
.lap-table .pos-second .col-pos { color: #c0c0c0; }
.lap-table .pos-third .col-pos { color: #cd7f32; }

/* Flash animation for updated rows - ~7 flashes over 4 seconds (0.6s cycle) */
@keyframes flash-purple {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(147, 51, 234, 0.4); }
}

.flash-update {
    animation: flash-purple 0.6s ease-in-out 7;
}

.flash-update td {
    animation: flash-purple 0.6s ease-in-out 7;
}
