/* Weather Info Popup - v1 */
/* Integrated into TMD Rain Tracker Pro */

/* ===== Modal Overlay ===== */
#weather-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.6);
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0;
}

#weather-modal.open {
    display: flex;
}

/* ===== Modal Container ===== */
.wi-container {
    width: 100%;
    height: 100%;
    max-width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--wi-bg);
    color: var(--wi-text);
    font-family: 'Inter', 'Kanit', system-ui, sans-serif;
    position: relative;
    padding: 16px;
    padding-top: 80px;
    animation: wiFadeIn 0.3s ease;
}

@media (min-width: 769px) {
    .wi-container {
        max-width: 1100px;
        height: auto;
        max-height: 95vh;
        margin: 20px auto;
        border-radius: 24px;
        border: 1px solid var(--wi-border);
        box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
        padding: 24px;
        padding-top: 60px;
    }
}

@keyframes wiFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== CSS Variables (Dark default) ===== */
#weather-modal {
    --wi-bg: #101826;
    --wi-card-bg: rgba(15, 23, 42, 0.6);
    --wi-card-border: rgba(255, 255, 255, 0.08);
    --wi-glass-bg: rgba(30, 41, 59, 0.6);
    --wi-text: #ffffff;
    --wi-text-secondary: #94a3b8;
    --wi-accent-blue: #38bdf8;
    --wi-accent-gold: #fbbf24;
    --wi-border: rgba(255, 255, 255, 0.1);
    --wi-hover-bg: rgba(255, 255, 255, 0.05);
    --wi-track-bg: rgba(255, 255, 255, 0.12);
    --wi-overlay-bg: rgba(16, 24, 38, 0.65);
}

[data-theme='light'] #weather-modal {
    --wi-bg: #f1f5f9;
    --wi-card-bg: rgba(255, 255, 255, 0.9);
    --wi-card-border: rgba(0, 0, 0, 0.08);
    --wi-glass-bg: rgba(255, 255, 255, 0.8);
    --wi-text: #1e293b;
    --wi-text-secondary: #64748b;
    --wi-accent-blue: #2563eb;
    --wi-accent-gold: #d97706;
    --wi-border: rgba(0, 0, 0, 0.08);
    --wi-hover-bg: rgba(0, 0, 0, 0.03);
    --wi-track-bg: rgba(0, 0, 0, 0.1);
    --wi-overlay-bg: rgba(241, 245, 249, 0.8);
}

[data-theme='light'] #weather-modal {
    background: rgba(0, 0, 0, 0.3);
}

/* ===== Header ===== */
.wi-header {
    display: flex;
    justify-content: space-between;
    align-items: center; /* keep header items centered vertically */
    margin-bottom: 16px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    background: var(--wi-bg);
    padding: 16px;
    border-bottom: 1px solid var(--wi-border);
}

.wi-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap; /* allow wrapping on very small screens */
    flex: 1; /* take up available space */
}

@media (min-width: 769px) {
    .wi-header {
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 100%;
        max-width: 1100px;
        padding: 20px 24px;
        border-radius: 24px 24px 0 0;
        border: 1px solid var(--wi-border);
        border-bottom: none;
    }
}

.wi-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--wi-text);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    white-space: nowrap;
}

.wi-header h1 span {
    color: var(--wi-text-secondary);
    font-size: 14px;
    font-weight: 400;
}

.wi-location-badge {
    font-size: 12px;
    color: var(--wi-accent-blue);
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    word-break: break-word;
}

/* ===== Close Button ===== */
.wi-close-btn {
    /* relative to header now, not fixed to screen */
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--wi-card-bg);
    border: 1px solid var(--wi-card-border);
    color: var(--wi-text-secondary);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
    flex-shrink: 0; /* prevent shrinking */
    margin-left: 12px;
}

.wi-close-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

/* ===== Loading State ===== */
.wi-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 12px;
    color: var(--wi-text-secondary);
}

.wi-loading i {
    font-size: 28px;
    animation: spin 1s linear infinite;
}

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

/* ===== Overview Section ===== */
.wi-overview {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
    margin-bottom: 16px;
    align-items: stretch;
}

@media (max-width: 768px) {
    .wi-overview {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* ===== Glass Panel ===== */
.wi-glass {
    background: var(--wi-glass-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--wi-card-border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.wi-hero-city {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.wi-hero-temp {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.wi-hero-highlow {
    font-size: 14px;
    font-weight: 500;
    color: var(--wi-text-secondary);
}

/* ===== Hourly Scroll ===== */
.wi-hourly-wrap {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.wi-hourly-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--wi-text-secondary);
    text-transform: uppercase;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.wi-hourly-scroll {
    display: flex;
    overflow-x: auto;
    gap: 0;
    scrollbar-width: none;
    cursor: grab;
    user-select: none;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px;
}

.wi-hourly-scroll::-webkit-scrollbar { display: none; }
.wi-hourly-scroll:active { cursor: grabbing; }

.wi-h-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
    padding: 12px 6px;
    gap: 6px;
    flex-shrink: 0;
    border-radius: 12px;
    border: 1px solid transparent;
    transition: background 0.2s;
}

.wi-h-item:hover { background: var(--wi-hover-bg); }

.wi-h-item-now {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.wi-h-time {
    font-size: 13px;
    color: var(--wi-text-secondary);
    font-weight: 500;
}

.wi-h-item-now .wi-h-time {
    color: var(--wi-accent-blue);
    font-weight: 700;
}

.wi-h-icon { font-size: 26px; margin: 2px 0; }

.wi-h-temp {
    font-size: 16px;
    font-weight: 700;
}

.wi-h-pop {
    font-size: 12px;
    font-weight: 600;
    color: #7dd3fc;
    display: flex;
    align-items: center;
    gap: 4px;
}

.wi-h-wind {
    font-size: 11px;
    font-weight: 500;
    color: var(--wi-text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===== Daily Section ===== */
.wi-daily-wrap {
    margin-bottom: 24px;
}

.wi-daily-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--wi-text);
}

.wi-daily-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.wi-daily-list::-webkit-scrollbar {
    display: none;
}

.wi-daily-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px 12px;
    background: var(--wi-card-bg);
    border: 1px solid var(--wi-card-border);
    border-radius: 16px;
    min-width: 85px;
    flex: 0 0 auto;
}

.wi-daily-item:hover {
    background: rgba(255,255,255,0.06);
    transform: translateY(-2px);
}

[data-theme='light'] .wi-daily-item:hover {
    background: rgba(0,0,0,0.04);
}

.wi-d-day {
    font-weight: 600;
    font-size: 12px;
    color: var(--wi-text-secondary);
    margin-bottom: 4px;
}

.wi-d-icon { font-size: 24px; margin: 4px 0; }

.wi-d-temps {
    display: flex;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
}

.wi-d-temps span:first-child { color: var(--wi-text); }
.wi-d-temps span:last-child { color: var(--wi-text-secondary); }

.wi-d-pop {
    font-size: 10px;
    font-weight: 600;
    color: #7dd3fc;
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 4px;
}

/* ===== Section Label ===== */
.wi-section-label {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--wi-text);
}

/* ===== Weather Grid (Detail Cards) ===== */
.wi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

@media (max-width: 1100px) {
    .wi-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .wi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

@media (max-width: 420px) {
    .wi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

/* ===== Weather Card ===== */
.wi-card {
    background: var(--wi-card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--wi-card-border);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 220px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.wi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

@media (max-width: 768px) {
    .wi-card {
        padding: 12px;
        min-height: 180px;
        border-radius: 14px;
    }
}

.wi-card-label {
    font-size: 11px;
    color: var(--wi-text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.wi-card-main {
    flex: 1;
    display: flex;
    align-items: flex-end;
    margin-bottom: 10px;
}

.wi-card-footer {
    border-top: 1px solid var(--wi-card-border);
    padding-top: 10px;
    margin-top: auto;
}

.wi-status-line {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
    color: var(--wi-text);
}

.wi-status-line i {
    font-size: 14px;
    color: var(--wi-accent-blue);
}

.wi-desc-line {
    font-size: 11px;
    color: var(--wi-text-secondary);
    line-height: 1.4;
    margin: 0;
}

@media (max-width: 768px) {
    .wi-desc-line { font-size: 10px; }
    .wi-status-line { font-size: 11px; }
}

/* ===== Big Value ===== */
.wi-big-val {
    font-size: 32px;
    font-weight: 600;
    line-height: 1;
    color: var(--wi-text);
}

.wi-big-unit {
    font-size: 14px;
    font-weight: 400;
    color: var(--wi-text-secondary);
}

@media (max-width: 768px) {
    .wi-big-val { font-size: 26px; }
    .wi-big-unit { font-size: 12px; }
}

/* ===== Feels-like / Humidity Bar Track ===== */
.wi-bar-track {
    position: relative;
    width: 100%;
    height: 5px;
    background: var(--wi-track-bg);
    border-radius: 3px;
    overflow: visible;
}

.wi-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 1s cubic-bezier(.4,0,.2,1);
}

.wi-bar-dot {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 0 6px rgba(0,0,0,0.4);
    transition: left 1s cubic-bezier(.4,0,.2,1);
}

/* ===== Arc Gauge (UV, AQI, Pressure) ===== */
.wi-arc-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wi-arc-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 8px;
}

/* ===== Visibility Bars ===== */
.wi-vis-bar {
    height: 6px;
    border-radius: 3px;
    background: #55B17E;
    transition: width 0.8s cubic-bezier(.4,0,.2,1), background 0.3s;
}

/* ===== Wind Compass ===== */
.wi-wind-row {
    justify-content: space-between;
    align-items: center;
}

.wi-wind-compass {
    width: 80px;
    height: 80px;
    position: relative;
    background: rgba(255,255,255,0.03);
    border-radius: 50%;
    flex-shrink: 0;
}

[data-theme='light'] .wi-wind-compass {
    background: rgba(0,0,0,0.03);
}

.wi-compass-ring {
    position: absolute;
    top: 4px; left: 4px; right: 4px; bottom: 4px;
    border: 1px dashed rgba(255,255,255,0.15);
    border-radius: 50%;
}

[data-theme='light'] .wi-compass-ring {
    border-color: rgba(0,0,0,0.1);
}

.wi-compass-ring span {
    position: absolute;
    font-size: 9px;
    color: var(--wi-text-secondary);
    font-weight: 600;
}

.wi-compass-ring span:nth-child(1) { top: 4px; left: 50%; transform: translateX(-50%); }
.wi-compass-ring span:nth-child(2) { right: 4px; top: 50%; transform: translateY(-50%); }
.wi-compass-ring span:nth-child(3) { bottom: 4px; left: 50%; transform: translateX(-50%); }
.wi-compass-ring span:nth-child(4) { left: 4px; top: 50%; transform: translateY(-50%); }

.wi-wind-arrow-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wi-wind-arrow-wrap i {
    font-size: 32px;
    color: var(--wi-accent-blue);
    transition: transform 1.5s cubic-bezier(0.4,0,0.2,1);
}

.wi-wind-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wi-wind-stats .wi-ws-val {
    font-size: 16px;
    font-weight: 700;
    color: var(--wi-text);
}

.wi-wind-stats .wi-ws-unit {
    font-size: 10px;
    color: var(--wi-text-secondary);
}

/* ===== Solar Viz (Sun/Moon Arc) ===== */
.wi-solar-viz { width: 100%; }

.wi-solar-svg { width: 100%; display: block; }

.wi-solar-path-bg {
    fill: none;
    stroke: var(--wi-track-bg);
    stroke-width: 2.5;
    stroke-dasharray: 5 5;
    stroke-linecap: round;
}

.wi-solar-path-sun {
    fill: none;
    stroke: url(#wi-sun-arc-gradient);
    stroke-width: 3.5;
    stroke-linecap: round;
}

.wi-solar-path-moon {
    fill: none;
    stroke: url(#wi-moon-arc-gradient);
    stroke-width: 3.5;
    stroke-linecap: round;
}

.wi-horizon-line {
    stroke: rgba(255,255,255,0.12);
    stroke-width: 1;
    stroke-dasharray: 6 3;
}

[data-theme='light'] .wi-horizon-line {
    stroke: rgba(0,0,0,0.1);
}

.wi-solar-sun { fill: #fbbf24; filter: drop-shadow(0 0 4px rgba(251,191,36,0.8)); }
.wi-solar-moon { fill: #e2e8f0; filter: drop-shadow(0 0 4px rgba(226,232,240,0.6)); }

.wi-dot-hidden {
    display: none !important;
    opacity: 0 !important;
}

.wi-solar-dur {
    text-align: center;
    font-size: 11px;
    color: var(--wi-text-secondary);
    margin: 4px 0 6px;
    font-weight: 500;
}

.wi-solar-times {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.wi-solar-time {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.wi-solar-time .wi-st-time {
    font-size: 14px;
    font-weight: 600;
    color: var(--wi-text);
}

.wi-solar-time .wi-st-label {
    font-size: 10px;
    color: var(--wi-text-secondary);
    display: flex;
    gap: 3px;
    align-items: center;
    margin-top: 2px;
}

.wi-ampm-tag {
    color: var(--wi-text);
    font-weight: 600;
}

/* ===== Sparkline ===== */
.wi-sparkline {
    position: absolute;
    inset: 0;
}

.wi-sparkline svg {
    width: 100%;
    height: 100%;
}

/* ===== Scrollbar for modal ===== */
.wi-container::-webkit-scrollbar { width: 4px; }
.wi-container::-webkit-scrollbar-track { background: transparent; }
.wi-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
.wi-container::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

[data-theme='light'] .wi-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); }
[data-theme='light'] .wi-container::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }

/* ===== Error State ===== */
.wi-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 12px;
    color: var(--wi-text-secondary);
    text-align: center;
}

.wi-error i { font-size: 32px; color: #ef4444; }

.wi-error-btn {
    margin-top: 8px;
    padding: 8px 20px;
    border-radius: 10px;
    background: var(--wi-accent-blue);
    color: white;
    font-weight: 600;
    font-size: 13px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.wi-error-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}
