/* NESO Corpus Explorer — tokens & components.
   Palette per the validated dataviz reference instance (see CONTRACT.md). */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;      /* cards / chart surface */
  --page:      #f9f9f7;      /* page plane */
  --ink:       #0b0b0b;
  --ink-2:     #52514e;
  --muted:     #898781;
  --grid:      #e1e0d9;
  --axis:      #c3c2b7;
  --border:    rgba(11,11,11,0.10);
  --accent:    #2a78d6;
  --accent-soft: #cde2fb;
  --mark-bg:   #fdedb1;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --shadow: 0 1px 3px rgba(11,11,11,0.06), 0 4px 16px rgba(11,11,11,0.05);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19; --page: #0d0d0d;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
    --accent: #3987e5; --accent-soft: #184f95; --mark-bg: #5a4a12;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19; --page: #0d0d0d;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
  --accent: #3987e5; --accent-soft: #184f95; --mark-bg: #5a4a12;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.3);
}

html, body { height: 100%; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 218px; flex: none; display: flex; flex-direction: column;
  background: var(--surface-1); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; padding: 18px 12px 12px;
}
.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }

.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent);
  color: #fff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 650; letter-spacing: .01em; }
.brand-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); }
.nav-ico { width: 18px; text-align: center; font-size: 13px; opacity: .85; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.extract-box { padding: 10px; border: 1px solid var(--border); border-radius: 10px; }
.extract-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin-bottom: 6px; }
.extract-bar { height: 5px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.extract-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width .6s; }
.extract-detail { font-size: 10.5px; color: var(--muted); margin-top: 5px; }
.theme-toggle {
  border: 1px solid var(--border); background: none; color: var(--ink-2);
  border-radius: 8px; padding: 7px; cursor: pointer; font: inherit; font-size: 12px;
}
.theme-toggle:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }

/* ---- generic components ---- */
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 21px; font-weight: 650; }
.page-head .sub { color: var(--muted); margin-top: 3px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px;
}
.card h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }

.grid { display: grid; gap: 14px; }
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .t-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tile .t-value { font-size: 24px; font-weight: 650; margin-top: 4px; }
.tile .t-sub { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--accent); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 500;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
  cursor: pointer; border: none; font-family: inherit;
}
.chip:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); text-decoration: none; }
.chip.gray { background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--ink-2); }
.chip .x { opacity: .6; font-weight: 700; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.badge.pdf { background: color-mix(in srgb, var(--series-8) 14%, transparent); color: var(--series-8); }
.badge.html, .badge.htm { background: color-mix(in srgb, var(--series-1) 14%, transparent); color: var(--series-1); }
.badge.docx, .badge.doc, .badge.dotx { background: color-mix(in srgb, var(--series-3) 16%, transparent); color: var(--series-3); }
.badge.pptx, .badge.ppt { background: color-mix(in srgb, var(--series-2) 14%, transparent); color: var(--series-2); }
.badge.other { background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--ink-2); }
.badge.gone { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical); }

mark { background: var(--mark-bg); color: inherit; border-radius: 2px; padding: 0 1px; }

input[type="text"], input[type="search"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
button.btn {
  font: inherit; font-weight: 550; border: none; border-radius: 9px;
  padding: 8px 15px; cursor: pointer; background: var(--accent); color: #fff;
}
button.btn:hover { filter: brightness(1.08); }
button.btn[disabled] { opacity: .5; cursor: default; }
button.btn.ghost { background: none; color: var(--ink-2); border: 1px solid var(--border); }
button.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); filter: none; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button {
  font: inherit; font-size: 12.5px; border: none; background: none; color: var(--ink-2);
  padding: 6px 13px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-weight: 600; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--grid); }
table.data td { padding: 7px 10px; 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: color-mix(in srgb, var(--ink) 3%, transparent); }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; margin: 30px auto;
  border: 3px solid var(--grid); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { color: var(--muted); text-align: center; padding: 34px 10px; }

.toast-holder { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast {
  background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--critical);
  border-radius: 9px; box-shadow: var(--shadow); padding: 10px 14px; font-size: 13px; max-width: 340px;
}

/* ---- search view ---- */
.search-layout { display: grid; grid-template-columns: 232px 1fr; gap: 20px; align-items: start; }
.facets { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 20px; }
.facet-group h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 7px; }
.facet-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 3px 7px; border-radius: 6px;
  cursor: pointer; font-size: 12.5px; color: var(--ink-2);
}
.facet-row:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.facet-row.on { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-weight: 600; }
.facet-row .cnt { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.result {
  padding: 13px 2px; border-bottom: 1px solid var(--grid);
}
.result .r-title { font-size: 14.5px; font-weight: 550; }
.result .r-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.result .r-snippet { color: var(--ink-2); font-size: 12.8px; margin-top: 5px; }

/* ---- doc viewer ---- */
.doc-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.doc-frame { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1); }
.doc-text { white-space: pre-wrap; font-size: 13px; line-height: 1.65; max-height: 78vh; overflow: auto; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 10px; font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { overflow-wrap: anywhere; }
.rel-item { padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 12.5px; }
.rel-item:last-child { border-bottom: none; }

/* ---- charts ---- */
.chart { width: 100%; }
.chart-lg { height: 430px; } .chart-md { height: 330px; } .chart-sm { height: 230px; }
.controls-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }

/* ---- SME chat ---- */
.chat { max-width: 850px; margin: 0 auto; display: flex; flex-direction: column; min-height: 70vh; }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 20px; }
.msg { max-width: 88%; border-radius: 14px; padding: 11px 15px; }
.msg.user { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, transparent); }
.msg.assistant { align-self: flex-start; background: var(--surface-1); border: 1px solid var(--border); box-shadow: var(--shadow); }
.msg .cite-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.cite-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 11.5px;
  max-width: 240px; background: var(--page); cursor: pointer;
}
.cite-card:hover { border-color: var(--accent); text-decoration: none; }
.cite-n { font-weight: 700; color: var(--accent); margin-right: 4px; }
.chat-input { display: flex; gap: 9px; position: sticky; bottom: 0; padding: 12px 0 4px; background: var(--page); }
.chat-input textarea { flex: 1; resize: none; height: 52px; }
.suggest-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }

.mode-note { font-size: 11px; color: var(--muted); margin-top: 8px; }
.insight-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.insight-card { border-left: 3px solid var(--accent); }
.insight-card .metric { font-size: 20px; font-weight: 650; margin: 4px 0; }
.insight-card p { font-size: 12.5px; color: var(--ink-2); }

@media (max-width: 1000px) {
  .search-layout, .doc-layout { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .brand-name, .brand-sub, .nav a span:not(.nav-ico), .extract-box, .theme-toggle { display: none; }
}
