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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.4;
    font-size: 16px; /* Base font size for em calculations */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-container {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

.fixed-header {
    position: sticky;
    top: 0;
    background: white;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1em;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.75em;
}

.title-section {
    text-align: center;
}

h1 {
    color: #2c3e50;
    font-size: 2em;
    margin-right: 0.5em;
    display: inline;
}

.subtitle {
    font-size: 1.1em;
    color: #7f8c8d;
    display: inline;
}

.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1em;
}

.legend {
    display: flex;
    gap: 1.5em;
    flex-wrap: wrap;
    align-items: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4em;
    font-weight: 500;
    font-size: 0.9em;
}

.legend-color {
    width: 1.2em;
    height: 1.2em;
    border-radius: 3px;
    border: 1px solid #ddd;
    flex-shrink: 0;
}

.legend-color.flat {
    background-color: #2ecc71;
}

.legend-color.time-trial {
    background-color: #3498db;
}

.legend-color.mountain {
    background-color: #e67e22;
}

.legend-color.hilly {
    background-color: #e91e63;
}

.timezone-section {
    display: flex;
    align-items: center;
    gap: 0.75em;
}

.timezone-toggle {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.5em 0.75em;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: background-color 0.3s;
    white-space: nowrap;
}

.timezone-toggle:hover {
    background-color: #2980b9;
}

.timezone-current {
    font-size: 0.85em;
    color: #2c3e50;
    font-weight: 600;
    white-space: nowrap;
}

.timezone-controls {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 1em;
    margin-top: 0.75em;
    display: none;
    flex-wrap: wrap;
    gap: 1em;
    align-items: center;
    justify-content: center;
}

.timezone-controls.expanded {
    display: flex;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5em;
}

label {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9em;
}

select {
    padding: 0.4em 0.6em;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 0.85em;
    background: white;
    min-width: 280px;
    max-width: 400px;
}

select optgroup {
    font-weight: bold;
    color: #2c3e50;
    background-color: #f8f9fa;
}

select option {
    font-weight: normal;
    padding: 4px 8px;
}

select:focus {
    outline: none;
    border-color: #3498db;
}

.btn {
    padding: 0.4em 0.8em;
    border: none;
    border-radius: 4px;
    background-color: #3498db;
    color: white;
    font-size: 0.85em;
    cursor: pointer;
    transition: background-color 0.3s;
    white-space: nowrap;
}

.btn:hover {
    background-color: #2980b9;
}

.btn:active {
    transform: translateY(1px);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5em;
    width: 100%;
}

.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    flex: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background-color: #34495e;
    color: white;
    padding: 0.5em 0.6em;
    text-align: left;
    font-weight: 600;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 0.2em 0.5em;
    border-bottom: 1px solid #ecf0f1;
    font-size: 1em;
    vertical-align: middle;
}

tr:hover {
    background-color: #f0f0f0;
}

.today-row {
    background-color: #fff9e6;
}

.selected-row, .selected-row:hover {
    background-color: #e2eff9;
}

.stage-cell {
    font-weight: 600;
    text-align: center;
    color: white;
    border-radius: 3px;
    margin: 1px;
    padding: 0.4em;
    font-size: 1em;
    position: relative;
}

.stage-type-indicator {
    font-size: 0.7em;
    font-weight: normal;
    opacity: 0.8;
    margin-left: 0.3em;
    vertical-align: super;
}

.stage-flat {
    background-color: #2ecc71;
}

.stage-time-trial {
    background-color: #3498db;
}

.stage-mountain {
    background-color: #e67e22;
}

.stage-hilly {
    background-color: #e91e63;
}

.date-cell {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.85em;
}

.time-cell {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 1.1em;
    line-height: 1;
}

.date-indicator {
    font-size: 0.8em;
    color: #e74c3c;
    font-weight: normal;
    font-family: 'Segoe UI', sans-serif;
}

.date-indicator::before {
    content: ' (';
}

.date-indicator::after {
    content: ')';
}

.time-trial-indicator {
    font-size: 0.8em;
    color: #3498db;
    font-weight: 600;
    font-style: italic;
    font-family: 'Segoe UI', sans-serif;
}

.info-note {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 1em;
    margin-top: 1.5em;
}

.info-note p {
    font-size: 0.8em;
    color: #856404;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    .fixed-header {
        padding: 0.75em;
    }
    
    .main-content {
        padding: 1em;
    }
    
    h1 {
        font-size: 1.8em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    .controls-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75em;
    }
    
    .legend {
        justify-content: center;
        gap: 1em;
    }
    
    .timezone-section {
        justify-content: center;
    }
    
    .timezone-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        justify-content: space-between;
    }
    
    select {
        min-width: auto;
        flex: 1;
    }
    
    th {
        padding: 0.4em 0.4em;
        font-size: 0.85em;
    }
    
    td {
        padding: 0.3em 0.3em;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .table-container {
        overflow-x: auto;
    }
    
    table {
        min-width: 600px;
    }
    
    .legend {
        gap: 0.75em;
    }
    
    .legend-item {
        font-size: 0.8em;
    }
}
