/**
 * Top Pneus - Styles Header
 *
 * Custom components for the Blocksy header:
 * - Cart icon badge (.tp-cart-link, .tp-cart-count)
 * - Language switcher (.tp-lang-switcher)
 * - Search form (.tp-header-search)
 * - Top bar (.tp-top-bar)
 * - Live search results (.tp-search-results)
 *
 * Blocksy-native elements (nav, logo, colors, buttons) are controlled
 * via Blocksy Customizer / set_theme_mod() — see inc/setup.php.
 *
 * @package TopPneus
 * @since 2.0.0
 * @version 3.9.0
 */

/* -------------------------------------------------------------------------
   ACTIONS HEADER (Panier custom)
   ------------------------------------------------------------------------- */

.tp-header-actions {
    display: flex;
    align-items: center;
    gap: var(--tp-space-md);
}

.tp-cart-link {
    position: relative;
    display: flex;
    align-items: center;
    padding: var(--tp-space-sm);
    color: var(--tp-gray-700);
    text-decoration: none;
}

.tp-cart-link:hover {
    color: var(--tp-red);
}

.tp-cart-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--tp-secondary);
    color: var(--tp-white);
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* -------------------------------------------------------------------------
   CART — Bottom row alignment + badge overflow fix
   Blocksy cart badge uses position:absolute, needs padding to not clip.
   ------------------------------------------------------------------------- */

.ct-header [data-row="bottom"] [data-id="cart"] {
    padding-right: 10px;
}

/* -------------------------------------------------------------------------
   CART DROPDOWN — Shadow (no native Blocksy option for dropdown mode)
   ------------------------------------------------------------------------- */

.ct-cart-content {
    box-shadow: var(--tp-shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
    border: 1px solid var(--tp-gray-200, #e5e7eb);
    border-radius: var(--tp-radius-lg, 8px);
}

/* ==========================================================================
   LANGUAGE SWITCHER
   ========================================================================== */

.tp-lang-switcher {
    display: flex;
    align-items: center;
}

.tp-lang-list {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 2px;
}

.tp-lang-item {
    list-style: none;
}

.tp-lang-item a {
    display: block;
    padding: 6px 10px;
    color: var(--tp-gray-600, #6b7280);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    border-radius: var(--tp-radius-sm, 4px);
    transition: all 0.15s ease;
}

.tp-lang-item a:hover {
    color: var(--tp-primary, #1a1a1a);
    background: var(--tp-gray-100, #f3f4f6);
}

.tp-lang-item.tp-lang-current a {
    color: var(--tp-primary, #1a1a1a);
    font-weight: 600;
    background: var(--tp-gray-100, #f3f4f6);
}

/* Séparateur visuel entre langues */
.tp-lang-item:not(:last-child)::after {
    content: "";
    display: inline-block;
}

/* Version dropdown */
.tp-lang-select {
    padding: 6px 28px 6px 12px;
    border: 1px solid var(--tp-gray-300, #d1d5db);
    border-radius: var(--tp-radius-sm, 4px);
    background: var(--tp-white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M3 5l3 3 3-3'/%3E%3C/svg%3E") right 8px center no-repeat;
    font-size: 13px;
    font-weight: 500;
    color: var(--tp-gray-700, #374151);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.tp-lang-select:hover {
    border-color: var(--tp-primary, #1a1a1a);
}

.tp-lang-select:focus {
    outline: none;
    border-color: var(--tp-primary, #1a1a1a);
    box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.1);
}

/* Integration avec header Blocksy (HTML element) */
/* Visual separator between cart and language switcher (@ux-expert) */
/* :not(.ct-panel) excludes offcanvas which also has .ct-header */
.ct-header:not(.ct-panel) .tp-lang-switcher {
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid var(--tp-gray-200);
}

.ct-header .tp-lang-list {
    display: flex !important;
    align-items: center !important;
    gap: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
}

.ct-header .tp-lang-item {
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ct-header .tp-lang-item a {
    display: inline-flex !important;
    align-items: center !important;
    padding: 0 10px !important;
    margin: 0 !important;
    font-size: 13px !important;
    font-weight: 500;
    color: var(--tp-gray-700) !important;
    background: transparent !important;
    border-radius: 0 !important;
    line-height: 1 !important;
    text-decoration: none !important;
    height: auto !important;
}

.ct-header .tp-lang-item a:hover {
    color: var(--tp-red) !important;
}

.ct-header .tp-lang-item.tp-lang-current a {
    color: var(--tp-red) !important;
    font-weight: 600 !important;
}

/* Séparateur pipe entre langues */
.ct-header .tp-lang-item:not(:last-child) a::after {
    content: "|";
    margin-left: 10px;
    color: var(--tp-gray-300);
    font-weight: 300;
}

/* Top bar style (si utilisé comme barre supérieure) */
.tp-lang-topbar {
    background: var(--tp-gray-100, #f3f4f6);
    border-bottom: 1px solid var(--tp-gray-200, #e5e7eb);
    padding: 4px 0;
}

.tp-lang-topbar .tp-lang-switcher {
    max-width: var(--tp-container-width);
    margin: 0 auto;
    padding: 0 var(--tp-space-lg, 24px);
    justify-content: flex-end;
}

.tp-lang-topbar .tp-lang-item a {
    padding: 4px 8px;
    font-size: 12px;
}

/* ==========================================================================
   HEADER SEARCH (shortcode [toppneus_header_search])
   ========================================================================== */

.tp-header-search {
    display: flex;
    align-items: center;
    position: relative;
}

/* Toggle button — hidden on desktop, visible on mobile */
.tp-header-search-toggle {
    display: none;
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: var(--tp-gray-700, #374151);
    line-height: 0;
}

.tp-header-search-toggle:hover {
    color: var(--tp-red, #e63946);
}

.tp-header-search-toggle:focus-visible {
    outline: 2px solid var(--tp-primary, #1a1a1a);
    outline-offset: 2px;
    border-radius: var(--tp-radius-sm, 4px);
}

/* Form */
.tp-header-search-form {
    display: flex;
    align-items: center;
    gap: 0;
}

.tp-header-search-input {
    width: 220px;
    padding: 7px 12px;
    border: 1px solid var(--tp-gray-300, #d1d5db);
    border-right: none;
    border-radius: var(--tp-radius-sm, 4px) 0 0 var(--tp-radius-sm, 4px);
    font-size: 13px;
    color: var(--tp-gray-700, #374151);
    background: var(--tp-white);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.tp-header-search-input::placeholder {
    color: var(--tp-gray-400, #9ca3af);
    font-size: 12px;
}

.tp-header-search-input:focus {
    border-color: var(--tp-primary, #1a1a1a);
    box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.08);
}

.tp-header-search-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px 10px;
    border: 1px solid var(--tp-primary, #1a1a1a);
    background: var(--tp-primary, #1a1a1a);
    color: var(--tp-white);
    border-radius: 0 var(--tp-radius-sm, 4px) var(--tp-radius-sm, 4px) 0;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s;
}

.tp-header-search-submit:hover {
    background: var(--tp-red, #e63946);
    border-color: var(--tp-red, #e63946);
}

.tp-header-search-submit:focus-visible {
    outline: 2px solid var(--tp-primary, #1a1a1a);
    outline-offset: 2px;
}

/* Blocksy header integration (HTML element) — !important needed to override Blocksy defaults */
.ct-header .tp-header-search {
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
}

/* ==========================================================================
   RESPONSIVE - HEADER
   ========================================================================== */

@media (max-width: 900px) {
    /* Header search: icon toggle on mobile, dropdown form */
    .tp-header-search-toggle {
        display: flex;
    }

    .tp-header-search-form {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        background: var(--tp-white);
        border: 1px solid var(--tp-gray-200, #e5e7eb);
        border-radius: var(--tp-radius-sm, 4px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        padding: 8px;
        z-index: 100;
        min-width: 280px;
    }

    .tp-header-search-form.tp-open {
        display: flex;
    }

    .tp-header-search-form .tp-header-search-input {
        width: 100%;
        border-right: none;
    }
}

/* Language switcher responsive */
@media (max-width: 900px) {
    .tp-lang-topbar {
        padding: 6px 0;
    }

    .tp-lang-topbar .tp-lang-switcher {
        justify-content: center;
    }

    /* Offcanvas lang switcher: now handled by .tp-lang-in-menu section below */

    /* Header search in mobile offcanvas panel */
    .ct-panel .tp-header-search-toggle {
        display: none !important;
    }

    .ct-panel .tp-header-search-form {
        display: flex !important;
        position: static !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        min-width: 0 !important;
        width: 100%;
    }

    .ct-panel .tp-header-search-input {
        flex: 1;
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.2);
        color: var(--tp-white);
    }

    .ct-panel .tp-header-search-input::placeholder {
        color: rgba(255, 255, 255, 0.5);
    }

    .ct-panel .tp-header-search-submit {
        background: rgba(255, 255, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.2);
    }

    .ct-panel .tp-header-search-submit:hover {
        background: rgba(255, 255, 255, 0.25);
    }
}

/* ==========================================================================
   COMBINED TOP BAR [toppneus_top_bar]
   Shipping banner + phone + language switcher in one row
   Place in Blocksy Header Builder > Top Row > HTML element
   ========================================================================== */

.tp-top-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    font-size: 12px;
    line-height: 1;
}

/* Language switcher inside top bar */
.tp-top-bar .tp-lang-switcher {
    margin: 0;
}

.tp-top-bar .tp-lang-list {
    gap: 0;
}

.tp-top-bar .tp-lang-item a {
    padding: 2px 8px;
    font-size: 12px;
}

/* Pipe separator between languages in top bar */
.tp-top-bar .tp-lang-item:not(:last-child) a::after {
    content: "|";
    margin-left: 8px;
    color: var(--tp-gray-300, #d1d5db);
    font-weight: 300;
}

/* Blocksy integration: top bar fills the row */
.ct-header [data-row="top"] .tp-top-bar {
    max-width: 100%;
}

/* =========================================================================
   Standalone Shipping banner (legacy, still used if placed independently)
   ========================================================================= */
.tp-shipping-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--tp-green-50, #f0fff4);
    color: var(--tp-green-800, #22543d);
    font-size: var(--tp-text-sm, 0.875rem);
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--tp-green-200, #c6f6d5);
}
.tp-shipping-banner svg {
    flex-shrink: 0;
    color: var(--tp-green-600, #38a169);
}

/* =========================================================================
   Standalone Phone number (legacy, still used if placed independently)
   ========================================================================= */
.tp-header-phone {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--tp-gray-700, #4a5568);
    font-size: var(--tp-text-sm, 0.875rem);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}
.tp-header-phone:hover {
    color: var(--tp-red, #e53e3e);
}
.tp-header-phone svg {
    flex-shrink: 0;
}
@media (max-width: 689px) {
    .tp-phone-number {
        display: none; /* Show icon only on mobile */
    }
}

/* =========================================================================
   Live Search Results
   ========================================================================= */
.tp-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--tp-white);
    border: 1px solid var(--tp-gray-200, #e2e8f0);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1001;
}
.tp-search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--tp-gray-100, #f7fafc);
    transition: background 0.15s;
}
.tp-search-result-item:last-child {
    border-bottom: none;
}
.tp-search-result-item:hover,
.tp-search-result-item:focus {
    background: var(--tp-gray-50, #f7fafc);
    outline: none;
}
.tp-search-result-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 4px;
    background: var(--tp-gray-50, #f7fafc);
}
.tp-search-result-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.tp-search-result-brand {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--tp-gray-500, #a0aec0);
    letter-spacing: 0.3px;
}
.tp-search-result-name {
    font-size: var(--tp-text-sm, 0.875rem);
    font-weight: 500;
    color: var(--tp-gray-800, #2d3748);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tp-search-result-price {
    font-size: var(--tp-text-sm, 0.875rem);
    font-weight: 700;
    color: var(--tp-gray-900, #1a202c);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ==========================================================================
   MOBILE LANGUAGE SWITCHER — Inside Blocksy offcanvas menu
   Injected via JS (i18n.php) at the bottom of .ct-panel-content.
   Hidden on desktop (only visible inside mobile menu panel).
   ========================================================================== */

/* ==========================================================================
   MOBILE CART ICON
   Injected via JS (woocommerce.php) before the hamburger trigger.
   Only visible on mobile (< 690px), hidden on desktop.
   ========================================================================== */

.tp-mobile-cart-link {
    display: none;
}

@media (max-width: 689px) {
    .tp-mobile-cart-link {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px;
        color: var(--tp-gray-700);
        text-decoration: none;
    }

    .tp-mobile-cart-link:hover {
        color: var(--tp-red);
    }

    .tp-mobile-cart-count {
        position: absolute;
        top: 0;
        right: -2px;
        background: var(--tp-red);
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        min-width: 16px;
        height: 16px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }
}

.tp-lang-in-menu {
    display: none;
}

/* Only visible inside Blocksy offcanvas panel */
.ct-panel .tp-lang-in-menu {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    padding: 16px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

/* Push to bottom — specificity 1-2-0 beats Blocksy's
   #offcanvas .ct-panel-content-inner > * (1-1-0) margin reset */
#offcanvas .ct-panel-content-inner > .tp-lang-in-menu {
    margin-top: auto;
}

.ct-panel .tp-lang-in-menu .tp-lang-list {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ct-panel .tp-lang-in-menu .tp-lang-item {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
}

.ct-panel .tp-lang-in-menu .tp-lang-item a {
    display: inline-flex;
    align-items: center;
    padding: 10px 14px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7) !important;
    background: transparent !important;
    text-decoration: none !important;
    transition: color 0.15s;
}

.ct-panel .tp-lang-in-menu .tp-lang-item a:hover {
    color: var(--tp-white) !important;
    background: rgba(255, 255, 255, 0.1) !important;
}

.ct-panel .tp-lang-in-menu .tp-lang-item.tp-lang-current a {
    color: var(--tp-white) !important;
    font-weight: 700;
}

/* Pipe separator between languages */
.ct-panel .tp-lang-in-menu .tp-lang-item:not(:last-child) a::after {
    content: "|";
    margin-left: 14px;
    color: rgba(255, 255, 255, 0.3);
    font-weight: 300;
}
