:root {
    --bg: #0f1117;
    --panel: #171a21;
    --panel-2: #1e222c;
    --border: #2a2f3a;
    --text: #e6e9ef;
    --muted: #9aa4b2;
    --accent: #2dd4bf;
    --accent-dim: #0f3b37;
    --gold: #fbbf24;
    --blue: #38bdf8;
    --green: #34d399;
    --rose: #fb7185;
}

* { 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; min-width: 0; }

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 ---------- */
.app-main { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; }
#loading { color: var(--muted); padding: 40px; text-align: center; }
#corpusView { display: flex; flex-direction: column; }
#evalView { flex: 1; }

.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; font-family: ui-monospace, Menlo, Consolas, monospace; }
.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; }
.meta-pill.distractor { color: var(--rose); border-color: var(--rose); }

.content-toggle { display: flex; gap: 6px; margin-bottom: 14px; }
.content-toggle button {
    padding: 6px 12px; background: var(--panel-2); border: 1px solid var(--border);
    color: var(--muted); border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.content-toggle button.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.doc-content { max-width: 100%; }
.trunc-note { color: var(--muted); font-size: 12px; margin-bottom: 12px; font-style: italic; }

/* verbalized list */
ol.verb-list { margin: 0; padding-left: 30px; }
ol.verb-list li { margin-bottom: 8px; line-height: 1.6; }

/* structured / result table */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.fin-table { border-collapse: collapse; width: 100%; font-size: 12.5px; background: var(--panel); }
table.fin-table th, table.fin-table td {
    border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; white-space: nowrap;
}
table.fin-table thead th { background: var(--panel-2); color: var(--text); font-weight: 600; position: sticky; top: 0; }
table.fin-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }
table.fin-table .rownum { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Eval card ---------- */
.card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; padding: 22px 26px; max-width: 1000px;
}
.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);
    font-family: ui-monospace, Menlo, Consolas, monospace;
}
.badge.id { color: var(--accent); border-color: var(--accent); }
.badge.db { color: var(--blue); border-color: var(--blue); }
.badge.diff-Easy { color: var(--green); border-color: var(--green); }
.badge.diff-Medium { color: var(--gold); border-color: var(--gold); }
.badge.diff-Hard { color: var(--rose); border-color: var(--rose); }
.badge.flag { color: #c084fc; border-color: #c084fc; }

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

.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; }
.field a.doclink { color: var(--blue); text-decoration: none; cursor: pointer; font-family: ui-monospace, Menlo, Consolas, monospace; margin-right: 6px; }
.field a.doclink:hover { text-decoration: underline; }

code.sql {
    display: block; background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 13px; color: var(--accent); white-space: pre-wrap; word-break: break-word;
}

.answer-head {
    display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px;
}
.answer-head .lbl { color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.answer-head .count { color: var(--muted); font-size: 12px; }
.answer-err { color: var(--rose); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

.empty { color: var(--muted); padding: 40px; text-align: center; }
.private-note { color: var(--muted); font-style: italic; }
