/* =========================================
   1. GLOBAL VARIABLES & RESET
   ========================================= */
   @import url('https://fonts.googleapis.com/css2?family=Encode+Sans+Condensed:wght@300;600&display=swap');
:root {
    --bg-dark: #121212;
    --sidebar-bg: #1e1e1e;
    --accent: #e5ff00; /* High-vis cycling yellow */
    --text-main: #ffffff;
    --text-dim: #a0a0a0;
    --border: #333;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    display: flex;
    height: 100vh;
    background: var(--bg-dark);
    color: var(--text-main);
}

.hidden { 
    display: none !important; 
}

/* =========================================
   2. LAYOUT & SIDEBAR NAVIGATION
   ========================================= */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    width: 32px;
    height: 32px;
    border-radius: 4px;
}

.sidebar-header h1 { 
    font-size: 1.2rem;
    color: var(--accent); 
    margin: 0;
}

#tool-menu {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

nav button {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-dim);
    text-align: left;
    padding: 10px 12px;
    margin-bottom: 4px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

nav button:hover, nav button.active {
    background: rgba(229, 255, 0, 0.1);
    color: var(--text-main);
}

nav button.active {
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
}

.icon {
    font-size: 1.1rem;
}

/* Sub-menu Styles */
.submenu {
    margin-left: 28px;
    border-left: 1px solid var(--border);
    padding-left: 8px;
    margin-bottom: 12px;
    margin-top: 4px;
}

.child-btn {
    font-size: 0.85rem;
    padding: 8px 12px;
    opacity: 0.8;
}

.child-btn:hover, .child-btn.active {
    opacity: 1;
    color: var(--accent);
}

/* =========================================
   3. MAIN CONTENT AREA
   ========================================= */
main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#view-header {
    padding: 20px 40px;
    border-bottom: 1px solid var(--border);
    background: var(--sidebar-bg);
}

#view-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

#module-container {
    padding: 40px;
    overflow-y: auto;
    flex-grow: 1;
}

.welcome-card, .tool-header {
    background: var(--sidebar-bg);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.loader, .error {
    padding: 20px;
    text-align: center;
    border-radius: 8px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
}

.error {
    border-color: #ff4d4d;
    color: #ff4d4d;
}

/* =========================================
   4. SHARED UI COMPONENTS (Buttons, Inputs)
   ========================================= */
.controls { 
    background: var(--sidebar-bg); 
    padding: 20px; 
    border-radius: 8px; 
    border: 1px solid var(--border);
    margin-bottom: 20px; 
    display: flex; 
    gap: 20px; 
    flex-wrap: wrap; 
    align-items: flex-end; 
}

.control-group { 
    display: flex; 
    flex-direction: column; 
}

.control-group label { 
    font-weight: 600; 
    margin-bottom: 6px; 
    font-size: 0.85rem; 
    color: var(--text-dim); 
    text-transform: uppercase;
}

.control-group input { 
    padding: 10px 12px; 
    background: var(--bg-dark); 
    border: 1px solid var(--border); 
    color: var(--text-main);
    border-radius: 4px; 
    font-size: 1rem;
    font-family: inherit;
}

.control-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-primary {
    padding: 10px 24px; 
    background-color: #007bff; 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: 600; 
    font-size: 1rem;
    transition: background 0.2s;
}

.btn-primary:hover { background-color: #0056b3; }

.btn-success {
    padding: 10px 24px; 
    background-color: #28a745; 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: 600; 
    font-size: 1rem;
    transition: background 0.2s;
}

.btn-success:hover { background-color: #218838; }

/* API Validation Styles */
.input-error {
    border-color: #ff4d4d !important;
    background-color: rgba(255, 77, 77, 0.05) !important;
}
.api-warning {
    color: #ff4d4d;
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 4px;
}

/* =========================================
   5. START GRID TOOL SPECIFIC STYLES
   ========================================= */
#grid-preview { 
    --font-scale: 1; /* Dynamic variable controlled by JS */
    background: white; 
    padding: 20px; 
    overflow: auto; 
    border: 1px solid var(--border); 
    border-radius: 8px;
    max-height: 70vh; 
}

#hidden-print-area { 
    position: absolute; 
    top: -9999px; 
    left: -9999px; 
    visibility: hidden; 
}

/* Grid Table Elements */
.race-grid { 
    border-collapse: collapse; 
    margin: 0 auto; 
    background-color: #fff; 
    border: 2px solid #000; 
    color: #000; 
}

.race-grid td { 
    border: 1px solid #000; 
    padding: 0; 
    vertical-align: top; 
    position: relative; 
}

.team-name-cell { 
    width: 45px; 
    background-color: #e6e6e6; 
    vertical-align: middle !important; 
    border: 2px solid #000 !important; 
    text-align: center; 
    overflow: hidden; 
}

.team-name-wrapper { 
    transform: rotate(-90deg); 
    white-space: nowrap; 
    font-weight: 700; 
    /* ORIGINAL 13px */
    font-size: calc(13px * var(--font-scale)); 
    text-transform: uppercase; 
    display: inline-block; 
    width: 120px; 
    text-align: center; 
    margin-left: -37px; 
    margin-right: -37px; 
}

.rider-cell { 
    width: 110px; 
    height: 70px; 
    position: relative; 
    box-sizing: border-box; 
}

/* Rider Data Points inside the Cell */
.bib { 
    position: absolute; 
    top: 2px; 
    left: 5px; 
    /* ORIGINAL 28px */
    font-size: calc(28px * var(--font-scale)); 
    font-weight: 800; 
    line-height: 1; 
    letter-spacing: -1px; 
    font-family: 'Arial Black', Arial, sans-serif; 
    z-index: 2; 
}

.gap { 
    position: absolute; 
    top: 6px; 
    right: 6px; 
    /* ORIGINAL 11px */
    font-size: calc(11px * var(--font-scale)); 
    font-weight: normal; 
    color: #000; 
    z-index: 2; 
}

.name { 
    position: absolute; 
    top: 36px; 
    left: 5px; 
    right: 5px; 
    /* ORIGINAL 10px */
    font-size: calc(10px * var(--font-scale)); 
    font-weight: 700; 
    text-transform: uppercase; 
    line-height: 1.1; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    z-index: 2; 
}

.rank { 
    position: absolute; 
    bottom: 3px; 
    left: 5px; 
    /* ORIGINAL 10px */
    font-size: calc(10px * var(--font-scale)); 
    font-weight: 600; 
    color: #000; 
    z-index: 2; 
}

/* Cell States */
.empty-cell { 
    background-color: #fcfcfc; 
}

.crossed-cell { 
    background-color: #fcfcfc; 
}

/* The "X" for DNS/DNF riders */
.crossed-cell::before, .crossed-cell::after { 
    content: ''; 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    width: 100%; 
    height: 2px; 
    background-color: #000; 
    z-index: 1; 
}

.crossed-cell::before { 
    transform: translate(-50%, -50%) rotate(28deg); 
}

.crossed-cell::after { 
    transform: translate(-50%, -50%) rotate(-28deg); 
}
/* Disabled button styling */
button:disabled {
    background: #444 !important;
    color: #888 !important;
    cursor: not-allowed !important;
}

/* LIF Tool Output Preview Box */
.output-preview {
    font-family: 'Consolas', 'Menlo', monospace;
    background: var(--bg-dark);
    border-radius: 6px;
    border: 1px solid var(--border);
    padding: 15px;
    font-size: 0.9rem;
    color: var(--accent); /* Makes the raw data pop slightly */
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin-bottom: 20px;
}/* =========================================
   8. COURIER TABLE OVERRIDES
   ========================================= */
.courier-table {
    font-family: 'Courier New', Courier, monospace;
}

/* Force Courier and un-bold everything */
.courier-table th, 
.courier-table td {
    font-family: 'Courier New', Courier, monospace !important;
    font-weight: normal !important;
    text-transform: none !important;
    border: 1px solid var(--border) !important; /* Strict grid lines */
    font-size: 0.95rem; 
}

/* Ensure inputs typed into editable cells match the font */
.courier-table {
    font-family: 'Courier New', Courier, monospace;
    white-space: nowrap; /* Forces table to stretch instead of wrapping text */
}

/* Force Courier and un-bold everything */
.courier-table th, 
.courier-table td {
    font-family: 'Courier New', Courier, monospace !important;
    font-weight: normal !important;
    text-transform: none !important;
    border: 1px solid var(--border) !important; /* Strict grid lines */
    font-size: 0.95rem; 
}

/* Ensure inputs typed into editable cells match the font */
.courier-table td[contenteditable="true"] {
    color: var(--text-main);
}
/* =========================================
   RESPONSIVE TABLE WRAPPER
   ========================================= */
.table-responsive { 
    width: 100%;
    overflow-x: auto; /* This triggers the horizontal scrollbar */
    margin-top: 20px; 
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Ensure the table inside stretches wide enough to scroll */
.table-responsive table {
    min-width: 100%;
}/* =========================================
   9. DRAGGABLE LIST (PDF Editor)
   ========================================= */
.draggable-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-width: 600px;
}

.draggable-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: grab;
    transition: background 0.2s, border-color 0.2s;
    color: var(--text-main);
}

.draggable-item:active {
    cursor: grabbing;
}

.draggable-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.drag-handle {
    color: var(--text-dim);
    cursor: grab;
    font-size: 1.2rem;
    user-select: none;
}

.file-name {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95rem;
    word-break: break-all;
}

/* Dragging States */
.draggable-item.dragging {
    opacity: 0.5;
    background: var(--bg-dark);
}

.draggable-item.drag-over {
    border: 2px dashed var(--accent);
    background: rgba(229, 255, 0, 0.05);
}

.empty-list-msg {
    color: var(--text-dim);
    font-style: italic;
    padding: 10px 0;
}/* =========================================
   10. PDF EDITOR STYLES (Tabs & Deletion Grid)
   ========================================= */

/* Tabs */
.pdf-tabs { 
    display: flex; 
    gap: 15px; 
    margin-bottom: 20px; 
    border-bottom: 1px solid var(--border); 
}

.pdf-tab { 
    background: transparent; 
    color: var(--text-dim); 
    border: none; 
    font-size: 1.1rem; 
    cursor: pointer; 
    padding: 10px 15px; 
    font-weight: 600; 
    transition: color 0.2s; 
    border-bottom: 3px solid transparent;
}

.pdf-tab:hover {
    color: var(--text-main);
}

.pdf-tab.active { 
    color: var(--accent); 
    border-bottom: 3px solid var(--accent); 
}

.pdf-view.hidden { 
    display: none !important; 
}

/* Deletion Grid */
.pdf-page-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); 
    gap: 20px; 
    margin-top: 15px; 
}

.pdf-page-item { 
    position: relative; 
    border: 3px solid transparent; 
    border-radius: 6px; 
    cursor: pointer; 
    transition: transform 0.2s, border-color 0.2s; 
    overflow: hidden; 
    background: white; /* PDF background is white */
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.pdf-page-item:hover { 
    transform: scale(1.03); 
}

.pdf-page-item canvas { 
    width: 100%; 
    height: auto; 
    display: block; 
}

.pdf-page-item .page-num { 
    position: absolute; 
    bottom: 5px; 
    right: 5px; 
    background: rgba(0,0,0,0.8); 
    color: white; 
    padding: 3px 8px; 
    border-radius: 4px; 
    font-size: 0.8rem; 
    font-weight: 600;
}

/* Deletion State (The Red Trash Overlay) */
.pdf-page-item.selected { 
    border-color: #dc3545; 
}

.pdf-page-item.selected::after { 
    content: '🗑️ Delete'; 
    position: absolute; 
    top: 0; left: 0; right: 0; bottom: 0; 
    background: rgba(220, 53, 69, 0.6); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    color: white; 
    font-weight: bold; 
    font-size: 1.2rem; 
}
/* =========================================
   11. POINTS/KOM REPORT STYLES
   ========================================= */

.print-area {
    width: 100%;
    background: white;
    color: black;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
    font-family: 'Encode Sans Condensed', sans-serif;
    font-size: 8pt;
}

.contest-sheet {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    page-break-after: always; /* New page for each contest when printing */
    width: 100%;
    margin-bottom: 40px;
}

.half-col { width: 48%; }

.pts-section-title {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 9pt;
    margin-bottom: 2mm;
}

.pts-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    color: black;
}

.pts-table th {
    text-align: left;
    border-bottom: 1pt solid #000;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 0;
    font-size: 7.5pt;
    background: transparent;
    color: black;
}

.pts-table td {
    border: none;
    padding: 2px 0;
    vertical-align: top;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pts-group-header td {
    background-color: #e6e6e6 !important;
    font-weight: 600;
    text-transform: uppercase;
    padding: 3px 5px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.pts-spacer-row td { height: 4mm; }
.col-rank { width: 8%; }
.col-bib  { width: 12%; }
.col-name { width: 45%; }
.col-nat  { width: 10%; }
.col-team { width: 15%; }
.col-pts  { width: 10%; text-align: right; }
.text-right { text-align: right; }

/* =========================================
   12. PRINT-SPECIFIC OVERRIDES
   ========================================= */
@media print {
    /* Set standard 10mm page margins for ALL tools */
    @page {
        size: letter;
        margin: 10mm; 
    }

    /* Add the extra 35mm drop ONLY to Points/KOM if needed for letterheads */
    body.print-points-kom .contest-sheet {
        padding-top: 35mm;
    }

    /* Hide the App Shell when printing */
    body.print-points-kom .sidebar,
    body.print-points-kom #view-header,
    body.print-points-kom .controls,
    body.print-points-kom .tool-header {
        display: none !important;
    }

    /* Override scroll bars and padding so entire document prints */
    body.print-points-kom {
        background: white !important;
    }

    body.print-points-kom #app-viewport,
    body.print-points-kom #module-container {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        height: auto !important;
    }

    body.print-points-kom .print-area {
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }
}/* =========================================
   14. PODIUM SUMMARY STYLES
   ========================================= */

.podium-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
    color: black;
}

.podium-table th {
    background-color: grey;
    color: white;
    font-weight: 600;
    padding: 6px 8px;
    text-align: left;
    border: 1px solid #ccc;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.podium-table .group-title-row th {
    font-size: 1.1rem;
    text-align: center;
    background-color: #555;
    padding: 8px;
}

.podium-table td {
    font-weight: 400;
    padding: 6px 8px;
    border: 1px solid #ccc;
    background: white;
}

/* Print View Override */
@media print {
    body.print-podium .sidebar,
    body.print-podium #view-header,
    body.print-podium .controls,
    body.print-podium .tool-header {
        display: none !important;
    }

    body.print-podium {
        background: white !important;
        color: black !important;
    }

    body.print-podium #app-viewport,
    body.print-podium #module-container {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        height: auto !important;
    }

    body.print-podium .print-area {
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }

    body.print-podium .podium-table {
        page-break-inside: avoid;
    }
}