/* Chat Widget Styles - Premium Redesign */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');

.chat-widget-fab {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 65px;
    height: 65px;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    border-radius: 50%;
    box-shadow: 0 8px 32px rgba(37, 99, 235, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 2147483647;
    /* Max z-index to ensure visibility */
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.chat-widget-fab:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

/* Robot Icon Animation */
.chat-widget-fab svg {
    width: 36px;
    height: 36px;
    fill: #ffffff;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.chat-window {
    position: fixed;
    bottom: 110px;
    left: 30px;
    /* Aligned with FAB */
    width: 380px;
    height: 600px;
    max-height: 80vh;
    background-color: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    font-family: 'Tajawal', sans-serif;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.chat-header {
    background: linear-gradient(135deg, #0f172a, #1e293b);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header h3::before {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    background-color: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 10px #22c55e;
}

.chat-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);

    /* FIX: Force text direction logic */
    unicode-bidi: plain;
}

.message[dir="rtl"] {
    text-align: right;
    direction: rtl;
}

.message[dir="ltr"] {
    text-align: left;
    direction: ltr;
}

.message.user {
    align-self: flex-start;
    /* User on Left (Ltr) or Right (Rtl) depending on Page Dir, but let's force standard chat layout */
    align-self: flex-end;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
    background-color: white;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    padding: 15px;
    background-color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid #f1f5f9;
}

/* Language Header */
.chat-lang-header p {
    text-align: center;
    font-weight: 800;
    margin-bottom: 20px;
    color: #334155;
    font-size: 16px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Premium Language Buttons */
.chat-lang-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 16px 20px;
    border-radius: 16px;
    width: 100%;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.chat-lang-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #e2e8f0;
    transition: background 0.3s;
}

.chat-lang-btn:hover {
    border-color: #fbbf24;
    transform: translateY(-3px);
    box-shadow: 0 12px 20px -5px rgba(251, 191, 36, 0.15);
    background: #fffcf5;
    /* Subtle yellow tint */
}

.chat-lang-btn:hover::before {
    background: #fbbf24;
    /* Gold bar on hover */
}

.chat-lang-flag {
    font-size: 28px;
    margin-right: 15px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.chat-lang-text {
    font-weight: 700;
    color: #1e293b;
    font-size: 17px;
    flex-grow: 1;
    text-align: left;
}

/* RTL specific adjust for Arabic */
.chat-lang-btn[dir="rtl"] .chat-lang-text {
    text-align: right;
    margin-right: 15px;
}

.chat-lang-btn[dir="rtl"] .chat-lang-flag {
    margin-right: 0;
    margin-left: 15px;
}

.chat-lang-btn[dir="rtl"] .chat-lang-arrow {
    transform: rotate(180deg);
}

.chat-lang-arrow {
    color: #cbd5e1;
    font-weight: bold;
    transition: color 0.3s, transform 0.3s;
}

.chat-lang-btn:hover .chat-lang-arrow {
    color: #fbbf24;
    transform: translateX(3px);
}

.chat-input-area input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 25px;
    outline: none;
    font-size: 15px;
    font-family: 'Tajawal', sans-serif;
    transition: border-color 0.2s;
    background-color: #f8fafc;
}

.chat-input-area input:focus {
    border-color: #3b82f6;
    background-color: white;
}

.chat-send-btn {
    background: #0f172a;
    color: white;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
}

.chat-send-btn:hover {
    background-color: #334155;
    transform: scale(1.05);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background-color: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
        opacity: 0.6;
    }

    50% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .chat-widget-fab {
        bottom: 20px;
        left: 20px;
        width: 55px;
        height: 55px;
    }

    .chat-window {
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 100000;
    }

    .chat-header {
        padding-top: 40px;
        /* Safe area for status bar */
    }
}