/* ══════════════════════════════════════════
   Landing Chat Widget — RTL-safe, themeable
   ══════════════════════════════════════════ */

/* Container */
.chat-widget {
    position: fixed;
    bottom: 20px;
    inset-inline-end: 20px;
    z-index: 9999;
    font-family: 'IBM Plex Sans Arabic', 'Cairo', 'Segoe UI', sans-serif;
    direction: rtl;
}

/* ── Toggle Button ── */
.chat-toggle {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary, #6366f1), var(--accent, #a855f7));
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    overflow: hidden;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.chat-toggle:focus-visible {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: 3px;
}

.chat-toggle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chat-toggle i {
    transition: transform 0.3s ease;
}

.chat-widget.open .chat-toggle i {
    transform: rotate(180deg);
}

/* Pulse animation for notifications */
.chat-toggle.has-popup::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--primary, #6366f1);
    animation: chatPulse 2s ease-in-out infinite;
}

@keyframes chatPulse {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 0; }
}

/* Online indicator dot */
.chat-toggle .online-dot {
    position: absolute;
    top: 2px;
    inset-inline-end: 2px;
    width: 14px;
    height: 14px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* ── Popup Bubble ── */
.chat-popup-bubble {
    position: absolute;
    bottom: 70px;
    inset-inline-end: 0;
    background: var(--surface, #fff);
    color: var(--ink, #334155);
    padding: 12px 18px;
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    font-size: 14px;
    line-height: 1.5;
    max-width: 260px;
    min-width: 160px;
    animation: bubbleIn 0.4s ease;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border-s, rgba(0, 0, 0, 0.05));
}

[dir="rtl"] .chat-popup-bubble {
    border-radius: 16px 16px 4px 16px;
}

.chat-popup-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.15);
}

.chat-popup-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    inset-inline-end: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--surface, #fff);
}

.chat-popup-bubble .bubble-close {
    position: absolute;
    top: 4px;
    inset-inline-start: 6px;
    background: none;
    border: none;
    color: var(--ink-3, #94a3b8);
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
    line-height: 1;
}

.chat-popup-bubble .bubble-close:hover {
    color: var(--ink-2, #64748b);
}

@keyframes bubbleIn {
    from { opacity: 0; transform: scale(0.8) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes bubbleOut {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to { opacity: 0; transform: scale(0.8) translateY(10px); }
}

.chat-popup-bubble.hiding {
    animation: bubbleOut 0.3s ease forwards;
}

[data-theme="dark"] .chat-popup-bubble {
    background: var(--surface, #1e293b);
    color: var(--ink, #e2e8f0);
    border-color: var(--border-s, rgba(255, 255, 255, 0.1));
}

[data-theme="dark"] .chat-popup-bubble::after {
    border-top-color: var(--surface, #1e293b);
}

/* ── Chat Panel ── */
.chat-panel {
    position: absolute;
    bottom: 80px;
    inset-inline-end: 0;
    width: 370px;
    height: 520px;
    background: var(--surface, #fff);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: slideIn 0.3s ease;
    border: 1px solid var(--border-s, rgba(0, 0, 0, 0.05));
}

[dir="rtl"] .chat-panel {
    transform-origin: bottom left;
}

.chat-widget.open .chat-panel {
    display: flex;
}

.chat-widget.open .chat-popup-bubble {
    display: none;
}

[data-theme="dark"] .chat-panel {
    background: var(--surface, #1e293b);
    border-color: var(--border-s, rgba(255, 255, 255, 0.1));
}

/* ── Header ── */
.chat-header {
    background: linear-gradient(135deg, var(--primary, #6366f1), var(--accent, #a855f7));
    padding: 14px 18px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-avatar i {
    font-size: 18px;
}

.chat-header-text h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.chat-header-text span {
    font-size: 11px;
    opacity: 0.85;
}

.chat-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.8;
    padding: 4px;
}

.chat-close:hover {
    opacity: 1;
}

.chat-close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Messages Area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-alt, #f8fafc);
}

[data-theme="dark"] .chat-messages {
    background: var(--bg, #0f172a);
}

/* Message bubbles */
.chat-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
}

/* User messages: start side (right in RTL) */
.chat-msg.user {
    align-self: flex-start;
    background: linear-gradient(135deg, var(--primary, #6366f1), var(--accent, #a855f7));
    color: white;
    border-end-end-radius: 4px;
}

/* Assistant messages: end side (left in RTL) */
.chat-msg.assistant {
    align-self: flex-end;
    background: var(--surface, #fff);
    color: var(--ink, #334155);
    border-end-start-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.chat-msg.assistant .msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    position: absolute;
    bottom: -4px;
    inset-inline-end: -30px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary, #6366f1), var(--accent, #a855f7));
    color: #fff;
    font-size: 10px;
}

.chat-msg.assistant .msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

[data-theme="dark"] .chat-msg.assistant {
    background: var(--surface-hover, #334155);
    color: var(--ink, #f1f5f9);
}

/* ── Suggested Questions ── */
.chat-suggested {
    padding: 10px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--bg-alt, #f1f5f9);
    border-top: 1px solid var(--border-s, rgba(0, 0, 0, 0.05));
    flex-shrink: 0;
}

[data-theme="dark"] .chat-suggested {
    background: var(--surface, #1e293b);
    border-top-color: var(--border-s, rgba(255, 255, 255, 0.05));
}

.suggestion-chip {
    background: var(--surface, white);
    border: 1px solid var(--primary, #6366f1);
    color: var(--primary, #6366f1);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.suggestion-chip:hover {
    background: var(--primary, #6366f1);
    color: white;
}

[data-theme="dark"] .suggestion-chip {
    background: transparent;
}

[data-theme="dark"] .suggestion-chip:hover {
    background: var(--primary, #6366f1);
}

/* ── Input Area ── */
.chat-input {
    padding: 12px 14px;
    background: var(--surface, white);
    border-top: 1px solid var(--border-s, rgba(0, 0, 0, 0.05));
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

[data-theme="dark"] .chat-input {
    background: var(--surface, #1e293b);
    border-top-color: var(--border-s, rgba(255, 255, 255, 0.05));
}

.chat-input input {
    flex: 1;
    border: 1px solid var(--border-s, #e2e8f0);
    border-radius: 25px;
    padding: 10px 16px;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
    background: var(--bg-alt, #fff);
    color: var(--ink, #334155);
}

.chat-input input:focus {
    border-color: var(--primary, #6366f1);
}

.chat-input input:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-soft, rgba(99,102,241,.15));
}

[data-theme="dark"] .chat-input input {
    background: var(--bg, #334155);
    border-color: var(--border, #475569);
    color: var(--ink, white);
}

.chat-input button {
    width: 40px;
    height: 40px;
    background: var(--primary, #6366f1);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.chat-input button:hover {
    background: var(--accent, #5a67d8);
    transform: scale(1.05);
}

.chat-input button:disabled {
    background: var(--ink-3, #cbd5e1);
    cursor: not-allowed;
    transform: none;
}

.chat-input button:focus-visible {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: 2px;
}

/* ── Animations ── */
@keyframes slideIn {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Typing Indicator ── */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

.typing-indicator span {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: var(--ink-3, #94a3b8);
    border-radius: 50%;
    animation: typing 1s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* ── Mobile Responsive ── */
@media (max-width: 480px) {
    .chat-panel {
        width: calc(100vw - 30px);
        height: 80vh;
        bottom: 75px;
        inset-inline-end: -5px;
    }

    .chat-popup-bubble {
        max-width: 220px;
        inset-inline-end: 0;
    }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    .chat-toggle,
    .chat-popup-bubble,
    .chat-panel,
    .typing-indicator span {
        animation: none !important;
        transition-duration: 0s !important;
    }
}
