/* ============================================= */
/*  style.css - Zwift Ladder Race Tool           */
/*  Complete professional styling                */
/*  Last updated: December 2025                  */
/* ============================================= */

/* 1. GLOBAL RESET & BASE STYLES */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    padding: 20px 0;
}

/* 2. COLOR VARIABLES (centralised for easy tweaking) */
:root {
    /* Team background colours */
    --team1-bg: #e3f2fd; /* Light blue */
    --team2-bg: #fff3e0; /* Light orange */

    /* Ranked gradient palette (lowest to highest) - reduced yellow, better green-to-red flow */
    --gradient-1: #d5f5d5;  /* Very light green - lowest */
    --gradient-2: #b0f0b0;
    --gradient-3: #90e090;
    --gradient-4: #70d070;  /* Mid-green */
    --gradient-5: #a0d0a0;  /* Slight gray-green transition */
    --gradient-6: #c8c890;  /* Muted yellowish-green */
    --gradient-7: #e0c080;  /* Light orange */
    --gradient-8: #f0a070;  /* Mid orange-red */
    --gradient-9: #e08060;
    --gradient-10: #d04040; /* Dark red - highest */

    /* Highlights for averages/power zone (keep matching ends) */
    --highlight-highest: var(--gradient-10);
    --highlight-lowest: var(--gradient-1);

    /* Spacer column background */
    --spacer-bg: #f0f0f0;
}

/* 3. LAYOUT CONTAINER */
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 4. HEADINGS */
h1 {
    text-align: center;
    font-size: 2.8rem;
    margin: 20px 0 10px;
    color: #2c3e50;
    font-weight: 700;
}

h1 + p {
    text-align: center;
    font-size: 1.2rem;
    color: #555;
    margin-bottom: 40px;
}

h2 {
    font-size: 2.2rem;
    color: #2c3e50;
    margin: 50px 0 20px;
    text-align: center;
}

h3 {
    font-size: 1.8rem;
    color: #2c3e50;
    margin: 40px 0 15px;
    text-align: center;
    position: relative;
}

h3::after {
    content: '';
    display: block;
    width: 80px;
    height: 4px;
    background: linear-gradient(45deg, #4CAF50, #2196F3);
    margin: 12px auto 0;
    border-radius: 2px;
}

/* 5. BUTTONS */
#testButton, button, input[type="button"] {
    cursor: pointer;
    transition: all 0.3s ease;
}

#testButton {
    display: block;
    margin: 0 auto 40px;
    padding: 16px 36px;
    font-size: 1.2rem;
    font-weight: 600;
    background: linear-gradient(45deg, #ff8a00, #e52e71);
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: 0 8px 20px rgba(255, 152, 0, 0.3);
}

#testButton:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 25px rgba(255, 152, 0, 0.4);
}

/* Add Rider & Paste buttons */
.team-section button {
    padding: 12px 24px;
    margin: 10px 8px 10px 0;
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
}

.team-section button:first-of-type {
    background: linear-gradient(45deg, #2196F3, #21CBF3);
    color: white;
}

.team-section button[onclick*="openPasteModal"] {
    background: #9b59b6;
    color: white;
}

/* Save button */
form > button:last-of-type {
    display: block;
    margin: 60px auto;
    padding: 20px 50px;
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: 0 12px 30px rgba(76, 175, 80, 0.4);
}

/* 6. FORM INPUTS */
form > div:first-of-type input {
    width: 700px;
    max-width: 95%;
    padding: 16px 24px;
    font-size: 1.2rem;
    border: 2px solid #ddd;
    border-radius: 14px;
    background-color: #fff;
    box-shadow: 0 6px 15px rgba(0,0,0,0.05);
}

.team-section > input[type="text"] {
    width: 450px;
    max-width: 100%;
    padding: 14px 20px;
    font-size: 1.1rem;
    border: 2px solid #ddd;
    border-radius: 12px;
    background-color: #f8f9fa;
}

/* 7. RIDER TABLES (ENTRY & RESULTS) */
.rider-table-wrapper {
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
}

.rider-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background-color: #fff;
}

.rider-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-size: 0.95rem;
    text-align: center;
}

.rider-table td {
    padding: 10px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

.rider-table input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background-color: #f8f9fa;
    font-size: 1rem;
}

/* 8. TEAM SECTION CARDS */
.team-section {
    background: #ffffff;
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 50px;
    box-shadow: 0 12px 35px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
}

/* 9. MODAL (Paste Power Curve) */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
}

.modal-content {
    background-color: #fff;
    margin: 8% auto;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 650px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.close {
    color: #999;
    float: right;
    font-size: 36px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #e74c3c;
}

#pasteArea {
    width: 100%;
    padding: 16px;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    border: 2px dashed #bbb;
    border-radius: 12px;
    background-color: #f8f9fa;
    resize: vertical;
}

/* 10. RESPONSIVE */
@media (max-width: 1200px) {
    .rider-table th, .rider-table td {
        padding: 8px 4px;
        font-size: 0.9rem;
    }
}

@media (max-width: 900px) {
    h1 { font-size: 2.2rem; }
    form > div:first-of-type input,
    .team-section > input[type="text"] {
        width: 100%;
    }
}

/* Button styling */
.button-group {
    margin-top: 15px;
    margin-bottom: 20px;
}

.button-group button {
    padding: 10px 15px;
    margin-right: 10px;
    background-color: #1976d2;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s;
}

.button-group button:hover {
    background-color: #1565c0;
}

/* Primary button for Save */
.primary-button {
    padding: 12px 24px;
    background-color: #2e7d32;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background-color 0.3s;
}

.primary-button:hover {
    background-color: #1b5e20;
}

/* Submit group centering */
.submit-group {
    text-align: center;
    margin: 30px 0;
}

.instructions {
    background-color: #e3f2fd;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 30px;
    font-size: 1em;
    line-height: 1.5;
}

.test-button-bottom {
    text-align: center;
    margin-top: 40px;
    padding: 20px 0;
    border-top: 1px solid #ddd;
}

.graphs-container {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    margin: 40px 0;
    gap: 30px;
}

.graph-wrapper {
    flex: 1;
    min-width: 300px;
    max-width: 500px;
    text-align: center;
}

.graph-wrapper canvas {
    height: 400px !important;
    width: 100% !important;
}

.graph-label {
    margin-top: 10px;
    font-weight: bold;
    color: #333;
}

.teams-grid {
    display: flex;
    gap: 40px;
    margin: 30px 0;
    justify-content: center;
    flex-wrap: wrap;
}

.team-column {
    flex: 1;
    min-width: 350px;
    max-width: 500px;
}

.team-column h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

.rider-paste-group {
    margin-bottom: 20px;
}

.rider-paste-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    color: #555;
}

.paste-area {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.95em;
    resize: vertical;
}

.paste-area:focus {
    border-color: #1976d2;
    outline: none;
}

/* Loading overlay */
#loading {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2em;
    text-align: center;
    padding: 2em;
    box-sizing: border-box;
}
.spinner {
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 1em;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* NEW: Sidebar Styles */
.sidebar-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    background: #28a745;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.9em;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1001;
    transition: background 0.3s;
}
.sidebar-toggle:hover { background: #218838; }
#racesCount { font-weight: bold; margin-left: 5px; }

.races-sidebar {
    position: fixed;
    top: 0;
    right: -350px;
    width: 340px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    transition: right 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
}
.races-sidebar.open { right: 0; }
.sidebar-header {
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-header h3 { margin: 0; font-size: 1.2em; }
.close-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.close-btn:hover { color: #dc3545; }
#racesList {
    list-style: none;
    padding: 0;
    margin: 0;
}
#racesList li {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}
#racesList li:hover {
    background: #f8f9fa;
}
#racesList li:last-child { border-bottom: none; }
#racesList strong { display: block; color: #1976d2; font-size: 1.1em; }
#racesList small { color: #666; }