/* ============================================================
   datamodel — lab900-style data model explorer
   ============================================================ */

:root {
  --bg: #f5f6f7;
  --panel: #ffffff;
  --panel-2: #fbfbfc;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0a0a0a;
  --text-2: #4b5563;
  --text-3: #9ca3af;
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --yellow: #eab308;
  --shadow: 0 1px 0 rgba(0,0,0,0.02);
  --radius: 10px;

  /* entity stereotype colors — match the PUML legend */
  --c-stock-bg:       #FEF6E4;
  --c-stock-fg:       #8a6d1a;
  --c-immutable-bg:   #E8F0FE;
  --c-immutable-fg:   #2452a8;
  --c-openmodule-bg:  #E6F4EA;
  --c-openmodule-fg:  #1f7a3a;
  --c-enum-bg:        #F3E8FD;
  --c-enum-fg:        #6b3aa6;
  --c-embeddable-bg:  #FFF1F2;
  --c-embeddable-fg:  #b03a4a;
  --c-interface-bg:   #e0f2fe;
  --c-interface-fg:   #0369a1;
  --c-default-bg:     #f3f4f6;
  --c-default-fg:     #374151;

  /* focal entity treatment (graph node showing in detail) */
  --focal-line: #a8324a;
  --focal-bg:   #fdebee;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Menlo", "Consolas", monospace;
  --font-serif: Georgia, "Iowan Old Style", "Cambria", serif;
}

[data-theme="dark"] {
  --bg: #0b0c0d;
  --panel: #131517;
  --panel-2: #17191c;
  --border: #24272b;
  --border-strong: #2f3338;
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --text-3: #6b7280;
  --green: #4ade80;
  --green-bg: rgba(34,197,94,0.08);
  --green-border: rgba(34,197,94,0.28);
  --shadow: 0 1px 0 rgba(0,0,0,0.5);

  --c-stock-bg:       rgba(254, 246, 228, 0.08);
  --c-stock-fg:       #e7c97a;
  --c-immutable-bg:   rgba(232, 240, 254, 0.08);
  --c-immutable-fg:   #8fb2ef;
  --c-openmodule-bg:  rgba(230, 244, 234, 0.08);
  --c-openmodule-fg:  #7fd49b;
  --c-enum-bg:        rgba(243, 232, 253, 0.10);
  --c-enum-fg:        #c9a6f0;
  --c-embeddable-bg:  rgba(255, 241, 242, 0.08);
  --c-embeddable-fg:  #f08c9a;
  --c-interface-bg:   rgba(224, 242, 254, 0.08);
  --c-interface-fg:   #7dc7f5;
  --c-default-bg:     #1f2226;
  --c-default-fg:     #c9ced6;

  --focal-line: #e57c92;
  --focal-bg:   rgba(229, 124, 146, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#root { height: 100vh; }

button {
  font-family: inherit; font-size: inherit; color: inherit;
  cursor: pointer; background: none; border: 0;
}
input, textarea {
  font-family: inherit; font-size: inherit; color: inherit;
}

/* ---------- shell ---------- */
.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 14px;
}

/* ---------- header card ---------- */
.header {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
}
.header-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header .prompt {
  font-family: var(--font-mono);
  color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.header .prompt .dollar { color: var(--green); font-weight: 600; }
.header .prompt .path { color: var(--text-2); }

.diagram-title {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
  flex-shrink: 1;
}
.diagram-title-placeholder {
  color: var(--text-3);
  font-weight: 500;
}

.edit-cluster {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.header .brand {
  margin-left: 18px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.header .brand span { color: var(--text-3); font-weight: 500; }
.header .search-inline {
  flex: 1;
  margin-left: 24px;
  max-width: 520px;
  position: relative;
}
.header .search-inline input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px 8px 34px;
  outline: none;
  transition: border-color .12s, background .12s;
}
.header .search-inline input:focus {
  border-color: var(--green-border);
  background: var(--panel);
}
.header .search-inline .icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); color: var(--text-3);
  pointer-events: none;
}
.header .search-inline .kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: inline-flex; gap: 4px;
}
.header .right {
  margin-left: auto;
  display: flex; align-items: center; gap: 14px;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-2);
}
.header .right .dot { color: var(--text-3); }
.header .status {
  display: inline-flex; align-items: center; gap: 6px;
}
.header .status .led {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-bg);
}
.header .status .label { color: var(--text); }
.header .clock { color: var(--text); }
.iconbtn {
  width: 30px; height: 30px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text-2);
  transition: color .12s, border-color .12s, background .12s;
}
.iconbtn:hover { color: var(--text); border-color: var(--border-strong); }
.iconbtn.active {
  background: var(--text);
  color: var(--panel);
  border-color: var(--text);
}
.iconbtn.active:hover { background: var(--text-2); border-color: var(--text-2); color: var(--panel); }
.iconbtn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Segmented icon-only toolbar — used in the header for diagram actions. */
.btn-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.btn-group .iconbtn {
  width: 28px; height: 28px;
  border: 0;
  background: transparent;
  border-radius: 6px;
}
.btn-group .iconbtn:hover {
  background: var(--panel);
  color: var(--text);
  border: 0;
}
.btn-group .iconbtn.active {
  background: var(--text);
  color: var(--panel);
}
.btn-group .iconbtn.active:hover {
  background: var(--text-2);
  color: var(--panel);
}
.kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text-2);
  background: var(--panel);
  min-width: 18px; text-align: center;
}

/* ---------- main 2-pane (left stack + graph) ---------- */
.main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
  min-height: 0;
}
.left-col {
  display: grid;
  grid-template-rows: minmax(180px, 38fr) minmax(220px, 62fr);
  gap: 14px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
  background: var(--panel);
}
.panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-family: var(--font-mono);
}
.panel-head .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font-mono);
}
.panel-head .save-indicator { margin-left: auto; }
.panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.panel-body.scroll-x { overflow: auto; }

/* ---------- entity list ---------- */
.list-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.list-search input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px 8px 32px;
  outline: none;
}
.list-search input:focus {
  border-color: var(--green-border);
  background: var(--panel);
}
.list-search .icon {
  position: absolute; left: 22px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}

.list-filters {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.list-filters .chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  transition: all .1s;
}
.list-filters .chip.active {
  background: var(--text);
  color: var(--panel);
  border-color: var(--text);
}
.list-filters .chip .dot {
  width: 7px; height: 7px; border-radius: 2px;
}

.list-pkg {
  padding: 10px 12px 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  text-transform: lowercase;
  letter-spacing: 0;
  display: flex; align-items: center; gap: 6px;
}
.list-pkg::before {
  content: ""; flex: 0 0 8px; height: 1px; background: var(--border);
}
.list-pkg::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.list-section-h {
  padding: 12px 12px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px dashed var(--border);
  margin-top: 6px;
}
.list-section-h:first-child {
  border-top: 0;
  margin-top: 0;
}
.list-section-h .count {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.list-item.key-item {
  grid-template-columns: auto 1fr auto;
}
.list-item.key-item .name {
  font-weight: 600;
}
.list-item.key-item .key-pin {
  color: var(--focal-line);
  font-size: 11px;
  opacity: 0.7;
}

.list-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 12px;
  cursor: pointer;
  border-left: 2px solid transparent;
  position: relative;
}
.list-item:hover { background: var(--panel-2); }
.list-item.active {
  background: var(--green-bg);
  border-left-color: var(--green);
}
.list-item .swatch {
  width: 8px; height: 8px; border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.06);
}
.list-item .name {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-item .name .abstract { color: var(--text-3); font-style: italic; }
.list-item .badge-sm {
  font-family: var(--font-mono);
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.02em;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ---------- detail panel ---------- */
.detail-empty {
  height: 100%;
  display: grid; place-items: center;
  padding: 32px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
}

.detail {
  padding: 18px 18px 24px;
}
.detail .ent-name {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.detail .ent-name .abstract { font-style: italic; color: var(--text-2); font-weight: 500; }
.detail .ent-name .interface-mark {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-3); font-weight: 400;
}
.detail .pkg {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.detail .badge-row {
  display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap;
}
.badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  display: inline-flex; align-items: center; gap: 5px;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }

.section-h {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  margin: 22px 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.section-h .count {
  font-weight: 500;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
}

.attr {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  align-items: baseline;
}
.attr:last-child { border-bottom: 0; }
.attr .vis {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  width: 12px;
}
.attr .attr-name {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}
.attr .attr-type {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  text-align: right;
}
.attr .attr-type a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px dotted var(--border-strong);
  cursor: pointer;
}
.attr .attr-type a:hover { color: var(--green); border-bottom-color: var(--green); }

.rel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  align-items: center;
  font-size: 13px;
}
.rel:last-child { border-bottom: 0; }
.rel-mid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rel-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.rel-verb {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  text-transform: lowercase;
}
.rel .rel-target {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dotted var(--border-strong);
}
.rel .rel-target:hover { color: var(--focal-line); border-bottom-color: var(--focal-line); }
.rel-edge-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.rel-edge-label code {
  font-family: var(--font-mono);
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}

.card-pill {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--panel);
  font-family: var(--font-mono);
  font-size: 13px;
  overflow: hidden;
  min-height: 28px;
  user-select: none;
}
.card-pill .end {
  padding: 4px 9px;
  font-weight: 700;
  background: var(--panel-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  color: var(--text);
  letter-spacing: 0.02em;
}
.card-pill .glyph {
  padding: 4px 7px;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  font-weight: 500;
  background: var(--panel);
}
.card-pill.kindless {
  background: var(--panel-2);
  border-style: dashed;
}
.card-pill.kindless .glyph {
  padding: 4px 12px;
  font-style: italic;
  font-size: 11px;
  color: var(--text-2);
}
.card-pill.k-inheritance {
  border-color: var(--text);
  background: var(--panel);
}
.card-pill.k-inheritance .end {
  background: var(--panel);
}
.card-pill.k-composition .end {
  background: var(--c-stock-bg);
  color: var(--c-stock-fg);
}
.card-pill.k-dependency {
  border-style: dashed;
}

.enum-vals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 4px 12px;
}
.enum-vals .val {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 8px;
  background: var(--c-enum-bg);
  color: var(--c-enum-fg);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.note {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--yellow);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: pre-wrap;
  line-height: 1.55;
  font-family: var(--font-sans);
}
.note strong { color: var(--text); }
.note code { font-family: var(--font-mono); font-size: 11.5px; }

/* ---------- graph ---------- */
.graph-wrap {
  position: relative;
  flex: 1; min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0);
  background-size: 18px 18px;
  background-position: 0 0;
}
.graph-wrap:fullscreen {
  background-color: var(--bg);
}
.graph-wrap:-webkit-full-screen {
  background-color: var(--bg);
}
[data-theme="dark"] .graph-wrap {
  background:
    radial-gradient(circle at 1px 1px, #1f2226 1px, transparent 0);
  background-size: 18px 18px;
}
.graph-wrap svg { width: 100%; height: 100%; display: block;  }
.graph-wrap svg.panning { cursor: grabbing; }
.graph-wrap svg.dragging-node,
.graph-wrap svg.dragging-node .node-header { cursor: grabbing !important; }
.graph-node .close-btn:hover path { stroke: var(--red, #d33); }
.graph-node .close-btn:hover rect { fill: var(--panel-2, rgba(255,0,0,0.08)); }
.graph-node .preview-btn:hover path,
.graph-node .preview-btn:hover circle { stroke: var(--focal-line); fill: var(--focal-line); }
.graph-node.ghost { opacity: 0.45; pointer-events: none; }
.ghost-edge { opacity: 0.4; }
.graph-node .edit-mini-btn rect {
  transition: fill 120ms ease, stroke 120ms ease;
}
.graph-node .edit-mini-btn:hover rect {
  fill: var(--green-bg);
  stroke: var(--green-border);
}
.graph-node .edit-mini-btn:hover text {
  fill: var(--text);
}

.graph-node text {
  font-family: var(--font-mono);
  font-size: 12px;
  fill: var(--text);
  user-select: none;
  pointer-events: none;
}
.graph-node.dim {
  opacity: 0.35;
}
.copy-glyph,
.edit-glyph {
  opacity: 0.35;
  transition: opacity 120ms ease;
  cursor: pointer;
}
.copy-glyph:hover,
.edit-glyph:hover {
  opacity: 1;
}
.copy-glyph:hover rect[stroke],
.edit-glyph:hover path[stroke],
.edit-glyph:hover line[stroke] {
  stroke: var(--focal-line);
}
.graph-node text.attr-name-link {
  fill: var(--text);
  cursor: pointer;
  transition: fill 120ms ease;
}
.graph-node g:hover > text.attr-name-link {
  fill: var(--focal-line);
}
.graph-edge {
  stroke: var(--border-strong);
  fill: none;
  stroke-width: 1.1;
}
.graph-edge.dim { opacity: 0.25; }
.graph-edge.composition { stroke: var(--text-2); }
.graph-edge.inheritance { stroke: var(--text); stroke-dasharray: 0; }
.graph-edge.dependency { stroke-dasharray: 4 3; }
.graph-edge.focal {
  stroke: var(--focal-line) !important;
  stroke-width: 1.5;
}
.graph-edge-g.focal text { fill: var(--focal-line); }
.graph-edge-g.dim { opacity: 0.18; }

.graph-toolbar {
  position: absolute;
  top: 12px; left: 12px;
  display: flex; gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.graph-toolbar button {
  height: 28px; padding: 0 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.graph-toolbar button:hover { background: var(--panel-2); color: var(--text); }
.graph-toolbar button.active { background: var(--text); color: var(--panel); }
.graph-toolbar .sep {
  width: 1px; background: var(--border); margin: 4px 2px;
}

.graph-legend {
  position: absolute;
  bottom: 12px; left: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  display: grid;
  grid-template-columns: auto auto;
  gap: 3px 14px;
  box-shadow: var(--shadow);
}
.graph-legend .row { display: inline-flex; align-items: center; gap: 6px; }
.graph-legend .swatch { width: 10px; height: 10px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.08); }
.graph-legend .line { width: 16px; height: 0; border-top: 1px solid var(--text-2); }
.graph-legend .line.dashed { border-top-style: dashed; }
.graph-legend .line.thick { border-top-width: 2px; border-top-color: var(--text); }

.graph-hint {
  position: absolute;
  bottom: 12px; right: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  display: flex; gap: 12px;
  box-shadow: var(--shadow);
}

.path-hidden-hint {
  position: absolute;
  top: 56px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--green-border);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: help;
  white-space: nowrap;
  max-width: calc(100% - 32px);
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,11,13,0.45);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  width: min(720px, 100%);
  max-height: 80vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-head h3 {
  margin: 0; font-size: 14px;
  font-family: var(--font-mono);
}
.modal-head .close {
  margin-left: auto;
  color: var(--text-3);
}
.modal-body { padding: 14px 18px; flex: 1; overflow: auto; }
.modal-body textarea {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  resize: vertical;
  outline: none;
}
.modal-body textarea:focus { border-color: var(--green-border); }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  align-items: center;
}
.modal-foot .hint {
  margin-right: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  transition: border-color .12s, background .12s, color .12s;
}
.btn:hover { border-color: var(--border-strong); background: var(--panel-2); }
.home-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.875rem;
  text-decoration: none;
  font-family: var(--font-mono);
  transition: border-color .15s, color .15s, background-color .15s;
}
.home-link:hover {
  border-color: var(--green);
  color: var(--green);
  background: rgba(126, 231, 135, 0.05);
}
.home-link svg { width: 16px; height: 16px; }
.btn.primary {
  background: var(--text); border-color: var(--text); color: var(--panel);
}
.btn.primary:hover { background: var(--text-2); border-color: var(--text-2); }
.btn.danger {
  background: #c1364e; border-color: #c1364e; color: #fff;
}
.btn.danger:hover { background: #a82d42; border-color: #a82d42; }
.btn.green {
  background: var(--green); border-color: var(--green); color: #052e16;
}
.btn .kbd { background: rgba(255,255,255,0.18); border: 0; color: inherit; }

/* ---------- footer ---------- */
.footer {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px;
}
.footer .heart { color: #ef4444; }
.footer .right { margin-left: auto; }

/* ---------- breadcrumb ---------- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px 0;
  border-top: 1px dashed var(--border);
  min-height: 28px;
  font-family: var(--font-mono);
  font-size: 12px;
  flex-wrap: wrap;
}
.navbtn {
  width: 22px; height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
  font-size: 12px;
  display: inline-grid; place-items: center;
  transition: color .12s, border-color .12s, background .12s;
}
.navbtn:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: var(--panel-2); }
.navbtn:disabled { opacity: 0.35; cursor: not-allowed; }
.navbtn.clear-path {
  margin-left: auto;
  color: var(--text-3);
}
.navbtn.clear-path:hover {
  color: var(--focal-line);
  border-color: var(--focal-line);
}
.bc-prefix {
  color: var(--text-3);
  margin: 0 4px 0 4px;
}
.bc-trail {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.bc-sep {
  color: var(--text-3);
  font-size: 12px;
  user-select: none;
}
.bc-seg {
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-2);
  border: 1px solid transparent;
  font-family: var(--font-mono);
  font-size: 12px;
  background: transparent;
  transition: all .1s;
}
.bc-seg:hover { background: var(--panel-2); color: var(--text); }
.bc-seg.current {
  background: var(--green-bg);
  color: var(--text);
  border-color: var(--green-border);
}
.bc-ellipsis {
  color: var(--text-3);
  padding: 0 2px;
  cursor: help;
}

/* ---------- graph toolbar segmented control ---------- */
.graph-toolbar .seg {
  display: inline-flex;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}
.graph-toolbar .seg button {
  padding: 0 8px; height: 24px;
  border-radius: 4px;
  font-size: 11px;
}
.graph-toolbar .seg button.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0,0,0,0.06), 0 0 0 1px var(--border);
}
[data-theme="dark"] .graph-toolbar .seg button.active {
  box-shadow: 0 0 0 1px var(--border-strong);
}

/* ---------- relations filter chips inside section-h ---------- */
.section-h .chip {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.section-h .chip.active {
  background: var(--text);
  color: var(--panel);
  border-color: var(--text);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--panel);
  padding: 10px 14px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  z-index: 200;
  animation: toast-in 160ms ease;
  max-width: calc(100vw - 48px);
}
.toast-prefix {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.7;
}
.toast code {
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.12);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--panel);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- responsive (collapse to stacked) ---------- */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .left-col { grid-row: 2; grid-template-rows: auto auto; }
}

/* ---------- library modal ---------- */
.modal.lib-modal {
  width: min(820px, 100%);
  max-height: 84vh;
}
.lib-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.lib-tab {
  padding: 10px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .12s, border-color .12s, background .12s;
}
.lib-tab:hover { color: var(--text); background: var(--panel); }
.lib-tab.active {
  color: var(--text);
  border-bottom-color: var(--green);
  background: var(--panel);
}
.lib-tab .count {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-3);
}

.lib-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lib-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  transition: border-color .12s, background .12s;
}
.lib-item:hover { border-color: var(--border-strong); background: var(--panel-2); }
.lib-item.current {
  border-color: var(--green-border);
  background: var(--green-bg);
}
.lib-item-main { flex: 1; min-width: 0; }
.lib-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  background: transparent;
  cursor: pointer;
}
.lib-name:hover { color: var(--green); }
.lib-current-pill {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--green);
  color: #052e16;
  padding: 1px 6px;
  border-radius: 999px;
}
.lib-meta {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.lib-actions {
  display: inline-flex;
  gap: 4px;
}
.lib-actions .iconbtn {
  width: 28px; height: 28px;
}
.lib-actions .iconbtn.lib-delete:hover {
  color: #c1364e;
  border-color: rgba(193,54,78,0.4);
}
.lib-rename-input {
  width: 100%;
  border: 1px solid var(--green-border);
  background: var(--panel);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 14px;
  font-family: var(--font-sans);
  font-weight: 600;
  outline: none;
}

.lib-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-2);
}
.lib-empty p { margin: 0; }
.lib-empty .btn { margin-top: 10px; }

.lib-new {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lib-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.lib-field > span {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.lib-field input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .12s, background .12s;
}
.lib-field input[type="text"]:focus {
  border-color: var(--green-border);
  background: var(--panel);
}
.lib-field textarea {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  resize: vertical;
  outline: none;
}
.lib-field textarea:focus { border-color: var(--green-border); background: var(--panel); }

.lib-new-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.lib-new-actions .hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- inline popovers ---------- */
.popover {
  position: fixed;
  z-index: 300;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  overflow: hidden;
  font-size: 13px;
  animation: popover-in 120ms ease;
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.popover-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.popover-head > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-x {
  width: 22px; height: 22px;
  display: inline-grid; place-items: center;
  border-radius: 4px;
  color: var(--text-3);
  font-size: 18px;
  line-height: 1;
}
.popover-x:hover { background: var(--panel); color: var(--text); }
.popover-body { padding: 12px; }
.pop-form { display: flex; flex-direction: column; gap: 10px; }
.pop-field { display: flex; flex-direction: column; gap: 4px; }
.pop-field > span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.pop-field input[type="text"],
.pop-field select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}
.pop-field input[type="text"]:focus,
.pop-field select:focus {
  border-color: var(--green-border);
  background: var(--panel);
}
.pop-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pop-pills {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.pop-pill {
  padding: 3px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  background: transparent;
}
.pop-pill:hover { color: var(--text); background: var(--panel-2); }
.pop-pill.active { background: var(--text); color: var(--panel); }
.pop-pill.mini { padding: 2px 7px; font-size: 11px; }
.pop-checkrow {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.pop-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.pop-check input { accent-color: var(--green); }
.pop-vis { display: inline-flex; gap: 2px; margin-left: auto; }
.pop-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.pop-hint code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}
.pop-error {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #c1364e;
  background: rgba(193,54,78,0.08);
  border: 1px solid rgba(193,54,78,0.18);
  border-radius: 5px;
  padding: 5px 8px;
}
.pop-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 2px;
}
.pop-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.pop-btn:hover { border-color: var(--border-strong); background: var(--panel-2); }
.pop-btn.primary {
  background: var(--text);
  color: var(--panel);
  border-color: var(--text);
}
.pop-btn.primary:hover { background: var(--text-2); border-color: var(--text-2); }
.pop-btn.danger {
  color: #c1364e;
  border-color: rgba(193,54,78,0.3);
}
.pop-btn.danger:hover {
  background: rgba(193,54,78,0.08);
}

/* ---------- editable edges ---------- */
.graph-edge-g.editable:hover .graph-edge {
  stroke: var(--focal-line) !important;
  stroke-width: 1.6;
}

/* ---------- empty state ---------- */
.empty-state {
  display: grid;
  place-items: center;
  padding: 20px;
  min-height: 0;
}
.empty-state-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
}
.empty-state-card svg { width: 32px; height: 32px; color: var(--text-3); margin-bottom: 8px; }
.empty-state-card h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.empty-state-card p {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
}
.empty-state-card .btn {
  margin-top: 12px;
}
.empty-state-card .hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  margin-top: 6px;
}

/* ---------- auth / cloud sync UI ---------- */
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.user-pill:hover { border-color: var(--border-strong); background: var(--panel-2); }
.user-pill .user-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  object-fit: cover;
  display: inline-block;
}
.user-pill .user-avatar-fallback {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--green-bg);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  display: inline-grid; place-items: center;
  text-transform: uppercase;
}
.user-pill .user-name {
  max-width: 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Compact variant — icon-only, used in the header. */
.user-pill.compact {
  padding: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-grid; place-items: center;
}
.user-pill.compact .user-avatar,
.user-pill.compact .user-avatar-fallback {
  width: 26px; height: 26px;
  border: 0;
}

.user-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  min-width: 220px;
  padding: 6px;
  z-index: 250;
  display: flex; flex-direction: column; gap: 2px;
}
.user-menu-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  border-radius: 6px;
  text-align: left;
}
.user-menu-row.identity {
  flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.user-menu-row.identity .name { font-weight: 600; }
.user-menu-row.identity .email { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.user-menu-row.action { cursor: pointer; }
.user-menu-row.action:hover { background: var(--panel-2); }

.user-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* save / sync indicator next to the diagram name in the breadcrumb row */
.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
}
.save-indicator .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
}
.save-indicator.saved .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.save-indicator.saving .dot { background: var(--yellow); }
.save-indicator.error .dot { background: #c1364e; }
.save-indicator.offline .dot { background: var(--text-3); }
.save-indicator.readonly { color: var(--text-3); }

.spin { animation: spin 900ms linear infinite; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- versions / chat panel (right column toggled from header) ---------- */
.main.with-side-panel {
  grid-template-columns: 380px 1fr 360px;
}
.versions-panel {
  display: flex; flex-direction: column;
  min-height: 0;
}
.versions-list {
  flex: 1; min-height: 0;
  overflow: auto;
  display: flex; flex-direction: column;
}
.version-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: start;
  cursor: pointer;
  transition: background .12s;
}
.version-row:hover { background: var(--panel-2); }
.version-row.current {
  background: var(--green-bg);
  border-left: 2px solid var(--green);
}
.version-row .v-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  object-fit: cover;
  margin-top: 1px;
}
.version-row .v-avatar-fallback {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--green-bg);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  display: grid; place-items: center;
  text-transform: uppercase;
  margin-top: 1px;
}
.version-row .v-main {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.version-row .v-message {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.version-row.auto .v-message {
  color: var(--text-3);
  font-style: italic;
  font-family: var(--font-mono);
  font-size: 12px;
}
.version-row .v-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.version-row .v-actions {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}
.version-row .v-restore {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
}
.version-row .v-restore:hover { background: var(--panel-2); color: var(--text); border-color: var(--border-strong); }

.versions-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
}

.versions-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ---------- AI chat panel ---------- */
.chat-panel {
  display: flex; flex-direction: column;
  min-height: 0;
}
.chat-list {
  flex: 1; min-height: 0;
  overflow: auto;
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 12px;
}
.chat-empty {
  margin: auto;
  padding: 24px 12px;
  text-align: center;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.chat-empty-hint {
  font-style: italic;
  opacity: 0.8;
  max-width: 280px;
  line-height: 1.5;
}
.chat-msg {
  display: flex;
}
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 92%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble {
  background: var(--green-bg);
  border: 1px solid var(--green);
  color: var(--text);
  white-space: pre-wrap;
}
.chat-msg.assistant .chat-bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.chat-bubble.streaming {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
}

/* Markdown rendering inside assistant bubbles. Styles are scoped to .markdown
   so they don't leak into other content. */
.chat-text.markdown > :first-child { margin-top: 0; }
.chat-text.markdown > :last-child { margin-bottom: 0; }
.chat-text.markdown p { margin: 0 0 8px; }
.chat-text.markdown ul,
.chat-text.markdown ol { margin: 4px 0 8px; padding-left: 22px; }
.chat-text.markdown li { margin: 2px 0; }
.chat-text.markdown li > p { margin: 0; }
.chat-text.markdown strong { font-weight: 600; }
.chat-text.markdown em { font-style: italic; }
.chat-text.markdown code {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.chat-text.markdown pre {
  margin: 6px 0 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.45;
}
.chat-text.markdown pre code {
  padding: 0;
  background: transparent;
  border: 0;
  font-size: inherit;
}
.chat-text.markdown a {
  color: var(--green);
  text-decoration: underline;
}
.chat-text.markdown blockquote {
  margin: 6px 0;
  padding: 4px 10px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
}
.chat-text.markdown hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}
.chat-text.markdown table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12px;
}
.chat-text.markdown th,
.chat-text.markdown td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.chat-toolcalls {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: flex; flex-direction: column;
  gap: 4px;
}
.chat-toolcall {
  display: flex; flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 12px;
}
.chat-toolcall.error {
  background: rgba(193, 54, 78, 0.08);
  border-color: rgba(193, 54, 78, 0.3);
}
.chat-toolcall-label {
  font-weight: 600;
  color: var(--text-2);
}
.chat-toolcall-args {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  background: transparent;
  padding: 0;
}
.chat-toolcall-err {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #c1364e;
}
.chat-error {
  margin-top: 4px;
  color: #c1364e;
  font-size: 12px;
  font-family: var(--font-mono);
}

.chat-input-bar {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.chat-input {
  flex: 1;
  resize: none;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  min-height: 38px;
  max-height: 160px;
}
.chat-input:focus {
  outline: none;
  border-color: var(--border-strong);
}
.chat-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.chat-input-bar .btn {
  align-self: flex-end;
}
.chat-signin {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- checkpoint dialog ---------- */
.modal.checkpoint-dialog { width: min(480px, 100%); }
.modal.confirm-dialog { width: min(440px, 100%); }
.confirm-dialog .confirm-message {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.checkpoint-dialog .author-line {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 12px;
}
.checkpoint-dialog .author-line img,
.checkpoint-dialog .author-line .user-avatar-fallback {
  width: 22px; height: 22px;
}
.checkpoint-dialog input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
}
.checkpoint-dialog input[type="text"]:focus {
  border-color: var(--green-border);
  background: var(--panel);
}

/* ---------- import dialog ---------- */
.modal.import-dialog { width: min(640px, 100%); }
.import-dialog .import-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.5;
}
.import-dialog .import-hint code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
}
.import-dialog textarea {
  min-height: 240px;
}
.import-dialog .import-actions {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px;
}
.import-dialog .import-actions .hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.import-dialog .import-actions .hint.error {
  color: var(--red, #d33);
}

/* ---------- share / read-only banner ---------- */
.share-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-2);
}
.share-banner .label { color: var(--text); font-weight: 600; }
.share-banner .btn { margin-left: auto; }

/* ---------- "lib-item" extension for cloud diagrams ---------- */
.lib-item .gh-pill {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
}
.lib-item .lib-link-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.lib-item .lib-link-row code {
  padding: 1px 5px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-2);
}

.lib-cta {
  display: flex; flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  text-align: center;
}
.lib-cta p { margin: 0; color: var(--text-2); }
.lib-cta .btn { margin-top: 8px; }

/* Open-from-link bar at the top of the library modal. */
.open-link {
  margin-bottom: 16px;
}
.open-link-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
}
.open-link-icon {
  display: inline-grid; place-items: center;
  width: 32px;
  color: var(--text-3);
  flex-shrink: 0;
}
.open-link-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text);
}
.open-link-row input[type="text"]::placeholder {
  color: var(--text-3);
}
.open-link-row .btn {
  flex-shrink: 0;
}
.open-link-error {
  margin-top: 6px;
  padding-left: 40px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #c1364e;
}

.lib-section { margin-bottom: 18px; }
.lib-section:last-child { margin-bottom: 0; }
.lib-section-h {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
}
.lib-section-h .count {
  margin-left: auto;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
