/* ===========================================
   APE Smart Search - CSS v1.9
   Risultati mobile sotto la barra
   =========================================== */

/* Variables */
:root {
    --ape-primary: #FFDD00;
    --ape-bg: #fff;
    --ape-border: #ddd;
    --ape-text: #1a1a1a;
    --ape-text-light: #666;
    --ape-radius: 8px;
}

/* ===========================================
   SEARCH BOX - Header integrato
   =========================================== */
.ape-search-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    z-index: 99999;
}

.ape-search-form {
    width: 100%;
}

/* Input wrapper - BARRA UNICA sfondo bianco */
.ape-search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 0 16px;
    transition: border-color 0.2s ease;
}

.ape-search-input-wrapper:focus-within {
    border-color: var(--ape-primary);
}

/* Icona lente */
.ape-search-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--ape-text-light);
}

/* Input - font-size 16px per evitare zoom su iOS */
.ape-search-input,
input.ape-search-input,
input[type="search"].ape-search-input {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    font-size: 16px !important; /* IMPORTANTE: 16px minimo per evitare zoom iOS */
    color: var(--ape-text);
    outline: none !important;
    box-shadow: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

/* Rimuovi stili focus del tema sull'input */
.ape-search-input:focus,
input.ape-search-input:focus,
input[type="search"].ape-search-input:focus {
    border: none !important;
    border-radius: 0 !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.ape-search-input::placeholder {
    color: var(--ape-text-light);
    opacity: 0.8;
    font-size: 14px;
}

/* Rimuovi X nativa dei browser */
.ape-search-input::-webkit-search-cancel-button,
.ape-search-input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

/* Bottone clear */
.ape-search-clear {
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: #ddd;
    border-radius: 50%;
    cursor: pointer;
    color: #666;
    transition: background 0.2s;
}

.ape-search-clear:hover {
    background: #ccc;
}

.ape-search-input:not(:placeholder-shown) ~ .ape-search-clear {
    display: flex;
}

/* ===========================================
   RESULTS DROPDOWN
   =========================================== */
.ape-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--ape-bg);
    border-radius: var(--ape-radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 99999;
    display: none;
    border: 1px solid var(--ape-border);
}

.ape-search-results.active {
    display: block;
    animation: ape-fadeIn 0.15s ease;
}

@keyframes ape-fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Loading */
.ape-search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    color: var(--ape-text-light);
    font-size: 14px;
}

.ape-search-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--ape-border);
    border-top-color: var(--ape-primary);
    border-radius: 50%;
    animation: ape-spin 0.7s linear infinite;
}

@keyframes ape-spin {
    to { transform: rotate(360deg); }
}

/* No results */
.ape-search-no-results {
    padding: 25px 15px;
    text-align: center;
    color: var(--ape-text-light);
}

.ape-search-no-results svg {
    margin-bottom: 8px;
    opacity: 0.4;
}

.ape-search-no-results small {
    display: block;
    margin-bottom: 12px;
}

.ape-search-nr-title {
    margin: 4px 0 4px;
    font-size: 16px;
    font-weight: 700;
    color: var(--ape-text, #16213e);
}

.ape-search-no-results small {
    max-width: 46ch;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.5;
}

/* WhatsApp button — stesso teal del tema (.ape-btn--whatsapp, #128C7E conforme WCAG),
   allineato sotto titolo e frase (revisione 2026-09-11) */
.ape-search-whatsapp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #128C7E;
    color: #fff !important;
    height: 44px;
    padding: 0 22px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    transition: background 0.2s;
}

.ape-search-whatsapp-btn:hover {
    background: #0E7466;
}

.ape-search-whatsapp-btn svg {
    opacity: 1;
    margin: 0;
}

/* ===========================================
   PRODUCT ITEM
   =========================================== */
.ape-search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    text-decoration: none;
    color: var(--ape-text);
    border-bottom: 1px solid #f0f0f0;
}

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

.ape-search-item:hover,
.ape-search-item.active {
    background: #fafafa;
}

.ape-search-item-image {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border-radius: 4px;
    overflow: hidden;
    background: #f5f5f5;
}

.ape-search-item-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ape-search-item-content {
    flex: 1;
    min-width: 0;
}

.ape-search-item-title {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    margin: 0 0 3px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ape-search-item-variant {
    display: inline-block;
    background: rgba(255, 221, 0, 0.35);
    color: #5a4d00;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    margin-top: 2px;
}

.ape-search-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.ape-search-item-sku {
    font-size: 11px;
    color: var(--ape-text-light);
    background: #f0f0f0;
    padding: 1px 5px;
    border-radius: 2px;
    font-family: monospace;
}

/* Chip del codice che ha fatto trovare il prodotto (OE / DEPO / EAN) — 2026-09-17 */
.ape-search-item-oe,
.ape-card__oe {
    background: #eaf1fb;
    color: #1d4a8a;
}
.ape-card__oe {
    margin-left: 6px;
}

/* Prezzo */
.ape-search-item-price {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}

.ape-search-item-price del,
.ape-search-item-price .ape-price-regular {
    color: var(--ape-text-light);
    font-size: 11px;
    text-decoration: line-through;
}

.ape-search-item-price ins,
.ape-search-item-price .ape-price-sale,
.ape-search-item-price .ape-price-normal {
    text-decoration: none;
    color: var(--ape-text);
    font-size: 14px;
    font-weight: 700;
}

/* ===========================================
   VIEW ALL LINK
   =========================================== */
.ape-search-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    background: #f8f8f8;
    color: var(--ape-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    border-top: 1px solid var(--ape-border);
}

.ape-search-view-all:hover {
    background: var(--ape-primary);
}

.ape-search-view-all span {
    background: var(--ape-primary);
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 11px;
}

/* ===========================================
   HEADER INTEGRATION - Site header specifico
   =========================================== */

/* Rimuovi TUTTI gli stili del tema sui wrapper esterni */
.search-form-wrapper,
.search-form-wrapper *:not(.ape-search-wrapper):not(.ape-search-wrapper *),
.search-form-inner,
.search-form-inner *:not(.ape-search-wrapper):not(.ape-search-wrapper *),
.header-search,
.site-header .search-form-wrapper {
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
}

/* Il wrapper del tema deve essere trasparente */
.search-form-wrapper {
    background: transparent !important;
}

/* Solo la nostra barra ha stili */
.ape-search-input-wrapper {
    background: #fff !important;
    border: 2px solid #e0e0e0 !important;
}

.site-header .ape-search-wrapper,
.search-form-wrapper .ape-search-wrapper,
.search-form-inner .ape-search-wrapper {
    max-width: 100%;
}

.site-header .ape-search-results,
.search-form-wrapper .ape-search-results {
    width: 100%;
    min-width: 100%;
    left: 0;
    right: 0;
}

/* ===========================================
   MODAL - Mobile fullscreen
   =========================================== */
.ape-search-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
    align-items: flex-start;
    justify-content: center;
}

.ape-search-modal[aria-hidden="false"] {
    display: flex;
}

.ape-search-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.ape-search-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--ape-bg);
    display: flex;
    flex-direction: column;
}

.ape-search-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--ape-text);
}

.ape-search-modal-box {
    max-width: 100%;
    padding: 55px 12px 12px;
}

.ape-search-modal-box .ape-search-wrapper {
    max-width: 100%;
}

.ape-search-modal-box .ape-search-results {
    position: relative;
    top: 0;
    margin-top: 10px;
    max-height: calc(100vh - 130px);
    box-shadow: none;
}

/* ===========================================
   RESPONSIVE - Mobile First
   =========================================== */

/* MOBILE - Evita zoom e risultati fuori schermo */
@media (max-width: 767px) {
    /* Previeni zoom su focus input iOS/Android */
    .ape-search-input {
        font-size: 16px !important; /* 16px = no zoom su iOS */
        height: 44px;
        touch-action: manipulation;
    }

    .ape-search-input-wrapper {
        padding: 0 12px;
    }

    /* Bottone X clear - sempre visibile quando c'è testo */
    .ape-search-clear {
        width: 28px;
        height: 28px;
        min-width: 28px;
        background: #666;
        color: #fff;
    }

    .ape-search-clear:hover,
    .ape-search-clear:active {
        background: #444;
    }

    /* Risultati SOTTO la barra di ricerca (non in fondo allo schermo) */
    .ape-search-results {
        position: absolute !important;
        top: calc(100% + 4px) !important;
        bottom: auto !important;
        left: 0 !important;
        right: 0 !important;
        max-height: 60vh;
        border-radius: 8px;
        box-shadow: 0 4px 20px rgba(0,0,0,0.2);
        animation: ape-fadeIn 0.15s ease;
    }

    /* Assicura che il wrapper abbia position relative per il posizionamento assoluto */
    .ape-search-wrapper {
        position: relative !important;
    }

    /* Se il wrapper è dentro header, assicura z-index alto */
    .search-form-wrapper,
    .search-form-inner {
        position: relative !important;
        z-index: 9999 !important;
    }

    .ape-search-item {
        padding: 10px;
        gap: 8px;
    }

    .ape-search-item-image {
        width: 45px;
        height: 45px;
    }

    .ape-search-item-title {
        font-size: 12px;
    }

    .ape-search-item-price {
        font-size: 13px;
    }

    /* Header search su mobile - larghezza piena */
    .site-header .ape-search-results,
    .search-form-wrapper .ape-search-results {
        min-width: 100%;
        width: 100%;
        left: 0 !important;
        right: 0 !important;
    }

    /* Overflow scroll per risultati lunghi */
    .ape-search-results {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Small phones */
@media (max-width: 359px) {
    .ape-search-input::placeholder {
        font-size: 12px;
    }
    .ape-search-item-image {
        width: 40px;
        height: 40px;
    }
    .ape-search-item-title {
        font-size: 11px;
    }
}

/* Tablet */
@media (min-width: 768px) {
    .ape-search-input-wrapper {
        padding: 0 16px;
    }

    .ape-search-input {
        height: 44px;
    }

    .ape-search-modal-content {
        width: 90%;
        max-width: 550px;
        height: auto;
        max-height: 75vh;
        margin-top: 12vh;
        border-radius: var(--ape-radius);
    }

    .ape-search-modal-box {
        padding: 16px;
    }

    .ape-search-modal-box .ape-search-results {
        max-height: 45vh;
    }

    .ape-search-item {
        padding: 12px;
        gap: 12px;
    }

    .ape-search-item-image {
        width: 60px;
        height: 60px;
    }

    .ape-search-item-title {
        font-size: 14px;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .ape-search-input {
        height: 46px;
    }

    .ape-search-item {
        padding: 14px;
        gap: 14px;
    }

    .ape-search-item-image {
        width: 65px;
        height: 65px;
    }

    .ape-search-item-title {
        font-size: 14px;
    }

    .site-header .ape-search-results,
    .search-form-wrapper .ape-search-results {
        min-width: 450px;
    }
}

/* ===========================================
   EXTRAS
   =========================================== */
.ape-search-highlight {
    background: rgba(255, 221, 0, 0.4);
    padding: 0 1px;
    border-radius: 2px;
}

/* "Forse cercavi" banner */
.ape-search-did-you-mean {
    padding: 8px 12px;
    background: #fff8e1;
    border-bottom: 1px solid #ffe082;
    font-size: 13px;
    color: #5d4037;
    cursor: pointer;
    transition: background 0.2s;
}

.ape-search-did-you-mean:hover {
    background: #fff3c4;
}

.ape-search-did-you-mean strong {
    color: #e65100;
}

.ape-search-sort-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: #e8f5e9;
    color: #2e7d32;
    font-size: 11px;
    border-bottom: 1px solid #c8e6c9;
}

.ape-search-sort-indicator svg {
    width: 12px;
    height: 12px;
}

/* Keyboard navigation */
.ape-search-item:focus {
    background: #f0f0f0;
    outline: 2px solid var(--ape-primary);
    outline-offset: -2px;
}

/* Pagina risultati a zero: "Prodotti vicini" sotto l'assistenza PRO (2026-09-14) */
.ape-search-vicini {
    margin: 32px 0 8px;
    padding-top: 24px;
    border-top: 1px solid #e5e7eb;
}
.ape-search-vicini__title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 6px;
}
.ape-search-vicini__note {
    color: #4b5563;
    font-size: 14px;
    margin: 0 0 18px;
    max-width: 70ch;
}

/* "Non trattiamo X" sulla pagina risultati (dizionario ricerca, 2026-09-14) */
.ape-search-non-trattiamo { margin: 8px 0 18px; padding: 16px 18px; background: #fff; border: 1px solid #e5e7eb; border-left: 4px solid #16213E; }
.ape-search-non-trattiamo h2 { margin: 0 0 6px; font-size: 20px; }
.ape-search-non-trattiamo p { margin: 0; color: #4b5563; font-size: 14px; max-width: 70ch; }

/* Vicini per veicolo (2026-09-15): "non trattiamo X per Golf 8, ecco cosa abbiamo" */
.ape-search-vicini--veicolo .ape-search-vicini__all { margin: 14px 0 0; }
.ape-search-vicini-veicolo { line-height: 1.45; }
