/* ==========================================================================
   weather.css - Updated & Mobile Friendly
   Fixes: Screen Overflow, Horizontal Scroll, Mobile Stacking
   ========================================================================== */

:root {
    --bg-gradient: linear-gradient(135deg, #1e1e2f 0%, #0f0f1a 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    
    --accent: #7c4dff;
    --accent-hover: #9e7aff;
    --danger: #ff4757;
    --warning: #ffa502;
    --success: #2ed573;
    
    --font-main: 'Poppins', sans-serif;
    --transition: all 0.3s ease;
}

/* Dynamic Themes */
body.theme-sunny   { --bg-gradient: linear-gradient(135deg, #FF7E5F 0%, #FEB47B 100%); }
body.theme-rainy   { --bg-gradient: linear-gradient(135deg, #2b5876 0%, #4e4376 100%); }
body.theme-cloudy  { --bg-gradient: linear-gradient(135deg, #606c88 0%, #3f4c6b 100%); }
body.theme-night   { --bg-gradient: linear-gradient(135deg, #141E30 0%, #243B55 100%); }
body.theme-default { --bg-gradient: linear-gradient(135deg, #1e1e2f 0%, #0f0f1a 100%); }

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.8s ease;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Glassmorphism */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
}

/* Base Container */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Nav & Header */
.top-nav {
    display: flex;
    justify-content: flex-start;
    margin-bottom: -10px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--glass-border);
    transition: var(--transition);
}

.btn-back:hover { background: rgba(255, 255, 255, 0.2); transform: translateX(-3px); }

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    flex-wrap: wrap;
    gap: 20px;
}

.logo { font-size: 1.6rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.logo i { color: var(--accent); }

.header-controls {
    display: flex;
    flex-grow: 1;
    max-width: 500px;
    justify-content: flex-end;
}

.search-container {
    display: flex;
    gap: 10px;
    width: 100%;
    position: relative;
}

.search-container input {
    width: 100%;
    padding: 12px 20px;
    border-radius: 30px;
    outline: none;
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
    font-family: inherit;
    border: 1px solid var(--glass-border);
    font-size: 1rem;
}

.search-container input:focus { border-color: var(--accent); box-shadow: 0 0 10px rgba(124, 77, 255, 0.3); }

/* Quick Cities */
.popular-cities {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 0 10px;
}
.popular-cities span {
    font-size: 0.85rem;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    cursor: pointer;
    border: 1px solid var(--glass-border);
}
.popular-cities span:hover { background: var(--accent); border-color: var(--accent); }

/* Buttons */
.btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(124, 77, 255, 0.4);
    transition: var(--transition);
}
.btn:hover { background: var(--accent-hover); }

/* Main Grid - FIXED OVERFLOW ISSUE HERE */
.main-grid {
    display: grid;
    /* 1fr for left column, 2fr for right column. minmax(0, X) stops blowout */
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: 20px;
    width: 100%;
}

/* This targets the column wrappers inside .main-grid to prevent grid stretching */
.main-grid > div {
    min-width: 0;
}

/* Left Column Panels */
.current-weather {
    padding: 30px;
    text-align: center;
}
.current-weather .city { font-size: 2.2rem; font-weight: 600; }
.current-weather .date { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 20px; }
.current-weather .temp { font-size: 5.5rem; font-weight: 700; line-height: 1; margin: 15px 0; }
.current-weather .icon { font-size: 4.5rem; color: var(--accent); margin: 15px 0; }
.current-weather .desc { font-size: 1.3rem; font-weight: 500;}

.current-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 20px;
}
.detail-item {
    background: rgba(0,0,0,0.25);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 15px;
    border: 1px solid rgba(255,255,255,0.05);
}
.detail-item i { color: var(--accent); font-size: 1.4rem; }
.detail-item div p { margin: 0; font-size: 0.85rem; color: var(--text-secondary); text-align: left;}
.detail-item div h4 { margin: 0; font-size: 1.1rem; font-weight: 600;}

/* Highlights */
.grid-panel { padding: 25px; }
.grid-panel h3 { margin-bottom: 20px; font-weight: 600; display: flex; align-items: center; gap: 10px; font-size: 1.2rem;}

.highlights-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}
.highlight-card {
    background: rgba(0,0,0,0.25);
    padding: 15px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.05);
}
.highlight-card p { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 8px;}
.highlight-card h4 { font-size: 1.2rem; font-weight: 600;}

/* AQI */
.aqi-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.25);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 15px;
    border: 1px solid rgba(255,255,255,0.05);
}
.aqi-value { font-size: 2.8rem; font-weight: 700; line-height: 1;}
.aqi-desc { font-size: 1rem; font-weight: 600; padding: 6px 16px; border-radius: 20px; color: #000; }
.aqi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.aqi-item {
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
    font-size: 0.85rem;
}
.aqi-item b { display: block; font-size: 1.1rem; margin-top: 5px; color: #fff;}

/* 24-Hour Forecast Horizontal Scroll Fix */
.hourly-forecast {
    display: flex;
    gap: 15px;
    overflow-x: auto; /* Enables scrolling */
    padding-bottom: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) rgba(0,0,0,0.2);
    -webkit-overflow-scrolling: touch;
    width: 100%; /* Ensures it stays inside parent */
}
.hourly-forecast::-webkit-scrollbar { height: 8px; }
.hourly-forecast::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 10px; }

.hourly-item {
    min-width: 100px;
    flex-shrink: 0; /* Prevents squishing */
    background: rgba(0,0,0,0.25);
    padding: 15px 10px;
    border-radius: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 1px solid rgba(255,255,255,0.05);
}
.hourly-item i { font-size: 1.6rem; color: var(--text-primary); }

/* 7-Day Forecast Grid Fix */
.daily-forecast {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.daily-item {
    display: grid;
    /* Fixed proportions so elements don't get cut off */
    grid-template-columns: 50px 30px 60px 1fr;
    align-items: center;
    background: rgba(0,0,0,0.25);
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    gap: 15px;
}
.daily-item .day { font-weight: 500; font-size: 1.05rem;}
.daily-item .temps { display: flex; justify-content: space-between; font-size: 1rem; align-items: center;}
.daily-item .temp-bar {
    width: 100%;
    height: 6px;
    background: linear-gradient(90deg, #3498db, #e74c3c);
    border-radius: 5px;
    opacity: 0.8;
}

/* Map & Chart */
.map-container { width: 100%; height: 350px; border-radius: 12px; z-index: 1; }
.charts-container { width: 100%; height: 250px; }

/* Alerts */
.alert-box {
    background: rgba(255, 71, 87, 0.15);
    border-left: 5px solid var(--danger);
    padding: 15px 20px;
    border-radius: 0 12px 12px 0;
    display: none;
    align-items: center;
    gap: 20px;
}

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    color: transparent !important;
    border-radius: 8px;
}
@keyframes loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

footer { text-align: center; padding: 20px; color: var(--text-secondary); font-size: 0.9rem; }
footer a { color: var(--accent); text-decoration: none; }

/* ==========================================================================
   Mobile & Tablet Responsive Adjustments
   ========================================================================== */

/* Tablet mode */
@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr; /* Switch to single column */
    }
    .header-controls {
        max-width: 100%;
    }
}

/* Mobile mode */
@media (max-width: 768px) {
    .container { padding: 10px; gap: 15px; }
    
    header { padding: 15px; flex-direction: column; gap: 15px; }
    .search-container { width: 100%; }
    
    .current-weather { padding: 20px 15px; }
    .current-weather .temp { font-size: 4rem; }
    
    .current-details { grid-template-columns: 1fr; } /* Stack feels like, humidity, etc. */
    
    .aqi-grid { grid-template-columns: repeat(2, 1fr); }
    
    /* 7-Day forecast mobile fix */
    .daily-item {
        grid-template-columns: 1fr 1fr 1fr;
        padding: 12px 15px;
    }
    .daily-item .temp-bar { display: none; } /* Hide color bar on mobile to save space */
    .daily-item .temps { justify-content: flex-end; gap: 10px;}
    
    .map-container { height: 280px; }
}

@media (max-width: 480px) {
    .aqi-main { flex-direction: column; gap: 10px; text-align: center;}
    .highlights-grid { grid-template-columns: 1fr; } /* Stack highlights on tiny phones */
}