/* ===== AI Chat Widget ===== */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Arsenal', sans-serif;
}

.rtl .chat-widget {
    right: auto;
    left: 24px;
}

/* Toggle Button */
.chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c8102e 0%, #e63946 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(200, 16, 46, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(200, 16, 46, 0.5);
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s ease;
}

.rtl .chat-window {
    right: auto;
    left: 0;
}

@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #c8102e 0%, #e63946 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-header-info strong {
    display: block;
    font-size: 14px;
    line-height: 1.2;
}

.chat-header-info small {
    font-size: 11px;
    opacity: 0.85;
}

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

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

.chat-new-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 320px;
    min-height: 200px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.chat-msg-assistant {
    align-self: flex-start;
}

.chat-msg-user {
    align-self: flex-end;
}

.chat-msg-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-msg-assistant .chat-msg-content {
    background: #f1f3f5;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}

.rtl .chat-msg-assistant .chat-msg-content {
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}

.chat-msg-user .chat-msg-content {
    background: linear-gradient(135deg, #c8102e, #e63946);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.rtl .chat-msg-user .chat-msg-content {
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
}

/* Sources */
.chat-msg-sources {
    margin-top: 6px;
    padding: 6px 10px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.6;
    color: #888;
}

.chat-msg-sources a {
    color: #c8102e;
    text-decoration: none;
}

.chat-msg-sources a:hover {
    text-decoration: underline;
}

/* Markdown rendering */
.chat-msg-content .chat-heading {
    display: block;
    font-size: 13px;
    margin-top: 6px;
    margin-bottom: 2px;
    color: #c8102e;
}

.chat-msg-content .chat-list-item {
    display: block;
    padding-left: 4px;
}

/* Suggestions */
.chat-suggestions {
    padding: 8px 16px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chat-suggestion {
    background: #fff5f5;
    border: 1px solid #fecaca;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    color: #c8102e;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chat-suggestion:hover {
    background: #c8102e;
    color: #fff;
    border-color: #c8102e;
}

/* Input Area */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
}

.chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #c8102e;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #c8102e;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-send-btn:not(:disabled):hover {
    background: #a00d24;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: #f1f3f5;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
}

.chat-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: chatTyping 1.4s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Mobile */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 32px);
        max-height: 70vh;
        bottom: 72px;
        right: -8px;
    }

    .rtl .chat-window {
        right: auto;
        left: -8px;
    }

    .chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .rtl .chat-widget {
        right: auto;
        left: 16px;
    }
}
