/* ============================================
   WEATHER WIDGET - Lu Nibareddu
   Pattern: Expandable card with forecast
   ============================================ */

.home-weather-widget {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    cursor: pointer;

    border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);

    transition: all var(--duration-slower) var(--ease-modal);
}

/* Background Image */
.home-weather-widget .weather-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: auto;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;

    transition: opacity var(--duration-normal) var(--ease-out);
}

/* Overlay Content (collapsed state) */
.home-weather-widget .weather-overlay {
    position: absolute;
    inset: 0;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    padding: var(--space-6);

    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.05) 0%,
        rgba(0, 0, 0, 0.25) 100%
    );

    color: var(--text-inverse);
    text-align: center;

    transition: opacity var(--duration-normal) var(--ease-out);
}

.weather-location {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.9;

    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.weather-data {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2) 0;
}

.weather-icon {
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.weather-temp {
    font-family: var(--font-mono);
    font-size: var(--text-4xl);
    font-weight: var(--weight-regular);
    line-height: 1;

    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.weather-condition {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    opacity: 0.9;

    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* === EXPANDED STATE === */

.home-weather-widget.expanded {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: -20px;
    z-index: calc(var(--z-header) + 1);

    aspect-ratio: auto;
    border-radius: 0;

    cursor: default;
}

.home-weather-widget.expanded .weather-bg {
    height: 40%;
    object-position: center bottom;
}

.home-weather-widget.expanded .weather-overlay {
    opacity: 0;
    pointer-events: none;
}

/* Expanded Content */
.weather-expanded {
    position: absolute;
    inset: 0;

    display: none;
    flex-direction: column;

    padding: var(--space-6);
    padding-top: calc(var(--safe-area-top) + var(--space-6));
    padding-bottom: calc(var(--safe-area-bottom) + var(--space-6));

    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.3) 0%,
        rgba(0, 0, 0, 0.5) 100%
    );

    color: var(--text-inverse);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.home-weather-widget.expanded .weather-expanded {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding-bottom: calc(var(--nav-height, 64px) + var(--safe-area-bottom, 0px) + var(--space-4));
}

/* Expanded Header */
.weather-expanded-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-8);
}

.weather-logo {
    height: 32px;
    width: auto;
    filter: brightness(0) invert(1);
    opacity: 0.9;
}

.weather-close {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 40px;
    height: 40px;

    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    border: none;
    border-radius: var(--radius-full);

    color: var(--text-inverse);
    cursor: pointer;

    transition: background var(--duration-fast) var(--ease-out);
}

.weather-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.weather-close .material-symbols-outlined {
    font-size: 24px;
}

/* Expanded Main */
.weather-expanded-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;

    text-align: center;
}

.weather-forecast {
    flex-shrink: 0;
}

.weather-expanded-location {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    opacity: 0.9;
    margin-bottom: var(--space-4);

    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.weather-expanded-current {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-3);
}

.weather-expanded-icon {
    font-size: 56px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.weather-expanded-temp {
    font-family: var(--font-mono);
    font-size: 72px;
    font-weight: var(--weight-regular);
    line-height: 1;

    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.weather-expanded-condition {
    font-size: var(--text-lg);
    font-weight: var(--weight-medium);
    opacity: 0.9;

    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Expanded Details (wind, humidity, sunrise, sunset) */
.weather-expanded-details {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-4);
    justify-content: center;
}

.weather-expanded-details .weather-detail {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
    opacity: 0.9;
}

/* Forecast Section */
.weather-forecast {
    display: flex;
    justify-content: center;
    gap: var(--space-3);

    margin-top: var(--space-8);
    padding-top: var(--space-6);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.forecast-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);

    padding: var(--space-4);
    min-width: 80px;

    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);

    transition: background var(--duration-fast) var(--ease-out);
}

.forecast-day:hover {
    background: rgba(255, 255, 255, 0.15);
}

.forecast-day-name {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
}

.forecast-day-icon {
    font-size: 28px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.forecast-day-temp {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
}

/* Gesture Hint */
.weather-gesture-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);

    margin-top: var(--space-6);
    opacity: 0.6;
}

.gesture-pill {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-full);
}

.weather-gesture-hint span {
    font-size: var(--text-xs);
}

/* === ANIMATIONS === */

@keyframes weatherExpandIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.home-weather-widget.expanded .weather-expanded {
    animation: weatherExpandIn var(--duration-normal) var(--ease-out);
}

/* Safe area support */
@supports (padding-top: env(safe-area-inset-top)) {
    .weather-expanded {
        padding-top: calc(env(safe-area-inset-top) + var(--space-6));
        padding-bottom: calc(env(safe-area-inset-bottom) + 100px);
    }
}

/* Loading state */
.home-weather-widget.loading .weather-temp,
.home-weather-widget.loading .weather-expanded-temp {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* === FALLBACK (no image) === */
.home-weather-widget .weather-bg-fallback {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        var(--color-primary) 0%,
        var(--brand-sea-light) 50%,
        var(--brand-nature) 100%
    );
}

/* ============================================
   ANIMATED WEATHER THEMES — CSS gradient fallback
   Activated when no custom background image is available.
   All animations are CSS-only, lightweight, mobile-friendly.
   ============================================ */

/* --- Animated background layer --- */
.weather-animated-bg {
    display: none; /* hidden by default — shown when a theme class is active */
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    border-radius: inherit;
}

/* Show animated bg whenever a theme class is present */
.home-weather-widget[class*="weather-theme-"] .weather-animated-bg {
    display: block;
}

/* ---- Clear / Sunny ---- */
.home-weather-widget.weather-theme-clear {
    background: linear-gradient(180deg, #1a8fe3 0%, #62c4f7 55%, #87CEEB 100%);
}

/* Sun disc — large, subtle, top-right, slow rotation */
.home-weather-widget.weather-theme-clear .weather-animated-bg::before {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 230, 100, 0.55) 35%, rgba(255, 200, 50, 0.15) 65%, transparent 75%);
    animation: sunGlow 4s ease-in-out infinite;
}

/* Sun rays ring — rotates slowly */
.home-weather-widget.weather-theme-clear .weather-animated-bg::after {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background:
        repeating-conic-gradient(
            from 0deg,
            rgba(255, 220, 80, 0.18) 0deg 8deg,
            transparent 8deg 22.5deg
        );
    animation: sunRaysRotate 18s linear infinite;
    opacity: 0.7;
}

@keyframes sunGlow {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50%       { opacity: 0.55; transform: scale(1.06); }
}

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

/* ---- Partly Cloudy ---- */
.home-weather-widget.weather-theme-partly-cloudy {
    background: linear-gradient(180deg, #4a90c4 0%, #87CEEB 55%, #c4d8e8 100%);
}

/* Single soft cloud drifting slowly right-to-left */
.home-weather-widget.weather-theme-partly-cloudy .weather-animated-bg::before {
    content: '';
    position: absolute;
    top: 22%;
    left: 0;
    width: 160px;
    height: 60px;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.35);
    animation: cloudDrift 20s linear infinite;
}

.home-weather-widget.weather-theme-partly-cloudy .weather-animated-bg::after {
    content: '';
    position: absolute;
    top: 14%;
    left: 30%;
    width: 90px;
    height: 40px;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.22);
    animation: cloudDrift 28s linear infinite reverse;
    animation-delay: -10s;
}

@keyframes cloudDrift {
    from { transform: translateX(110%); }
    to   { transform: translateX(-110%); }
}

/* ---- Cloudy / Overcast ---- */
.home-weather-widget.weather-theme-cloudy {
    background: linear-gradient(180deg, #6b7d8e 0%, #8e9eab 55%, #b8c6d4 100%);
}

/* Two cloud layers at different speeds */
.home-weather-widget.weather-theme-cloudy .weather-animated-bg::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 0;
    width: 200px;
    height: 70px;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.20);
    animation: cloudDrift 15s linear infinite;
}

.home-weather-widget.weather-theme-cloudy .weather-animated-bg::after {
    content: '';
    position: absolute;
    top: 30%;
    left: 0;
    width: 240px;
    height: 80px;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.12);
    animation: cloudDrift 25s linear infinite;
    animation-delay: -8s;
}

/* ---- Fog / Mist ---- */
.home-weather-widget.weather-theme-fog {
    background: linear-gradient(180deg, #8e9eab 0%, #b0bec5 55%, #d4dde3 100%);
}

/* Horizontal fog bands fading in/out */
.home-weather-widget.weather-theme-fog .weather-animated-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        rgba(255, 255, 255, 0.18) 18px,
        transparent 36px
    );
    animation: fogPulse 6s ease-in-out infinite;
}

.home-weather-widget.weather-theme-fog .weather-animated-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        rgba(255, 255, 255, 0.10) 24px,
        transparent 48px
    );
    animation: fogPulse 9s ease-in-out infinite reverse;
    animation-delay: -3s;
}

@keyframes fogPulse {
    0%, 100% { opacity: 0.4; transform: translateY(0px); }
    50%       { opacity: 1;   transform: translateY(-6px); }
}

/* ---- Rain ---- */
.home-weather-widget.weather-theme-rain {
    background: linear-gradient(180deg, #3d5a7c 0%, #546e8a 55%, #7b8fa1 100%);
}

/* Diagonal falling streaks via repeating-linear-gradient */
.home-weather-widget.weather-theme-rain .weather-animated-bg::before {
    content: '';
    position: absolute;
    inset: -100% 0 0 0;
    height: 200%;
    background: repeating-linear-gradient(
        100deg,
        transparent 0px,
        transparent 6px,
        rgba(180, 210, 240, 0.25) 6px,
        rgba(180, 210, 240, 0.25) 7px
    );
    background-size: 30px 60px;
    animation: rainFall 1.5s linear infinite;
}

@keyframes rainFall {
    from { transform: translateY(0); }
    to   { transform: translateY(60px); }
}

/* ---- Snow ---- */
.home-weather-widget.weather-theme-snow {
    background: linear-gradient(180deg, #8fa8c8 0%, #b8cde0 55%, #dce6f0 100%);
}

/* Soft dots falling slowly using radial-gradient pattern */
.home-weather-widget.weather-theme-snow .weather-animated-bg::before {
    content: '';
    position: absolute;
    inset: -100% 0 0 0;
    height: 200%;
    background-image:
        radial-gradient(circle, rgba(255,255,255,0.75) 1.5px, transparent 1.5px),
        radial-gradient(circle, rgba(255,255,255,0.45) 1px,   transparent 1px);
    background-size: 28px 28px, 18px 18px;
    background-position: 0 0, 9px 9px;
    animation: snowFall 6s linear infinite;
}

@keyframes snowFall {
    from { transform: translateY(0); }
    to   { transform: translateY(50%); }
}

/* ---- Storm / Thunderstorm ---- */
.home-weather-widget.weather-theme-storm {
    background: linear-gradient(180deg, #2c3e50 0%, #3d5266 55%, #4a6072 100%);
}

/* Same rain streaks as rain theme */
.home-weather-widget.weather-theme-storm .weather-animated-bg::before {
    content: '';
    position: absolute;
    inset: -100% 0 0 0;
    height: 200%;
    background: repeating-linear-gradient(
        100deg,
        transparent 0px,
        transparent 6px,
        rgba(160, 200, 230, 0.30) 6px,
        rgba(160, 200, 230, 0.30) 7px
    );
    background-size: 30px 60px;
    animation: rainFall 1.2s linear infinite;
}

/* Lightning flash — brief opacity spike every 5 s */
.home-weather-widget.weather-theme-storm .weather-animated-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(220, 240, 255, 0.0);
    animation: lightningFlash 5s ease-in-out infinite;
    animation-delay: 2s;
}

@keyframes lightningFlash {
    0%, 88%, 92%, 96%, 100% { background: rgba(220, 240, 255, 0.0); }
    90%                      { background: rgba(220, 240, 255, 0.55); }
    94%                      { background: rgba(220, 240, 255, 0.20); }
}
