:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #6b7280;
  --line: #dfe3e8;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --viewport: #101418;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --panel: #1e2227;
    --ink: #e8eaed;
    --muted: #9aa3ad;
    --line: #2e343b;
    --accent: #6b9bff;
    --accent-ink: #10131a;
    --viewport: #0b0e11;
  }
}

* { box-sizing: border-box; }
/* A class selector beats the UA [hidden] rule, so restate it with weight. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; margin: 0; letter-spacing: 0.2px; }
.topbar h1 span { color: var(--muted); font-weight: 400; }
.topbar-meta { display: flex; align-items: center; gap: 10px; }
.status {
  font-size: 12px; color: var(--muted); font-family: var(--mono);
  min-width: 16ch; text-align: right;
}
.status.busy { color: var(--accent); }
.status.error { color: var(--danger); }

.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }

.sidebar {
  border-right: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; display: flex; flex-direction: column;
}
.panel { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel.grow {
  flex: 1; min-height: 180px;
  /* A column so the list takes the slack and scrolls, leaving the Apply row
     and Auto-update anchored instead of overflowing the next panel. */
  display: flex; flex-direction: column; min-width: 0;
}
.panel.grow > .neuron-list { flex: 1; overflow-y: auto; min-height: 150px; }
/* An expanded cell panel needs real room; let the whole sidebar scroll
   rather than squeezing the list into a two-row porthole. */
.panel.grow { flex: 1 0 auto; }
.panel h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 0 0 8px;
}
.pill {
  background: var(--line); border-radius: 999px; padding: 1px 7px;
  font-size: 11px; color: var(--ink);
}

.row { display: flex; gap: 6px; margin-bottom: 8px; }
.row input { flex: 1; min-width: 0; }
input, select, button, output {
  font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); padding: 5px 8px;
}
input[type=range] { padding: 0; }
button { cursor: pointer; background: var(--panel); }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.wide { width: 100%; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 13px; }
.field {
  display: flex; align-items: center; gap: 6px; margin: 6px 0;
  font-size: 13px; color: var(--muted); flex-wrap: wrap;
}
.field input, .field select { flex: 1; min-width: 70px; color: var(--ink); }
.filebtn {
  display: block; text-align: center; margin-top: 8px; padding: 5px;
  border: 1px dashed var(--line); border-radius: 6px; cursor: pointer; font-size: 13px;
}
.filebtn:hover { border-color: var(--accent); }

.search-results { list-style: none; margin: 0 0 8px; padding: 0; max-height: 160px; overflow-y: auto; }
.search-results li {
  padding: 4px 6px; border-radius: 4px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 8px; font-size: 13px;
}
.search-results li:hover { background: var(--bg); }
.search-results .id { font-family: var(--mono); color: var(--muted); }

.neuron-list { list-style: none; margin: 0; padding: 0; min-width: 0; }
.neuron-item {
  /* disclosure, visible, swatch, name, method tag, unload */
  display: grid; grid-template-columns: auto auto auto 1fr auto auto; gap: 5px;
  align-items: center; padding: 6px 4px; border-bottom: 1px solid var(--line);
}
.neuron-item.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.swatch {
  width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line);
  padding: 0; cursor: pointer;
}
.neuron-name { min-width: 0; cursor: pointer; }
.neuron-name b { display: block; font-family: var(--mono); font-size: 12px; }
.neuron-name small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: none; background: none; color: var(--muted); padding: 2px 4px; }
.icon-btn:hover { color: var(--danger); }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 6px 10px 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  border: 1px solid transparent; border-bottom: none;
  border-radius: 6px 6px 0 0; padding: 6px 12px; background: none; color: var(--muted);
}
.tab.active { background: var(--bg); border-color: var(--line); color: var(--ink); }

.views { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }

#viewport, #cy { flex: 1; min-height: 0; background: var(--viewport); position: relative; overflow: hidden; }
#viewport canvas { display: block; width: 100% !important; height: 100% !important; }
#cy { background: var(--panel); }
.viewport-overlay {
  position: absolute; top: 10px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; gap: 12px;
  pointer-events: none; font-size: 12px; color: #cfd6de;
}
.picked { font-family: var(--mono); background: rgba(0,0,0,0.45); padding: 4px 8px; border-radius: 6px; }
.hint { background: rgba(0,0,0,0.35); padding: 4px 8px; border-radius: 6px; }
kbd {
  font-family: var(--mono); font-size: 11px; background: rgba(255,255,255,0.14);
  border-radius: 3px; padding: 0 4px;
}
.viewport-tools, .table-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line);
}
.viewport-tools .field, .table-tools .field { margin: 0; }
.muted { color: var(--muted); font-size: 12px; }

.chart-wrap { flex: 1; min-height: 0; padding: 12px; overflow: auto; }
#strata-chart svg { width: 100%; height: auto; max-height: 100%; }
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line);
}
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 9px; }
.stat dt { font-size: 11px; color: var(--muted); }
.stat dd { margin: 2px 0 0; font-family: var(--mono); font-size: 14px; }

.table-scroll { flex: 1; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; font-family: var(--mono); }
th, td { text-align: right; padding: 3px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); text-align: right; z-index: 1; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.cards { padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; }
.card table { font-size: 12px; }
.card td:first-child, .card th:first-child { text-align: left; }
.card .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* -- deploy notification --------------------------------------------------- */
.update-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
}
.update-banner[hidden] { display: none; }
.update-banner button.primary {
  background: var(--accent-ink);
  color: var(--accent);
  border-color: var(--accent-ink);
}
.update-banner .icon-btn { color: var(--accent-ink); margin-left: auto; }
.update-banner .icon-btn:hover { color: var(--accent-ink); opacity: 0.7; }

/* -- per-neuron render settings -------------------------------------------- */
.apply-row { display: flex; gap: 6px; margin-top: 10px; }
.apply-row button { flex: 1; min-width: 0; padding-inline: 6px; font-size: 12px; }
.scope-note { margin: 6px 0 8px; line-height: 1.4; }
/* The panel no longer matches what is on screen -- Apply would change it. */
.scope-note.pending { color: var(--accent); }

/* Method tag on each row of the loaded list, so differing render styles are
   visible without selecting each neuron in turn. */
.neuron-method {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 4px;
  cursor: pointer;
  background: none;
}
.neuron-method:hover { color: var(--ink); border-color: var(--accent); }
.neuron-method.stale { color: var(--danger); border-color: var(--danger); }

/* -- per-cell display panel ------------------------------------------------ */
/* The row is a grid; the expanded panel is a second row spanning every column. */
.neuron-item { grid-template-areas: none; }
.disclosure {
  border: none; background: none; color: var(--muted);
  padding: 0 2px; cursor: pointer; font-size: 10px; line-height: 1;
  transition: transform 0.12s ease;
}
.disclosure[aria-expanded="true"] { transform: rotate(90deg); color: var(--ink); }
.cell-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 8px;
  align-items: center;
  margin: 6px 0 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  font-size: 12px;
}
.cell-panel .full { grid-column: 1 / -1; }
.cell-panel label.check { margin: 0; }
.cell-panel input[type="range"] { width: 100%; }
.cell-panel input[type="color"] {
  width: 28px; height: 20px; padding: 0; border: 1px solid var(--line);
  border-radius: 3px; cursor: pointer;
}
.cell-panel select, .cell-panel input[type="number"] { width: 100%; font-size: 12px; }
.cell-panel .sub {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: auto 1fr; gap: 5px 8px;
  align-items: center;
  margin-left: 10px; padding-left: 8px;
  border-left: 2px solid var(--line);
}
.cell-panel .note { grid-column: 1 / -1; color: var(--muted); font-size: 11px; margin: 0; }
.cell-panel label.check.disabled { opacity: 0.45; cursor: not-allowed; }

/* -- annotations context menu --------------------------------------------- */
.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 190px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
}
.context-menu[hidden] { display: none; }
.context-menu button {
  display: block; width: 100%; text-align: left;
  border: none; background: none; color: var(--ink);
  padding: 7px 10px; font-size: 13px; border-radius: 4px; cursor: pointer;
}
.context-menu button:hover { background: var(--accent); color: var(--accent-ink); }
tr.ctx-target { outline: 1px solid var(--accent); outline-offset: -1px; }

/* Marker dropped on the annotation a fly-to landed on. */
.flyto-note {
  position: absolute; left: 12px; bottom: 44px;
  padding: 5px 10px; font-size: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--accent); border-radius: var(--radius);
}

/* -- narrow viewports ------------------------------------------------------ */
/* The sidebar is a fixed 300px track, so below about 420px the grid overflows
   and the whole page renders as a squeezed column with a horizontal scrollbar.
   That shows up transiently whenever the page paints before the container has
   its real width (a background tab, an embedded pane), not only on a phone. */
@media (max-width: 720px) {
  .layout { grid-template-columns: 220px 1fr; }
}
@media (max-width: 480px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 45vh;
  }
  .topbar { flex-wrap: wrap; gap: 6px; }
}

/* -- per-synapse-type rows ------------------------------------------------- */
.type-row {
  grid-column: 1 / -1;
  padding: 5px 0;
  border-top: 1px solid var(--line);
}
.type-row:first-of-type { border-top: none; }
.type-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
}
.type-dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  flex: none;
}
.type-name {
  font-family: var(--mono); font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.type-count {
  margin-left: auto; color: var(--muted); font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.type-reset { font-size: 13px; line-height: 1; flex: none; }
.type-reset:disabled { opacity: 0.3; cursor: default; }
.type-reset:not(:disabled):hover { color: var(--accent); }
.type-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 8px;
  align-items: center; margin: 5px 0 2px 16px;
}
.type-grid label { font-size: 11px; color: var(--muted); }
.type-grid input[type="range"] { width: 100%; }
.type-grid select { font-size: 11px; }
.type-grid input[type="color"] {
  width: 26px; height: 18px; padding: 0;
  border: 1px solid var(--line); border-radius: 3px; cursor: pointer;
}
