:root {
    --rb-body-bg: #f8f9fa;
    --rb-body-color: #212529;
    --rb-card-bg: #ffffff;
    --rb-card-shadow: 0 2px 4px rgba(0,0,0,0.1);
    --rb-border-color: #dee2e6;
    --rb-text-muted: #6c757d;
    --rb-sidebar-width: 340px;
}

[data-bs-theme="dark"] {
    --rb-body-bg: #212529;
    --rb-body-color: #f8f9fa;
    --rb-card-bg: #2b3035;
    --rb-card-shadow: 0 2px 4px rgba(0,0,0,0.3);
    --rb-border-color: #495057;
    --rb-text-muted: #adb5bd;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1040;
}

.sidebar-overlay-active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--rb-sidebar-width);
    height: 100vh;
    background: var(--rb-card-bg);
    border-left: 1px solid var(--rb-border-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 1050;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--rb-border-color);
    background: var(--rb-card-bg);
}

.sidebar-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    opacity: 0.5;
    padding: 0;
    line-height: 1;
}

.sidebar-close:hover {
    opacity: 1;
}

.sidebar-nav {
    display: flex;
    border-bottom: 1px solid var(--rb-border-color);
    background: var(--rb-card-bg);
}

.sidebar-nav-btn {
    flex: 1;
    border: none;
    background: none;
    padding: 0.75rem 0.5rem;
    font-size: 0.8rem;
    color: var(--rb-text-muted);
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.sidebar-nav-btn i {
    display: block;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.sidebar-nav-btn:hover {
    color: var(--rb-body-color);
}

.sidebar-nav-btn.active {
    color: #0d6efd;
    border-bottom-color: #0d6efd;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
}

.sidebar-tab {
    display: none;
    padding: 1rem;
}

.sidebar-tab.active {
    display: block;
}

.sidebar-section-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--rb-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-doc-item {
    background: var(--rb-body-bg);
    border: 1px solid var(--rb-border-color);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    transition: border-color 0.2s;
}

.sidebar-doc-item:hover {
    border-color: #0d6efd;
}

.sidebar-doc-title {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.btn-xs {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    line-height: 1.2;
}

body {
    background-color: var(--rb-body-bg);
    color: var(--rb-body-color);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.card {
    background-color: var(--rb-card-bg);
    box-shadow: var(--rb-card-shadow);
    border: 1px solid var(--rb-border-color);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.card-body h3 {
    margin-bottom: 0;
}

.table {
    color: var(--rb-body-color);
}

.table th {
    font-size: 0.9rem;
    border-color: var(--rb-border-color);
}

.table td {
    border-color: var(--rb-border-color);
}

.text-muted {
    color: var(--rb-text-muted) !important;
}

.bg-light {
    background-color: var(--rb-card-bg) !important;
}

footer {
    background-color: var(--rb-card-bg) !important;
    border-top: 1px solid var(--rb-border-color);
}

.btn-outline-secondary {
    color: var(--rb-body-color);
    border-color: var(--rb-border-color);
}

.btn-outline-secondary:hover {
    background-color: var(--rb-border-color);
    color: var(--rb-body-color);
}

.navbar-brand small {
    color: var(--rb-text-muted);
}

[data-bs-theme="dark"] .navbar.bg-dark {
    background-color: #1a1d20 !important;
}

[data-bs-theme="dark"] .table-hover tbody tr:hover {
    background-color: rgba(255,255,255,0.04);
}

.chat-container {
    height: calc(100vh - 200px);
    min-height: 400px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble-user {
    background-color: var(--rb-chat-user-bg, #0d6efd);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
}

.chat-bubble-bot {
    background-color: var(--rb-chat-bot-bg, #e9ecef);
    color: var(--rb-body-color);
    margin-right: auto;
    border-bottom-left-radius: 0.25rem;
}

.chat-bubble-time {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 0.25rem;
    text-align: right;
}

.chat-bubble-user .chat-bubble-time {
    color: rgba(255,255,255,0.8);
}

.chat-bubble-bot .chat-bubble-time {
    color: var(--rb-text-muted);
}

.chat-bubble p {
    margin-bottom: 0.5rem;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble ul, .chat-bubble ol {
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
}

.chat-bubble code {
    background-color: rgba(0,0,0,0.1);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

[data-bs-theme="dark"] .chat-bubble-bot code {
    background-color: rgba(255,255,255,0.1);
}

.chat-bubble pre {
    background-color: rgba(0,0,0,0.1);
    padding: 0.5rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

[data-bs-theme="dark"] .chat-bubble-bot pre {
    background-color: rgba(255,255,255,0.1);
}

.chat-sources {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--rb-border-color);
}

.chat-source-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: rgba(0,0,0,0.03);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}

[data-bs-theme="dark"] .chat-source-item {
    background-color: rgba(255,255,255,0.05);
}

.chat-source-badge {
    background-color: var(--rb-primary, #0d6efd);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    white-space: nowrap;
}

.chat-source-text {
    flex: 1;
    color: var(--rb-text-muted);
    line-height: 1.4;
}

.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--rb-border-color);
    background-color: var(--rb-card-bg);
}

.chat-textarea {
    resize: none;
    border-radius: 1.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--rb-border-color);
    background-color: var(--rb-body-bg);
    color: var(--rb-body-color);
    min-height: 48px;
    max-height: 150px;
}

.chat-textarea:focus {
    border-color: var(--rb-primary, #0d6efd);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.chat-btn-send {
    border-radius: 50%;
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-btn-cancel {
    border-radius: 1.5rem;
    padding: 0.5rem 1rem;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: var(--rb-text-muted);
}

.chat-status-dots::after {
    content: '';
    animation: chatDots 1.5s steps(4, end) infinite;
}

@keyframes chatDots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

mark {
    background-color: rgba(13, 110, 253, 0.2);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    cursor: help;
}

[data-bs-theme="dark"] mark {
    background-color: rgba(13, 110, 253, 0.4);
}

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--rb-text-muted);
    text-align: center;
    padding: 2rem;
}

.chat-empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

[data-bs-theme="dark"] .chat-bubble-bot {
    --rb-chat-bot-bg: #2b3035;
}

[data-bs-theme="dark"] .chat-bubble-user {
    --rb-chat-user-bg: #0d6efd;
}

[data-bs-theme="light"] .chat-bubble-bot {
    --rb-chat-bot-bg: #e9ecef;
}

[data-bs-theme="light"] .chat-bubble-user {
    --rb-chat-user-bg: #0d6efd;
}

.chat-source-card {
    background-color: rgba(0,0,0,0.03);
    border: 1px solid var(--rb-border-color);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
    font-size: 0.8rem;
}

.chat-source-card:hover {
    border-color: var(--rb-primary, #0d6efd);
    transform: translateY(-1px);
}

[data-bs-theme="dark"] .chat-source-card {
    background-color: rgba(255,255,255,0.05);
}

.chat-source-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.chat-source-card-title {
    font-weight: 500;
    color: var(--rb-body-color);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.chat-source-card-score {
    font-size: 0.7rem;
    color: var(--rb-text-muted);
    background-color: rgba(0,0,0,0.05);
    padding: 0.1rem 0.4rem;
    border-radius: 1rem;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.chat-source-card-snippet {
    color: var(--rb-text-muted);
    font-size: 0.75rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.chat-source-card-bar {
    height: 3px;
    background-color: var(--rb-border-color);
    border-radius: 2px;
    margin-top: 0.4rem;
    overflow: hidden;
}

.chat-source-card-bar-fill {
    height: 100%;
    background-color: var(--rb-primary, #0d6efd);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.chat-source-modal-title {
    font-size: 1rem;
    font-weight: 600;
    word-break: break-word;
}

.chat-source-modal-meta {
    font-size: 0.75rem;
    color: var(--rb-text-muted);
    margin-bottom: 0.75rem;
}

.chat-source-modal-text {
    background-color: var(--rb-body-bg);
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.source-highlight {
    background-color: rgba(13, 110, 253, 0.2);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.source-highlight:hover {
    background-color: rgba(13, 110, 253, 0.4);
}

[data-bs-theme="dark"] .source-highlight {
    background-color: rgba(13, 110, 253, 0.4);
}

[data-bs-theme="dark"] .source-highlight:hover {
    background-color: rgba(13, 110, 253, 0.6);
}

.drop-zone {
    border: 2px dashed var(--rb-border-color);
    border-radius: 0.75rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--rb-primary, #0d6efd);
    background-color: rgba(13, 110, 253, 0.05);
}

.drop-zone-icon {
    font-size: 2.5rem;
    color: var(--rb-text-muted);
    margin-bottom: 0.75rem;
}

.drop-zone-text {
    color: var(--rb-text-muted);
    font-size: 0.9rem;
}

.drop-zone-text strong {
    color: var(--rb-primary, #0d6efd);
}

[data-bs-theme="dark"] .drop-zone:hover,
[data-bs-theme="dark"] .drop-zone.drag-over {
    background-color: rgba(13, 110, 253, 0.1);
}

.upload-file-input {
    display: none;
}

.upload-preview {
    background-color: var(--rb-body-bg);
    border: 1px solid var(--rb-border-color);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-top: 1rem;
}

.upload-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.upload-preview-name {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.upload-preview-remove {
    background: none;
    border: none;
    color: var(--rb-text-muted);
    font-size: 1.25rem;
    padding: 0;
    line-height: 1;
    cursor: pointer;
}

.upload-preview-remove:hover {
    color: #dc3545;
}

.upload-progress {
    height: 4px;
    background-color: var(--rb-border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.upload-progress-bar {
    height: 100%;
    background-color: var(--rb-primary, #0d6efd);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-error {
    color: #dc3545;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.upload-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.upload-tab-btn {
    border: 1px solid var(--rb-border-color);
    background: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    color: var(--rb-body-color);
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.upload-tab-btn:hover {
    border-color: var(--rb-primary, #0d6efd);
}

.upload-tab-btn.active {
    background-color: var(--rb-primary, #0d6efd);
    color: white;
    border-color: var(--rb-primary, #0d6efd);
}

.upload-tab-content {
    display: none;
}

.upload-tab-content.active {
    display: block;
}

.skeleton-pulse {
    background: linear-gradient(90deg, var(--rb-border-color) 25%, rgba(255,255,255,0.4) 50%, var(--rb-border-color) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
    border-radius: 0.25rem;
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.skeleton-row.right {
    flex-direction: row-reverse;
}

.skeleton-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-bubble {
    height: 48px;
    border-radius: 1rem;
    flex-grow: 1;
    max-width: 70%;
}

.skeleton-line {
    height: 12px;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.chat-skeleton {
    padding: 1rem;
}

.chat-skeleton .skeleton-row {
    margin-bottom: 0.75rem;
}

.chat-skeleton .skeleton-avatar {
    background: var(--rb-border-color);
}

.chat-skeleton .skeleton-bubble {
    background: var(--rb-border-color);
}

.chat-skeleton .skeleton-bubble.short {
    max-width: 40%;
}

.chat-skeleton .skeleton-bubble.medium {
    max-width: 55%;
}

.list-skeleton-row td {
    padding: 0.75rem 0.5rem;
}

.list-skeleton-row .skeleton-line {
    height: 14px;
    width: 80%;
}