/* ═══════════════════════════════════════════════
   WP AI Chat — Widget Frontend
════════════════════════════════════════════════ */

/* Reset léger : box-sizing + font, sans écraser padding/margin
   (les classes spécifiques gèrent leurs propres espacements) */
#wp-ai-chat-root,
#wp-ai-chat-root *,
#wp-ai-chat-root *::before,
#wp-ai-chat-root *::after {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Conteneur positionné ───────────────────── */
.wpaichat-wrapper {
    position: fixed;
    z-index: 2147483000;
}
.wpaichat-br { bottom: 24px; right: 24px; }
.wpaichat-bl { bottom: 24px; left: 24px; }

/* ─── Bouton flottant ────────────────────────── */
.wpaichat-toggle {
    width: 60px; height: 60px; border-radius: 50%;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,.22);
    transition: transform .2s ease, box-shadow .2s ease;
    color: white; position: relative;
}
.wpaichat-toggle:hover {
    transform: scale(1.07);
    box-shadow: 0 6px 28px rgba(0,0,0,.28);
}
/* Pulse animation to draw attention on first load */
.wpaichat-toggle.wpaichat-pulse {
    animation: wpaichat-pulse 2s ease-in-out 3;
}
@keyframes wpaichat-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0,0,0,.22); }
    50% { box-shadow: 0 4px 20px rgba(0,0,0,.22), 0 0 0 12px rgba(var(--wpaichat-rgb, 124,58,237), .15); }
}
.wpaichat-toggle:active { transform: scale(.96); }
.wpaichat-toggle svg { transition: opacity .2s, transform .2s; }
.wpaichat-toggle .icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.wpaichat-toggle .icon-open  { opacity: 1; transform: rotate(0deg); }
.wpaichat-open .icon-close   { opacity: 1; transform: rotate(0deg); }
.wpaichat-open .icon-open    { opacity: 0; transform: rotate(90deg); }
.wpaichat-open .wpaichat-preview,
.wpaichat-open .wpaichat-preview.is-visible { display: none !important; }

/* Preview bubble — positioned relative to wrapper, above toggle button */
.wpaichat-preview {
    position: absolute !important; bottom: 72px !important; right: 0 !important;
    max-width: 260px !important;
    background: white !important; border-radius: 14px !important;
    padding: 12px 16px !important;
    display: none;
    box-shadow: 0 4px 24px rgba(0,0,0,.15) !important;
    font-size: 13px !important; color: #374151 !important;
    line-height: 1.4 !important; cursor: pointer !important;
    animation: wpaichat-fadeIn .3s ease;
    transition: transform .15s, box-shadow .15s, opacity .3s ease;
    z-index: 1 !important;
}
.wpaichat-preview.is-visible {
    display: block !important;
}
.wpaichat-preview-arrow {
    position: absolute !important; bottom: -6px !important; right: 24px !important;
    width: 12px !important; height: 12px !important;
    background: white !important; transform: rotate(45deg) !important;
    box-shadow: 2px 2px 4px rgba(0,0,0,.06) !important;
}
.wpaichat-preview:hover {
    transform: translateY(-2px); box-shadow: 0 6px 28px rgba(0,0,0,.18) !important;
}
@keyframes wpaichat-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Fenêtre de chat ────────────────────────── */
.wpaichat-window {
    position: absolute;
    bottom: 76px; right: 0;
    width: 390px; max-width: calc(100vw - 32px);
    height: min(560px, calc(100vh - 120px));
    background: white;
    box-shadow: 0 8px 48px rgba(0,0,0,.16);
    display: flex; flex-direction: column;
    opacity: 0; transform: translateY(16px) scale(.97);
    pointer-events: none;
    transition: opacity .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
    max-height: calc(100vh - 120px);
}
.wpaichat-bl .wpaichat-window { right: auto; left: 0; }
.wpaichat-window.is-open {
    opacity: 1; transform: translateY(0) scale(1); pointer-events: all;
}

/* ─── En-tête ────────────────────────────────── */
.wpaichat-header {
    padding: 14px 16px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.wpaichat-header-left  { display: flex; align-items: center; gap: 10px; }
.wpaichat-header-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; flex-shrink: 0;
}
.wpaichat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.wpaichat-header-avatar .avatar-emoji { font-size: 20px; }
.wpaichat-header-name   { font-weight: 700; font-size: 15px; color: white; line-height: 1.2; }
.wpaichat-header-status {
    font-size: 12px; color: rgba(255,255,255,.8);
    display: flex; align-items: center; gap: 5px; margin-top: 2px;
}
.wpaichat-status-dot {
    width: 7px; height: 7px; border-radius: 50%; background: #4ade80;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(74,222,128,.3);
}
.wpaichat-header-actions {
    display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.wpaichat-reset, .wpaichat-close {
    width: 32px; height: 32px; border-radius: 8px;
    background: rgba(255,255,255,.15); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: white; transition: background .15s, transform .15s; flex-shrink: 0;
}
.wpaichat-reset:hover, .wpaichat-close:hover { background: rgba(255,255,255,.25); }
.wpaichat-reset:active { transform: rotate(-180deg); }

/* ─── Messages ───────────────────────────────── */
.wpaichat-messages {
    flex: 1 !important; overflow-y: auto !important; min-height: 0 !important;
    padding: 22px 20px !important; display: flex !important;
    flex-direction: column !important; gap: 16px !important;
    box-sizing: border-box !important;
}
.wpaichat-messages::-webkit-scrollbar { width: 4px; }
.wpaichat-messages::-webkit-scrollbar-track { background: transparent; }
.wpaichat-messages::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 2px; }

.wpaichat-msg {
    display: flex !important; max-width: 87% !important;
    animation: wpaichat-in .2s ease;
    padding: 0 !important; margin: 0 !important;
    box-sizing: border-box !important;
}
@keyframes wpaichat-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.wpaichat-msg.user { align-self: flex-end !important; flex-direction: row-reverse !important; }
.wpaichat-msg.bot  { align-self: flex-start !important; }

.wpaichat-bubble {
    padding: 14px 18px !important; border-radius: 14px !important;
    font-size: 14px !important; line-height: 1.7 !important;
    word-break: break-word !important; overflow-wrap: break-word !important;
    box-sizing: border-box !important;
}
.wpaichat-bubble ul {
    margin: 8px 0 4px !important; padding-left: 20px !important;
    list-style: disc !important;
}
.wpaichat-bubble li { margin: 5px 0 !important; padding: 0 !important; }
.wpaichat-bubble strong { font-weight: 600 !important; }
.wpaichat-bubble .wpaichat-heading {
    display: block !important; font-weight: 700 !important; font-size: 13px !important;
    text-transform: uppercase; letter-spacing: .04em;
    opacity: .7; margin: 10px 0 4px !important;
}
.wpaichat-bubble .wpaichat-heading:first-child { margin-top: 0 !important; }
.wpaichat-bubble .wpaichat-para { margin-top: 8px !important; display: block !important; }
.wpaichat-msg.user .wpaichat-bubble {
    background: #f3f4f6 !important; color: #111827 !important;
    border-radius: 14px 4px 14px 14px !important;
}
.wpaichat-msg.bot .wpaichat-bubble {
    color: #111827 !important;
    border-radius: 4px 14px 14px 14px !important;
}

/* ─── Indicateur de frappe ───────────────────── */
.wpaichat-typing .wpaichat-bubble {
    padding: 12px 16px;
    display: flex; gap: 5px; align-items: center;
}
.wpaichat-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: #9ca3af;
    animation: wpaichat-bounce 1.2s infinite;
}
.wpaichat-typing span:nth-child(2) { animation-delay: .2s; }
.wpaichat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes wpaichat-bounce {
    0%,60%,100% { transform: translateY(0); opacity: .5; }
    30%  { transform: translateY(-5px); opacity: 1; }
}

/* ─── Zone de saisie ─────────────────────────── */
.wpaichat-input-area {
    padding: 14px 16px;
    border-top: 1px solid #f3f4f6;
    display: flex; gap: 8px; align-items: flex-end;
    flex-shrink: 0; background: white;
}
.wpaichat-textarea {
    flex: 1; border: 1.5px solid #e5e7eb; border-radius: 12px;
    padding: 9px 12px; font-size: 14px; font-family: inherit;
    resize: none; outline: none; line-height: 1.5;
    min-height: 40px; max-height: 120px;
    transition: border-color .15s; color: #111827; background: white;
}
.wpaichat-textarea:focus { border-color: #7c3aed; }
.wpaichat-textarea::placeholder { color: #9ca3af; }

.wpaichat-send {
    width: 40px; height: 40px; border-radius: 10px;
    border: none; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: white; transition: opacity .15s, transform .15s;
}
.wpaichat-send:hover  { opacity: .88; transform: scale(1.05); }
.wpaichat-send:active { transform: scale(.95); }
.wpaichat-send:disabled { opacity: .5; cursor: default; transform: none; }

/* ─── Liens produits dans les messages ───────── */
.wpaichat-bubble a {
    color: inherit; text-decoration: underline;
}
.wpaichat-product-link {
    display: inline-flex; align-items: center; gap: 3px;
    background: rgba(0,0,0,.05);
    border: 1px solid rgba(0,0,0,.1);
    border-radius: 6px;
    padding: 2px 8px 2px 6px;
    font-weight: 600;
    text-decoration: none !important;
    transition: background .15s, transform .1s;
    white-space: nowrap;
}
.wpaichat-product-link:hover {
    background: rgba(0,0,0,.09);
    transform: translateY(-1px);
}
.wpaichat-product-link svg { flex-shrink: 0; opacity: .7; }

/* ═══════════════════════════════════════════════
   STYLES THÉMATIQUES
════════════════════════════════════════════════ */

/* ─── GLASS (Apple-inspired) ─────────────────── */
.wpaichat-window[data-style="glass"] {
    background: rgba(235,235,255,.58);
    backdrop-filter: blur(32px) saturate(180%) brightness(1.04);
    -webkit-backdrop-filter: blur(32px) saturate(180%) brightness(1.04);
    border: 1px solid rgba(255,255,255,.62);
    box-shadow: 0 24px 64px rgba(0,0,0,.16), inset 0 1px 0 rgba(255,255,255,.75);
}
[data-style="glass"] .wpaichat-header {
    border-bottom: 1px solid rgba(255,255,255,.25);
}
[data-style="glass"] .wpaichat-messages { background: transparent; }
[data-style="glass"] .wpaichat-msg.bot .wpaichat-bubble {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
    border-radius: 4px 18px 18px 18px;
}
[data-style="glass"] .wpaichat-msg.user .wpaichat-bubble {
    border-radius: 18px 4px 18px 18px;
}
[data-style="glass"] .wpaichat-input-area {
    background: rgba(255,255,255,.52);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255,255,255,.38);
}
[data-style="glass"] .wpaichat-textarea {
    background: rgba(255,255,255,.72);
    border-color: rgba(255,255,255,.5);
}

/* ─── DARK ───────────────────────────────────── */
.wpaichat-window[data-style="dark"] {
    background: #111827;
    box-shadow: 0 24px 64px rgba(0,0,0,.55);
    border: 1px solid rgba(255,255,255,.06);
}
[data-style="dark"] .wpaichat-header {
    background: #1a2035 !important;
}
[data-style="dark"] .wpaichat-header-name  { color: #f9fafb !important; }
[data-style="dark"] .wpaichat-header-status { color: rgba(249,250,251,.55) !important; }
[data-style="dark"] .wpaichat-close {
    background: rgba(255,255,255,.08) !important;
    color: #9ca3af !important;
}
[data-style="dark"] .wpaichat-close:hover {
    background: rgba(255,255,255,.14) !important;
    color: #f9fafb !important;
}
[data-style="dark"] .wpaichat-messages { background: #111827; }
[data-style="dark"] .wpaichat-msg.bot .wpaichat-bubble {
    background: rgba(255,255,255,.06) !important;
    border: 1px solid rgba(255,255,255,.08) !important;
    color: #e5e7eb !important;
}
[data-style="dark"] .wpaichat-msg.user .wpaichat-bubble { color: #fff !important; }
[data-style="dark"] .wpaichat-input-area {
    background: #0f172a;
    border-top: 1px solid rgba(255,255,255,.06);
}
[data-style="dark"] .wpaichat-textarea {
    background: #1f2937;
    border-color: rgba(255,255,255,.1);
    color: #f9fafb;
}
[data-style="dark"] .wpaichat-textarea::placeholder { color: rgba(255,255,255,.28); }
[data-style="dark"] .wpaichat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); }
[data-style="dark"] .wpaichat-typing span { background: rgba(255,255,255,.3); }

/* ─── SOFT ───────────────────────────────────── */
.wpaichat-window[data-style="soft"] {
    background: #fdf4ff;
}
[data-style="soft"] .wpaichat-messages { background: #fdf4ff; }
[data-style="soft"] .wpaichat-msg.bot .wpaichat-bubble {
    border-radius: 4px 20px 20px 20px;
}
[data-style="soft"] .wpaichat-msg.user .wpaichat-bubble {
    border-radius: 20px 4px 20px 20px;
}
[data-style="soft"] .wpaichat-input-area {
    background: #fdf4ff;
    border-top: 1.5px solid rgba(124,58,237,.1);
}
[data-style="soft"] .wpaichat-textarea {
    border-radius: 16px;
}

/* ─── MINIMAL ────────────────────────────────── */
.wpaichat-window[data-style="minimal"] {
    background: #fff;
    box-shadow: none;
    border: 1.5px solid #e5e7eb;
}
[data-style="minimal"] .wpaichat-header {
    border-bottom: 1.5px solid #e5e7eb;
}
[data-style="minimal"] .wpaichat-status-dot { display: none; }
[data-style="minimal"] .wpaichat-header-status { color: #6b7280 !important; }
[data-style="minimal"] .wpaichat-close {
    background: transparent !important;
}
[data-style="minimal"] .wpaichat-close:hover {
    background: #f3f4f6 !important;
    color: #111827 !important;
}
[data-style="minimal"] .wpaichat-msg.bot .wpaichat-bubble {
    border-radius: 0 12px 12px 0;
    padding-left: 16px;
}
[data-style="minimal"] .wpaichat-input-area {
    border-top: 1.5px solid #e5e7eb;
}
[data-style="minimal"] .wpaichat-textarea { border-radius: 8px; }
[data-style="minimal"] .wpaichat-send     { border-radius: 8px; }

/* ─── Suggestion Chips (Quick Replies) ───────── */
.wpaichat-suggestions {
    display: flex !important; flex-wrap: wrap !important;
    gap: 6px !important; padding: 2px 20px 8px !important;
    animation: wpaichat-in .2s ease;
}
.wpaichat-chip {
    display: inline-block !important;
    padding: 7px 14px !important;
    border: 1.5px solid rgba(124,58,237,.25) !important;
    border-radius: 20px !important;
    background: transparent !important;
    color: #7c3aed !important;
    font-size: 12.5px !important; font-weight: 500 !important;
    cursor: pointer !important;
    transition: all .15s ease !important;
    white-space: nowrap !important;
    font-family: inherit !important;
    line-height: 1.3 !important;
}
.wpaichat-chip:hover {
    background: rgba(124,58,237,.08) !important;
    border-color: #7c3aed !important;
    transform: translateY(-1px);
}
.wpaichat-chip:active { transform: scale(.97); }

/* Dark theme chips */
[data-style="dark"] .wpaichat-suggestions .wpaichat-chip {
    border-color: rgba(255,255,255,.15) !important;
    color: #a78bfa !important;
}
[data-style="dark"] .wpaichat-suggestions .wpaichat-chip:hover {
    background: rgba(167,139,250,.12) !important;
    border-color: #a78bfa !important;
}

/* Follow-up chips — slightly smaller */
.wpaichat-followups {
    padding-top: 0 !important;
}
.wpaichat-chip-follow {
    font-size: 11.5px !important;
    padding: 5px 12px !important;
}

/* ─── Product Cards ─────────────────────────── */
.wpaichat-product-cards {
    display: flex !important; gap: 10px !important;
    overflow-x: auto !important; padding: 4px 20px 8px !important;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0 !important;
    min-height: 0 !important;
    height: auto !important;
}
.wpaichat-product-cards::-webkit-scrollbar { height: 3px; }
.wpaichat-product-cards::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }
.wpaichat-product-card {
    flex: 0 0 160px !important; background: #fff !important;
    border: 1px solid #e5e7eb !important; border-radius: 12px !important;
    overflow: hidden !important; scroll-snap-align: start;
    display: flex !important; flex-direction: column !important;
    transition: transform .15s, box-shadow .15s;
    height: auto !important; min-height: 220px !important;
}
.wpaichat-product-card:hover {
    transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.1);
}
.wpaichat-card-image {
    display: block !important; background: #f9fafb !important;
    position: relative !important;
}
.wpaichat-card-badge {
    position: absolute !important; top: 6px !important; left: 6px !important;
    padding: 2px 7px !important; border-radius: 6px !important;
    font-size: 10px !important; font-weight: 700 !important;
    text-transform: uppercase !important; letter-spacing: .03em;
    z-index: 1 !important; line-height: 1.4 !important;
}
.wpaichat-badge-sale {
    background: #ef4444 !important; color: #fff !important;
}
.wpaichat-badge-low {
    background: #f59e0b !important; color: #fff !important;
}
.wpaichat-card-image img {
    width: 100% !important; height: 120px !important;
    object-fit: cover !important; display: block !important;
}
/* Placeholder image fallback */
.wpaichat-card-image img[src*="placeholder"],
.wpaichat-card-image img[src*="woocommerce-placeholder"] {
    object-fit: contain !important; padding: 16px !important;
    opacity: .4 !important; background: #f3f4f6 !important;
}
.wpaichat-card-info {
    padding: 10px 12px 6px !important; flex: 1 !important;
}
.wpaichat-card-name {
    font-size: 12.5px !important; font-weight: 600 !important;
    color: #111827 !important; text-decoration: none !important;
    display: -webkit-box !important; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden !important;
    line-height: 1.3 !important;
}
.wpaichat-card-name:hover { text-decoration: underline !important; }
.wpaichat-card-price {
    font-size: 13px !important; font-weight: 700 !important;
    color: #111827 !important; margin-top: 4px !important;
}
.wpaichat-card-price del { opacity: .5; font-weight: 400; font-size: 11px; }
.wpaichat-card-price ins { text-decoration: none; }
.wpaichat-card-atc {
    display: block !important; text-align: center !important;
    padding: 7px 8px !important; margin: 6px 10px 10px !important;
    border-radius: 8px !important; font-size: 12px !important;
    font-weight: 600 !important; cursor: pointer !important;
    text-decoration: none !important;
    background: var(--wpaichat-primary, #7c3aed) !important;
    color: #fff !important; border: none !important;
    transition: opacity .15s, transform .1s;
}
.wpaichat-card-atc:hover { opacity: .88; transform: scale(1.02); }
.wpaichat-card-atc.is-added {
    background: #10b981 !important; pointer-events: none !important;
}
.wpaichat-card-oos {
    display: block !important; text-align: center !important;
    padding: 7px 8px !important; margin: 6px 10px 10px !important;
    font-size: 12px !important; color: #9ca3af !important;
    font-weight: 500 !important;
}

[data-style="glass"] .wpaichat-product-card {
    background: rgba(255,255,255,.72) !important;
    border-color: rgba(255,255,255,.5) !important;
    backdrop-filter: blur(8px);
}
[data-style="dark"] .wpaichat-product-card {
    background: #1f2937 !important;
    border-color: rgba(255,255,255,.08) !important;
}
[data-style="dark"] .wpaichat-card-name { color: #f9fafb !important; }
[data-style="dark"] .wpaichat-card-price { color: #e5e7eb !important; }
[data-style="dark"] .wpaichat-card-image { background: #111827 !important; }

/* ─── Mobile ─────────────────────────────────── */
@media (max-width: 480px) {
    .wpaichat-br { bottom: 12px !important; right: 12px !important; }
    .wpaichat-bl { bottom: 12px !important; left: 12px !important; }
    .wpaichat-window {
        position: fixed !important;
        top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
        width: 100vw !important; height: 100vh !important;
        max-width: 100vw !important; max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 2147483001;
    }
    .wpaichat-bl .wpaichat-window,
    .wpaichat-br .wpaichat-window {
        right: 0 !important; left: 0 !important;
        margin: 0 !important;
        width: 100vw !important;
    }
    .wpaichat-messages {
        padding: 16px 14px !important;
    }
    .wpaichat-bubble {
        padding: 12px 14px !important;
        font-size: 14px !important;
    }
    .wpaichat-product-cards {
        padding: 4px 14px 8px !important;
    }
    .wpaichat-product-card {
        flex: 0 0 140px !important;
    }
    .wpaichat-card-image img {
        height: 100px !important;
    }
    .wpaichat-preview {
        max-width: 220px !important;
        right: -4px !important;
        bottom: 66px !important;
    }
    .wpaichat-toggle {
        width: 54px !important; height: 54px !important;
    }
    .wpaichat-header {
        padding: 16px !important;
        padding-top: max(16px, env(safe-area-inset-top)) !important;
    }
    .wpaichat-input-area {
        padding-bottom: max(14px, env(safe-area-inset-bottom)) !important;
    }
    .wpaichat-suggestions {
        padding: 2px 14px 8px !important;
    }
    .wpaichat-chip {
        font-size: 12px !important;
        padding: 6px 12px !important;
    }
}
