/* ============================================
   UniPolicy Inquiry - University Document RAG
   ============================================ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-input: #2a2e3f;
    --border: #2e3348;
    --text-primary: #f5f6fa;
    --text-secondary: #cdd1e0;
    --text-muted: #a0a4b8;
    --accent: #6c8cff;
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --purple: #a78bfa;
    --policy: #7eb8e5;
    --policy-light: #a8d0f0;
    --policy-bg: rgba(126, 184, 229, 0.08);
    --policy-border: rgba(126, 184, 229, 0.2);
    --radius: 8px;
    --header-height: 52px;
    --tabs-height: 44px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg-primary); color: var(--text-primary); line-height: 1.6; }

/* ---------- Header ---------- */
.header {
    background: rgba(15, 17, 23, 0.6);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--policy-border);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__back {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 6px;
    color: var(--text-secondary); text-decoration: none;
    transition: background 0.2s, color 0.2s;
}
.header__back:hover { background: var(--policy-bg); color: var(--text-primary); }
.header__back svg { width: 20px; height: 20px; }

.header__brand { display: flex; align-items: center; gap: 8px; }
.header__icon { font-size: 1.2rem; }
.header__title { font-size: 1.1rem; font-weight: 600; color: var(--policy-light); }

.header__badge {
    margin-left: auto;
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--policy); background: var(--policy-bg);
    border: 1px solid var(--policy-border);
    padding: 3px 10px; border-radius: 4px;
}

/* ---------- Tab Bar ---------- */
.tabs {
    position: sticky;
    top: var(--header-height);
    z-index: 90;
    background: rgba(15, 17, 23, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(46, 51, 72, 0.5);
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 6px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs__btn {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 16px; border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit; font-size: 0.78rem; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: all 0.15s;
}

.tabs__btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.tabs__btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.04);
}

.tabs__btn--active {
    color: var(--policy-light);
    background: var(--policy-bg);
    border-color: var(--policy-border);
}

/* ---------- Tab Panels ---------- */
.tab-panel {
    display: none;
}

.tab-panel--active {
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: tabFade 0.2s ease;
}

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

/* ---------- Main ---------- */
.main {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 20px 64px;
}

/* ---------- Section Titles ---------- */
.arch__title,
.pipeline-detail__title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ---------- Pipeline Detail ---------- */
.pipeline-detail {
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 10px;
    padding: 16px 20px;
}

.pipeline-detail__steps {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.pstep {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(46, 51, 72, 0.3);
}

.pstep:last-child { border-bottom: none; }

.pstep__num {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--policy-bg);
    border: 1px solid var(--policy-border);
    color: var(--policy);
    font-size: 0.72rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.pstep__body { flex: 1; min-width: 0; }

.pstep__name {
    font-size: 0.85rem; font-weight: 600;
    color: var(--text-primary);
}

.pstep__model {
    font-size: 0.7rem; font-weight: 500;
    color: var(--policy);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    margin-top: 1px;
}

.pstep__desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.pstep__time {
    font-size: 0.7rem; font-weight: 600;
    color: var(--text-muted);
    background: rgba(46, 51, 72, 0.4);
    padding: 2px 8px; border-radius: 4px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* ---------- Pipeline Visualizer ---------- */
.pipeline-viz {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 8px 0 16px;
}

.pipeline-viz__step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
}

.pipeline-viz__step span {
    font-size: 0.68rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.3px;
    color: var(--text-muted);
    transition: color 0.3s;
}

.pipeline-viz__dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s;
}

.pipeline-viz__step--active .pipeline-viz__dot {
    background: var(--policy);
    box-shadow: 0 0 8px rgba(91, 155, 213, 0.5);
    animation: pulsePipe 1s ease-in-out infinite;
}
.pipeline-viz__step--active span { color: var(--policy-light); }

.pipeline-viz__step--done .pipeline-viz__dot {
    background: var(--green);
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.3);
}
.pipeline-viz__step--done span { color: var(--green); }

@keyframes pulsePipe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.pipeline-viz__arrow {
    width: 28px; height: 2px;
    background: var(--border);
    position: relative;
    flex-shrink: 0;
}
.pipeline-viz__arrow::after {
    content: ''; position: absolute;
    right: 0; top: -3px;
    border: 4px solid transparent;
    border-left: 5px solid var(--border);
}

/* ---------- Search ---------- */
.search__filters {
    display: flex; gap: 12px; margin-bottom: 10px; flex-wrap: wrap;
}
.search__filter {
    display: flex; align-items: center; gap: 8px;
}
.search__filter-label {
    font-size: 0.82rem; color: var(--text-muted); font-weight: 500; white-space: nowrap;
}
.search__filter-select {
    padding: 8px 12px;
    border-radius: 6px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-primary);
    font-family: inherit; font-size: 0.85rem;
    outline: none; cursor: pointer;
    transition: border-color 0.2s;
}
.search__filter-select:focus { border-color: var(--policy); }
.search__filter-select--short { max-width: 140px; }

.search__form { display: flex; gap: 8px; }

.search__input {
    flex: 1; padding: 12px 16px;
    border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-primary);
    font-family: inherit; font-size: 0.92rem;
    outline: none; transition: border-color 0.2s;
}
.search__input:focus { border-color: var(--policy); }
.search__input::placeholder { color: var(--text-muted); }

.search__btn {
    width: 44px; height: 44px;
    border-radius: 8px; border: 1px solid var(--policy-border);
    background: var(--policy-bg); color: var(--policy);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s; flex-shrink: 0;
}
.search__btn:hover { background: rgba(91, 155, 213, 0.15); border-color: var(--policy); }
.search__btn:disabled { opacity: 0.4; cursor: not-allowed; }
.search__btn svg { width: 18px; height: 18px; }

.search__examples {
    display: flex; align-items: center; gap: 6px;
    flex-wrap: wrap; margin-top: 10px;
}
.search__examples-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }

.search__example {
    padding: 4px 10px; border-radius: 14px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-muted); font-family: inherit;
    font-size: 0.72rem; cursor: pointer;
    transition: all 0.15s; white-space: nowrap;
}
.search__example:hover {
    border-color: var(--policy-border); color: var(--policy-light);
    background: var(--policy-bg);
}

/* ---------- Loading ---------- */
.loading {
    display: flex; align-items: center; justify-content: center;
    gap: 12px; padding: 40px 0;
}
.loading__spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border); border-top-color: var(--policy);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading__text { font-size: 0.82rem; color: var(--text-muted); }

/* ---------- Timing Bar ---------- */
.timing {
    display: flex; gap: 2px; height: 28px;
    border-radius: 6px; overflow: hidden; margin-bottom: 10px;
}
.timing__segment {
    display: flex; align-items: center; justify-content: center;
    gap: 4px; padding: 0 6px; min-width: 0; overflow: hidden;
    transition: flex 0.4s ease;
}
.timing__segment--embed { background: rgba(108, 140, 255, 0.15); }
.timing__segment--retrieve { background: rgba(74, 222, 128, 0.15); }
.timing__segment--rerank { background: rgba(167, 139, 250, 0.15); }
.timing__segment--generate { background: rgba(91, 155, 213, 0.15); }

.timing__label {
    font-size: 0.58rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.3px;
    white-space: nowrap; overflow: hidden;
}
.timing__segment--embed .timing__label { color: var(--accent); }
.timing__segment--retrieve .timing__label { color: var(--green); }
.timing__segment--rerank .timing__label { color: var(--purple); }
.timing__segment--generate .timing__label { color: var(--policy); }

.timing__value {
    font-size: 0.58rem; font-weight: 500;
    color: var(--text-muted); white-space: nowrap;
}

/* ---------- Retrieval Info ---------- */
.retrieval-info {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; padding: 8px 0;
    font-size: 0.75rem; color: var(--text-muted);
}

.retrieval-info__stage {
    display: inline-flex; align-items: center; gap: 6px;
}

.retrieval-info__label {
    font-size: 0.6rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.3px;
    color: var(--policy); background: var(--policy-bg);
    border: 1px solid var(--policy-border);
    padding: 1px 6px; border-radius: 3px;
}

.retrieval-info__arrow { color: var(--text-muted); font-size: 0.85rem; }

.retrieval-info strong { color: var(--text-primary); font-weight: 600; }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 12px; }

.answer {
    background: rgba(26, 29, 39, 0.6);
    border: 1px solid var(--policy-border);
    border-radius: 10px; overflow: hidden;
}
.answer__header {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; background: var(--policy-bg);
    border-bottom: 1px solid var(--policy-border);
    font-size: 0.78rem; font-weight: 600; color: var(--policy-light);
}
.answer__header svg { width: 16px; height: 16px; }
.answer__meta {
    margin-left: auto; font-size: 0.65rem;
    font-weight: 400; color: var(--text-muted);
}
.answer__body {
    padding: 14px 16px; font-size: 0.88rem;
    color: var(--text-secondary); line-height: 1.7;
}
.answer__body p { margin-bottom: 0.6em; }
.answer__body p:last-child { margin-bottom: 0; }
.answer__body h1, .answer__body h2, .answer__body h3 {
    color: var(--text-primary); margin: 1em 0 0.4em; line-height: 1.3;
}
.answer__body h1 { font-size: 1.1rem; }
.answer__body h2 { font-size: 1rem; }
.answer__body h3 { font-size: 0.95rem; }
.answer__body strong { color: var(--text-primary); }
.answer__body em { color: var(--text-secondary); font-style: italic; }
.answer__body ul { margin: 0.4em 0; padding-left: 1.4em; }
.answer__body li { margin-bottom: 0.3em; }
.answer__body ol { margin: 0.4em 0; padding-left: 1.4em; }
.answer__body table {
    width: 100%; border-collapse: collapse; margin: 0.6em 0;
    font-size: 0.85rem;
}
.answer__body th, .answer__body td {
    border: 1px solid var(--policy-border);
    padding: 0.4em 0.6em; text-align: left;
}
.answer__body th {
    background: var(--policy-bg); color: var(--text-primary);
    font-weight: 600;
}
.answer__body td { color: var(--text-secondary); }
.answer__error { color: var(--red); }

.sources {
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 10px; overflow: hidden;
}
.sources__header {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; border-bottom: 1px solid rgba(46, 51, 72, 0.5);
    font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
}
.sources__header svg { width: 16px; height: 16px; }
.sources__count {
    margin-left: auto; font-size: 0.65rem;
    font-weight: 400; color: var(--text-muted);
}
.sources__list { display: flex; flex-direction: column; }

.source {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(46, 51, 72, 0.3);
}
.source:last-child { border-bottom: none; }

.source__head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.source__rank {
    font-size: 0.65rem; font-weight: 700;
    color: var(--text-muted); background: rgba(46, 51, 72, 0.5);
    padding: 1px 6px; border-radius: 4px;
}
.source__title { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); }
.source__category {
    font-size: 0.62rem; font-weight: 500;
    color: var(--policy); background: var(--policy-bg);
    border: 1px solid var(--policy-border);
    padding: 1px 6px; border-radius: 3px;
    white-space: nowrap;
}
.source__score {
    margin-left: auto; font-size: 0.65rem; font-weight: 700;
    padding: 2px 8px; border-radius: 4px;
}
.source__score--high { color: var(--green); background: rgba(74, 222, 128, 0.1); }
.source__score--mid { color: var(--yellow); background: rgba(250, 204, 21, 0.1); }
.source__score--low { color: var(--text-muted); background: rgba(46, 51, 72, 0.5); }

.source__lang, .source__scope, .source__pages {
    font-size: 0.6rem; font-weight: 600;
    padding: 1px 6px; border-radius: 3px;
    white-space: nowrap; flex-shrink: 0;
}
.source__lang {
    text-transform: uppercase; letter-spacing: 0.3px;
}
.source__lang--en { color: #60a5fa; background: rgba(96, 165, 250, 0.12); border: 1px solid rgba(96, 165, 250, 0.2); }
.source__lang--hu { color: #f472b6; background: rgba(244, 114, 182, 0.12); border: 1px solid rgba(244, 114, 182, 0.2); }
.source__scope {
    color: var(--green); background: rgba(74, 222, 128, 0.08);
    border: 1px solid rgba(74, 222, 128, 0.15);
    font-weight: 500;
}
.source__pages {
    color: var(--text-muted); background: rgba(46, 51, 72, 0.4);
    font-weight: 500;
}

.source__text {
    font-size: 0.75rem; color: var(--text-muted); line-height: 1.6;
    display: -webkit-box; -webkit-line-clamp: 3;
    -webkit-box-orient: vertical; overflow: hidden;
}
.source-empty { padding: 16px; font-size: 0.82rem; color: var(--text-muted); text-align: center; }

/* ---------- Evaluation & Monitoring ---------- */

/* Aggregate scores bar */
.eval__scores {
    display: flex;
    gap: 8px;
}

.eval__score {
    flex: 1;
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 8px;
    padding: 12px 10px;
    text-align: center;
}

.eval__score-val {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.eval__score-val--green { color: var(--green); }
.eval__score-val--yellow { color: var(--yellow); }

.eval__score-name {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Section containers */
.eval__section {
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 10px;
    padding: 16px;
}

.eval__section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.eval__section-note {
    font-weight: 400;
    font-size: 0.65rem;
    text-transform: none;
    letter-spacing: 0;
}

/* Methodology cards */
.eval__method {
    padding: 12px 0;
    border-bottom: 1px solid rgba(46, 51, 72, 0.3);
}

.eval__method:last-child { border-bottom: none; }

.eval__method-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.eval__method-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.eval__method-result {
    font-size: 0.82rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 2px 10px;
    border-radius: 4px;
}

.eval__method-result--green {
    color: var(--green);
    background: rgba(74, 222, 128, 0.1);
}

.eval__method-result--yellow {
    color: var(--yellow);
    background: rgba(250, 204, 21, 0.1);
}

.eval__method-formula {
    font-size: 0.72rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    color: var(--policy);
    background: rgba(15, 17, 23, 0.4);
    padding: 5px 10px;
    border-radius: 4px;
    margin-bottom: 6px;
    overflow-x: auto;
}

.eval__method-explain {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 4px;
}

.eval__method-why {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
    padding-left: 10px;
    border-left: 2px solid var(--policy-border);
}

.eval__method-why strong {
    color: var(--text-primary);
}

/* Test suite table */
.eval__table-wrap {
    overflow-x: auto;
    margin-bottom: 8px;
}

.eval__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    min-width: 680px;
}

.eval__table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    background: rgba(15, 17, 23, 0.3);
    border-bottom: 1px solid rgba(46, 51, 72, 0.4);
    white-space: nowrap;
}

.eval__table td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(46, 51, 72, 0.2);
    color: var(--text-secondary);
    vertical-align: middle;
}

.eval__table tbody tr:hover td {
    background: rgba(108, 140, 255, 0.03);
}

.eval__table td:first-child {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 0.68rem;
    width: 30px;
}

.eval__table code {
    font-size: 0.65rem;
    background: rgba(46, 51, 72, 0.4);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--policy-light);
    white-space: nowrap;
}

.eval__hit {
    color: var(--green);
    font-weight: 700;
    text-align: center;
    font-size: 0.85rem;
}

.eval__miss {
    color: var(--red);
    font-weight: 700;
    text-align: center;
    font-size: 0.85rem;
}

/* Category badges */
.eval__cat {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 3px;
    font-size: 0.62rem;
    font-weight: 600;
    white-space: nowrap;
}

.eval__cat--en_policy {
    color: var(--accent);
    background: rgba(108, 140, 255, 0.1);
}

.eval__cat--en_faculty {
    color: var(--green);
    background: rgba(74, 222, 128, 0.1);
}

.eval__cat--en_faculty_rules {
    color: var(--purple);
    background: rgba(167, 139, 250, 0.1);
}

.eval__cat--hu_faculty {
    color: #f472b6;
    background: rgba(244, 114, 182, 0.1);
}

.eval__cat--cross_lang {
    color: var(--yellow);
    background: rgba(250, 204, 21, 0.1);
}

.eval__cat--scope_boost {
    color: var(--policy);
    background: var(--policy-bg);
}

.eval__cat--specific_facts {
    color: #fb923c;
    background: rgba(251, 146, 60, 0.1);
}

.eval__table-note {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.eval__table-note code {
    font-size: 0.65rem;
    background: rgba(46, 51, 72, 0.4);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--policy-light);
}

/* Prometheus */
.eval__card-note--live {
    color: var(--green);
}
.eval__card-note--live::before {
    content: '';
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 4px;
    animation: pulseLive 2s ease-in-out infinite;
}
@keyframes pulseLive {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.eval__prom-card {
    background: rgba(15, 17, 23, 0.3);
    border: 1px solid rgba(46, 51, 72, 0.3);
    border-radius: 8px;
    padding: 6px 0;
}

.prom-row {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 5px 14px;
}
.prom-row--divider {
    height: 1px; background: rgba(46, 51, 72, 0.3);
    margin: 3px 14px; padding: 0;
}
.prom-row__name { font-size: 0.72rem; color: var(--text-muted); }
.prom-row__val {
    font-size: 0.75rem; font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ---------- Knowledge Base ---------- */
.kb {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.kb__summary {
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 10px;
    overflow: hidden;
}

.kb__summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(46, 51, 72, 0.2);
}

.kb__summary-row:last-child { border-bottom: none; }

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

.kb__summary-val {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Chunk strategy detail */
.kb__chunk-strategy {
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 10px;
    padding: 16px 18px;
}

.kb__chunk-strategy-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--policy);
    margin-bottom: 8px;
}

.kb__chunk-strategy-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 14px;
}

.kb__chunk-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.kb__chunk-step {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.kb__chunk-step-num {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--policy-bg);
    border: 1px solid var(--policy-border);
    color: var(--policy);
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

.kb__chunk-step-body {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.kb__chunk-step-body strong {
    color: var(--text-primary);
}

.kb__chunk-step-body code {
    background: rgba(91, 155, 213, 0.1);
    border: 1px solid rgba(91, 155, 213, 0.15);
    color: var(--policy-light);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.75rem;
}

.kb__chunk-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    border-top: 1px solid rgba(46, 51, 72, 0.3);
    padding-top: 10px;
}

.kb__docs-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
}

.kb__docs-count {
    font-weight: 400;
    font-size: 0.65rem;
    text-transform: none;
    letter-spacing: 0;
}

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

/* Document cards */
.kb-doc {
    background: rgba(26, 29, 39, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.5);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.15s;
}

.kb-doc:hover {
    border-color: rgba(46, 51, 72, 0.8);
}

.kb-doc--open {
    border-color: var(--policy-border);
}

.kb-doc__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.kb-doc__head:hover {
    background: rgba(255, 255, 255, 0.02);
}

.kb-doc__title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kb-doc__lang, .kb-doc__scope {
    font-size: 0.6rem; font-weight: 600;
    padding: 1px 6px; border-radius: 3px;
    white-space: nowrap; flex-shrink: 0;
}
.kb-doc__lang { text-transform: uppercase; letter-spacing: 0.3px; }
.kb-doc__lang--en { color: #60a5fa; background: rgba(96, 165, 250, 0.12); border: 1px solid rgba(96, 165, 250, 0.2); }
.kb-doc__lang--hu { color: #f472b6; background: rgba(244, 114, 182, 0.12); border: 1px solid rgba(244, 114, 182, 0.2); }
.kb-doc__scope {
    color: var(--green); background: rgba(74, 222, 128, 0.08);
    border: 1px solid rgba(74, 222, 128, 0.15);
    font-weight: 500;
}

.kb-doc__category {
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--policy);
    background: var(--policy-bg);
    border: 1px solid var(--policy-border);
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.kb-doc__chunks {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    background: rgba(46, 51, 72, 0.4);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.kb-doc__toggle {
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
    display: flex;
}

.kb-doc__toggle svg {
    width: 16px;
    height: 16px;
}

.kb-doc--open .kb-doc__toggle {
    transform: rotate(180deg);
}

.kb-doc__body {
    display: none;
    border-top: 1px solid rgba(46, 51, 72, 0.3);
    padding: 12px 14px;
}

.kb-doc--open .kb-doc__body {
    display: block;
    animation: tabFade 0.2s ease;
}

.kb-doc__loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 8px 0;
}

.kb-doc__unavailable {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 4px 0;
}

.kb-doc__chunks-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Individual chunks */
.kb-chunk {
    background: rgba(15, 17, 23, 0.4);
    border: 1px solid rgba(46, 51, 72, 0.3);
    border-radius: 6px;
    overflow: hidden;
}

.kb-chunk__head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: rgba(46, 51, 72, 0.2);
    border-bottom: 1px solid rgba(46, 51, 72, 0.2);
    flex-wrap: wrap;
}

.kb-chunk__idx {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--policy);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.kb-chunk__title {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.kb-chunk__lang, .kb-chunk__scope, .kb-chunk__pages {
    font-size: 0.58rem; font-weight: 600;
    padding: 0px 5px; border-radius: 3px;
    white-space: nowrap;
}
.kb-chunk__lang { text-transform: uppercase; letter-spacing: 0.3px; }
.kb-chunk__lang--en { color: #60a5fa; background: rgba(96, 165, 250, 0.12); }
.kb-chunk__lang--hu { color: #f472b6; background: rgba(244, 114, 182, 0.12); }
.kb-chunk__scope { color: var(--green); background: rgba(74, 222, 128, 0.08); font-weight: 500; }
.kb-chunk__pages { color: var(--text-muted); background: rgba(46, 51, 72, 0.4); font-weight: 500; }

.kb-chunk__dim {
    font-size: 0.6rem;
    color: var(--text-muted);
    opacity: 0.6;
    margin-left: auto;
}

.kb-chunk__text {
    padding: 8px 10px;
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.6;
    max-height: 120px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

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

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
    .main { padding: 12px 12px 48px; }

    .tabs { justify-content: flex-start; padding: 6px 12px; }
    .tabs__btn { padding: 6px 12px; font-size: 0.72rem; }
    .tabs__btn span { display: none; }
    .tabs__btn svg { width: 16px; height: 16px; }

    .pipeline-viz__step { padding: 0 6px; }
    .pipeline-viz__step span { font-size: 0.6rem; }
    .pipeline-viz__arrow { width: 16px; }

    .timing__label { display: none; }
    .retrieval-info { flex-direction: column; gap: 4px; }

    .search__examples { gap: 4px; }
    .search__example { font-size: 0.68rem; padding: 3px 8px; }

    .eval__scores { flex-wrap: wrap; }
    .eval__score { min-width: calc(50% - 4px); }

    .kb-doc__head { flex-wrap: wrap; }
    .kb-doc__title { white-space: normal; }
}

/* ===========================================
   Chat layout (replaces the old single-question UI)
   =========================================== */

.chat-app {
    display: grid;
    grid-template-columns: 280px 1fr;
    /* main has padding 20px top + 64px bottom = 84px, plus header + tabs above. */
    height: calc(100vh - var(--header-height) - var(--tabs-height) - 84px);
    min-height: 480px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    overflow: hidden;
}

/* ----- Sidebar ------------------------------------------------------ */
.chat-sidebar {
    border-right: 1px solid var(--border);
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-sidebar__header {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-newbtn {
    width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 12px;
    border-radius: 6px; border: 1px solid var(--policy-border);
    background: var(--policy-bg); color: var(--policy);
    font-size: 0.88rem; font-weight: 500; cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.chat-newbtn:hover { background: rgba(126, 184, 229, 0.18); border-color: var(--policy); }
.chat-newbtn svg { width: 16px; height: 16px; }
.chat-sidebar__list { flex: 1; overflow-y: auto; padding: 6px; }
.chat-sidebar__empty {
    padding: 24px 14px;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-align: center;
    line-height: 1.5;
}
.sess {
    display: flex; align-items: stretch; gap: 4px;
    border-radius: 6px;
    margin-bottom: 4px;
    transition: background 0.1s;
}
.sess:hover { background: var(--bg-card); }
.sess--active { background: var(--policy-bg); }
.sess--active .sess__title { color: var(--policy-light); }
.sess__main {
    flex: 1; min-width: 0;
    text-align: left;
    padding: 8px 10px;
    border: none; background: transparent; color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
}
.sess__title {
    font-size: 0.86rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 2px;
}
.sess__meta {
    font-size: 0.72rem; color: var(--text-muted);
    display: flex; gap: 4px;
}
.sess__actions { display: flex; align-items: center; gap: 2px; padding-right: 4px; opacity: 0; transition: opacity 0.15s; }
.sess:hover .sess__actions, .sess--active .sess__actions { opacity: 1; }
.sess__btn {
    width: 24px; height: 24px;
    border: none; background: transparent; color: var(--text-muted);
    border-radius: 4px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.sess__btn:hover { background: var(--bg-input); color: var(--text-primary); }
.sess__btn--danger:hover { color: var(--red); }
.sess__btn svg { width: 14px; height: 14px; }

/* ----- Main column -------------------------------------------------- */
.chat-main {
    display: flex; flex-direction: column;
    min-width: 0;
    min-height: 0;       /* allow inner flex children to overflow & scroll */
    overflow: hidden;
}

.chat-filters {
    display: flex; gap: 12px; align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.chat-filter { display: flex; align-items: center; gap: 8px; }
.chat-filter--right { margin-left: auto; }
.chat-filter__label { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }
.chat-filter__select {
    padding: 6px 10px;
    border-radius: 5px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-primary);
    font-family: inherit; font-size: 0.82rem;
    outline: none; cursor: pointer;
    max-width: 320px;
}
.chat-filter__select--short { max-width: 130px; }
.chat-filter__select:focus { border-color: var(--policy); }

.chat-status__dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.4);
}
.chat-status__label { font-size: 0.78rem; color: var(--text-secondary); }
.chat-filter--working .chat-status__dot { background: var(--yellow); animation: pulse 1.2s ease-in-out infinite; }
.chat-filter--err .chat-status__dot { background: var(--red); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ----- Messages list ----------------------------------------------- */
.chat-messages {
    flex: 1 1 0;
    min-height: 0;       /* required for overflow-y to work inside a flex column */
    overflow-y: auto;
    padding: 16px 18px;
    display: flex; flex-direction: column;
    gap: 14px;
}

.chat-empty {
    margin: auto;
    text-align: center;
    max-width: 540px;
    padding: 32px 16px;
}
.chat-empty__title { font-size: 1.3rem; color: var(--text-primary); font-weight: 500; margin-bottom: 6px; }
.chat-empty__sub { color: var(--text-muted); font-size: 0.88rem; line-height: 1.5; margin-bottom: 18px; }
.chat-examples { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chat-example {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: 999px;
    font-family: inherit; font-size: 0.82rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.chat-example:hover { border-color: var(--policy); color: var(--policy-light); }

/* ----- Message bubble ---------------------------------------------- */
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg__avatar {
    flex-shrink: 0;
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 600;
    border: 1px solid var(--border);
}
.msg--user .msg__avatar { background: var(--bg-card); color: var(--text-primary); }
.msg--assistant .msg__avatar { background: var(--policy-bg); color: var(--policy); border-color: var(--policy-border); }

.msg__body { flex: 1; min-width: 0; }
.msg__content {
    color: var(--text-primary);
    line-height: 1.55;
    font-size: 0.92rem;
    word-wrap: break-word;
}
.msg--user .msg__content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 10px;
    white-space: pre-wrap;
}
.msg--assistant .msg__content { padding: 4px 0; }
.msg__content p { margin: 0.4em 0; }
.msg__content ol, .msg__content ul { margin: 0.4em 0; padding-left: 1.4em; }
.msg__content h1, .msg__content h2, .msg__content h3 { margin: 0.6em 0 0.3em; line-height: 1.3; }
.msg__content table {
    width: 100%; border-collapse: collapse;
    margin: 0.6em 0; font-size: 0.84rem;
}
.msg__content th, .msg__content td {
    border: 1px solid var(--policy-border);
    padding: 0.4em 0.6em; text-align: left;
}
.msg__content th { background: var(--policy-bg); color: var(--text-primary); font-weight: 600; }
.msg__content code {
    background: var(--bg-input);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.msg__cursor { color: var(--policy); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.msg__meta {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    margin-top: 6px;
    font-size: 0.74rem; color: var(--text-muted);
}
.msg__rewrite {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    cursor: help;
}
.msg__rewrite svg { width: 11px; height: 11px; }
.msg__timing { color: var(--text-muted); }
.msg__error { color: var(--red); }

/* ----- Sources panel ----------------------------------------------- */
.msg__sources {
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    overflow: hidden;
}
.msg__sources-head {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.82rem;
    user-select: none;
}
.msg__sources-head svg { width: 14px; height: 14px; }
.msg__sources-head:hover { background: var(--bg-input); }
.msg__sources-count {
    margin-left: 4px;
    font-size: 0.74rem;
    background: var(--policy-bg);
    color: var(--policy);
    padding: 1px 7px;
    border-radius: 999px;
}
.msg__sources-chevron { margin-left: auto; transition: transform 0.2s; }
.msg__sources--open .msg__sources-chevron { transform: rotate(180deg); }
.msg__sources-list {
    display: none;
    padding: 4px 12px 10px;
    border-top: 1px solid var(--border);
    flex-direction: column;
    gap: 6px;
}
.msg__sources--open .msg__sources-list { display: flex; }

.src {
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-radius: 5px;
    border: 1px solid var(--border);
}
.src__head {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    margin-bottom: 4px;
    font-size: 0.78rem;
}
.src__rank { color: var(--text-muted); font-weight: 600; }
.src__title { color: var(--text-primary); flex: 1; min-width: 120px; font-weight: 500; }
.src__scope {
    background: var(--policy-bg); color: var(--policy);
    padding: 1px 7px; border-radius: 3px;
    font-size: 0.72rem;
}
.src__lang {
    padding: 1px 6px; border-radius: 3px;
    font-size: 0.7rem; font-weight: 600;
}
.src__lang--en { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.src__lang--hu { background: rgba(167, 139, 250, 0.15); color: var(--purple); }
.src__pages { color: var(--text-muted); font-size: 0.74rem; }
.src__score { color: var(--text-muted); font-size: 0.74rem; margin-left: auto; }
.src__text {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
    white-space: pre-wrap;
    max-height: 160px;
    overflow-y: auto;
}

/* ----- Composer ---------------------------------------------------- */
.chat-composer {
    display: flex; gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}
.chat-composer__input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.45;
    resize: none;
    outline: none;
    min-height: 40px;
    max-height: 200px;
}
.chat-composer__input:focus { border-color: var(--policy); }
.chat-composer__input::placeholder { color: var(--text-muted); }
.chat-composer__send {
    flex-shrink: 0;
    width: 44px; height: 44px;
    border: 1px solid var(--policy-border);
    background: var(--policy-bg);
    color: var(--policy);
    border-radius: 8px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}
.chat-composer__send:hover:not(:disabled) { background: rgba(126, 184, 229, 0.2); border-color: var(--policy); }
.chat-composer__send:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-composer__send svg { width: 18px; height: 18px; }

/* ----- Responsive --------------------------------------------------- */
@media (max-width: 800px) {
    .chat-app {
        grid-template-columns: 1fr;
        /* mobile main has padding ~40px (20 top + 20 bottom typical) */
        height: calc(100vh - var(--header-height) - var(--tabs-height) - 60px);
    }
    .chat-sidebar { display: none; }
    .chat-filters { padding: 8px 10px; gap: 8px; }
    .chat-filter { gap: 4px; }
    .chat-filter__select { font-size: 0.78rem; padding: 5px 8px; }
}
