/**
 * CLSEG Global Header Styles
 * Design tokens derived from DNA.md
 * Container: 1440px max-width aligned with page shell
 */

/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
    /* Header surface tokens */
    --header-bg: #ffffff;
    --header-fg: #0C0F14;
    --header-accent: #2563EB;
    --header-border: #E2E8F0;
    --header-surface: #F8FAFC;

    /* Topbar tokens */
    --topbar-bg: #070A0E;
    --topbar-fg: #C8D3E3;
    --topbar-accent: #3B82F6;
    --topbar-border: rgba(255, 255, 255, 0.08);

    /* Z-index contract */
    --z-header: 9000;
    --z-mega-menu: 9100;
    --z-mobile-drawer: 9500;

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

    /* Font families */
    --font-heading: 'Outfit', 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', system-ui, sans-serif;
    --font-body: 'DM Sans', 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', system-ui, sans-serif;
}

/* ============================================================
   Container — 1440px max-width shell
   ============================================================ */
.header-container {
    width: 100%;
    max-width: 1440px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 16px;
    padding-right: 16px;
}

@media (min-width: 640px) {
    .header-container {
        padding-left: 20px;
        padding-right: 20px;
    }
}

@media (min-width: 1024px) {
    .header-container {
        padding-left: 24px;
        padding-right: 24px;
    }
}

/* ============================================================
   Site Header — Base (in-flow, not fixed)
   ============================================================ */
.site-header {
    position: relative;
    z-index: var(--z-header);
    width: 100%;
}

/* ============================================================
   Top Bar
   ============================================================ */
.header-topbar {
    background: var(--topbar-bg);
    color: var(--topbar-fg);
    border-bottom: 1px solid var(--topbar-border);
    font-family: var(--font-body);
    font-size: 13px;
    line-height: 1.4;
    overflow: visible;
    transition: max-height var(--header-transition),
                opacity var(--header-transition),
                padding var(--header-transition),
                border-width var(--header-transition);
    max-height: 60px;
    padding-top: 10px;
    padding-bottom: 10px;
}

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

.topbar-left,
.topbar-center,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-left {
    flex: 1;
}

.topbar-center {
    flex: 0 0 auto;
}

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

.topbar-trust-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--topbar-fg);
}

.topbar-trust-item i {
    color: var(--topbar-accent);
    font-size: 12px;
}

.topbar-divider {
    width: 1px;
    height: 14px;
    background: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.topbar-contact-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--topbar-fg);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.topbar-contact-link:hover {
    color: #ffffff;
}

.topbar-contact-link i {
    color: var(--topbar-accent);
    font-size: 13px;
}

.topbar-contact-link .fa-whatsapp {
    color: #25D366;
}

/* ============================================================
   Language Switcher (Top Bar)
   ============================================================ */
.header-lang-switcher {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    color: var(--topbar-fg);
    font-size: 13px;
    cursor: pointer;
}

.header-lang-switcher > .fa-globe {
    color: var(--topbar-accent);
    font-size: 14px;
}

/* Adapter output styling */
.header-lang-switcher .jcm-language-switcher {
    position: relative;
}

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

.header-lang-switcher .jcm-language-switcher-dropdown .jcm-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--topbar-fg);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 0;
    font-family: var(--font-body);
    transition: color 0.2s ease;
}

.header-lang-switcher .jcm-language-switcher-dropdown .jcm-dropdown-toggle:hover {
    color: #ffffff;
}

.header-lang-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu,
.header-lang-switcher .jcm-language-switcher ul[class*="dropdown"] {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background: #ffffff;
    border: 1px solid var(--header-border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 6px 0;
    z-index: calc(var(--z-header) + 200);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.header-lang-switcher .jcm-language-switcher-dropdown.is-open .jcm-dropdown-menu,
.header-lang-switcher .jcm-language-switcher ul[class*="dropdown"].is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.header-lang-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu li a,
.header-lang-switcher .jcm-language-switcher ul li a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    color: #334155;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.15s ease, color 0.15s ease;
}

.header-lang-switcher .jcm-language-switcher-dropdown .jcm-dropdown-menu li a:hover {
    background: #F1F5F9;
    color: #2563EB;
}

/* ============================================================
   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-main-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    padding-top: 18px;
    padding-bottom: 18px;
    gap: 20px;
    transition: padding var(--header-transition);
}

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

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

.header-logo {
    width: clamp(144px, 15vw, 220px);
    height: auto;
    display: block;
    transition: width var(--header-transition), opacity var(--header-transition);
}

/* Default state: show light-bg logo, hide dark-bg logo */
.header-logo--light {
    display: block;
}

.header-logo--dark {
    display: none;
}

/* ============================================================
   Desktop Navigation (Center Zone)
   ============================================================ */
.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: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
    font-family: var(--font-heading);
}

.nav-item {
    position: relative;
}

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

.nav-link:hover {
    color: var(--header-accent);
    background: rgba(37, 99, 235, 0.05);
}

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

.nav-item.is-active > .nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 2px;
    background: var(--header-accent);
    border-radius: 2px;
}

.nav-arrow {
    font-size: 10px;
    transition: transform 0.25s ease;
}

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

/* ============================================================
   Action Zone (Right)
   ============================================================ */
.header-actions {
    grid-column: 3;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
}

.header-cta-btn {
    display: none;
    align-items: center;
    gap: 8px;
    background: var(--header-accent);
    color: #ffffff;
    padding: 10px 22px;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

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

.header-cta-btn:hover {
    background: #1D4ED8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

/* ============================================================
   Hamburger
   ============================================================ */
.header-hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

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

.header-hamburger:hover {
    background: rgba(0, 0, 0, 0.04);
}

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

.header-hamburger[aria-expanded="true"] .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.header-hamburger[aria-expanded="true"] .hamburger-line:nth-child(2) {
    opacity: 0;
}

.header-hamburger[aria-expanded="true"] .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ============================================================
   Mega Menu (Desktop)
   ============================================================ */
.mega-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    background: #ffffff;
    border-top: 1px solid var(--header-border);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.05);
    z-index: var(--z-mega-menu);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    pointer-events: none;
    display: none;
}

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

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

.mega-menu-inner {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 32px;
    padding-top: 32px;
    padding-bottom: 32px;
}

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

.mega-category-block {
    min-width: 0;
}

.mega-category-title {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 6px 0;
    line-height: 1.3;
}

.mega-category-title a {
    color: #0C0F14;
    text-decoration: none;
    transition: color 0.2s ease;
}

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

.mega-category-desc {
    font-family: var(--font-body);
    font-size: 12px;
    color: #64748B;
    margin: 0 0 12px 0;
    line-height: 1.5;
}

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

.mega-category-links li {
    margin-bottom: 4px;
}

.mega-category-links li a {
    display: inline-block;
    font-family: var(--font-body);
    font-size: 13px;
    color: #475569;
    text-decoration: none;
    padding: 3px 0;
    transition: color 0.15s ease, padding-left 0.15s ease;
}

.mega-category-links li a:hover {
    color: var(--header-accent);
    padding-left: 4px;
}

.mega-view-all {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--header-accent);
    text-decoration: none;
    transition: gap 0.2s ease;
}

.mega-view-all:hover {
    gap: 8px;
}

/* Mega Menu Support Card */
.mega-menu-support {
    width: 220px;
    flex-shrink: 0;
}

.mega-support-card {
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    padding: 24px 20px;
    text-align: center;
}

.mega-support-icon {
    font-size: 28px;
    color: var(--header-accent);
    margin-bottom: 12px;
}

.mega-support-title {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    color: #0C0F14;
    margin: 0 0 8px 0;
}

.mega-support-desc {
    font-family: var(--font-body);
    font-size: 12px;
    color: #64748B;
    line-height: 1.5;
    margin: 0 0 14px 0;
}

.mega-support-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--header-accent);
    text-decoration: none;
    transition: gap 0.2s ease;
}

.mega-support-link:hover {
    gap: 8px;
}

/* ============================================================
   Scrolled State (.is-scrolled)
   ============================================================ */
.site-header.is-scrolled .header-topbar {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    border-bottom-width: 0;
    overflow: hidden;
    pointer-events: none;
}

.site-header.is-scrolled .header-main {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    z-index: var(--z-header);
}

.site-header.is-scrolled .header-main-inner {
    padding-top: 12px;
    padding-bottom: 12px;
}

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

/* Spacer compensates for fixed header */
.header-spacer {
    display: none;
    height: 0;
}

.site-header.is-scrolled + .header-spacer,
.header-spacer.is-active {
    display: block;
}

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

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

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(12, 15, 20, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(360px, 85vw);
    background: #ffffff;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

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

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
}

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

.drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    color: #334155;
    font-size: 18px;
    transition: background 0.2s ease;
}

.drawer-close:hover {
    background: #F1F5F9;
}

/* Drawer Navigation */
.drawer-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
    min-width: 0;
}

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

.drawer-nav-item {
    border-bottom: 1px solid #F1F5F9;
}

.drawer-nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 20px;
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 500;
    color: #0C0F14;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: color 0.2s ease, background 0.2s ease;
}

.drawer-nav-link:hover {
    background: #F8FAFC;
    color: var(--header-accent);
}

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

.drawer-arrow {
    font-size: 11px;
    transition: transform 0.3s ease;
    color: #94A3B8;
}

.drawer-nav-item--expandable.is-expanded .drawer-arrow {
    transform: rotate(180deg);
}

/* Drawer Submenu */
.drawer-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    background: #F8FAFC;
}

.drawer-nav-item--expandable.is-expanded .drawer-submenu {
    max-height: 1200px;
}

.drawer-category-group {
    padding: 10px 20px 10px 28px;
    border-bottom: 1px solid #E2E8F0;
}

.drawer-category-group:last-child {
    border-bottom: none;
}

.drawer-category-title {
    display: block;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: #0C0F14;
    text-decoration: none;
    margin-bottom: 6px;
    transition: color 0.2s ease;
}

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

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

.drawer-category-links li a {
    display: block;
    font-family: var(--font-body);
    font-size: 13px;
    color: #475569;
    text-decoration: none;
    padding: 4px 0;
    min-width: 0;
    overflow-wrap: anywhere;
    transition: color 0.15s ease;
}

.drawer-category-links li a:hover {
    color: var(--header-accent);
}

/* Drawer Footer */
.drawer-footer {
    padding: 20px;
    border-top: 1px solid var(--header-border);
    flex-shrink: 0;
    min-width: 0;
}

.drawer-contact-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
    min-width: 0;
}

.drawer-contact-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    color: #334155;
    text-decoration: none;
    min-width: 0;
    overflow-wrap: anywhere;
    transition: color 0.2s ease;
}

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

.drawer-contact-link i {
    flex-shrink: 0;
    width: 16px;
    color: var(--header-accent);
}

.drawer-contact-link .fa-whatsapp {
    color: #25D366;
}

.drawer-cta-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    background: var(--header-accent);
    color: #ffffff;
    padding: 12px 20px;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 16px;
    transition: background 0.2s ease;
}

.drawer-cta-btn:hover {
    background: #1D4ED8;
}

/* Drawer Language Switcher */
.drawer-lang-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #475569;
}

.drawer-lang-switcher > .fa-globe {
    color: var(--header-accent);
    font-size: 14px;
    flex-shrink: 0;
}

.drawer-lang-switcher .jcm-language-switcher ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.drawer-lang-switcher .jcm-language-switcher ul li a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #475569;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 3px;
    border: 1px solid #E2E8F0;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.drawer-lang-switcher .jcm-language-switcher ul li a:hover {
    border-color: var(--header-accent);
    color: var(--header-accent);
}

/* ============================================================
   Mobile Responsive
   ============================================================ */
@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-right {
        justify-content: flex-end;
        flex: 1;
    }

    .header-topbar {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .header-main-inner {
        grid-template-columns: 1fr auto;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .header-nav {
        display: none;
    }

    .header-actions {
        grid-column: 2;
    }

    .header-logo {
        width: clamp(120px, 28vw, 176px);
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .topbar-left {
        display: none;
    }

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

    .header-main-inner {
        grid-template-columns: 1fr auto;
    }

    .header-nav {
        display: none;
    }

    .header-actions {
        grid-column: 2;
    }

    .header-logo {
        width: clamp(140px, 20vw, 190px);
    }
}

/* ============================================================
   Scrolled State Mobile Fix
   ============================================================ */
@media (max-width: 1023px) {
    .site-header.is-scrolled .header-main-inner {
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

/* ============================================================
   Body scroll lock when drawer is open
   ============================================================ */
body.drawer-is-open {
    overflow: hidden;
}

/* ============================================================
   Mega Menu Responsive (narrower desktops)
   ============================================================ */
@media (min-width: 1024px) and (max-width: 1279px) {
    .mega-menu-categories {
        grid-template-columns: repeat(2, 1fr);
    }

    .mega-menu-inner {
        grid-template-columns: 1fr 200px;
    }

    .mega-menu-support {
        width: 200px;
    }
}

@media (min-width: 1280px) {
    .mega-menu-categories {
        grid-template-columns: repeat(4, 1fr);
    }
}
