/**
 * Header Builder Enterprise - Estilos del header
 * Mobile-first: base = móvil, min-width para tablet/desktop
 */

/* Variables CSS */
:root {
    --hbe-height: 70px;
    --hbe-bg: #ffffff;
    --hbe-border: #e5e7eb;
    --hbe-text: #1f2937;
    --hbe-text-muted: #6b7280;
    --hbe-accent: #2563eb;
    --hbe-accent-hover: #1d4ed8;
    --hbe-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --hbe-shadow-sticky: 0 4px 12px rgba(0, 0, 0, 0.1);
    --hbe-transition: 0.2s ease;
}

/* Header principal - base móvil */
.hbe-header {
    position: relative;
    background: var(--hbe-bg);
    border-bottom: 1px solid var(--hbe-border);
    box-shadow: var(--hbe-shadow);
    z-index: 1000;
    overflow: visible;
    transition: transform var(--hbe-transition), box-shadow var(--hbe-transition);
}

.hbe-header.hbe-header-sticky {
    position: sticky;
    top: 0;
}

.hbe-header.hbe-header-sticky.is-scrolled {
    box-shadow: var(--hbe-shadow-sticky);
}

.hbe-header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
    overflow: visible;
}

/* Móvil: 2 filas - la fila crece para el buscador */
.hbe-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    align-content: flex-start;
    gap: 8px;
    min-height: var(--hbe-height);
    padding: 8px 0;
    position: relative;
}

/* Móvil: orden de elementos */
.hbe-logo { order: 1; }
.hbe-megamenu-trigger { order: 2; }
.hbe-cart { order: 3; }
.hbe-account { order: 4; }
.hbe-mobile-toggle { order: 5; }

/* Logo */
.hbe-logo {
    flex-shrink: 0;
}

.hbe-logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--hbe-text);
    font-weight: 700;
    font-size: 1.5rem;
    transition: opacity var(--hbe-transition);
}

.hbe-logo-link:hover {
    opacity: 0.85;
}

.hbe-logo-link img {
    max-height: var(--hbe-logo-height, calc(var(--hbe-height) - 20px));
    width: auto;
    object-fit: contain;
}

.hbe-logo-text {
    white-space: nowrap;
}

/* Catálogo / Mega menú trigger - móvil: solo icono */
.hbe-catalog-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    padding: 10px 12px;
    background: var(--hbe-accent);
    color: #fff !important;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background var(--hbe-transition), transform var(--hbe-transition);
}

.hbe-catalog-btn:hover {
    background: var(--hbe-accent-hover);
}

.hbe-catalog-btn:focus {
    outline: 2px solid var(--hbe-accent);
    outline-offset: 2px;
}

.hbe-catalog-btn[aria-expanded="true"] {
    background: var(--hbe-accent-hover);
}

.hbe-catalog-btn .hbe-catalog-text {
    display: none;
}

/* Navegación - oculta en móvil */
.hbe-nav {
    display: none;
}

.hbe-menu {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.hbe-menu li {
    margin: 0;
}

.hbe-menu a {
    display: block;
    padding: 10px 14px;
    color: var(--hbe-text);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 6px;
    transition: color var(--hbe-transition), background var(--hbe-transition);
}

.hbe-menu a:hover {
    color: var(--hbe-accent);
    background: rgba(37, 99, 235, 0.08);
}

/* Buscador - móvil: fila 2, ancho completo, forzar visibilidad */
.hbe-search {
    display: flex !important;
    order: 10;
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0;
    max-width: none;
}

.hbe-search-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    min-width: 0;
}

.hbe-search-form {
    display: flex;
    align-items: center;
    background: #f3f4f6;
    border: 1px solid var(--hbe-border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color var(--hbe-transition), box-shadow var(--hbe-transition);
}

.hbe-search-form:focus-within {
    border-color: var(--hbe-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hbe-search-input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: none;
    background: transparent;
    font-size: 0.85rem;
    color: var(--hbe-text);
}

.hbe-search-input::placeholder {
    color: var(--hbe-text-muted);
}

.hbe-search-input:focus {
    outline: none;
}

.hbe-search-submit {
    flex-shrink: 0;
    padding: 8px 12px;
    border: none;
    background: var(--hbe-accent);
    color: #fff;
    cursor: pointer;
    transition: background var(--hbe-transition);
}

.hbe-search-submit:hover {
    background: var(--hbe-accent-hover);
}

/* Resultados búsqueda AJAX */
.hbe-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--hbe-border);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

.hbe-search-results.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.hbe-search-results.loading {
    padding: 24px;
    text-align: center;
    color: var(--hbe-text-muted);
}

.hbe-search-result-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--hbe-text);
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
}

.hbe-search-result-item:last-child {
    border-bottom: none;
}

.hbe-search-result-item:hover {
    background: #f9fafb;
}

.hbe-search-result-image {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    background: #f3f4f6;
}

.hbe-search-result-info {
    flex: 1;
    min-width: 0;
}

.hbe-search-result-title {
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hbe-search-result-price {
    font-size: 0.9rem;
    color: var(--hbe-accent);
    font-weight: 600;
}

/* Carrito */
.hbe-cart {
    flex-shrink: 0;
}

.hbe-account .hbe-account-text {
    display: none;
}

.hbe-cart-link {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px;
    color: var(--hbe-text);
    text-decoration: none;
    border-radius: 8px;
    transition: background var(--hbe-transition), color var(--hbe-transition);
    position: relative;
}

.hbe-cart-link:hover {
    background: #f3f4f6;
    color: var(--hbe-accent);
}

.hbe-cart-count {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--hbe-accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Cuenta */
.hbe-account {
    flex-shrink: 0;
}

.hbe-account-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: var(--hbe-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    border-radius: 8px;
    transition: background var(--hbe-transition), color var(--hbe-transition);
}

.hbe-account-link:hover {
    background: #f3f4f6;
    color: var(--hbe-accent);
}

/* Mobile toggle - visible en móvil */
.hbe-mobile-toggle {
    display: flex;
    margin-left: auto;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    transition: background var(--hbe-transition);
}

.hbe-mobile-toggle:hover {
    background: #f3f4f6;
}

.hbe-mobile-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--hbe-text);
    border-radius: 1px;
    transition: transform 0.3s, opacity 0.3s;
}

.hbe-mobile-toggle.is-active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.hbe-mobile-toggle.is-active span:nth-child(2) {
    opacity: 0;
}

.hbe-mobile-toggle.is-active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Mobile menu - overlay (se abre con toggle) */
.hbe-mobile-menu {
    display: block;
    position: fixed;
    top: var(--hbe-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 999;
    overflow-y: auto;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.hbe-mobile-menu.is-open {
    opacity: 1;
    visibility: visible;
}

.hbe-mobile-search {
    margin-bottom: 24px;
}

.hbe-mobile-search .hbe-search-form {
    width: 100%;
}

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

.hbe-mobile-nav li {
    margin: 0;
    border-bottom: 1px solid #f3f4f6;
}

.hbe-mobile-nav a {
    display: block;
    padding: 16px 0;
    color: var(--hbe-text);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--hbe-transition);
}

.hbe-mobile-nav a:hover {
    color: var(--hbe-accent);
}

/* Mobile: menú debajo del header de 2 filas */
.hbe-mobile-menu {
    top: calc(var(--hbe-height) + 52px);
}

/* Tablet: 769px+ */
@media (min-width: 769px) {
    .hbe-header-inner {
        padding: 0 20px;
    }

    .hbe-header-row {
        gap: 12px;
    }

    .hbe-search .hbe-search-input {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .hbe-search .hbe-search-submit {
        padding: 10px 14px;
    }

    .hbe-mobile-menu {
        top: calc(var(--hbe-height) + 56px);
    }
}

/* Desktop: 1025px+ - una fila, nav visible, ocultar mobile */
@media (min-width: 1025px) {
    .hbe-header-inner {
        padding: 0 24px;
    }

    .hbe-header-row {
        flex-wrap: nowrap;
        gap: 24px;
    }

    .hbe-nav {
        display: flex !important;
        flex: 1;
        align-items: center;
        min-width: 0;
    }

    .hbe-mobile-toggle {
        display: none !important;
    }

    .hbe-mobile-menu {
        display: none !important;
    }

    .hbe-logo { order: 1; }
    .hbe-megamenu-trigger { order: 2; }
    .hbe-nav { order: 3; }
    .hbe-search { order: 4; }
    .hbe-cart { order: 5; }
    .hbe-account { order: 6; }

    .hbe-search {
        order: 4;
        flex: 1 1 auto;
        width: auto;
        min-width: 200px;
        max-width: 480px;
    }

    .hbe-catalog-btn {
        padding: 10px 16px;
    }

    .hbe-catalog-btn .hbe-catalog-text {
        display: inline;
    }

    .hbe-account .hbe-account-text {
        display: inline;
    }

    .hbe-cart-link {
        padding: 10px 14px;
    }

    .hbe-search-input {
        padding: 12px 16px;
        font-size: 0.95rem;
    }

    .hbe-search-submit {
        padding: 12px 16px;
    }
}
