/* Oregon Water Temperature Forecasts — Main Stylesheet */

:root {
    --primary: #1a5276;
    --primary-light: #2980b9;
    --accent: #27ae60;
    --danger: #c0392b;
    --warm: #e67e22;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #dce1e6;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

header .subtitle {
    font-size: 0.85rem;
    opacity: 0.85;
    margin-top: 2px;
}

header .subtitle a {
    color: white;
    text-decoration: underline;
    opacity: 0.9;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    position: relative;
}

.search-box input {
    padding: 8px 14px;
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
    width: 260px;
    background: rgba(255,255,255,0.2);
    color: white;
    outline: none;
    transition: background 0.2s;
}

.search-box input::placeholder { color: rgba(255,255,255,0.6); }
.search-box input:focus { background: rgba(255,255,255,0.35); }

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 2000;
}

.search-results.active { display: block; }

.search-result-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 0.85rem;
}

.search-result-item:hover { background: #f0f4f8; }
.search-result-item .source-tag {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--primary-light);
    color: white;
    margin-right: 6px;
}

#legendBtn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}
#legendBtn:hover { background: rgba(255,255,255,0.35); }

/* Legend */
.legend {
    position: absolute;
    top: 80px;
    right: 20px;
    background: white;
    padding: 16px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 1500;
    font-size: 0.85rem;
    min-width: 220px;
    transition: opacity 0.2s, transform 0.2s;
}

.legend.hidden { display: none; }

.legend h3 { margin-bottom: 10px; color: var(--primary); font-size: 0.95rem; }
.legend hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
    font-size: 0.8rem;
}

.dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Map */
main {
    flex: 1;
    display: flex;
    position: relative;
}

#map {
    flex: 1;
    min-height: 500px;
}

/* Sidebar */
.sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 90vw;
    height: 100%;
    background: white;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    z-index: 1200;
    overflow-y: auto;
    padding: 20px;
    transition: transform 0.3s ease;
}

.sidebar.hidden { transform: translateX(100%); }

.close-btn {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    color: var(--text-light);
    line-height: 1;
}

.sidebar h2 { font-size: 1.1rem; margin-bottom: 4px; padding-right: 30px; }
.sidebar .meta { font-size: 0.8rem; color: var(--text-light); margin-bottom: 16px; }

.sidebar .temp-display {
    text-align: center;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.sidebar .temp-display .temp-value {
    font-size: 2.8rem;
    font-weight: 700;
    line-height: 1.1;
}

.sidebar .temp-display .temp-label {
    font-size: 0.85rem;
    margin-top: 4px;
    opacity: 0.8;
}

.sidebar .mini-forecast {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 16px;
}

.sidebar .mini-forecast .day {
    text-align: center;
    padding: 8px 2px;
    border-radius: 6px;
    font-size: 0.7rem;
    background: #f8f9fa;
}

.sidebar .mini-forecast .day .temp {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 4px 0;
}

.sidebar .detail-link {
    display: block;
    text-align: center;
    padding: 10px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.sidebar .detail-link:hover { background: var(--primary-light); }

.sidebar canvas { margin: 12px 0; }

/* Status bar */
.status-bar {
    background: var(--primary);
    color: white;
    padding: 6px 24px;
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    opacity: 0.9;
}

/* Station detail page */
.station-detail {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
}

.station-header {
    margin-bottom: 24px;
}

.station-header h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.station-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-light);
    flex-wrap: wrap;
}

.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--primary-light);
    color: white;
}

.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.card h3 {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 8px;
    font-weight: 500;
}

.big-number {
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.2;
}

.sub-text {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 4px;
}

.current-temp { border-left: 4px solid var(--primary-light); }

.chart-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.chart-section h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--primary);
}

.forecast-table {
    margin-top: 12px;
    overflow-x: auto;
}

.forecast-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.forecast-table th,
.forecast-table td {
    padding: 8px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.forecast-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: var(--text-light);
}

.weather-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.weather-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    font-size: 0.8rem;
}

.weather-card .wx-name { font-weight: 600; margin-bottom: 4px; }
.weather-card .wx-temp { font-size: 1.3rem; font-weight: 700; margin: 4px 0; }
.weather-card .wx-desc { color: var(--text-light); font-size: 0.75rem; }

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-light);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

.hidden { display: none !important; }

.error-msg {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: var(--danger);
    padding: 16px;
    border-radius: 8px;
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    header { padding: 10px 16px; }
    header h1 { font-size: 1.1rem; }
    .search-box input { width: 180px; }
    .sidebar { width: 100%; }
    .cards-row { grid-template-columns: 1fr; }
    .station-detail { padding: 12px; }
}

/* Temperature color utilities */
.temp-cold { color: #2166ac; }
.temp-cool { color: #67a9cf; }
.temp-moderate { color: #5a5a5a; }
.temp-warm { color: #ef8a62; }
.temp-hot { color: #b2182b; }
.temp-critical { color: #67001f; }

.bg-cold { background: #d1e5f0; }
.bg-cool { background: #e0f0f8; }
.bg-moderate { background: #f7f7f7; }
.bg-warm { background: #fde0cc; }
.bg-hot { background: #f4a582; }
.bg-critical { background: #b2182b; color: white; }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal.hidden { display: none; }
.modal-content {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 420px;
    width: 90%;
    position: relative;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal-content h2 { margin-bottom: 16px; color: var(--primary); }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--primary-light); }

/* Download buttons */
.download-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 12px 0;
}
.dl-btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: #f8f9fa;
    color: var(--text);
    transition: background 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.dl-btn:hover { background: #e2e8f0; }
.dl-btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.dl-btn.primary:hover { background: var(--primary-light); }

/* Sponsor banner */
.sponsor-bar {
    background: #f8f9fa;
    text-align: center;
    padding: 4px 16px;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 1px solid #eef2f6;
}
.sponsor-bar:empty { display: none; }
.sponsor-bar a { display: inline-block; line-height: 0; }
.sponsor-bar img { max-width: 728px; width: 100%; height: auto; border-radius: 4px; }
.sponsor-label {
    font-size: 0.6rem;
    color: #bbb;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    writing-mode: vertical-rl;
}

/* Coefficient table */
.coef-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin-bottom: 12px;
}
.coef-table th {
    background: #f8f9fa;
    padding: 8px 10px;
    text-align: center;
    font-weight: 600;
    color: var(--text-light);
    border-bottom: 2px solid var(--border);
    font-size: 0.78rem;
}
.coef-table td {
    padding: 6px 10px;
    text-align: center;
    border-bottom: 1px solid #f0f0f0;
}
.coef-table tr:hover { background: #fafbfc; }
