.chat-container {
    display: flex;
    height: calc(100vh - 100px);
    max-height: 800px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    margin: 1rem;
    border: 1px solid rgba(13, 32, 53, 0.1);
}

.chat-sidebar {
    width: 300px;
    border-left: 2px solid rgba(27, 77, 108, 0.12);
    background: linear-gradient(180deg, #e7ece8 0%, #eef4ee 45%, #f8faf8 100%);
    overflow-y: auto;
    position: relative;
}

.sidebar-header {
    padding: 1.75rem 1.5rem;
    border-bottom: none;
    background: linear-gradient(160deg, #0D2035 0%, #1B4D6C 55%, #2B6B63 100%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.1rem;
    border-radius: 0;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
    position: relative;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 3px;
    border-radius: 3px;
    background: linear-gradient(90deg, transparent, rgba(139, 158, 126, 0.5), rgba(139, 158, 126, 0.6), rgba(139, 158, 126, 0.5), transparent);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.05rem;
    color: white;
    font-weight: 700;
    flex: 0;
}

.sidebar-header .btn {
    width: 100%;
    justify-content: center;
    border-radius: 8px;
    padding: 0.7rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(27, 77, 108, 0.35);
    background: linear-gradient(135deg, #1B4D6C 0%, #2A6B8C 50%, #3A7B9A 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.sidebar-header .btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 24px rgba(27, 77, 108, 0.55);
    background: linear-gradient(135deg, #16455F 0%, #2A6B8C 50%, #3A7B9A 100%) !important;
}

.conversations-list {
    padding: 0.5rem;
}

.conversation-item {
    padding: 0.75rem;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border: 1px solid rgba(27, 77, 108, 0.06);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
    background: transparent;
}

.conversation-item:hover {
    background-color: rgba(27, 77, 108, 0.06);
    border-color: rgba(27, 77, 108, 0.15);
    box-shadow: 0 2px 8px rgba(27, 77, 108, 0.08);
}

.conversation-item:hover .conversation-delete-btn {
    opacity: 1;
    left: 0.5rem;
}

.conversation-item.active {
    background: linear-gradient(135deg, #1B4D6C 0%, #2E7066 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 20px rgba(27, 77, 108, 0.3);
    transform: translateX(1px);
}

.conversation-item.active .text-muted {
    color: rgba(255, 255, 255, 0.9) !important;
}

.conversation-delete-btn {
    position: absolute;
    top: 0.75rem;
    left: -2rem;
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    opacity: 0;
    transition: all 0.3s ease;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-delete-btn:hover {
    color: #c82333;
    transform: scale(1.2);
}

.conversation-item.active .conversation-delete-btn {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-item.active .conversation-delete-btn:hover {
    color: white;
}

.conversation-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.conversation-preview {
    font-size: 0.875rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.25rem;
}

.no-conversations {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #8899aa;
    font-size: 0.95rem;
    line-height: 1.7;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 1.75rem 1.5rem;
    border-bottom: none;
    background: linear-gradient(150deg, #0A1A2A 0%, #123750 45%, #2B6B63 100%);
    display: flex;
    justify-content: flex-start;
    align-items: center;
    color: white;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    position: relative;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 5%;
    right: 5%;
    height: 3px;
    border-radius: 3px;
    background: linear-gradient(90deg, transparent, rgba(139, 158, 126, 0.4), rgba(139, 158, 126, 0.5), rgba(139, 158, 126, 0.4), transparent);
}

.chat-header h4 {
    margin: 0;
    color: white;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo-shell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 247, 244, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 8px;
    padding: 0.3rem 0.55rem;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.header-logo {
    height: 40px;
    width: auto;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 2px rgba(16, 39, 60, 0.28));
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    background: linear-gradient(180deg, #edf3ef 0%, #f4f7f4 40%, #fafcfb 100%);
    position: relative;
}

.message {
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    position: relative;
    z-index: 2;
    /* In RTL, flex 'row' naturally starts from the right */
}

.user-message {
    /* flex-start = right side in RTL */
    justify-content: flex-start;
    padding-left: 15%;
}

.ai-message {
    /* flex-end = left side in RTL */
    justify-content: flex-start;
    padding-left: 2.75rem;
    padding-right: 15%;
}

.message-content {
    max-width: 70%;
    padding: 1rem 1.25rem;
    border-radius: 10px;
    position: relative;
    transition: all 0.3s ease;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--light-blue) 100%);
    color: white;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(27, 77, 108, 0.25);
}

.ai-message .message-content {
    max-width: 100%;
    background-color: white;
    border: 1px solid rgba(13, 32, 53, 0.08);
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.message-text {
    margin-bottom: 0.5rem;
    direction: rtl;
    text-align: right;
}

.message-text:last-child {
    margin-bottom: 0;
}

.message-sources {
    margin-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    padding-top: 0.6rem;
}

.ai-message .message-sources {
    border-top-color: #e9ecef;
}

.sources-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.sources-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.source-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: linear-gradient(135deg, #f0f4f0 0%, #e8f0ea 100%);
    color: #1B4D6C;
    border: 1px solid #b5c3b5;
    padding: 0.3rem 0.7rem;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: default;
    text-decoration: none;
}

.source-tag.source-link {
    cursor: pointer;
}

.source-tag:hover {
    background: linear-gradient(135deg, #1B4D6C 0%, #2A6B8C 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(27, 77, 108, 0.3);
    transform: translateY(-1px);
}

.source-tag i {
    font-size: 0.7rem;
    opacity: 0.8;
}

.user-message .source-tag {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.3);
}

.user-message .sources-label {
    color: rgba(255, 255, 255, 0.75);
}

.user-message .message-sources {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.message-confidence {
    margin-top: 0.25rem;
}

.message-time {
    font-size: 0.75rem;
    color: #6c757d;
    align-self: flex-end;
    margin: 0.25rem;
}

/* Searching / loading bubble */
.searching-message .message-content {
    background: linear-gradient(135deg, #e8f0ec 0%, #f0f7f2 100%) !important;
    border: 1px dashed rgba(27, 77, 108, 0.35) !important;
    box-shadow: 0 2px 10px rgba(27, 77, 108, 0.1) !important;
    padding: 0.65rem 1rem !important;
}

.searching-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    direction: rtl;
    flex-wrap: nowrap;
}

.searching-logo {
    height: 28px;
    width: auto;
    flex-shrink: 0;
    animation: search-pulse 1.5s ease-in-out infinite;
}

@keyframes search-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.85); }
}

.searching-text {
    font-size: 0.88rem;
    color: #4a6080;
    font-style: italic;
    white-space: nowrap;
}

.searching-dots {
    display: flex;
    align-items: center;
    gap: 0.22rem;
    flex-shrink: 0;
}

.searching-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: #1B4D6C;
    animation: typing 1.4s ease-in-out infinite both;
}

.searching-dots span:nth-child(1) { animation-delay: -0.32s; }
.searching-dots span:nth-child(2) { animation-delay: -0.16s; }
.searching-dots span:nth-child(3) { animation-delay: 0s; }

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #6c757d;
    animation: typing 1.4s ease-in-out infinite both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Status badge pulse */
.badge.bg-success {
    position: relative;
    border-radius: 24px;
    padding: 0.4rem 0.85rem;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
    background: linear-gradient(135deg, #1b8a3e 0%, #2eac55 100%) !important;
    box-shadow: 0 2px 10px rgba(40, 167, 69, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.badge.bg-success .fa-circle {
    animation: pulse-dot 2s ease-in-out infinite;
    filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.6));
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.badge.bg-danger {
    border-radius: 24px;
    padding: 0.4rem 0.85rem;
    font-weight: 600;
    font-size: 0.8rem;
    box-shadow: 0 2px 10px rgba(220, 53, 69, 0.3);
}

.chat-input {
    padding: 1rem 1.25rem 1.25rem;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, #ffffff 100%);
    border-top: none;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
    backdrop-filter: blur(8px);
}

.disclaimer-footer {
    padding: 0.55rem 1.25rem;
    background-color: #edf3ef;
    border-top: 2px solid #1B4D6C;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.74rem;
    color: #2d4a5e;
    line-height: 1.55;
    text-align: right;
    direction: rtl;
    flex-shrink: 0;
}

.disclaimer-footer i {
    color: #1B4D6C;
    font-size: 0.78rem;
    margin-top: 0.15rem;
    flex-shrink: 0;
}

.chat-input-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
}

.chat-input-form .form-control {
    flex: 1;
    direction: rtl;
    text-align: right;
    border-radius: 8px !important;
    border: 2px solid #e2e8f0 !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0.85rem 1.1rem;
    resize: none;
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    background-color: #f8faff;
}

.chat-input-form .form-control:focus {
    border-color: var(--primary-blue) !important;
    box-shadow: 0 0 0 3px rgba(27, 77, 108, 0.12) !important;
    background-color: white;
    outline: none;
}

.send-btn {
    width: 52px !important;
    height: 52px !important;
    min-width: 52px;
    border-radius: 10px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0;
    font-size: 1.1rem;
    box-shadow: 0 4px 14px rgba(27, 77, 108, 0.35) !important;
    transition: all 0.25s ease !important;
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--light-blue) 100%) !important;
    border: none !important;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(27, 77, 108, 0.5) !important;
}

.send-btn:disabled {
    opacity: 0.5;
    transform: none;
}

.send-btn i {
    transform: rotate(-45deg);
}

.welcome-message {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    pointer-events: none;
    z-index: 1;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 220ms ease, transform 220ms ease;
}

.chat-messages.has-messages .welcome-message {
    opacity: 0;
    transform: translateY(-10px);
}

.welcome-card {
    text-align: center;
    max-width: 420px;
    padding: 2.5rem 2rem;
    background: linear-gradient(180deg, #ffffff 0%, #f7faf7 100%);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(13, 32, 53, 0.12);
    border: 1px solid #d8e3d8;
}

.welcome-logo {
    height: 110px;
    width: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto 1.25rem;
}

.welcome-card h5 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.6rem;
}

.welcome-card p {
    color: #6c757d;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.welcome-hints {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.hint-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: #f3f5f1;
    color: var(--primary-blue);
    border: 1px solid #d5ddd5;
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
}

.alert-sm {
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    border-radius: 12px;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.alert-danger {
    background-color: #fce4ec;
    color: #d63031;
}

/* Feedback buttons */
.message-feedback {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #dee2e6;
}

.ai-message .message-feedback {
    border-top-color: #e9ecef;
}

.btn-feedback {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    font-size: 0.9rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.btn-feedback:hover {
    background-color: #f0f0f0;
    color: #495057;
    transform: scale(1.1);
}

.btn-feedback.active {
    background-color: #eef2ff;
    color: #1d4ed8;
    box-shadow: 0 2px 8px rgba(29, 78, 216, 0.2);
}

.btn-feedback.btn-like {
    color: #6c757d;
}

.btn-feedback.btn-like.active {
    color: #28a745;
    background-color: #f0f8f0;
}

.btn-feedback.btn-like:hover {
    color: #28a745;
    background-color: #f0f8f0;
}

.btn-feedback.btn-dislike {
    color: #6c757d;
}

.btn-feedback.btn-dislike.active {
    color: #dc3545;
    background-color: #f8f0f0;
}

.btn-feedback.btn-dislike:hover {
    color: #dc3545;
    background-color: #f8f0f0;
}

@media (max-width: 768px) {
    .chat-container {
        border-radius: 10px;
        margin: 0.5rem;
        height: calc(100vh - 120px);
    }
    
    .chat-sidebar {
        width: 220px;
    }
    
    .message-content {
        max-width: 85%;
    }

    .header-logo {
        height: 30px;
    }

    .header-logo-shell {
        padding: 0.25rem 0.45rem;
        border-radius: 12px;
    }

    .searching-logo {
        height: 22px;
    }

    .welcome-logo {
        height: 92px;
    }
}