/*
 * Header — modern, clean, no legacy dependency.
 * BEM-style namespace: .hd-d__* (desktop), .hd-mbar__* (mobile bar), .hd-menu__* (off-canvas).
 *
 * Mobile menu is independent: own DOM (.hd-menu), own JS (header-mobile.js).
 * Legacy .navigation/#cssmenu hidden visually on mobile (CSS) — kept for desktop.
 */

/* ──────────────── COMMON ──────────────── */
.hd-mbar,
.hd-msearch,
.hd-mslogan,
.hd-menu,
.hd-menu-backdrop {
    display: none;
}

/* ──────────────── DESKTOP (≥992px) ──────────────── */
.hd-d {
    background: #fff;
}
.hd-d__inner {
    display: flex;
    align-items: center;
    max-width: 1440px;
    margin: 0 auto;
    padding: 10px 15px;
    gap: 16px;
}
.hd-d__logo {
    flex: 0 0 auto;
    line-height: 0;
}
.hd-d__logo img {
    display: block;
    width: 300px;
    max-width: 100%;
    height: auto;
}
.hd-d__slogan {
    flex: 1 1 auto;
    text-align: center;
    line-height: 0;
}
.hd-d__slogan img {
    display: inline-block;
    width: 300px;
    height: 30px;
    max-width: 100%;
}
.hd-d__search {
    flex: 0 0 280px;
    max-width: 280px;
}
.hd-d__theme {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
}

/* ──────────────── MOBILE (<992px) ──────────────── */
@media (max-width: 991px) {
    /* Hide desktop block */
    .hd-d { display: none; }

    /* Disable legacy fixed-bar — invisible but kept in DOM for any leftover JS refs */
    #cssmenu.table_all_menu {
        position: static !important;
        background: transparent !important;
        height: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }
    .navigation {
        display: none !important;
    }

    /* MOBILE BAR — fixed top */
    .hd-mbar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        align-items: center;
        gap: 6px;
        padding: 6px 10px;
        height: 52px;
        background: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,.06);
    }

    /* Hamburger 30px */
    .hd-mbar__ham {
        flex: 0 0 30px;
        width: 30px;
        height: 30px;
        padding: 4px;
        background: transparent;
        border: 0;
        cursor: pointer;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        -webkit-tap-highlight-color: transparent;
    }
    .hd-mbar__ham span {
        display: block;
        width: 22px;
        height: 3px;
        background: #404759;
        border-radius: 2px;
        transition: transform .25s, opacity .15s;
    }
    .hd-mbar__ham:hover span { background: #d90202; }
    body.hd-menu-open .hd-mbar__ham span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    body.hd-menu-open .hd-mbar__ham span:nth-child(2) { opacity: 0; }
    body.hd-menu-open .hd-mbar__ham span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    /* Theme toggle 38px (visual styles in dark-mode.css) */
    .hd-mbar__theme {
        flex: 0 0 38px;
        width: 38px;
        height: 38px;
    }

    /* Logo (free flex) */
    .hd-mbar__logo {
        flex: 1 1 auto;
        text-align: center;
        min-width: 0;
        line-height: 0;
        overflow: hidden;
    }
    .hd-mbar__logo img {
        display: inline-block;
        max-width: 100%;
        max-height: 36px;
        width: auto;
        height: auto;
        vertical-align: middle;
    }

    /* Avatar slot 40px (mini-login plugin overlays here) */
    .hd-mbar__avatar {
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
    }

    /* Search 30px */
    .hd-mbar__search {
        flex: 0 0 30px;
        width: 30px;
        height: 30px;
        padding: 3px;
        background: transparent;
        border: 0;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .hd-mbar__search img {
        display: block;
        width: 24px;
        height: 24px;
    }
    .hd-mbar__search:hover img {
        filter: brightness(0) saturate(100%) invert(18%) sepia(93%) saturate(5236%) hue-rotate(356deg) brightness(89%) contrast(118%);
    }

    /* Mini-login avatar override */
    #mini-login-widget {
        position: fixed !important;
        top: 6px !important;
        right: 50px !important;
    }

    /* Search dropdown */
    .hd-msearch {
        position: fixed;
        top: 52px;
        left: 0;
        right: 0;
        z-index: 999;
        padding: 10px;
        background: #fff;
        border-bottom: 1px solid #d1d5db;
        box-shadow: 0 4px 16px rgba(0,0,0,.12);
    }
    .hd-msearch.active { display: block; }

    /* Slogan */
    .hd-mslogan {
        display: block;
        text-align: center;
        margin-top: 60px;
        padding: 6px 10px;
        line-height: 0;
    }
    .hd-mslogan img {
        display: inline-block;
        max-width: 300px;
        height: auto;
    }

    /* ─── OFF-CANVAS MENU ─── */
    .hd-menu {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(280px, 80vw);
        z-index: 1010;
        background: #fff;
        box-shadow: 2px 0 16px rgba(0,0,0,.2);
        transform: translateX(-100%);
        transition: transform .25s ease;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    body.hd-menu-open .hd-menu {
        transform: translateX(0);
    }
    .hd-menu__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        border-bottom: 1px solid #e5e7eb;
    }
    .hd-menu__title {
        font-weight: 700;
        font-size: 16px;
        text-transform: uppercase;
        letter-spacing: .5px;
        color: #1f2937;
    }
    .hd-menu__close {
        width: 32px;
        height: 32px;
        background: transparent;
        border: 0;
        font-size: 28px;
        line-height: 1;
        color: #404759;
        cursor: pointer;
        padding: 0;
    }
    .hd-menu__close:hover { color: #d90202; }
    .hd-menu__body {
        padding: 8px 0;
    }
    .hd-menu__list,
    .hd-menu__list ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    .hd-menu__list li {
        border-bottom: 1px solid #f3f4f6;
    }
    .hd-menu__list a {
        display: block;
        padding: 12px 16px;
        color: #1f2937;
        text-decoration: none;
        font-size: 15px;
    }
    .hd-menu__list a:hover {
        background: #f3f4f6;
        color: #d90202;
    }
    .hd-menu__list .sub-menu {
        display: none;
        background: #f9fafb;
    }
    .hd-menu__list .menu-item-has-children.is-open > .sub-menu {
        display: block;
    }
    .hd-menu__list .sub-menu a {
        padding-left: 32px;
        font-size: 14px;
        color: #374151;
    }
    .hd-menu__list .menu-item-has-children > a::after {
        content: '▾';
        float: right;
        margin-left: 8px;
        font-size: 12px;
        opacity: .6;
        transition: transform .2s;
    }
    .hd-menu__list .menu-item-has-children.is-open > a::after {
        transform: rotate(180deg);
    }

    /* Backdrop */
    .hd-menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1009;
        background: rgba(0,0,0,.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s ease;
    }
    body.hd-menu-open .hd-menu-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
    body.hd-menu-open {
        overflow: hidden;
    }
}

/* ──────────────── THEME TOGGLE base (sun/moon swap CSS in dark-mode.css) ──────────────── */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 50%;
    color: #475569;
    cursor: pointer;
    transition: background .2s, color .2s, transform .2s;
}
.theme-toggle:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}
