/* ── Variables ── */
:root {
    --sidebar-width: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(99, 102, 241, 0.2);
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: rgba(99, 102, 241, 0.1);
    --surface: #ffffff;
    --surface-secondary: #f8fafc;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #6b7280;
    --radius: 0.75rem;
    --radius-sm: 0.5rem;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Skip Link ── */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    z-index: 9999;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
}

/* ── Base ── */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--surface-secondary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

a { color: var(--accent); transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 0.75rem;
}

.sidebar-brand h5 {
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    margin: 0;
}

.sidebar-brand small {
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

.sidebar .nav-link {
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    margin: 1px 0.65rem;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.875rem;
    font-weight: 450;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sidebar .nav-link i {
    font-size: 1.05rem;
    opacity: 0.7;
}

.sidebar .nav-link:hover {
    background-color: var(--sidebar-hover);
    color: #fff;
}

.sidebar .nav-link:hover i { opacity: 1; }

.sidebar .nav-link.active {
    background-color: var(--sidebar-active);
    color: #fff;
}

.sidebar .nav-link.active i { opacity: 1; color: var(--accent); }

.sidebar .nav-link .badge {
    font-size: 0.65rem;
    padding: 0.2em 0.55em;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.12) !important;
}

.sidebar-stats {
    padding: 0 1.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.8;
}

.sidebar-stats i { margin-right: 0.25rem; opacity: 0.6; }

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-footer .dropdown-toggle {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color var(--transition);
}

.sidebar-footer .dropdown-toggle:hover { color: #fff; }

.sidebar-footer .dropdown-menu {
    background: var(--sidebar-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

.sidebar-footer .dropdown-item {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    transition: all var(--transition);
}

.sidebar-footer .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

/* Language switcher (shared partial) */
.lang-switcher-toggle { color: rgba(255, 255, 255, 0.7); font-size: 0.82rem; text-decoration: none; }
.lang-switcher-toggle:hover { color: #fff; }

/* ── Page Layout ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.75rem;
}

.page-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.15rem;
}

.page-header p {
    color: var(--text-secondary);
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* ── Cards ── */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--surface);
    transition: box-shadow var(--transition), transform var(--transition);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.card-body { padding: 1.25rem; }
.card-footer { background: transparent; border-top: 1px solid var(--border); }

/* Stat Cards */
.stat-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    margin-bottom: 0.85rem;
}

.stat-card .stat-icon.purple { background: rgba(99, 102, 241, 0.1); color: #6366f1; }
.stat-card .stat-icon.green { background: rgba(34, 197, 94, 0.1); color: #16a34a; }
.stat-card .stat-icon.blue { background: rgba(59, 130, 246, 0.1); color: #2563eb; }
.stat-card .stat-icon.amber { background: rgba(245, 158, 11, 0.1); color: #d97706; }

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Collection Cards */
.card-collection {
    cursor: pointer;
    border: 1px solid var(--border);
}

.card-collection:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(99, 102, 241, 0.3);
}

.card-collection .card-title {
    font-size: 1rem;
    font-weight: 600;
}

.card-collection .card-text {
    font-size: 0.85rem;
    line-height: 1.5;
}

.card-collection .card-footer {
    font-size: 0.78rem;
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
}

.card-collection .collection-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.card-collection .collection-meta i { opacity: 0.6; }

/* ── Tables ── */
.table {
    font-size: 0.875rem;
}

.table thead th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    border-bottom-width: 1px;
    padding: 0.85rem 1rem;
}

.table tbody td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    color: var(--text-primary);
}

.table-hover tbody tr:hover { background-color: var(--surface-secondary); }
.table tbody tr { transition: background-color var(--transition); }

/* ── Badges ── */
.badge {
    font-weight: 500;
    font-size: 0.72rem;
    padding: 0.3em 0.65em;
    border-radius: 6px;
    letter-spacing: 0.01em;
}

/* Document status and source badges now use Bootstrap bg-* classes */

/* ── Buttons ── */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    transition: all var(--transition);
}

.btn-primary {
    background-color: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

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

.btn-outline-secondary:hover {
    background-color: var(--surface-secondary);
    border-color: #cbd5e1;
    color: var(--text-primary);
}

.btn-outline-danger {
    border-color: #fecaca;
    color: #dc2626;
}

.btn-outline-danger:hover {
    background-color: #fef2f2;
    border-color: #fca5a5;
    color: #b91c1c;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ── Forms ── */
.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    font-size: 0.875rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

/* ── Upload Zone ── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--surface);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-zone i {
    color: var(--text-muted);
    transition: color var(--transition);
}

.upload-zone:hover i { color: var(--accent); }

.upload-zone p { color: var(--text-secondary); }

/* ── Search Results ── */
.search-result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 1.15rem 1.25rem;
    margin-bottom: 0.75rem;
    transition: all var(--transition);
}

.search-result:hover {
    box-shadow: var(--shadow);
    border-left-color: var(--accent-hover);
}

.search-result h6 {
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
}

.search-score {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    background: var(--surface-secondary);
    padding: 0.2em 0.6em;
    border-radius: 4px;
    white-space: nowrap;
}

/* ── Alerts ── */
.alert {
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    border: none;
    padding: 0.85rem 1.15rem;
}

.alert-success { background: #dcfce7; color: #166534; }
.alert-danger { background: #fef2f2; color: #991b1b; }
.alert-warning { background: #fef9c3; color: #854d0e; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ── List Groups ── */
.list-group-item {
    border-color: var(--border);
    padding: 0.85rem 1.25rem;
    transition: background-color var(--transition);
    font-size: 0.875rem;
}

.list-group-item-action:hover {
    background-color: var(--surface-secondary);
}

/* ── Breadcrumbs ── */
.breadcrumb {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.breadcrumb-item a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb-item a:hover { color: var(--accent); }
.breadcrumb-item.active { color: var(--text-muted); }

/* ── Document Detail ── */
.doc-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.doc-meta i { opacity: 0.6; }

.doc-tags .badge {
    font-size: 0.75rem;
    font-weight: 450;
    padding: 0.35em 0.7em;
}

.chunk-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    transition: background-color var(--transition);
}

.chunk-item:last-child { border-bottom: none; }
.chunk-item:hover { background-color: var(--surface-secondary); }

.chunk-item .chunk-index {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.chunk-item .chunk-model {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.extracted-text {
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-secondary);
    background: var(--surface-secondary);
    padding: 1.25rem;
    border-radius: var(--radius-sm);
    margin: 0;
}

/* ── Empty States ── */
.empty-state {
    text-align: center;
    padding: 3.5rem 1rem;
}

.empty-state i {
    font-size: 3rem;
    color: var(--border);
    margin-bottom: 1rem;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

/* ── Auth Pages ── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
    padding: 2rem;
}

.auth-card {
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.auth-card .auth-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-card .auth-brand h3 {
    font-weight: 700;
    font-size: 1.4rem;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.auth-card .auth-brand p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

.auth-card .auth-links {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.85rem;
}

.auth-card .auth-links a {
    color: var(--text-secondary);
    text-decoration: none;
}

.auth-card .auth-links a:hover { color: var(--accent); }

/* ── Delete Confirm ── */
.delete-card {
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    background: #fff;
}

.delete-card .card-body { padding: 1.5rem; }

.delete-card .delete-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fef2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #dc2626;
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease-out; }

/* ── Responsive ── */
@media (max-width: 991px) {
    .page-header {
        flex-direction: column;
        gap: 1rem;
    }
    .page-header .btn {
        align-self: flex-start;
    }
}

.mobile-topbar {
    display: none;
    background: var(--sidebar-bg);
    padding: 0.75rem 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1040;
}
.mobile-topbar .brand { color: #fff; font-weight: 700; font-size: 1rem; text-decoration: none; }
.mobile-topbar .brand i { color: var(--accent); }
.mobile-topbar .btn-toggle {
    background: none; border: none; color: #fff; font-size: 1.25rem; padding: 0.25rem 0.5rem; cursor: pointer;
}
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1049;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 768px) {
    .mobile-topbar { display: flex; }
    .sidebar {
        position: fixed;
        top: 0; left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1050;
        transition: left 0.25s ease;
    }
    .sidebar.open { left: 0; }
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    .card-collection .card-title {
        font-size: 0.95rem;
    }
    .card-collection .collection-meta {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* ── Auth Helpers ── */
.auth-back-link {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 1.25rem;
    transition: color var(--transition);
}
.auth-back-link:hover { color: var(--accent); }
.auth-back-link i { margin-right: 0.2rem; }

.auth-card--centered { text-align: center; }
.auth-card--wide { max-width: 460px; }

.auth-separator { color: var(--border); }

.auth-messages {
    text-align: left;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
.auth-messages .btn-close { font-size: 0.7rem; }

/* ── Sidebar Helpers ── */
.sidebar-org-logo { max-height: 32px; border-radius: 4px; margin-bottom: 0.25rem; }
.sidebar-divider { border-color: rgba(255,255,255,0.06); margin: 0.75rem 1.25rem; }
.sidebar-lang-wrapper { padding: 0 1.25rem; }
.sidebar-footer .dropdown-divider { border-color: rgba(255,255,255,0.06); }

/* ── Organization ── */
.org-logo-preview { max-height: 48px; border-radius: 4px; }

/* ── Code Blocks ── */
.code-block-wrap { white-space: pre-wrap; }

/* ── Badge Variants ── */
.badge-sm { font-size: 0.65rem; vertical-align: middle; }
.badge-tag { background: var(--accent-light); color: var(--accent); }

/* ── Onboarding / Welcome ── */
.onboarding-wrapper { max-width: 680px; margin: 0 auto; padding: 2rem 0; }
.onboarding-header { text-align: center; margin-bottom: 2.5rem; }
.onboarding-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.onboarding-subtitle { color: var(--text-secondary); font-size: 0.95rem; }

.onboarding-steps { display: grid; gap: 1rem; margin-bottom: 2.5rem; }
.onboarding-step {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.onboarding-step-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.onboarding-step-number.purple { background: rgba(99, 102, 241, 0.1); color: #6366f1; }
.onboarding-step-number.green { background: rgba(22, 163, 74, 0.1); color: #16a34a; }
.onboarding-step-number.blue { background: rgba(37, 99, 235, 0.1); color: #2563eb; }

.onboarding-step-title { font-weight: 600; margin-bottom: 0.25rem; }
.onboarding-step-desc { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }

.onboarding-actions { display: flex; gap: 0.75rem; justify-content: center; }
.onboarding-actions .btn { padding: 0.6rem 1.5rem; }

.onboarding-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.onboarding-footer p { font-size: 0.85rem; color: var(--text-secondary); margin: 0; }
.onboarding-footer i { margin-right: 0.25rem; }
.onboarding-footer a { color: #6366f1; text-decoration: none; font-weight: 500; }

/* ── Status Icon (confirmation pages) ── */
.status-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
}
.status-icon--success { background: rgba(22, 163, 74, 0.1); }
.status-icon--success i { font-size: 1.5rem; color: #16a34a; }
.status-icon--accent { background: rgba(99, 102, 241, 0.1); }
.status-icon--accent i { font-size: 1.75rem; color: #6366f1; }

/* ── Info Box ── */
.info-box {
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: left;
}
.info-box-title { font-size: 0.78rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; }
.info-box ol { font-size: 0.82rem; color: var(--text-secondary); margin: 0; padding-left: 1.25rem; line-height: 1.7; }

/* ── Upload Zone Helpers ── */
.upload-zone .upload-icon { font-size: 2.5rem; }
.upload-zone .file-name { color: var(--accent); }

/* ── Text Utilities ── */
.text-desc { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }
.text-hint { font-size: 0.78rem; color: var(--text-muted); }
.text-subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }
.confirm-text { font-size: 0.9rem; }
.chunk-content { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }

/* ── Misc Component Helpers ── */
.icon-empty-sm { font-size: 1.5rem; color: var(--text-muted); }
.icon-empty-lg { font-size: 2rem; color: var(--text-muted); }
.progress-thin { height: 8px; }
.cell-truncate { max-width: 200px; }
.key-display { word-break: break-all; font-size: 0.85rem; }
.alert-compact { font-size: 0.85rem; }
.border-separator { border-color: rgba(255,255,255,0.06) !important; }
