/* --- Global Styles & Variables --- */
:root {
    /* Day Theme */
    --body-bg-day: linear-gradient(135deg, #e0f2f7 0%, #a7d9eb 100%); /* Light blue, airy */
    --text-color-day: #333;
    --card-bg-day: rgba(255, 255, 255, 0.8);
    --card-border-day: #e0e0e0;
    --shadow-color-day: rgba(0, 0, 0, 0.1);
    --btn-bg-day: #f0f0f0;
    --btn-text-day: #555;
    --btn-active-bg-day: #007bff; /* Bootstrap primary blue */
    --btn-active-text-day: #fff;
    --footer-bg-day: linear-gradient(135deg, rgba(240, 240, 240, 0.9) 0%, rgba(220, 220, 220, 0.9) 100%);
    --footer-text-day: #555;
    --link-color-day: #007bff;

    /* Night Theme */
    --body-bg-night: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%); /* Dark blue-gray */
    --text-color-night: #e0e0e0;
    --card-bg-night: rgba(44, 62, 80, 0.8);
    --card-border-night: #3a4a5b;
    --shadow-color-night: rgba(0, 0, 0, 0.4);
    --btn-bg-night: #34495e;
    --btn-text-night: #c0c0c0;
    --btn-active-bg-night: #00bcd4; /* Cyan accent for night */
    --btn-active-text-night: #fff;
    --footer-bg-night: linear-gradient(135deg, rgba(30, 40, 50, 0.9) 0%, rgba(20, 30, 40, 0.9) 100%);
    --footer-text-night: #c0c0c0;
    --link-color-night: #00bcd4;

    /* Transitions */
    --transition-speed: 0.5s ease-in-out;
}

/* General overflow prevention - USE WITH CAUTION */
/* This will hide any content that extends beyond the viewport horizontally.
   It's better to fix the specific overflowing element, but this can be a fallback. */

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Quicksand', sans-serif; /* Default font */
    color: var(--text-color-day); /* Default to day text color */
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

body {
    min-height: 100vh; /* Use vh for full viewport height */
    min-width: 100vw;
    background: var(--body-bg-day); /* Default to day background */
    background-repeat: no-repeat;
    background-attachment: fixed;
    transition: background var(--transition-speed), color var(--transition-speed);
    display: flex;
    flex-direction: column;
}

/* --- Theme Specific Styles --- */
body.theme-light {
    background: var(--body-bg-day);
    color: var(--text-color-day);
}
.theme-light .card-weather,
.theme-light .card-details,
.theme-light .card-uv-index {
    background: var(--card-bg-day);
    border: 1px solid var(--card-border-day);
    box-shadow: 0 4px 15px var(--shadow-color-day);
}
.theme-light .navbar,
.theme-light .footer {
    background: var(--footer-bg-day); /* Navbar and footer share footer background */
}
.theme-light .brand-text,
.theme-light .sub-brand-text,
.theme-light .footer-text {
    color: var(--footer-text-day) !important; /* !important for text-muted override */
}
.theme-light .footer-link {
    color: var(--link-color-day);
}
.theme-light .hourly-nav-btn {
    background-color: var(--btn-bg-day);
    color: var(--btn-text-day);
    border-color: var(--btn-text-day);
}
.theme-light .hourly-nav-btn.active {
    background-color: var(--btn-active-bg-day);
    color: var(--btn-active-text-day);
    border-color: var(--btn-active-bg-day);
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5); /* Blue glow */
    transform: translateY(-2px); /* Slight lift */
}
.theme-light .theme-toggle-btn {
    background-color: var(--btn-bg-day);
    color: var(--btn-text-day);
    border-color: var(--btn-text-day);
}
.theme-light .theme-toggle-btn .fa-moon { display: inline-block; }
.theme-light .theme-toggle-btn .fa-sun { display: none; }


body.theme-dark {
    background: var(--body-bg-night);
    color: var(--text-color-night);
}
.theme-dark .card-weather,
.theme-dark .card-details,
.theme-dark .card-uv-index {
    background: var(--card-bg-night);
    border: 1px solid var(--card-border-night);
    box-shadow: 0 4px 15px var(--shadow-color-night);
}
.theme-dark .navbar,
.theme-dark .footer {
    background: var(--footer-bg-night);
}
.theme-dark .brand-text,
.theme-dark .sub-brand-text,
.theme-dark .footer-text {
    color: var(--footer-text-night) !important;
}
.theme-dark .footer-link {
    color: var(--link-color-night);
}
.theme-dark .hourly-nav-btn {
    background-color: var(--btn-bg-night);
    color: var(--btn-text-night);
    border-color: var(--btn-text-night);
}
.theme-dark .hourly-nav-btn.active {
    background-color: var(--btn-active-bg-night);
    color: var(--btn-active-text-night);
    border-color: var(--btn-active-bg-night);
    box-shadow: 0 0 15px rgba(0, 188, 212, 0.7); /* Cyan glow */
    transform: translateY(-2px); /* Slight lift */
}
.theme-dark .theme-toggle-btn {
    background-color: var(--btn-bg-night);
    color: var(--btn-text-night);
    border-color: var(--btn-text-night);
}
.theme-dark .theme-toggle-btn .fa-moon { display: none; }
.theme-dark .theme-toggle-btn .fa-sun { display: inline-block; }


/* --- Layout & Typography --- */
.main-font {
    font-family: 'Quicksand', sans-serif;
}

.sub-font {
    font-family: 'Ubuntu Mono', monospace;
}

/* --- Navbar --- */
.navbar {
    padding: 0.8rem 1rem; /* Keep padding consistent */
    transition: background var(--transition-speed);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    justify-content: space-between; /* This should push brand left, toggle right */
    align-items: center; /* Vertically align items in the navbar */
}

.navbar-brand {
    display: flex;
    align-items: center;
    font-size: 1.5rem; /* Smaller font for mobile brand */
    font-weight: 600;
    margin-right: auto; /* Push content to the right */
}
.weather-icon-brand {
    margin-right: 8px; /* Slightly less margin to reduce brand width */
    font-size: 1.2em; /* Smaller icon for mobile brand */
}
.sub-brand-text {
    font-size: 0.55em; /* Make it even smaller */
    opacity: 0.8;
}

.theme-toggle-btn {
    font-size: 0.8rem; /* Smaller font size for the button */
    padding: 6px 10px; /* Smaller padding */
    border-radius: 50%; /* Make it a circle */
    width: 40px; /* Fixed width for circle */
    height: 40px; /* Fixed height for circle */
    display: flex; /* Use flex to center icon */
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevent it from shrinking too much */
}
.theme-toggle-btn span {
    display: none; /* Hide "Toggle Theme" text on mobile */
}

#content {
    flex-grow: 1;
    padding-top: 20px;
    padding-bottom: 20px;
    max-width: 1300px; /* Increased max-width for the main content area */
    margin-left: auto;
    margin-right: auto;
    width: 95%; /* Use a percentage to ensure it's not too wide but allows some padding */
}

/* --- Hourly Navigation --- */
.hourly-nav-row {
    margin-bottom: 20px;
    position: relative; /* For the fade effects */
    padding: 0 10px; /* Adjust padding to make room for shadows */
}
.hourly-nav-wrapper {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto; /* Keep horizontal scroll on mobile */
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */

    flex-wrap: nowrap; /* Default for mobile: no wrap, allow scroll */
    justify-content: flex-start;
}
/* Hide scrollbar for Webkit browsers (Chrome, Safari) */
.hourly-nav-wrapper::-webkit-scrollbar {
    display: none;
    height: 0; /* Ensures no scrollbar track visible */
}

.hourly-nav-btn {
    min-width: 70px; /* Adjusted to prevent cut-off */
    width: auto; /* Allow width to expand with content */
    flex-shrink: 0;
    margin: 0 5px;
    border-radius: 25px;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
    font-family: 'Ubuntu Mono', monospace;
    font-weight: bold;
    padding: 8px 12px;
    white-space: nowrap; /* Prevent text from wrapping inside button */
    font-size: 1rem; /* Ensure legible size */
    box-sizing: border-box; /* Ensure padding is included in width calculation */
}
.hourly-nav-btn:hover {
    opacity: 0.9;
}
.hourly-nav-btn.active {
    font-weight: bolder;
}

/* Add a visual cue for scrollability (optional but recommended) */
.hourly-nav-row::before,
.hourly-nav-row::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20px; /* Width of the fade effect */
    pointer-events: none; /* Allows clicks/taps through */
    z-index: 2; /* Ensure it's above the buttons */
}
.hourly-nav-row::before {
    left: 0;
    background: linear-gradient(to right, var(--body-bg-day) 0%, rgba(255,255,255,0) 100%);
}
.hourly-nav-row::after {
    right: 0;
    background: linear-gradient(to left, var(--body-bg-day) 0%, rgba(255,255,255,0) 100%);
}

/* Adjust fade effect for night theme */
body.theme-dark .hourly-nav-row::before {
    background: linear-gradient(to right, var(--body-bg-night) 0%, rgba(0,0,0,0) 100%);
}
body.theme-dark .hourly-nav-row::after {
    background: linear-gradient(to left, var(--body-bg-night) 0%, rgba(0,0,0,0) 100%);
}

/* --- Main Carousel --- */
.main-carousel {
    padding: 0 50px; /* Add horizontal padding to the carousel container itself */
    padding-bottom: 20px;
    border-radius: 15px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    min-height: 400px; /* Keep a reasonable minimum height for structure */
}

.carousel-item {
    padding: 20px 0; /* Remove horizontal padding here since .main-carousel now has it */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Align content to top of carousel item */
    width: 100%;
}

/* Carousel controls */
.carousel-control-prev,
.carousel-control-next {
    width: 30px; /* Smaller width for mobile controls */
    opacity: 0.7;
    transition: opacity 0.2s ease;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10; /* Ensure arrows are above cards if needed */
    height: 100%; /* Make them span full height to make tapping easier */
}

.carousel-control-prev {
    left: 0; /* Align left arrow to the left edge of the carousel container */
}

.carousel-control-next {
    right: 0; /* Align right arrow to the right edge */
}

.carousel-control-prev-icon,
.carousel-control-next-icon {
    width: 20px; /* Smaller visual icon */
    height: 20px;
    background-size: 100% 100%; /* Ensure icon fills its container */
}

/* --- Weather Cards Layout --- */
.weather-cards-grid {
    display: grid;
    grid-template-columns: 1fr; /* Default to single column for small screens */
    gap: 20px; /* Space between cards */
    width: 100%;
    max-width: 100%; /* Initially allow full width within carousel item */
    margin-top: 20px;
    justify-items: center; /* Center cards within their grid cells */
    align-items: start; /* Align cards to the start of their grid cell vertically */
}

.card-weather,
.card-details,
.card-uv-index {
    border-radius: 15px;
    padding: 15px; /* Slightly less padding on mobile for more content room */
    text-align: center;
    transition: background var(--transition-speed), color var(--transition-speed), border-color var(--transition-speed), box-shadow var(--transition-speed);
    width: 100%; /* Take full width of its grid column */
    max-width: 450px; /* Limit individual card width to prevent them from becoming too wide */
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
}

.card-weather {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    min-height: 220px;
}

.weather-main-icon {
    width: 120px; /* Smaller main icon on mobile */
    height: auto;
    margin-bottom: 10px;
}

.icon-phrase {
    font-size: 1.3rem; /* Smaller phrase font on mobile */
    font-weight: 500;
    margin-bottom: 10px;
}

.current-temp {
    font-size: 3.5rem; /* Smaller temp font on mobile */
    font-weight: 700;
    line-height: 1;
    margin: 0;
}

.card-details,
.card-uv-index {
    padding: 15px; /* Consistent padding on mobile */
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.card-title {
    font-size: 1.15rem; /* Smaller card titles on mobile */
    font-weight: 600;
    margin-bottom: 12px;
    width: 100%;
}

.detail-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-family: 'Ubuntu Mono', monospace;
    font-size: 0.85rem; /* Smaller detail text on mobile */
    line-height: 1.3;
}
.detail-item i {
    font-size: 1em; /* Smaller icons within details */
    margin-right: 8px;
    min-width: 25px;
    text-align: center;
    flex-shrink: 0;
}

/* Specific layout for the Precipitation Card */
.precipitation-card {
    /* Keep flexbox for stacking items if you want card title separate,
       or make it grid too if title is part of the grid.
       For now, assume precipitation-item handles its own grid. */
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.precipitation-item {
    display: grid; /* Changed to Grid! */
    /* Define 3 columns:
       1. Icon (fixed width or auto)
       2. Probability text (takes remaining space)
       3. Value (fixed width, right-aligned)
       4. Unit (fixed width, right-aligned)
    */
    grid-template-columns: auto 1fr auto auto; /* Icon | Prob | Value | Unit */
    align-items: center; /* Vertically center items in their grid cells */
    width: 100%; /* Ensure item takes full width of card */
    margin-bottom: 8px; /* Spacing between precipitation types */
    font-family: 'Ubuntu Mono', monospace;
    font-size: 0.85rem; /* Match detail-item font size */
    gap: 5px; /* Gap between grid columns */
}

.precipitation-item i {
    /* Icon is the first column, auto-sized by content */
    font-size: 1em; /* Match detail-item icon size */
    margin-right: 0; /* Remove margin here, gap handles spacing */
    min-width: 25px; /* Ensure alignment */
    text-align: center;
    flex-shrink: 0; /* No flex-shrink needed with Grid, but harmless */
}

.precipitation-prob {
    /* Probability text is the second column, takes remaining space */
    text-align: left; /* Align text to the left within its grid cell */
    padding-right: 5px; /* Small padding to separate from value */
}

.precipitation-value {
    /* Value is the third column, fixed width and right-aligned */
    text-align: right; /* Align value to the right */
    font-weight: bold; /* Make the value stand out */
    min-width: 30px; /* Adjust as needed for max value length, e.g., "100" */
}

.precipitation-unit {
    /* Unit is the fourth column, fixed width and right-aligned */
    text-align: left; /* Align unit to the left */
    min-width: 25px; /* Adjust as needed for "mm", "cm", "%" */
}

/* UV Index Specifics */
.uv-index-value {
    font-size: 1.8rem; /* Smaller UV value on mobile */
    font-weight: bold;
    margin-bottom: 8px;
    display: block;
    width: 100%;
    text-align: center;
}
.uv-index-text {
    font-size: 1rem; /* Smaller UV text on mobile */
    font-weight: 500;
    display: block;
    width: 100%;
    text-align: center;
}
.progress-bar-container {
    margin-top: 10px;
    margin-bottom: 10px;
    height: 25px;
}
.progress-bar {
    font-size: 0.9rem;
}

/* UV Index Colors */
.uv-low { background-color: #77dd77; color: #000; }
.uv-moderate { background-color: #fdfd96; color: #000; }
.uv-high { background-color: #ffb347; color: #000; }
.uv-very-high { background-color: #ff6961; color: #FFF; }
.uv-extreme { background-color: #b19cd9; color: #FFF; }


/* --- Footer --- */
.footer {
    padding: 15px 0;
    text-align: center;
    transition: background var(--transition-speed), color var(--transition-speed);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    margin-top: auto;
    flex-shrink: 0;
}
.footer-content {
    max-width: 900px;
}

.footer-link {
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}
.footer-link:hover {
    text-decoration: underline;
}

.accuweather-logo {
    height: 1.2em;
    width: auto;
    vertical-align: middle;
    margin-left: 5px;
}

.twitter-icon {
    font-size: 1.1em;
    vertical-align: middle;
    margin-left: 5px;
    margin-right: 3px;
}

/* --- Responsive Adjustments --- */

/* Small devices (landscape phones, 576px and up) - BS 'sm' */
@media (min-width: 576px) {
    .weather-cards-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        justify-items: center;
    }
    .card-weather {
        grid-column: span 1;
    }
}

/* Medium devices (tablets, 768px and up) - BS 'md' */
@media (min-width: 768px) {
    /* Navbar for larger screens */
    .navbar-brand {
        font-size: 1.8rem; /* Restore desktop size */
    }
    .weather-icon-brand {
        font-size: 1.5em; /* Restore desktop size */
    }
    .sub-brand-text {
        font-size: 0.6em; /* Restore desktop size */
    }
    .theme-toggle-btn {
        width: auto; /* Auto width on desktop */
        height: auto; /* Auto height on desktop */
        border-radius: .25rem; /* Standard button corners */
        font-size: 1rem; /* Restore desktop font size */
        padding: 8px 15px; /* Restore desktop padding */
    }
    .theme-toggle-btn span {
        display: inline; /* Show "Toggle Theme" text on desktop */
        margin-left: 8px; /* Space between icon and text */
    }
    .theme-toggle-btn i {
        margin-right: 0; /* No margin on icon itself if text is next to it */
    }

    /* Hourly Navigation should wrap */
    .hourly-nav-wrapper {
        flex-wrap: wrap; /* Allow buttons to wrap to next line on desktop */
        overflow-x: hidden; /* HIDE horizontal scrollbar on desktop */
        justify-content: center; /* Center buttons when wrapped */
        padding: 0; /* Remove horizontal padding that could contribute to overflow */
    }
    .hourly-nav-btn {
        min-width: 90px; /* Restore fixed width for desktop */
        margin: 5px 8px;
        font-size: 1.0rem; /* Restore desktop font size */
    }

    /* Carousel controls for larger screens */
    .carousel-control-prev,
    .carousel-control-next {
        width: 50px; /* Wider for easier clicking */
        opacity: 0.7; /* Keep subtle opacity */
    }
    .carousel-control-prev-icon,
    .carousel-control-next-icon {
        width: 25px; /* Larger icons on desktop */
        height: 25px;
    }

    /* Weather Cards Grid for larger screens */
    .weather-cards-grid {
        grid-template-columns: 2fr 1fr; /* Two columns: main is 2/3, side is 1/3 */
        grid-template-areas:
            "main-weather details-card"
            "precipitation-card uv-index-card";
        max-width: 1000px; /* Increased max width for content on md */
    }
    .card-weather {
        grid-area: main-weather;
        padding: 40px; /* Restore desktop padding */
        max-width: none; /* Allow it to expand within its grid area */
    }
    .card-details:nth-of-type(2) { /* First details card */
        grid-area: details-card;
        max-width: none;
    }
    .card-details:nth-of-type(3) { /* Precipitation card */
        grid-area: precipitation-card;
        max-width: none;
    }
    .card-uv-index {
        grid-area: uv-index-card;
        padding: 20px; /* Slightly more padding for UV on larger screens */
        max-width: none;
    }

    .current-temp {
        font-size: 5rem; /* Restore desktop size */
    }
    .weather-main-icon {
        width: 180px; /* Restore desktop size */
    }
    .icon-phrase {
        font-size: 1.7rem;
    }
    .card-title {
        font-size: 1.35rem;
    }
    .detail-item {
        font-size: 1rem;
    }
    .detail-item i {
        font-size: 1.2em;
        margin-right: 10px;
    }
    .uv-index-value {
        font-size: 2rem;
    }
    .uv-index-text {
        font-size: 1.1rem;
    }
    .precipitation-item {
        font-size: 1rem; /* Match detail-item font size on desktop */
        gap: 10px; /* Larger gap on desktop */
    }
    .precipitation-item i {
        font-size: 1.2em; /* Match detail-item icon size on desktop */
    }
    .precipitation-value {
        min-width: 40px; /* Adjust for desktop if values are longer */
    }
    .precipitation-unit {
        min-width: 30px; /* Adjust for desktop if units are longer */
    }
}

/* Large devices (desktops, 992px and up) - BS 'lg' */
@media (min-width: 992px) {
    .weather-cards-grid {
        grid-template-columns: 1.5fr 1fr 1fr; /* Adjust ratios as desired */
        grid-template-areas:
            "main-weather details-card precipitation-card"
            "main-weather details-card uv-index-card"; /* UV index below precipitation */
        gap: 25px; /* Slightly more gap */
        max-width: 1200px; /* Increased max width for content on lg */
    }
    .card-weather {
        grid-area: main-weather;
        padding: 50px;
    }
    .card-details:nth-of-type(2) {
        grid-area: details-card;
    }
    .card-details:nth-of-type(3) { /* Precipitation Card */
        grid-area: precipitation-card;
    }
    .card-uv-index {
        grid-area: uv-index-card;
        padding: 30px;
    }

    .current-temp {
        font-size: 6rem; /* Even larger temp on desktop */
    }
    .weather-main-icon {
        width: 200px; /* Even larger icon */
    }
    .icon-phrase {
        font-size: 1.8rem;
    }
    .card-title {
        font-size: 1.4rem;
    }
    .detail-item {
        font-size: 1.05rem;
    }
}

/* Extra large devices (large desktops, 1200px and up) - BS 'xl' */
@media (min-width: 1200px) {
    #content {
        max-width: 1400px; /* Even wider content area for very large screens */
    }
    .weather-cards-grid {
        gap: 30px;
        max-width: 1300px;
    }
    .card-weather {
        padding: 60px;
    }
}