/* Brand constants (fixed in both themes) */
:root {
  --ft-primary: #ee3f24;
  --ft-secondary: #124b83;
  --ft-dark: #171717;
  --row-h: 30px;
  --indent: 20px;
  font-family: Outfit, Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Light theme (default) */
:root {
  color-scheme: light;
  --bg: #fff;
  --surface: #fff;
  --surface-2: #f5f5f5;
  --side-bg: #fcfcfc;
  --border: #e5e5e5;
  --text: #0a0a0a;
  --text-2: #5c5c5c;
  --text-3: #8a8a8a;
  --accent: #124b83;
  --focus-ring: rgba(18, 75, 131, 0.35);
  --header-bg: #124b83;
  --select: rgba(18, 75, 131, 0.09);
  --checked: #fff4f1;
  --checked-selected: #fbe7e2;
  --drop-bg: #e7eef6;
  --flash: #dfe8ff;
  --mark: #ffe3a8;
  --chip-border: #b9c6d4;
  --hover-strong: rgba(0, 0, 0, 0.06);
  --shadow: rgba(0, 0, 0, 0.12);
  --danger: #e40014;
  --green: #00bb7f;
  --moved: #1447e6; --moved-bg: #eef2fe; --moved-border: #b5c6f7;
  --review: #b4232f; --review-bg: #fff3f4; --review-border: #f4b4ba;
  --dup: #8a6500; --dup-bg: #fff9e6; --dup-border: #f0d27a;
  --issue: #e40014; --issue-bg: #fff1f2; --issue-border: #f5a3aa; --issue-text: #9c0010;
  --bulk-bg: #fffaf8; --bulk-border: #f5b8ab;
  --toast-bg: #171717; --toast-error: #8f0010; --toast-action: #ffb3a6;
  --backdrop: rgba(10, 10, 10, 0.4);

  --g-bg: #f4f7f9;
  --g-link: rgba(18, 75, 131, 0.2);
  --g-label: #1d2b36;
  --g-muted: #6b7f8c;
  --g-node: #1b8fb4;
  --g-virtual: #33475b;
  --g-path: #e07812;
  --g-dup: #cf9a00;
  --g-review: #d6404c;
  --g-moved: #3d6be0;
  --g-drop: #1f9d55;
  --g-match: #b25d00;
  --g-overlay: rgba(244, 247, 249, 0.92);
  --g-overlay-border: rgba(18, 75, 131, 0.12);
  --g-btn-border: rgba(27, 143, 180, 0.4);
  --g-hover: rgba(18, 75, 131, 0.08);
}

/* Dark theme: follows the OS unless the user picked light, or forced with data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1a22;
    --surface: #15232d;
    --surface-2: #1b2c37;
    --side-bg: #122029;
    --border: #253744;
    --text: #e6edf1;
    --text-2: #a9b8c2;
    --text-3: #7d909c;
    --accent: #7cb3ea;
    --focus-ring: rgba(124, 179, 234, 0.4);
    --header-bg: #0f2a45;
    --select: rgba(124, 179, 234, 0.14);
    --checked: rgba(238, 63, 36, 0.12);
    --checked-selected: rgba(238, 63, 36, 0.2);
    --drop-bg: rgba(124, 179, 234, 0.18);
    --flash: rgba(124, 179, 234, 0.3);
    --mark: rgba(255, 196, 64, 0.35);
    --chip-border: #3a5162;
    --hover-strong: rgba(255, 255, 255, 0.08);
    --shadow: rgba(0, 0, 0, 0.5);
    --danger: #ff5a66;
    --green: #2fd39a;
    --moved: #8fb3ff; --moved-bg: rgba(143, 179, 255, 0.12); --moved-border: rgba(143, 179, 255, 0.4);
    --review: #ff8f98; --review-bg: rgba(236, 111, 121, 0.12); --review-border: rgba(236, 111, 121, 0.45);
    --dup: #f0c955; --dup-bg: rgba(232, 185, 49, 0.12); --dup-border: rgba(232, 185, 49, 0.45);
    --issue: #ff8f98; --issue-bg: rgba(228, 0, 20, 0.14); --issue-border: rgba(255, 90, 102, 0.45); --issue-text: #ffb3b9;
    --bulk-bg: rgba(238, 63, 36, 0.06); --bulk-border: rgba(238, 63, 36, 0.45);
    --toast-bg: #24343f; --toast-error: #8f0010; --toast-action: #ffb3a6;
    --backdrop: rgba(0, 0, 0, 0.6);

    --g-bg: #11202a;
    --g-link: rgba(150, 182, 198, 0.22);
    --g-label: #dbe6ec;
    --g-muted: #7f96a4;
    --g-node: #5ec4e0;
    --g-virtual: #e9eef1;
    --g-path: #f5a04a;
    --g-dup: #e8b931;
    --g-review: #ec6f79;
    --g-moved: #8fb3ff;
    --g-drop: #7be3a0;
    --g-match: #ffe08a;
    --g-overlay: rgba(17, 32, 42, 0.92);
    --g-overlay-border: rgba(255, 255, 255, 0.06);
    --g-btn-border: rgba(94, 196, 224, 0.35);
    --g-hover: rgba(255, 255, 255, 0.08);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1a22;
  --surface: #15232d;
  --surface-2: #1b2c37;
  --side-bg: #122029;
  --border: #253744;
  --text: #e6edf1;
  --text-2: #a9b8c2;
  --text-3: #7d909c;
  --accent: #7cb3ea;
  --focus-ring: rgba(124, 179, 234, 0.4);
  --header-bg: #0f2a45;
  --select: rgba(124, 179, 234, 0.14);
  --checked: rgba(238, 63, 36, 0.12);
  --checked-selected: rgba(238, 63, 36, 0.2);
  --drop-bg: rgba(124, 179, 234, 0.18);
  --flash: rgba(124, 179, 234, 0.3);
  --mark: rgba(255, 196, 64, 0.35);
  --chip-border: #3a5162;
  --hover-strong: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.5);
  --danger: #ff5a66;
  --green: #2fd39a;
  --moved: #8fb3ff; --moved-bg: rgba(143, 179, 255, 0.12); --moved-border: rgba(143, 179, 255, 0.4);
  --review: #ff8f98; --review-bg: rgba(236, 111, 121, 0.12); --review-border: rgba(236, 111, 121, 0.45);
  --dup: #f0c955; --dup-bg: rgba(232, 185, 49, 0.12); --dup-border: rgba(232, 185, 49, 0.45);
  --issue: #ff8f98; --issue-bg: rgba(228, 0, 20, 0.14); --issue-border: rgba(255, 90, 102, 0.45); --issue-text: #ffb3b9;
  --bulk-bg: rgba(238, 63, 36, 0.06); --bulk-border: rgba(238, 63, 36, 0.45);
  --toast-bg: #24343f; --toast-error: #8f0010; --toast-action: #ffb3a6;
  --backdrop: rgba(0, 0, 0, 0.6);

  --g-bg: #11202a;
  --g-link: rgba(150, 182, 198, 0.22);
  --g-label: #dbe6ec;
  --g-muted: #7f96a4;
  --g-node: #5ec4e0;
  --g-virtual: #e9eef1;
  --g-path: #f5a04a;
  --g-dup: #e8b931;
  --g-review: #ec6f79;
  --g-moved: #8fb3ff;
  --g-drop: #7be3a0;
  --g-match: #ffe08a;
  --g-overlay: rgba(17, 32, 42, 0.92);
  --g-overlay-border: rgba(255, 255, 255, 0.06);
  --g-btn-border: rgba(94, 196, 224, 0.35);
  --g-hover: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  grid-template-columns: minmax(0, 1fr);
  font-size: 14px;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Header */
.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--header-bg); color: #fff;
}
.topbar .logo { height: 30px; }
.topbar .divider { width: 1px; height: 26px; background: rgba(255, 255, 255, 0.3); }
.topbar h1 { font-size: 18px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; line-height: 18px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--text-2); background: var(--surface);
}
.pill-onblue { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.25); color: #fff; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 6px 12px;
  cursor: pointer; font-weight: 500; font-size: 13.5px; white-space: nowrap;
  background: none;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--ft-primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: #d93519; }
.btn-ghost-light { color: #fff; border-color: rgba(255, 255, 255, 0.35); }
.btn-ghost-light:not(:disabled):hover { background: rgba(255, 255, 255, 0.12); }
.btn-quiet { border-color: var(--border); background: var(--surface); color: var(--text); }
.btn-quiet:not(:disabled):hover { background: var(--surface-2); }
.btn-sm { padding: 3px 9px; font-size: 12.5px; border-radius: 6px; }
.btn-link { border: 0; padding: 0; color: var(--accent); background: none; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.theme-btn { display: inline-flex; align-items: center; gap: 6px; }
.theme-btn svg { width: 15px; height: 15px; fill: currentColor; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.search {
  position: relative; display: flex; align-items: center;
  flex: 0 1 420px; min-width: 220px;
}
.search svg { position: absolute; left: 10px; width: 16px; height: 16px; fill: var(--text-3); }
.search input {
  width: 100%; padding: 7px 10px 7px 34px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.search input:focus, select:focus, .picker input:focus { outline: 2px solid var(--focus-ring); outline-offset: 0; border-color: var(--accent); }
select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.ts-notice {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; cursor: pointer;
  border: 1px solid var(--dup-border); background: var(--dup-bg); color: var(--dup);
  border-radius: 8px; padding: 5px 10px; font-size: 12.5px; font-weight: 500;
}
.ts-notice::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.ts-notice.off { border-color: var(--border); background: var(--surface-2); color: var(--text-2); cursor: help; }
.check-label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); cursor: pointer; user-select: none; }
.stats { color: var(--text-2); font-size: 12.5px; margin-left: auto; text-align: right; }
.stats b { color: var(--text); font-weight: 600; }
.stats .warn { color: var(--danger); }

/* Drop target bar */
.dropbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  min-height: 46px;
}
.dropbar-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); font-weight: 600; }
.pins { display: contents; }
.drop-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; border: 1.5px dashed var(--chip-border); border-radius: 8px;
  background: var(--surface); font-size: 13px; cursor: pointer; max-width: 260px;
}
.drop-chip.drop-root { padding-right: 10px; color: var(--text-2); }
.drop-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-chip .unpin {
  border: 0; background: none; cursor: pointer; color: var(--text-3);
  width: 20px; height: 20px; border-radius: 4px; line-height: 1; font-size: 15px;
}
.drop-chip .unpin:hover { background: var(--surface-2); color: var(--text); }
.drop-chip.drop-ok { border-color: var(--accent); border-style: solid; background: var(--drop-bg); }
.hint { color: var(--text-3); font-size: 12.5px; }

/* Main layout */
.layout {
  display: grid; min-height: 0;
  /* --side-w is set by the splitter; min() keeps the tree at least 320px wide when the window shrinks. */
  grid-template-columns: minmax(0, 1fr) 7px min(var(--side-w, 400px), max(280px, calc(100% - 327px)));
}
.splitter { position: relative; cursor: col-resize; touch-action: none; outline: none; }
.splitter::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 1px; background: var(--border);
  transition: left 0.12s, width 0.12s, background 0.12s;
}
.splitter::before {
  /* grip */
  content: ""; position: absolute; z-index: 1; top: 50%; left: 1px; width: 5px; height: 34px; margin-top: -17px;
  border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border);
}
.splitter:hover::after, .splitter:focus-visible::after, body.resizing .splitter::after { left: 2px; width: 3px; background: var(--accent); }
.splitter:hover::before, .splitter:focus-visible::before, body.resizing .splitter::before { border-color: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
.tree-wrap { min-height: 0; display: flex; flex-direction: column; }
.tree { flex: 1; overflow: auto; padding: 6px 0 40px; outline: none; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--side-bg); }
.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 8px; background: var(--surface); }
.tab {
  border: 0; background: none; padding: 11px 10px 9px; cursor: pointer;
  color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; text-align: center; }
.tab .count.has { background: var(--ft-primary); color: #fff; }
.panel { overflow: auto; padding: 16px; flex: 1; }

/* Tree rows */
.row {
  position: relative;
  display: flex; align-items: center; gap: 6px;
  height: var(--row-h);
  padding-left: calc(var(--depth) * var(--indent) + 8px); padding-right: 10px;
  cursor: pointer; user-select: none; white-space: nowrap;
  border-left: 3px solid transparent;
}
.row::before {
  /* indentation guides */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: calc(var(--depth) * var(--indent) + 8px);
  background: repeating-linear-gradient(to right, transparent 0 17px, var(--border) 17px 18px, transparent 18px var(--indent));
  pointer-events: none;
}
.row:hover { background: var(--surface-2); }
.row.selected { background: var(--select); }
.row.checked { background: var(--checked); }
.row.selected.checked { background: var(--checked-selected); }
.row.moved { border-left-color: var(--moved); }
.row.dragging { opacity: 0.45; }
.row.drop-ok { background: var(--drop-bg); box-shadow: inset 0 0 0 2px var(--accent); }
.row.flash { animation: flash 1.2s ease-out; }
.row.context > .name { font-weight: 400; color: var(--text-2); }
@keyframes flash { from { background: var(--flash); } to { background: transparent; } }

.twisty {
  width: 18px; height: 18px; flex: none; border: 0; padding: 0; background: none;
  display: grid; place-items: center; cursor: pointer; color: var(--text-2); border-radius: 4px;
}
.twisty:hover { background: var(--hover-strong); }
.twisty svg { width: 12px; height: 12px; fill: currentColor; transition: transform 0.12s; }
.twisty.open svg { transform: rotate(90deg); }
.twisty-spacer { width: 18px; flex: none; }
.row .check { margin: 0; width: 14px; height: 14px; accent-color: var(--ft-primary); opacity: 0; flex: none; cursor: pointer; }
.row:hover .check, .row .check:checked, .tree.multi .row .check { opacity: 1; }
.row .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; max-width: 55%; }
.row.group > .name { font-weight: 600; }
.row.deleted .name { text-decoration: line-through; color: var(--text-3); }
.row .sci { color: var(--text-3); font-style: italic; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.row .kids { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.row .tail { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; padding-left: 8px; }
.row .tail > * { flex: none; }
/* Tag chips give way first when the row is narrow, so the fish name stays readable. */
.row .tail > .ann { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
.row .pin-btn { opacity: 0; }
.row:hover .pin-btn, .row.selected .pin-btn { opacity: 1; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }

.b-species { color: var(--accent); border-color: var(--focus-ring); }
.b-pending { color: var(--review); border-color: var(--review-border); background: var(--review-bg); }
.b-dup { color: var(--dup); border-color: var(--dup-border); background: var(--dup-bg); }
.b-fuzzy { color: var(--text-2); border-style: dashed; }
.b-rejected, .b-deleted { color: var(--text-2); background: var(--surface-2); }
.b-issue { color: var(--issue); border-color: var(--issue-border); background: var(--issue-bg); }
.b-moved { color: var(--moved); border-color: var(--moved-border); background: var(--moved-bg); }
.verified { color: var(--green); font-size: 13px; }

.empty { padding: 40px 24px; color: var(--text-2); text-align: center; }
.empty.error { color: var(--danger); }

/* Side panel content */
.panel h2 { font-size: 19px; margin: 0 0 2px; font-weight: 600; word-break: break-word; }
.panel .sciname { color: var(--text-2); font-style: italic; margin-bottom: 10px; }
.panel h4 {
  margin: 20px 0 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3); font-weight: 600;
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 5px 10px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; }
.crumbs .sep { color: var(--text-3); }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }
.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-height: 260px; overflow: auto; }
.list li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-top: 1px solid var(--border); font-size: 13px; }
.list li:first-child { border-top: 0; }
.list .muted, .muted { color: var(--text-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.card + .card { margin-top: 12px; }
.card.bulk { border-color: var(--bulk-border); background: var(--bulk-bg); }
.issue-box { border: 1px solid var(--issue-border); background: var(--issue-bg); color: var(--issue-text); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }

/* Tags and notes */
.tag-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 2px; padding: 1px 8px; border-radius: 999px;
  background: var(--select); color: var(--accent); font-size: 12px; font-weight: 500; line-height: 20px;
  white-space: nowrap; cursor: pointer;
}
.tag-chip:hover { text-decoration: underline; text-underline-offset: 2px; }
.tag-chip.removable { padding-right: 3px; }
.tag-chip button {
  border: 0; background: none; color: inherit; cursor: pointer; width: 18px; height: 18px;
  border-radius: 50%; line-height: 1; font-size: 14px; opacity: 0.7; padding: 0;
}
.tag-chip button:hover { opacity: 1; background: var(--hover-strong); }
.tag-chip.sm { padding: 0 7px; font-size: 11.5px; line-height: 18px; }
.tag-chip.more { cursor: default; background: var(--surface-2); color: var(--text-2); }
.tag-chip.more:hover { text-decoration: none; }
.tag-input {
  flex: 1; min-width: 150px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-size: 13px;
}
.note-input {
  display: block; width: 100%; margin-top: 10px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; resize: vertical;
}
.tag-input:focus, .note-input:focus { outline: 2px solid var(--focus-ring); outline-offset: 0; border-color: var(--accent); }
.notes { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.notes li { border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; padding: 7px 10px; }
.note-text { white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.note-meta { color: var(--text-3); font-size: 11.5px; margin-top: 3px; }
.note-mark { color: var(--accent); font-size: 12px; font-weight: 500; white-space: nowrap; }
.gnode .g-mark { fill: var(--g-node); font-weight: 400; }

/* Parent picker */
.picker { position: relative; }
.picker input { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.picker-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow); max-height: 280px; overflow: auto; padding: 4px;
}
.picker-list button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.picker-list button.active, .picker-list button:hover { background: var(--select); }
.picker-list .path { display: block; color: var(--text-3); font-size: 11.5px; }

/* Changes list */
.change { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.change:first-of-type { border-top: 0; }
.change .route { color: var(--text-2); grid-column: 1; }
.change .route b { color: var(--text); font-weight: 500; }
.change .revert { grid-row: 1 / span 2; grid-column: 2; align-self: center; }

/* View switch */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface-2); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px var(--shadow); }

/* Graph view */
.graph { position: relative; flex: 1; min-height: 0; background: var(--g-bg); overflow: hidden; container-type: inline-size; }
.graph-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; user-select: none; touch-action: none; }
.graph-svg:active { cursor: grabbing; }
.g-link { fill: none; stroke: var(--g-link); stroke-width: 1.2px; }
.g-link.on-path { stroke: var(--g-path); stroke-width: 2.2px; }
.gnode { cursor: pointer; }
.gnode circle { fill: var(--g-bg); stroke: var(--g-node); stroke-width: 1.8px; transition: r 0.1s; }
.gnode.group circle { fill: var(--g-node); }
.gnode.virtual circle { fill: var(--g-virtual); stroke: var(--g-virtual); }
.gnode.dup circle { stroke: var(--g-dup); }
.gnode.dup.group circle, .gnode.dup.virtual circle { fill: var(--g-dup); }
.gnode.review circle { stroke: var(--g-review); }
.gnode.review.group circle { fill: var(--g-review); }
.gnode text { fill: var(--g-label); font-size: 13px; paint-order: stroke; stroke: var(--g-bg); stroke-width: 3px; stroke-linejoin: round; }
.gnode.group text, .gnode.virtual text { font-weight: 600; }
.gnode .g-count { fill: var(--g-muted); font-weight: 400; }
.gnode.context text { fill: var(--g-muted); }
.gnode.matched text { fill: var(--g-match); }
.gnode.deleted text { text-decoration: line-through; fill: var(--g-muted); }
.gnode.path text { fill: var(--g-path); }
.gnode.selected text { fill: var(--g-path); font-weight: 700; }
.gnode.selected circle { r: 6.5px; stroke-width: 2.4px; }
.gnode.moved circle { stroke: var(--g-moved); stroke-dasharray: 2 2; }
.gnode.moved text { font-style: italic; }
.gnode.checked circle { stroke: var(--ft-primary); stroke-width: 3px; }
.gnode:hover text { text-decoration: underline; text-underline-offset: 3px; }
.gnode.dragging { opacity: 0.35; }
.gnode.drop-ok circle { r: 9px; stroke: var(--g-drop); stroke-width: 3px; }
.gnode.drop-ok text { fill: var(--g-drop); }
.g-crumbs, .g-tools, .g-legend, .g-empty { position: absolute; z-index: 2; }
.g-crumbs { top: 12px; left: 14px; right: 380px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--g-muted); font-size: 13px; }
.g-crumbs button { border: 0; background: none; color: var(--g-label); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.g-crumbs button:hover { background: var(--g-hover); }
.g-crumbs b { color: var(--g-path); }
.g-crumbs .exit { margin-left: 8px; border: 1px solid var(--g-btn-border); padding: 2px 8px; color: var(--g-label); }
.g-tools { top: 10px; right: 12px; display: flex; gap: 6px; }
.g-btn {
  border: 1px solid var(--g-btn-border); background: var(--g-overlay); color: var(--g-node);
  border-radius: 8px; padding: 5px 11px; cursor: pointer; font-weight: 600; font-size: 12.5px;
}
.g-btn:hover:not(:disabled) { background: var(--g-hover); }
.g-btn:disabled { color: var(--g-muted); border-color: var(--g-overlay-border); cursor: default; }
.g-legend {
  left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px;
  padding: 9px 14px; background: var(--g-overlay); border-top: 1px solid var(--g-overlay-border);
  color: var(--g-label); font-size: 12.5px;
}
.g-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1.8px solid var(--g-node); }
.lg-group { background: var(--g-node); }
.lg-leaf { background: transparent; }
.lg-dup { background: var(--g-dup); border-color: var(--g-dup); }
.lg-review { background: var(--g-review); border-color: var(--g-review); }
.lg-moved { border-color: var(--g-moved); border-style: dashed; }
.lg-hint { margin-left: auto; color: var(--g-muted); }
.g-empty { top: 50%; left: 0; right: 0; text-align: center; color: var(--g-muted); transform: translateY(-50%); }

/* Drag ghost, toast, dialog */
.drag-ghost {
  pointer-events: none; z-index: 30;
  position: fixed; top: -200px; left: 0;
  padding: 6px 12px; border-radius: 8px; background: var(--ft-secondary); color: #fff;
  font-size: 13px; font-weight: 500; white-space: nowrap;
}
.drag-ghost.follow { top: 0; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--toast-bg); color: #fff; padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 8px 28px var(--shadow); font-size: 13.5px; max-width: min(640px, calc(100vw - 32px)); z-index: 20;
}
.toast.error { background: var(--toast-error); }
.toast button { background: none; border: 0; color: var(--toast-action); font-weight: 600; cursor: pointer; padding: 0; }
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px var(--shadow);
}
dialog::backdrop { background: var(--backdrop); }
dialog form { padding: 20px; }
dialog h3 { margin: 0 0 10px; color: var(--accent); }
dialog #dialogBody { font-size: 13.5px; color: var(--text-2); max-height: 50vh; overflow: auto; }
dialog ul { padding-left: 18px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }

/* When the graph area is narrow (small window or a wide details panel), stack its breadcrumb and buttons. */
@container (max-width: 760px) {
  .g-crumbs { right: 12px; }
  .g-tools { top: 40px; left: 12px; right: auto; flex-wrap: wrap; }
  .lg-hint { display: none; }
}

@media (max-width: 900px) {
  /* Let the page grow and scroll as a whole instead of squeezing the panes into the window height. */
  html, body { height: auto; }
  body { overflow: visible; min-height: 100vh; grid-template-rows: auto auto auto auto; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .splitter { display: none; }
  .tree { max-height: 65vh; }
  .graph { flex: none; height: 70vh; }
  .g-crumbs { right: 12px; }
  .g-tools { top: 40px; left: 12px; right: auto; flex-wrap: wrap; }
  .lg-hint { display: none; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 12px; row-gap: 8px; }
  .topbar h1, .topbar .divider { display: none; }
  .toolbar, .dropbar { padding-left: 12px; padding-right: 12px; }
  .search { flex: 1 1 100%; min-width: 0; }
  .toolbar .spacer { display: none; }
  .stats { flex-basis: 100%; }
}
