/* CSS Variables for easy customization */
:root {
    --primary-color: #1a365d;
    --primary-light: #2c5282;
    --secondary-color: #4299e1;
    --accent-color: #ed8936;
    --background: #f7fafc;
    --card-background: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --success-color: #48bb78;
    --error-color: #f56565;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-sm: 4px;
}

/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.site-header {
    background: var(--primary-color);
    color: white;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.site-title {
    font-size: 1.5rem;
    font-weight: 600;
}

.main-nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.nav-link:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
    color: white;
    background: var(--primary-light);
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state, .error {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--card-background);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.empty-state h2, .error h2 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.error h2 {
    color: var(--error-color);
}

.error button {
    margin-top: 1rem;
    padding: 0.5rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Search Section */
.search-section {
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.search-section h3 {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Athlete Search Results */
.athlete-results {
    margin-bottom: 2rem;
}

.athlete-card {
    background: var(--card-background);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary-color);
}

.athlete-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.athlete-header h4 {
    margin: 0;
    color: var(--primary-color);
}

.athlete-team {
    color: var(--text-secondary);
    font-weight: 500;
}

.athlete-info {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.athlete-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--background);
    border-radius: var(--radius-sm);
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.athlete-events {
    margin-top: 1rem;
}

.mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.mini-table th,
.mini-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.mini-table th {
    color: var(--text-muted);
    font-weight: 500;
}

.dropped-row {
    color: var(--text-muted);
    text-decoration: line-through;
}

/* Event List */
.event-list h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.event-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.event-card {
    background: var(--card-background);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.event-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--secondary-color);
}

.event-date {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.event-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.event-location {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.event-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

/* Race Results Page */
.race-results {
    background: var(--card-background);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.race-header {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem;
}

.back-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.2s;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.race-header h2 {
    margin-bottom: 0.5rem;
}

.race-info {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Filters */
.filters {
    display: flex;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.filter-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 0.875rem;
}

/* Results Layout */
.results-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
    padding: 1.5rem;
}

.results-main h3, .results-sidebar h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

.results-table, .standings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-table th, .standings-table th {
    background: var(--background);
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.results-table td, .standings-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.results-table tr:hover, .standings-table tr:hover {
    background: var(--background);
}

.results-table tr.dnf {
    color: var(--text-muted);
}

.total-time {
    font-weight: 600;
}

.points {
    font-weight: 600;
    color: var(--primary-color);
}

.no-results {
    color: var(--text-muted);
    font-style: italic;
    padding: 1rem;
}

.field-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: var(--background);
    border-radius: var(--radius-sm);
}

/* Team Standings Sidebar */
.team-standings {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.team-card {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary-color);
}

.team-place {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    min-width: 2rem;
}

.team-info {
    flex: 1;
}

.team-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.team-points {
    color: var(--accent-color);
    font-weight: 600;
    font-size: 0.9rem;
}

.team-scorers {
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.scorer {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: white;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
}

/* Season Standings */
.season-standings h2 {
    margin-bottom: 0.5rem;
}

.standings-meta {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Gender Tabs */
.gender-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.gender-tab {
    padding: 0.75rem 2rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.gender-tab:hover {
    color: var(--primary-color);
}

.gender-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Tabs */
.standings-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: var(--background);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: var(--border-color);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

.tab-content.hidden {
    display: none;
}

/* Race Breakdown */
.breakdown {
    font-size: 0.8rem;
}

.race-points {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    margin-right: 0.25rem;
}

.race-points.dropped {
    background: var(--error-color);
    color: white;
    opacity: 0.6;
    text-decoration: line-through;
}

.more-results {
    margin-top: 1rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Footer */
.site-footer {
    background: var(--primary-color);
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    padding: 1rem;
    font-size: 0.875rem;
}

/* Responsive Design */
@media (max-width: 900px) {
    .results-layout {
        grid-template-columns: 1fr;
    }

    .results-sidebar {
        order: -1;
    }
}

@media (max-width: 600px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .race-cards {
        grid-template-columns: 1fr;
    }

    .race-info {
        flex-direction: column;
        gap: 0.25rem;
    }

    .filters {
        flex-direction: column;
        gap: 0.75rem;
    }

    .results-table th, .results-table td,
    .standings-table th, .standings-table td {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.pagination-controls.pagination-bottom {
    border-bottom: none;
    border-top: 1px solid var(--border-color);
    margin-bottom: 0;
    margin-top: 1rem;
}

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-size-selector label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.page-size-selector select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 0.875rem;
}

.page-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.page-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: var(--background);
    border-color: var(--primary-color);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-number {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: 0 0.5rem;
}

/* Team All Racers (sidebar) */
.team-all-racers {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.team-racer {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    display: block;
}

.team-racer.scoring {
    background: var(--success-color);
    color: white;
    font-weight: 500;
}

.team-racer.non-scoring {
    background: var(--background);
    color: var(--text-muted);
}

/* Time Behind column */
.time-behind {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Run time with rank */
.run-time {
    position: relative;
    white-space: nowrap;
}

.run-rank {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-left: 1px;
    vertical-align: super;
    opacity: 0.7;
}

/* Print Styles */
@media print {
    .site-header, .site-footer, .filters, .back-btn, .standings-tabs, .pagination-controls {
        display: none !important;
    }

    .main-content {
        max-width: 100%;
        padding: 0;
    }

    .race-results {
        box-shadow: none;
    }

    .race-header {
        background: white;
        color: black;
        border-bottom: 2px solid black;
    }

    .results-layout {
        display: block;
    }

    .results-sidebar {
        margin-top: 2rem;
        page-break-before: always;
    }
}
