/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --background: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-color);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: white;
    padding: 1.5rem 2rem;
    text-align: center;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.header .subtitle {
    font-size: 0.95rem;
    opacity: 0.9;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    text-align: center;
}

/* Controls */
.controls-card {
    position: sticky;
    top: 52px;
    z-index: 100;
    background: var(--card-bg);
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 150px;
    flex: 1;
}

.control-group label,
.control-group .control-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.select-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.select-input:hover {
    border-color: var(--primary-color);
}

.select-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.range-input {
    width: 100%;
    cursor: pointer;
}

/* Maps */
.maps-card {
    padding: 1rem;
}

.maps-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.map-panel {
    background: #fafafa;
    border-radius: 6px;
    padding: 0.5rem;
}

.map-container {
    width: 100%;
    height: 450px;
    border-radius: 4px;
    overflow: hidden;
}

/* Status message */
.status-message {
    text-align: center;
    padding: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.status-message.error {
    color: #dc2626;
}

/* Datasets info grid */
.datasets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.dataset-card {
    background: var(--background);
    border-radius: 6px;
    padding: 1rem;
    border-left: 4px solid var(--primary-color);
}

.dataset-card h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.dataset-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.25rem 0;
}

.dataset-card.cerra_land { border-left-color: #1f77b4; }
.dataset-card.cerra_orig { border-left-color: #aec7e8; }
.dataset-card.era5 { border-left-color: #ff7f0e; }
.dataset-card.era5land { border-left-color: #2ca02c; }
.dataset-card.metno { border-left-color: #9467bd; }
.dataset-card.clms { border-left-color: #d62728; }

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    justify-content: center;
    gap: 0;
    background: var(--card-bg);
    padding: 0;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 200;
}

.tab-button {
    padding: 1rem 2rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab-button:hover {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Category map styles (generic climate index tabs) */
.category-map-panel {
    background: #fafafa;
    border-radius: 6px;
    padding: 0.5rem;
}

.category-map {
    height: 600px;
}

/* Category info panel (index definitions) */
.category-info {
    line-height: 1.8;
}

.category-info p {
    margin-bottom: 0.4rem;
}

.category-info b {
    color: var(--text-color);
}

.category-info sub,
.category-info sup {
    font-size: 0.75em;
}

/* T2M specific styles */
.t2m-map-panel {
    background: #fafafa;
    border-radius: 6px;
    padding: 0.5rem;
}

.t2m-map {
    height: 600px;
}

.t2m-info {
    line-height: 1.8;
}

.t2m-info p {
    margin-bottom: 0.5rem;
}

.t2m-info strong {
    color: var(--text-color);
}

/* Stations validation tab */
.stations-chart-panel {
    background: #fafafa;
    border-radius: 6px;
    padding: 0.5rem;
}

.stations-chart {
    height: 500px;
}

.model-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.model-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}

.model-toggle-label input[type="checkbox"] {
    cursor: pointer;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.stats-table th,
.stats-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.stats-table th {
    background: var(--background);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.stats-table tbody tr:nth-child(even) {
    background: var(--background);
}

.stats-table tbody tr:hover {
    background: #e0e7ff;
}

/* Guide tab */
.guide-card {
    line-height: 1.7;
    max-width: 860px;
}

.guide-card h3 {
    text-align: left;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.guide-card p {
    margin-bottom: 0.75rem;
}

.guide-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.92rem;
}

.guide-table th,
.guide-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

.guide-table th {
    background: var(--background);
    font-weight: 600;
}

.guide-table td:first-child {
    white-space: nowrap;
    width: 120px;
}

.guide-dl {
    margin: 0 0 1rem;
}

.guide-dl dt {
    font-weight: 600;
    margin-top: 0.75rem;
}

.guide-dl dd {
    margin-left: 1rem;
    color: var(--text-muted);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    margin-top: 2rem;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 900px) {
    .maps-container {
        grid-template-columns: 1fr;
    }

    .map-container {
        height: 350px;
    }

    .controls-row {
        flex-direction: column;
    }

    .control-group {
        width: 100%;
    }
}
