/* 
 * CHS Airport Weather Widget Styles
 * Version: 2.0.3
 * WCAG 2.1 AA Compliant
 * Enhanced with better image fallback handling
 */

/* Base Widget Styles */
.chs-airport-weather-widget {
    display: flex !important;
    align-items: center !important;
    font-family: 'Brandon Grotesque', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 500;
    padding: 0;
    margin: 0;
    color: #0f0f10; /* Updated black text */
    cursor: pointer;
    position: relative !important;
}

.chs-airport-weather-widget:hover:not(.active) {
    opacity: 0.9;
}

.chs-airport-weather-widget.active {
    opacity: 1;
}

.chs-airport-weather-widget:focus {
    outline: 2px solid #0088FF; /* Royal Blue */
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(0, 136, 255, 0.4);
}

.chs-airport-weather-widget .chs-airport-weather-icon {
    display: flex;
    align-items: center !important;
    margin-right: 5px;
}

.chs-airport-weather-widget .chs-airport-weather-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: brightness(1);
    transform-origin: center center;
    transition: transform 0.2s ease;
    background-color: transparent;
    /* Ensure the image container maintains size even if image fails */
    min-width: 24px;
    min-height: 24px;
    display: block;
}

.chs-airport-weather-widget .chs-airport-weather-temp {
    font-size: 18px !important;
    font-weight: 500 !important;
    display: flex !important;
    align-items: center !important;
    line-height: 1 !important;
}

.chs-airport-weather-widget .chs-airport-weather-temp span {
    font-weight: 500 !important;
}

.chs-airport-weather-widget .temp-value {
    font-weight: 500 !important;
}

.chs-airport-weather-widget .temp-unit {
    font-size: 16px !important;
    margin-top: -2px !important;
    font-weight: 500 !important;
}

/* Error state */
.chs-airport-weather-widget.chs-airport-weather-error {
    color: #0f0f10; /* Updated black text */
    font-size: 14px;
    font-weight: 500;
    cursor: default;
}

/* ENHANCED: Image error handling and fallback styles */
.chs-airport-weather-widget img.icon-error-fallback,
.chs-airport-weather-popup img.icon-error-fallback {
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    position: relative;
}

/* Loading state for refreshing */
.chs-airport-weather-widget.is-refreshing {
    opacity: 0.7;
    pointer-events: none;
}

/* Weather Popup Styles - FIXED ISSUES WITH POPUP DISPLAY */
.chs-airport-weather-popup {
    display: none;
    position: fixed;
    z-index: 100000;
    background: #fff;
    border-radius: 0; /* Square corners */
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25); /* Strong shadow */
    font-family: 'Brandon Grotesque', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
    font-size: 14px;
    color: #0f0f10; /* Updated black text */
    line-height: 1.5;
    max-width: 400px;
    width: 400px; /* Fixed width for consistency */
    opacity: 0; /* Start with opacity 0 */
    visibility: hidden; /* Start hidden */
    transition: opacity 0.2s ease; /* Transition for opacity only */
}

/* Show the popup when it has the is-visible class */
.chs-airport-weather-popup.is-visible {
    display: block;
    opacity: 1;
    visibility: visible;
}

/* Overlay for modal-like behavior - IMPROVED z-index and positioning */
.chs-airport-weather-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5); /* Slightly darker overlay */
    z-index: 99999;
    animation: chs_airport_fadeIn 0.2s ease;
}

/* Style for active widget */
.chs-airport-weather-widget.active {
    z-index: 100001;
}

/* Body class to prevent scrolling when popup is open */
body.chs-airport-weather-open {
    overflow: hidden;
}

/* Popup Header */
.chs-airport-weather-popup-header {
    position: relative;
    background: #0088FF; /* Royal Blue */
    color: white;
    padding: 12px 15px;
}

.chs-airport-weather-popup-header h3 {
    margin: 0;
    padding: 0;
    font-size: 1.5rem; /* 24px equivalent - MAIN TITLE */
    font-weight: 600;
}

/* IMPROVED: Larger click target for close button - WCAG compliant */
.chs-airport-weather-popup-close {
    position: absolute;
    top: 12px;
    right: 8px;
    width: 42px; /* Increased from 32px for better touch target */
    height: 42px; /* Increased from 32px for better touch target */
    border-radius: 0; /* Square corners */
    border: none;
    background: rgba(255, 255, 255, 0.3); /* Increased visibility */
    color: white;
    font-size: 24px; /* Increased from 20px */
    line-height: 1;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 100010; /* Ensure button is above all other elements */
}

.chs-airport-weather-popup-close:hover,
.chs-airport-weather-popup-close:focus {
    background: rgba(255, 255, 255, 0.5);
    outline: 2px solid white;
    outline-offset: -2px;
}

/* Current Weather Display - UPDATED LAYOUT */
.chs-airport-weather-popup-current {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background-color: #F8F8F8; /* Very light grey */
    border-bottom: 1px solid #DEE2E8; /* Dark blue tone */
}

/* Group icon and temp together */
.chs-airport-weather-popup-main-group {
    display: flex;
    align-items: center;
}

.chs-airport-weather-popup-icon {
    margin-right: 12px;
}

.chs-airport-weather-popup-icon img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    /* ENHANCED: Better fallback handling for popup icons */
    min-width: 48px;
    min-height: 48px;
    background-color: transparent;
    display: block;
}

.chs-airport-weather-popup-temp {
    font-size: 32px;
    font-weight: 600;
    line-height: 1;
    color: #0f0f10; /* Updated black text */
}

.chs-airport-weather-popup-temp span {
    font-size: 18px;
    vertical-align: top;
    margin-left: 2px;
}

/* Group description and feels like together */
.chs-airport-weather-popup-desc-group {
    text-align: right;
    max-width: 45%;
}

.chs-airport-weather-popup-desc {
    font-size: 16px;
    margin-bottom: 4px;
    color: #0f0f10; /* Updated black text */
    font-weight: 500;
}

.chs-airport-weather-feels-like {
    font-size: 14px;
    color: #555;
}

/* Weather Info Grid - FIXED ALIGNMENT */
.chs-airport-weather-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 10px;
    padding: 15px 20px; /* FIXED: Added consistent horizontal padding to align with other sections */
    background-color: #FFFFFF; /* Changed to white for better contrast with sections */
    border-bottom: 1px solid #DEE2E8; /* Dark blue tone */
}

.chs-airport-weather-info-item {
    font-size: 13px;
    color: #0f0f10; /* Updated black text */
}

.chs-airport-weather-info-item span {
    font-weight: 600;
    color: #0f0f10; /* Updated black text */
    margin-right: 5px;
}

/* NEW - Hourly Forecast Header */
.chs-airport-weather-hourly-header {
    background: #0088FF; /* Royal Blue */
    color: white;
    padding: 12px 15px;
}

.chs-airport-weather-hourly-header h3 {
    margin: 0;
    padding: 0;
    font-size: 1.25rem; /* 20px equivalent - SECTION TITLES */
    font-weight: 600;
}

/* IMPROVED: Hourly Timeline with better scrolling behavior */
.chs-airport-weather-hourly-timeline {
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
    background-color: #FFFFFF;
    border-bottom: 1px solid #DEE2E8;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: #0088FF #f0f0f0;
    scroll-behavior: smooth; /* Smoother scrolling */
}

.chs-airport-weather-hourly-timeline::-webkit-scrollbar {
    height: 6px;
}

.chs-airport-weather-hourly-timeline::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.chs-airport-weather-hourly-timeline::-webkit-scrollbar-thumb {
    background-color: #0088FF;
    border-radius: 3px;
}

/* IMPROVED: Hour slots with better touch targets for mobile */
.chs-airport-weather-hour-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
    text-align: center;
    padding: 8px 4px; /* Add padding for better touch targets */
}

.chs-airport-weather-hour-time {
    font-size: 13px;
    margin-bottom: 8px;
    font-weight: 500;
    color: #0f0f10; /* Updated black text */
}

.chs-airport-weather-hour-icon {
    margin-bottom: 8px;
}

/* ENHANCED: Better image handling for hourly and daily icons */
.chs-airport-weather-hour-icon img,
.chs-airport-weather-day-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    min-width: 24px; /* Prevent collapse when image is broken */
    min-height: 24px;
    background-color: transparent;
    display: inline-block;
    transition: opacity 0.2s ease;
}

/* ENHANCED: Better fallback for broken images */
.chs-airport-weather-hour-icon img:not([src]),
.chs-airport-weather-hour-icon img[src=""],
.chs-airport-weather-hour-icon img[src*="undefined"],
.chs-airport-weather-hour-icon img[src*="null"],
.chs-airport-weather-day-icon img:not([src]),
.chs-airport-weather-day-icon img[src=""],
.chs-airport-weather-day-icon img[src*="undefined"],
.chs-airport-weather-day-icon img[src*="null"] {
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    position: relative;
}

/* Style for fallback icons */
.chs-airport-weather-hour-icon img.icon-error-fallback,
.chs-airport-weather-day-icon img.icon-error-fallback {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    opacity: 0.8;
}

/* Loading animation for images */
.chs-airport-weather-hour-icon img[src=""],
.chs-airport-weather-day-icon img[src=""],
.chs-airport-weather-popup-icon img[src=""] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.chs-airport-weather-hour-temp {
    font-size: 16px;
    font-weight: 600;
    color: #0f0f10; /* Updated black text */
}

/* NEW - 3-Day Forecast Header */
.chs-airport-weather-forecast-header {
    background: #0088FF; /* Royal Blue */
    color: white;
    padding: 12px 15px;
}

.chs-airport-weather-forecast-header h3 {
    margin: 0;
    padding: 0;
    font-size: 1.25rem; /* 20px equivalent - SECTION TITLES */
    font-weight: 600;
}

/* NEW - 3-Day Forecast Layout */
.chs-airport-weather-forecast-days {
    display: flex;
    justify-content: space-around;
    padding: 20px; /* FIXED: Consistent padding to match other sections */
    background-color: #FFFFFF;
}

.chs-airport-weather-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    text-align: center;
    position: relative;
    padding: 8px 4px; /* Add padding for better touch targets */
}

.chs-airport-weather-day:not(:last-child):after {
    content: '';
    position: absolute;
    right: 0;
    top: 10%;
    height: 80%;
    width: 1px;
    background-color: #DEE2E8;
}

.chs-airport-weather-day-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #0f0f10; /* Updated black text */
}

.chs-airport-weather-day-icon {
    margin-bottom: 10px;
}

/* ENHANCED: Better sizing for daily forecast icons */
.chs-airport-weather-day-icon img {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
}

.chs-airport-weather-day-temp {
    font-size: 14px;
    color: #0f0f10; /* Updated black text */
}

/* Animation keyframes */
@keyframes chs_airport_fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Icon Animations - SMALL WIDGET ANIMATIONS REMOVED */
/* Only apply animations to popup icons, not the small widget */
.chs-airport-weather-popup-icon img.chs-airport-weather-sun-icon,
.chs-airport-weather-hour-icon img.chs-airport-weather-sun-icon,
.chs-airport-weather-day-icon img.chs-airport-weather-sun-icon {
    animation: chs_airport_sun_pulse 3s infinite ease-in-out;
}

.chs-airport-weather-popup-icon img.chs-airport-weather-moon-icon,
.chs-airport-weather-hour-icon img.chs-airport-weather-moon-icon,
.chs-airport-weather-day-icon img.chs-airport-weather-moon-icon {
    animation: chs_airport_moon_glow 4s infinite ease-in-out;
}

.chs-airport-weather-popup-icon img.chs-airport-weather-cloud-icon,
.chs-airport-weather-hour-icon img.chs-airport-weather-cloud-icon,
.chs-airport-weather-day-icon img.chs-airport-weather-cloud-icon {
    animation: chs_airport_cloud_float 5s infinite ease-in-out;
}

.chs-airport-weather-popup-icon img.chs-airport-weather-rain-icon,
.chs-airport-weather-hour-icon img.chs-airport-weather-rain-icon,
.chs-airport-weather-day-icon img.chs-airport-weather-rain-icon {
    animation: chs_airport_rain_fall 2s infinite ease-in-out;
}

.chs-airport-weather-popup-icon img.chs-airport-weather-snow-icon,
.chs-airport-weather-hour-icon img.chs-airport-weather-snow-icon,
.chs-airport-weather-day-icon img.chs-airport-weather-snow-icon {
    animation: chs_airport_snow_fall 3s infinite ease-in-out;
}

.chs-airport-weather-popup-icon img.chs-airport-weather-storm-icon,
.chs-airport-weather-hour-icon img.chs-airport-weather-storm-icon,
.chs-airport-weather-day-icon img.chs-airport-weather-storm-icon {
    animation: chs_airport_storm_flash 5s infinite ease-in-out;
}

/* IMPROVED: Reduced animation intensity for accessibility */
@keyframes chs_airport_sun_pulse {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.05); filter: brightness(1.05); }
}

@keyframes chs_airport_moon_glow {
    0%, 100% { opacity: 0.95; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.03); filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.7)); }
}

@keyframes chs_airport_cloud_float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-1px); }
}

@keyframes chs_airport_rain_fall {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(1px); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2)); }
}

@keyframes chs_airport_snow_fall {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(1px) rotate(2deg); }
}

@keyframes chs_airport_storm_flash {
    0%, 15%, 25%, 35%, 100% { opacity: 1; filter: brightness(1); }
    20%, 30% { opacity: 0.9; filter: brightness(1.2); }
}

/* NEW: Reduced motion media query for accessibility */
@media (prefers-reduced-motion: reduce) {
    .chs-airport-weather-popup-icon img,
    .chs-airport-weather-hour-icon img,
    .chs-airport-weather-day-icon img {
        animation: none !important;
    }
    
    /* Also disable loading animation for reduced motion */
    .chs-airport-weather-hour-icon img[src=""],
    .chs-airport-weather-day-icon img[src=""],
    .chs-airport-weather-popup-icon img[src=""] {
        animation: none !important;
        background: #f0f0f0;
    }
}

/* High contrast mode support */
@media (forced-colors: active) {
    .chs-airport-weather-widget,
    .chs-airport-weather-popup-close {
        border: 1px solid currentColor;
    }
    
    .chs-airport-weather-hour-slot,
    .chs-airport-weather-day {
        border: 1px solid currentColor;
    }
}

/* ENHANCED: Better IE11 support where object-fit isn't supported */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .chs-airport-weather-hour-icon img,
    .chs-airport-weather-day-icon img,
    .chs-airport-weather-popup-icon img {
        width: auto;
        height: auto;
        max-width: 24px;
        max-height: 24px;
    }
    
    .chs-airport-weather-popup-icon img {
        max-width: 48px;
        max-height: 48px;
    }
    
    .chs-airport-weather-day-icon img {
        max-width: 32px;
        max-height: 32px;
    }
}

/* IMPROVED: Responsive adjustments with better touch targets */
@media (max-width: 480px) {
    .chs-airport-weather-popup {
        position: fixed;
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        max-width: 100%;
        width: 100%;
        box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.2);
        border-radius: 0;
        max-height: 80vh;
        overflow-y: auto;
        transform: none !important; /* Override center positioning */
    }
    
    /* Hourly timeline scrolling on mobile with improved spacing */
    .chs-airport-weather-hourly-timeline {
        padding: 15px 15px;
        justify-content: flex-start;
    }
    
    .chs-airport-weather-hour-slot {
        min-width: 70px; /* Increased from 65px for larger touch target */
        margin-right: 8px; /* Increased from 5px for better spacing */
        padding: 10px 5px; /* Added padding for touch */
    }
    
    /* Adjust forecast day sizing on mobile */
    .chs-airport-weather-day {
        padding: 10px 5px; /* Added padding for touch */
    }
    
    .chs-airport-weather-day-name {
        font-size: 13px; /* Increased from 12px for readability */
    }
    
    .chs-airport-weather-day-temp {
        font-size: 13px; /* Increased from 12px for readability */
    }
    
    /* IMPROVED: Better layout of current weather section on mobile */
    .chs-airport-weather-popup-current {
        flex-wrap: wrap;
        padding: 15px; /* Reduced padding */
    }
    
    .chs-airport-weather-popup-desc-group {
        width: 100%;
        text-align: left;
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        max-width: 100%;
    }
    
    /* Improve touch target size for close button on mobile */
    .chs-airport-weather-popup-close {
        width: 44px; /* Increased size for mobile */
        height: 44px; /* Increased size for mobile */
        top: 8px;
        right: 8px;
    }
    
    /* Adjust header text on mobile - maintain hierarchy */
    .chs-airport-weather-popup-header h3 {
        font-size: 1.25rem; /* Smaller main title on mobile */
        padding-right: 40px; /* Make space for the larger close button */
    }
    
    .chs-airport-weather-hourly-header h3,
    .chs-airport-weather-forecast-header h3 {
        font-size: 1.125rem; /* Smaller section titles on mobile */
    }
}

/* ENHANCED: Error states and connectivity indicators */
.chs-airport-weather-widget.network-error {
    opacity: 0.6;
}

.chs-airport-weather-widget.network-error::after {
    content: '⚠';
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Smooth transitions for dynamic content updates */
.chs-airport-weather-popup-temp,
.chs-airport-weather-feels-like,
.chs-airport-weather-popup-desc,
.chs-airport-weather-info-item {
    transition: all 0.3s ease;
}

/* Loading state styles */
.chs-airport-weather-widget.is-refreshing .chs-airport-weather-icon img {
    animation: pulse 1.5s ease-in-out infinite;
}

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