/* ===================================
   PETGAS Header - Common Styles
   ================================= */

/* CSS Custom Properties */
:root {
    /* Colors */
    --header-primary-color: #0a4b2a;
    --header-accent-color: #1abc9c;
    --header-bg-color: rgba(255, 255, 255, 0.98);
    --header-text-color: #ffffff;
    --header-nav-text: #333333;
    --header-shadow: rgba(0, 0, 0, 0.1);
    
    /* Dimensions */
    --header-height-desktop: 80px;
    --header-height-mobile: 60px;
    --marquee-height: 50px;
    
    /* Typography */
    --header-font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --header-font-weight-normal: 400;
    --header-font-weight-semibold: 600;
    --header-font-size-base: 0.85rem;
    --header-font-size-marquee: 0.9rem;
    
    /* Spacing */
    --header-padding: 1rem;
    --header-gap: 25px;
    --header-border-radius: 4px;
    
    /* Animation */
    --animation-duration: 0.3s;
    --animation-easing: cubic-bezier(0.4, 0, 0.2, 1);
    --marquee-scroll-duration: 30s;
    
    /* Z-index layers */
    --z-header: 1000;
    --z-mobile-menu: 1100;
    --z-mobile-overlay: 1050;
    
    /* Breakpoints (em-based) */
    --breakpoint-mobile: 64em; /* 1024px */
    --breakpoint-tablet: 48em; /* 768px */
    --breakpoint-small: 30em; /* 480px */
}

/* Optimized CSS Reset and Normalize for Header Elements */
.site-header {
    contain: layout paint style; /* CSS Containment for better performance */
    will-change: transform; /* Hint for browser optimization */
}

.site-header *,
.site-header *::before,
.site-header *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Header Container */
.site-header {
    position: relative;
    width: 100%;
    font-family: var(--header-font-family);
    font-weight: var(--header-font-weight-normal);
    line-height: 1.5;
    z-index: var(--z-header);
    /* Performance optimizations */
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
    will-change: transform, opacity; /* Optimize for animations */
    contain: content; /* Isolate the header's rendering */
}

/* Header Loading States */
.header-loading #header-container {
    min-height: 130px; /* Approximate height of header + marquee */
    background-color: var(--header-bg-color);
    opacity: 0.8;
    position: relative;
    overflow: hidden;
}

.header-loading #header-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--header-primary-color), var(--header-accent-color));
    animation: headerLoading 1.5s infinite ease-in-out;
}

.header-loading-extended #header-container {
    background-color: #f5f5f5;
}

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

/* Screen Reader Only Content */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Focus Styles */
.site-header a:focus,
.site-header button:focus {
    outline: 2px solid var(--header-accent-color);
    outline-offset: 2px;
    border-radius: var(--header-border-radius);
    position: relative;
    z-index: 1;
}

/* Enhanced focus styles for better visibility */
.site-header a:focus-visible,
.site-header button:focus-visible {
    outline: 3px solid var(--header-accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(26, 188, 156, 0.2);
}

/* Skip to content link for screen readers */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--header-accent-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 9999;
    font-weight: 600;
    transition: top 0.3s ease;
}

.skip-to-content:focus {
    top: 6px;
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Ensure proper tab order */
.site-header [tabindex="-1"] {
    outline: none !important;
}

/* High contrast focus indicators */
@media (prefers-contrast: high) {
    .site-header a:focus,
    .site-header button:focus {
        outline: 3px solid;
        outline-color: Highlight;
        background: Highlight;
        color: HighlightText;
    }
}

/* Remove default button styles */
.site-header button {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* Remove default list styles */
.site-header ul {
    list-style: none;
}

/* Remove default link styles */
.site-header a {
    text-decoration: none;
    color: inherit;
}

/* Image optimization */
.site-header img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Responsive Breakpoint System */

/* Mobile First - Base styles (0 - 1023px) */
@media screen and (max-width: calc(var(--breakpoint-mobile) - 0.0625em)) {
    .desktop-nav {
        display: none !important;
    }
    
    .mobile-menu-toggle {
        display: flex !important;
    }
    
    /* Ensure mobile menu components are available */
    .mobile-menu,
    .mobile-menu-overlay {
        display: block;
    }
    
    /* Prevent scrolling when mobile menu is open */
    body.mobile-menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

/* Desktop styles (1024px and up) */
@media screen and (min-width: var(--breakpoint-mobile)) {
    .desktop-nav {
        display: flex !important;
        visibility: visible;
        opacity: 1;
        transition: opacity var(--animation-duration) var(--animation-easing);
    }
    
    .mobile-menu-toggle {
        display: none !important;
        visibility: hidden;
        opacity: 0;
        transition: opacity var(--animation-duration) var(--animation-easing);
    }
    
    /* Hide mobile menu components on desktop */
    .mobile-menu,
    .mobile-menu-overlay {
        display: none !important;
        visibility: hidden;
        opacity: 0;
    }
    
    /* Ensure mobile menu is closed if window is resized to desktop */
    .mobile-menu.open {
        right: -100% !important;
        opacity: 0;
    }
    
    .mobile-menu-overlay.open {
        opacity: 0 !important;
        visibility: hidden !important;
    }
    
    /* Remove body scroll lock on desktop */
    body.mobile-menu-open {
        overflow: auto;
        position: static;
        width: auto;
    }
}

/* Tablet adjustments (768px - 1023px) */
@media screen and (min-width: var(--breakpoint-tablet)) and (max-width: calc(var(--breakpoint-mobile) - 0.0625em)) {
    :root {
        --header-padding: 1.5rem;
        --header-gap: 20px;
    }
    
    /* Ensure mobile menu toggle is properly positioned on tablets */
    .mobile-menu-toggle {
        top: 25px;
        right: 25px;
        width: 48px;
        height: 48px;
    }
    
    /* Adjust mobile menu for tablet screens */
    .mobile-menu {
        max-width: 380px;
    }
}

/* Small mobile adjustments (0 - 479px) */
@media screen and (max-width: calc(var(--breakpoint-small) - 0.0625em)) {
    :root {
        --header-padding: 0.75rem;
        --header-gap: 15px;
        --header-font-size-base: 0.8rem;
        --header-font-size-marquee: 0.85rem;
    }
}

/* High DPI displays */
@media screen and (-webkit-min-device-pixel-ratio: 2), 
       screen and (min-resolution: 192dpi) {
    .site-header img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .site-header * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support (future-proofing) */
@media (prefers-color-scheme: dark) {
    :root {
        --header-bg-color: rgba(26, 26, 26, 0.98);
        --header-nav-text: #ffffff;
        --header-shadow: rgba(255, 255, 255, 0.1);
    }
}

/* Print styles */
@media print {
    .site-header {
        position: static;
        box-shadow: none;
    }
    
    .mobile-menu,
    .mobile-menu-toggle,
    .mobile-menu-overlay {
        display: none !important;
    }
}

/* Container queries support (future enhancement) */
@supports (container-type: inline-size) {
    .site-header {
        container-type: inline-size;
    }
}

/* Performance optimizations */
.site-header {
    contain: layout style;
    will-change: auto;
}

/* Ensure proper stacking context */
.site-header {
    isolation: isolate;
}

/* Smooth transitions for responsive breakpoint changes */
.site-header.transitioning .desktop-nav,
.site-header.transitioning .mobile-menu-toggle {
    transition: all var(--animation-duration) var(--animation-easing);
}

.site-header.transitioning .desktop-nav {
    transition-property: opacity, visibility, transform;
}

.site-header.transitioning .mobile-menu-toggle {
    transition-property: opacity, visibility, transform;
}