/* ─── Packfood AI — Widget WhatsApp Style ─────────────────────────────────── */

:root {
    --pfai-wa-header:      #075E54;
    --pfai-wa-header-dk:   #054c44;
    --pfai-wa-green:       #25D366;
    --pfai-wa-sent:        #DCF8C6;
    --pfai-wa-sent-text:   #1a1a1a;
    --pfai-wa-recv:        #ffffff;
    --pfai-wa-bg:          #ECE5DD;
    --pfai-wa-input-bg:    #f0f2f5;
    --pfai-wa-border:      #d1d7db;
    --pfai-wa-text-muted:  #667781;
    --pfai-wa-tick:        #53bdeb;
    --pfai-panel-w:        370px;
    --pfai-panel-h:        600px;
    --pfai-z:              999999;
    /* Couleur override depuis PHP (bouton flottant) */
    --widget-color:        #25D366;
}

/* ─── Conteneur global ────────────────────────────────────────────────────── */

.packfood-ai-widget {
    position: fixed;
    z-index: var(--pfai-z);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
    /* Isolation du widget : empêche les styles du thème de s'infiltrer */
    isolation: isolate;
}

.packfood-ai-widget * { box-sizing: border-box; }

.packfood-ai-bottom-right { bottom: 24px; right: 24px; }
.packfood-ai-bottom-left  { bottom: 24px; left:  24px; }

/* ─── Bulle de notification proactive ────────────────────────────────────── */

.packfood-ai-notif {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    background: #fff;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 6px 24px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
    padding: 12px 38px 12px 14px;
    max-width: 260px;
    min-width: 200px;
    cursor: pointer;
    z-index: 10;
}
.packfood-ai-notif:not([hidden]) {
    display: block;
    animation: pfai-notif-in .35s cubic-bezier(.22,.68,0,1.2) forwards;
}
.packfood-ai-notif--out {
    animation: pfai-notif-out .25s ease forwards !important;
}
.packfood-ai-notif--secure {
    bottom: 145px !important;
}
.packfood-ai-notif--secure:not([hidden]) {
    display: block;
    animation: pfai-notif-in .35s cubic-bezier(.22,.68,0,1.2) forwards;
    border-left: 4px solid #25D366;
}
.packfood-ai-notif--secure .packfood-ai-notif__text::before {
    content: '🔒 ';
}
@keyframes pfai-notif-in {
    from { opacity: 0; transform: translateY(10px) scale(.92); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes pfai-notif-out {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to   { opacity: 0; transform: translateY(6px) scale(.94); }
}
/* Flèche pointant vers l'avatar */
.packfood-ai-notif::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 18px;
    border: 8px solid transparent;
    border-top-color: #fff;
    border-bottom: none;
    filter: drop-shadow(0 3px 3px rgba(0,0,0,.08));
}
.packfood-ai-notif__text {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.5;
    color: #1a1a1a;
}
#packfood-ai-widget .packfood-ai-notif__close {
    position: absolute !important;
    top: 8px !important;
    right: 8px !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    padding: 0 !important;
    margin: 0 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: transform .15s;
}
#packfood-ai-widget .packfood-ai-notif__close:hover {
    background: transparent !important;
    background-color: transparent !important;
    transform: scale(1.1);
}

/* ─── Bouton flottant WhatsApp Business (pill vert) ─────────────────────── */

#packfood-ai-widget .packfood-ai-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    box-shadow: 0 0 0 3px #e53935, 0 4px 18px rgba(0,0,0,.28), 0 2px 8px rgba(0,0,0,.18) !important;
    transition: transform .18s, box-shadow .18s !important;
    width: 58px !important;
    height: 58px !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    outline: none !important;
    overflow: hidden !important;
}

#packfood-ai-widget .packfood-ai-toggle:hover {
    transform: translateY(-2px) scale(1.05) !important;
    box-shadow: 0 0 0 3px #e53935, 0 6px 24px rgba(0,0,0,.35), 0 3px 10px rgba(0,0,0,.22) !important;
}

#packfood-ai-widget .packfood-ai-toggle:active {
    transform: translateY(0) scale(.98) !important;
}

.packfood-ai-toggle__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.packfood-ai-toggle__icon svg { width: 26px; height: 26px; }
.packfood-ai-toggle__icon--close { display: none; }

/* Avatar rond dans le bouton toggle */
.packfood-ai-toggle__avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center top;
    flex-shrink: 0;
    display: block;
}

.packfood-ai-toggle__label {
    display: none;
}

/* ─── Panneau de chat ────────────────────────────────────────────────────── */

.packfood-ai-panel {
    position: absolute;
    bottom: calc(100% + 16px);
    right: 0;
    width: var(--pfai-panel-w);
    height: var(--pfai-panel-h);
    background: var(--pfai-wa-bg);
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,.28), 0 2px 8px rgba(0,0,0,.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: pfai-open .18s ease;
}

.packfood-ai-bottom-left .packfood-ai-panel {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.packfood-ai-panel[hidden] { display: none; }

@keyframes pfai-open {
    from { opacity: 0; transform: scale(.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* ─── Header WhatsApp ────────────────────────────────────────────────────── */

.packfood-ai-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--pfai-wa-header);
    color: #fff;
    flex-shrink: 0;
    gap: 10px;
}

.packfood-ai-panel__header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

/* Avatar cercle avec photo ou initiales */
.packfood-ai-panel__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: #b2dfdb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--pfai-wa-header);
    border: 2px solid rgba(255,255,255,.2);
}

.packfood-ai-panel__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.packfood-ai-panel__avatar-initials {
    font-size: 15px;
    font-weight: 700;
    color: var(--pfai-wa-header);
    letter-spacing: -.5px;
    user-select: none;
}

.packfood-ai-panel__meta { min-width: 0; }

.packfood-ai-panel__name {
    margin: 0;
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.packfood-ai-panel__status {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    opacity: .9;
}

.packfood-ai-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    flex-shrink: 0;
}

.packfood-ai-panel__header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

#packfood-ai-widget .packfood-ai-btn-icon {
    -webkit-appearance: none !important;
    appearance: none !important;
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    border-radius: 50% !important;
    box-shadow: none !important;
    outline: none !important;
    width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    margin: 0 !important;
    color: rgba(255,255,255,.85);
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}

#packfood-ai-widget .packfood-ai-btn-icon:hover {
    background: transparent !important;
    background-color: transparent !important;
    color: #fff;
}

.packfood-ai-btn-icon__circle {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, opacity .15s;
}
.packfood-ai-btn-icon__circle--green { background: #25D366; }
.packfood-ai-btn-icon__circle--red   { background: #e53935; }
.packfood-ai-btn-icon:hover .packfood-ai-btn-icon__circle {
    transform: scale(1.12);
    opacity: .9;
}

/* ─── Zone conversation cards ───────────────────────────────────────────── */

.packfood-ai-cards {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    background: #f0f4f8;
}

.packfood-ai-cards::-webkit-scrollbar { width: 4px; }
.packfood-ai-cards::-webkit-scrollbar-track { background: transparent; }
.packfood-ai-cards::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }

/* ─── Carte individuelle ─────────────────────────────────────────────────── */

.packfood-ai-card {
    background: #fff;
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.04);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity .3s ease, transform .3s cubic-bezier(.22,.68,0,1.2), box-shadow .2s;
}

.packfood-ai-card--visible {
    opacity: 1;
    transform: translateY(0);
}

.packfood-ai-card--active {
    box-shadow: 0 4px 20px rgba(7,94,84,.1), 0 1px 4px rgba(0,0,0,.06);
    border: 1.5px solid rgba(37,211,102,.3);
}

.packfood-ai-card--error {
    background: #fff8f0;
    border: 1px solid #ffd0a0;
}

.packfood-ai-card--error > p {
    color: #b04500;
    font-size: 13px;
    margin: 0 0 10px;
}

/* ─── En-tête de carte (avatar + nom + heure) ───────────────────────────── */

.packfood-ai-card__agent {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.packfood-ai-card__avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #e8f5e9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    color: #075E54;
}

.packfood-ai-card__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    display: block;
}

.packfood-ai-card__agent-name {
    font-weight: 700;
    font-size: 12.5px;
    color: #075E54;
    flex: 1;
}

.packfood-ai-card__time {
    font-size: 10.5px;
    color: #bbb;
    flex-shrink: 0;
}

/* ─── Contenu texte ──────────────────────────────────────────────────────── */

.packfood-ai-card__content {
    font-size: 13.5px;
    line-height: 1.55;
    color: #1a1a1a;
}

.packfood-ai-card__content strong { font-weight: 700; }
.packfood-ai-card__content em { font-style: italic; }
.packfood-ai-card__content p { margin: 0 0 6px; }
.packfood-ai-card__content p:last-child { margin: 0; }
.packfood-ai-card__content ul,
.packfood-ai-card__content ol { padding-left: 18px; margin: 4px 0; }
.packfood-ai-card__content li { margin-bottom: 3px; }
.packfood-ai-card__content h3 {
    font-size: 13px;
    font-weight: 700;
    margin: 8px 0 4px;
    color: #075E54;
}
.packfood-ai-card__content a {
    color: #075E54;
    text-decoration: underline;
    word-break: break-all;
}

/* ─── Bulle réponse utilisateur ─────────────────────────────────────────── */

.packfood-ai-card__user-reply {
    margin-top: 12px;
    background: #DCF8C6;
    color: #1a1a1a;
    padding: 8px 12px 5px;
    border-radius: 12px 12px 4px 12px;
    font-size: 13px;
    line-height: 1.45;
    align-self: flex-end;
    max-width: 88%;
    margin-left: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: pfai-reply-in .2s ease;
}

@keyframes pfai-reply-in {
    from { opacity: 0; transform: translateX(8px); }
    to   { opacity: 1; transform: translateX(0); }
}

.packfood-ai-card__user-reply-time {
    font-size: 10px;
    color: #6a9a6a;
    text-align: right;
}

/* ─── Zone de saisie dans la carte ──────────────────────────────────────── */

.packfood-ai-card__input-area {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.packfood-ai-card__input {
    flex: 1;
    min-height: 36px;
    max-height: 100px;
    padding: 7px 14px;
    background: #f5f7f9;
    border: 1.5px solid #e0e0e0;
    border-radius: 20px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
    color: #1a1a1a;
    transition: border-color .15s, background .15s;
    overflow-y: auto;
}

.packfood-ai-card__input:focus {
    border-color: #25D366;
    background: #fff;
}

.packfood-ai-card__input::placeholder { color: #b0b0b0; }

#packfood-ai-widget .packfood-ai-card__send {
    -webkit-appearance: none !important;
    appearance: none !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    border-radius: 50% !important;
    background: #25D366 !important;
    background-color: #25D366 !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 1px 3px rgba(0,0,0,.2) !important;
    outline: none !important;
    padding: 0 !important;
    margin: 0 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}

#packfood-ai-widget .packfood-ai-card__send:not(:disabled):hover {
    background: #1ebe5d !important;
    background-color: #1ebe5d !important;
}
#packfood-ai-widget .packfood-ai-card__send:not(:disabled):active { transform: scale(.9); }
#packfood-ai-widget .packfood-ai-card__send:disabled {
    background: #d1d7db !important;
    background-color: #d1d7db !important;
    cursor: not-allowed;
    box-shadow: none !important;
}

/* ─── Indicateur de saisie (3 points) ───────────────────────────────────── */

.packfood-ai-thinking {
    display: none;
    padding: 0 12px 12px;
    align-items: center;
    flex-shrink: 0;
}
.packfood-ai-thinking:not([hidden]) {
    display: flex;
}

.packfood-ai-thinking__dots {
    background: #fff;
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    display: flex;
    gap: 5px;
    align-items: center;
}

.packfood-ai-thinking__dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b0bec5;
    animation: pfai-bounce 1.3s infinite ease-in-out;
}

.packfood-ai-thinking__dots span:nth-child(2) { animation-delay: .2s; }
.packfood-ai-thinking__dots span:nth-child(3) { animation-delay: .4s; }

@keyframes pfai-bounce {
    0%, 60%, 100% { transform: translateY(0); background: #b0bec5; }
    30%            { transform: translateY(-5px); background: #78909c; }
}

/* ─── Cartes produits ────────────────────────────────────────────────────── */

/* ─── Grille produits 2 colonnes ─────────────────────────────────────────── */

#packfood-ai-widget .packfood-ai-product-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    margin-top: 10px;
    width: 100%;
    box-sizing: border-box;
}

/* Carte = lien cliquable entier */
#packfood-ai-widget .packfood-ai-product-card {
    display: flex !important;
    flex-direction: column !important;
    min-width: 0 !important;
    background: #fff !important;
    border: 1px solid #e8e8e8 !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    box-shadow: 0 1px 4px rgba(0,0,0,.07) !important;
    text-decoration: none !important;
    color: inherit !important;
    cursor: pointer !important;
    transition: box-shadow .18s, transform .18s;
    padding: 0 !important;
    margin: 0 !important;
}

#packfood-ai-widget .packfood-ai-product-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.13) !important;
    transform: translateY(-2px);
    text-decoration: none !important;
    color: inherit !important;
}

/* Image */
#packfood-ai-widget .packfood-ai-product-card__img-wrap {
    position: relative !important;
    width: 100% !important;
    padding-top: 100% !important; /* carré */
    background: #f5f5f5 !important;
    overflow: hidden !important;
    flex-shrink: 0 !important;
}

#packfood-ai-widget .packfood-ai-product-card__image {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Badge Promo */
#packfood-ai-widget .packfood-ai-product-card__badge {
    position: absolute !important;
    top: 6px !important;
    left: 6px !important;
    background: #e63946 !important;
    color: #fff !important;
    font-size: 9px !important;
    font-weight: 700 !important;
    letter-spacing: .4px;
    text-transform: uppercase;
    padding: 2px 6px !important;
    border-radius: 20px !important;
    z-index: 1 !important;
}

/* Titre */
#packfood-ai-widget .packfood-ai-product-card__name {
    font-size: 11.5px !important;
    font-weight: 600 !important;
    color: #1a1a1a !important;
    margin: 0 !important;
    padding: 7px 8px 3px !important;
    line-height: 1.35 !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden !important;
    white-space: normal !important;
}

/* Prix */
#packfood-ai-widget .packfood-ai-product-card__prices {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    flex-wrap: wrap !important;
    padding: 0 8px 8px !important;
    margin: 0 !important;
}

#packfood-ai-widget .packfood-ai-product-card__price--sale {
    font-size: 13px !important;
    font-weight: 800 !important;
    color: #e63946 !important;
}

#packfood-ai-widget .packfood-ai-product-card__price--regular {
    font-size: 10.5px !important;
    color: #aaa !important;
    text-decoration: line-through !important;
}

/* ─── Responsive mobile ──────────────────────────────────────────────────── */

@media (max-width: 480px) {
    .packfood-ai-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100%;
    }

    .packfood-ai-panel {
        position: fixed;
        bottom: 72px;
        left: 0;
        right: 0;
        width: 100%;
        height: calc(100vh - 72px);
        border-radius: 0;
    }

    .packfood-ai-toggle {
        position: fixed !important;
        bottom: 52px !important;
        right: 14px !important;
        left: auto !important;
    }

    .packfood-ai-notif,
    .packfood-ai-notif--secure {
        right: 14px !important;
        left: auto !important;
    }
}
