/* chat.css — Scoped chat modal styles */

/* ================================================================
   OVERLAY & MODAL CONTAINER
   ================================================================ */
.chat-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chat-modal-overlay.active {
    display: flex;
    opacity: 1;
}

.chat-container {
    width: 90%;
    max-width: 500px;
    height: 80vh;
    max-height: 700px;
    background: #ffffff;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    /* IMPORTANT: The container is always LTR for layout positioning.
       Individual message bubbles handle their own text direction. */
    direction: ltr;
}

.chat-modal-overlay.active .chat-container {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .chat-container {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
}

/* ================================================================
   HEADER
   ================================================================ */
.chat-header {
    padding: 14px 18px;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
    /* Header text references Arabic labels — keep rtl here only for the text */
    direction: rtl;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-title {
    font-weight: 700;
    font-size: 1rem;
}

.chat-header-subtitle {
    font-size: 0.75rem;
    color: #94a3b8;
    font-family: 'Roboto Mono', monospace;
    direction: ltr;
}

.chat-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 50%;
    line-height: 1;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 36px;
    min-height: 36px;
}

/* .chat-close-btn svg, .chat-close-btn box-icon {
    fill: currentColor;
    color: inherit;
} */

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* ================================================================
   MESSAGES AREA
   ================================================================ */
.chat-messages-area {
    flex: 1;
    padding: 20px 16px;
    overflow-y: auto;
    background: rgba(91, 59, 176, 0.03); /* Subtle primary tint to break pure white */
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Always LTR so flex-end/flex-start mean right/left consistently */
    direction: ltr !important;
}

/* ================================================================
   MESSAGE WRAPPERS — Two-sided layout
   ================================================================ */
.chat-message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    width: fit-content;
    margin-bottom: 8px;
}

.chat-msg-right {
    align-self: flex-end !important;
    margin-left: auto !important;
    margin-right: 0 !important;
    align-items: flex-end !important;
}

.chat-msg-left {
    align-self: flex-start !important;
    margin-right: auto !important;
    margin-left: 0 !important;
    align-items: flex-start !important;
}

.chat-message-bubble {
    padding: 12px 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
    border-radius: 18px;
}

.chat-bubble-user {
    background: #5b3bb0 !important;
    color: #ffffff !important;
    border: 1px solid #4a2f91 !important;
}

.chat-bubble-support {
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid #e2e8f0 !important;
}

.chat-msg-right .chat-message-bubble {
    border-bottom-right-radius: 4px;
}
.chat-msg-left .chat-message-bubble {
    border-bottom-left-radius: 4px;
}
/* ================================================================
   MESSAGE FOOTER (timestamp + checkmarks)
   ================================================================ */
.chat-message-footer {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    font-size: 0.68rem;
    color: #94a3b8;
    /* LTR so the time and checkmarks always read left-to-right */
    direction: ltr;
}

.chat-msg-right .chat-message-footer {
    justify-content: flex-end;
}

.chat-msg-left .chat-message-footer {
    justify-content: flex-start;
}

/* ================================================================
   CHECKMARKS
   ================================================================ */
.chat-checkmarks {
    display: inline-flex;
    align-items: center;
    font-size: 0.78rem;
    color: #94a3b8;
}

/* Double checkmark — read confirmation */
.chat-check-double {
    color: #4ade80;
    font-size: 0.78rem;
    letter-spacing: -3px; /* bring the two ✓✓ symbols closer together */
}

/* ================================================================
   INPUT AREA
   ================================================================ */
.chat-input-area {
    background: #ffffff;
    padding: 14px 18px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-shrink: 0;
    direction: rtl;
    box-shadow: 0 -4px 12px -4px rgba(0,0,0,0.02);
}

.chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 12px 18px;
    max-height: 120px;
    min-height: 48px;
    overflow-y: auto;
    font-family: inherit;
    resize: none;
    outline: none;
    font-size: 0.95rem;
    transition: all 0.2s;
    background: #f8fafc;
    color: #0f172a;
    line-height: 1.4;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.chat-input:focus {
    border-color: #cbd5e1;
    background: #ffffff;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02), 0 0 0 3px rgba(91, 59, 176, 0.1);
}

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #5b3bb0;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.18s, transform 0.15s;
    flex-shrink: 0;
}

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

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.93);
}

.chat-send-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.chat-send-btn svg, .chat-send-btn box-icon {
    display: block;
    fill: currentColor;
    color: inherit;
}

/* ================================================================
   EMPTY / LOADING / ERROR STATES
   ================================================================ */
.chat-empty-state,
.chat-loading-state,
.chat-error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #64748b;
    text-align: center;
    gap: 10px;
    font-size: 0.95rem;
    padding: 20px;
    margin: auto;
    /* center vertically inside the messages flex col */
    align-self: center;
}

/* Loading spinner (pure CSS — no icon library needed) */
.chat-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #5b3bb0;
    border-radius: 50%;
    animation: chat-spin 0.8s linear infinite;
}

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

/* ================================================================
   UNREAD BADGE
   ================================================================ */
.chat-unread-badge {
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 9px;
    vertical-align: middle;
    font-family: monospace;
}

/* ================================================================
   CHAT TRIGGER BUTTON (on exchange page / history page)
   ================================================================ */
.chat-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #5b3bb0;
    color: white;
    padding: 8px 16px;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.9rem;
    font-family: 'Cairo', sans-serif;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.chat-trigger-btn:hover {
    background: #4c1d95;
    color: white;
}

.chat-trigger-indicator {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.68rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}
