/* ═══════════════════════════════════════════════════════════
   SarfiPay Investor-Grade AI Assistant (Gen-3.1)
   Premium Fintech UI/UX Overhaul
   ═══════════════════════════════════════════════════════════ */

:root {
    --assistant-primary: #2563eb;
    --assistant-primary-dark: #1e40af;
    --assistant-bg: #ffffff;
    --assistant-bg-dark: #0f172a;
    --assistant-text: #0f172a;
    --assistant-text-dark: #f8fafc;
    --assistant-bot-msg: #f1f5f9;
    --assistant-bot-msg-dark: #1e293b;
    --assistant-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    --assistant-radius: 16px;
    --assistant-z: 99999;
}

/* --- Phase 1: Floating Button (Critical) --- */
.sarfipay-assistant-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--assistant-primary), var(--assistant-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    z-index: var(--assistant-z);
    transition: all 0.3s ease;
    border: none;
    outline: none;
}

.sarfipay-assistant-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 30px rgba(37, 99, 235, 0.4);
}

.sarfipay-assistant-btn:active {
    transform: scale(0.95);
}

.sarfipay-assistant-btn svg {
    width: 18px;
    height: 18px;
    color: white;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
}

/* Phase 2: Dark Mode Visibility for Button */
[data-theme="dark"] .sarfipay-assistant-btn,
body.dark .sarfipay-assistant-btn {
    background: linear-gradient(135deg, #0f172a, #1e293b);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- Phase 3 & 5: Chat Panel UI --- */
.container-chat {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 340px;
    max-height: 550px;
    height: 500px;
    background: var(--assistant-bg);
    border-radius: var(--assistant-radius);
    box-shadow: var(--assistant-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--assistant-z);
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.container-chat.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dark Mode Panel */
[data-theme="dark"] .container-chat,
body.dark .container-chat {
    background: var(--assistant-bg-dark);
    color: var(--assistant-text-dark);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Header */
.chat-header {
    padding: 20px;
    background: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

[data-theme="dark"] .chat-header,
body.dark .chat-header {
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

.chat-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: inherit;
}

.chat-header .header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    opacity: 0.7;
}

.chat-header .status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
}

.chat-close-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.5;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
}

.chat-close-btn:hover {
    opacity: 1;
}

/* Messages Area */
.chat-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
}

.chat-content::-webkit-scrollbar {
    width: 4px;
}

.chat-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* Message Styles */
.user-message {
    background: var(--assistant-primary);
    color: white !important;
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.bot-message {
    background: var(--assistant-bot-msg);
    color: var(--assistant-text) !important;
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    border: 1px solid var(--border, rgba(0,0,0,0.05));
}

[data-theme="dark"] .bot-message,
body.dark .bot-message {
    background: var(--assistant-bot-msg-dark);
    color: var(--assistant-text-dark) !important;
}

/* Suggestions Area */
.chat-footer {
    padding: 16px;
    background: transparent;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.message-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 0 2px;
}

.suggestion-chip {
    background: transparent;
    border: 1px solid var(--assistant-primary);
    color: var(--assistant-primary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-chip:hover {
    background: var(--assistant-primary);
    color: white;
}

/* Phase 4: Input Area Fix */
[data-theme="dark"] .chat-footer,
body.dark .chat-footer {
    border-top-color: rgba(255, 255, 255, 0.05);
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--assistant-bot-msg);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

[data-theme="dark"] .chat-input-wrapper,
body.dark .chat-input-wrapper {
    background: var(--assistant-bot-msg-dark);
}

.chat-input-wrapper:focus-within {
    border-color: var(--assistant-primary);
    background: var(--assistant-bg);
}

[data-theme="dark"] .chat-input-wrapper:focus-within,
body.dark .chat-input-wrapper:focus-within {
    background: var(--assistant-bg-dark);
}

.chat-input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    padding: 8px 0;
    color: inherit;
    font-size: 0.95rem;
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    background: var(--assistant-primary);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.1);
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
}

/* Phase 7: Responsive Fix */
@media (max-width: 768px) {
    .container-chat {
        width: 90%;
        right: 5%;
        bottom: 90px;
        height: 60%;
        max-height: 450px;
    }

    .sarfipay-assistant-btn {
        width: 42px !important;
        height: 42px !important;
        min-width: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        bottom: 15px !important;
        right: 15px !important;
    }

    .sarfipay-assistant-btn svg {
        width: 14px !important;
        height: 14px !important;
    }
}

/* Typing Indicator (Updated) */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
    opacity: 0.4;
    animation: typing 1s infinite alternate;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    from { transform: translateY(0); opacity: 0.4; }
    to { transform: translateY(-4px); opacity: 1; }
}

/* Link Style */
.chat-link {
    color: var(--assistant-primary);
    text-decoration: none;
    font-weight: 700;
}
.chat-link:hover {
    text-decoration: underline;
}

/* --- Phase 8: RTL Support (Arabic) --- */
[dir="rtl"] .sarfipay-assistant-btn {
    right: auto;
    left: 24px;
}

[dir="rtl"] .container-chat {
    right: auto;
    left: 24px;
}

[dir="rtl"] .chat-content {
    direction: rtl;
}

[dir="rtl"] .user-message {
    align-self: flex-start;
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .bot-message {
    align-self: flex-end;
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}

@media (max-width: 768px) {
    [dir="rtl"] .sarfipay-assistant-btn {
        right: auto;
        left: 15px;
    }

    [dir="rtl"] .container-chat {
        right: auto;
        left: 5%;
    }
}

