:root {
    --bg: #0f1117;
    --panel: #171a21;
    --panel-2: #1e222c;
    --border: #2a2f3a;
    --text: #e6e9ef;
    --muted: #9aa4b2;
    --accent: #22c55e;
    --accent-dim: #16351f;
    --gold: #fbbf24;
    --blue: #38bdf8;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
}

.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 18px 16px;
}

.app-sidebar header h1 {
    margin: 0;
    font-size: 22px;
    letter-spacing: -0.02em;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.controls { margin-top: 18px; display: flex; flex-direction: column; gap: 18px; }

.sidebar-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 6px;
}

.view-toggle {
    display: flex;
    gap: 6px;
}

.view-toggle button {
    flex: 1;
    padding: 8px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.12s;
}

.view-toggle button:hover { color: var(--text); border-color: #3a4150; }

.view-toggle button.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.search-box { display: flex; flex-direction: column; gap: 8px; }

.filter-row { display: flex; gap: 6px; }
.filter-row select { flex: 1; }

input[type="text"], select, button {
    font-family: inherit;
    font-size: 13px;
}

input[type="text"], select {
    width: 100%;
    padding: 8px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    outline: none;
}

input[type="text"]:focus, select:focus { border-color: var(--accent); }

select option { background: var(--panel-2); color: var(--text); }

.search-box button, .nav-controls button {
    padding: 8px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.12s;
}
.search-box button:hover, .nav-controls button:hover { border-color: var(--accent); color: var(--accent); }

.nav-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-controls button { flex: 1; }
#corpusCounter, #evalCounter {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: 12px;
    min-width: 64px;
    text-align: center;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}
.sidebar-footer a { color: var(--blue); text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }

/* ---------- Main panel ---------- */
.app-main {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
}

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

/* Corpus view */
#corpusView { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.doc-meta-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
}
.doc-meta-card h2 {
    margin: 0 0 12px;
    font-size: 20px;
    word-break: break-word;
}
.meta-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: center;
}
.meta-pill {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--muted);
}
.meta-pill b { color: var(--text); font-weight: 600; }
.doc-link {
    margin-left: auto;
    color: var(--blue);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
}
.doc-link:hover { text-decoration: underline; }

.pdf-wrap {
    flex: 1;
    min-height: 480px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #525659;
}
#pdfFrame { width: 100%; height: 100%; border: none; }

.no-pdf {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--muted);
}

/* Eval view */
#evalView { flex: 1; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px 26px;
    max-width: 980px;
}

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--muted);
}
.badge.type-metrics-generated { color: var(--blue); border-color: var(--blue); }
.badge.type-domain-relevant { color: var(--gold); border-color: var(--gold); }
.badge.type-novel-generated { color: #c084fc; border-color: #c084fc; }
.badge.id { color: var(--accent); border-color: var(--accent); }

.card h2 { margin: 0 0 18px; font-size: 20px; line-height: 1.4; }

.answer-banner {
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 18px;
}
.answer-banner .lbl { color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.answer-banner .val { font-size: 16px; font-weight: 600; margin-top: 4px; white-space: pre-wrap; }

.field { margin-bottom: 16px; }
.field .lbl {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 5px;
}
.field .val { line-height: 1.6; white-space: pre-wrap; }
.field a.doclink { color: var(--blue); text-decoration: none; cursor: pointer; }
.field a.doclink:hover { text-decoration: underline; }

.evidence-item {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
}
.evidence-head {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--muted);
}
.evidence-head .page-pill {
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 6px;
    padding: 2px 8px;
    font-weight: 600;
}
.evidence-text {
    white-space: pre-wrap;
    font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
    max-height: 260px;
    overflow: auto;
    background: var(--bg);
    border-radius: 8px;
    padding: 10px 12px;
}
details.full-page { margin-top: 8px; }
details.full-page > summary {
    cursor: pointer;
    color: var(--blue);
    font-size: 12px;
    user-select: none;
}
details.full-page .evidence-text { margin-top: 8px; max-height: 420px; }

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