/* Knowledge Base UI: sidebar KB list, KB panel form (create tabs, BibTeX upload),
   and modal dialogs (delete confirmation, clear history). */

/* KB Panel */
.kb-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    background: var(--bg-card);
    margin-bottom: 8px;
    font-family: inherit;
    color: var(--text-main);
}
.kb-select:focus {
    border-color: var(--secondary);
}

.kb-info {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
}

.kb-create-toggle {
    font-size: 11px;
    color: var(--secondary);
    cursor: pointer;
    border: none;
    background: none;
    padding: 2px 0;
    font-weight: 500;
}

.kb-create-form {
    display: none;
    margin-top: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
}
.kb-create-form.visible { display: block; }

.kb-tab-strip {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.kb-create-form .kb-tab-button {
    flex: 1;
    width: auto;
    padding: 7px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    font-family: 'Chivo', sans-serif;
    margin-bottom: -1px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.kb-create-form .kb-tab-button:hover:not(.active) {
    color: var(--text-main);
    background: var(--bg-card);
}
.kb-create-form .kb-tab-button.active {
    background: var(--secondary);
    color: white;
    border-color: var(--secondary);
    font-weight: 600;
}
.kb-tab-panel { display: none; }
.kb-tab-panel.active { display: block; }

.kb-tab-content textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
    font-size: 12px;
    min-height: 120px;
    font-family: monospace;
    resize: vertical;
    margin-bottom: 8px;
}

.kb-create-form input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 8px;
    outline: none;
    font-family: inherit;
}

/* KB Section */
.kb-section {
    padding-top: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.kb-create-form input:focus {
    border-color: var(--secondary);
}

.kb-create-form button {
    width: 100%;
    padding: 8px;
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: 'Chivo', sans-serif;
}
.kb-create-form button:hover { background: #037a82; }

.kb-delete-btn {
    font-size: 11px;
    color: #dc2626;
    cursor: pointer;
    border: none;
    background: none;
    padding: 4px 0;
    font-weight: 500;
    margin-left: 8px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(27, 68, 121, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.modal h3 { margin-bottom: 12px; color: var(--primary); font-family: 'Chivo', sans-serif; }
.modal p { margin-bottom: 12px; color: var(--text-muted); font-size: 14px; }
.modal input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--input-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.modal-buttons button {
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    font-family: 'Chivo', sans-serif;
    font-weight: 500;
}
.modal-cancel { background: #e2e8f0; border: none; color: var(--text-main); }
.modal-confirm { background: #dc2626; color: white; border: none; }
.modal-confirm:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Build KBs from Zotero modal ─────────────────────────────────────────── */
.hidden { display: none !important; }
.zotero-build-modal-content {
    max-width: 80vw;
    width: 720px;
    max-height: 80vh;
    overflow: auto;
}
.zotero-plan-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}
.zotero-plan-table th,
.zotero-plan-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border, #e2e8f0);
    text-align: left;
    vertical-align: middle;
}
.zotero-plan-table th {
    font-weight: 600;
    color: var(--text-main);
    background: rgba(27, 68, 121, 0.04);
}
.zotero-plan-table input[type="text"] {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--input-border, #cbd5e1);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}
.zotero-progress {
    white-space: pre-wrap;
    font-family: 'Menlo', 'Monaco', monospace;
    font-size: 12px;
    padding: 8px;
    background: rgba(27, 68, 121, 0.04);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius);
    max-height: 50vh;
    overflow: auto;
    margin: 8px 0;
}
.zotero-execute-btn {
    background: var(--secondary, #1b4479);
    color: white;
    border: none;
}
.zotero-execute-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── KB Statistics Panel ─────────────────────────────────────────────────── */

/* Tab strip inside the KB detail area (Stats tab) */
.kb-detail-tab-strip {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin: 10px 0 10px;
}
.kb-detail-tab-btn {
    padding: 5px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    font-family: 'Chivo', sans-serif;
    margin-bottom: -1px;
    transition: background 0.15s, color 0.15s;
}
.kb-detail-tab-btn:hover:not(.active) {
    color: var(--text-main);
    background: var(--bg-card);
}
.kb-detail-tab-btn.active {
    background: var(--secondary);
    color: white;
    border-color: var(--secondary);
    font-weight: 600;
}

#kb-stats-container {
    font-size: 12px;
    color: var(--text-main);
}

.kb-stats-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kb-stats-loading,
.kb-stats-empty,
.kb-stats-error {
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 0;
}
.kb-stats-error { color: #dc2626; }

.kb-stats-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.kb-stats-name {
    font-weight: 600;
    color: var(--primary);
    font-size: 13px;
    margin-right: 2px;
}
.kb-stats-pill {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 99px;
    background: var(--secondary);
    color: white;
    font-weight: 500;
}
.kb-stats-pill-muted {
    background: #e2e8f0;
    color: var(--text-muted);
}

.kb-stats-section {
    padding: 4px 0;
}
.kb-stats-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 6px;
}

/* Inline SVG bar chart */
.kb-stats-chart {
    display: block;
    overflow: visible;
}
.kb-stats-bar {
    fill: var(--secondary);
    opacity: 0.85;
    transition: opacity 0.2s;
}
.kb-stats-bar:hover { opacity: 1; }
.kb-stats-bar-label {
    font-size: 8px;
    fill: var(--text-muted);
}
.kb-stats-year-label {
    font-size: 8px;
    fill: var(--text-muted);
}

.kb-stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.kb-stats-table th,
.kb-stats-table td {
    padding: 4px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.kb-stats-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
}
.kb-stats-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.kb-stats-note {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    margin: 2px 0 0;
}

/* ── Async ingestion progress bar ────────────────────────────────────────── */

.progress-bar {
    width: 100%;
    height: 8px;
    background: #eee;
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0 4px;
}
.progress-bar-fill {
    height: 100%;
    background: var(--accent, #4a90e2);
    width: 0%;
    transition: width 200ms linear;
}
.progress-label {
    font-size: 0.85em;
    color: #555;
    margin-bottom: 8px;
}

/* ── DOI add panel ───────────────────────────────────────────────────────── */

.kb-dois-panel {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.kb-dois-panel.visible {
    display: block;
}

/* Local-file drag-and-drop zone for adding files into the selected KB */
.kb-dropzone {
    border: 2px dashed var(--border, #ccc);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    margin: 0.5rem 0;
}
.kb-dropzone.over {
    background: var(--surface-alt, #f5f5f5);
}
.link {
    cursor: pointer;
    text-decoration: underline;
}
.hidden {
    display: none;
}
#kb-local-progress {
    white-space: pre-wrap;
    font-family: monospace;
    max-height: 30vh;
    overflow: auto;
}
#kb-build-capsules-progress { white-space: pre-wrap; font-family: monospace; max-height: 30vh; overflow: auto; }
