/* Corpus Explorer styles — matches knowledge-graph palette */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: system-ui, -apple-system, 'Inter', sans-serif; color: #1E293B; background: #F8FAFC; }
body { display: flex; flex-direction: column; min-height: 100vh; }

/* header */
header {
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px; height: 56px;
    background: #fff; border-bottom: 1px solid #CBD5E1;
    position: sticky; top: 0; z-index: 10;
}
header .brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: #1E293B; }
header .brand img { height: 26px; }
header .brand b { color: #E8177F; font-weight: 800; font-size: 0.95rem; }
header h1 { font-size: 1rem; font-weight: 600; padding-left: 14px; border-left: 1px solid #CBD5E1; }
header .sub { color: #64748B; font-size: 0.78rem; padding-left: 6px; font-weight: 400; }
header .top-nav { margin-left: auto; display: flex; gap: 4px; }
header .top-nav a { color: #64748B; text-decoration: none; font-size: 0.85rem; padding: 6px 12px; border-radius: 6px; }
header .top-nav a:hover { background: #F1F5F9; color: #E8177F; }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid #E2E8F0; background: #fff; }
.tab {
    font: 600 0.88rem/1 inherit;
    background: transparent; border: 0; padding: 14px 18px; cursor: pointer;
    color: #64748B; position: relative; border-radius: 0;
}
.tab:hover { color: #E8177F; }
.tab.active { color: #E8177F; }
.tab.active::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: -1px;
    height: 2px; background: #E8177F;
}

/* panes */
#view { flex: 1; padding: 28px 32px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }
.pane { display: none; }
.pane.active { display: block; animation: fadeIn 0.18s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* cards */
.card {
    background: #fff; border: 1px solid #E2E8F0; border-radius: 10px;
    padding: 20px 22px; overflow: hidden;
}
.card h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 14px; color: #1E293B; }
.sub { color: #64748B; font-size: 0.8rem; line-height: 1.5; margin-top: 8px; }

/* hero stats */
.hero-stats {
    display: flex; align-items: center; justify-content: center; gap: 22px;
    padding: 28px 20px 14px;
}
.big-stat { text-align: center; min-width: 130px; padding: 20px 26px; background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; }
.big-stat .num { font-size: 2rem; font-weight: 800; color: #E8177F; font-variant-numeric: tabular-nums; }
.big-stat .lbl { font-size: 0.78rem; color: #64748B; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; font-weight: 600; }
.big-stat .sub2 { font-size: 0.68rem; color: #94A3B8; margin-top: 5px; font-weight: 500; }
.hero-stats .arrow { color: #94A3B8; font-size: 1.4rem; font-weight: 400; }
.hero-sub { text-align: center; color: #64748B; font-size: 0.9rem; max-width: 640px; margin: 0 auto 30px; line-height: 1.55; }

.overview-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
}
.overview-grid .pipeline-card { grid-column: 1 / -1; }
.overview-grid .flow-card { grid-column: 1 / -1; }

/* Sankey */
#ov-flow { width: 100%; min-height: 620px; }
.sankey-svg { width: 100%; height: 620px; display: block; font-family: system-ui, sans-serif; }
.sankey-svg path { transition: fill-opacity 0.1s; cursor: pointer; }
.sankey-svg rect { cursor: default; }

.card-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-hd h3 { margin-bottom: 0; }
.segm { display: inline-flex; padding: 2px; background: #F1F5F9; border-radius: 6px; gap: 2px; }
.segm button { font: 600 0.74rem/1 inherit; padding: 6px 10px; background: transparent; border: 0; border-radius: 4px; color: #64748B; cursor: pointer; }
.segm button.active { background: #fff; color: #E8177F; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* length histogram */
#ov-length-hist { height: 150px; }
#ov-length-hist svg { width: 100%; height: 100%; display: block; }
#ov-length-caption b { color: #1E293B; }

/* top entities panel */
.ent-list { display: flex; flex-direction: column; gap: 4px; max-height: 640px; overflow-y: auto; padding-right: 4px; }
.ent-list::-webkit-scrollbar { width: 6px; }
.ent-list::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
.ent-row {
    display: grid; grid-template-columns: 160px 95px 1fr 70px 72px;
    gap: 10px; align-items: center;
    font-size: 0.82rem; padding: 3px 6px; border-radius: 5px;
}
.ent-row:hover { background: #F8FAFC; }
.ent-row .ent-term { color: #1E293B; font-weight: 600; }
.ent-row .ent-group { font-size: 0.65rem; font-weight: 700; padding: 2px 7px; border-radius: 100px; text-transform: uppercase; letter-spacing: 0.04em; text-align: center; }
.ent-row .ent-bar { background: #F1F5F9; height: 6px; border-radius: 3px; overflow: hidden; }
.ent-row .ent-bar > span { display: block; height: 100%; border-radius: 3px; }
.ent-row .ent-cn { text-align: right; font: 500 0.76rem/1 ui-monospace, monospace; color: #334155; }
.ent-row .ent-dc { text-align: right; font: 500 0.7rem/1 ui-monospace, monospace; color: #94A3B8; }

/* source bars (overview) */
.src-bar { display: grid; grid-template-columns: 100px 1fr 90px; gap: 10px; align-items: center; padding: 5px 0; font-size: 0.83rem; }
.src-bar .nm { color: #334155; font-weight: 600; }
.src-bar .tr { background: #F1F5F9; height: 14px; border-radius: 4px; overflow: hidden; position: relative; }
.src-bar .tr > span { display: block; height: 100%; border-radius: 4px; }
.src-bar .cn { text-align: right; font: 500 0.76rem/1 ui-monospace, monospace; color: #64748B; }

/* year chart */
#ov-year-chart { height: 180px; position: relative; }
#ov-year-chart svg { width: 100%; height: 100%; display: block; }
#ov-year-caption { text-align: right; }

/* pipeline */
.pipeline { list-style: none; counter-reset: pipe; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.pipeline li {
    counter-increment: pipe; position: relative; padding: 14px 14px 14px 40px;
    background: #F8FAFC; border: 1px solid #E2E8F0; border-radius: 8px;
    font-size: 0.85rem; color: #334155; line-height: 1.5;
}
.pipeline li::before {
    content: counter(pipe); position: absolute; left: 10px; top: 12px;
    width: 22px; height: 22px; border-radius: 50%; background: #E8177F; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
}
.pipeline li b { color: #1E293B; }

/* sources grid */
.sources-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.src-card {
    background: #fff; border: 1px solid #E2E8F0; border-radius: 10px;
    padding: 20px 22px; position: relative; overflow: hidden;
}
.src-card::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: var(--accent, #E8177F);
}
.src-card h3 {
    font-size: 1.1rem; font-weight: 700; margin-bottom: 6px;
    display: flex; align-items: center; gap: 10px;
}
.src-card h3 .chip { font-size: 0.66rem; font-weight: 700; padding: 3px 8px; border-radius: 100px; background: var(--accent-soft, #FFF5F9); color: var(--accent, #E8177F); letter-spacing: 0.04em; text-transform: uppercase; }
.src-card .desc { color: #64748B; font-size: 0.86rem; line-height: 1.55; margin-bottom: 14px; }
.src-card .stats { display: flex; gap: 22px; margin-bottom: 16px; }
.src-card .stats > div { line-height: 1.2; }
.src-card .stats .n { font-size: 1.2rem; font-weight: 700; color: #1E293B; font-variant-numeric: tabular-nums; }
.src-card .stats .l { font-size: 0.72rem; color: #64748B; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; margin-top: 2px; }
.src-card .year-strip { height: 28px; display: flex; align-items: end; gap: 1px; margin-bottom: 14px; }
.src-card .year-strip > span { flex: 1; background: var(--accent, #E8177F); opacity: 0.7; border-radius: 1px 1px 0 0; min-height: 1px; }
.src-card .year-labels { display: flex; justify-content: space-between; font-size: 0.65rem; color: #94A3B8; font-family: ui-monospace, monospace; margin-top: -10px; margin-bottom: 12px; }
.src-card .journals { margin-top: 14px; font-size: 0.78rem; color: #64748B; }
.src-card .journals b { color: #1E293B; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 4px; }
.src-card .journals ol { padding-left: 16px; line-height: 1.5; }
.src-card .journals li { margin-bottom: 2px; }
.src-card .journals .j-cnt { color: #94A3B8; font-family: ui-monospace, monospace; font-size: 0.72rem; }

/* mini-stats row */
.src-card .mini-stats {
    display: flex; flex-wrap: wrap; gap: 6px 16px;
    font-size: 0.76rem; color: #475569;
    padding: 10px 0 14px; margin-bottom: 10px;
    border-top: 1px solid #F1F5F9; border-bottom: 1px solid #F1F5F9;
}
.src-card .mini-stats b { color: #1E293B; font-weight: 600; }
.src-card .mini-stats .faded { color: #94A3B8; }

/* block label */
.block-lbl {
    font-size: 0.68rem; font-weight: 700; color: #64748B;
    text-transform: uppercase; letter-spacing: 0.06em;
    margin: 14px 0 8px;
}
.block-lbl-note { text-transform: none; letter-spacing: 0; font-weight: 500; color: #94A3B8; }

/* entity chips inside source card */
.ent-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.ent-chip {
    --ec: #E8177F;
    font-size: 0.73rem; padding: 4px 9px; border-radius: 100px;
    background: color-mix(in srgb, var(--ec) 10%, white);
    color: color-mix(in srgb, var(--ec) 80%, #1E293B);
    border: 1px solid color-mix(in srgb, var(--ec) 25%, transparent);
    font-weight: 500;
}
.ent-chip b { font-weight: 700; margin-right: 3px; }

/* topic mix inside source card */
.topic-mix { display: flex; flex-direction: column; gap: 4px; }
.tm-row { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 10px; align-items: center; font-size: 0.8rem; }
.tm-row .tm-lbl { color: #334155; }
.tm-row .tm-bar { background: #F1F5F9; height: 8px; border-radius: 3px; overflow: hidden; }
.tm-row .tm-bar > span { display: block; height: 100%; border-radius: 3px; }
.tm-row .tm-pct { font: 500 0.72rem/1 ui-monospace, monospace; color: #64748B; text-align: right; }

/* discriminating tokens */
.disc-tokens { display: flex; flex-wrap: wrap; gap: 5px; }
.disc-token {
    font-size: 0.75rem; padding: 3px 9px; border-radius: 4px;
    background: #F8FAFC; color: #475569;
    border: 1px solid #E2E8F0; font-family: ui-monospace, monospace;
}
.disc-token:hover { border-color: #E8177F; color: #E8177F; }

/* docs tab */
.doc-toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.doc-toolbar input[type=search],
.doc-toolbar select,
.fact-toolbar input[type=search],
.fact-toolbar select {
    font: inherit; font-size: 0.88rem; padding: 8px 12px; border: 1px solid #CBD5E1; border-radius: 6px; background: #fff;
}
.doc-toolbar input[type=search] { flex: 1; min-width: 240px; }
.doc-toolbar input[type=search]:focus,
.fact-toolbar input[type=search]:focus { outline: none; border-color: #E8177F; box-shadow: 0 0 0 3px rgba(232,23,127,0.1); }
.doc-count { font-size: 0.82rem; color: #64748B; font-variant-numeric: tabular-nums; margin-left: auto; }
.loading-msg { padding: 24px; text-align: center; color: #64748B; font-size: 0.88rem; }

.doc-list { background: #fff; border: 1px solid #E2E8F0; border-radius: 10px; overflow: hidden; }
.doc-row {
    display: grid; grid-template-columns: 80px 1fr 110px 70px; gap: 14px;
    padding: 10px 16px; border-top: 1px solid #F1F5F9; align-items: center;
    cursor: pointer; transition: background 0.05s;
}
.doc-row:first-child { border-top: 0; }
.doc-row:hover { background: #FFF5F9; }
.doc-row .src-chip { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 100px; text-align: center; text-transform: uppercase; letter-spacing: 0.04em; }
.doc-row .title { font-size: 0.88rem; color: #1E293B; font-weight: 500; line-height: 1.4; }
.doc-row .title em { display: block; font-style: normal; font-size: 0.75rem; color: #64748B; font-weight: 400; margin-top: 2px; }
.doc-row .yr { font-size: 0.8rem; color: #64748B; font-family: ui-monospace, monospace; text-align: right; }
.doc-row .nf { font-size: 0.8rem; color: #64748B; font-family: ui-monospace, monospace; text-align: right; }

.doc-pager { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 18px 0 0; font-size: 0.85rem; color: #64748B; }
.doc-pager button { font: 600 0.82rem/1 inherit; padding: 8px 14px; background: #fff; border: 1px solid #CBD5E1; border-radius: 6px; cursor: pointer; color: #334155; }
.doc-pager button:hover:not(:disabled) { border-color: #E8177F; color: #E8177F; background: #FFF5F9; }
.doc-pager button:disabled { opacity: 0.4; cursor: default; }

.btn { font: 600 0.82rem/1 inherit; padding: 8px 14px; background: #fff; border: 1px solid #CBD5E1; border-radius: 6px; cursor: pointer; color: #334155; }
.btn:hover { border-color: #E8177F; color: #E8177F; background: #FFF5F9; }

/* factoids */
.fact-toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.fact-toolbar input[type=search] { flex: 1; min-width: 200px; }
.fact-caption { font-size: 0.82rem; color: #64748B; margin-left: auto; }

.fact-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.fact-card {
    background: #fff; border: 1px solid #E2E8F0; border-radius: 10px;
    padding: 14px 16px; display: flex; flex-direction: column; gap: 8px;
    border-left: 3px solid var(--accent, #E8177F);
}
.fact-card .txt { font-size: 0.88rem; color: #1E293B; line-height: 1.5; }
.fact-card .meta { font-size: 0.7rem; color: #64748B; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: auto; }
.fact-card .meta .chip { font-size: 0.64rem; font-weight: 700; padding: 2px 7px; border-radius: 100px; background: var(--accent-soft, #FFF5F9); color: var(--accent, #E8177F); letter-spacing: 0.04em; text-transform: uppercase; }
.fact-card .meta .dt { color: #475569; font-weight: 500; }
.fact-card .meta .len-pill { font-size: 0.65rem; padding: 1px 7px; border-radius: 100px; background: #F1F5F9; color: #64748B; font-family: ui-monospace, monospace; margin-left: auto; }
.fact-card .txt mark { background: #FFE5F0; color: #1E293B; padding: 0 2px; border-radius: 2px; font-weight: 600; }

/* tree */
.tree-hint { color: #64748B; font-size: 0.9rem; margin-bottom: 14px; }
.tree-view {
    background: #fff; border: 1px solid #E2E8F0; border-radius: 10px;
    padding: 14px 20px 20px; font-size: 0.88rem;
}
.tree-src, .tree-doc { user-select: none; }
.tree-src > .hd, .tree-doc > .hd {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 6px; border-radius: 6px; cursor: pointer;
}
.tree-src > .hd:hover, .tree-doc > .hd:hover { background: #F1F5F9; }
.tree-src > .hd .caret, .tree-doc > .hd .caret { color: #94A3B8; font-size: 0.7rem; width: 10px; }
.tree-src > .hd .nm { font-weight: 700; color: #1E293B; display: flex; align-items: center; gap: 10px; }
.tree-src > .hd .nm .dot { width: 10px; height: 10px; border-radius: 50%; }
.tree-src > .hd .count { font: 500 0.76rem/1 ui-monospace, monospace; color: #64748B; margin-left: auto; }
.tree-src[open] > .hd > .caret::before { content: '▾'; }
.tree-src:not([open]) > .hd > .caret::before { content: '▸'; }
.tree-src .children { display: none; padding-left: 22px; margin-top: 4px; border-left: 1px solid #F1F5F9; margin-left: 10px; }
.tree-src[open] > .children { display: block; }

.tree-doc > .hd .title { flex: 1; color: #334155; font-size: 0.84rem; line-height: 1.4; }
.tree-doc > .hd .title em { display: block; font-style: normal; font-size: 0.72rem; color: #94A3B8; margin-top: 1px; }
.tree-doc > .hd .nf { font: 500 0.72rem/1 ui-monospace, monospace; color: #94A3B8; }
.tree-doc[open] > .hd .caret::before { content: '▾'; }
.tree-doc:not([open]) > .hd .caret::before { content: '▸'; }
.tree-doc .facts { display: none; padding: 8px 0 8px 22px; margin-left: 4px; border-left: 2px solid #FFE5F0; margin-top: 2px; margin-bottom: 4px; }
.tree-doc[open] > .facts { display: block; }
.tree-doc .facts .f { font-size: 0.82rem; color: #334155; line-height: 1.55; padding: 4px 6px; }
.tree-doc .facts .f::before { content: '•'; color: #E8177F; margin-right: 8px; font-weight: 700; }

/* modal (doc detail) */
.modal { position: fixed; inset: 0; background: rgba(10,20,32,0.6); backdrop-filter: blur(4px); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; padding: 26px 32px 32px; max-width: 720px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.35); position: relative; }
.modal-close { position: absolute; top: 10px; right: 12px; background: transparent; border: 0; font-size: 1.5rem; color: #64748B; padding: 4px 10px; border-radius: 5px; cursor: pointer; }
.modal-close:hover { background: #F1F5F9; color: #1E293B; }
.modal-card h2 { font-size: 1.15rem; margin-bottom: 8px; padding-right: 30px; line-height: 1.4; }
.modal-card .kv { display: flex; gap: 10px; font-size: 0.85rem; padding: 3px 0; }
.modal-card .kv .k { min-width: 90px; color: #64748B; font-weight: 500; }
.modal-card .kv .v { color: #1E293B; flex: 1; }
.modal-card .note { margin-top: 14px; padding: 10px 14px; background: #FFF5F9; border-left: 3px solid #E8177F; border-radius: 4px; color: #334155; font-size: 0.85rem; }
.modal-card .ext-links { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.modal-card .ext-links a { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 6px; background: #FFF5F9; color: #E8177F; font-size: 0.78rem; font-weight: 600; text-decoration: none; border: 1px solid rgba(232,23,127,0.25); }
.modal-card .ext-links a:hover { background: #E8177F; color: #fff; }
.modal-card .fact-block { margin-top: 18px; padding-top: 14px; border-top: 1px solid #E2E8F0; }
.modal-card .fact-block h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: #64748B; margin-bottom: 10px; font-weight: 700; }
.modal-card .fact-block .f { font-size: 0.85rem; color: #1E293B; padding: 6px 8px; border-left: 2px solid #FFE5F0; margin: 4px 0; line-height: 1.55; }

/* loader */
.loader { position: fixed; inset: 0; background: #F8FAFC; display: flex; align-items: center; justify-content: center; color: #64748B; font-size: 0.95rem; z-index: 200; transition: opacity 0.25s; }
.loader.hide { opacity: 0; pointer-events: none; }

@media (max-width: 900px) {
    .overview-grid { grid-template-columns: 1fr; }
    .pipeline { grid-template-columns: 1fr 1fr; }
    .doc-row { grid-template-columns: 60px 1fr 60px; }
    .doc-row .yr { display: none; }
    #view { padding: 20px 16px; }
    .tabs { overflow-x: auto; white-space: nowrap; }
}
