/* ========================================
   Nexus — Collaborative Knowledge Base
   ======================================== */

:root {
  /* Surfaces */
  --bg:             #191919;
  --bg-sidebar:     #202020;
  --bg-hover:       #2c2c2c;
  --bg-active:      #2f2f2f;
  --bg-card:        #1e1e1e;
  --bg-input:       #252525;
  --bg-elevated:    #282828;

  /* Borders */
  --border:         #2e2e2e;
  --border-subtle:  #262626;
  --border-focus:   #444;

  /* Text */
  --text:           #e0e0e0;
  --text-secondary: #999;
  --text-faint:     #888;
  --text-on-accent: #fff;

  /* Accent */
  --accent:         #5b9bd5;
  --accent-hover:   #6ba8e0;
  --accent-subtle:  rgba(91, 155, 213, 0.12);
  --accent-glow:    rgba(91, 155, 213, 0.08);

  /* Danger */
  --danger:         #d55b5b;

  /* Layout */
  --sidebar-width:  260px;
  --content-max:    860px;
  --radius:         6px;
  --radius-lg:      10px;

  /* Typography */
  --font:           'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:      'Fira Code', 'SF Mono', 'Cascadia Code', monospace;

  /* Transitions */
  --speed:          150ms;
  --ease:           cubic-bezier(0.25, 0.1, 0.25, 1);
}


/* ── Reset ──────────────────────────────── */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

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

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

::selection {
  background: var(--accent);
  color: var(--text-on-accent);
}


/* ── Utility ────────────────────────────── */

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: background var(--speed) var(--ease),
              color var(--speed) var(--ease);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 10px 20px;
  background: var(--accent);
  color: var(--text-on-accent);
  border-radius: var(--radius);
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background var(--speed) var(--ease),
              transform 80ms var(--ease);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}


/* ── Login Page ─────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
}

.login-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 600px 400px at 50% 40%, var(--accent-glow) 0%, transparent 70%);
}

.login-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border-subtle) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-subtle) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: 0.4;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, black 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, black 20%, transparent 70%);
}

.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand .brand-icon {
  margin-bottom: 12px;
}

.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text);
}

.login-brand .brand-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
  letter-spacing: 0.03em;
}

/* Tabs */
.login-tabs {
  display: flex;
  position: relative;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.login-tab {
  flex: 1;
  padding: 10px 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  transition: color var(--speed) var(--ease);
}

.login-tab.active {
  color: var(--text);
}

.tab-indicator {
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 50%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: transform 250ms var(--ease);
}

/* Form */
.login-form {
  display: none;
}

.login-form.active {
  display: block;
  animation: fadeUp 200ms var(--ease);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.field input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color var(--speed) var(--ease),
              box-shadow var(--speed) var(--ease);
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.login-error {
  font-size: 0.82rem;
  color: var(--danger);
  text-align: center;
  margin-bottom: 12px;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 200ms, max-height 200ms;
}

.login-error.visible {
  opacity: 1;
  max-height: 40px;
}

.login-form .btn-primary {
  margin-top: 20px;
}


/* ── App Layout ─────────────────────────── */

.editor-page {
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}


/* ── Sidebar ────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 250ms var(--ease),
              opacity 200ms var(--ease);
  z-index: 10;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 8px 16px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-name {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius);
  color: var(--text-faint);
  transition: background var(--speed), color var(--speed);
}

.sidebar-collapse-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.sidebar-expand-btn {
  position: fixed;
  top: 14px;
  left: 8px;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  color: var(--text-faint);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  transition: background var(--speed), color var(--speed);
}

.sidebar-expand-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar.collapsed ~ .sidebar-expand-btn {
  display: flex;
}

.sidebar.collapsed ~ .content #hatchery-container {
  padding-left: 20px;
}

/* Sidebar footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-ai-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 10px 6px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-subtle);
  border: 1px solid rgba(91, 155, 213, 0.25);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
}

.sidebar-ai-btn:hover {
  background: rgba(91, 155, 213, 0.18);
  border-color: rgba(91, 155, 213, 0.4);
}

.sidebar-footer-name {
  font-size: 0.78rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar scroll area */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 4px;
}

.sidebar-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}


/* ── Page Tree ──────────────────────────── */

.tree-section {
  margin-bottom: 8px;
}

.tree-empty {
  padding: 4px 10px 4px 16px;
  margin: 1px 6px;
  color: var(--text-faint);
  font-size: 0.85rem;
}

a.tree-link {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

a.tree-link:hover {
  color: var(--text);
}

.tree-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 16px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tree-section-header .btn-icon {
  width: 22px;
  height: 22px;
  opacity: 0;
  transition: opacity var(--speed);
}

.tree-section:hover .tree-section-header .btn-icon {
  opacity: 1;
}

/* Tree items */
.tree-item {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 10px 4px calc(16px + var(--depth, 0) * 20px);
  cursor: pointer;
  border-radius: 4px;
  margin: 1px 6px;
  transition: background var(--speed) var(--ease);
  user-select: none;
  position: relative;
}

.tree-item:hover {
  background: var(--bg-hover);
}

.tree-item.active {
  background: var(--bg-active);
}

.tree-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 2.5px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.tree-expand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: color var(--speed), background var(--speed);
  font-size: 0.7rem;
}

.tree-expand:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

.tree-expand svg {
  transition: transform 150ms var(--ease);
}

.tree-expand.expanded svg {
  transform: rotate(90deg);
}

.tree-expand.no-children {
  visibility: hidden;
}

.tree-icon {
  font-size: 0.9rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.tree-title {
  flex: 1;
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  transition: color var(--speed);
}

.tree-item:hover .tree-title,
.tree-item.active .tree-title {
  color: var(--text);
}

.tree-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--speed);
}

.tree-item:hover .tree-actions {
  opacity: 1;
}

.tree-actions .btn-icon {
  width: 22px;
  height: 22px;
}

/* Tree children container */
.tree-children {
  overflow: hidden;
}

.tree-children.collapsed {
  display: none;
}

/* Drag & drop */
.tree-item.dragging {
  opacity: 0.4;
}

.tree-item.drag-over-above::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 16px;
  right: 8px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.tree-item.drag-over-below::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 16px;
  right: 8px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.tree-item.drag-over-inside {
  background: var(--accent-subtle);
  outline: 1.5px solid var(--accent);
  outline-offset: -1.5px;
  border-radius: 4px;
}

.drop-indicator {
  display: none;
  position: fixed;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  z-index: 100;
  pointer-events: none;
}

.drop-indicator.visible {
  display: block;
}


/* ── Main Content ───────────────────────── */

.content {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.content::-webkit-scrollbar {
  width: 6px;
}

.content::-webkit-scrollbar-track {
  background: transparent;
}

.content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
}

.content-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 60px 80px 120px;
  display: none;
}

.content-inner.visible {
  display: block;
  animation: fadeUp 250ms var(--ease);
}

.page-header {
  margin-bottom: 24px;
}

.page-header-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.page-title {
  display: block;
  width: 100%;
  flex: 1;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  padding: 0;
  border: none;
  background: none;
  letter-spacing: -0.02em;
}

.page-title::placeholder {
  color: var(--text-faint);
}

.page-title.readonly {
  opacity: 1;
}

.readonly-badge {
  display: none;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  align-self: center;
  white-space: nowrap;
}

/* Empty state */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-faint);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
}


/* ── Editor / ProseMirror ───────────────── */

#editor {
  min-height: 200px;
}

.ProseMirror {
  outline: none;
  line-height: 1.65;
  font-size: 0.95rem;
  color: var(--text);
}

.ProseMirror > * {
  margin-bottom: 2px;
}

.ProseMirror p {
  margin: 0;
  padding: 3px 0;
}

.ProseMirror > p.is-editor-empty:first-child::before {
  content: 'Start writing, or press "/" for commands...';
  color: var(--text-faint);
  pointer-events: none;
  float: left;
  height: 0;
}

/* Headings */
.ProseMirror h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 32px;
  margin-bottom: 4px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.ProseMirror h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 2px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.ProseMirror h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 2px;
  line-height: 1.35;
}

/* Lists */
.ProseMirror ul,
.ProseMirror ol {
  padding-left: 24px;
  margin: 4px 0;
}

.ProseMirror li {
  margin: 2px 0;
}

.ProseMirror li p {
  margin: 0;
}

.ProseMirror ul > li {
  list-style-type: disc;
}

.ProseMirror ul > li > ul > li {
  list-style-type: circle;
}

.ProseMirror ol > li {
  list-style-type: decimal;
}

/* Code */
.ProseMirror code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 3px;
  color: #e06c75;
}

.ProseMirror pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 8px 0;
  overflow-x: auto;
}

.ProseMirror pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.6;
}

/* Blockquote */
.ProseMirror blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin: 8px 0;
  color: var(--text-secondary);
}

/* Horizontal rule */
.ProseMirror hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* Links */
.ProseMirror a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(91, 155, 213, 0.4);
  text-underline-offset: 2px;
  transition: text-decoration-color var(--speed);
}

.ProseMirror a:hover {
  text-decoration-color: var(--accent);
}

/* Link bubble */
.link-bubble {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.link-bubble-url {
  color: var(--accent);
  text-decoration: none;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-bubble-url:hover { text-decoration: underline; }
.link-bubble-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
}
.link-bubble-btn:hover { color: var(--text); }

/* Bold / italic */
.ProseMirror strong {
  font-weight: 600;
}

/* Mark / highlight */
.ProseMirror mark {
  background: rgba(91, 155, 213, 0.2);
  padding: 1px 2px;
  border-radius: 2px;
}


/* Tables */
.ProseMirror table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  table-layout: fixed;
  overflow: hidden;
}

.ProseMirror th,
.ProseMirror td {
  border: 1px solid #404040;
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  position: relative;
  min-width: 80px;
}

.ProseMirror th {
  background: #2f2f2f;
  font-weight: 600;
  font-size: 0.88rem;
}

.ProseMirror td p,
.ProseMirror th p {
  margin: 0;
  padding: 0;
}

.ProseMirror .selectedCell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-subtle);
  pointer-events: none;
}

.ProseMirror .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: -2px;
  width: 4px;
  background: var(--accent);
  pointer-events: none;
}

.ProseMirror.resize-cursor {
  cursor: col-resize;
}

.table-context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border-focus);
  border-radius: 6px;
  padding: 4px 0;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.table-context-menu button {
  display: block;
  width: 100%;
  padding: 6px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.table-context-menu button:hover {
  background: var(--accent-subtle);
}

/* Page link mentions */
.page-link {
  display: inline;
  padding: 1px 4px;
  background: var(--accent-subtle);
  border-radius: 3px;
  color: var(--accent);
  font-size: 0.9em;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--speed);
}

.page-link:hover {
  background: rgba(91, 155, 213, 0.2);
  text-decoration: none;
}

/* Mention autocomplete popup */
.mention-popup {
  position: fixed;
  z-index: 300;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 200px;
  max-width: 320px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: fadeUp 120ms var(--ease);
}

.mention-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  font-size: 0.85rem;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--speed), color var(--speed);
}

.mention-item.selected,
.mention-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.mention-empty {
  padding: 10px;
  font-size: 0.82rem;
  color: var(--text-faint);
  text-align: center;
}

/* ── Block-level interactions ───────────── */

.ProseMirror > * {
  position: relative;
  border-radius: 3px;
}

/* Drag handle (CSS-only, appears on hover) */
.ProseMirror > *::before {
  content: '⠿';
  position: absolute;
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-faint);
  border-radius: 3px;
  opacity: 0;
  transition: opacity var(--speed), color var(--speed);
  cursor: grab;
  user-select: none;
  pointer-events: auto;
}

.ProseMirror > *:hover::before {
  opacity: 1;
}

.ProseMirror > *:hover::before:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

/* Don't show drag handle on hr */
.ProseMirror > hr::before {
  display: none;
}


/* ── Context Menu ───────────────────────── */

.context-menu {
  display: none;
  position: fixed;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.context-menu.visible {
  display: block;
  animation: fadeUp 120ms var(--ease);
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 12px;
  font-size: 0.82rem;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: background var(--speed), color var(--speed);
}

.context-menu button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.context-menu button.danger {
  color: var(--danger);
}

.context-menu button.danger:hover {
  background: rgba(213, 91, 91, 0.1);
}


/* ── Presence ────────────────────────────── */

.presence {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.presence-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #3a7d44;
  border: 2px solid var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  cursor: default;
}

.presence-avatar:nth-child(2) { background: #7d3a6d; }
.presence-avatar:nth-child(3) { background: #3a5f7d; }
.presence-avatar:nth-child(4) { background: #7d6a3a; }


/* ── Toolbar ─────────────────────────────── */

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-top: 8px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  color: var(--text-faint);
  position: relative;
  transition: background var(--speed), color var(--speed);
}

.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.toolbar-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}


/* ── Side Panels ─────────────────────────── */

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  z-index: 25;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 250ms var(--ease);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.2);
}

.side-panel.open {
  transform: translateX(0);
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.side-panel-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.side-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.side-panel-content::-webkit-scrollbar {
  width: 4px;
}

.side-panel-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.side-panel-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.panel-empty {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
  padding: 24px 12px;
  line-height: 1.6;
}


/* ── Comments ────────────────────────────── */

.comment-thread {
  margin-bottom: 16px;
  padding: 10px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
}

.comment-thread.resolved {
  opacity: 0.5;
}

.comment {
  margin-bottom: 8px;
}

.comment:last-child {
  margin-bottom: 0;
}

.comment.reply {
  padding-left: 12px;
  border-left: 2px solid var(--border);
  margin-left: 4px;
}

.comment-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 3px;
}

.comment-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.comment-time {
  font-size: 0.7rem;
  color: var(--text-faint);
}

.comment-body {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.comment-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-text {
  background: none;
  border: none;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0;
  transition: color var(--speed);
}

.btn-text:hover {
  color: var(--text-secondary);
}

.btn-text.danger:hover {
  color: var(--danger);
}

.btn-text.accent {
  color: var(--accent);
}

.reply-indicator {
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 4px;
  min-height: 0;
}

#comment-form textarea {
  display: block;
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
  resize: vertical;
  min-height: 56px;
  margin-bottom: 8px;
  transition: border-color var(--speed);
}

#comment-form textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}


/* ── Version History ─────────────────────── */

.version-item {
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  margin-bottom: 8px;
  background: var(--bg);
  transition: border-color var(--speed);
}

.version-item.active {
  border-color: var(--accent);
}

.version-info {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}

.version-number {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

.version-pinned {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-faint);
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 2px;
  letter-spacing: 0.02em;
}

.version-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 4px;
  background: var(--bg-hover);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.version-filter-bar {
  padding: 4px 4px 8px;
}

.version-filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-faint);
  cursor: pointer;
}

.version-filter-toggle input {
  accent-color: var(--accent);
  cursor: pointer;
}

.version-title {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}

.version-meta {
  font-size: 0.72rem;
  color: var(--text-faint);
  width: 100%;
}

.version-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}


/* ── Block Lock Indicators ──────────────── */

.block-locked {
  position: relative;
  opacity: 0.6;
  border-radius: 4px;
  outline: 1.5px dashed var(--accent);
  outline-offset: 2px;
  transition: opacity var(--speed);
  cursor: not-allowed;
}

.block-locked::after {
  content: attr(data-locked-by) ' is editing';
  position: absolute;
  top: -2px;
  right: 0;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: 0.02em;
}


/* ── Responsive ─────────────────────────── */

@media (max-width: 860px) {
  .content-inner {
    padding: 40px 32px 100px;
  }

  .page-title {
    font-size: 1.75rem;
  }
}

@media (max-width: 640px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
  }

  .content-inner {
    padding: 40px 20px 100px;
  }
}


/* ── Slash Command Popup ─────────────── */

.slash-popup {
  position: fixed;
  z-index: 300;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 200px;
  max-width: 280px;
  max-height: 300px;
  overflow-y: scroll;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: fadeUp 120ms var(--ease);
}
.slash-popup::-webkit-scrollbar { width: 6px; }
.slash-popup::-webkit-scrollbar-track { background: transparent; }
.slash-popup::-webkit-scrollbar-thumb {
  background: var(--border-focus);
  border-radius: 3px;
}

.slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  font-size: 0.85rem;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--speed), color var(--speed);
}

.slash-item.selected,
.slash-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.slash-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-faint);
  flex-shrink: 0;
}

.slash-item.selected .slash-icon,
.slash-item:hover .slash-icon {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.slash-title {
  font-weight: 500;
}

.slash-empty {
  padding: 10px;
  font-size: 0.82rem;
  color: var(--text-faint);
  text-align: center;
}


/* ── Search Modal ────────────────────── */

.search-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
}

.search-modal.open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  animation: fadeUp 120ms var(--ease);
}

.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.search-dialog {
  position: relative;
  width: 100%;
  max-width: 540px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.search-input-icon {
  flex-shrink: 0;
  color: var(--text-faint);
}

.search-input-wrap input {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text);
  background: none;
  border: none;
  outline: none;
}

.search-input-wrap input::placeholder {
  color: var(--text-faint);
}

.search-kbd {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-faint);
}

.search-results {
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
}

.search-results::-webkit-scrollbar {
  width: 4px;
}

.search-results::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.search-hint {
  padding: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-faint);
}

.search-result-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--speed);
}

.search-result-item:hover,
.search-result-item.selected {
  background: var(--bg-hover);
}

.search-result-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.search-result-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.search-result-title {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-snippet {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-snippet mark {
  background: rgba(91, 155, 213, 0.25);
  color: var(--accent);
  padding: 0 1px;
  border-radius: 2px;
}


/* ── AI Prompt Modal ─────────────────── */

.ai-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
}

.ai-modal.open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  animation: fadeUp 120ms var(--ease);
}

.ai-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.ai-modal-dialog {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.ai-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.ai-modal-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.ai-modal-body {
  padding: 16px;
}

.ai-modal-body p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.ai-modal-textarea {
  display: block;
  width: 100%;
  min-height: 320px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  resize: vertical;
}

.ai-modal-footer {
  padding: 12px 16px 16px;
}

.ai-modal-footer .btn-primary {
  width: auto;
  padding: 8px 20px;
  font-size: 0.85rem;
}


/* ── Share Modal ─────────────────────── */

.share-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
}

.share-modal.open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  animation: fadeUp 120ms var(--ease);
}

.share-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.share-modal-dialog {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.share-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.share-modal-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.share-modal-body {
  padding: 16px;
}

.share-create-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.share-create-row input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  transition: border-color var(--speed);
}

.share-create-row input:focus {
  border-color: var(--accent);
}

.share-create-row .btn-primary {
  width: auto;
  white-space: nowrap;
  padding: 8px 16px;
}

.share-list {
  max-height: 260px;
  overflow-y: auto;
}

.share-list::-webkit-scrollbar {
  width: 4px;
}

.share-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.share-empty {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
  padding: 20px 12px;
}

.share-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  margin-bottom: 6px;
  background: var(--bg);
}

.share-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.share-item-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-item-date {
  font-size: 0.72rem;
  color: var(--text-faint);
}

.share-item-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
