/* ═══════════════════════════════════════════════════════════
   Design System — Chatbot RAG CEPJ/CTPS
   Mode Clair Moderne · Institutionnel · Glassmorphism
   ═══════════════════════════════════════════════════════════ */

/* ── Reset & Variables ───────────────────────────────────── */

:root {
    /* Palette Claire */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --surface: #f1f5f9;
    --surface-hover: #e2e8f0;
    --glass-bg: rgba(255, 255, 255, 0.94);
    --glass-border: #e2e8f0;
    --glass-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);

    /* Accent — Bleu Républicain & Éducation / UNSA */
    --accent: #1d4ed8;
    --accent-hover: #1e40af;
    --accent-glow: rgba(29, 78, 216, 0.2);
    --accent-subtle: #eff6ff;

    /* Sémantique */
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
    --info: #0284c7;

    /* Texte contrasté */
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    /* Typographie */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

    /* Espacements */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
}

/* ── Glass Effect ────────────────────────────────────────── */

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* ── Screens ─────────────────────────────────────────────── */

#login-screen,
#chat-screen {
    width: 100%;
    height: 100vh;
    display: none;
}

#login-screen.active {
    display: flex;
}

#chat-screen.active {
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

/* ── Login Screen ────────────────────────────────────────── */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 50% 10%, #eff6ff 0%, #f8fafc 60%, #e2e8f0 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 48px 40px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
    border-radius: var(--radius-xl);
    animation: fadeInUp 0.6s ease-out;
}

.login-header {
    text-align: center;
    margin-bottom: 36px;
}

.logo-badge {
    width: 64px;
    height: 64px;
    max-width: 64px;
    max-height: 64px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 160, 227, 0.18);
    border: 2px solid #e2e8f0;
    overflow: hidden;
    padding: 3px;
    flex-shrink: 0;
}

.brand-logo-img {
    width: 54px;
    height: 54px;
    max-width: 54px;
    max-height: 54px;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.login-header .subtitle {
    font-size: 1rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 4px;
}

.login-header .org {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ── Form Elements ───────────────────────────────────────── */

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.error-msg {
    color: var(--error);
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 12px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.1);
}

.hidden {
    display: none !important;
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    color: #fff;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    line-height: 1;
}

.btn-icon:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.login-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 24px;
}



/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
    width: 280px;
    min-width: 280px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--glass-border);
    border-radius: 0;
    transition: var(--transition-slow);
    z-index: 100;
}

.sidebar.collapsed {
    margin-left: -280px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo-img {
    width: 26px;
    height: 26px;
    max-width: 26px;
    max-height: 26px;
    min-width: 26px;
    min-height: 26px;
    border-radius: 50%;
    object-fit: contain;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.logo-icon-sm {
    font-size: 1.3rem;
}

.sidebar-title {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.sidebar-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.sidebar-btn.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    font-size: 1.2rem;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ── Chat Main ───────────────────────────────────────────── */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

/* ── Chat Header ─────────────────────────────────────────── */

.chat-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--glass-border);
    border-radius: 0;
    flex-shrink: 0;
}

.header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-info h2 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.header-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    background: var(--accent-subtle);
    color: var(--accent);
    border-radius: 100px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.status-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Messages ────────────────────────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeInUp 0.3s ease-out;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    max-width: 32px;
    max-height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    padding: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.avatar-logo-img {
    width: 26px;
    height: 26px;
    max-width: 26px;
    max-height: 26px;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}

.message.user .message-avatar {
    background: var(--accent-subtle);
    border: none;
    padding: 0;
}

.message-bubble {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    line-height: 1.65;
    font-size: 0.92rem;
}

.message.bot .message-bubble {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    color: var(--text-primary);
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    border: none;
    color: #fff;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.25);
}

.message.bot .message-bubble p {
    margin-bottom: 10px;
}

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

/* ── Typography & Markdown RAG Styling ───────────────────── */

.rag-heading-1,
.rag-heading-2,
.rag-heading-3 {
    color: var(--text-primary);
    font-weight: 700;
    margin: 18px 0 10px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rag-heading-1 {
    font-size: 1.15rem;
    border-bottom: 2px solid var(--accent-subtle);
    padding-bottom: 6px;
}

.rag-heading-2 {
    font-size: 1.05rem;
    color: var(--accent);
}

.rag-heading-3 {
    font-size: 0.98rem;
    color: #1e3a8a;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.rag-paragraph {
    margin-bottom: 12px;
    line-height: 1.7;
    color: #334155;
}

.rag-divider {
    border: none;
    height: 1px;
    background: #e2e8f0;
    margin: 16px 0;
}

.rag-ordered-list,
.rag-bullet-list {
    margin: 10px 0 16px 20px;
    padding-left: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rag-ordered-list {
    list-style-type: decimal;
}

.rag-bullet-list {
    list-style-type: disc;
}

.rag-ordered-list li,
.rag-bullet-list li {
    line-height: 1.6;
    color: #334155;
}

.rag-ordered-list li strong,
.rag-bullet-list li strong {
    color: var(--text-primary);
}

.rag-blockquote {
    margin: 12px 0;
    padding: 10px 16px;
    background: #f1f5f9;
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    color: #475569;
    font-size: 0.9rem;
    line-height: 1.6;
}

.rag-callout {
    margin: 14px 0;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.6;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.rag-callout-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.rag-callout-danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.rag-callout-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.rag-citation-box {
    margin: 8px 0;
    padding: 10px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    color: #1e3a8a;
}

.rag-citation-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #eff6ff;
    color: #1d4ed8;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
    border: 1px solid #dbeafe;
}

.rag-inline-cite {
    color: #1d4ed8;
    font-weight: 600;
    background: rgba(29, 78, 216, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
}

.rag-link {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 500;
}

.rag-link:hover {
    color: var(--accent-hover);
}

/* ── Topic Buttons ───────────────────────────────────────── */

.welcome-topics {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.welcome-topics p {
    width: 100%;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px !important;
}

.topic-btn {
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 100px;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    transition: var(--transition);
}

.topic-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

/* ── Disclaimer ──────────────────────────────────────────── */

.disclaimer {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.15);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--warning);
    line-height: 1.5;
}

/* ── Message Meta Header (Confidence + Time) ─────────────── */

.message-meta-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.message-timestamp {
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 500;
}

/* ── Message Actions Bar (Copier, Imprimer) ───────────────── */

.message-actions-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px dashed #e2e8f0;
}

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
}

.msg-action-btn:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: var(--accent);
    transform: translateY(-1px);
}

.msg-action-btn.copied {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}

/* ── Sources Grid & Modern Cards ──────────────────────────── */

.sources-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.sources-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 8px;
}

.source-item-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: var(--transition);
}

.source-item-card:hover {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.source-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}

.source-type-pill {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    background: #e2e8f0;
    color: #334155;
    padding: 1px 6px;
    border-radius: 4px;
}

.source-item-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.35;
}

.source-item-article {
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 500;
}

.source-link-btn {
    margin-top: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    align-self: flex-start;
}

.source-link-btn:hover {
    text-decoration: underline;
}

.source-score {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 100px;
}

.score-high {
    background: #dcfce7;
    color: #15803d;
}

.score-medium {
    background: #fef3c7;
    color: #b45309;
}

.score-low {
    background: #fee2e2;
    color: #b91c1c;
}

/* ── Confidence Badge ────────────────────────────────────── */

.confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.confidence-high {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.confidence-medium {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.confidence-low {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ── Typing Indicator ────────────────────────────────────── */

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 12px 20px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite;
}

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

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

/* ── Chat Input ──────────────────────────────────────────── */

.chat-input-area {
    padding: 16px 24px 24px;
    flex-shrink: 0;
}

.chat-form {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
    padding: 4px;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 4px 4px 4px 16px;
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    padding: 10px 0;
    max-height: 120px;
    min-height: 40px;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    padding: 4px 16px 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Corpus Panel & Source Management ───────────────────── */

.corpus-panel {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    animation: fadeIn 0.2s ease-out;
}

.corpus-modal {
    width: 92%;
    max-width: 850px;
    height: 85vh;
    max-height: 720px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    animation: fadeInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
    overflow: hidden;
}

.corpus-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--glass-border);
    background: #ffffff;
}

.corpus-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.corpus-title-group h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Tabs */
.corpus-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 24px;
    border-bottom: 1px solid var(--glass-border);
    background: #f1f5f9;
    overflow-x: auto;
}

.corpus-tab-btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.corpus-tab-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.corpus-tab-btn.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(29, 78, 216, 0.25);
}

/* Tab panes */
.corpus-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: #f8fafc;
}

.tab-pane {
    display: none;
    height: 100%;
}

.tab-pane.active {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Toolbar */
.corpus-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.input-search {
    flex: 1;
    max-width: 320px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-md);
    padding: 8px 14px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition);
}

.input-search:focus {
    border-color: var(--accent);
}

.corpus-list-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 480px;
    padding-right: 4px;
}

/* Corpus items */
.corpus-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    transition: var(--transition);
}

.corpus-item:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.corpus-item-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

.corpus-item-info {
    flex: 1;
    min-width: 0;
}

.corpus-item-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.3;
}

.corpus-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.tag-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--surface-hover);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
}

.tag-cepj {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
}

.tag-ctps {
    background: rgba(168, 85, 247, 0.15);
    color: #c084fc;
    border-color: rgba(168, 85, 247, 0.3);
}

.corpus-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.corpus-item-badge {
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--accent-subtle);
    color: var(--accent);
}

.btn-delete-source {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-delete-source:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
}

/* Forms inside modal */
/* URL mode selector */
.url-mode-selector {
    display: flex;
    gap: 12px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: var(--transition);
}

.radio-label:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.radio-label input[type="radio"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.corpus-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.flex-1 { flex: 1; }
.form-group.flex-2 { flex: 2; }

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.corpus-form input[type="text"],
.corpus-form input[type="url"],
.corpus-form input[type="date"],
.corpus-form select,
.corpus-form textarea {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition);
}

.corpus-form input:focus,
.corpus-form select:focus,
.corpus-form textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.corpus-form select {
    cursor: pointer;
}

.corpus-form textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.5;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed rgba(29, 78, 216, 0.35);
    border-radius: var(--radius-lg);
    background: rgba(29, 78, 216, 0.03);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(29, 78, 216, 0.08);
}

.drop-icon {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 8px;
}

.drop-text {
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.drop-browse {
    color: var(--accent);
    text-decoration: underline;
    font-weight: 600;
}

.drop-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

.file-preview {
    margin-top: 12px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--surface-hover);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 600;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

/* ── Animations ──────────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 150;
        width: 280px;
    }

    .sidebar.collapsed {
        margin-left: -280px;
    }

    .message {
        max-width: 95%;
    }

    .login-card {
        padding: 32px 24px;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 12px 16px 16px;
    }

    .header-info h2 {
        font-size: 0.85rem;
    }

    .welcome-topics {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .header-badge,
    .header-actions {
        display: none;
    }
}
