/* NIGAN Live Timing - Mobile-first responsive styles */

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --text: #e0e0e0;
    --text-muted: #999;
    --accent: #0f3460;
    --border: #2a2a4a;
    --green: #27ae60;
    --red: #e74c3c;
    --amber: #f39c12;
    --highlight: #2ecc71;

    /* Class colours matching LiveDisplay */
    --class-250: #228B22;
    --class-250-text: #fff;
    --class-350: #0000CD;
    --class-350-text: #fff;
    --class-500: #FFD700;
    --class-500-text: #000;
    --class-750: #fff;
    --class-750-text: #000;
    --class-1400: #DC143C;
    --class-1400-text: #fff;
    --class-1wd: #fff;
    --class-1wd-text: #000;
    --class-2wd: #fff;
    --class-2wd-text: #000;
    --class-morgan: #fff;
    --class-morgan-text: #000;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* Header */
.header {
    background: var(--accent);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 44px;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header nav {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
    margin-left: 12px;
}

.header nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    white-space: nowrap;
}

.header nav a:hover,
.header nav a.active {
    color: #fff;
}

/* Status badge */
.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    flex-shrink: 0;
    margin-left: 8px;
    min-width: 60px;
    min-height: 20px;
    line-height: 16px;
}

.status-live {
    background: var(--green);
    color: #fff;
    animation: pulse 2s infinite;
}

.status-offline {
    background: var(--red);
    color: #fff;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Toast notification for new runs */
.toast {
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--green);
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    text-align: center;
    max-width: 90vw;
}

.toast.show { opacity: 1; }
.toast.flagged { background: var(--red); }

.provisional-banner {
    background: #e74c3c;
    color: #fff;
    text-align: center;
    padding: 8px 12px;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}
.provisional-banner a {
    color: #fff;
    text-decoration: underline;
}

/* Main content */
.content {
    padding: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Cards / Sections */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    min-height: 120px;
}

.card-header {
    padding: 8px 12px;
    font-weight: 700;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    border-radius: 7px 7px 0 0;
}

.card-body {
    padding: 0;
}

/* Tables */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.results-table th {
    text-align: left;
    padding: 6px 8px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

.results-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table .pos { width: 30px; text-align: center; font-weight: 700; }
.results-table .num { width: 40px; text-align: center; font-weight: 700; }
.results-table .time { text-align: right; font-variant-numeric: tabular-nums; }
.results-table .rider { overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.results-table .flagged { color: var(--red); font-weight: 700; }

/* Horizontal scroll wrapper for wide tables */
.table-scroll {
    overflow-x: scroll;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    padding: 0;
}

/* Compact results table (smaller font for many session columns) */
.results-compact {
    font-size: 0.75rem;
    white-space: nowrap;
    width: auto;
}

.results-compact th {
    font-size: 0.65rem;
    padding: 4px 5px;
}

.results-compact td {
    padding: 3px 5px;
}

.results-compact .time {
    min-width: 42px;
}

.results-compact .rider {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Class section headers */
.class-header {
    padding: 6px 12px;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.class-record {
    font-weight: 400;
    font-size: 0.75rem;
    opacity: 0.9;
}

.class-250 { background: var(--class-250); color: var(--class-250-text); }
.class-350 { background: var(--class-350); color: var(--class-350-text); }
.class-500 { background: var(--class-500); color: var(--class-500-text); }
.class-750 { background: var(--class-750); color: var(--class-750-text); }
.class-1400 { background: var(--class-1400); color: var(--class-1400-text); }
.class-1WD { background: var(--class-1wd); color: var(--class-1wd-text); }
.class-2WD { background: var(--class-2wd); color: var(--class-2wd-text); }
.class-Morgan { background: var(--class-morgan); color: var(--class-morgan-text); }

/* FTD banner */
.ftd-banner {
    background: var(--amber);
    color: #000;
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
}

.ftd-banner .ftd-label { font-size: 0.85rem; }
.ftd-banner .ftd-time { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.ftd-banner .ftd-rider { font-size: 0.95rem; }

/* Live run display */
.live-panel {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    text-align: center;
}

.live-panel.running { border-color: var(--green); }
.live-panel.finished { border-color: var(--amber); }
.live-panel.flagged-state { border-color: var(--red); }

.rider-card {
    transition: border-color 0.3s, opacity 0.3s;
}

.live-clock {
    font-size: 3.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    margin: 12px 0;
}

.live-rider {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.live-machine {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.live-number {
    display: inline-block;
    background: var(--accent);
    padding: 2px 12px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.live-status-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.live-splits {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}

.split-chip {
    background: var(--accent);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.split-chip .split-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    display: block;
}

.split-chip .split-value {
    font-weight: 700;
}

.split-chip.speed { border-left: 3px solid var(--amber); }

/* Rider modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.7;
    z-index: 1;
}

.modal-close:hover { opacity: 1; }

.modal-header {
    padding: 16px;
    border-radius: 11px 11px 0 0;
    text-align: center;
}

.modal-rider-num {
    font-size: 1.8rem;
    font-weight: 700;
}

.modal-rider-name {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 2px;
}

.modal-rider-info {
    font-size: 0.85rem;
    margin-top: 4px;
    opacity: 0.85;
}

.modal-rider-stats {
    font-size: 0.85rem;
    font-weight: 700;
    margin-top: 6px;
}

.modal-rider-record {
    font-size: 0.8rem;
    font-weight: 400;
    margin-top: 4px;
    opacity: 0.85;
}

.modal-body { padding: 0; }

.modal-runs-table td,
.modal-runs-table th {
    padding: 8px 12px;
}

.modal-best {
    background: rgba(39, 174, 96, 0.2);
}

.modal-best td { font-weight: 700; }

[data-rider-num] {
    cursor: pointer;
}

[data-rider-num]:hover {
    text-decoration: underline;
}

/* Qualifier highlight */
.qualifier-top { background: rgba(39, 174, 96, 0.3); font-weight: bold; }
.qualifier-out { background: rgba(231, 76, 60, 0.25); color: #ccc; }

/* Responsive */
@media (min-width: 768px) {
    .content { padding: 16px 24px; }
    .live-clock { font-size: 5rem; }
    .live-rider { font-size: 1.8rem; }
    .results-table { font-size: 0.9rem; }
    .results-table .rider { max-width: 250px; }
    .results-compact { font-size: 0.8rem; }
    .results-compact th { font-size: 0.7rem; }
    .results-compact .rider { max-width: 180px; }
}

@media (min-width: 1024px) {
    .class-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* Utility */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.empty-state {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}
