/* =================================================
   Custom Header — Tienda Globus v5.0
   ================================================= */

/* Variables — sobreescritas desde PHP con los ajustes */
:root {
    --ch-accent:     #1a3a5c;
    --ch-nav-bg:     #ffffff;
    --ch-nav-text:   #222222;
    --ch-top-bg:     #ffffff;
    --ch-top-text:   #222222;
    --ch-top-h:      70px;
    --ch-max-w:      1280px;
    --ch-radius:     8px;
    --ch-transition: .18s ease;
}

/* ── Admin bar ── */
.admin-bar #ch { top: 32px; }
@media screen and (max-width: 782px) {
    .admin-bar #ch { top: 46px; }
    .admin-bar .ch-panel { top: 46px; }
}

/* ══════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════ */
#ch {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    background: var(--ch-top-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1;
    color: var(--ch-top-text);
    transition: box-shadow .3s;
}

#ch.is-scrolled {
    box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.07);
}

#ch .ch-wrap {
    max-width: var(--ch-max-w, 1280px);
    margin: 0 auto;
    padding: 0 28px;
    display: flex;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

/* ── Fila 1: Logo / Central / Acciones ── */
#ch .ch-bar--top {
    height: var(--ch-top-h);
    background: var(--ch-top-bg);
    border-bottom: 1px solid rgba(0,0,0,.06);
}

#ch .ch-bar--top .ch-wrap {
    height: 100%;
    gap: 24px;
}

/* Logo */
#ch .ch-logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    text-decoration: none;
    line-height: 0;
    box-sizing: border-box;
}

#ch .ch-logo__img {
    display: block;
    height: calc(var(--ch-top-h) * .55);
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

#ch .ch-logo__text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ch-accent);
    letter-spacing: -.02em;
    white-space: nowrap;
}

/* Espacio central (buscador u otro contenido) */
#ch .ch-search {
    flex: 1;
    min-width: 0;
    max-width: 560px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

/*
 * FiboSearch inyecta estilos inline en sus elementos con alta especificidad.
 * Los !important aquí son necesarios para poder ganarle.
 * No se usan en ningún otro sitio del plugin.
 */
#ch .ch-search .dgwt-wcas-search-wrapp {
    width: 100% !important;
    margin: 0 !important;
    display: block !important;
}
#ch .ch-search .dgwt-wcas-sf-wrapp {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
}
#ch .ch-search .dgwt-wcas-search-input,
#ch .ch-search input[type="search"],
#ch .ch-search input[type="text"] {
    width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    float: none !important;
}
#ch .ch-search form {
    width: 100% !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
}
#ch .ch-search .search-field {
    flex: 1 !important;
    width: 100% !important;
}

/* Acciones: carrito + cuenta */
#ch .ch-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    box-sizing: border-box;
}

#ch .ch-icon-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--ch-radius);
    color: var(--ch-top-text);
    text-decoration: none;
    background: transparent;
    border: none;
    box-shadow: none;
    cursor: pointer;
    transition: background var(--ch-transition), color var(--ch-transition);
    box-sizing: border-box;
}

#ch .ch-icon-btn::before,
#ch .ch-icon-btn::after { display: none; }

#ch .ch-icon-btn:hover {
    background: rgba(0,0,0,.055);
    color: var(--ch-accent);
}

#ch .ch-icon-btn svg { display: block; flex-shrink: 0; }

/* Badge carrito */
#ch .ch-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--ch-accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    border: 2px solid var(--ch-top-bg);
    box-sizing: border-box;
}

#ch .ch-badge[hidden] { display: none; }

/* Hamburguesa móvil */
#ch .ch-burger {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: none;
    border: none;
    box-shadow: none;
    border-radius: var(--ch-radius);
    cursor: pointer;
    box-sizing: border-box;
}

#ch .ch-burger::before,
#ch .ch-burger::after { display: none; }

#ch .ch-burger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--ch-top-text);
    border-radius: 2px;
    transition: transform .22s ease, opacity .22s ease;
}

#ch .ch-burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#ch .ch-burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; transform: scaleX(0); }
#ch .ch-burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Fila 2: Barra de categorías ── */
#ch .ch-bar--nav {
    height: 44px;
    background: var(--ch-nav-bg);
    border-bottom: 1px solid rgba(0,0,0,.06);
}

#ch .ch-bar--nav .ch-wrap {
    height: 100%;
    gap: 0;
    overflow: hidden;
}

/* Botón "Todo" */
html body #ch .ch-todo-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 16px;
    background: var(--ch-accent);
    color: #fff;
    border: none;
    border-radius: 0;
    box-shadow: none;
    cursor: pointer;
    font-size: .87rem;
    font-weight: 600;
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
    transition: filter var(--ch-transition);
    box-sizing: border-box;
}

#ch .ch-todo-btn::before,
#ch .ch-todo-btn::after { display: none; }

html body #ch .ch-todo-btn:hover,
html body #ch .ch-todo-btn[aria-expanded="true"] { filter: brightness(.82); }

#ch .ch-todo-btn svg  { stroke: #fff; flex-shrink: 0; }
#ch .ch-todo-btn span { color: #fff; }

/* Separador vertical entre el botón y las categorías */
#ch .ch-nav-sep {
    flex-shrink: 0;
    width: 1px;
    height: 20px;
    margin: 0 6px;
    background: rgba(128,128,128,.2);
}

/* Lista de categorías fijas */
#ch .ch-cats {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: stretch;
    height: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    flex-wrap: nowrap;
}

#ch .ch-cat {
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
    list-style: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#ch .ch-cat__link {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 10px;
    height: 100%;
    color: var(--ch-nav-text);
    text-decoration: none;
    font-size: .83rem;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: background var(--ch-transition), border-color var(--ch-transition), opacity var(--ch-transition);
    box-sizing: border-box;
}

#ch .ch-cat__link:hover {
    background: rgba(128,128,128,.1);
    border-bottom-color: var(--ch-nav-text);
}

#ch .ch-cat.is-active .ch-cat__link {
    font-weight: 600;
    border-bottom-color: var(--ch-nav-text);
}

#ch .ch-cat__icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
}



/* ══════════════════════════════════════════════
   OVERLAY
   Gestiona la profundidad visual detrás del panel.
   z-index deliberadamente por debajo del panel (10000)
   y por encima del header (1000).
   ══════════════════════════════════════════════ */
.ch-overlay {
    position: fixed;
    inset: 0;
    z-index: 1001;
    background: rgba(10,20,40,.48);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .28s ease, visibility .28s ease;
    /* visibility evita que reciba eventos cuando está oculto */
}

.ch-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* ══════════════════════════════════════════════
   PANEL LATERAL "TODO"
   ══════════════════════════════════════════════ */
.ch-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1002;
    width: 300px;
    max-width: 88vw;
    display: flex;
    flex-direction: column;
    background: #fff;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    box-shadow: 2px 0 24px rgba(0,0,0,.12);
    /* hidden gestionado por JS con clase, no atributo,
       para que la transición funcione correctamente */
}

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

/* Cabecera del panel */
.ch-panel__head {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 14px 0 20px;
    background: var(--ch-accent);
    box-sizing: border-box;
}

.ch-panel__title {
    font-size: .9rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: .01em;
}

html body .ch-panel__close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    background: rgba(255,255,255,.12);
    border: none;
    border-radius: 6px;
    box-shadow: none;
    cursor: pointer;
    color: #fff;
    font-size: 0;
    transition: background var(--ch-transition);
    box-sizing: border-box;
}

.ch-panel__close::before,
.ch-panel__close::after { display: none; }

.ch-panel__close svg { display: block; }

html body .ch-panel__close:hover { background: rgba(255,255,255,.24); }

/* Cuerpo scrolleable */
.ch-panel__body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 0 48px;
    scrollbar-width: thin;
    scrollbar-color: #e0e0e0 transparent;
    box-sizing: border-box;
}

.ch-panel__body::-webkit-scrollbar       { width: 3px; }
.ch-panel__body::-webkit-scrollbar-track { background: transparent; }
.ch-panel__body::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

/* Reset listas dentro del panel */
.ch-panel ul,
.ch-panel ol,
.ch-panel li {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Ítem de categoría */
.ch-panel__item {
    border-bottom: 1px solid #f0f0f0;
}

.ch-panel__item:last-child { border-bottom: none; }

/* Fila: enlace + toggle */
.ch-panel__row {
    display: flex;
    align-items: stretch;
    min-height: 52px;
}

/* Enlace de navegación */
.ch-panel__link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px 12px 20px;
    color: #1a2a3a;
    text-decoration: none;
    font-size: .88rem;
    font-weight: 500;
    line-height: 1.3;
    min-width: 0;
    transition: background var(--ch-transition), color var(--ch-transition);
    box-sizing: border-box;
}

.ch-panel__link:hover {
    background: #f4f7fb;
    color: var(--ch-accent);
}

/* Categoría activa (página actual) — fondo acento, texto blanco */
/* Ítem desplegado — acordeón abierto */
html body .ch-panel .ch-panel__item.is-open > .ch-acc-row .ch-panel__link,
html body .ch-panel .ch-panel__item.is-open > .ch-acc-row a.ch-panel__link {
    background: var(--ch-accent) !important;
    color: #fff !important;
    font-weight: 600;
}

html body .ch-panel .ch-panel__item.is-open > .ch-acc-row .ch-acc-btn,
html body .ch-panel .ch-panel__item.is-open > .ch-acc-row .ch-panel__toggle {
    color: rgba(255,255,255,.8) !important;
    border-left-color: rgba(255,255,255,.2) !important;
}

html body .ch-panel .ch-panel__item.is-open > .ch-acc-row .ch-panel__link:hover,
html body .ch-panel .ch-panel__item.is-open > .ch-acc-row a.ch-panel__link:hover {
    filter: brightness(.9);
    color: #fff !important;
}

/* Estado activo — categoría madre actual */
.ch-panel__item.is-current-cat > .ch-acc-row .ch-panel__link {
    background: var(--ch-accent);
    color: #fff;
    font-weight: 600;
}

.ch-panel__item.is-current-cat > .ch-acc-row .ch-panel__link:hover {
    background: var(--ch-accent);
    filter: brightness(.88);
    color: #fff;
}

.ch-panel__item.is-current-cat > .ch-acc-row .ch-acc-btn,
.ch-panel__item.is-current-cat > .ch-acc-row .ch-panel__toggle {
    color: rgba(255,255,255,.8);
    border-left-color: rgba(255,255,255,.2);
}

/* También para menús de WordPress (clases nativas) */
.ch-panel__item.current-menu-item > .ch-acc-row .ch-panel__link,
.ch-panel__item.current-menu-ancestor > .ch-acc-row .ch-panel__link,
.ch-panel__item.current-menu-parent > .ch-acc-row .ch-panel__link {
    background: var(--ch-accent);
    color: #fff;
    font-weight: 600;
}

.ch-panel__item.current-menu-item > .ch-acc-row .ch-acc-btn,
.ch-panel__item.current-menu-ancestor > .ch-acc-row .ch-acc-btn,
.ch-panel__item.current-menu-parent > .ch-acc-row .ch-panel__toggle {
    color: rgba(255,255,255,.8);
    border-left-color: rgba(255,255,255,.2);
}

.ch-panel__link img {
    display: block;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    object-fit: contain;
    opacity: .85;
}

.ch-panel__link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Botón toggle — solo despliega subcategorías */
html body .ch-panel__toggle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: auto; /* se estira al alto de .ch-panel__row */
    padding: 0;
    background: none;
    border: none;
    border-left: 1px solid #efefef;
    border-radius: 0;
    box-shadow: none;
    cursor: pointer;
    color: #c0c8d4;
    font-size: 0;
    transition: background var(--ch-transition), color var(--ch-transition);
    box-sizing: border-box;
}

.ch-panel__toggle::before,
.ch-panel__toggle::after { display: none; }

.ch-panel__toggle svg {
    display: block;
    transition: transform .25s ease;
}

html body .ch-panel__toggle:hover {
    background: #f4f7fb;
    color: var(--ch-accent);
}

.ch-panel__item.is-open .ch-panel__toggle {
    color: var(--ch-accent);
    background: #edf2f8;
}

.ch-panel__item.is-open .ch-panel__toggle svg {
    transform: rotate(180deg);
}

/* Subcategorías — acordeón */
.ch-panel__subs {
    overflow: hidden;
    max-height: 0;
    transition: max-height .28s ease;
    background: #f8f9fb;
    border-top: 1px solid #efefef;
}

.ch-panel__subs li {
    border-bottom: 1px solid #efefef;
}

.ch-panel__subs li:last-child { border-bottom: none; }

.ch-panel__subs a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px 11px 32px;
    color: #4a5568;
    text-decoration: none;
    font-size: .84rem;
    transition: background var(--ch-transition), color var(--ch-transition);
    box-sizing: border-box;
}

.ch-panel__subs a:hover {
    background: #edf2f8;
    color: var(--ch-accent);
}

.ch-panel__subs img {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    object-fit: contain;
    opacity: .7;
}

/* ── Fila búsqueda móvil ── */
#ch .ch-bar--search {
    display: none; /* oculta en escritorio, el buscador ya está en fila 1 */
    background: var(--ch-top-bg);
    border-bottom: 1px solid rgba(0,0,0,.06);
    padding: 8px 0;
}

#ch .ch-bar--search .ch-wrap {
    height: auto;
    padding: 0 16px;
}

#ch .ch-bar--search .ch-search {
    max-width: 100%;
    margin: 0;
    width: 100%;
}

/* ── Sistema de acordeón genérico (ch-acc-*) ── */

/* Contenedor cuerpo — oculto por defecto */
.ch-acc-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height .28s ease;
}

/* Botón toggle — rota la flecha al abrirse */
.ch-acc-item.is-open > .ch-acc-row .ch-acc-btn svg,
.ch-panel__sub-item.is-open3 > .ch-panel__sub-row .ch-panel__toggle3 svg {
    transform: rotate(180deg);
}

/* Abrir panel__subs3 cuando is-open3 */
.ch-panel__sub-item.is-open3 > .ch-panel__subs3 {
    max-height: 9999px !important;
}

/* Estilos visuales por profundidad */
.ch-panel__item.depth-1 { border-bottom: none; }
.ch-panel__item.depth-1 > .ch-acc-row { background: #f8f9fb; }

.ch-panel__item.depth-1 .ch-panel__link {
    padding-left: 32px;
    font-size: .855rem;
    font-weight: 400;
    color: #4a5568;
}
.ch-panel__item.depth-1 .ch-panel__link:hover { color: var(--ch-accent); background: #edf2f8; }

.ch-panel__item.depth-2 > .ch-acc-row { background: #f2f4f8; }
.ch-panel__item.depth-2 .ch-panel__link {
    padding-left: 44px;
    font-size: .83rem;
    font-weight: 400;
    color: #5a6880;
}
.ch-panel__item.depth-2 .ch-panel__link:hover { color: var(--ch-accent); background: #e4eaf4; }

/* Separadores */
.ch-panel__subs-wrap { border-top: 1px solid #efefef; }
.ch-acc-body .ch-acc-item { border-bottom: 1px solid #efefef; }
.ch-acc-body .ch-acc-item:last-child { border-bottom: none; }

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */
@media (max-width: 960px) {
    #ch .ch-wrap { padding: 0 16px; }
    #ch .ch-search { max-width: none; }
}

@media (max-width: 640px) {
    .admin-bar #ch   { top: 0; }
    #ch .ch-bar--nav { display: none; }
    #ch .ch-bar--top .ch-search { display: none; }
    #ch .ch-bar--search { display: block; }

    /* Hamburguesa izquierda · Logo centro · Carrito+Cuenta derecha */
    #ch .ch-bar--top .ch-wrap {
        gap: 0;
        justify-content: space-between;
    }

    #ch .ch-burger {
        display: flex;
        order: 1;
        flex-shrink: 0;
    }

    #ch .ch-logo {
        order: 2;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    #ch .ch-actions {
        order: 3;
        margin-left: auto;
    }

    /* Ocultar el burger original que estaba al final de .ch-actions */
    #ch .ch-actions .ch-burger { display: none; }

    .ch-panel { width: 100%; max-width: 100%; }
}


/* Ocultar iconos cuando show_icons = 0 en ajustes */
.ch-icons-off .ch-cat__icon,
.ch-icons-off .ch-panel__link img {
    display: none;
}
