/* ================================================
   AI Chat Widget
   ================================================ */

/* ── FAB Button ─────────────────────────────── */
#ai-chat-fab {
    position: fixed;
    bottom: 65px;
    right: 28px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--partner-color, #6c5dd3);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
    z-index: 9998;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    outline: none;
}

#ai-chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

/* ── FAB Tooltip ────────────────────────────── */
#ai-chat-fab::before {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(30, 30, 40, 0.88);
    color: #fff;
    font-size: 12px;
    font-family: inherit;
    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 7px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease, transform 0.18s ease;
    transform: translateY(-50%) translateX(6px);
}

#ai-chat-fab::after {
    content: '';
    position: absolute;
    right: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-left-color: rgba(30, 30, 40, 0.88);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
}

#ai-chat-fab:hover::before,
#ai-chat-fab:hover::after {
    opacity: 1;
}

#ai-chat-fab:hover::before {
    transform: translateY(-50%) translateX(0);
}

#ai-chat-fab.is-open::before,
#ai-chat-fab.is-open::after {
    display: none;
}

#ai-chat-fab.is-open {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.7);
}

#ai-chat-fab svg {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#ai-chat-fab.is-open .fab-icon-chat {
    transform: scale(0) rotate(45deg);
    opacity: 0;
    position: absolute;
}

#ai-chat-fab.is-open .fab-icon-close {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

#ai-chat-fab .fab-icon-close {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
    position: absolute;
}

/* ── Notification Badge ─────────────────────── */
#ai-chat-fab .fab-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    background: #f44336;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}

/* ── Chat Window ────────────────────────────── */
#ai-chat-window {
    position: fixed;
    bottom: 65px;
    right: 28px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 130px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    z-index: 9997;
    overflow: hidden;
    transform-origin: bottom right;
    opacity: 0;
    transform: scale(0.85) translateY(20px);
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#ai-chat-window.is-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

/* ── Header ─────────────────────────────────── */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--partner-color, #6c5dd3);
    color: #fff;
    flex-shrink: 0;
    direction: rtl;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-chat-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    margin: 0;
}

.ai-chat-subtitle {
    font-size: 11px;
    opacity: 0.82;
    margin: 0;
}

.ai-chat-header-actions {
    display: flex;
    gap: 6px;
}

.ai-chat-header-btn {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    transition: background 0.18s;
}

.ai-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* ── Messages Area ──────────────────────────── */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    direction: rtl;
    scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 4px;
}

/* ── Bubble ─────────────────────────────────── */
.ai-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 7px;
}

.ai-msg-row.user-row {
    flex-direction: row-reverse;
}

.ai-msg-bubble {
    max-width: 78%;
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}

.ai-msg-row.bot-row .ai-msg-bubble {
    background: #f3f3f7;
    color: #333;
    border-bottom-right-radius: 4px;
}

.ai-msg-row.user-row .ai-msg-bubble {
    background: var(--partner-color, #6c5dd3);
    color: #fff;
    border-bottom-left-radius: 4px;
    white-space: pre-wrap;
}

.ai-msg-time {
    font-size: 10px;
    color: #b0b0b0;
    margin-top: 3px;
    text-align: left;
    direction: ltr;
    flex-shrink: 0;
    align-self: flex-end;
}

.ai-msg-row.user-row .ai-msg-time {
    text-align: right;
}

/* ── Streaming Cursor ──────────────── */
.ai-typing-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background: var(--partner-color, #6c5dd3);
    margin-right: 2px;
    vertical-align: middle;
    animation: ai-blink 0.7s steps(1) infinite;
}

@keyframes ai-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ── Typing Dots ─ */
.ai-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
}

.ai-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    animation: ai-dot-bounce 1.2s infinite ease-in-out;
}

.ai-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes ai-dot-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40%            { transform: scale(1.2); opacity: 1;   }
}

/* ── Welcome / Empty State ──────────────────── */
.ai-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 24px;
    text-align: center;
    color: #888;
    gap: 10px;
}

.ai-chat-welcome svg {
    opacity: 0.35;
}

.ai-chat-welcome p {
    font-size: 13px;
    margin: 0;
    line-height: 1.7;
}

/* ── Input Area ─────────────────────────────── */
.ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    flex-shrink: 0;
    direction: rtl;
}

#ai-chat-input {
    flex: 1;
    border: 1.5px solid #e8e8ee;
    border-radius: 12px;
    padding: 9px 13px;
    font-size: 13.5px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.18s;
    direction: rtl;
    background: #fafafa;
}

#ai-chat-input:focus {
    border-color: var(--partner-color, #6c5dd3);
    background: #fff;
}

#ai-chat-input::placeholder {
    color: #bbb;
}

#ai-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--partner-color, #6c5dd3);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.18s, transform 0.18s;
}

#ai-chat-send:hover:not(:disabled) {
    opacity: 0.88;
    transform: scale(1.06);
}

#ai-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ── Error Bubble ───────────────────────────── */
.ai-msg-error {
    background: #fff0f0 !important;
    color: #c0392b !important;
    font-size: 13px !important;
    border: 1px solid #ffd7d7 !important;
}

/* ── Mobile ─────────────────────────────────── */
@media (max-width: 480px) {
    #ai-chat-window {
        left: 10px;
        right: 10px;
        width: auto;
        bottom: 66px;
        border-radius: 14px;
    }

    #ai-chat-fab {
        right: 16px;
        bottom: 65px;
    }
}

/* ── Paywall ─────────────────────────────────── */
.ai-chat-paywall {
    margin: 8px 4px 4px;
    padding: 14px 16px;
    background: #fff8e1;
    border: 1.5px solid #ffe082;
    border-radius: 14px;
    text-align: center;
    direction: rtl;
}

.ai-chat-paywall p {
    margin: 0 0 10px;
    font-size: 13px;
    color: #5d4037;
    line-height: 1.7;
}

.ai-chat-paywall-icon {
    display: block;
    font-size: 26px;
    margin-bottom: 8px;
}

.ai-chat-paywall-sub {
    font-size: 12px !important;
    color: #888 !important;
    margin-top: 2px !important;
}

.ai-chat-paywall--auth {
    background: #f3f3f7;
    border-color: #d0d0e0;
}

.ai-chat-paywall--auth p {
    color: #444;
}

.ai-chat-paywall-btn {
    display: inline-block;
    padding: 8px 22px;
    background: var(--partner-color, #6c5dd3);
    color: #fff !important;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    text-decoration: none;
    transition: opacity 0.18s;
}

.ai-chat-paywall-btn:hover {
    opacity: 0.85;
    text-decoration: none;
}

/* ── Send button spinner ─────────────────────── */
.ai-send-spinner {
    display: none;
    animation: ai-spin 0.7s linear infinite;
}

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

#ai-chat-send.is-loading .ai-send-icon    { display: none; }
#ai-chat-send.is-loading .ai-send-spinner { display: block; }
