/* BiblioAI app styles. Colours are tokens; dark mode has its own steps. */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #7a7974;
  --line: #e2e0da;
  --grid: #ecebe6;
  --side: #17202b;
  --side-ink: #c9d1da;
  --side-ink-2: #7f8b98;
  --side-active: #243242;
  --accent: #c8642d;
  --accent-ink: #ffffff;
  --accent-soft: #fbeee6;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --other: #b9b8b2;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-ink: #006300; --critical-ink: #b42323;
  --warn-bg: #fff6e0; --crit-bg: #fdecec;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #8f8e86;
    --line: #34342f; --grid: #2a2a27; --side: #0d1117; --side-ink: #c9d1da; --side-ink-2: #6b7682; --side-active: #1c2633;
    --accent: #e08a55; --accent-ink: #111110; --accent-soft: #3a2619;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767; --other: #5c5b56;
    --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
    --good-ink: #5fd35f; --critical-ink: #f08080; --warn-bg: #3a2f12; --crit-bg: #3a1a1a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #8f8e86;
  --line: #34342f; --grid: #2a2a27; --side: #0d1117; --side-ink: #c9d1da; --side-ink-2: #6b7682; --side-active: #1c2633;
  --accent: #e08a55; --accent-ink: #111110; --accent-soft: #3a2619;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767; --other: #5c5b56;
  --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
  --good-ink: #5fd35f; --critical-ink: #f08080; --warn-bg: #3a2f12; --crit-bg: #3a1a1a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.app.collapsed { grid-template-columns: 64px 1fr; }
.side { background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-size: 19px; font-weight: 700; color: #fff; border-bottom: 1px solid #ffffff14; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand .logo svg { width: 18px; height: 18px; }
.brand b { color: var(--accent); }
.brand .collapse { margin-left: auto; background: none; border: 0; color: var(--side-ink-2); cursor: pointer; font-size: 18px; }
.nav-group { padding: 14px 16px 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--side-ink-2); }
.side nav a { display: flex; align-items: center; gap: 12px; padding: 9px 18px; color: var(--side-ink); text-decoration: none; font-size: 13.5px; border-left: 3px solid transparent; }
.side nav a:hover { background: #ffffff0a; }
.side nav a.on { background: var(--side-active); border-left-color: var(--accent); color: #fff; font-weight: 600; }
.side nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.side .foot { margin-top: auto; padding: 14px 16px; font-size: 12px; color: var(--side-ink-2); border-top: 1px solid #ffffff14; }
.app.collapsed .side nav span, .app.collapsed .nav-group, .app.collapsed .brand span, .app.collapsed .side .foot { display: none; }
.app.collapsed .side nav a { justify-content: center; padding: 11px 0; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 22px; position: sticky; top: 0; z-index: 20; }
.topbar .row1 { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.topbar h1 { font-size: 15px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13px; white-space: nowrap; }
.pill .count { background: var(--ink); color: var(--surface); border-radius: 999px; padding: 0 8px; font-size: 11.5px; font-weight: 600; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
a.btn { color: var(--ink); text-decoration: none; }
a.btn.primary { color: var(--accent-ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 600; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 40%, var(--line)); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 14px; height: 14px; }
.yr { width: 70px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.dropdown { position: relative; }
.menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 24px #0002; padding: 8px; min-width: 210px; max-height: 340px; overflow: auto; display: none; }
.dropdown.open .menu { display: block; }
.menu label { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.menu label:hover { background: var(--surface-2); }
.menu .muted { padding: 4px 6px; }
.menu button.item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 5px; cursor: pointer; }
.menu button.item:hover { background: var(--surface-2); }
.showing { color: var(--ink-2); font-size: 12.5px; }
.showing b { color: var(--ink); }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 22px; background: var(--warn-bg); border-bottom: 1px solid var(--line); font-size: 13px; }
.banner.crit { background: var(--crit-bg); }
.banner .x { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--ink-2); font-size: 16px; }

.page { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.page-head { margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 22px; display: flex; gap: 10px; align-items: center; }
.page-head p { margin: 2px 0 0; color: var(--ink-2); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .tools { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.card-body { padding: 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.controls select, .controls input { padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.controls input[type=number] { width: 70px; }
.chart-box { position: relative; height: 380px; }
.chart-box.tall { height: 560px; }
.chart-box.short { height: 260px; }
.net-box { height: 560px; border-radius: 8px; background: var(--surface); }
.card.expanded { position: fixed; inset: 16px; z-index: 50; overflow: auto; margin: 0; box-shadow: 0 10px 40px #0005; }
.card.expanded .chart-box, .card.expanded .net-box { height: calc(100vh - 170px); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; cursor: pointer; color: var(--ink-2); font-size: 13.5px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: var(--surface-2); }
.table-wrap { overflow: auto; max-height: 560px; }
.rank-list { max-height: 520px; overflow: auto; font-size: 13px; }
.rank-list div { display: flex; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--grid); }
.rank-list i { font-style: normal; color: var(--ink-3); width: 22px; text-align: right; flex: none; }
.rank-list span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list b { font-variant-numeric: tabular-nums; }

.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 180px; }
.bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; }
.status { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12.5px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.good { color: var(--good-ink); } .status.warning { color: #a66f00; } .status.critical { color: var(--critical-ink); }

.score { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.score-ring { width: 120px; height: 120px; flex: none; }
.score-parts { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; }
.field label small { font-weight: 400; color: var(--ink-2); }
.field input[type=text], .field input[type=number], .field textarea, .field select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.field textarea { min-height: 70px; resize: vertical; }
.field textarea.code { font: 12.5px/1.45 ui-monospace, Consolas, monospace; min-height: 120px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer; color: var(--ink-2); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.log { font: 12.5px/1.5 ui-monospace, Consolas, monospace; color: var(--ink-2); white-space: pre-wrap; max-height: 200px; overflow: auto; margin: 0; }
.err { color: var(--critical-ink); font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 12.5px; }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
select.dec { padding: 3px 6px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }
.empty h3 { color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); padding: 8px 16px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.group-row { padding: 10px 0; border-bottom: 1px solid var(--grid); display: flex; gap: 12px; align-items: flex-start; }
.group-row .variants { flex: 1; }
.tag { display: inline-block; padding: 1px 8px; margin: 2px 4px 2px 0; border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.report-item { display: flex; gap: 14px; padding: 14px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.report-item img { max-width: 360px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.report-item .body { flex: 1; min-width: 0; }
.report-item .body .table-wrap { max-height: 220px; }
.flow svg { width: 100%; max-width: 820px; display: block; margin: 0 auto; }
.flow svg text { fill: var(--ink); font-size: 12px; }
.flow .editable { cursor: pointer; }
.flow .editable:hover rect { stroke: var(--accent); }
.wordcloud { width: 100%; height: 480px; }
.hidden { display: none !important; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 9px 18px; border-radius: 8px; z-index: 100; font-size: 13px; }
