/* AI Chat Widget — floating assistant on the storefront.
   Phase 2 (docs/AI/AI_plan_01.md §3.13).
   - Bottom-right floating bubble.
   - Slide-out panel with messages + input.
   - RTL support via dir="auto" on message containers.
   - Responsive: collapses to bubble on mobile.
*/

#ai-chat-widget {
    position: fixed;
    bottom: 84px; /* above the floating view-cart bar (.cbar, ~70px tall) and the cookie banner */
    right: 20px;
    /* Above the customer page's floating cart bar (z-index 200) so the chat
       launcher/panel never render under it; below modals/drawers (300+),
       the promo popup (960) and the AR/fullscreen overlays (9999). */
    z-index: 210;
    font-family: -apple-system, BlinkMacSystemFont, 'Google Sans', 'Inter', sans-serif;
}

/* Cookie banner (z-index 99997, ~66px tall fixed bottom bar) — while it's
   visible, lift the whole widget so the bubble sits just above the banner
   instead of under it. Class toggled by the observer in ai-chat-widget.blade.php. */
.ai-cookie-offset#ai-chat-widget {
    bottom: 150px;
}

/* "Order via AI Chat" label above the bubble */
.ai-chat-label {
    position: absolute;
    bottom: 68px; /* sits just above the bubble */
    right: 0;
    background: var(--amber, #f59e0b);
    color: #000;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 6px;
    white-space: nowrap;
    letter-spacing: 0.02em;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}
.ai-chat-label::after {
    content: '';
    position: absolute;
    bottom: -5px;
    right: 18px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--amber, #f59e0b);
}

/* ─── Bubble ─────────────────────────────────────────────────────────── */
#ai-chat-bubble {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: var(--amber, #f59e0b);
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}
#ai-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(245, 158, 11, 0.55);
}
#ai-chat-bubble svg {
    width: 28px;
    height: 28px;
}

/* ─── Panel ──────────────────────────────────────────────────────────── */
#ai-chat-panel {
    display: none;
    position: absolute;
    /* Above legal overlays (cookie banner 99997) when open — the bubble must
       stay below them, but the open panel needs to be usable. */
    z-index: 100000;
    bottom: 80px; /* adjusted for larger bubble */
    right: 0;
    width: 360px;
    max-height: 520px;
    background: var(--bg1, #1a1512);
    border: 1px solid var(--border, #3a322c);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 0;
    transform: translateY(8px);
}
#ai-chat-panel.open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.ai-chat-header {
    padding: 14px 18px;
    background: var(--bg2, #2a2320);
    border-bottom: 1px solid var(--border, #3a322c);
    font-size: 14px;
    font-weight: 600;
    color: var(--t1, #ece7e2);
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-chat-header::before {
    content: "🤖";
    font-size: 16px;
}
.ai-chat-header > span {
    flex: 1;
}

/* X close button — inline-start edge of the header (left in LTR, right in RTL) */
.ai-chat-close {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-inline-end: 4px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--t3, #8a8a90);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}
.ai-chat-close:hover {
    color: var(--t1, #ece7e2);
    background: rgba(255, 255, 255, 0.08);
}

/* ─── Messages ───────────────────────────────────────────────────────── */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 320px;
    scrollbar-width: thin;
    scrollbar-color: var(--border, #3a322c) transparent;
}
.ai-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border, #3a322c);
    border-radius: 2px;
}

.ai-msg {
    max-width: 88%;
    padding: 6px 11px;
    border-radius: 10px;
    font-size: 12.5px;
    line-height: 1.45;
    word-wrap: break-word;
}

.ai-msg-user {
    align-self: flex-end;
    background: var(--amber, #f59e0b);
    color: #000;
    border-bottom-right-radius: 4px;
}

.ai-msg-assistant {
    align-self: flex-start;
    background: var(--card, #2a2320);
    color: var(--t1, #ece7e2);
    border: 1px solid var(--border, #3a322c);
    border-bottom-left-radius: 4px;
}

.ai-msg-system {
    align-self: center;
    background: transparent;
    color: var(--t3, #8a8a90);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 6px;
}

/* Staff reply bubble (human handoff) — green-tinted variant of assistant */
.ai-msg-staff {
    background: rgba(34, 197, 94, 0.10);
    border-color: rgba(34, 197, 94, 0.35);
    color: #ffffff;
}
.ai-msg-staff-name {
    font-size: 10px;
    font-weight: 700;
    color: #4ade80;
    margin-bottom: 3px;
    letter-spacing: 0.02em;
}

/* ─── Suggestion chips (quick replies) ────────────────────────────────── */
.ai-chat-chips {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px 4px;
}
.ai-chip {
    padding: 7px 14px;
    border-radius: 16px;
    border: 1px solid var(--amber, #f59e0b);
    background: transparent;
    color: var(--amber, #f59e0b);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
    font-family: inherit;
}
.ai-chip:hover {
    background: rgba(245, 158, 11, 0.12);
}

/* ─── Status ─────────────────────────────────────────────────────────── */
.ai-chat-status {
    padding: 4px 14px;
    font-size: 11px;
    color: var(--t3, #8a8a90);
    min-height: 18px;
}

/* ─── Input area ─────────────────────────────────────────────────────── */
.ai-chat-input-area {
    padding: 12px 14px;
    background: var(--bg2, #2a2320);
    border-top: 1px solid var(--border, #3a322c);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    padding: 9px 14px;
    background: var(--card, #2a2320);
    border: 1px solid var(--border, #3a322c);
    border-radius: 20px;
    color: var(--t1, #ece7e2);
    font-size: 13px;
    outline: none;
    resize: none;
    font-family: inherit;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
}
.ai-chat-input:focus {
    border-color: var(--amber, #f59e0b);
}
.ai-chat-input::placeholder {
    color: var(--t3, #8a8a90);
}

.ai-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--amber, #f59e0b);
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    outline: none;
    transition: transform 0.15s ease;
}
.ai-chat-send:hover {
    transform: scale(1.05);
}
.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── RTL ────────────────────────────────────────────────────────────── */
[dir="rtl"] .ai-msg-user {
    align-self: flex-start;
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
}
[dir="rtl"] .ai-msg-assistant {
    align-self: flex-end;
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}

/* ─── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #ai-chat-panel {
        width: calc(100vw - 32px);
        right: -4px;
        max-height: 70vh;
    }
    #ai-chat-widget {
        bottom: 84px; /* stay above the floating view-cart bar on mobile too */
        right: 16px;
    }
    .ai-chat-messages {
        max-height: 40vh;
    }
}

/* ─── Dark-mode ready (uses CSS vars with defaults) ───────────────────── */
