/* =============================================================
   KORENCE SEARCH v5.1.0
   ============================================================= */

/* ── Barre déclencheur ── */
.korence-trigger-wrapper {
    position: relative;
    width: 100%;
    margin: 0 auto;
    cursor: text;
}

#korence-search-trigger {
    width: 100%;
    padding: 12px 15px 12px 42px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background-color: #f9f9f9;
    cursor: text;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

#korence-search-trigger:hover {
    border-color: #bbb;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.korence-trigger-wrapper .korence-search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa;
    font-size: 16px;
    pointer-events: none;
}

/* ── Modale — base mobile ── */
.korence-modal {
    display: none;
    position: fixed !important;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background-color: #fff;
    z-index: 999999;
}

.korence-modal.active {
    display: flex;
    flex-direction: column;
    animation: korence-fade-in 0.18s ease-out;
}

@keyframes korence-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.korence-modal-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* ── Header modale ── */
.korence-modal-header {
    display: flex !important;
    align-items: center !important;
    padding: 14px 16px !important;
    border-bottom: 1px solid #eee !important;
    background: #fff !important;
    gap: 8px !important;
    flex-shrink: 0 !important;
    position: sticky;
    top: 0;
    z-index: 2;
}

#korence-modal-input {
    flex-grow: 1  !important;
    border: none !important;
    font-size: 18px !important;
    padding: 8px 6px !important;
    outline: none !important;
    background: transparent !important;
    color: #222 !important;
    min-width: 0 !important;
}

#korence-modal-input::placeholder { color: #bbb; }

.korence-close-btn {
    background: none !important;
    border: none !important;
    font-size: 28px !important;
    line-height: 1 !important;
    color: #999 !important;
    cursor: pointer;
    padding: 4px 8px !important;
    border-radius: 6px !important;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.korence-close-btn:hover {
    background: #f5f5f5;
    color: #333;
}

/* ── Bouton retour (chevron) — ferme la modale ── */
.korence-back-btn {
    background: none !important;
    border: none !important;
    font-size: 36px !important;
    line-height: 1 !important;
    font-weight: 300 !important;
    color: #555 !important;
    cursor: pointer;
    padding: 2px 6px 4px !important;
    border-radius: 6px !important;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.korence-back-btn:hover {
    background: #f5f5f5 !important;
    color: #111 !important;
}

/* ── Zone de contenu ── */
.korence-modal-content {
    flex-grow: 1;
    overflow-y: auto;
    background-color: #fff;
    -webkit-overflow-scrolling: touch;
}

/* ── Résultats de saisie (ul) ── */
#korence-predictive-results {
    list-style: none;
    margin: 0;
    padding: 0;
}

#korence-predictive-results li {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid #f5f5f5;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    gap: 12px;
    animation: korence-slide-in 0.14s ease-out both;
}

@keyframes korence-slide-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

#korence-predictive-results li:hover   { background-color: #fafafa; }
#korence-predictive-results li.focused { background-color: #fff5ee; outline: 2px solid #ff6600; outline-offset: -2px; }
#korence-predictive-results li strong  { font-weight: 700; color: #111; }

.korence-suggest-icon { font-size: 17px; flex-shrink: 0; opacity: 0.65; }

.korence-section-header {
    font-size: 10px !important;
    font-weight: 800 !important;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #bbb !important;
    padding: 14px 18px 4px !important;
    background: transparent !important;
    border-bottom: none !important;
    cursor: default !important;
    animation: none !important;
    gap: 0 !important;
}

.korence-section-header:hover { background: transparent !important; }

/* Badge "via synonymes" dans le header produits */
.korence-syn-badge {
    display: inline-block !important;
    margin-left: 8px !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    background: #f3e5f5 !important;
    color: #6a1b9a !important;
    padding: 2px 8px !important;
    border-radius: 10px !important;
    letter-spacing: 0.3px;
    text-transform: none !important;
    vertical-align: middle;
}

.korence-category-item { color: #e85d00 !important; }
.korence-category-item strong { color: #c04800 !important; }

.korence-product-item   { padding: 10px 16px !important; gap: 14px !important; }

.korence-prod-img {
    width: 48px; height: 48px;
    object-fit: cover; border-radius: 6px; flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08); background: #f5f5f5;
}

.korence-prod-info {
    display: flex; flex-direction: column; justify-content: center;
    flex: 1; min-width: 0; gap: 3px;
}

.korence-prod-title {
    font-size: 14px; font-weight: 500; color: #222;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.korence-prod-title strong { font-weight: 800; color: #111 !important; }
.korence-prod-price        { font-size: 13px; color: #ff6600; font-weight: 700; }

.korence-oos-badge {
    font-size: 10px; background: #f0f0f0; color: #aaa;
    padding: 2px 8px; border-radius: 10px; white-space: nowrap; flex-shrink: 0;
}

/* ── Loading / Empty ── */
.korence-loading {
    display: flex !important;
    align-items: center; gap: 12px;
    padding: 22px 20px !important;
    color: #aaa; font-size: 14px;
    cursor: default !important; border-bottom: none !important; animation: none !important;
}
.korence-loading:hover { background: transparent !important; }

.korence-spinner {
    display: inline-block; width: 18px; height: 18px;
    border: 2px solid #eee; border-top-color: #ff6600;
    border-radius: 50%; flex-shrink: 0;
    animation: korence-spin 0.65s linear infinite;
}

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

.korence-empty-state {
    display: flex !important;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; padding: 40px 20px !important;
    color: #bbb; font-size: 15px; text-align: center;
    cursor: default !important; border-bottom: none !important; animation: none !important;
}
.korence-empty-state:hover { background: transparent !important; }
.korence-empty-icon         { font-size: 36px; opacity: 0.4; }
.korence-empty-state strong { color: #888; font-weight: 600; }

/* ── Footer CTA ── */
.korence-footer-item {
    border-top: 2px solid #f0f0f0 !important;
    border-bottom: none !important; padding: 0 !important;
    cursor: default !important;
    animation: korence-slide-in 0.2s ease-out both !important;
}
.korence-footer-item:hover { background: transparent !important; }

.korence-see-all {
    display: flex; align-items: center !important; gap: 10px !important;
    padding: 14px 18px; color: #ff6600; font-size: 14px;
    font-weight: 600; text-decoration: none;
    transition: background 0.15s; width: 100%; box-sizing: border-box;
}
.korence-see-all:hover { background: #fff8f3 !important; color: #cc4400 !important; }
.korence-see-all strong { font-weight: 700 !important; color: inherit !important; }
.korence-see-all > span:first-child { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.korence-count-badge {
    background: #ff6600 !important; color: #fff !important;
    font-size: 11px !important; font-weight: 700 !important;
    padding: 2px 9px !important; border-radius: 12px !important; white-space: nowrap !important; flex-shrink: 0;
}

.korence-arrow { font-size: 18px; flex-shrink: 0; opacity: 0.7; }

/* =============================================================
   ÉTAT PAR DÉFAUT (kds = korence default state)
   ============================================================= */

.korence-default-state {
    padding-bottom: 16px;
    animation: korence-fade-in 0.2s ease-out;
}

/* ── Section générique ── */
.kds-section {
    border-bottom: 1px solid #f2f2f2 !important;
    padding-bottom: 8px !important;
    margin-bottom: 2px !important;
}

.kds-section:last-child {
    border-bottom: none !important;
}

/* ── En-tête de section ── */
.kds-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 14px 18px 6px !important;
}

.kds-header--solo {
    padding-bottom: 10px;
}

.kds-header-label {
    font-size: 11px !important;
    font-weight: 800 !important;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: #bbb;
}

/* ── Bouton "Tout effacer" ── */
.kds-clear-all {
    background: none !important;
    border: none !important;
    font-size: 12px;
    color: #aaa !important;
    cursor: pointer !important;
    padding: 3px 6px !important;
    border-radius: 4px !important;
    transition: color 0.15s, background 0.15s;
    font-weight: 500 !important;
}

.kds-clear-all:hover {
    color: #ff6600 !important;
    background: #fff5ee !important;
}

/* ── Liste des recherches récentes ── */
.kds-list {
    list-style: none !important;
    margin: 0 !important !important;
    padding: 0 !important;
}

.kds-item {
    display: flex;
    align-items: center !important;
    padding: 5px 5px !important;
    gap: 12px !important;
    border-bottom: 1px solid #fafafa !important;
    cursor: pointer;
    transition: background 0.12s;
    animation: korence-slide-in 0.14s ease-out both;
}

.kds-item:last-child { border-bottom: none; }
.kds-item:hover      { background: #fafafa; }

.kds-item-icon {
    font-size: 16px !important;
    flex-shrink: 0 !important;
    opacity: 0.5 !important;
}

.kds-item-label {
    flex: 1;
    font-size: 15px !important;
    color: #444 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    cursor: pointer;
}

/* ── Bouton × supprimer récente ── */
.kds-remove-btn {
    background: none !important;
    border: none !important;
    font-size: 20px !important;
    line-height: 1 !important;
    color: #ccc !important;
    cursor: pointer !important;
    padding: 0 4px !important;
    border-radius: 4px !important;
    flex-shrink: 0 !important;
    transition: color 0.15s, background 0.15s !important;
    margin-left: auto;
}

.kds-remove-btn:hover {
    color: #ff6600 !important;
    background: #fff0e8 !important;
}

/* ── Pills tendances ── */
.kds-pills {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 2px 18px 14px !important;
}

.kds-pill {
    display: inline-flex !important;
    align-items: center !important;
    padding: 7px 5px !important;
    background: #fff !important;
    border: 1.5px solid #ffe0c4 !important;
    border-radius: 20px !important;
    font-size: 13px !important;
    color: #cc4800 !important !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: background 0.16s, border-color 0.16s, color 0.16s, transform 0.12s;
    /* Animation décalée via propriété CSS custom */
    animation: korence-pill-pop 0.24s ease-out var(--pill-delay, 0ms) both;
}

@keyframes korence-pill-pop {
    from { opacity: 0; transform: scale(0.88) translateY(4px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

.kds-pill:hover {
    background: #fff5ee !important;
    border-color: #ff6600 !important;
    color: #ff6600 !important;
    transform: translateY(-1px);
}

.kds-pill:active {
    transform: scale(0.96);
}

/* ── Bloc HTML ── */
.kds-html-section {
    padding-bottom: 0;
}

.kds-html-block {
    padding: 0 16px 16px;
    /* Le contenu rendu peut contenir n'importe quel HTML — on le laisse s'exprimer */
}

/* Optionnel : si le bloc HTML contient une image seule */
.kds-html-block img {
    max-width: 100% !important;
    border-radius: 8px !important;
    display: block !important;
}

/* =============================================================
   DESKTOP (≥ 768px)
   ============================================================= */
@media (min-width: 768px) {

    .korence-modal {
        background-color: rgba(0, 0, 0, 0.55);
        padding-top: 8vh;
        align-items: center;
        justify-content: flex-start;
    }

    .korence-modal-container {
        width: 70%;
        max-width: 820px;
        height: auto;
        max-height: 80vh;
        background: #fff;
        border-radius: 14px;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
        overflow: hidden;
        animation: korence-modal-drop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    @keyframes korence-modal-drop {
        from { opacity: 0; transform: translateY(-16px) scale(0.97); }
        to   { opacity: 1; transform: translateY(0)     scale(1);    }
    }

    .korence-modal-header  { padding: 18px 22px; }
    #korence-modal-input   { font-size: 22px; }

    #korence-predictive-results li { padding: 5px 10px; }
    .korence-section-header        { padding: 16px 22px 4px !important; }
    .korence-product-item          { padding: 5px 10px !important; }
    .korence-see-all               { padding: 15px 22px; }

    /* ── Layout 2 colonnes (résultats de saisie) ── */
    #korence-predictive-results[aria-hidden="false"] {
        display: grid !important;
        /* minmax(0,1fr) empêche le contenu d'élargir la colonne au-delà de 50% */
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        /* dense : le grid remonte remplir les cases vides au lieu de suivre
           l'ordre du DOM — les produits partent donc de la ligne 1, col 2 */
        grid-auto-flow: row dense;
        align-items: start;
        overflow-x: hidden;
    }

    /* Colonne 1 : catégories + recherches suggérées */
    #korence-predictive-results li:not(.korence-product-item):not(.korence-footer-item):not(.korence-products-header) {
        grid-column: 1;
        min-width: 0; /* évite le débordement du texte hors de la colonne */
    }

    /* Header produits — ancré en haut de la colonne 2 (grid-row: 1 obligatoire,
       sinon le grid auto-place la col 2 après les dernières lignes de la col 1) */
    #korence-predictive-results li.korence-products-header {
        grid-column: 2;
        grid-row: 1;
        border-left: 1px solid #f0f0f0;
        background: #fafafa;
        min-width: 0;
    }

    /* Items produits — colonne 2 (s'empilent à partir de la ligne 2) */
    #korence-predictive-results li.korence-product-item {
        grid-column: 2;
        border-left: 1px solid #f0f0f0;
        background: #fafafa;
        min-width: 0;
    }

    /* Le footer "Voir tous" s'étale sur les 2 colonnes */
    #korence-predictive-results li.korence-footer-item {
        grid-column: 1 / -1;
        background: #fff;
    }

    /* État par défaut desktop */
    .kds-header                   { padding: 16px 22px 6px; }
    .kds-item                     { padding: 9px 22px; }
    .kds-pills                    { padding: 2px 22px 16px; gap: 10px; }
    .kds-html-block               { padding: 0 22px 18px; }

    /* Grille 2 colonnes pour les pills sur grand écran */
    .kds-pills {
        display: flex !important;
        flex-wrap: wrap !important;
    }
}

/* =========================================================
   RECHERCHES RÉCENTES EN PILULES
   ========================================================= */

.kds-recent-pills {
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px  !important;
    padding: 0 5px 5px !important; /* Espacement similaire aux tendances */
}

/* Structure de base de la pilule (div) */
.kds-pill.kds-recent-pill {
    display: inline-flex !important;
    align-items: center !important;
    background-color: #e8f5e9 !important;
    color: #2e7d32 !important;
    border: 1px solid #c8e6c9 !important;
    padding: 2px 2px !important;
    border-radius: 20px  !important;
    font-size: 14px !important;
    cursor: default !important;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.kds-pill.kds-recent-pill:hover {
    background-color: #c8e6c9 !important;
    transform: translateY(-1px);
}

/* Label (Texte de la recherche) cliquable */
.kds-pill-label {
    cursor: pointer;
    margin-right: 8px !important;
}

/* Bouton 'X' pour la suppression */
.kds-remove-pill-btn {
    background: none !important;
    border: none !important;
    color: #2e7d32 !important;
    font-size: 18px !important;
    line-height: 1 !important;
    padding: 0 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0.6 !important;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.kds-remove-pill-btn:hover {
    opacity: 1 !important;
    color: #1b5e20 !important;
}