/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- Theme: dark (default) --- */
:root, [data-theme="dark"] {
    --bg: #0b1120;
    --bg-card: #141b2d;
    --bg-card-hover: #1a2340;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --accent: #38bdf8;
    --accent-dim: #0ea5e9;
    --border: #1e293b;
    --temp-hot: #ef4444;
    --temp-warm: #f97316;
    --temp-mild: #eab308;
    --temp-cool: #22d3ee;
    --temp-cold: #3b82f6;
    --aqi-good: #22c55e;
    --aqi-moderate: #eab308;
    --aqi-unhealthy: #f97316;
    --aqi-bad: #ef4444;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --chart-grid: rgba(255,255,255,0.06);
    --chart-label: rgba(148,163,184,0.6);
    --chart-cursor: rgba(255,255,255,0.3);
}

/* --- Theme: light-sunny (daytime, clear/mostly clear) --- */
[data-theme="light-sunny"] {
    --bg: #fefce8;
    --bg-card: #ffffff;
    --bg-card-hover: #fef9c3;
    --text: #1c1917;
    --text-dim: #78716c;
    --accent: #d97706;
    --accent-dim: #b45309;
    --border: #fbbf24;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --chart-grid: rgba(0,0,0,0.06);
    --chart-label: rgba(120,113,108,0.7);
    --chart-cursor: rgba(0,0,0,0.85);
}

/* --- Theme: light-cloudy (daytime, cloud cover > 50%) --- */
[data-theme="light-cloudy"] {
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --bg-card-hover: #e2e8f0;
    --text: #1e293b;
    --text-dim: #64748b;
    --accent: #0284c7;
    --accent-dim: #0369a1;
    --border: #cbd5e1;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --chart-grid: rgba(0,0,0,0.06);
    --chart-label: rgba(100,116,139,0.7);
    --chart-cursor: rgba(0,0,0,0.85);
}

/* --- Theme: twilight (civil twilight) --- */
[data-theme="twilight"] {
    --bg: #1c1022;
    --bg-card: #27182f;
    --bg-card-hover: #2f1f38;
    --text: #e2d8ea;
    --text-dim: #a78bba;
    --accent: #fb923c;
    --accent-dim: #ea580c;
    --border: #ea580c;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --chart-grid: rgba(255,255,255,0.06);
    --chart-label: rgba(167,139,186,0.6);
    --chart-cursor: rgba(255,255,255,0.3);
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Header ===== */
header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

.search-wrap {
    flex: 1;
    max-width: 400px;
    position: relative;
}

#searchInput {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

#searchInput:focus { border-color: var(--accent); }

.search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    box-shadow: var(--shadow);
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
}

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

.search-item {
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.selected { background: var(--bg-card-hover); }
.search-item .country { color: var(--text-dim); font-size: 0.8rem; }

.local-clock {
    color: var(--text-dim);
    font-size: 0.8rem;
    font-family: monospace;
    white-space: nowrap;
    margin-left: auto;
}

.local-clock:empty { display: none; }

.units-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0 0.6rem;
    height: 38px;
    border-radius: 19px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.units-btn:hover { background: var(--bg-card-hover); }

.geo-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: 1.4rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.geo-btn:hover { background: var(--bg-card-hover); }

/* ===== Main Layout ===== */
main {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    width: 100%;
}

.hidden { display: none !important; }

.loading {
    display: flex;
    justify-content: center;
    padding: 4rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.welcome {
    text-align: center;
    padding: 6rem 2rem;
    color: var(--text-dim);
}

.welcome h2 { font-size: 2rem; margin-bottom: 0.5rem; color: var(--text); }

/* ===== Current Conditions ===== */
.current-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.current-location h2 {
    font-size: 1.6rem;
    font-weight: 600;
}

.current-location p { color: var(--text-dim); font-size: 0.9rem; }

.current-main {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.current-temp-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.weather-icon-lg { font-size: 3.5rem; }

.current-temp {
    font-size: 4rem;
    font-weight: 300;
    line-height: 1;
}

.condition-text { font-size: 1.2rem; margin-bottom: 0.25rem; }
.feels-like { color: var(--text-dim); font-size: 0.9rem; }
.high-low { color: var(--text-dim); font-size: 0.9rem; }

.current-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-value { font-size: 1rem; font-weight: 500; margin-top: 0.15rem; }

/* ===== Current Layout ===== */
.current-layout {
    display: flex;
    gap: 1.5rem;
}

.current-left { flex: 1; }

/* ===== Holidays ===== */
.holidays-list {
    flex: 0 0 220px;
    border-left: 1px solid var(--border);
    padding-left: 1.5rem;
}

.holidays-list:empty { display: none; }

.holidays-list h4 {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.holiday-item {
    display: flex;
    flex-direction: column;
    padding: 0.3rem 0;
    font-size: 0.85rem;
}

.holiday-name { color: var(--text); }
.holiday-date { color: var(--text-dim); font-size: 0.75rem; }

@media (max-width: 768px) {
    .current-layout { flex-direction: column; }
    .holidays-list {
        flex: none;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-left: 0;
        padding-top: 1rem;
    }
}

/* ===== Astronomy ===== */
.astro-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.astro-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background 0.2s;
}

.astro-card:hover { background: var(--bg-card-hover); }

.astro-card h4 { font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; margin-bottom: 0.5rem; }
.astro-row { display: flex; justify-content: space-between; padding: 0.3rem 0; font-size: 0.9rem; }
.astro-row .label { color: var(--text-dim); }
.day-offset { font-size: 0.7em; color: var(--text-dim); vertical-align: super; }

/* ===== Hourly ===== */
.hourly-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    min-width: 0;
    overflow: hidden;
}

.hourly-section h3 { font-size: 1rem; margin-bottom: 0.75rem; }

.hourly-scroll {
    display: flex;
    flex-wrap: nowrap;
    gap: 0;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    -webkit-overflow-scrolling: touch;
    user-select: none;
    cursor: grab;
    padding-top: 1rem;
}

.hourly-scroll:active { cursor: grabbing; }

.hourly-item {
    flex: 0 0 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    position: relative;
    padding: 0.5rem 0.25rem;
    font-size: 0.8rem;
    border-right: 1px solid var(--border);
}

.hourly-item:last-child { border-right: none; }
.hourly-day { color: var(--accent); font-size: 0.7rem; font-weight: 600; position: absolute; top: -0.9rem; }
.hourly-time { color: var(--text-dim); font-size: 0.75rem; }
.hourly-icon { font-size: 1.3rem; }
.hourly-temp { font-weight: 600; }
.hourly-precip { color: var(--accent); font-size: 0.7rem; }

/* ===== Chart ===== */
.chart-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.chart-section h3 { font-size: 1rem; margin-bottom: 0.5rem; }

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.2s;
}

.legend-item.off { opacity: 0.3; }

.legend-swatch {
    width: 14px;
    height: 3px;
    border-radius: 1px;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: 175px;
}

#chartCanvasTop, #chartCanvasBot {
    display: block;
    width: 100%;
    height: 175px;
}

.chart-tooltip {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    font-size: 0.8rem;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
    box-shadow: var(--shadow);
}

.chart-tooltip .tt-time { color: var(--text-dim); margin-bottom: 0.3rem; font-size: 0.75rem; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 0.4rem; padding: 0.1rem 0; }
.chart-tooltip .tt-swatch { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chart-tooltip .tt-label { color: var(--text-dim); }
.chart-tooltip .tt-value { font-weight: 500; margin-left: auto; padding-left: 0.5rem; }

.chart-cursor {
    position: absolute;
    top: 0;
    width: 1px;
    height: 100%;
    background: var(--text-dim);
    opacity: 0.4;
    pointer-events: none;
}

/* ===== Daily ===== */
.daily-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.daily-section h3 { font-size: 1rem; margin-bottom: 0.75rem; }

.daily-row {
    display: grid;
    grid-template-columns: 100px 40px 1fr 60px 60px;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    gap: 0.5rem;
}

.daily-row:last-child { border-bottom: none; }
.daily-day { font-weight: 500; }
.daily-icon { font-size: 1.3rem; text-align: center; }
.daily-desc { color: var(--text-dim); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.daily-high { font-weight: 600; text-align: right; }
.daily-low { color: var(--text-dim); text-align: right; }

.daily-bar-wrap {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    position: relative;
    flex: 1;
}

/* ===== Air Quality ===== */
.air-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.air-section h3 { font-size: 1rem; margin-bottom: 0.75rem; }

.air-content {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.aqi-badge {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.aqi-badge .aqi-label { font-size: 0.6rem; font-weight: 400; text-transform: uppercase; }
.aqi-details { display: flex; flex-wrap: wrap; gap: 1rem; }
.aqi-item .aqi-item-label { font-size: 0.75rem; color: var(--text-dim); }
.aqi-item .aqi-item-value { font-size: 1rem; font-weight: 500; }

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 1;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover { color: var(--text); }

.date-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.date-nav-label {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-right: 0.25rem;
}

.date-nav input[type="date"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    font-size: 0.9rem;
}

.date-nav-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s;
}

.date-nav-btn:hover { background: var(--bg-card-hover); }

.modal-section { margin-bottom: 1.25rem; }
.modal-section h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--accent); }
.modal-section h4 { font-size: 0.85rem; margin: 0.5rem 0 0.25rem; color: var(--text-dim); text-transform: uppercase; }

.modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.25rem 2.5rem;
}

.modal-item {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.85rem;
}

.modal-item .mi-label { color: var(--text-dim); }
.modal-item .mi-value { font-weight: 500; }

/* ===== Footer ===== */
footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-dim);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .astro-section { grid-template-columns: 1fr; }
    .current-temp { font-size: 3rem; }
    .weather-icon-lg { font-size: 2.5rem; }
    .daily-row { grid-template-columns: 80px 30px 1fr 50px 50px; font-size: 0.85rem; }
}

@media (max-width: 600px) {
    .header-inner { flex-wrap: wrap; }
    .search-wrap { max-width: none; order: 10; flex-basis: 100%; margin-top: 0.5rem; }
    .local-clock { order: 9; flex-basis: 100%; text-align: right; margin-top: 0.25rem; }
    .current-main { flex-direction: column; align-items: flex-start; }
}
