:root {
    /* Racing Dashboard Colors */
    --bg-main: #0a0a0c; /* Deep asphalt black */
    --bg-panel: #151518; /* Dark carbon */
    --bg-panel-hover: #1f1f23;
    
    --racing-red: #e10600; /* Formula 1 Red */
    --racing-red-hover: #ff1a12;
    --fastest-lap: #b800ff; /* F1 purple for fastest lap */
    --system-active: #00d233; /* Racing green */
    
    --text-primary: #ffffff;
    --text-secondary: #878790;
    --text-muted: #53535a;
    
    --border-color: #2a2a30;
    --border-light: rgba(255, 255, 255, 0.05);
    
    --radius-sm: 4px;
    --radius-md: 8px;
}

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

body {
    font-family: 'Outfit', -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image: 
        linear-gradient(45deg, #0a0a0c 25%, transparent 25%, transparent 75%, #0a0a0c 75%, #0a0a0c), 
        linear-gradient(45deg, #0a0a0c 25%, transparent 25%, transparent 75%, #0a0a0c 75%, #0a0a0c);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    background-color: #111113;
}

.app-container {
    width: 100%;
    max-width: 1600px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100vh;
}

/* Header */
.app-header {
    background: var(--bg-panel);
    border-left: 4px solid var(--racing-red);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

.app-header-left h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 1px;
    margin-bottom: 0.2rem;
    text-transform: uppercase;
}

.app-header-left h1 span {
    color: var(--racing-red);
    font-style: italic;
}

.app-header-left p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.2rem;
    background: #0a0a0c;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
    border: 1px solid var(--border-color);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ff3b30;
}

.dot.active {
    background-color: var(--system-active);
    box-shadow: 0 0 10px var(--system-active);
}

/* Layout - 3 Columns */
.main-content {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 1.5rem;
    flex: 1;
    min-height: 0; /* Important for scrollable children in flexbox */
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 250px 1fr 250px;
    }
}

@media (max-width: 992px) {
    .main-content {
        grid-template-columns: 1fr;
        height: auto;
    }
    .app-container {
        height: auto;
    }
}

/* Base Panel Styles */
.dashboard-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.2rem;
    background: #111113;
    border-bottom: 2px solid var(--border-color);
}

.panel-header h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}

.panel-body {
    padding: 1.2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* For scrolling lists */
}

/* Controls */
.controls-wrapper {
    gap: 1.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
}

select, input[type="text"] {
    padding: 0.85rem 1rem;
    background: #0a0a0c;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    outline: none;
    transition: all 0.2s;
    width: 100%;
}

select:focus, input[type="text"]:focus {
    border-color: var(--text-secondary);
}

.action-buttons-vertical {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: auto; /* Push to bottom of control panel */
}

/* Buttons */
.btn {
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
}

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

.btn-primary {
    background-color: var(--racing-red);
    color: white;
}

.btn-primary:not(:disabled):hover {
    background-color: var(--racing-red-hover);
    box-shadow: 0 0 15px rgba(225, 6, 0, 0.4);
}

.btn-danger {
    background-color: #2a2a30;
    color: var(--text-primary);
    border: 1px solid #3f3f46;
}

.btn-danger:not(:disabled):hover {
    background-color: #3f3f46;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}

.btn-outline:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

/* Center Vision Section */
.vision-section {
    border-top: 3px solid var(--racing-red);
}

.vision-section .panel-body {
    padding: 0;
    gap: 0;
}

/* Video Container */
.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

canvas#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    z-index: 10;
}

.scanning-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    background: 
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px) center / 100% 50% no-repeat,
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px) center / 50% 100% no-repeat;
}

.instruction-text {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 6px 16px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    pointer-events: none;
    z-index: 20;
    border: 1px solid rgba(255,255,255,0.2);
}

/* Big Timer */
.main-timer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: #111113;
}

.timer-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.timer-display {
    font-family: 'Orbitron', monospace;
    font-size: 4.5rem;
    font-weight: 700;
    color: white;
    letter-spacing: 2px;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    text-shadow: 0 0 20px rgba(255,255,255,0.1);
}

/* Laps List */
.laps-wrapper {
    padding: 0;
}

.laps-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

/* Scrollbar */
.laps-list::-webkit-scrollbar {
    width: 4px;
}
.laps-list::-webkit-scrollbar-track {
    background: #0a0a0c;
}
.laps-list::-webkit-scrollbar-thumb {
    background: var(--text-muted);
}

.lap-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-family: 'Orbitron', monospace;
    position: relative;
    transition: all 0.2s;
}

.lap-item:hover {
    background: rgba(255,255,255,0.02);
}

.lap-item.best-lap {
    background: rgba(184, 0, 255, 0.05);
}

.lap-item.best-lap .lap-time {
    color: var(--fastest-lap);
}

.lap-item.best-lap::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 3px;
    background-color: var(--fastest-lap);
}

.lap-item.best-lap::after {
    content: 'FASTEST';
    font-family: 'Outfit', sans-serif;
    position: absolute;
    right: 1rem;
    top: 0;
    color: var(--fastest-lap);
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 1px;
}

.lap-number {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.lap-number span {
    color: var(--text-primary);
    font-size: 1rem;
    display: inline-block;
    width: 24px;
}

.lap-time {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.lap-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: 'Outfit', sans-serif;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2rem 0;
}

/* Modal Styles */
.modal-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: 0 0 30px rgba(0,0,0,0.8), 0 0 0 1px var(--fastest-lap);
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-panel);
}

.modal-header h2 {
    color: var(--text-primary);
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-close:hover {
    color: var(--racing-red);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

/* Recap Table */
.recap-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Outfit', sans-serif;
}

.recap-table th {
    text-align: left;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-bottom: 2px solid var(--border-color);
}

.recap-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.recap-table tbody tr:hover {
    background: rgba(255,255,255,0.02);
}

.recap-table td:nth-child(3),
.recap-table td:nth-child(4) {
    font-family: 'Orbitron', monospace;
}

.recap-table td:nth-child(3) {
    color: var(--fastest-lap);
}

.pos-badge {
    background: var(--bg-panel);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
}
.pos-badge.pos-1 {
    background: rgba(184, 0, 255, 0.2);
    color: var(--fastest-lap);
    border-color: var(--fastest-lap);
}

/* Timer Tabular Nums */
.timer-display, .lap-time, #headerTimer, #allTimeMs, #winnerTime {
    font-family: 'Roboto Mono', monospace !important;
    font-variant-numeric: tabular-nums;
}
