* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #f0d15a;
    --primary-dark: #d4b43f;
    --secondary: #111111;
    --success: #6fdc6f;
    --warning: #f0d15a;
    --danger: #ff5c5c;
    --dark: #0b0b0b;
    --light: #f3f4f6;
    --border: #2e2e2e;
    --text: #f8f8f8;
    --text-light: #bbbbbb;
    
    /* Colors for flags */
    --flag-green: #22c55e;
    --flag-yellow: #eab308;
    --flag-red: #ef4444;
    --flag-white: #ffffff;
    --flag-black: #000000;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0a0a0a;
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
}

.tv-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

/* Header */
.tv-header {
    background: linear-gradient(90deg, #060606 0%, #151515 50%, #060606 100%);
    color: white;
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    border-bottom: 3px solid var(--primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.header-status {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85em;
    white-space: nowrap;
}

.header-status .status-text {
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 0.9em;
}

.header-status .sync-dot {
    width: 10px;
    height: 10px;
}

.header-content {
    flex: 1;
    min-width: 0;
}

.event-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.event-logo {
    height: 34px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.header-content h1 {
    font-size: clamp(1rem, 1.8vw, 1.4rem);
    font-weight: 700;
    margin-bottom: 2px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    word-break: break-word;
}

.header-info {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
    font-size: clamp(0.72rem, 1vw, 0.88rem);
    align-items: center;
}

.header-info span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-categories {
    color: var(--text-light);
    font-size: 0.9em;
    letter-spacing: 0.03em;
}

.session-name-info {
    color: var(--primary);
    font-weight: 600;
}

.race-timer-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
    font-weight: 700;
    color: #f0d15a;
    white-space: nowrap;
}

.race-timer-badge .timer-remaining {
    color: #ff9933;
    font-size: 0.9em;
}

.flag {
    font-size: 1.5em;
    display: inline-block;
    animation: pulse 1s infinite;
}

.flag.green { color: var(--flag-green); }
.flag.yellow { color: var(--flag-yellow); }
.flag.red { color: var(--flag-red); }
.flag.white { color: var(--flag-white); }
.flag.black { color: var(--flag-black); }

/* Badge de bandeira no header */
.flag-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 4px;
    font-weight: 800;
    font-size: 0.9em;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.flag-badge-green  { background: #16a34a; color: #fff; }
.flag-badge-yellow { background: #eab308; color: #000; animation: flag-blink 0.8s infinite; }
.flag-badge-red    { background: #dc2626; color: #fff; animation: flag-blink 0.6s infinite; }
.flag-badge-white  { background: #ffffff; color: #000; border: 1px solid #999; }
.flag-badge-black  { background: #111; color: #fff; border: 1px solid #555; }
.flag-badge-checkered { background: repeating-conic-gradient(#000 0% 25%, #fff 0% 50%) 0 0 / 12px 12px; color: #fff; text-shadow: 0 0 4px #000; }
.flag-badge-sc     { background: #f97316; color: #fff; animation: flag-blink 1s infinite; }
.flag-badge-vsc    { background: #fb923c; color: #fff; animation: flag-blink 1s infinite; }
.flag-badge-warmup { background: #6b7280; color: #fff; }

@keyframes flag-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.controls-bar {
    display: flex;
    gap: 15px;
    align-items: center;
}

.control-select {
    padding: 12px 15px;
    border: 2px solid var(--primary);
    border-radius: 6px;
    background: white;
    color: var(--text);
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 250px;
}

.control-select[multiple] {
    min-height: 100px;
    padding: 8px;
}

.control-select option {
    padding: 8px;
    color: var(--text);
    background: white;
}

.control-select option:checked {
    background: var(--primary);
    color: white;
}

.control-select:hover {
    background: #f3f4f6;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.2);
}

.control-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.3);
}

.btn-small {
    padding: 12px 25px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1em;
}

.btn-small:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.btn-small:active {
    transform: scale(0.98);
}

/* Main Content */
.tv-main {
    flex: 1;
    overflow: auto;
    padding: 20px 30px;
    display: flex;
    gap: 20px;
}

.rankings-container {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 20px;
    overflow: auto;
    backdrop-filter: blur(10px);
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.ranking-table thead {
    background: rgba(30, 64, 175, 0.2);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.ranking-table th {
    padding: 8px 6px;
    text-align: left;
    font-weight: 700;
    border-bottom: 2px solid var(--primary);
    white-space: nowrap;
}

.ranking-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.02);
}

.ranking-table tbody tr:hover {
    background: rgba(30, 64, 175, 0.1);
    color: white;
}

.ranking-table tbody tr.position-1 {
    background: rgba(34, 197, 94, 0.15);
    border-left: 4px solid var(--success);
}

.ranking-table tbody tr.position-2 {
    background: rgba(59, 130, 246, 0.15);
    border-left: 4px solid #3b82f6;
}

.ranking-table tbody tr.position-3 {
    background: rgba(217, 119, 6, 0.15);
    border-left: 4px solid #d97706;
}

.ranking-table td {
    padding: 8px 6px;
    color: rgba(255, 255, 255, 0.9);
}

.ranking-table td.loading {
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
}

/* Column widths */
.col-pos { width: 60px; font-weight: 700; color: var(--flag-yellow); }
.col-car { width: 80px; font-weight: 700; }
.col-driver { flex: 1; min-width: 200px; }
.col-category { width: 120px; }
.col-category {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8em;
}
.col-laps { width: 80px; text-align: center; }
.col-time { width: 120px; text-align: right; }
.col-best { width: 120px; text-align: right; }
.col-last { width: 120px; text-align: right; }
.col-gap { width: 100px; text-align: right; }

/* Info Panel */
.info-panel {
    width: 300px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    backdrop-filter: blur(10px);
}

.panel-section {
    background: rgba(30, 64, 175, 0.1);
    border-left: 3px solid var(--primary);
    padding: 15px;
    border-radius: 6px;
}

.panel-section h3 {
    color: white;
    font-size: 1.1em;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    color: rgba(255, 255, 255, 0.8);
}

.info-item .label {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
}

.info-item .value {
    font-weight: 700;
    color: white;
    font-size: 1.1em;
    font-family: 'Courier New', monospace;
}

.flag-display {
    text-align: center;
    padding: 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.4em;
    color: white;
}

.flag-display.green {
    background: rgba(34, 197, 94, 0.3);
    border: 2px solid var(--flag-green);
    color: var(--flag-green);
}

.flag-display.yellow {
    background: rgba(234, 179, 8, 0.3);
    border: 2px solid var(--flag-yellow);
    color: var(--flag-yellow);
}

.flag-display.red {
    background: rgba(239, 68, 68, 0.3);
    border: 2px solid var(--flag-red);
    color: var(--flag-red);
}

.flag-display.white {
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid white;
    color: white;
}

.flag-display.black {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid white;
    color: white;
}

.status-text {
    font-weight: 600;
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    text-align: center;
}

.status-text.connected {
    background: rgba(34, 197, 94, 0.2);
    color: var(--flag-green);
}

.status-text.disconnected {
    background: rgba(239, 68, 68, 0.2);
    color: var(--flag-red);
}

.timestamp {
    font-size: 0.85em;
    opacity: 0.7;
    text-align: center;
}

/* Footer */
.tv-footer {
    background: rgba(0, 0, 0, 0.5);
    border-top: 2px solid var(--primary);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95em;
}

.sync-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--flag-green);
    display: inline-block;
    animation: sync-pulse 1s infinite;
}

.sync-dot.inactive {
    background: var(--flag-red);
    animation: none;
}

@keyframes sync-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(30, 64, 175, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(30, 64, 175, 0.8);
}

/* Responsive */
@media (max-width: 1920px) {
    .ranking-table {
        font-size: 1em;
    }
    
    .ranking-table th,
    .ranking-table td {
        padding: 12px 8px;
    }
}

@media (max-width: 1400px) {
    .tv-main {
        flex-direction: column;
    }
    
    .info-panel {
        width: 100%;
        max-height: 250px;
        flex-direction: row;
        overflow-x: auto;
    }
    
    .panel-section {
        flex: 0 0 auto;
        min-width: 250px;
    }
}

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .tv-container {
        min-height: 100vh;
        height: auto;
    }

    .tv-header {
        padding: 14px 16px;
    }

    .event-logo {
        height: 24px;
    }

    .tv-main {
        padding: 12px;
    }

    .tv-footer {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
}
