/* ============================================================
   Ospaces — visual identity "panes on a frame"
   ------------------------------------------------------------
   The workspace sits on a deep-indigo FRAME (the "space").
   Content lives on a light floating PANE; the sidebar is a rail
   directly on the frame — light-on-dark in BOTH themes.
   Type: Space Grotesk (display) · Instrument Sans (UI/body)
         · JetBrains Mono (code).  Accent: iris #5b5bd6.
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font: "Instrument Sans", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-display: "Space Grotesk", var(--font);
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* the frame: constant dark canvas behind everything */
  --frame: #1b1e36;
  --frame-deep: #14162b;

  /* pane surfaces */
  --bg: #ffffff;
  --bg-sidebar: transparent;
  --bg-hover: rgba(35, 39, 74, 0.055);
  --bg-active: rgba(35, 39, 74, 0.1);
  --bg-code: #f4f5fa;
  --bg-callout: #f1f2f9;
  --bg-modal: #ffffff;
  --bg-input: #ffffff;
  --bg-banner: #e5534b;

  --text: #1f2335;
  --text-light: #676d89;
  --text-faint: #989db6;
  --text-placeholder: rgba(31, 35, 53, 0.34);

  --border: #e7e8f1;
  --border-strong: #d0d2e2;
  --accent: #5b5bd6;
  --accent-hover: #4a4ac8;
  --accent-soft: #8f8ff3;
  --danger: #e5534b;
  --star: #efaf3d;

  --shadow-popover: rgba(20, 22, 43, 0.06) 0 0 0 1px, rgba(20, 22, 43, 0.09) 0 4px 10px, rgba(20, 22, 43, 0.16) 0 14px 32px;
  --shadow-card: rgba(20, 22, 43, 0.08) 0 0 0 1px, rgba(20, 22, 43, 0.07) 0 2px 6px;
  --shadow-pane: 0 1px 2px rgba(8, 9, 22, 0.3), 0 10px 40px rgba(8, 9, 22, 0.35);

  --radius-pane: 14px;
  --radius-card: 10px;
  --radius-ctl: 8px;

  --sidebar-w: 268px;
  --topbar-h: 46px;
  --page-w: 708px;
}

html[data-theme="dark"] {
  --frame: #0b0d1b;
  --frame-deep: #070812;

  --bg: #14172a;
  --bg-hover: rgba(190, 196, 255, 0.07);
  --bg-active: rgba(190, 196, 255, 0.13);
  --bg-code: #1c2038;
  --bg-callout: #1d2138;
  --bg-modal: #191d33;
  --bg-input: #1f2340;

  --text: #e3e5f3;
  --text-light: #a1a6c2;
  --text-faint: #6e7392;
  --text-placeholder: rgba(227, 229, 243, 0.3);

  --border: #262a45;
  --border-strong: #383d61;

  --shadow-popover: rgba(150, 156, 255, 0.1) 0 0 0 1px, rgba(0, 0, 0, 0.45) 0 4px 10px, rgba(0, 0, 0, 0.6) 0 14px 32px;
  --shadow-card: rgba(150, 156, 255, 0.1) 0 0 0 1px, rgba(0, 0, 0, 0.35) 0 2px 6px;
  --shadow-pane: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 40px rgba(0, 0, 0, 0.5);
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--frame);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; }
::selection { background: rgba(91, 91, 214, 0.24); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
#sidebar ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border: 2px solid transparent; background-clip: content-box; }

/* visible keyboard focus without spamming contenteditable surfaces */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [role="switch"]:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 1px;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px; color: var(--text-light);
  font-size: 15px; flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---- icons (inline SVG) ---- */
.ic { display: block; flex-shrink: 0; }
.sb-action-icon, .ti-icon, .lib-p-icon, .lib-tab-ic, .result-icon,
.menu-item-ic, .ti-toggle, .lib-twist { display: inline-flex; align-items: center; justify-content: center; }
.menu-item-ic { width: 22px; }
.result-icon { width: 26px; }
/* the default (no-emoji) page icon renders as a subtle line glyph */
.page-file-ic { color: var(--text-faint); }
.tree-item.active .page-file-ic, .lib-item:hover .page-file-ic { color: var(--text-light); }

/* brand mark: iris gradient tile (shared recipe) */
.sb-logo, .login-logo, .empty-logo {
  background: linear-gradient(135deg, #6a63e8 0%, #4f52d4 55%, #3d3fb8 100%);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ============================================================
   Login screen — the frame at full depth
   ============================================================ */
/* ---- Login: premium split (living brand story + refined form) ---- */
#login-screen { min-height: 100vh; min-height: 100dvh; display: flex; background: var(--bg); }
.login-split { flex: 1; display: grid; grid-template-columns: 1.08fr 0.92fr; min-height: 0; }

/* ============ left: the "space" — deep iris frame with aurora ============ */
.login-brand {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; gap: 24px;
  padding: 46px 54px; color: #fff;
  background:
    radial-gradient(120% 120% at 12% 8%, #6f5be6 0%, #5b5bd6 34%, #4038c4 72%, #2e2a9e 100%);
}
/* drifting aurora blobs give the frame depth + life */
.login-aurora {
  position: absolute; inset: -30% -10% -10%; pointer-events: none; z-index: 0;
  background:
    radial-gradient(38% 44% at 20% 22%, rgba(160, 160, 255, 0.55), transparent 62%),
    radial-gradient(34% 40% at 82% 30%, rgba(224, 143, 208, 0.42), transparent 60%),
    radial-gradient(46% 50% at 68% 88%, rgba(106, 99, 232, 0.55), transparent 64%),
    radial-gradient(40% 46% at 8% 92%, rgba(120, 140, 255, 0.40), transparent 62%);
  filter: blur(6px) saturate(1.05);
  animation: login-aurora 26s ease-in-out infinite alternate;
}
@keyframes login-aurora {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(2%, -2.5%, 0) scale(1.08); }
  100% { transform: translate3d(-2%, 1.5%, 0) scale(1.04); }
}
/* faint dotted grid — the "frame" texture */
.login-grid-tex {
  position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: 0.5;
  background-image: radial-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1.4px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(120% 100% at 50% 0%, #000 40%, transparent 92%);
          mask-image: radial-gradient(120% 100% at 50% 0%, #000 40%, transparent 92%);
}
.login-brand > * { position: relative; z-index: 1; }

.login-brand-mark { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 600; font-size: 18px; color: #fff; align-self: flex-start; text-decoration: none; }
.login-logo-sm {
  width: 30px; height: 30px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.16); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  font-family: var(--font-display); font-weight: 700; font-size: 16px;
}

.login-brand-body { max-width: 500px; }
.login-eyebrow {
  display: inline-block; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase; color: rgba(255, 255, 255, 0.78);
  padding: 5px 11px; border-radius: 999px; margin-bottom: 18px;
  background: rgba(255, 255, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.login-brand-title { font-family: var(--font-display); font-size: clamp(34px, 3.4vw, 50px); font-weight: 600; letter-spacing: -1.4px; line-height: 1.02; margin-bottom: 16px; }
.login-brand-sub { font-size: 16.5px; line-height: 1.58; color: rgba(255, 255, 255, 0.82); max-width: 430px; }

/* ---- floating product showcase: panes on the frame ---- */
.login-stage {
  position: relative; margin-top: 44px; max-width: 460px;
  animation: login-rise 0.9s cubic-bezier(0.2, 0.85, 0.3, 1) 0.05s both;
}
@keyframes login-rise { from { opacity: 0; transform: translateY(22px); } }
.lx-win {
  position: relative; border-radius: 14px; overflow: hidden;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 2px 6px rgba(10, 8, 45, 0.28), 0 30px 60px -18px rgba(8, 6, 40, 0.6);
  transform: perspective(1400px) rotateX(6deg) rotateY(-9deg) rotate(0.4deg);
  transform-origin: 50% 60%;
  animation: lx-float 8s ease-in-out infinite alternate;
}
@keyframes lx-float {
  from { transform: perspective(1400px) rotateX(6deg) rotateY(-9deg) translateY(0); }
  to   { transform: perspective(1400px) rotateX(6deg) rotateY(-9deg) translateY(-12px); }
}
.lx-bar { display: flex; align-items: center; gap: 6px; padding: 10px 13px; background: #f3f3fb; border-bottom: 1px solid #e7e7f3; }
.lx-dot { width: 8px; height: 8px; border-radius: 50%; background: #cfcfe0; }
.lx-dot:nth-child(1) { background: #f0a3a3; }
.lx-dot:nth-child(2) { background: #f3d08a; }
.lx-dot:nth-child(3) { background: #9fd6a8; }
.lx-bar-t { margin-left: 8px; font-family: var(--font-mono); font-size: 10.5px; color: #9195b4; letter-spacing: 0.02em; }
.lx-body { display: grid; grid-template-columns: 74px 1fr; min-height: 176px; }
.lx-side { padding: 14px 11px; display: flex; flex-direction: column; gap: 9px; background: #1b1e36; }
.lx-s-logo { width: 20px; height: 20px; border-radius: 6px; background: linear-gradient(135deg, #6a63e8, #4f52d4); margin-bottom: 4px; }
.lx-s-row { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.15); }
.lx-s-row.short { width: 62%; }
.lx-s-row.is-on { background: rgba(150, 150, 255, 0.85); }
.lx-main { padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 9px; }
.lx-h { width: 58%; height: 12px; border-radius: 5px; background: #2a2d4a; }
.lx-line { height: 7px; border-radius: 4px; background: #e2e3ef; }
.lx-line.short { width: 72%; }
.lx-kanban { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.lx-card { height: 46px; border-radius: 8px; background: #eef0fb; box-shadow: inset 0 0 0 1px #e3e5f5; }
.lx-card.tall { height: 62px; background: linear-gradient(160deg, #eae8ff, #f4f0ff); box-shadow: inset 0 0 0 1px #ddd8fb; }

/* satellite chips floating off the pane */
.lx-chip {
  position: absolute; display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 11px; font-size: 12.5px; font-weight: 600; color: #232746;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 30px -8px rgba(8, 6, 40, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  animation: lx-float2 6.5s ease-in-out infinite alternate;
}
.lx-chip-a { top: -16px; right: 4px; animation-delay: -1.6s; }
.lx-chip-b { bottom: 8px; left: -30px; }
@keyframes lx-float2 { from { transform: translateY(0); } to { transform: translateY(-9px); } }
.lx-chip-ic { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; background: #22a06b; color: #fff; }
.lx-chip-ic svg { width: 11px; height: 11px; }
.lx-chip-spark { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, #7b5be6, #5b5bd6); box-shadow: 0 0 0 3px rgba(123, 91, 230, 0.18); }

/* footer: mono feature tags + credit */
.login-brand-foot { display: flex; flex-direction: column; gap: 14px; }
.login-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.login-tags span {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.82); padding: 4px 9px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.09); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
}
.login-credit { font-size: 12.5px; color: rgba(255, 255, 255, 0.6); }

/* ============ right: form panel (theme-aware surface) ============ */
.login-panel { position: relative; display: flex; align-items: center; justify-content: center; padding: 44px 32px; background: var(--bg); }
.login-home {
  position: absolute; top: 24px; left: 28px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  font-size: 13.5px; font-weight: 500; color: var(--text-light);
  padding: 6px 11px 6px 9px; border-radius: 8px; transition: background 0.14s, color 0.14s;
}
.login-home:hover { color: var(--text); background: var(--bg-hover); }
.login-home svg { transition: transform 0.14s; }
.login-home:hover svg { transform: translateX(-2px); }

.login-card {
  width: 100%; max-width: 384px; text-align: left; padding: 0; background: transparent;
  animation: login-card-in 0.55s cubic-bezier(0.2, 0.85, 0.3, 1) both;
}
@keyframes login-card-in { from { opacity: 0; transform: translateY(14px); } }
/* re-fire a subtle fade when switching login<->signup */
.login-card.is-swapping .login-heading,
.login-card.is-swapping .login-sub { animation: login-swap 0.34s ease both; }
@keyframes login-swap { from { opacity: 0; transform: translateY(-4px); } }

.login-logo {
  width: 46px; height: 46px; margin: 0 0 18px; border-radius: 13px; font-size: 24px;
  box-shadow: 0 8px 22px rgba(79, 82, 212, 0.4);
}
.login-heading { font-family: var(--font-display); font-size: 27px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.login-sub { color: var(--text-light); font-size: 14.5px; margin: 7px 0 24px; }

.login-field { margin-bottom: 14px; }
.login-label-row { display: flex; align-items: baseline; justify-content: space-between; }
.login-label { display: block; text-align: left; font-size: 12.5px; font-weight: 600; color: var(--text-light); margin: 0 0 6px; }
.login-forgot { font-size: 12px; font-weight: 500; color: var(--accent); background: none; padding: 0; }
.login-forgot:hover { text-decoration: underline; }

.login-input-wrap { position: relative; display: flex; align-items: center; }
.login-in-ic {
  position: absolute; left: 12px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint); pointer-events: none; transition: color 0.14s;
}
.login-in-ic svg { width: 17px; height: 17px; }
.login-input {
  width: 100%; padding: 11px 13px 11px 38px; font-size: 14.5px; font-family: var(--font);
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg-input); color: var(--text); outline: none;
  transition: border-color 0.14s, box-shadow 0.14s, background 0.14s;
}
.login-input::placeholder { color: var(--text-placeholder); }
.login-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 91, 214, 0.16); }
.login-input-wrap:focus-within .login-in-ic { color: var(--accent); }
/* password field leaves room for the toggle */
#login-password { padding-right: 44px; }
/* valid email → green check + subtle green border */
.login-in-ok {
  position: absolute; right: 12px; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; color: #fff; background: #22a06b;
  opacity: 0; transform: scale(0.6); transition: opacity 0.16s, transform 0.16s;
}
.login-in-ok svg { width: 11px; height: 11px; }
.login-field.is-valid .login-in-ok { opacity: 1; transform: scale(1); }
.login-field.is-valid .login-input { border-color: rgba(34, 160, 107, 0.55); }
.login-field.is-invalid .login-input { border-color: var(--danger); }
.login-field.is-invalid .login-in-ic { color: var(--danger); }

.login-pw-toggle {
  position: absolute; right: 6px; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 7px; color: var(--text-faint);
  transition: color 0.14s, background 0.14s;
}
.login-pw-toggle:hover { color: var(--text-light); background: var(--bg-hover); }
.login-pw-toggle svg { width: 17px; height: 17px; }

/* [hidden] must win over the display below (author styles beat the UA rule) */
.login-caps[hidden], .login-strength[hidden] { display: none !important; }
.login-caps {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 12px; font-weight: 500; color: #b8791b;
}
.login-caps svg { width: 13px; height: 13px; }
html[data-theme="dark"] .login-caps { color: #e6b25a; }

.login-strength { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.login-strength-bar { flex: 1; height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.login-strength-bar > i {
  display: block; height: 100%; width: 0%; border-radius: 3px; background: var(--danger);
  transition: width 0.28s cubic-bezier(0.2, 0.85, 0.3, 1), background 0.28s;
}
.login-strength-label { font-size: 11.5px; font-weight: 600; color: var(--text-faint); min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.login-strength[data-level="1"] > .login-strength-bar > i { width: 30%; background: #e5534b; }
.login-strength[data-level="2"] > .login-strength-bar > i { width: 58%; background: #e0982f; }
.login-strength[data-level="3"] > .login-strength-bar > i { width: 80%; background: #3d9a5c; }
.login-strength[data-level="4"] > .login-strength-bar > i { width: 100%; background: #22a06b; }

.login-btn {
  position: relative; width: 100%; margin-top: 6px; padding: 11px 13px; border-radius: 10px;
  font-size: 14.5px; font-weight: 500; border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--bg); color: var(--text);
  transition: background 0.14s, border-color 0.14s, box-shadow 0.14s, transform 0.1s;
}
.login-btn:hover { background: var(--bg-hover); }
.login-btn.primary {
  margin-top: 4px; background: var(--accent); border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 2px 6px rgba(40, 40, 120, 0.2), 0 8px 20px rgba(82, 82, 205, 0.3);
}
.login-btn.primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(40, 40, 120, 0.24), 0 12px 26px rgba(82, 82, 205, 0.4); }
.login-btn.primary:active { transform: translateY(0); }
.login-btn:disabled { cursor: default; transform: none; }
.login-btn.primary:disabled { opacity: 0.9; }
/* spinner shown while submitting */
.login-spin { display: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; animation: login-spin 0.6s linear infinite; }
.login-btn.is-loading .login-btn-label { visibility: hidden; }
.login-btn.is-loading .login-spin { display: block; position: absolute; }
@keyframes login-spin { to { transform: rotate(360deg); } }

.login-divider {
  display: flex; align-items: center; gap: 10px; margin: 18px 0 14px;
  color: var(--text-faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em;
}
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.login-error, .login-note {
  display: flex; align-items: flex-start; gap: 8px;
  margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px; text-align: left; line-height: 1.4;
}
.login-error { background: rgba(229, 83, 75, 0.1); color: var(--danger); box-shadow: inset 0 0 0 1px rgba(229, 83, 75, 0.22); animation: login-shake 0.34s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
.login-error::before {
  content: ""; flex-shrink: 0; width: 15px; height: 15px; margin-top: 1px;
  background: currentColor;
  -webkit-mask: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8v5'/%3E%3Cpath d='M12 16.5h.01'/%3E%3C/svg%3E");
          mask: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8v5'/%3E%3Cpath d='M12 16.5h.01'/%3E%3C/svg%3E");
}
.login-note { background: rgba(34, 160, 107, 0.1); color: #1c8a5b; box-shadow: inset 0 0 0 1px rgba(34, 160, 107, 0.24); }
html[data-theme="dark"] .login-note { color: #4fca8f; }
@keyframes login-shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }

.login-switch { margin-top: 22px; font-size: 13.5px; color: var(--text-light); }
.login-switch a { color: var(--accent); text-decoration: none; font-weight: 600; }
.login-switch a:hover { text-decoration: underline; }
.login-legal { margin-top: 16px; font-size: 11.5px; line-height: 1.5; color: var(--text-faint); }
.login-legal a { color: var(--text-light); text-decoration: none; }
.login-legal a:hover { text-decoration: underline; color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .login-aurora, .lx-win, .lx-chip { animation: none !important; }
  .login-stage, .login-card, .login-card.is-swapping .login-heading, .login-card.is-swapping .login-sub { animation: none !important; }
}

@media (max-width: 980px) {
  .login-split { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-panel { padding: 64px 22px 40px; align-items: flex-start; }
  .login-card { margin: 0 auto; }
}
@media (max-width: 420px) {
  .login-home { top: 16px; left: 16px; }
  .login-panel { padding: 58px 16px 32px; }
}

/* ============================================================
   App layout — rail on the frame, content on a floating pane
   ============================================================ */
#app { display: flex; height: 100vh; padding: 8px; }

#sidebar {
  width: var(--sidebar-w); flex-shrink: 0; height: 100%;
  background: var(--bg-sidebar);
  padding-right: 8px;
  display: flex; flex-direction: column;
  transition: margin-left 0.2s ease;
  /* the rail lives on the dark frame in BOTH themes */
  --text: #eceef8;
  --text-light: #b6bad2;
  --text-faint: #7e83a4;
  --text-placeholder: rgba(236, 238, 248, 0.35);
  --bg-hover: rgba(255, 255, 255, 0.07);
  --bg-active: rgba(255, 255, 255, 0.13);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  color: var(--text);
}
body.sidebar-collapsed #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sb-header {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 10px 8px 6px;
}
.sb-workspace {
  display: flex; align-items: center; gap: 9px; padding: 4px 6px; border-radius: 8px;
  min-width: 0; flex: 1;
}
.sb-logo {
  width: 24px; height: 24px; border-radius: 7px; flex-shrink: 0;
  font-size: 14px;
}
.sb-ws-name {
  font-family: var(--font-display); font-weight: 600; font-size: 14.5px; letter-spacing: 0.1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#btn-collapse { opacity: 0; transition: opacity 0.15s; }
#sidebar:hover #btn-collapse { opacity: 1; }

.sb-top-actions { padding: 2px 8px 8px; display: flex; flex-direction: column; gap: 1px; }
.sb-action {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border-radius: var(--radius-ctl); min-height: 30px;
  font-size: 13.5px; font-weight: 500; color: var(--text-light);
  text-align: left; line-height: 1.15;
  transition: background 0.12s, color 0.12s;
}
.sb-action:hover { background: var(--bg-hover); color: var(--text); }
.sb-action.active { background: var(--bg-active); color: var(--text); }
.sb-action-icon {
  width: 18px; height: 18px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  text-align: center; font-size: 14px; color: var(--text-faint);
  transition: color 0.12s;
}
.sb-action:hover .sb-action-icon, .sb-action.active .sb-action-icon { color: var(--text-light); }

/* the one prominent create action */
.sb-action-primary {
  margin: 6px 0 2px; color: var(--text); font-weight: 600;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-soft) 32%, transparent);
}
.sb-action-primary .sb-action-icon { color: var(--accent-soft); }
.sb-action-primary:hover { background: color-mix(in srgb, var(--accent) 32%, transparent); color: #fff; }
.sb-action-primary:hover .sb-action-icon { color: #fff; }

/* nav clusters (AI Assistant · Workspace) fold with the same chevron as every
   other section, so the whole column shares one dropdown model */
.sb-nav-section { margin-top: 12px; }
.sb-nav-section > .sb-action { min-height: 29px; }

.sb-kbd {
  margin-left: auto; font-size: 10.5px; color: var(--text-faint);
  font-family: var(--font); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px;
}

.sb-scroll { flex: 1; overflow-y: auto; padding: 6px 8px 12px; border-top: 1px solid var(--border); }
.sb-section { margin-top: 14px; }
.sb-scroll > .sb-section:first-child { margin-top: 2px; }
.sb-section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  font-family: var(--font-display);
  font-size: 11px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.7px;
  padding: 2px 6px 2px 4px; margin-bottom: 2px; border-radius: 6px;
  cursor: pointer; user-select: none;
  transition: background 0.12s, color 0.12s;
}
.sb-section-title:hover { background: var(--bg-hover); color: var(--text-light); }
.sb-sec-head { display: inline-flex; align-items: center; gap: 3px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-sec-twist {
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; flex-shrink: 0; color: var(--text-faint);
  transform: rotate(90deg); transition: transform 0.15s;
}
.sb-section.collapsed .sb-sec-twist { transform: rotate(0deg); }
.sb-section.collapsed > *:not(.sb-section-title) { display: none; }
.sb-section-add { opacity: 0; width: 20px; height: 20px; font-size: 14px; }
.sb-section:hover .sb-section-add, .sb-section-title:hover .sb-section-add { opacity: 1; }
.sb-add-page { color: var(--text-faint); font-size: 13.5px; margin-top: 2px; }

/* --- tree items --- */
.tree-item {
  display: flex; align-items: center; gap: 2px;
  padding: 3px 4px 3px 4px; border-radius: 7px;
  font-size: 13.5px; color: var(--text-light); font-weight: 500;
  cursor: pointer; user-select: none; min-height: 28px;
  transition: background 0.12s, color 0.12s;
}
.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--bg-active); color: var(--text); box-shadow: inset 2px 0 0 var(--accent-soft); }
.tree-item.dragging { opacity: 0.4; }
.tree-item.drop-before { box-shadow: inset 0 2px 0 var(--accent-soft); }
.tree-item.drop-after { box-shadow: inset 0 -2px 0 var(--accent-soft); }
.tree-item.drop-inside { background: var(--bg-active); box-shadow: inset 0 0 0 1.5px var(--accent-soft); }
.ti-toggle {
  width: 20px; height: 20px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 10px;
  transition: transform 0.15s;
}
.ti-toggle:hover { background: var(--bg-active); }
.ti-toggle.expanded { transform: rotate(90deg); }
.ti-icon { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.ti-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-actions { display: none; align-items: center; gap: 1px; }
.tree-item:hover .ti-actions { display: flex; }
.ti-actions .icon-btn { width: 22px; height: 22px; font-size: 13px; }
.tree-empty { font-size: 13px; color: var(--text-faint); padding: 3px 8px; font-style: italic; }

/* --- sidebar footer --- */
.sb-footer { padding: 6px 8px 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 1px; }
/* Settings / Trash / Theme collapse into one tidy icon row (names in tooltips) */
.sb-footer-row { display: flex; gap: 4px; margin: 1px 0; }
.sb-footer-row .sb-action { flex: 1; justify-content: center; gap: 0; font-size: 0; padding: 7px 0; }
.sb-footer-row .sb-action .sb-action-icon { font-size: 14px; }
.sb-user {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 6px 2px; margin-top: 4px; font-size: 12.5px; color: var(--text-light);
  border-top: 1px solid var(--border);
}
.sb-user-av {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 11px; color: #fff;
  background: linear-gradient(135deg, #6a63e8 0%, #4f52d4 55%, #3d3fb8 100%);
  text-transform: uppercase;
}
.sb-user-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   Main — the floating pane / topbar
   ============================================================ */
#main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg);
  border-radius: var(--radius-pane);
  box-shadow: var(--shadow-pane);
  overflow: hidden;
  position: relative;
}

#topbar {
  height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px;
}
#breadcrumbs { display: flex; align-items: center; gap: 2px; font-size: 13.5px; min-width: 0; overflow: hidden; }
.crumb {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 7px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 180px; cursor: pointer;
  color: var(--text-light);
}
.crumb:hover { background: var(--bg-hover); color: var(--text); }
.crumb:last-child { color: var(--text); font-weight: 500; }
.crumb-home { display: inline-flex; align-items: center; gap: 6px; color: var(--text-light); }
.crumb-sep { color: var(--text-faint); flex-shrink: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
#save-indicator { font-size: 12px; color: var(--text-faint); margin-right: 6px; }
#btn-fav.faved { color: var(--star); }
.topbar-btn {
  font-size: 13px; font-weight: 500; color: var(--text-light);
  padding: 5px 11px; border-radius: 7px;
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ============================================================
   Page
   ============================================================ */
#page-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }

#trash-banner {
  background: var(--bg-banner); color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 16px; position: sticky; top: 0; z-index: 5;
}
#trash-banner button {
  border: 1px solid rgba(255, 255, 255, 0.7); color: #fff;
  padding: 2px 10px; border-radius: 6px; font-size: 13px;
}
#trash-banner button:hover { background: rgba(255, 255, 255, 0.15); }

#page-cover {
  height: 200px; width: 100%; display: none; position: relative;
}
#page-cover.has-cover { display: block; }
.cover-actions {
  position: absolute; right: 24px; bottom: 12px; display: none; gap: 1px;
  background: var(--bg); border-radius: 7px; box-shadow: var(--shadow-card); overflow: hidden;
}
#page-cover:hover .cover-actions { display: flex; }
.cover-actions button { font-size: 12px; padding: 4px 8px; color: var(--text-light); }
.cover-actions button:hover { background: var(--bg-hover); }

#page-body { max-width: var(--page-w); margin: 0 auto; padding: 0 48px 30vh; }

#page-head { padding-top: 56px; position: relative; }
#page-cover.has-cover ~ #page-body #page-head,
body .has-cover-layout #page-head { padding-top: 24px; }

#page-icon {
  font-size: 66px; line-height: 1; width: 78px; height: 78px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; cursor: pointer; user-select: none;
}
#page-icon:hover { background: var(--bg-hover); }
#page-icon.overlaps { margin-top: -56px; }

#page-head-actions { display: flex; gap: 4px; height: 28px; margin: 4px 0; opacity: 0; transition: opacity 0.15s; }
#page-head:hover #page-head-actions { opacity: 1; }
#page-head-actions button {
  font-size: 13px; color: var(--text-faint); padding: 4px 8px; border-radius: 7px;
}
#page-head-actions button:hover { background: var(--bg-hover); }

#page-title {
  font-family: var(--font-display);
  font-size: 40px; font-weight: 700; line-height: 1.18; outline: none;
  word-break: break-word; padding: 3px 2px; letter-spacing: -0.8px;
}
#page-title:empty::before { content: attr(data-placeholder); color: var(--text-placeholder); }

/* user font prefs extend to display type (chrome stays branded, content follows) */
html.pref-serif { --font-display: Georgia, "Iowan Old Style", "Times New Roman", Times, serif; }
html.pref-mono { --font-display: var(--font-mono); }
#page-body.page-font-serif { --font-display: Georgia, "Iowan Old Style", "Times New Roman", Times, serif; }
#page-body.page-font-mono { --font-display: var(--font-mono); }

/* ============================================================
   Editor blocks
   ============================================================ */
#editor { padding: 8px 0 0; min-height: 120px; cursor: text; }

.block { position: relative; display: flex; align-items: flex-start; padding: 3px 2px; border-radius: 6px; }
.block.dragging { opacity: 0.4; }
.block-gutter {
  position: absolute; left: -46px; top: 3px; height: 24px;
  display: flex; align-items: center; gap: 0;
  opacity: 0; transition: opacity 0.12s;
}
.block:hover .block-gutter { opacity: 1; }
.bg-add, .bg-drag {
  width: 22px; height: 24px; border-radius: 6px; color: var(--text-faint);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.bg-add:hover, .bg-drag:hover { background: var(--bg-hover); color: var(--text-light); }
.bg-drag { cursor: grab; font-size: 12px; letter-spacing: -1px; width: 18px; }

.block-content {
  flex: 1; min-width: 0; outline: none; line-height: 1.55; font-size: 16px;
  word-break: break-word; white-space: pre-wrap; padding: 1px 0;
  caret-color: var(--text);
}
.block-content:empty::before { content: attr(data-placeholder); color: var(--text-placeholder); pointer-events: none; }
.block-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(91, 91, 214, 0.45); }
.block-content a.page-link {
  color: var(--text); text-decoration: none; font-weight: 500; cursor: pointer;
  border-bottom: 1.5px solid var(--border-strong); border-radius: 2px; padding: 0 1px;
  white-space: nowrap;
}
.block-content a.page-link:hover { background: var(--bg-hover); border-bottom-color: var(--accent-soft); }
.block-content a.page-link-missing { opacity: 0.55; border-bottom-style: dashed; }

/* @ mention atoms (people + dates) — inline, non-editable chips */
.block-content .mention {
  color: var(--accent); font-weight: 500; cursor: default; white-space: nowrap;
  border-radius: 3px; padding: 0 2px; -webkit-user-modify: read-only;
}
.block-content .mention-person { color: var(--accent); background: var(--accent-soft, rgba(91, 91, 214, 0.12)); }
.block-content .mention-date { color: var(--text-light); background: var(--bg-hover); }
.block-content .mention:hover { filter: brightness(0.97); }
.block-content .mention-unknown { color: var(--text-faint); }

/* backlinks — linked references + unlinked mentions */
#backlinks { margin: 2px 0 8px; }
.backlinks-head { font-size: 12.5px; color: var(--text-faint); padding: 2px 0 4px; }
.backlinks-head-unlinked { margin-top: 8px; }
.backlink-item {
  display: flex; align-items: baseline; gap: 8px; width: 100%; overflow: hidden;
  font-size: 13.5px; color: var(--text-light); padding: 3px 6px; border-radius: 6px; text-align: left;
}
.backlink-item:hover { background: var(--bg-hover); }
.backlink-src { font-weight: 500; color: var(--text); flex: none; white-space: nowrap; }
.backlink-snip {
  color: var(--text-faint); font-size: 12.5px; min-width: 0; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.backlink-snip mark { background: var(--hl, #fdeaa8); color: inherit; border-radius: 3px; padding: 0 1px; }
html[data-theme="dark"] .backlink-snip mark { background: #5a4a12; color: #f4e6b0; }
/* unlinked mention row: clickable snippet + a one-click "Link" affordance */
.backlink-unlinked { padding: 0; gap: 4px; }
.backlink-open {
  display: flex; align-items: baseline; gap: 8px; flex: 1; min-width: 0;
  font-size: 13.5px; color: var(--text-light); padding: 3px 6px; border-radius: 6px; text-align: left;
}
.backlink-open:hover { background: var(--bg-hover); }
.backlink-linkbtn {
  flex: none; font-size: 12px; font-weight: 500; color: var(--accent, #2b6cff);
  padding: 2px 9px; border-radius: 6px; align-self: center;
}
.backlink-linkbtn:hover { background: var(--bg-hover); }
.block-content code {
  font-family: var(--font-mono); font-size: 84%; color: #c74e6c;
  background: var(--bg-code); padding: 1px 5px; border-radius: 5px;
}
html[data-theme="dark"] .block-content code { color: #ef8fa9; }

/* headings — the display face carries the document's voice */
.b-h1 .block-content { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1.25; letter-spacing: -0.5px; }
.b-h1 { margin-top: 24px; }
.b-h2 .block-content { font-family: var(--font-display); font-size: 24px; font-weight: 600; line-height: 1.3; letter-spacing: -0.3px; }
.b-h2 { margin-top: 18px; }
.b-h3 .block-content { font-family: var(--font-display); font-size: 19px; font-weight: 600; line-height: 1.3; }
.b-h3 { margin-top: 12px; }

/* lists */
.b-bullet::before {
  content: "●"; font-size: 8px; line-height: 26px; width: 24px; text-align: center;
  flex-shrink: 0; color: var(--accent);
}
.num-label {
  width: 24px; flex-shrink: 0; text-align: left; padding-left: 4px;
  font-size: 15px; line-height: 25px; color: var(--accent); font-weight: 500; user-select: none;
  font-family: var(--font-display);
}

/* todo */
.todo-box { width: 24px; flex-shrink: 0; display: flex; align-items: center; height: 24px; }
.todo-box input {
  width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0 4px 0 0;
}
.b-todo.checked .block-content { color: var(--text-faint); text-decoration: line-through; }

/* quote */
.b-quote { border-left: 3px solid var(--accent); padding-left: 14px; margin: 4px 0; }
.b-quote .block-content { font-size: 16px; color: var(--text-light); }

/* callout */
.b-callout {
  background: var(--bg-callout); border-radius: var(--radius-card); padding: 14px 14px 14px 12px; margin: 4px 0;
  border: 1px solid var(--border);
}
.callout-icon { width: 28px; flex-shrink: 0; font-size: 17px; line-height: 24px; user-select: none; }

/* code */
.b-code {
  background: var(--bg-code); border-radius: var(--radius-card); padding: 26px 16px 16px; margin: 4px 0;
  border: 1px solid var(--border);
}
.b-code .block-content {
  font-family: var(--font-mono); font-size: 13px; line-height: 1.6; color: var(--text);
}
.code-lang {
  position: absolute; top: 5px; left: 14px;
  font-size: 11px; color: var(--text-faint); font-family: var(--font-mono);
  padding: 1px 6px; border-radius: 5px;
}
.code-lang:hover { background: var(--bg-hover); color: var(--text-light); }
.lang-menu { max-height: 300px; }

/* code block toolbar: language chip + line-wrap toggle + copy */
.code-bar {
  position: absolute; top: 5px; left: 14px; right: 14px;
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
}
.code-bar .code-lang { position: static; top: auto; left: auto; }
.code-copy, .code-wrap-btn {
  font-size: 11px; color: var(--text-faint); font-family: var(--font-mono);
  background: none; border: none; cursor: pointer; padding: 1px 6px; border-radius: 5px;
  opacity: 0; transition: opacity .12s, background .12s, color .12s;
}
.code-wrap-btn { margin-left: auto; }
.b-code:hover .code-copy, .b-code:hover .code-wrap-btn,
.code-copy.done, .code-wrap-btn.on { opacity: 1; }
.code-copy:hover, .code-wrap-btn:hover { background: var(--bg-hover); color: var(--text-light); }
.code-copy.done { color: var(--accent, #5b5bd6); }
.code-wrap-btn.on { color: var(--accent, #5b5bd6); }
.b-code.code-nowrap .block-content { white-space: pre; overflow-x: auto; }

/* syntax highlighting (highlight.js token classes) */
.hljs-comment, .hljs-quote { color: #6a737d; font-style: italic; }
.hljs-keyword, .hljs-doctag, .hljs-template-tag, .hljs-deletion { color: #c2429b; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: #268659; }
.hljs-number, .hljs-literal, .hljs-built_in, .hljs-type, .hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta { color: #3b5bd0; }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-section { color: #6f42c1; }
.hljs-variable, .hljs-template-variable, .hljs-attr, .hljs-attribute, .hljs-property, .hljs-params { color: #c25e12; }
.hljs-name, .hljs-tag, .hljs-selector-tag, .hljs-selector-id, .hljs-selector-class { color: #268659; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

html[data-theme="dark"] .hljs-comment, html[data-theme="dark"] .hljs-quote { color: #8b90ab; }
html[data-theme="dark"] .hljs-keyword, html[data-theme="dark"] .hljs-doctag, html[data-theme="dark"] .hljs-template-tag, html[data-theme="dark"] .hljs-deletion { color: #f57ec0; }
html[data-theme="dark"] .hljs-string, html[data-theme="dark"] .hljs-regexp, html[data-theme="dark"] .hljs-addition { color: #9ce0b9; }
html[data-theme="dark"] .hljs-number, html[data-theme="dark"] .hljs-literal, html[data-theme="dark"] .hljs-built_in, html[data-theme="dark"] .hljs-type, html[data-theme="dark"] .hljs-symbol, html[data-theme="dark"] .hljs-bullet, html[data-theme="dark"] .hljs-link, html[data-theme="dark"] .hljs-meta { color: #92aaff; }
html[data-theme="dark"] .hljs-title, html[data-theme="dark"] .hljs-title.function_, html[data-theme="dark"] .hljs-title.class_, html[data-theme="dark"] .hljs-section { color: #cbaaff; }
html[data-theme="dark"] .hljs-variable, html[data-theme="dark"] .hljs-template-variable, html[data-theme="dark"] .hljs-attr, html[data-theme="dark"] .hljs-attribute, html[data-theme="dark"] .hljs-property, html[data-theme="dark"] .hljs-params { color: #ffb079; }
html[data-theme="dark"] .hljs-name, html[data-theme="dark"] .hljs-tag, html[data-theme="dark"] .hljs-selector-tag, html[data-theme="dark"] .hljs-selector-id, html[data-theme="dark"] .hljs-selector-class { color: #8ee7a8; }

/* divider */
.b-divider { padding: 8px 2px; cursor: default; outline: none; }
.divider-line { flex: 1; height: 1px; background: var(--border-strong); pointer-events: none; }
.b-divider.selected { background: rgba(91, 91, 214, 0.15); }

/* table of contents */
.b-toc { margin: 2px 0; }
.toc-wrap { flex: 1; min-width: 0; padding: 2px 0; }
.toc-empty { color: var(--text-faint); font-size: 14px; font-style: italic; padding: 3px 4px; }
.toc-item {
  display: block; padding: 3px 6px; border-radius: 6px; cursor: pointer;
  font-size: 14px; color: var(--text-light); line-height: 1.45;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: underline; }
.toc-l1 { padding-left: 6px; color: var(--text); font-weight: 500; }
.toc-l2 { padding-left: 24px; }
.toc-l3 { padding-left: 42px; }
.toc-flash { background: rgba(91, 91, 214, 0.14); border-radius: 6px; }

/* tables */
.b-table { margin: 4px 0; }
.table-wrap { flex: 1; min-width: 0; }
.table-scroll { display: flex; align-items: flex-start; overflow-x: auto; padding: 2px 0; }
.table-frame { position: relative; width: fit-content; max-width: 100%; }
.ntable { border-collapse: collapse; table-layout: auto; }
.ntable.t-fixed { table-layout: fixed; }
.t-cell {
  border: 1px solid var(--border); padding: 6px 9px; vertical-align: top;
  font-size: 15px; line-height: 1.5; color: var(--text); outline: none;
  min-width: 90px; max-width: 420px; word-break: break-word; white-space: pre-wrap;
  caret-color: var(--text); cursor: text;
}
/* once a table is resized (fixed layout) the colgroup owns the widths */
.ntable.t-fixed .t-cell { min-width: 0; max-width: none; }

/* column resize handle: thin drag zone straddling each column's right border */
.t-col-grip { position: relative; }
.t-col-resize {
  position: absolute; top: 0; right: -3px; width: 7px; height: 22px;
  cursor: col-resize; user-select: none; z-index: 3;
}
.t-col-resize::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px;
  background: transparent; border-radius: 2px; transition: background 0.1s;
}
.b-table:hover .t-col-resize:hover::after,
.t-col-resize.dragging::after { background: var(--accent); }
body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-select: none !important; }
.t-cell.t-head { font-weight: 600; background: var(--bg-code); font-family: var(--font-display); font-size: 14px; }
.t-cell:focus { box-shadow: inset 0 0 0 2px var(--accent); }

/* row / column grips (reveal on table hover) */
.t-ctrl-row td, .t-row-grip { border: none; padding: 0; }
.t-corner { width: 16px; }
.t-col-grip, .t-row-grip {
  color: transparent; cursor: pointer; text-align: center; user-select: none;
  font-size: 12px; line-height: 1; border-radius: 4px;
}
.t-col-grip { height: 15px; }
.t-row-grip { width: 16px; vertical-align: middle; }
.b-table:hover .t-col-grip, .b-table:hover .t-row-grip { color: var(--text-faint); }
.t-col-grip:hover, .t-row-grip:hover { background: var(--bg-active); color: var(--text-light) !important; }

/* add row / column buttons */
.t-add-col, .t-add-row {
  opacity: 0; transition: opacity 0.12s, background 0.12s;
  color: var(--text-faint); font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center; border-radius: 5px;
}
.t-add-col { align-self: stretch; width: 16px; margin-left: 4px; }
.t-add-row { width: 100%; height: 16px; margin-top: 4px; }
.b-table:hover .t-add-col, .b-table:hover .t-add-row { opacity: 1; }
.t-add-col:hover, .t-add-row:hover { background: var(--bg-hover); color: var(--text-light); }

/* columns */
.b-columns { margin: 2px 0; }
.cols-wrap { flex: 1; min-width: 0; display: flex; align-items: stretch; gap: 4px; }
.col-box { position: relative; flex: 1 1 0; min-width: 0; }
.col-box + .col-box { border-left: 1px solid var(--border); padding-left: 14px; }
/* a column is now a container of rich blocks */
.col-cell { display: flex; flex-direction: column; gap: 2px; min-height: 1.6em; }
.col-blk { position: relative; }
.col-tx {
  outline: none; min-height: 1.5em; padding: 2px 4px; border-radius: 6px; flex: 1; min-width: 0;
  font-size: 16px; line-height: 1.5; color: var(--text); word-break: break-word; white-space: pre-wrap;
  caret-color: var(--text);
}
.col-tx:empty::before { content: attr(data-placeholder); color: var(--text-placeholder); pointer-events: none; }
/* headings */
.cb-h2 .col-tx { font-size: 21px; font-weight: 650; line-height: 1.3; padding-top: 4px; }
.cb-h3 .col-tx { font-size: 17px; font-weight: 600; line-height: 1.3; padding-top: 3px; }
/* list-ish blocks: prefix + text on one row */
.cb-todo, .cb-bullet, .cb-callout { display: flex; align-items: flex-start; gap: 6px; }
.col-dot { flex: 0 0 auto; padding: 2px 0 0 4px; color: var(--text-light); user-select: none; }
.col-check {
  flex: 0 0 auto; margin: 5px 0 0 4px; width: 16px; height: 16px; border-radius: 4px; cursor: pointer;
  border: 1.5px solid var(--border-strong); background: var(--bg); position: relative;
}
.col-check.checked { background: var(--accent); border-color: var(--accent); }
.col-check.checked::after { content: "✓"; position: absolute; inset: 0; color: #fff; font-size: 11px; line-height: 13px; text-align: center; }
.cb-todo-done .col-tx { color: var(--text-faint); text-decoration: line-through; }
.cb-callout { background: var(--bg-code); border-radius: 6px; padding: 6px 8px; }
.col-callout-ic { flex: 0 0 auto; }
.col-hr { border-top: 1px solid var(--border-strong); margin: 8px 2px; }
/* per-column image */
.col-img-fig { position: relative; margin: 2px 0; max-width: 100%; border-radius: 6px; }
.col-img-fig img { display: block; max-width: 100%; height: auto; border-radius: 6px; background: var(--bg-code); }
.col-img-bar { position: absolute; top: 6px; right: 6px; display: none; gap: 4px; background: var(--bg); padding: 3px; border-radius: 6px; box-shadow: var(--shadow-card); }
.col-img-fig:hover .col-img-bar { display: flex; }
.col-img-zone {
  width: 100%; text-align: left; padding: 12px 14px; font-size: 13px; color: var(--text-light);
  background: var(--bg-code); border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.col-img-zone:hover { background: var(--bg-hover); color: var(--text); }
/* add-a-block affordance at the foot of each column */
.col-add-blk {
  margin-top: 2px; padding: 3px 6px; font-size: 12px; text-align: left; border-radius: 5px;
  color: var(--text-faint); background: none; opacity: 0; transition: opacity 0.12s; cursor: pointer;
}
.col-box:hover .col-add-blk { opacity: 1; }
.col-add-blk:hover { background: var(--bg-hover); color: var(--text-light); }
.col-blk-menu { min-width: 190px; }
.col-del {
  position: absolute; top: -2px; right: 2px; z-index: 2;
  width: 18px; height: 18px; border-radius: 5px; font-size: 14px; line-height: 1;
  color: var(--text-faint); background: var(--bg); opacity: 0; transition: opacity 0.12s;
  display: flex; align-items: center; justify-content: center;
}
.b-columns:hover .col-del { opacity: 1; }
.col-del:hover { background: var(--bg-active); color: var(--text); }
.col-add {
  flex: 0 0 16px; align-self: stretch; border-radius: 5px; opacity: 0; transition: opacity 0.12s;
  color: var(--text-faint); font-size: 15px; display: flex; align-items: center; justify-content: center;
}
.b-columns:hover .col-add { opacity: 1; }
.col-add:hover { background: var(--bg-hover); color: var(--text-light); }

/* indent */
.block[data-indent="1"] { margin-left: 28px; }
.block[data-indent="2"] { margin-left: 56px; }
.block[data-indent="3"] { margin-left: 84px; }
.block[data-indent="4"] { margin-left: 112px; }
.block[data-indent="5"] { margin-left: 140px; }
.block[data-indent="6"] { margin-left: 168px; }

/* multi-block selection */
.block.sel-block { background: rgba(91, 91, 214, 0.13); }
html[data-theme="dark"] .block.sel-block { background: rgba(120, 124, 255, 0.24); }

/* drop indicator */
#drop-indicator {
  position: absolute; height: 3px; background: rgba(91, 91, 214, 0.5);
  border-radius: 2px; pointer-events: none; z-index: 10; display: none;
}

/* ============================================================
   Popovers & menus
   ============================================================ */
#popover-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
/* Only the actual popover/toolbar boxes capture events — never the full-screen
   layer itself. A hidden (display:none) child captures nothing, so a cached-but-
   hidden toolbar can't block clicks/scroll across the page. */
#popover-layer > * { pointer-events: auto; }
.popover {
  position: absolute; background: var(--bg-modal); border-radius: 12px;
  box-shadow: var(--shadow-popover); overflow: hidden auto;
  min-width: 220px; max-height: 380px; animation: pop-in 0.12s ease;
  padding: 4px;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-3px); } }

.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 10px; font-size: 13.5px; text-align: left; color: var(--text);
  border-radius: 7px;
}
.menu-item:hover, .menu-item.selected { background: var(--bg-hover); }
.menu-item.danger { color: var(--danger); }
.menu-icon {
  width: 24px; height: 24px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 15px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg);
}
.menu-label { flex: 1; min-width: 0; }
.menu-title { font-size: 13.5px; }
.menu-desc { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.menu-section {
  font-family: var(--font-display);
  font-size: 10.5px; font-weight: 600; color: var(--text-faint);
  padding: 8px 10px 3px; text-transform: uppercase; letter-spacing: 0.7px;
}
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu-empty { padding: 12px; font-size: 13px; color: var(--text-faint); }

/* emoji picker */
.emoji-grid {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; padding: 8px;
  width: 306px;
}
.emoji-grid button {
  font-size: 19px; padding: 4px; border-radius: 6px; line-height: 1.2;
}
.emoji-grid button:hover { background: var(--bg-hover); }
.picker-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 0; font-size: 12px; color: var(--text-faint);
}
.picker-head button { color: var(--text-faint); font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.picker-head button:hover { background: var(--bg-hover); color: var(--text); }

/* cover picker */
.cover-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; width: 320px; }
.cover-grid button { height: 44px; border-radius: 7px; border: 1px solid var(--border); }
.cover-grid button:hover { box-shadow: 0 0 0 2px var(--accent); }

/* ============================================================
   Modals (search, trash)
   ============================================================ */
#modal-layer {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 11, 26, 0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding-top: 90px;
}
.modal {
  background: var(--bg-modal); border-radius: 16px; box-shadow: var(--shadow-popover);
  width: 560px; max-width: calc(100vw - 40px); max-height: 65vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: modal-in 0.16s cubic-bezier(0.2, 0.85, 0.3, 1);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
.modal-search-input {
  width: 100%; padding: 15px 18px; font-size: 16px; font-family: var(--font);
  border: none; outline: none; background: transparent; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.modal-results { overflow-y: auto; padding: 6px; }
.result-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; color: var(--text);
}
.result-item:hover, .result-item.selected { background: var(--bg-hover); }
.result-icon { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }
.result-main { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 1px; }
.result-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-path { margin-left: auto; font-size: 12px; color: var(--text-faint); white-space: nowrap; padding-left: 12px; align-self: center; }
.result-snippet { font-size: 12px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-snippet mark, .lib-snippet mark {
  background: rgba(91, 91, 214, 0.18); color: inherit; border-radius: 3px; padding: 0 1px;
}

/* library search snippets */
.lib-name-main { display: flex; flex-direction: column; min-width: 0; flex: 1; justify-content: center; gap: 1px; }
.lib-name-main .lib-p-title { flex: 0 0 auto; }
.lib-snippet { font-size: 12.5px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-row.has-snippet { height: auto; min-height: 50px; padding-top: 6px; padding-bottom: 6px; }

/* templates gallery */
.templates-modal { width: 720px; max-height: 78vh; }
.tpl-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 20px 22px 16px; border-bottom: 1px solid var(--border);
}
.tpl-title { font-family: var(--font-display); font-size: 19px; font-weight: 700; color: var(--text); }
.tpl-sub { font-size: 13.5px; color: var(--text-light); margin-top: 2px; }
.tpl-close { align-self: flex-start; }
.tpl-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  padding: 18px 22px 24px; overflow-y: auto;
}
.tpl-card {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 3px;
  padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.08s;
}
.tpl-card:hover { border-color: var(--accent-soft); box-shadow: 0 4px 16px rgba(20, 22, 43, 0.08), 0 0 0 1px var(--accent-soft); }
.tpl-card:active { transform: scale(0.985); }
.tpl-card-icon {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; background: var(--bg-callout);
  margin-bottom: 8px; color: var(--text-light);
}
.tpl-emoji { font-size: 22px; line-height: 1; }
.tpl-card-name { font-family: var(--font-display); font-size: 14.5px; font-weight: 600; color: var(--text); }
.tpl-card-desc { font-size: 12.5px; color: var(--text-light); line-height: 1.4; }
.tpl-card-preview { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; }
.tpl-card-preview:empty { display: none; }

@media (max-width: 680px) {
  .templates-modal { width: calc(100vw - 24px); }
  .tpl-grid { grid-template-columns: repeat(2, 1fr); }
}

/* settings / profile — two-pane tabbed dialog */
.settings-modal {
  width: 780px; max-width: calc(100vw - 32px);
  height: 620px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.settings-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px 16px; border-bottom: 1px solid var(--border);
}
.settings-title { font-family: var(--font-display); font-size: 19px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; }
.settings-shell { flex: 1 1 auto; min-height: 0; display: flex; }
.settings-nav {
  flex: 0 0 196px;
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 12px; overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-callout);
}
.settings-nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 9px 12px; text-align: left;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font-family: var(--font); font-size: 14px; color: var(--text-light);
  transition: background .12s ease, color .12s ease;
}
.settings-nav-item .ic { flex: 0 0 auto; opacity: 0.85; }
.settings-nav-item:hover { background: var(--bg-hover); color: var(--text); }
.settings-nav-item.active { background: rgba(91, 91, 214, 0.1); color: var(--accent); font-weight: 600; }
.settings-nav-item.active .ic { opacity: 1; }
html[data-theme="dark"] .settings-nav-item.active { background: rgba(120, 124, 255, 0.16); color: var(--accent-soft); }
.settings-content { flex: 1 1 auto; min-width: 0; overflow-y: auto; padding: 22px 28px 28px; }
.settings-pane { animation: settings-pane-in 0.16s ease both; }
.settings-pane[hidden] { display: none; }
.settings-pane > .settings-section-label:first-child { margin-top: 0; }
@keyframes settings-pane-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.settings-help { font-size: 12.5px; color: var(--text-faint); margin: 9px 2px 0; line-height: 1.55; }
.settings-body { padding: 18px 22px 6px; overflow-y: auto; }
.settings-profile { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.settings-avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 52px;
  background: linear-gradient(135deg, #6a63e8, #4649c0);
  color: #fff; font-size: 22px; font-weight: 600; font-family: var(--font-display);
  display: flex; align-items: center; justify-content: center;
}
.settings-id { min-width: 0; }
.settings-name-line { font-size: 15px; font-weight: 600; color: var(--text); }
.settings-email { font-size: 13px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-section-label {
  font-family: var(--font-display);
  font-size: 11px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.7px; margin: 18px 0 7px;
}
.settings-input {
  width: 100%; padding: 9px 11px; font-size: 14px; font-family: var(--font);
  border: 1px solid var(--border-strong); border-radius: var(--radius-ctl);
  background: var(--bg-input); color: var(--text); outline: none;
}
.settings-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 91, 214, 0.16); }
.settings-seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; }
.settings-seg button {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 15px;
  font-size: 13px; font-family: var(--font); color: var(--text-light);
  background: var(--bg); border: none; cursor: pointer;
}
.settings-seg button + button { border-left: 1px solid var(--border-strong); }
.settings-seg button.active { background: rgba(91, 91, 214, 0.1); color: var(--accent); font-weight: 600; }
html[data-theme="dark"] .settings-seg button.active { background: rgba(120, 124, 255, 0.18); color: var(--accent-soft); }
.settings-stats { display: flex; gap: 12px; }
.settings-stat { flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--bg-callout); }
.settings-stat-n { font-family: var(--font-display); font-size: 20px; font-weight: 700; color: var(--text); }
.settings-stat-l { font-size: 12.5px; color: var(--text-light); margin-top: 2px; }
.settings-foot { padding: 14px 22px; border-top: 1px solid var(--border); }
.settings-logout {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px;
  font-size: 13.5px; font-family: var(--font); color: var(--danger);
  background: transparent; border: 1px solid var(--border-strong); border-radius: var(--radius-ctl); cursor: pointer;
}
.settings-logout:hover { background: rgba(229, 83, 75, 0.08); border-color: var(--danger); }

@media (max-width: 720px) {
  .settings-modal { width: calc(100vw - 20px); height: 90vh; }
  .settings-shell { flex-direction: column; }
  .settings-nav {
    flex: 0 0 auto; flex-direction: row; gap: 4px;
    overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--border);
    padding: 8px 10px;
  }
  .settings-nav-item { width: auto; white-space: nowrap; padding: 8px 12px; }
  .settings-content { padding: 18px 18px 24px; }
}

/* markdown import */
.import-modal { width: 600px; }
.import-body { padding: 16px 22px 6px; display: flex; flex-direction: column; gap: 12px; }
.import-row { display: flex; gap: 10px; align-items: center; }
.import-row .settings-input { flex: 1; }
.import-file-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 13px; white-space: nowrap;
  font-size: 13.5px; color: var(--text-light); background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: var(--radius-ctl); cursor: pointer;
}
.import-file-btn:hover { background: var(--bg-hover); color: var(--text); }
.import-textarea {
  width: 100%; min-height: 240px; resize: vertical; padding: 12px 14px;
  font-family: var(--font-mono, ui-monospace, monospace); font-size: 13px; line-height: 1.5;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg-code); color: var(--text); outline: none;
}
.import-textarea:focus { border-color: var(--accent); }
.import-foot { display: flex; justify-content: flex-end; }
.import-create {
  padding: 8px 18px; font-size: 14px; font-weight: 600; font-family: var(--font);
  color: #fff; background: var(--accent); border: none; border-radius: var(--radius-ctl); cursor: pointer;
  box-shadow: 0 3px 10px rgba(91, 91, 214, 0.3);
}
.import-create:hover { background: var(--accent-hover); }

@media (max-width: 620px) {
  .import-modal { width: calc(100vw - 24px); }
  .import-row { flex-direction: column; align-items: stretch; }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-family: var(--font-display); font-size: 15px; font-weight: 600;
}
.modal-head button { font-size: 13px; color: var(--danger); padding: 4px 8px; border-radius: 6px; font-weight: 500; font-family: var(--font); }
.modal-head button:hover { background: rgba(229, 83, 75, 0.1); }
.trash-actions { display: flex; gap: 2px; margin-left: auto; }

/* keyboard shortcut sheet */
.shortcuts-modal { width: 680px; max-height: 78vh; }
.sc-body { overflow-y: auto; padding: 4px 14px 16px; }
.sc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 28px; padding: 0 4px; }
.sc-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 5px 6px; border-radius: 6px; font-size: 13.5px; color: var(--text);
}
.sc-row:hover { background: var(--bg-hover); }
.sc-keys { display: flex; gap: 4px; flex-shrink: 0; }
.sc-keys kbd {
  font-family: var(--font); font-size: 11.5px; font-weight: 500; color: var(--text-light);
  background: var(--bg-code); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; min-width: 20px; text-align: center;
}
@media (max-width: 640px) { .sc-grid { grid-template-columns: 1fr; } }

/* ============================================================
   Empty state / toast
   ============================================================ */
#empty-state { height: 100%; display: flex; align-items: center; justify-content: center; }
.empty-inner { text-align: center; color: var(--text-light); }
.empty-logo {
  width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 16px; opacity: 0.5;
  font-size: 32px;
}
.empty-inner p { margin-bottom: 16px; font-size: 15px; }
.empty-inner .login-btn { width: auto; padding: 8px 16px; margin: 0 auto; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #22264a; color: #eef0fb; font-size: 13.5px; font-weight: 500;
  padding: 10px 18px; border-radius: 12px; z-index: 300; transition: transform 0.25s ease;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 10px 30px rgba(4, 5, 16, 0.5);
  display: flex; align-items: center; gap: 14px;
}
#toast.show { transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-action {
  color: var(--accent-soft); font-weight: 600; font-size: 13.5px;
  padding: 2px 6px; margin: -2px -6px; border-radius: 6px; flex-shrink: 0;
}
.toast-action:hover { background: rgba(143, 143, 243, 0.16); }

/* ============================================================
   Library (all-pages home view)
   ============================================================ */
#library-view { max-width: 1080px; margin: 0 auto; padding: 40px 56px 80px; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.lib-title { font-family: var(--font-display); font-size: 32px; font-weight: 700; letter-spacing: -0.6px; color: var(--text); }
.lib-newpage {
  background: var(--accent); color: #fff; font-size: 13.5px; font-weight: 600;
  padding: 9px 17px; border-radius: 9px; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(91, 91, 214, 0.3);
  transition: background 0.12s, box-shadow 0.12s;
}
.lib-newpage:hover { background: var(--accent-hover); box-shadow: 0 4px 14px rgba(91, 91, 214, 0.4); }

.lib-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.lib-tabs { display: flex; gap: 2px; }
.lib-tab {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px 10px;
  font-size: 13.5px; font-weight: 500; color: var(--text-light);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.lib-tab:hover { color: var(--text); }
.lib-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
html[data-theme="dark"] .lib-tab.active { color: var(--accent-soft); border-bottom-color: var(--accent-soft); }
.lib-tab-ic { font-size: 14px; }
.lib-tools { display: flex; align-items: center; gap: 8px; padding-bottom: 4px; }
.lib-search-wrap { position: relative; display: flex; align-items: center; }
.lib-search-ic { position: absolute; left: 9px; color: var(--text-faint); pointer-events: none; }
.lib-search {
  background: var(--bg-code); border: 1px solid transparent; border-radius: 9px;
  padding: 7px 10px 7px 30px; font-size: 13.5px; font-family: var(--font); color: var(--text); width: 190px;
  transition: border-color 0.12s, width 0.12s, background 0.12s;
}
.lib-search:focus { border-color: var(--accent); background: var(--bg-input); width: 230px; outline: none; }
.lib-search::placeholder { color: var(--text-placeholder); }
.lib-sort { width: 32px; height: 32px; color: var(--text-light); border-radius: 8px; }
.lib-sort:hover { background: var(--bg-hover); color: var(--text); }
.lib-templates-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  font-size: 13px; font-weight: 500; color: var(--text-light); white-space: nowrap;
}
.lib-templates-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.lib-templates-btn span { display: inline-flex; }

.lib-table { margin-top: 2px; }
.lib-row {
  display: flex; align-items: center; gap: 12px;
  padding: 0 8px; height: 40px; border-bottom: 1px solid var(--border);
}
.lib-colhead { height: 34px; color: var(--text-faint); font-size: 12px; border-bottom-color: var(--border-strong); }
.lib-colhead .lib-c-name, .lib-colhead .lib-c-time {
  font-family: var(--font-display); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px;
}
.lib-c-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.lib-c-time { width: 200px; flex: 0 0 200px; color: var(--text-light); font-size: 13px; }

.lib-item { cursor: pointer; border-radius: 8px; }
.lib-item:hover { background: var(--bg-hover); }
.lib-item.lib-child { }
.lib-twist {
  width: 20px; height: 20px; flex: 0 0 20px; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 10px; border-radius: 5px; transition: transform 0.12s; opacity: 0;
}
.lib-item:hover .lib-twist { opacity: 1; }
.lib-twist.has-children { opacity: 0.7; }
.lib-twist.expanded { transform: rotate(90deg); }
.lib-twist.leaf { visibility: hidden; }
.lib-p-icon { font-size: 17px; width: 20px; text-align: center; flex: 0 0 20px; }
.lib-p-title { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-addnew {
  display: flex; align-items: center; gap: 6px; height: 36px; padding-left: 8px;
  color: var(--text-faint); font-size: 14px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.lib-addnew:hover { background: var(--bg-hover); color: var(--text-light); }
.lib-addnew .lib-addnew-plus { width: 20px; text-align: center; font-size: 15px; }
.lib-empty { padding: 40px 8px; text-align: center; color: var(--text-faint); font-size: 14px; }

@media (max-width: 720px) {
  #library-view { padding: 24px 18px 60px; }
  .lib-c-time { width: 110px; flex-basis: 110px; }
  .lib-search { width: 120px; }
}

/* ============================================================
   Toggle blocks
   ============================================================ */
.toggle-tri {
  width: 24px; height: 24px; flex-shrink: 0; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 11px; transition: transform 0.12s;
}
.toggle-tri:hover { background: var(--bg-hover); color: var(--text); }
.toggle-tri.expanded { transform: rotate(90deg); }

/* collapsible-heading fold chevron — floats in the left margin (no text shift),
   revealed on hover or kept visible while the section is collapsed */
.heading-tri { position: absolute; left: -68px; width: 22px; height: 24px; opacity: 0; }
.b-h1 > .heading-tri { top: 8px; }
.b-h2 > .heading-tri { top: 5px; }
.b-h3 > .heading-tri { top: 3px; }
.block:hover > .heading-tri, .block[data-collapsed="1"] > .heading-tri { opacity: 1; }
/* blocks moving together with a dragged parent */
.block.dragging-sub { opacity: 0.4; }

/* ============================================================
   Text & highlight colors
   ============================================================ */
.fg-gray { color: #767b93; }
.fg-brown { color: #97695a; }
.fg-orange { color: #c56f2c; }
.fg-yellow { color: #b98e34; }
.fg-green { color: #4d8464; }
.fg-blue { color: #4874c9; }
.fg-purple { color: #8a63cf; }
.fg-pink { color: #b8538e; }
.fg-red { color: #ca5049; }
.bg-gray { background: #eceef3; }
.bg-brown { background: #ece5e1; }
.bg-orange { background: #fbecdd; }
.bg-yellow { background: #fbf3da; }
.bg-green { background: #ddefe1; }
.bg-blue { background: #e0e9f8; }
.bg-purple { background: #efeafc; }
.bg-pink { background: #f9e3f0; }
.bg-red { background: #fbe4e2; }
.block-content span[class*="bg-"] { border-radius: 4px; padding: 1px 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

html[data-theme="dark"] .fg-gray { color: #979cb5; }
html[data-theme="dark"] .fg-brown { color: #bc8672; }
html[data-theme="dark"] .fg-orange { color: #d48a54; }
html[data-theme="dark"] .fg-yellow { color: #cda04c; }
html[data-theme="dark"] .fg-green { color: #6fa886; }
html[data-theme="dark"] .fg-blue { color: #7d9de4; }
html[data-theme="dark"] .fg-purple { color: #ab8ce4; }
html[data-theme="dark"] .fg-pink { color: #da84b6; }
html[data-theme="dark"] .fg-red { color: #e17870; }
html[data-theme="dark"] .bg-gray { background: #2b2f4a; }
html[data-theme="dark"] .bg-brown { background: #443028; }
html[data-theme="dark"] .bg-orange { background: #533a24; }
html[data-theme="dark"] .bg-yellow { background: #4e4227; }
html[data-theme="dark"] .bg-green { background: #21402f; }
html[data-theme="dark"] .bg-blue { background: #1f2f56; }
html[data-theme="dark"] .bg-purple { background: #382b55; }
html[data-theme="dark"] .bg-pink { background: #4c2a41; }
html[data-theme="dark"] .bg-red { background: #4f2c29; }

/* ============================================================
   Formatting toolbar (text selection)
   ============================================================ */
.fmt-toolbar {
  position: fixed; z-index: 150; display: none; align-items: center; gap: 1px;
  background: #22264a; border-radius: 12px; padding: 4px;
  box-shadow: rgba(4, 5, 16, 0.4) 0 6px 18px, rgba(255, 255, 255, 0.08) 0 0 0 1px;
}

/* hovering an external link shows this "open" hint */
.link-hint {
  position: fixed; z-index: 150; display: none; align-items: center; gap: 4px;
  max-width: min(90vw, 460px); padding: 4px 4px 4px 11px; border-radius: 10px;
  background: #22264a; color: #d7daed; font-size: 12.5px; line-height: 1.3; cursor: pointer;
  box-shadow: rgba(4, 5, 16, 0.4) 0 6px 18px, rgba(255, 255, 255, 0.08) 0 0 0 1px;
}
html[data-theme="dark"] .link-hint { background: #262a4e; box-shadow: rgba(0,0,0,0.5) 0 6px 18px, rgba(255, 255, 255, 0.1) 0 0 0 1px; }
.link-hint-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.9; max-width: 320px; }
.link-hint-open {
  flex: none; display: inline-flex; align-items: center; gap: 3px; cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 7px;
  background: var(--accent); color: #fff; border: none;
}
.link-hint-open:hover { filter: brightness(1.08); }
.link-hint-open .lh-ext { font-size: 12px; line-height: 1; }

/* add / edit link dialog */
.link-modal-back {
  position: fixed; inset: 0; z-index: 250; pointer-events: auto;
  background: rgba(10, 11, 26, 0.55); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding-top: 18vh;
}
.link-modal {
  background: var(--bg-modal); border-radius: 16px; box-shadow: var(--shadow-popover);
  width: 460px; max-width: calc(100vw - 40px); padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
  animation: modal-in 0.16s cubic-bezier(0.2, 0.85, 0.3, 1);
}
.link-modal.lm-shake { animation: lm-shake 0.28s; }
@keyframes lm-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.lm-title { font-size: 16px; font-weight: 600; font-family: var(--font-display); color: var(--text); }
.lm-text {
  font-size: 12.5px; color: var(--text-light);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lm-text b { color: var(--text); font-weight: 600; }
.lm-input {
  width: 100%; padding: 10px 12px; font-size: 14.5px; font-family: var(--font);
  color: var(--text); background: var(--bg-input, var(--bg-code)); outline: none;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-ctl);
}
.lm-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(51, 126, 169, 0.18); }
.lm-err { min-height: 15px; font-size: 12px; color: var(--danger); }
.lm-actions { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.lm-spacer { flex: 1; }
.lm-actions button {
  padding: 7px 14px; border-radius: var(--radius-ctl); font-size: 13.5px; font-weight: 500;
  font-family: var(--font); cursor: pointer; border: 1px solid transparent;
}
.lm-cancel { background: transparent; border-color: var(--border-strong); color: var(--text-light); }
.lm-cancel:hover { background: var(--bg-hover); color: var(--text); }
.lm-add { background: var(--accent); color: #fff; }
.lm-add:hover { filter: brightness(1.06); }
.lm-remove { background: transparent; color: var(--danger); border-color: transparent; margin-right: auto; }
.lm-remove:hover { background: rgba(229, 83, 75, 0.1); }
html[data-theme="dark"] .fmt-toolbar { background: #262a4e; box-shadow: rgba(0,0,0,0.5) 0 6px 18px, rgba(255, 255, 255, 0.1) 0 0 0 1px; }
.fmt-btn {
  min-width: 28px; height: 28px; padding: 0 7px; border-radius: 8px;
  color: #d7daed; font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.fmt-btn:hover { background: rgba(255, 255, 255, 0.12); }
.fmt-btn.mono { font-family: var(--font-mono); font-size: 12px; }
.fmt-btn i { font-style: italic; }
.fmt-a { text-decoration: underline; text-underline-offset: 2px; }
.fmt-hl { background: #efaf3d; color: #22264a; border-radius: 4px; padding: 0 4px; font-weight: 600; }
.fmt-sep { width: 1px; height: 18px; background: rgba(255, 255, 255, 0.15); margin: 0 3px; }
.fmt-link-input {
  border: none; outline: none; background: transparent; color: #fff;
  font-family: var(--font); font-size: 14px; padding: 4px 8px; width: 240px;
}
.fmt-link-input::placeholder { color: rgba(255, 255, 255, 0.45); }
.fmt-toolbar.link-mode { padding: 4px 6px; }

.color-pop { min-width: 190px; }
.col-chip {
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; border: 1px solid var(--border);
}

/* ============================================================
   View entrance — a quiet rise as panes swap
   ============================================================ */
#page-view, #library-view, #database-view, #trash-view, #tasks-view,
#inbox-view, #daily-view, #graph-view, #empty-state {
  animation: view-in 0.18s ease both;
}
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

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

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 800px) {
  #app { padding: 0; }
  #main { border-radius: 0; box-shadow: none; }
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    background: var(--frame);
    padding-right: 0;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 12px 0 40px rgba(4, 5, 16, 0.5);
  }
  body.sidebar-collapsed #sidebar { margin-left: 0; transform: translateX(-100%); box-shadow: none; }
  #page-body { padding: 0 24px 30vh; }
  .block-gutter { left: -24px; }
  .bg-add { display: none; }
}
