:root {
  --bg: #0f1216;
  --panel: #171c22;
  --line: #2a323c;
  --fg: #e6ebf1;
  --muted: #8b98a6;
  --accent: #4da3ff;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .5px; color: var(--fg); }
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active, .topbar nav a:hover { color: var(--fg); }
.spacer { flex: 1; }
.who { color: var(--muted); }
form.inline { display: inline; }
button.link {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font: inherit; padding: 0;
}
button.link:hover { color: var(--fg); }

main { max-width: 1100px; margin: 0 auto; padding: 24px 18px 64px; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 17px; margin: 28px 0 10px; }
.muted { color: var(--muted); }

.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 18px; min-width: 140px;
}
.card .num { font-size: 26px; font-weight: 700; }
.card .lbl { color: var(--muted); }

ol.todo { color: var(--muted); }
ol.todo li { margin: 4px 0; }

/* ── Catalog ── */
.filters {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px; margin: 14px 0 18px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.filters select, .filters input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; color: var(--fg); font: inherit;
}
.filters button {
  background: var(--accent); border: none; border-radius: 6px; color: #06121f;
  padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.filters .reset { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td {
  border-bottom: 1px solid var(--line); padding: 6px 8px;
  text-align: left; vertical-align: top;
}
.grid th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.grid td.num { text-align: right; white-space: nowrap; }
.grid tbody tr:hover { background: #1b2129; }

/* Sortable headers */
.grid th.sorted a { color: var(--accent); }
.grid th a { color: var(--muted); }
.grid th a:hover { color: var(--fg); text-decoration: none; }
.grid th .arrow { font-size: 10px; margin-left: 2px; }

/* Model table: the config column is the flexible one, everything else is
   fixed-width so a long name cannot push the layout wider than the screen. */
.grid.models { table-layout: fixed; width: 100%; }
.grid.models td.cfg {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: ui-monospace, monospace; font-size: 12px;
}
.grid.models td.mono { white-space: nowrap; font-size: 12px; }
.grid.models th.num, .grid.models td.num { text-align: right; }
.grid.models col.c-run { width: 104px; }
.grid.models col.c-name { width: auto; }
.grid.models col.c-kind { width: 92px; }
.grid.models col.c-num { width: 76px; }
.grid.models col.c-sm { width: 60px; }
.grid.models col.c-mode { width: 96px; }
.grid.models col.c-date { width: 118px; }

.tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: #22303d; color: #b8d4f0; font-size: 11px;
}
.tag.k-ae { background: #1f3a2b; color: #a9e5bf; }
.tag.k-recursive { background: #3a2f1f; color: #f0d5a8; }
.tag.k-pairs { background: #33223d; color: #dcb8f0; }
.tag.k-e2e { background: #3d2226; color: #f0b8c0; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 16px; margin: 14px 0;
}
.panel h2 { margin: 0 0 8px; }
pre.mono { white-space: pre-wrap; word-break: break-word; }

.button {
  display: inline-block; background: var(--accent); color: #06121f;
  padding: 7px 14px; border-radius: 6px; font-weight: 600; margin-right: 8px;
}
.button.ghost { background: none; border: 1px solid var(--line); color: var(--fg); }
.button:hover { text-decoration: none; filter: brightness(1.08); }

.error { color: var(--error); }

/* ── Inference ── */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.row input, .row select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; color: var(--fg); font: inherit;
}
.row button, .panel > button {
  background: var(--accent); border: none; border-radius: 6px; color: #06121f;
  padding: 7px 12px; font: inherit; font-weight: 600; cursor: pointer;
}
.row button:hover { filter: brightness(1.08); }

.out {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px; margin-top: 10px; white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  max-height: 420px; overflow: auto;
}
.out .line { display: flex; gap: 8px; margin: 2px 0; }
.out .line .lbl { color: var(--muted); min-width: 64px; }
.out .line .val { white-space: pre-wrap; word-break: break-word; }
.good { color: #a9e5bf; }
.warn { color: #f0d5a8; }

.tree-level { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.tree-level-label { color: var(--muted); font-size: 12px; min-width: 72px; }
.node {
  background: #22303d; border: 1px solid var(--line); color: var(--fg);
  border-radius: 5px; padding: 3px 7px; font-size: 11px; cursor: pointer;
  font-family: ui-monospace, monospace;
}
.node.leaf { background: #1f3a2b; }
.node:hover { border-color: var(--accent); }

/* ── Latents / heat map ── */
.grow { flex: 1 1 320px; }
textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; color: var(--fg); font: inherit; width: 100%; resize: vertical;
}
.grid-host { margin: 8px 0; }
.grid-head { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.heat {
  display: grid; gap: 2px; margin: 4px 0;
  grid-auto-rows: var(--cell); width: max-content;
  --cell: 26px;
}
.heat .cell {
  width: var(--cell); height: var(--cell); border: 1px solid #0b0e12;
  border-radius: 2px;
}
.heat .cell:hover { outline: 1px solid var(--accent); }
button.ghost {
  background: none; border: 1px solid var(--line); color: var(--fg);
  padding: 6px 10px; border-radius: 6px; font: inherit; cursor: pointer;
}

/* ── Tree (SVG) ── */
.tree-svg {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  margin: 8px 0; max-width: 100%; overflow: auto;
}
.tree-svg .edge { stroke: #46525f; stroke-width: 1.2; fill: none; }
.tree-svg g.tnode { cursor: pointer; }
.tree-svg g.tnode rect { fill: #22303d; stroke: #3a4753; }
.tree-svg g.tnode.leaf rect { fill: #1f3a2b; }
.tree-svg g.tnode text { fill: var(--fg); font-size: 10px; font-family: ui-monospace, monospace; }
.tree-svg g.tnode:hover rect { stroke: var(--accent); }
.tree-svg g.tnode.sel rect { stroke: #ffb454; stroke-width: 2; }
.chip {
  display: inline-block; background: #22303d; border-radius: 4px;
  padding: 2px 7px; font-size: 12px; font-family: ui-monospace, monospace;
}
.scorer h3 { margin: 0 0 6px; font-size: 15px; }

/* ── Monitoring ── */
.scroll-x { overflow-x: auto; }
.scroll-x table { min-width: 100%; }
.chip { margin-right: 4px; }

/* ── Login ── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; margin: 0;
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 28px; width: 320px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { text-align: center; margin-bottom: 6px; letter-spacing: 1px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-card input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; color: var(--fg); font: inherit;
}
.login-card button {
  background: var(--accent); border: none; border-radius: 6px; color: #06121f;
  padding: 9px; font: inherit; font-weight: 600; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.08); }
.error { color: var(--error); margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
