/* Folio — app styles. System UI font, light/dark tokens, option tones, then components. */

/* ------------------------------------------------------------------ tokens */

:root {
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #ffffff;
  --bg-sidebar: #f7f7f5;
  --bg-soft: #f7f6f3;
  --bg-elev: #ffffff;
  --bg-code: #f7f6f3;
  --bg-inline-code: rgba(135, 131, 120, 0.15);
  --fg: #37352f;
  --fg-strong: #191919;
  --fg-muted: rgba(55, 53, 47, 0.65);
  --fg-faint: rgba(55, 53, 47, 0.45);
  --fg-ghost: rgba(55, 53, 47, 0.3);
  --border: rgba(55, 53, 47, 0.12);
  --border-strong: rgba(55, 53, 47, 0.2);
  --hover: rgba(55, 53, 47, 0.06);
  --active: rgba(55, 53, 47, 0.12);
  --accent: #2383e2;
  --accent-hover: #0f6fca;
  --accent-soft: rgba(35, 131, 226, 0.14);
  --accent-fg: #ffffff;
  --danger: #e03e3e;
  --danger-soft: rgba(224, 62, 62, 0.1);
  --select: rgba(35, 131, 226, 0.28);
  --shadow-pop: 0 0 0 1px rgba(15, 15, 15, 0.05), 0 3px 6px rgba(15, 15, 15, 0.1), 0 9px 24px rgba(15, 15, 15, 0.2);
  --shadow-card: 0 0 0 1px rgba(15, 15, 15, 0.06), 0 2px 4px rgba(15, 15, 15, 0.06);
  --net-edge: #9b9a97;
  --net-edge-soft: #c7c6c3;
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px rgba(35, 131, 226, 0.6);

  /* option tones: bg (chips), fg (text), line (strokes/swatches), soft (node fill) */
  --t-default-bg: rgba(206, 205, 202, 0.5); --t-default-fg: #37352f; --t-default-line: #9b9a97; --t-default-soft: #f7f7f5;
  --t-gray-bg: #e3e2e0;   --t-gray-fg: #32302c;   --t-gray-line: #8c8b88;   --t-gray-soft: #f1f1ef;
  --t-brown-bg: #eee0da;  --t-brown-fg: #442a1e;  --t-brown-line: #ae7d68;  --t-brown-soft: #f6eeea;
  --t-orange-bg: #fadec9; --t-orange-fg: #49290e; --t-orange-line: #d9730d; --t-orange-soft: #fbf0e7;
  --t-yellow-bg: #fdecc8; --t-yellow-fg: #402c1b; --t-yellow-line: #cb912f; --t-yellow-soft: #fbf5e4;
  --t-green-bg: #dbeddb;  --t-green-fg: #1c3829;  --t-green-line: #448361;  --t-green-soft: #eef5ee;
  --t-blue-bg: #d3e5ef;   --t-blue-fg: #183347;   --t-blue-line: #337ea9;   --t-blue-soft: #e9f2f7;
  --t-purple-bg: #e8deee; --t-purple-fg: #412454; --t-purple-line: #9065b0; --t-purple-soft: #f4eff7;
  --t-pink-bg: #f5e0e9;   --t-pink-fg: #4c2337;   --t-pink-line: #c14c8a;   --t-pink-soft: #faf0f4;
  --t-red-bg: #ffe2dd;    --t-red-fg: #5d1715;    --t-red-line: #d44c47;    --t-red-soft: #fdf0ee;

  --sidebar-w: 248px;
  --page-w: 708px;
  --topbar-h: 45px;
  --pad-x: 96px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191919;
    --bg-sidebar: #202020;
    --bg-soft: #252525;
    --bg-elev: #252525;
    --bg-code: #202020;
    --bg-inline-code: rgba(135, 131, 120, 0.25);
    --fg: #e3e2e0;
    --fg-strong: #f5f5f4;
    --fg-muted: rgba(227, 226, 224, 0.6);
    --fg-faint: rgba(227, 226, 224, 0.42);
    --fg-ghost: rgba(227, 226, 224, 0.28);
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --hover: rgba(255, 255, 255, 0.055);
    --active: rgba(255, 255, 255, 0.1);
    --accent: #3b8fe0;
    --accent-hover: #5aa2e8;
    --accent-soft: rgba(59, 143, 224, 0.22);
    --danger: #ef6b62;
    --danger-soft: rgba(239, 107, 98, 0.14);
    --select: rgba(59, 143, 224, 0.38);
    --shadow-pop: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 3px 6px rgba(0, 0, 0, 0.4), 0 9px 24px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 2px 4px rgba(0, 0, 0, 0.3);
    --net-edge: #7d7c78;
    --net-edge-soft: #55544f;
    --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px rgba(59, 143, 224, 0.7);
    --t-default-bg: rgba(255, 255, 255, 0.12); --t-default-fg: #e3e2e0; --t-default-line: #8a8984; --t-default-soft: #232323;
    --t-gray-bg: #474747;   --t-gray-fg: #d6d5d3;   --t-gray-line: #9b9a97; --t-gray-soft: #262626;
    --t-brown-bg: #5c4033;  --t-brown-fg: #ead7cd;  --t-brown-line: #a27763; --t-brown-soft: #2b2320;
    --t-orange-bg: #854c1d; --t-orange-fg: #fbdcc3; --t-orange-line: #cb7b37; --t-orange-soft: #2f241b;
    --t-yellow-bg: #89632a; --t-yellow-fg: #fcecc8; --t-yellow-line: #c19138; --t-yellow-soft: #2e281b;
    --t-green-bg: #2b593f;  --t-green-fg: #d2ebd8;  --t-green-line: #4f9768; --t-green-soft: #1f2a23;
    --t-blue-bg: #28456c;   --t-blue-fg: #d1e3f4;   --t-blue-line: #4a83cf; --t-blue-soft: #1d2633;
    --t-purple-bg: #492f64; --t-purple-fg: #e6d7f2; --t-purple-line: #8a63b4; --t-purple-soft: #262030;
    --t-pink-bg: #69314c;   --t-pink-fg: #f6d6e5;   --t-pink-line: #b94e7c; --t-pink-soft: #2d1f26;
    --t-red-bg: #6e3630;    --t-red-fg: #fbd7d2;    --t-red-line: #c2564f; --t-red-soft: #2e1f1e;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #191919;
  --bg-sidebar: #202020;
  --bg-soft: #252525;
  --bg-elev: #252525;
  --bg-code: #202020;
  --bg-inline-code: rgba(135, 131, 120, 0.25);
  --fg: #e3e2e0;
  --fg-strong: #f5f5f4;
  --fg-muted: rgba(227, 226, 224, 0.6);
  --fg-faint: rgba(227, 226, 224, 0.42);
  --fg-ghost: rgba(227, 226, 224, 0.28);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --hover: rgba(255, 255, 255, 0.055);
  --active: rgba(255, 255, 255, 0.1);
  --accent: #3b8fe0;
  --accent-hover: #5aa2e8;
  --accent-soft: rgba(59, 143, 224, 0.22);
  --danger: #ef6b62;
  --danger-soft: rgba(239, 107, 98, 0.14);
  --select: rgba(59, 143, 224, 0.38);
  --shadow-pop: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 3px 6px rgba(0, 0, 0, 0.4), 0 9px 24px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 2px 4px rgba(0, 0, 0, 0.3);
  --net-edge: #7d7c78;
  --net-edge-soft: #55544f;
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px rgba(59, 143, 224, 0.7);
  --t-default-bg: rgba(255, 255, 255, 0.12); --t-default-fg: #e3e2e0; --t-default-line: #8a8984; --t-default-soft: #232323;
  --t-gray-bg: #474747;   --t-gray-fg: #d6d5d3;   --t-gray-line: #9b9a97; --t-gray-soft: #262626;
  --t-brown-bg: #5c4033;  --t-brown-fg: #ead7cd;  --t-brown-line: #a27763; --t-brown-soft: #2b2320;
  --t-orange-bg: #854c1d; --t-orange-fg: #fbdcc3; --t-orange-line: #cb7b37; --t-orange-soft: #2f241b;
  --t-yellow-bg: #89632a; --t-yellow-fg: #fcecc8; --t-yellow-line: #c19138; --t-yellow-soft: #2e281b;
  --t-green-bg: #2b593f;  --t-green-fg: #d2ebd8;  --t-green-line: #4f9768; --t-green-soft: #1f2a23;
  --t-blue-bg: #28456c;   --t-blue-fg: #d1e3f4;   --t-blue-line: #4a83cf; --t-blue-soft: #1d2633;
  --t-purple-bg: #492f64; --t-purple-fg: #e6d7f2; --t-purple-line: #8a63b4; --t-purple-soft: #262030;
  --t-pink-bg: #69314c;   --t-pink-fg: #f6d6e5;   --t-pink-line: #b94e7c; --t-pink-soft: #2d1f26;
  --t-red-bg: #6e3630;    --t-red-fg: #fbd7d2;    --t-red-line: #c2564f; --t-red-soft: #2e1f1e;
  color-scheme: dark;
}

.tone-default { --tone-bg: var(--t-default-bg); --tone-fg: var(--t-default-fg); --tone-line: var(--t-default-line); --tone-soft: var(--t-default-soft); }
.tone-gray    { --tone-bg: var(--t-gray-bg);    --tone-fg: var(--t-gray-fg);    --tone-line: var(--t-gray-line);    --tone-soft: var(--t-gray-soft); }
.tone-brown   { --tone-bg: var(--t-brown-bg);   --tone-fg: var(--t-brown-fg);   --tone-line: var(--t-brown-line);   --tone-soft: var(--t-brown-soft); }
.tone-orange  { --tone-bg: var(--t-orange-bg);  --tone-fg: var(--t-orange-fg);  --tone-line: var(--t-orange-line);  --tone-soft: var(--t-orange-soft); }
.tone-yellow  { --tone-bg: var(--t-yellow-bg);  --tone-fg: var(--t-yellow-fg);  --tone-line: var(--t-yellow-line);  --tone-soft: var(--t-yellow-soft); }
.tone-green   { --tone-bg: var(--t-green-bg);   --tone-fg: var(--t-green-fg);   --tone-line: var(--t-green-line);   --tone-soft: var(--t-green-soft); }
.tone-blue    { --tone-bg: var(--t-blue-bg);    --tone-fg: var(--t-blue-fg);    --tone-line: var(--t-blue-line);    --tone-soft: var(--t-blue-soft); }
.tone-purple  { --tone-bg: var(--t-purple-bg);  --tone-fg: var(--t-purple-fg);  --tone-line: var(--t-purple-line);  --tone-soft: var(--t-purple-soft); }
.tone-pink    { --tone-bg: var(--t-pink-bg);    --tone-fg: var(--t-pink-fg);    --tone-line: var(--t-pink-line);    --tone-soft: var(--t-pink-soft); }
.tone-red     { --tone-bg: var(--t-red-bg);     --tone-fg: var(--t-red-fg);     --tone-line: var(--t-red-line);     --tone-soft: var(--t-red-soft); }

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--select); }
.ico { flex: none; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.ico circle[r="1"] { fill: currentColor; stroke: none; }
.muted { color: var(--fg-muted); }
.spacer { flex: 1 1 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Outline (not box-shadow) so component shadows never hide the focus ring. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[contenteditable]:focus-visible { outline: none; }

/* ------------------------------------------------------------------ app grid */

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.sidebar-collapsed #app { grid-template-columns: 0 minmax(0, 1fr) auto; }

#sidebar {
  grid-column: 1;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  color: var(--fg-muted);
  user-select: none;
}
body.sidebar-collapsed #sidebar { visibility: hidden; border-right: 0; }

#main {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#content {
  flex: 1 1 auto;
  overflow: auto;
  overflow-x: hidden;
  outline: none;
  overscroll-behavior: contain;
}

#peek {
  grid-column: 3;
  width: min(560px, 46vw);
  border-left: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: -4px 0 16px rgba(15, 15, 15, 0.06);
  z-index: 5;
}

#overlays { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
#overlays > * { pointer-events: auto; }

/* ------------------------------------------------------------------ buttons & inputs */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  color: var(--fg);
  transition: background 0.12s;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--active); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(0.94); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { height: 26px; padding: 0 8px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-muted);
  flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn:active { background: var(--active); }
.icon-btn.small { width: 22px; height: 22px; border-radius: 4px; }

.linkbtn {
  border: 0;
  background: none;
  padding: 0 2px;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.linkbtn:hover { color: var(--accent-hover); }

.input {
  width: 100%;
  height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg-soft);
  font-size: 14px;
  outline: none;
  min-width: 0;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--bg); }
select.input { padding: 2px 6px; }

/* ------------------------------------------------------------------ popover, menu, modal, toast */

.popover {
  position: fixed;
  background: var(--bg-elev);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  overflow: auto;
  z-index: 100;
  font-size: 14px;
  color: var(--fg);
  min-width: 180px;
  max-width: calc(100vw - 16px);
  animation: pop-in 0.12s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

.menu { display: flex; flex-direction: column; padding: 6px 4px; min-width: 220px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 30px;
  padding: 4px 10px;
  border: 0;
  border-radius: 5px;
  background: none;
  text-align: left;
  font-size: 14px;
  color: var(--fg);
}
.menu-item.active, .menu-item:focus-visible { background: var(--hover); box-shadow: none; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .menu-ico { color: var(--danger); }
.menu-item.disabled { opacity: 0.45; cursor: default; }
.menu-ico { display: inline-grid; place-items: center; width: 18px; height: 18px; color: var(--fg-muted); flex: none; }
.menu-ico.emoji { font-size: 16px; line-height: 1; }
.menu-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-hint { color: var(--fg-faint); font-size: 12px; white-space: nowrap; }
.menu-check { color: var(--fg); display: inline-grid; }
.menu-sub { color: var(--fg-faint); display: inline-grid; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--border); }
.menu-header { padding: 6px 10px 4px; font-size: 12px; font-weight: 500; color: var(--fg-faint); }
.menu-empty { padding: 8px 12px; color: var(--fg-faint); font-size: 13px; }
.menu-node { padding: 4px 8px; }

.slash-menu { width: 320px; max-height: 380px; }
.slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: 5px;
  background: none;
  text-align: left;
}
.slash-item.active { background: var(--hover); }
.slash-ico {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-muted);
  flex: none;
}
.slash-text { display: flex; flex-direction: column; min-width: 0; }
.slash-label { font-size: 14px; color: var(--fg); }
.slash-desc { font-size: 12px; color: var(--fg-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.prompt-pop { display: flex; gap: 6px; padding: 8px; }
.prompt-pop .btn { height: 32px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 120;
  animation: fade-in 0.12s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 20px;
  font-size: 14px;
}
.modal-msg { margin: 0 0 6px; font-size: 15px; font-weight: 600; color: var(--fg-strong); }
.modal-detail { margin: 0 0 4px; color: var(--fg-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 8px;
  background: #2f2f2f;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 200;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #b8322c; }

/* emoji picker */
.emoji-pop { display: flex; flex-direction: column; gap: 8px; padding: 10px; }
.emoji-top { display: flex; gap: 6px; }
.emoji-top .btn { height: 32px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 2px; max-height: 240px; overflow: auto; }
.emoji-btn { width: 34px; height: 34px; border: 0; border-radius: 6px; background: none; font-size: 20px; line-height: 1; padding: 0; }
.emoji-btn:hover, .emoji-btn:focus-visible { background: var(--hover); }

/* pickers (select options, relations) */
.picker { display: flex; flex-direction: column; max-height: 420px; }
.picker-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; border-bottom: 1px solid var(--border); background: var(--bg-soft); }
.picker-top .input { flex: 1 1 140px; background: transparent; border: 0; box-shadow: none; padding: 2px 4px; height: 26px; }
.picker-selected { width: 100%; }
.picker-list { overflow: auto; padding: 4px; }
.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 3px 8px;
  border: 0;
  border-radius: 5px;
  background: none;
  text-align: left;
}
.picker-item.active, .picker-item:hover { background: var(--hover); }
.picker-item .menu-check { margin-left: auto; }
.picker-create { font-size: 13px; color: var(--fg-muted); }
.picker-page { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* cell editors */
.cell-pop { min-width: 0; border-radius: 4px; }
.cell-editor { display: flex; }
.cell-input {
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border: 0;
  outline: none;
  background: var(--bg-elev);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
}
.date-pop { display: flex; flex-direction: column; gap: 8px; padding: 10px; }
.date-actions { display: flex; gap: 6px; }

/* options editor (database header menu) */
.opt-editor { display: flex; flex-direction: column; padding: 6px 4px; min-width: 260px; }
.opt-row { display: flex; align-items: center; gap: 6px; padding: 2px 6px; }
.opt-row .input { height: 28px; }
.opt-swatches { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 8px 8px 34px; }
.swatch { width: 20px; height: 20px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--tone-bg); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 3px var(--fg-muted); }
.opt-add { margin: 4px 6px; }

/* ------------------------------------------------------------------ chips & values */

.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  height: 20px;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--tone-bg, var(--t-default-bg));
  color: var(--tone-fg, var(--t-default-fg));
  font-size: 13px;
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.removable { cursor: pointer; }
.chip.removable::after { content: "×"; margin-left: 5px; opacity: 0.6; }
.rel-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 0 4px 0 2px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: underline;
  text-decoration-color: var(--fg-ghost);
  text-underline-offset: 3px;
}
.rel-chip .ico { color: var(--fg-muted); }
.rel-chip.link { cursor: pointer; }
.rel-chip.link:hover { background: var(--hover); }
.v-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; min-width: 0; }
.v-icon { font-size: 15px; line-height: 1; flex: none; }
.v-text { white-space: pre-wrap; word-break: break-word; }
.v-number { font-variant-numeric: tabular-nums; }
.v-date { color: var(--fg); white-space: nowrap; }
.v-url { color: var(--fg); text-decoration: underline; text-decoration-color: var(--fg-ghost); text-underline-offset: 3px; word-break: break-all; }
.v-check {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--fg-faint);
  border-radius: 3px;
  color: #fff;
  vertical-align: middle;
}
.v-check.on { background: var(--accent); border-color: var(--accent); }
.v-check .ico { stroke-width: 2.2; }
.empty-val { color: var(--fg-ghost); }

/* property panel (row pages, network detail) */
.props-panel { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.prop-row { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr); gap: 6px; align-items: start; }
.prop-name { display: flex; align-items: center; gap: 6px; min-height: 34px; padding: 6px 6px; color: var(--fg-muted); border-radius: 4px; overflow: hidden; white-space: nowrap; }
.prop-name span { overflow: hidden; text-overflow: ellipsis; }
.prop-value { min-height: 34px; padding: 6px 8px; border-radius: 4px; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; word-break: break-word; }
.prop-value:hover { background: var(--hover); }
.prop-value.readonly { cursor: default; color: var(--fg-muted); }
.prop-value.readonly:hover { background: none; }

/* ------------------------------------------------------------------ sidebar */

.sb-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px 8px; }
.sb-ws {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  height: 32px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  color: var(--fg);
}
.sb-ws:hover { background: var(--hover); }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--peer, #888);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  flex: none;
  text-transform: uppercase;
}
.sb-ws-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.sb-ws-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-ws-sub { font-size: 12px; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-actions { display: flex; flex-direction: column; padding: 2px 8px 6px; }
.sb-action {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--fg-muted);
  font-size: 14px;
  text-align: left;
  width: 100%;
}
.sb-action:hover { background: var(--hover); color: var(--fg); }
.sb-action .menu-hint { margin-left: auto; }
.sb-section { padding: 10px 16px 4px; font-size: 12px; font-weight: 600; color: var(--fg-faint); }
.sb-scroll { flex: 1 1 auto; overflow: auto; padding-bottom: 12px; }
.sb-tree { list-style: none; margin: 0; padding: 0 8px; }
.sb-tree ul { list-style: none; margin: 0; padding: 0; }
.tree-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding-left: calc(4px + var(--depth, 0) * 14px);
  padding-right: 4px;
  border-radius: 6px;
  color: var(--fg-muted);
  cursor: pointer;
}
.tree-item:hover { background: var(--hover); }
.tree-item.active { background: var(--active); color: var(--fg); font-weight: 500; }
.tree-item.dragging { opacity: 0.4; }
.tree-item.drop-inside { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tree-item.drop-before::before, .tree-item.drop-after::after {
  content: "";
  position: absolute;
  left: calc(8px + var(--depth, 0) * 14px);
  right: 4px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.tree-item.drop-before::before { top: -1px; }
.tree-item.drop-after::after { bottom: -1px; }
.tree-toggle {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--fg-faint);
  flex: none;
}
.tree-toggle:hover { background: var(--active); color: var(--fg); }
.tree-toggle .ico { transition: transform 0.12s; }
.tree-toggle.open .ico { transform: rotate(90deg); }
.tree-icon { display: inline-grid; place-items: center; width: 22px; height: 22px; font-size: 15px; line-height: 1; flex: none; color: var(--fg-muted); }
.tree-link {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  font: inherit;
}
.tree-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; }
.tree-dots { display: inline-flex; gap: 2px; margin-right: 2px; }
.peer-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--peer); flex: none; }
.tree-btns { display: none; gap: 1px; }
.tree-item:hover .tree-btns, .tree-item:focus-within .tree-btns, .tree-item.menu-open .tree-btns { display: inline-flex; }
.tree-btns .icon-btn { width: 22px; height: 22px; }
.tree-btns .icon-btn:hover { background: var(--active); }
.tree-empty { padding: 4px 8px 4px calc(36px + var(--depth, 0) * 14px); font-size: 13px; color: var(--fg-ghost); }
.sb-foot { border-top: 1px solid var(--border); padding: 6px 8px; display: flex; flex-direction: column; }
.sb-backdrop { display: none; }

.trash-pop { display: flex; flex-direction: column; width: 360px; max-height: 440px; }
.trash-top { padding: 8px; border-bottom: 1px solid var(--border); }
.trash-list { overflow: auto; padding: 4px; }
.trash-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 8px; border-radius: 5px; min-height: 36px; }
.trash-item:hover { background: var(--hover); }
.trash-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.trash-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.trash-path { font-size: 12px; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-empty { padding: 20px; text-align: center; color: var(--fg-faint); }

/* ------------------------------------------------------------------ topbar */

#topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--topbar-h);
  padding: 0 10px 0 12px;
  flex: none;
  font-size: 14px;
  background: var(--bg);
  min-width: 0;
}
.tb-toggle { display: none; }
body.sidebar-collapsed .tb-toggle { display: inline-grid; }
.crumbs { display: flex; align-items: center; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 220px;
  height: 26px;
  padding: 0 6px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--fg-muted);
  white-space: nowrap;
  font-size: 14px;
}
.crumb:last-child { color: var(--fg); flex-shrink: 1; }
.crumb:hover { background: var(--hover); color: var(--fg); }
.crumb-text { overflow: hidden; text-overflow: ellipsis; }
.crumb-sep { color: var(--fg-ghost); padding: 0 1px; flex: none; }
.tb-peers { display: flex; align-items: center; padding: 0 4px; }
.tb-peers .avatar { width: 26px; height: 26px; font-size: 12px; margin-left: -6px; box-shadow: 0 0 0 2px var(--bg); }
.tb-peers .avatar:first-child { margin-left: 0; }
.tb-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  font-size: 12px;
  white-space: nowrap;
  background: var(--bg-soft);
  color: var(--fg-muted);
}
.tb-status.offline { background: var(--danger-soft); color: var(--danger); }
.tb-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tb-status.saving::before { animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.3; } }

/* ------------------------------------------------------------------ page */

.page { width: 100%; max-width: calc(var(--page-w) + var(--pad-x) * 2); margin: 0 auto; padding: 0 var(--pad-x) 30vh; }
.page.page-wide { max-width: none; padding-left: var(--pad-x); padding-right: var(--pad-x); }
.page.peek { padding: 0 40px 30vh; max-width: none; }
.page-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 calc(var(--pad-x) * -1);
  padding: 8px 16px;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
}
.page.peek .page-banner { margin: 0 -40px; }
.page-banner .btn { height: 26px; background: transparent; border-color: rgba(255, 255, 255, 0.7); color: #fff; }
.page-banner .btn:hover { background: rgba(255, 255, 255, 0.15); }
.page-head { padding-top: 64px; }
.page.peek .page-head { padding-top: 28px; }
.page-head.has-icon { padding-top: 44px; }
.page-icon-row { min-height: 0; display: flex; align-items: flex-end; }
.page-icon {
  font-size: 66px;
  line-height: 1.1;
  height: 78px;
  min-width: 78px;
  padding: 0;
  margin: 0 0 6px -4px;
  border: 0;
  border-radius: 6px;
  background: none;
}
.page-icon:hover { background: var(--hover); }
.page-tools { display: flex; gap: 4px; height: 28px; margin-bottom: 4px; opacity: 0; transition: opacity 0.12s; }
.page-head:hover .page-tools, .page-tools:focus-within { opacity: 1; }
.page-tools .btn { height: 26px; padding: 0 6px; font-size: 13px; color: var(--fg-faint); border: 0; background: none; }
.page-tools .btn:hover { background: var(--hover); color: var(--fg-muted); }
.page-title {
  margin: 0;
  padding: 3px 2px;
  font-size: 40px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--fg-strong);
  outline: none;
  word-break: break-word;
  white-space: pre-wrap;
  cursor: text;
}
.page-title.is-empty::before { content: attr(data-ph); color: var(--fg-ghost); pointer-events: none; }
.page.peek .page-title { font-size: 32px; }
.page-props { margin: 14px 0 4px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.add-prop { margin-top: 2px; height: 30px; color: var(--fg-faint); border: 0; background: none; padding: 0 6px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; border-radius: 4px; }
.add-prop:hover { background: var(--hover); color: var(--fg-muted); }
.page-body { padding-top: 12px; }
.page-tail { min-height: 120px; cursor: text; }
.page-hint { color: var(--fg-ghost); padding: 3px 2px; font-size: 16px; }
.page-missing { padding: 80px 24px; text-align: center; color: var(--fg-muted); }
.page-missing h2 { color: var(--fg); font-size: 22px; }

/* ------------------------------------------------------------------ blocks */

.blocks { position: relative; }
.blk {
  position: relative;
  display: flex;
  padding-left: calc(var(--indent, 0) * 26px);
  margin: 1px 0;
}
.blk-gutter {
  position: absolute;
  top: 3px;
  left: calc(var(--indent, 0) * 26px - 48px);
  display: flex;
  gap: 0;
  opacity: 0;
  transition: opacity 0.1s;
}
.blk:hover > .blk-gutter, .blk.menu-open > .blk-gutter { opacity: 1; }
.blk-gutter .icon-btn { width: 24px; height: 24px; color: var(--fg-ghost); }
.blk-gutter .icon-btn:hover { color: var(--fg-muted); }
.blk-handle { cursor: grab; }
.blk-handle:active { cursor: grabbing; }
.blk-main { display: flex; align-items: flex-start; flex: 1 1 auto; min-width: 0; border-radius: 4px; position: relative; }
.blk.selected .blk-main { background: var(--accent-soft); }
.blk.dragging { opacity: 0.35; }
.blk-text {
  flex: 1 1 auto;
  min-width: 0;
  padding: 3px 2px;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--fg);
  min-height: 1.5em;
}
.blk-text.is-empty::before { content: attr(data-ph); color: var(--fg-ghost); pointer-events: none; position: absolute; }
.blk-text.is-empty:not(:focus):not(.ph-always)::before { content: ""; }
.blk-text a, .blk-content a, .detail-body a { color: inherit; text-decoration: underline; text-decoration-color: var(--fg-faint); text-underline-offset: 3px; cursor: pointer; }
.blk-text a:hover { text-decoration-color: var(--fg); }
.blk-text code, .blk-content code, .detail-body code, .modal code {
  font-family: var(--mono);
  font-size: 85%;
  padding: 0.15em 0.35em;
  border-radius: 4px;
  background: var(--bg-inline-code);
  color: #eb5757;
}
mark { background: var(--t-yellow-bg); color: inherit; border-radius: 2px; padding: 0 1px; }

.blk[data-type="h1"] { margin-top: 1.6em; }
.blk[data-type="h2"] { margin-top: 1.2em; }
.blk[data-type="h3"] { margin-top: 0.9em; }
.blk:first-child[data-type^="h"] { margin-top: 0.4em; }
.blk[data-type="h1"] .blk-text { font-size: 30px; font-weight: 700; line-height: 1.3; color: var(--fg-strong); }
.blk[data-type="h2"] .blk-text { font-size: 24px; font-weight: 650; line-height: 1.3; color: var(--fg-strong); }
.blk[data-type="h3"] .blk-text { font-size: 20px; font-weight: 600; line-height: 1.3; color: var(--fg-strong); }
.blk[data-type="h1"] .blk-gutter { top: 9px; }
.blk[data-type="h2"] .blk-gutter { top: 6px; }
.blk[data-type="h3"] .blk-gutter { top: 4px; }

.blk-marker {
  flex: none;
  width: 24px;
  min-height: 30px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 3px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  user-select: none;
}
.blk-marker.num { width: auto; min-width: 24px; padding-right: 4px; font-variant-numeric: tabular-nums; justify-content: flex-end; }
.blk-marker.bullet { font-size: 20px; line-height: 1.2; padding-top: 2px; }
.blk-check {
  flex: none;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin: 6px 8px 0 4px;
  padding: 0;
  border: 1.5px solid var(--fg-muted);
  border-radius: 3px;
  background: transparent;
  color: #fff;
}
.blk-check.on { background: var(--accent); border-color: var(--accent); }
.blk-check .ico { stroke-width: 2.2; }
.blk-check.static { margin: 5px 8px 0 4px; }
.blk[data-type="todo"].checked .blk-text, .blk-row.checked .blk-content { color: var(--fg-faint); text-decoration: line-through; text-decoration-color: var(--fg-ghost); }
.blk-toggle-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-top: 3px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--fg);
}
.blk-toggle-btn:hover { background: var(--hover); }
.blk-toggle-btn .tri { width: 0; height: 0; border-left: 7px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent; transition: transform 0.12s; }
.blk-toggle-btn.open .tri { transform: rotate(90deg); }
.blk-toggle-empty { padding: 3px 2px 3px 26px; color: var(--fg-ghost); font-size: 15px; cursor: text; }
.blk[data-type="quote"] .blk-text { border-left: 3px solid currentColor; padding-left: 14px; margin: 3px 0; font-size: 1.05em; }
.blk[data-type="callout"] .blk-main, .blk-callout {
  display: flex;
  gap: 8px;
  padding: 12px 14px 12px 12px;
  border-radius: 6px;
  background: var(--bg-soft);
  margin: 3px 0;
}
.blk-callout-icon {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  font-size: 20px;
  line-height: 26px;
  text-align: center;
}
button.blk-callout-icon:hover { background: var(--hover); }
.blk[data-type="callout"] .blk-text { padding-top: 1px; }
.blk-code-wrap { flex: 1 1 auto; min-width: 0; margin: 4px 0; border-radius: 6px; background: var(--bg-code); position: relative; }
.code-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px 0; font-size: 12px; color: var(--fg-faint); }
.code-lang { border: 0; background: none; color: var(--fg-muted); font-size: 12px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.code-lang:hover { background: var(--hover); }
.code-copy { margin-left: auto; height: 22px; padding: 0 8px; font-size: 12px; border: 0; border-radius: 4px; background: none; color: var(--fg-muted); opacity: 0; transition: opacity 0.12s; }
.blk-code-wrap:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-copy:hover { background: var(--hover); }
.blk-text.code, .blk-code {
  display: block;
  margin: 0;
  padding: 10px 16px 16px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  tab-size: 2;
  overflow-x: auto;
  background: transparent;
}
.blk-code { background: var(--bg-code); border-radius: 6px; padding: 12px 16px; }
.blk-divider { flex: 1 1 auto; padding: 12px 2px; cursor: pointer; }
.blk-divider hr, .static-blocks hr { margin: 0; border: 0; border-top: 1px solid var(--border-strong); }
.blk.selected .blk-divider hr { border-top-color: var(--accent); }
.blk-pagelink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin: 1px 0;
  padding: 3px 4px;
  border: 0;
  border-radius: 4px;
  background: none;
  font-size: 16px;
  text-align: left;
  color: var(--fg);
}
.blk-pagelink:hover { background: var(--hover); }
.blk-pagelink .ico { color: var(--fg-muted); }
.blk-pagelink .pl-title { text-decoration: underline; text-decoration-color: var(--fg-ghost); text-underline-offset: 3px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blk-pagelink .pl-status { font-size: 12px; color: var(--fg-faint); border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 5px; white-space: nowrap; }
.blk-pagelink.gone .pl-title { color: var(--fg-faint); text-decoration: line-through; }
.blk-pagelink-wrap { flex: 1 1 auto; min-width: 0; outline: none; border-radius: 4px; }
.blk-pagelink-wrap:focus-visible { box-shadow: var(--focus-ring); }

/* peer presence on blocks */
.blk.peer .blk-main { box-shadow: 0 0 0 2px var(--peer); }
.peer-tag {
  position: absolute;
  right: 0;
  top: -11px;
  padding: 0 6px;
  border-radius: 4px 4px 4px 0;
  background: var(--peer);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
  z-index: 2;
}

@keyframes flash { 0%, 30% { background: var(--t-yellow-bg); } 100% { background: transparent; } }
.blk.flash .blk-main { animation: flash 2s ease-out; }

.drop-line {
  position: absolute;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.8;
  pointer-events: none;
  z-index: 3;
}

/* floating format toolbar */
.fmt-bar {
  position: fixed;
  display: flex;
  gap: 1px;
  padding: 3px;
  border-radius: 7px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-pop);
  z-index: 90;
}
.fmt-bar button {
  min-width: 30px;
  height: 28px;
  padding: 0 7px;
  border: 0;
  border-radius: 4px;
  background: none;
  font-size: 14px;
  color: var(--fg);
}
.fmt-bar button:hover { background: var(--hover); }
.fmt-bar button.on { color: var(--accent); }
.fmt-bar .f-b { font-weight: 700; }
.fmt-bar .f-i { font-style: italic; font-family: Georgia, serif; }
.fmt-bar .f-u { text-decoration: underline; }
.fmt-bar .f-s { text-decoration: line-through; }
.fmt-bar .f-c { font-family: var(--mono); font-size: 13px; }

/* static (read-only) blocks: network detail panel */
.static-blocks { font-size: 15px; }
.sblk { padding-left: calc(var(--indent, 0) * 24px); margin: 2px 0; }
.blk-content { padding: 2px 0; white-space: pre-wrap; word-break: break-word; }
.blk-row { display: flex; align-items: flex-start; }
.blk-row .blk-marker { min-height: 0; padding-top: 2px; }
.sblk.blk-h1 .blk-content { font-size: 22px; font-weight: 700; }
.sblk.blk-h2 .blk-content { font-size: 19px; font-weight: 650; }
.sblk.blk-h3 .blk-content { font-size: 16px; font-weight: 650; margin-top: 8px; }
.sblk.blk-quote .blk-content { border-left: 3px solid currentColor; padding-left: 12px; }
.static-blocks .blk-callout { padding: 10px 12px; }

/* ------------------------------------------------------------------ peek panel */

.peek-head { display: flex; align-items: center; gap: 4px; height: var(--topbar-h); padding: 0 10px; flex: none; border-bottom: 1px solid transparent; }
.peek-head .crumb { max-width: 60%; }
.peek-body { flex: 1 1 auto; overflow: auto; min-height: 0; }

/* ------------------------------------------------------------------ databases */

.db { padding-top: 6px; }
.db-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  min-height: 42px;
  position: sticky;
  left: 0;
}
.db-tabs { display: flex; align-items: center; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.db-tabs::-webkit-scrollbar { display: none; }
.db-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: none;
  font-size: 14px;
  color: var(--fg-muted);
  white-space: nowrap;
  position: relative;
}
.db-tab:hover { background: var(--hover); color: var(--fg); }
.db-tab.active { color: var(--fg); font-weight: 500; }
.db-tab.active::after { content: ""; position: absolute; left: 6px; right: 6px; bottom: -7px; height: 2px; background: var(--fg); border-radius: 1px; }
.db-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.db-search { width: 170px; height: 28px; font-size: 13px; }
.db-empty { padding: 32px 0; color: var(--fg-faint); text-align: center; font-size: 14px; }

.db-table-wrap { overflow-x: auto; margin: 0 calc(var(--pad-x) * -1); padding: 0 var(--pad-x); }
.db-table { border-collapse: collapse; font-size: 14px; min-width: 100%; table-layout: fixed; }
.db-table th, .db-table td { border: 1px solid var(--border); border-left: 0; text-align: left; vertical-align: top; padding: 0; }
.db-table tr > :last-child { border-right: 0; }
.db-table thead th { border-top: 0; font-weight: 400; color: var(--fg-muted); }
.th-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 34px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 14px;
  white-space: nowrap;
  text-align: left;
}
.th-btn:hover { background: var(--hover); }
.th-btn span { overflow: hidden; text-overflow: ellipsis; }
.th-btn .sort-ind { margin-left: auto; color: var(--fg-faint); }
.th-add { width: 40px; }
.th-add .th-btn { justify-content: center; }
.db-table td.cell { height: 34px; padding: 6px 8px; cursor: pointer; overflow: hidden; word-break: break-word; }
.db-table td.cell:hover { background: var(--hover); }
.db-table td.cell.readonly { cursor: default; color: var(--fg-muted); }
.db-table td.cell-title { position: relative; padding-right: 74px; }
.db-table td.cell-title .v-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: flex; }
.db-table td.cell-title .v-title span { overflow: hidden; text-overflow: ellipsis; }
.row-actions { position: absolute; right: 6px; top: 5px; display: none; gap: 2px; }
.db-table tr:hover .row-actions, .row-actions:focus-within { display: flex; }
.row-open {
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-card);
}
.row-open:hover { color: var(--fg); background: var(--bg-soft); }
.row-actions .icon-btn { width: 24px; height: 24px; background: var(--bg-elev); border: 1px solid var(--border-strong); box-shadow: var(--shadow-card); }
.db-table td.td-pad { border-right: 0; }
.db-foot { display: flex; align-items: center; gap: 12px; min-height: 36px; font-size: 14px; color: var(--fg-faint); border-bottom: 1px solid var(--border); }
.db-new-row { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; border: 0; background: none; color: var(--fg-faint); font-size: 14px; border-radius: 4px; }
.db-new-row:hover { background: var(--hover); color: var(--fg-muted); }
.db-count { margin-left: auto; font-size: 13px; }
.db-count b { font-weight: 500; color: var(--fg-muted); }

/* board */
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; margin: 0 calc(var(--pad-x) * -1); padding: 4px var(--pad-x) 24px; }
.board-col { flex: 0 0 260px; display: flex; flex-direction: column; gap: 6px; border-radius: 8px; padding: 4px; min-height: 80px; transition: background 0.1s; }
.board-col.drop { background: var(--accent-soft); }
.board-col-head { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 4px; font-size: 14px; color: var(--fg-muted); }
.board-count { color: var(--fg-faint); font-size: 13px; }
.board-col-body { display: flex; flex-direction: column; gap: 6px; min-height: 8px; }
.board-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-card);
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
}
.board-card:hover { background: var(--bg-soft); }
.board-card.dragging { opacity: 0.4; }
.card-title { font-weight: 500; display: flex; gap: 6px; align-items: center; word-break: break-word; }
.card-props { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--fg-muted); }
.card-props .chip { font-size: 12px; height: 18px; line-height: 18px; }
.card-props .rel-chip { font-size: 12px; line-height: 18px; }
.board-add { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border: 0; border-radius: 5px; background: none; color: var(--fg-faint); font-size: 14px; text-align: left; width: 100%; }
.board-add:hover { background: var(--hover); color: var(--fg-muted); }
.board-newgroup { flex: 0 0 200px; padding-top: 4px; }
.board-setup { padding: 32px 0; text-align: center; color: var(--fg-muted); font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ------------------------------------------------------------------ network view */

.net-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin: 8px 0 12px; }
.net-stats { display: flex; gap: 22px; font-size: 14px; color: var(--fg-muted); }
.net-stats .stat { display: flex; align-items: baseline; gap: 6px; }
.net-stats .stat b { font-size: 22px; font-weight: 650; color: var(--fg-strong); font-variant-numeric: tabular-nums; }
.net-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--fg-muted); }
.net-legend span { display: inline-flex; align-items: center; gap: 6px; }
.net-legend .sw { width: 12px; height: 12px; border-radius: 3px; background: var(--tone-soft); border: 1.5px solid var(--tone-line); display: inline-block; }
.net-legend .ln { width: 22px; height: 0; border-top: 1.5px solid var(--net-edge); display: inline-block; }
.net-legend .ln.soft { border-top-style: dashed; border-top-color: var(--net-edge); }
.net-legend .ln.cyc { border-top-color: var(--danger); border-top-width: 2px; }
.net-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; font-size: 13px; }
.net-label { font-size: 12px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--fg-faint); margin-right: 4px; }
.fchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: var(--bg);
  font-size: 13px;
  color: var(--fg);
}
.fchip i { width: 9px; height: 9px; border-radius: 50%; background: var(--tone-line); flex: none; }
.fchip b { font-weight: 500; color: var(--fg-faint); font-variant-numeric: tabular-nums; }
.fchip:hover { background: var(--hover); }
.fchip[aria-pressed="false"] { opacity: 0.5; text-decoration: line-through; background: transparent; border-style: dashed; }
.net-status { display: inline-flex; gap: 8px; align-items: center; margin-left: 8px; color: var(--fg-muted); }
.net-tools { display: flex; align-items: center; justify-content: flex-end; gap: 2px; margin-bottom: 4px; }
.net-zoom { font-size: 12px; color: var(--fg-muted); min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }
.net-panel {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  max-height: 72vh;
  -webkit-overflow-scrolling: touch;
}
.net-empty { padding: 40px 20px; text-align: center; color: var(--fg-muted); font-size: 14px; }
.net-svg { display: block; font-family: var(--font); user-select: none; }
.net-svg .edge { fill: none; stroke: var(--net-edge); stroke-width: 1.5; transition: opacity 0.15s; }
.net-svg .edge.k-start, .net-svg .edge.k-end { stroke: var(--net-edge-soft); }
.net-svg .edge.k-redundant { stroke: var(--net-edge); stroke-dasharray: 5 4; opacity: 0.8; }
.net-svg .edge.k-cycle { stroke: var(--danger); stroke-width: 2; }
.net-svg .ah { fill: var(--net-edge); }
.net-svg .ah-soft { fill: var(--net-edge); opacity: 0.8; }
.net-svg .ah-hi { fill: var(--accent); }
.net-svg .ah-cyc { fill: var(--danger); }
.net-svg .node { cursor: pointer; outline: none; transition: opacity 0.15s; }
.net-svg .node rect { fill: var(--tone-soft); stroke: var(--tone-line); stroke-width: 1.5; }
.net-svg .node:hover rect { stroke-width: 2.2; }
.net-svg .node:focus-visible rect { stroke: var(--accent); stroke-width: 3; }
.net-svg .node .tid { font-size: 12px; font-weight: 700; fill: var(--tone-line); font-variant-numeric: tabular-nums; }
.net-svg .node .tag { font-size: 9.5px; font-weight: 600; letter-spacing: 0.05em; fill: var(--fg-faint); }
.net-svg .node .tname { font-size: 14px; font-weight: 500; fill: var(--fg); }
.net-svg .term rect { fill: var(--bg-soft); stroke: var(--net-edge-soft); stroke-width: 1.5; }
.net-svg .term text { font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; fill: var(--fg-faint); }
.net-svg.focus .node, .net-svg.focus .term { opacity: 0.22; }
.net-svg.focus .edge { opacity: 0.12; }
.net-svg.focus .on { opacity: 1; }
.net-svg.focus .edge.on { opacity: 1; stroke: var(--accent); stroke-width: 2.2; }
.net-svg.focus .edge.on.k-cycle { stroke: var(--danger); }
.net-svg .node.self rect { stroke-width: 3; }
.net-svg .node.off { opacity: 0.12; pointer-events: none; }
.net-svg .edge.off { opacity: 0.06; }
.net-svg .node.dim { opacity: 0.35; }
.net-svg.focus .node.off, .net-svg.focus .edge.off { opacity: 0.06; }
.net-hint, .net-note { font-size: 13px; color: var(--fg-faint); margin: 8px 0; }
.net-sub { font-size: 15px; font-weight: 600; margin: 28px 0 4px; color: var(--fg); }
.net-loose { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.loose-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  font-size: 14px;
}
.loose-card:hover { background: var(--hover); }
.net-detail { margin: 12px 0 8px; }
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.detail-head .btn { height: 28px; }
.detail-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--tone-line);
  border-radius: 8px;
  padding: 14px 18px;
  background: var(--bg);
}
.detail-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-title .tid { font-weight: 700; color: var(--tone-line); font-variant-numeric: tabular-nums; }
.detail-title h3 { margin: 0; font-size: 18px; font-weight: 650; color: var(--fg-strong); }
.detail-meta { margin: 4px 0 10px; font-size: 13px; color: var(--fg-muted); }
.detail-body { font-size: 15px; }
.detail-props { margin-top: 12px; font-size: 14px; }
.detail-props summary { cursor: pointer; color: var(--fg-muted); padding: 4px 0; }
.net-setup { padding: 40px 20px; text-align: center; color: var(--fg); display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px; }
.net-setup-ico { color: var(--fg-faint); }

/* ------------------------------------------------------------------ search */

.search-backdrop { align-items: start; padding-top: 12vh; }
.search-modal {
  width: min(640px, 100%);
  max-height: min(560px, 76vh);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.search-top { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border); color: var(--fg-faint); }
.search-input { flex: 1 1 auto; height: 52px; border: 0; outline: none; background: none; font-size: 17px; color: var(--fg); min-width: 0; }
.search-input:focus-visible { box-shadow: none; }
.search-results { overflow: auto; padding: 6px; }
.search-section { padding: 8px 10px 4px; font-size: 12px; font-weight: 600; color: var(--fg-faint); }
.search-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  font-size: 14px;
}
.search-item.active { background: var(--hover); }
.search-ico { width: 20px; height: 20px; display: inline-grid; place-items: center; color: var(--fg-muted); font-size: 16px; line-height: 1; flex: none; margin-top: 1px; }
.search-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.search-title { color: var(--fg); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-crumbs { font-size: 12px; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-snippet { font-size: 13px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.search-empty { padding: 28px; text-align: center; color: var(--fg-faint); font-size: 14px; }
.search-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--fg-faint); }
kbd { font-family: var(--font); font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--bg-soft); }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1100px) {
  :root { --pad-x: 56px; }
}

@media (max-width: 860px) {
  :root { --pad-x: 24px; }
  #peek {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(100vw, 560px);
    z-index: 60;
  }
  .page.peek { padding: 0 24px 30vh; }
  .page.peek .page-banner { margin: 0 -24px; }
}

@media (max-width: 760px) {
  #app, body.sidebar-collapsed #app { grid-template-columns: 0 minmax(0, 1fr) 0; }
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 86vw);
    z-index: 70;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.18s ease-out, visibility 0.18s;
    box-shadow: var(--shadow-pop);
  }
  body.sidebar-open #sidebar { visibility: visible; transform: none; }
  body.sidebar-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 15, 15, 0.35); z-index: 65; }
  .tb-toggle, body.sidebar-collapsed .tb-toggle { display: inline-grid; }
  :root { --pad-x: 16px; }
  .page { padding-bottom: 40vh; }
  .page-head { padding-top: 28px; }
  .page-head.has-icon { padding-top: 20px; }
  .page-title { font-size: 30px; }
  .page-icon { font-size: 52px; height: 62px; min-width: 62px; }
  .page-tools { opacity: 1; }
  .blk { padding-left: calc(var(--indent, 0) * 20px); }
  .blk-gutter { display: none; }
  .crumb { max-width: 140px; }
  .tb-status .tb-status-text { display: none; }
  .tb-status { padding: 0 6px; }
  .db-search { width: 120px; }
  .prop-row { grid-template-columns: minmax(96px, 120px) minmax(0, 1fr); }
  .net-stats { gap: 14px; }
  .search-backdrop { padding-top: 16px; }
  .fmt-bar { max-width: calc(100vw - 16px); overflow-x: auto; }
  .page.peek { padding: 0 16px 30vh; }
  .page.peek .page-banner { margin: 0 -16px; }
}

@media (hover: none) {
  .tree-btns { display: inline-flex; }
  .row-actions { display: flex; position: static; margin-top: 4px; }
  .db-table td.cell-title { padding-right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  #sidebar, #topbar, #peek, .blk-gutter, .page-tools { display: none !important; }
  #app { display: block; height: auto; }
  body { overflow: visible; }
  #content { overflow: visible; }
}

/* ------------------------------------------------------------------ sign-in (Discord) */

.avatar { overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.login-body { overflow: auto; display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; background: var(--bg-sidebar); }
.login-card {
  width: min(380px, 100%);
  padding: 36px 32px 28px;
  border-radius: 12px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-card);
  text-align: center;
}
.login-logo { display: block; margin: 0 auto 12px; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; color: var(--fg-strong); }
.login-card .muted { margin: 0 0 22px; }
.login-btn { justify-content: center; width: 100%; height: 40px; font-size: 15px; text-decoration: none; }
.login-error { margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 14px; text-align: left; }
.login-note { margin: 16px 0 0; font-size: 13px; color: var(--fg-faint); }
