/* ==========================================================================
   GLOBAL HEADER — Wfaucet
   Design tokens derived from DNA.md
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
    /* Header surface & foreground */
    --header-bg: #FFFFFF;
    --header-fg: #1A1A1A;
    --header-accent: #B8860B;
    --header-accent-hover: #9A7209;
    --header-border: #E5E5E5;
    --header-surface: #FAFAFA;

    /* Topbar */
    --topbar-bg: #1A1A1A;
    --topbar-fg: #E5E5E5;
    --topbar-accent: #C9A962;

    /* Mega menu */
    --mega-bg: #FFFFFF;
    --mega-fg: #1A1A1A;
    --mega-border: #E5E5E5;
    --mega-accent: #B8860B;

    /* Drawer */
    --drawer-bg: #FFFFFF;
    --drawer-fg: #1A1A1A;

    /* Z-index contract */
    --z-header: 9000;
    --z-mega: 9100;
    --z-drawer-overlay: 9200;
    --z-drawer: 9300;

    /* Layout */
    --header-max-width: 1440px;
    --header-gutter: 1rem;

    /* Transitions */
    --header-transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 640px) {
    :root { --header-gutter: 1.25rem; }
}
@media (min-width: 1024px) {
    :root { --header-gutter: 1.5rem; }
}

/* --- Reset & Base --- */
.site-header,
.site-header *,
.mobile-drawer,
.mobile-drawer * {
    box-sizing: border-box;
}

.site-header {
    position: relative;
    z-index: var(--z-header);
    font-family: 'Lato', system-ui, sans-serif;
    line-height: 1.5;
}

/* --- Header Container (1440px shell) --- */
.header-container {
    width: 100%;
    max-width: var(--header-max-width);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--header-gutter);
    padding-right: var(--header-gutter);
}

/* ==========================================================================
   TOP BAR
   ========================================================================== */
.header-topbar {
    background: var(--topbar-bg);
    color: var(--topbar-fg);
    font-size: 0.8125rem;
    line-height: 1.4;
    transition: max-height var(--header-transition),
                opacity var(--header-transition),
                padding var(--header-transition);
    overflow: visible;
    max-height: 60px;
    padding: 0.625rem 0;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar-left,
.topbar-center,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.topbar-left {
    flex: 1;
}

.topbar-center {
    flex: 1;
    justify-content: center;
}

.topbar-right {
    flex: 0 0 auto;
    justify-content: flex-end;
}

.topbar-item {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;
}

.topbar-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.8;
}

.topbar-link {
    color: var(--topbar-fg);
    text-decoration: none;
    transition: color 0.2s;
}

.topbar-link:hover {
    color: var(--topbar-accent);
}

.topbar-hours {
    color: rgba(255, 255, 255, 0.7);
}

/* Language Switcher in Topbar */
.locale-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    position: relative;
}

.locale-icon {
    width: 15px;
    height: 15px;
    opacity: 0.8;
}

/* JCM Language Switcher Styling */
.locale-switcher .jcm-language-switcher {
    position: relative;
}

.locale-switcher .jcm-language-switcher ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.locale-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 160px;
    background: var(--header-bg);
    border: 1px solid var(--header-border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 0.5rem 0;
    z-index: calc(var(--z-header) + 200);
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

.locale-switcher .jcm-language-switcher-dropdown:hover .jcm-dropdown-menu,
.locale-switcher .jcm-language-switcher-dropdown.is-open.jcm-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.locale-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    color: var(--header-fg);
    text-decoration: none;
    font-size: 0.8125rem;
    transition: background 0.15s;
}

.locale-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu a:hover {
    background: var(--header-surface);
    color: var(--header-accent);
}

.locale-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu img {
    width: 18px;
    height: 13px;
    border-radius: 2px;
    object-fit: cover;
}

/* Topbar mobile */
@media (max-width: 767px) {
    /* Language switcher: hide in topbar on mobile — drawer handles it */
    .header-topbar__lang { display: none; }
    .topbar-left,
    .topbar-center {
        display: none;
    }
    .topbar-inner {
        justify-content: flex-end;
    }
    .header-topbar {
        padding: 0.5rem 0;
        max-height: 44px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .topbar-left {
        display: none;
    }
    .topbar-center {
        flex: 1;
        justify-content: flex-start;
    }
}

/* ==========================================================================
   MAIN HEADER
   ========================================================================== */
.header-main {
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    position: relative;
    transition: background var(--header-transition),
                box-shadow var(--header-transition),
                padding var(--header-transition);
}

.header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    padding-top: 1.125rem;
    padding-bottom: 1.125rem;
    gap: 1.5rem;
    transition: padding var(--header-transition);
}

@media (min-width: 1024px) {
    .header-inner {
        padding-top: 1.375rem;
        padding-bottom: 1.375rem;
    }
}

/* --- Logo --- */
.header-brand {
    grid-column: 1;
    display: flex;
    align-items: center;
}

.header-logo-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.header-logo {
    height: auto;
    display: block;
    transition: opacity 0.3s, width var(--header-transition);
}

.logo-light {
    width: clamp(144px, 15vw, 220px);
}

.logo-dark {
    width: clamp(144px, 15vw, 220px);
    display: none;
}

/* Default state: light surface -> show logo-on-light, hide logo-on-dark */
/* (logo-dark shown only when header surface is dark) */

@media (max-width: 1023px) {
    .logo-light {
        width: clamp(120px, 28vw, 176px);
    }
    .logo-dark {
        width: clamp(120px, 28vw, 176px);
    }
}

/* --- Desktop Navigation --- */
.header-nav {
    grid-column: 2;
    justify-self: center;
    display: none;
}

@media (min-width: 1024px) {
    .header-nav {
        display: flex;
        align-items: center;
    }
}

.nav-list {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.625rem 1rem;
    color: var(--header-fg);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--header-accent);
    background: rgba(184, 134, 11, 0.05);
}

.nav-item.is-active .nav-link {
    color: var(--header-accent);
}

.nav-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.25s;
}

.nav-item-products.is-mega-open .nav-chevron {
    transform: rotate(180deg);
}

/* --- Action Zone --- */
.header-actions {
    grid-column: 3;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

.header-cta {
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--header-accent);
    color: #FFFFFF;
    padding: 0.625rem 1.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

@media (min-width: 1024px) {
    .header-cta {
        display: inline-flex;
    }
}

.header-cta:hover {
    background: var(--header-accent-hover);
    box-shadow: 0 4px 12px rgba(184, 134, 11, 0.25);
}

/* --- Mobile Toggle --- */
.mobile-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    gap: 5px;
}

@media (min-width: 1024px) {
    .mobile-toggle {
        display: none;
    }
}

.hamburger-bar {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--header-fg);
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
}

/* Hamburger -> X animation */
.mobile-toggle[aria-expanded="true"] .hamburger-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.mobile-toggle[aria-expanded="true"] .hamburger-bar:nth-child(2) {
    opacity: 0;
}
.mobile-toggle[aria-expanded="true"] .hamburger-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ==========================================================================
   SCROLLED STATE
   ========================================================================== */
.site-header.is-scrolled .header-topbar {
    max-height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.site-header.is-scrolled .header-main {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--header-bg);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
    border-bottom-color: transparent;
}

.site-header.is-scrolled .header-inner {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

.site-header.is-scrolled .logo-light {
    width: clamp(120px, 12vw, 170px);
}

/* Spacer to prevent layout jump */
.header-spacer {
    display: none;
    height: 0;
}

.header-spacer.is-active {
    display: block;
}

/* ==========================================================================
   MEGA MENU
   ========================================================================== */
.mega-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--mega-bg);
    border-top: 1px solid var(--mega-border);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.1);
    z-index: var(--z-mega);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}

.mega-menu.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.mega-menu-inner {
    padding: 2.5rem 0;
}

.mega-menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2rem;
}

@media (min-width: 1200px) {
    .mega-menu-grid {
        grid-template-columns: repeat(4, 1fr) minmax(200px, 240px);
    }
}

/* Mega Category Block */
.mega-category {
    padding: 0;
}

.mega-category-title {
    display: block;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--mega-fg);
    text-decoration: none;
    margin-bottom: 0.375rem;
    transition: color 0.2s;
}

.mega-category-title:hover {
    color: var(--mega-accent);
}

.mega-category-desc {
    font-size: 0.75rem;
    color: #737373;
    margin: 0 0 0.75rem;
    line-height: 1.5;
}

.mega-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.mega-children li {
    margin-bottom: 0.375rem;
}

.mega-children a {
    font-size: 0.8125rem;
    color: #525252;
    text-decoration: none;
    transition: color 0.15s;
    display: inline-block;
    padding: 0.125rem 0;
}

.mega-children a:hover {
    color: var(--mega-accent);
}

.mega-view-all {
    display: inline-block;
    margin-top: 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--mega-accent);
    text-decoration: none;
    transition: opacity 0.2s;
}

.mega-view-all:hover {
    opacity: 0.75;
}

/* Mega Support Column */
.mega-support {
    display: none;
}

@media (min-width: 1200px) {
    .mega-support {
        display: block;
    }
}

.mega-support-card {
    background: var(--header-surface);
    border: 1px solid var(--mega-border);
    border-radius: 8px;
    padding: 1.5rem;
}

.mega-support-card h4 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--mega-fg);
    margin: 0 0 0.5rem;
}

.mega-support-card p {
    font-size: 0.8125rem;
    color: #525252;
    line-height: 1.6;
    margin: 0 0 1rem;
}

.mega-support-link {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--mega-accent);
    text-decoration: none;
    transition: opacity 0.2s;
}

.mega-support-link:hover {
    opacity: 0.75;
}

/* Mega menu responsive: stack on smaller desktops */
@media (min-width: 1024px) and (max-width: 1199px) {
    .mega-menu-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Mega menu max-height for viewport fit */
.mega-menu-inner {
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    scrollbar-width: thin;
}

/* ==========================================================================
   MOBILE DRAWER
   ========================================================================== */
.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: var(--z-drawer);
    pointer-events: none;
    visibility: hidden;
}

.mobile-drawer.is-open {
    pointer-events: auto;
    visibility: visible;
}

.drawer-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: var(--z-drawer-overlay);
}

.mobile-drawer.is-open .drawer-overlay {
    opacity: 1;
}

.drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(380px, 85vw);
    background: var(--drawer-bg);
    z-index: var(--z-drawer);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.mobile-drawer.is-open .drawer-panel {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem var(--header-gutter);
    border-bottom: 1px solid var(--header-border);
}

.drawer-logo-link {
    display: inline-flex;
}

.drawer-logo {
    width: clamp(120px, 28vw, 150px);
    height: auto;
}

.drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--drawer-fg);
}

.drawer-close svg {
    width: 22px;
    height: 22px;
}

/* Drawer Navigation */
.drawer-nav {
    flex: 1;
    padding: 1rem 0;
}

.drawer-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.drawer-item {
    border-bottom: 1px solid rgba(229, 229, 229, 0.5);
}

.drawer-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 1rem var(--header-gutter);
    color: var(--drawer-fg);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: color 0.2s, background 0.2s;
}

.drawer-link:hover {
    color: var(--header-accent);
    background: rgba(184, 134, 11, 0.03);
}

.drawer-item.is-active > .drawer-link {
    color: var(--header-accent);
}

.drawer-chevron {
    width: 18px;
    height: 18px;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.drawer-accordion-trigger[aria-expanded="true"] .drawer-chevron {
    transform: rotate(180deg);
}

/* Drawer Accordion Panel */
.drawer-accordion-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
    background: var(--header-surface);
}

.drawer-accordion-trigger[aria-expanded="true"] + .drawer-accordion-panel {
    max-height: 2000px;
}

.drawer-category {
    padding: 0.75rem var(--header-gutter) 0.75rem calc(var(--header-gutter) + 0.75rem);
}

.drawer-category-title {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--drawer-fg);
    text-decoration: none;
    margin-bottom: 0.375rem;
    transition: color 0.2s;
}

.drawer-category-title:hover {
    color: var(--header-accent);
}

.drawer-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.drawer-children li {
    margin-bottom: 0.25rem;
}

.drawer-children a {
    font-size: 0.8125rem;
    color: #525252;
    text-decoration: none;
    padding: 0.25rem 0;
    display: inline-block;
    transition: color 0.15s;
}

.drawer-children a:hover {
    color: var(--header-accent);
}

/* Drawer Footer */
.drawer-footer {
    padding: 1.25rem var(--header-gutter);
    border-top: 1px solid var(--header-border);
    margin-top: auto;
}

.drawer-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: var(--header-accent);
    color: #FFFFFF;
    padding: 0.875rem 1.5rem;
    border-radius: 4px;
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s;
    margin-bottom: 1rem;
}

.drawer-cta:hover {
    background: var(--header-accent-hover);
}

.drawer-contact {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.drawer-contact a {
    font-size: 0.8125rem;
    color: #525252;
    text-decoration: none;
    transition: color 0.15s;
}

.drawer-contact a:hover {
    color: var(--header-accent);
}

.drawer-locale {
    padding-top: 0.75rem;
    border-top: 1px solid var(--header-border);
}

.drawer-locale .jcm-language-switcher {
    font-size: 0.8125rem;
}

.drawer-locale .jcm-language-switcher ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.drawer-locale .jcm-language-switcher a {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    border-radius: 4px;
    color: #525252;
    text-decoration: none;
    font-size: 0.8125rem;
    transition: background 0.15s, color 0.15s;
}

.drawer-locale .jcm-language-switcher a:hover {
    background: var(--header-surface);
    color: var(--header-accent);
}

.drawer-locale .jcm-language-switcher img {
    width: 18px;
    height: 13px;
    border-radius: 2px;
    object-fit: cover;
}

/* ==========================================================================
   BODY SCROLL LOCK (when drawer is open)
   ========================================================================== */
body.drawer-open {
    overflow: hidden;
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */
.site-header a:focus-visible,
.site-header button:focus-visible,
.mobile-drawer a:focus-visible,
.mobile-drawer button:focus-visible {
    outline: 2px solid var(--header-accent);
    outline-offset: 2px;
}

/* Skip to content (optional, rendered externally) */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 99999;
    padding: 0.75rem 1.5rem;
    background: var(--header-accent);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    top: 0;
}

/* ==========================================================================
   PRINT
   ========================================================================== */
@media print {
    .site-header,
    .mobile-drawer,
    .header-spacer {
        display: none !important;
    }
}
