:root {
  --bg: #f3efe6;
  --paper: #fbf9f4;
  --surface: #ffffff;
  --ink: #2b2a28;
  --ink-soft: #6f6c66;
  --ink-faint: #b8b3aa;
  --line: rgba(43, 42, 40, 0.12);
  --line-strong: rgba(43, 42, 40, 0.24);
  --accent: #3b6db5;
  --accent-soft: rgba(59, 109, 181, 0.14);
  --accent-ink: rgba(59, 109, 181, 0.85);
  --highlight: #fff3a8;
  --danger: #b03a2e;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-card: 0 1px 0 rgba(43, 42, 40, 0.04), 0 4px 16px rgba(43, 42, 40, 0.06);
  --shadow-pop: 0 12px 32px rgba(43, 42, 40, 0.18);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

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

html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: 0; cursor: pointer; }

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

/* ---------- FLASH ---------- */
.flash-stack {
  position: fixed; top: 16px; right: 16px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
}
.flash {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  display: flex; align-items: center; gap: 10px;
  transition: opacity 200ms, transform 200ms;
}
.flash-hide { opacity: 0; transform: translateY(-4px); }
.flash-close {
  font-size: 18px; line-height: 1; color: var(--ink-soft);
  padding: 0 2px;
}
.flash-close:hover { color: var(--ink); }

/* ---------- BUTTONS ---------- */
.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 6px 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; line-height: 1;
  border: 1px solid transparent; transition: background 120ms, color 120ms, border 120ms;
}
/* The display above beats the UA sheet's [hidden] rule, so `hidden` on a
   button would otherwise do nothing. */
.primary-btn[hidden],
.ghost-btn[hidden],
.danger-btn[hidden],
.icon-btn[hidden] { display: none; }
.primary-btn { background: var(--accent); color: #fff; padding: 8px 16px; }
.primary-btn:hover { background: #2f5d9f; }
.ghost-btn { color: var(--ink-soft); }
.ghost-btn:hover { color: var(--ink); background: rgba(43, 42, 40, 0.05); }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.danger:hover { background: rgba(176, 58, 46, 0.08); }
.danger-btn { background: var(--danger); color: #fff; padding: 8px 16px; }
.danger-btn:hover { background: #8c2d23; }
.icon-btn {
  width: 28px; height: 28px; padding: 0; color: var(--ink);
  border: 1px solid var(--line); background: var(--surface);
}
.icon-btn:hover { border-color: var(--ink-soft); }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.primary:hover { background: #2f5d9f; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { border-color: var(--danger); background: rgba(176, 58, 46, 0.08); }

/* ---------- LANDING ---------- */
body.landing { background: var(--bg); }
.landing-stage {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
}
.landing-card {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 48px 40px; text-align: center;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.brand-mark {
  width: 56px; height: 56px; border-radius: var(--radius);
  display: block; margin-bottom: 4px;
}
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.brand-tag { color: var(--ink-soft); font-size: 14px; }
.google-btn {
  margin-top: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 18px; min-width: 260px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-weight: 600;
}
.google-btn:hover { border-color: var(--ink-soft); text-decoration: none; }
.landing-fineprint { font-size: 11px; color: var(--ink-soft); margin-top: 4px; }
.auth-divider {
  display: flex; align-items: center; gap: 10px; width: 100%;
  color: var(--ink-soft); font-size: 12px; margin-top: 6px;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.auth-form { width: 100%; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.auth-field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.auth-field input {
  padding: 10px 12px; font: inherit; font-weight: 400;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.auth-field input:focus { outline: none; border-color: var(--accent); }
.auth-submit {
  padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
}
.auth-submit:hover { background: #2f5d9f; }
.auth-errors p, .auth-error { color: var(--danger); font-size: 12px; font-weight: 500; }
.auth-alt { font-size: 13px; color: var(--ink-soft); }
.auth-alt a { font-weight: 600; }

/* ---------- CONFIRM PAGE ---------- */
body.centered { background: var(--bg); }
.confirm-stage { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.confirm-card {
  width: min(440px, 100%); background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 32px; box-shadow: var(--shadow-card);
}
.confirm-card h1 { font-size: 18px; margin-bottom: 8px; }
.confirm-card p { color: var(--ink-soft); margin-bottom: 24px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- WORKSPACE LAYOUT ---------- */
body.workspace-body { background: var(--bg); overflow: hidden; }

.workspace {
  --sidebar-w: 260px;
  display: grid;
  grid-template-columns: var(--sidebar-w) 6px 1fr;
  grid-template-rows: 100vh;
  grid-template-rows: 100dvh;
  height: 100vh;
  height: 100dvh;
}
.workspace.has-links { grid-template-columns: var(--sidebar-w) 6px 1fr 360px; }
.workspace.has-history { grid-template-columns: var(--sidebar-w) 6px 1fr 380px; }
.workspace.has-research { grid-template-columns: var(--sidebar-w) 6px 1fr 360px; }

.sidebar-resizer {
  cursor: col-resize;
  background: transparent;
  border-right: 1px solid var(--line);
  margin-left: -1px;
  position: relative;
  user-select: none;
  touch-action: none;
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging,
.sidebar-resizer:focus-visible {
  background: var(--accent);
  border-right-color: var(--accent);
  outline: none;
}
body.resizing-sidebar { cursor: col-resize; user-select: none; }
body.resizing-sidebar * { cursor: col-resize !important; }

/* SIDEBAR */
.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-width: 0;
}
.sidebar-head {
  padding: 14px 14px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-square {
  width: 18px; height: 18px; border-radius: 4px; display: block; flex: none;
}
.brand-text { font-weight: 700; letter-spacing: -0.01em; }
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-search {
  margin: 0 14px 10px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 10px;
  color: var(--ink-soft);
}
.sidebar-search input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 12.5px;
}
.sidebar-search input::placeholder { color: var(--ink-faint); }

.tree {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 4px 4px 12px;
  scrollbar-width: thin;
  display: flex; flex-direction: column;
}

.sidebar-tags {
  margin: 0 14px 10px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.sidebar-tags[hidden] { display: none; }
.sidebar-tags-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
}
.sidebar-tags-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  font-weight: 600;
}
.sidebar-tags-clear {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--ink-soft);
  padding: 0 2px;
}
.sidebar-tags-clear:hover { color: var(--accent); text-decoration: underline; }
.sidebar-tags-list {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.tag-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
}
.tag-pill:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}
.tag-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.tag-pill .tp-count {
  font-size: 10px;
  color: var(--ink-faint);
}
.tag-pill.active .tp-count { color: var(--accent); }
.sidebar-foot {
  flex: none;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px;
  background: var(--paper);
}
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg); color: var(--ink-soft);
  border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.avatar:hover, .avatar:focus-visible { background: var(--line); }
.logout-form { margin: 0; }

/* TREE NODES */
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; padding-left: calc(8px + var(--depth, 0) * 14px);
  border-radius: 4px; cursor: pointer; position: relative;
  border-left: 2px solid transparent;
  color: var(--ink);
}
.tree-row:hover { background: rgba(43, 42, 40, 0.04); }
.tree-row.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.tree-row.drop-target { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.tree-row.dragging { opacity: 0.35; }
.tree-row .chev {
  width: 12px; height: 12px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-soft); transition: transform 120ms;
}
.tree-row.open .chev { transform: rotate(90deg); }
.tree-row .leaf-spacer { width: 12px; }
.tree-row .icon { color: var(--ink-soft); display: inline-flex; }
.tree-row.active .icon { color: var(--accent); }
.tree-row .label {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px;
}
.tree-row .badge {
  font-size: 10px; color: var(--ink-faint);
  margin-left: auto; opacity: 1; transition: opacity 120ms;
}
.tree-row .hover-actions {
  display: none; align-items: center; gap: 4px; margin-left: auto;
}
.tree-row:hover .badge { display: none; }
.tree-row:hover .hover-actions { display: inline-flex; }
.tree-row.renaming .label { display: none; }
.tree-row .rename-input {
  flex: 1; min-width: 0; padding: 1px 6px; border: 1px solid var(--accent);
  background: var(--surface); border-radius: 3px; font-size: 12.5px; outline: none;
}
.hover-icon-btn {
  width: 18px; height: 18px; border-radius: 3px; color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.hover-icon-btn:hover { background: rgba(43, 42, 40, 0.08); color: var(--ink); }

.drop-indicator {
  height: 2px; background: var(--accent); margin: 1px 0 1px;
  margin-left: calc(8px + var(--depth, 0) * 14px);
  border-radius: 2px;
}

/* Trash pinned at the bottom of the tree. */
/* Trash sits in the tree as a top-level node next to "All notes" — it holds
   whole deleted subtrees now, so it has to grow with the tree rather than
   cling to the bottom of the sidebar and fight the explorer for space. */
.tree-branch.trash-branch { margin-top: 2px; }
.tree-row.trash-row .icon,
.tree-row.trash-row .label { color: var(--ink-soft); }
.tree-row.trashed-row .icon,
.tree-row.trashed-row .label { color: var(--ink-soft); }
.tree-row.trashed-row .hover-icon-btn[data-action="purge-folder"]:hover {
  color: var(--danger);
  background: rgba(176, 58, 46, 0.10);
}
.tree-row.trash-row.drop-target {
  background: rgba(176, 58, 46, 0.10);
  outline-color: var(--danger);
}
.tree-row.trash-row .hover-icon-btn:hover {
  color: var(--danger);
  background: rgba(176, 58, 46, 0.10);
}

/* ---------- MAIN ---------- */
.main {
  display: flex; flex-direction: column;
  background: var(--surface);
  min-width: 0;
  position: relative;
}
.topbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sidebar-toggle { display: none; }
.breadcrumb {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-soft);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.breadcrumb .crumb { white-space: nowrap; }
.breadcrumb .crumb.current { color: var(--ink); font-weight: 600; }
.breadcrumb .sep { color: var(--ink-faint); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 11px; color: var(--ink-soft); min-width: 90px; text-align: right; }
/* Toolbar buttons that kick off a background AI job (improve, translate):
   accent-coloured, and their icon spins while the job runs. */
.ai-improve-btn, .ai-action-btn { padding: 6px 8px; color: var(--accent); }
.ai-improve-btn:hover, .ai-action-btn:hover { color: var(--accent); background: rgba(56, 110, 184, 0.10); }
.ai-improve-btn.is-busy, .ai-action-btn.is-busy { opacity: 0.6; cursor: progress; }
.ai-improve-btn.is-busy svg, .ai-action-btn.is-busy svg { animation: ai-spin 1.1s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }

.editor-pane {
  flex: 1; overflow-y: auto; background: var(--surface); position: relative;
}
.editor-shell {
  max-width: 780px; margin: 0 auto;
  padding: 32px 56px 56px;
}
.note-title {
  width: 100%; border: 0; outline: none; background: transparent;
  font-size: 28px; font-weight: 700; letter-spacing: -0.01em;
  margin-bottom: 16px; color: var(--ink);
}
.note-title::placeholder { color: var(--ink-faint); }

/* QUILL OVERRIDES */
.quill-host { background: var(--surface); }
.ql-toolbar.ql-snow {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius);
  background: var(--paper);
  margin-bottom: 12px;
  padding: 6px 8px;
}
.ql-container.ql-snow {
  border: 0 !important;
  font-size: 14.5px;
  font-family: inherit;
}
.ql-editor {
  padding: 0; min-height: 320px;
  line-height: 1.65; color: var(--ink);
}
.ql-editor h1 { font-size: 22px; margin: 18px 0 10px; }
.ql-editor h2 { font-size: 18px; margin: 16px 0 8px; }
.ql-editor h3 { font-size: 15px; margin: 14px 0 6px; }
.ql-editor blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 12px 0; color: var(--ink-soft);
}
.ql-editor .note-link {
  color: var(--accent);
  text-decoration: underline; text-decoration-style: dotted;
  font-weight: 600;
}
.ql-editor .note-link.unresolved {
  color: var(--danger);
  text-decoration-style: wavy;
}

/* ---------- TABLES ---------- */
.ql-editor table,
.view-body table {
  border-collapse: collapse;
  margin: 12px 0;
  width: auto;
  table-layout: auto;
}
.ql-editor td,
.view-body td {
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  min-width: 64px;
  vertical-align: top;
}
.ql-editor td:focus-within {
  background: var(--accent-soft);
}

/* Insert-size picker (10×10 hover grid) */
.table-picker {
  position: absolute;
  z-index: 60;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.12);
}
.table-picker[hidden] { display: none; }
.table-picker-grid {
  display: grid;
  grid-template-columns: repeat(10, 18px);
  grid-template-rows: repeat(10, 18px);
  gap: 2px;
}
.table-picker-cell {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 2px;
  cursor: pointer;
}
.table-picker-cell.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.table-picker-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

/* Floating per-cell action toolbar */
.table-tools {
  position: absolute;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.table-tools[hidden] { display: none; }
.table-tools button {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 3px;
  padding: 4px 6px;
  font: 600 11px/1 var(--mono, ui-monospace, monospace);
  color: var(--ink);
  cursor: pointer;
}
.table-tools button:hover { background: var(--accent-soft); }
.table-tools button.danger { color: var(--danger); }
.table-tools button.danger:hover { background: rgba(220, 60, 60, 0.12); }
.table-tools-sep {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 2px 4px;
}

/* ---------- VIEW MODE ---------- */
.note-view {
  max-width: 780px; margin: 0 auto;
  padding: 32px 56px 56px;
}
.view-title {
  font-size: 28px; font-weight: 700; letter-spacing: -0.01em;
  margin-bottom: 6px; color: var(--ink); line-height: 1.25;
}
.view-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  font-size: 12px; color: var(--ink-soft);
  margin-bottom: 18px;
}
.view-meta-sep { color: var(--line-strong); }
.view-meta-ai { color: var(--accent); font-weight: 600; }
.view-body {
  font-size: 14.5px; line-height: 1.65; color: var(--ink);
  min-height: 160px;
}
.view-body p { margin: 8px 0; }
.view-body h1 { font-size: 22px; margin: 18px 0 10px; }
.view-body h2 { font-size: 18px; margin: 16px 0 8px; }
.view-body h3 { font-size: 15px; margin: 14px 0 6px; }
.view-body ul, .view-body ol { margin: 8px 0; padding-left: 24px; }
.view-body li { margin: 2px 0; }
/* Quill 2 stores both bullet and numbered lists as <ol data-list="…">;
   keep view-mode markers consistent with edit-mode. */
.view-body ol[data-list="bullet"] { list-style-type: disc; }
.view-body ol[data-list="ordered"] { list-style-type: decimal; }
.view-body li[data-list="bullet"] { list-style-type: disc; }
.view-body li[data-list="ordered"] { list-style-type: decimal; }
.view-body .ql-ui { display: none; }

/* Checklist lines. Quill draws its own checkbox from a .ql-ui element it
   generates at runtime, which #viewBody never gets — decorateTodos inserts a
   real .todo-box button as the line's first child instead, so the marker slot
   has to stand down. */
.view-body li[data-list="checked"],
.view-body li[data-list="unchecked"] { list-style-type: none; }
.view-body li.todo-done { color: var(--ink-soft); text-decoration: line-through; }
.todo-box {
  flex: none;
  width: 15px; height: 15px; padding: 0; margin-right: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: -2px;
  border: 1px solid var(--line-strong); border-radius: 4px;
  background: var(--surface); color: transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.todo-box svg { width: 11px; height: 11px; }
.todo-box:hover:not(:disabled) { border-color: var(--accent); }
.todo-box[aria-checked="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--surface);
}
.todo-box:disabled { cursor: default; opacity: 0.7; }
.view-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 12px 0; color: var(--ink-soft);
}
.view-body pre, .view-body code {
  font-family: var(--mono); font-size: 13px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px;
}
.view-body code { padding: 0 4px; }
.view-body pre { padding: 10px 12px; overflow-x: auto; }
.view-body pre code { border: 0; padding: 0; background: transparent; }
.view-body a { color: var(--accent); text-decoration: underline; text-decoration-color: var(--line-strong); }
.view-body a:hover { text-decoration-color: var(--accent); }
.view-body .wiki-link {
  color: var(--accent); font-weight: 600;
  text-decoration: underline; text-decoration-style: dotted;
}
.view-body .wiki-link:hover { background: var(--accent-soft); border-radius: 3px; }
.view-body .wiki-link.unresolved {
  color: var(--danger);
  text-decoration-style: wavy;
  cursor: help;
}
.view-body .tag-chip {
  display: inline-block;
  padding: 0 6px;
  margin: 0 1px;
  font-size: 0.88em;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  vertical-align: baseline;
}
.view-body .tag-chip:hover {
  text-decoration: none;
  background: var(--accent);
  color: var(--surface);
}
/* Date tokens (@2026-08-03) render as chips like tags, but in the ink palette
   rather than the accent one — a date is a fact about the note, not a filter
   the user chose. */
.view-body .date-chip {
  display: inline-block;
  padding: 0 6px;
  margin: 0 1px;
  font-size: 0.88em;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 4px;
  background: rgba(43, 42, 40, 0.06);
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
  vertical-align: baseline;
}
.view-body .date-chip:hover {
  text-decoration: none;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.view-body .view-empty { color: var(--ink-soft); font-style: italic; }
.view-body img { max-width: 100%; height: auto; cursor: zoom-in; }

/* ---------- IMAGE LIGHTBOX ---------- */
.image-lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10, 12, 16, 0.92);
  display: flex; flex-direction: column;
  user-select: none;
}
.image-lightbox[hidden] { display: none; }
.image-lightbox-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.35);
  color: #f4f4f5;
}
.image-lightbox-btn {
  width: 32px; height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #f4f4f5;
  border-radius: 6px;
  font-size: 16px; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.image-lightbox-btn:hover { background: rgba(255, 255, 255, 0.18); }
.image-lightbox-zoom {
  min-width: 56px; text-align: center;
  font-size: 13px; font-variant-numeric: tabular-nums;
  color: #d4d4d8;
}
.image-lightbox-close { margin-left: auto; }
.image-lightbox-stage {
  flex: 1; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
}
.image-lightbox-stage.dragging { cursor: grabbing; }
.image-lightbox-img {
  max-width: 100%; max-height: 100%;
  transform-origin: center center;
  transition: transform 80ms ease-out;
  pointer-events: none;
  -webkit-user-drag: none;
}
.image-lightbox-stage.dragging .image-lightbox-img { transition: none; }

/* ---------- ATTACHMENTS ---------- */
.quill-host.drop-files {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  background: var(--accent-soft);
}
.view-body .attachment-chip,
.ql-editor a[href^="/attachments/"] {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin: 2px 4px 2px 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.2;
  vertical-align: middle;
  max-width: 100%;
}
.view-body .attachment-chip:hover,
.ql-editor a[href^="/attachments/"]:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}
.view-body .attachment-chip .att-icon { color: var(--ink-soft); display: inline-flex; }
.view-body .attachment-chip.is-pdf .att-icon { color: var(--danger); }
.view-body .attachment-chip .att-name { font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-body .attachment-chip .att-size { color: var(--ink-soft); font-size: 11px; }
.view-body .attachment-chip .att-action {
  margin-left: 4px; padding: 2px 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; color: var(--accent);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 24px; color: var(--ink-soft); gap: 12px;
  height: 100%;
}
.empty-state h2 { color: var(--ink); font-size: 18px; }
.empty-state[hidden] { display: none; }

.empty-row {
  font-size: 12px; color: var(--ink-soft);
  padding: 10px 16px;
}

/* ---------- FOLDER / RESULTS LISTING ---------- */
.folder-view {
  max-width: 780px; margin: 0 auto;
  padding: 32px 56px 56px;
}
.folder-view[hidden] { display: none; }
.folder-view-head {
  display: flex; align-items: baseline; gap: 12px;
}
.folder-view-title {
  flex: 1; min-width: 0;
  font-size: 24px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder-view-actions { display: flex; gap: 6px; flex-shrink: 0; }
.folder-view-actions[hidden] { display: none; }
/* Match the sidebar's blue + button: accent fill, 28px tall. */
.folder-view-actions .primary-btn {
  height: 28px; padding: 0 12px; font-size: 12.5px;
  border-color: var(--accent);
}
.folder-view-sub {
  margin: 4px 0 18px; font-size: 11.5px; color: var(--ink-faint);
}
.folder-list { display: flex; flex-direction: column; }
.folder-list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 5px; cursor: pointer;
  border-top: 1px solid var(--line);
  color: var(--ink);
}
.folder-list-row:last-child { border-bottom: 1px solid var(--line); }
.folder-list-row:hover { background: rgba(43, 42, 40, 0.04); }
.folder-list-row.drop-target { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.folder-list-row.dragging { opacity: 0.35; }
.folder-list-row .fl-icon { color: var(--ink-soft); display: inline-flex; flex-shrink: 0; }
.folder-list-row .fl-name {
  flex: 1; min-width: 0; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder-list-row .fl-sub {
  display: block; font-size: 11px; color: var(--ink-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder-list-row .fl-meta {
  font-size: 11px; color: var(--ink-faint); flex-shrink: 0;
}
.folder-list-row .fl-actions { display: none; align-items: center; flex-shrink: 0; }
.folder-list-row:hover .fl-actions { display: inline-flex; }
.folder-list-empty {
  padding: 28px 10px; font-size: 12.5px; color: var(--ink-soft); text-align: center;
}

@media (max-width: 720px) {
  .folder-view { padding: 20px 16px 40px; }
}

/* ---------- LINKS PANEL ---------- */
.links-panel {
  background: var(--paper); border-left: 1px solid var(--line-strong);
  display: flex; flex-direction: column; min-width: 0;
}
.links-panel[hidden] { display: none; }
.links-panel-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.links-panel-body { flex: 1; overflow-y: auto; }
.links-section + .links-section { border-top: 1px solid var(--line-strong); }
.links-section-head {
  padding: 12px 16px 6px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.links-section-head strong { font-size: 12px; letter-spacing: 0.3px; color: var(--ink); }
.links-section-sub { color: var(--ink-soft); font-size: 11px; }
.links-section-body { padding-bottom: 6px; }
.link-card {
  padding: 10px 16px; border-top: 1px solid var(--line);
  cursor: pointer; display: block;
}
.link-card:first-child { border-top: 0; }
.link-card:hover { background: var(--surface); text-decoration: none; }
.link-card.unresolved { opacity: 0.7; }
.link-card .lc-title { font-size: 12.5px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.link-card.unresolved .lc-title { color: var(--danger); }
.link-card .lc-folder { font-size: 10px; color: var(--ink-soft); margin-top: 2px; }
.link-card .lc-tag {
  margin-left: auto; font-size: 9px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.8px;
}
.link-card.suggested {
  display: flex; align-items: center; gap: 10px;
  cursor: default;
}
.link-card.suggested:hover { background: transparent; }
.link-card.suggested .suggested-link {
  flex: 1; min-width: 0; color: inherit; display: block;
  padding: 2px 0;
}
.link-card.suggested .suggested-link:hover { text-decoration: none; }
.link-card.suggested .suggested-link:hover .lc-title { color: var(--accent); }
.link-card.suggested .suggested-insert {
  font-size: 11px; font-weight: 600; color: var(--accent);
  padding: 4px 8px; border: 1px solid var(--accent-soft); border-radius: var(--radius);
  background: var(--accent-soft);
  white-space: nowrap;
}
.link-card.suggested .suggested-insert:hover { background: var(--accent); color: var(--surface); }
.link-card.suggested.is-busy { opacity: 0.5; pointer-events: none; }

/* ---------- HISTORY PANEL ---------- */
.history-panel {
  background: var(--paper); border-left: 1px solid var(--line-strong);
  display: flex; flex-direction: column; min-width: 0;
}
.history-panel[hidden] { display: none; }
.history-panel-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.history-panel-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.history-hint { padding: 10px 16px; font-size: 11px; color: var(--ink-soft); }
.history-list { border-top: 1px solid var(--line-strong); }
.history-row {
  padding: 10px 16px; border-top: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
}
.history-row:first-child { border-top: 0; }
.history-row:hover { background: var(--surface); }
.history-row .hv-select { margin-top: 3px; cursor: pointer; }
.hv-main { min-width: 0; flex: 1; }
.hv-title { font-size: 12.5px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.hv-badge {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
}
.hv-badge.ai { background: var(--accent-soft); color: var(--accent); }
.hv-badge.user { background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line-strong); }
.hv-current { margin-left: auto; font-size: 9px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.6px; }
.hv-when { font-size: 10px; color: var(--ink-soft); margin-top: 2px; }
.hv-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; visibility: hidden; }
.history-row:hover .hv-actions, .history-row.active .hv-actions { visibility: visible; }
.history-row.active { background: var(--surface); }
.hv-action.hv-delete:hover { color: var(--danger); background: rgba(176, 58, 46, 0.10); }

.history-compare {
  border-top: 1px solid var(--line-strong);
}
.history-compare[hidden] { display: none; }
.history-compare-head {
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.history-compare-body {
  padding: 4px 16px 16px;
  font-size: 13px; line-height: 1.6; color: var(--ink);
  max-height: 45vh; overflow-y: auto;
}
.diff-text { white-space: pre-wrap; word-break: break-word; }
.diff-text ins { background: rgba(40, 160, 90, 0.18); text-decoration: none; color: var(--ink); }
.diff-text del { background: rgba(220, 60, 60, 0.15); text-decoration: line-through; color: var(--ink-soft); }

.history-preview-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; margin-bottom: 14px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); border-radius: var(--radius);
  font-size: 12px; font-weight: 600;
}
.history-preview-banner[hidden] { display: none; }
.history-preview-banner .ghost-btn { flex-shrink: 0; }

/* ---------- RESEARCH PANEL ---------- */
.research-panel {
  background: var(--paper); border-left: 1px solid var(--line-strong);
  display: flex; flex-direction: column; min-width: 0;
}
.research-panel[hidden] { display: none; }
.research-panel-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.research-panel-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.research-form {
  display: flex; gap: 8px; padding: 14px 16px 6px;
}
.research-form input {
  flex: 1; min-width: 0;
  padding: 8px 10px; font: inherit; font-size: 13px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.research-form input:focus { outline: none; border-color: var(--accent); }
.research-form .primary-btn { flex-shrink: 0; font-size: 12px; padding: 8px 12px; }
.research-hint { padding: 4px 16px 12px; font-size: 11px; color: var(--ink-soft); }
.research-jobs { border-top: 1px solid var(--line-strong); }
.research-row {
  padding: 12px 16px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 5px;
}
.research-row[data-folder] { cursor: pointer; }
.research-row[data-folder]:hover { background: var(--paper-soft, rgba(0,0,0,0.03)); }
.research-row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.research-topic {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.research-badge {
  flex-shrink: 0; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--ink-soft);
}
.research-badge.run { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.research-badge.ok { color: #2e7d4f; border-color: #2e7d4f; background: rgba(40, 160, 90, 0.12); }
.research-badge.err { color: var(--danger); border-color: var(--danger); background: rgba(220, 60, 60, 0.10); }
.research-delete { flex-shrink: 0; padding: 4px 6px; }
.research-delete svg { width: 14px; height: 14px; }
.research-row-detail { font-size: 12px; color: var(--ink-soft); word-break: break-word; }
.research-row-meta {
  display: flex; align-items: center; gap: 12px;
  font-size: 11px; color: var(--ink-soft);
}
.research-folder { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.research-folder svg { flex-shrink: 0; }
.research-spinner {
  flex-shrink: 0; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: research-spin 0.9s linear infinite;
}
@keyframes research-spin { to { transform: rotate(360deg); } }
#researchBtn { position: relative; }
.research-dot {
  position: absolute; top: 2px; right: 2px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: research-pulse 1.4s ease-in-out infinite;
}
.research-dot[hidden] { display: none; }
@keyframes research-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

/* ---------- PICKER ---------- */
.picker {
  position: fixed; z-index: 50; width: 340px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.picker[hidden] { display: none; }
.picker-head {
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; color: var(--ink-soft);
  font-size: 11.5px;
}
.picker-query { color: var(--accent); font-weight: 700; }
.picker-hint { margin-left: auto; font-size: 10px; color: var(--ink-faint); }
.picker-list { list-style: none; max-height: 280px; overflow-y: auto; }
.picker-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; border-left: 2px solid transparent;
}
.picker-item:hover, .picker-item.active {
  background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent);
}
.picker-item .pi-title { font-weight: 500; font-size: 12.5px; }
.picker-item.active .pi-title, .picker-item:hover .pi-title { font-weight: 700; }
.picker-item .pi-folder { font-size: 10px; color: var(--ink-soft); }
.picker-item.create {
  border-top: 1px dashed var(--line); color: var(--accent); font-weight: 600;
}

/* ---------- CALENDAR ---------- */
/* Wider than .folder-view: seven columns need the room. */
.calendar-view {
  display: flex; flex-direction: column;
  min-height: 0; height: 100%;
  padding: 24px 32px 32px;
}
.calendar-view[hidden] { display: none; }
.calendar-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; flex-shrink: 0;
}
.calendar-title {
  flex: 1; min-width: 0;
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.calendar-nav { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.calendar-week {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.calendar-day {
  background: var(--surface);
  display: flex; flex-direction: column; min-width: 0;
  overflow-y: auto;
}
.calendar-day.empty { background: var(--paper); }
.calendar-day.today .cd-number {
  background: var(--accent); color: var(--surface);
  border-radius: 999px; padding: 0 6px;
}
/* The head carries its own (sticky) background, which paints over the top edge
   of any border drawn on the day itself — so tint the head too rather than
   relying on the outline alone to read as "this is the day you clicked". */
.calendar-day.anchor { outline: 2px solid var(--accent); outline-offset: -2px; }
.calendar-day.anchor .calendar-day-head { background: var(--accent-soft); }
.calendar-day.anchor .cd-weekday { color: var(--accent); }
.calendar-day-head {
  display: flex; align-items: baseline; gap: 6px;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: inherit; z-index: 1;
}
.calendar-day-head .cd-weekday {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-faint); font-weight: 600;
}
.calendar-day-head .cd-number {
  margin-left: auto; font-size: 13px; font-weight: 700; color: var(--ink);
}
/* "New note on this day". It keeps its box at all times and only fades in, so
   hovering a lane doesn't shove the date number sideways. */
.calendar-day-head .cd-add {
  flex-shrink: 0;
  width: 18px; height: 18px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 4px; background: none; cursor: pointer;
  color: var(--ink-faint); font: inherit; font-size: 15px; line-height: 1;
  opacity: 0; transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.calendar-day:hover .cd-add,
.calendar-day-head .cd-add:focus-visible { opacity: 1; }
.calendar-day-head .cd-add:hover { background: var(--accent-soft); color: var(--accent); }
/* No hover on touch, so the affordance has to be permanent there. */
@media (hover: none) {
  .calendar-day-head .cd-add { opacity: 1; }
}
.calendar-day-notes { display: flex; flex-direction: column; padding: 4px; gap: 2px; }
/* A day with no notes is just its header — no empty padding band under it. */
.calendar-day-notes:empty { display: none; }
.calendar-note {
  display: flex; align-items: center; gap: 6px;
  width: 100%; text-align: left;
  padding: 6px 6px; border-radius: 4px;
  background: none; border: 0; cursor: pointer;
  color: var(--ink); font: inherit; font-size: 12px;
}
.calendar-note:hover { background: var(--accent-soft); color: var(--accent); }
.calendar-note .cn-icon { color: var(--ink-faint); display: inline-flex; flex-shrink: 0; }
.calendar-note:hover .cn-icon { color: var(--accent); }
.calendar-note .cn-title {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.calendar-note .cn-folder {
  margin-left: auto; flex-shrink: 0;
  font-size: 10px; color: var(--ink-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%;
}

/* ---------- TODOS ---------- */
/* Narrower than the calendar: a task list is one column of text, so it reads
   better constrained than stretched across a wide window. */
.todo-view {
  display: flex; flex-direction: column;
  min-height: 0; height: 100%;
  padding: 24px 32px 32px;
}
.todo-view[hidden] { display: none; }
.todo-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; flex-shrink: 0;
}
.todo-title {
  flex: 1; min-width: 0;
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink);
}
.todo-filter { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.todo-filter .ghost-btn.active {
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.todo-list {
  flex: 1; min-height: 0; overflow-y: auto;
  max-width: 720px; width: 100%;
}
.todo-empty { color: var(--ink-faint); font-size: 13px; padding: 8px 0; }
.td-group {
  margin-bottom: 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.td-note {
  display: flex; align-items: center; gap: 6px;
  width: 100%; text-align: left;
  padding: 8px 12px;
  background: var(--paper); border: 0; border-bottom: 1px solid var(--line);
  cursor: pointer; color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 600;
}
.td-note:hover { background: var(--accent-soft); color: var(--accent); }
.td-note .cn-icon { color: var(--ink-faint); display: inline-flex; flex-shrink: 0; }
.td-note:hover .cn-icon { color: var(--accent); }
.td-note .cn-title {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.td-note .cn-folder {
  margin-left: auto; flex-shrink: 0; font-weight: 400;
  font-size: 10px; color: var(--ink-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%;
}
.td-row {
  display: flex; align-items: flex-start; gap: 0;
  padding: 7px 12px; font-size: 13px; color: var(--ink);
}
.td-row + .td-row { border-top: 1px solid var(--line); }
.td-row .todo-box { margin-top: 1px; }
.td-row.done .td-text { color: var(--ink-soft); text-decoration: line-through; }
.td-text { min-width: 0; word-break: break-word; }
.td-text.td-blank { color: var(--ink-faint); font-style: italic; }

/* ---------- DATE PICKER ---------- */
.date-picker {
  position: fixed; z-index: 50; width: 240px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  overflow: hidden; padding-bottom: 4px;
}
.date-picker[hidden] { display: none; }
.date-picker-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.date-picker-month {
  flex: 1; text-align: center;
  font-size: 12px; font-weight: 700; color: var(--ink);
}
.date-picker-nav {
  width: 22px; height: 22px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); border-radius: 4px;
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  font-size: 13px; line-height: 1;
}
.date-picker-nav:hover { background: var(--accent-soft); color: var(--accent); }
.date-picker-weekdays, .date-picker-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  padding: 6px 6px 0;
}
.date-picker-weekdays span {
  text-align: center; font-size: 10px; font-weight: 600;
  color: var(--ink-faint); padding-bottom: 2px;
}
.dp-day {
  aspect-ratio: 1; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 4px; background: none; cursor: pointer;
  font: inherit; font-size: 11.5px; color: var(--ink);
}
.dp-day:hover { background: var(--accent-soft); color: var(--accent); }
.dp-day.out { color: var(--ink-faint); }
.dp-day.today { font-weight: 700; text-decoration: underline; }
.dp-day.active { background: var(--accent); color: var(--surface); font-weight: 700; }
.date-picker-hint {
  padding: 6px 10px 2px; font-size: 10px; color: var(--ink-faint); text-align: center;
}

/* ---------- CONTEXT MENU ---------- */
.ctx-menu {
  position: fixed; z-index: 60;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  list-style: none; min-width: 180px; padding: 6px 0;
}
.ctx-menu[hidden] { display: none; }
.ctx-menu li {
  padding: 6px 12px; cursor: pointer;
  font-size: 12px; color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.ctx-menu li:hover { background: var(--accent-soft); color: var(--accent); }
.ctx-menu li .kbd { font-family: var(--mono); font-size: 10px; color: var(--ink-soft); }
.ctx-menu li.danger { color: var(--danger); }
.ctx-menu li.danger:hover { background: rgba(176, 58, 46, 0.08); color: var(--danger); }
.ctx-menu .divider { height: 1px; background: var(--line); margin: 4px 0; padding: 0; pointer-events: none; }

/* ---------- SCRIM (mobile) ---------- */
.sidebar-scrim {
  display: none;
  position: fixed; inset: 0; z-index: 30;
  background: rgba(43, 42, 40, 0.42); border: 0; padding: 0;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .workspace.has-links { grid-template-columns: 1fr; }
  .workspace.has-history { grid-template-columns: 1fr; }
  .workspace.has-research { grid-template-columns: 1fr; }
  .sidebar-resizer { display: none; }
  .sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; height: 100dvh;
    width: min(300px, 86vw); z-index: 40;
    transform: translateX(-100%); transition: transform 200ms ease;
    box-shadow: var(--shadow-pop);
  }
  .workspace.sidebar-open .sidebar { transform: translateX(0); }
  .workspace.sidebar-open .sidebar-scrim { display: block; }
  .sidebar-toggle { display: inline-flex; }
  .editor-shell { padding: 22px 18px 56px; }
  .note-view { padding: 22px 18px 56px; }
  .note-title, .view-title { font-size: 22px; }
  .links-panel, .history-panel, .research-panel {
    position: fixed; inset: 0; z-index: 50;
    border-left: 0; border-top: 1px solid var(--line-strong);
  }
  .topbar { padding: 10px 16px; }
  .save-status { display: none; }
  /* Seven columns don't fit: stack the week as seven day blocks that the
     pane scrolls through, rather than one unreadable column each. */
  .calendar-view { padding: 18px 16px 32px; height: auto; }
  .calendar-week {
    grid-template-columns: 1fr;
    flex: none;
  }
  .calendar-day { overflow: visible; }
  .calendar-day-head { position: static; }
  .todo-view { padding: 18px 16px 32px; }
  /* The head wraps rather than squeezing the filter buttons off the edge. */
  .todo-head { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .editor-shell { padding: 16px 14px 56px; }
  .note-view { padding: 16px 14px 56px; }
  .topbar-actions .ghost-btn { padding: 6px 8px; font-size: 12px; }
  .picker { width: calc(100vw - 24px); left: 12px !important; }
  .calendar-head { flex-wrap: wrap; }
}

/* ---- admin: user management ---- */
/* .confirm-card sets an explicit width, not a max-width, so this has to
   override `width` to widen the card for the user table. */
.admin-card { width: min(1040px, 100%); }
.admin-users-scroll { overflow-x: auto; margin-top: 8px; }
.admin-users { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
.admin-users th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-soft); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.admin-users td { padding: 10px; border-bottom: 1px solid #e3e1dc; vertical-align: middle; }
.admin-users-email { font-weight: 500; }
/* Also worn by the "this device" pill in the settings sessions list. */
.admin-users-badge, .sessions-badge {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px;
  background: rgba(43, 42, 40, 0.07); color: var(--ink-soft);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
}
.admin-users-ok { color: var(--ink-soft); }
.admin-users-locked { color: var(--danger); font-weight: 500; }
.admin-users-nowrap { white-space: nowrap; }
.admin-users-actions { white-space: nowrap; text-align: right; }
.admin-users-note { font-size: 12px; color: var(--ink-soft); margin-top: 14px; }
.admin-users-immune { font-size: 12px; color: var(--ink-soft); }
.admin-users-actions form { display: inline; }
.admin-users-actions .ghost-btn { padding: 4px 8px; font-size: 12px; }

.admin-dialog {
  border: none; border-radius: 10px; padding: 0;
  max-width: 420px; width: 90%; margin: auto; inset: 0;
}
.admin-dialog form { display: flex; flex-direction: column; gap: 0.8em; padding: 24px; }
.admin-dialog-input {
  width: 100%; margin-top: 4px; padding: 8px;
  border: 1px solid #d6d3cc; border-radius: 6px;
  font-family: inherit; font-size: 14px;
}
.admin-dialog-buttons { display: flex; gap: 0.5em; justify-content: flex-end; margin-top: 0.4em; }

/* Below the width the table needs, drop the grid and stack each account into
   its own block so the actions are never scrolled out of sight. */
@media (max-width: 720px) {
  .admin-users-scroll { overflow-x: visible; }
  .admin-users, .admin-users tbody, .admin-users tr, .admin-users td { display: block; width: auto; }
  .admin-users thead { display: none; }
  .admin-users tr { padding: 14px 0; border-bottom: 1px solid #e3e1dc; }
  .admin-users td { border: 0; padding: 2px 0; }
  .admin-users td:not(.admin-users-actions):not(:first-child)::before {
    content: attr(data-label) ": "; color: var(--ink-soft);
  }
  .admin-users-actions { margin-top: 8px; text-align: left; white-space: normal; }
  .admin-users-actions .ghost-btn { padding: 6px 10px; }
}

/* ---- settings: page shell ---- */
/* One pane at a time behind a nav rail, rather than every section stacked in
   one 440px column. .confirm-card sets an explicit width (not a max-width),
   so widening the card means overriding `width` — same as .admin-card. */
.settings-stage { place-items: start center; }
.settings-card { width: min(960px, 100%); padding: 24px 28px 28px; }
.settings-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line);
}
.settings-card h1 { margin-bottom: 2px; }
/* Qualified by .settings-card: `.confirm-card p` sets margin-bottom: 24px and
   outranks a bare class selector. */
.settings-card .settings-subtitle { font-size: 13px; color: var(--ink-soft); margin: 0; }

.settings-body {
  display: grid; grid-template-columns: 190px 1fr; gap: 28px; margin-top: 20px;
}

.settings-nav { display: flex; flex-direction: column; gap: 2px; align-self: start; }
.settings-nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; color: var(--ink-soft);
  text-decoration: none; border-left: 2px solid transparent;
}
.settings-nav-item:hover { background: rgba(43, 42, 40, 0.05); color: var(--ink); text-decoration: none; }
.settings-nav-item.is-active {
  background: var(--accent-soft); color: var(--accent-ink); border-left-color: var(--accent);
}
.settings-nav-item.settings-nav-danger { color: var(--danger); }
.settings-nav-item.settings-nav-danger.is-active { background: rgba(176, 58, 46, 0.1); border-left-color: var(--danger); }
.settings-nav-count {
  padding: 0 6px; border-radius: 999px; background: rgba(43, 42, 40, 0.08);
  font-size: 11px; font-weight: 600; color: var(--ink-soft);
}

/* Panes are all visible until the script adds .js-panes — no JS means the
   old single-scroll page, not a blank one. */
.settings-panes > .settings-pane + .settings-pane {
  margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line);
}
.settings-panes.js-panes > .settings-pane { display: none; margin-top: 0; padding-top: 0; border-top: 0; }
.settings-panes.js-panes > .settings-pane.is-active { display: block; }

.settings-pane-title { font-size: 15px; margin-bottom: 6px; }
.settings-pane-danger { color: var(--danger); }
.settings-card .settings-hint { font-size: 13px; color: var(--ink-soft); margin: 0 0 12px; }
.settings-card .settings-hint:last-child { margin-bottom: 0; }
.settings-card .settings-status {
  font-size: 13px; color: var(--ink-soft); margin: 0 0 14px;
  padding: 10px 12px; border-radius: var(--radius); background: rgba(43, 42, 40, 0.04);
}
.settings-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.settings-block:first-of-type { margin-top: 16px; }
.settings-block-title { font-size: 13px; margin-bottom: 4px; }
.settings-note { font-size: 12px; color: var(--ink-soft); }
.settings-optional { opacity: 0.7; }

.settings-form { display: flex; flex-direction: column; gap: 0.8em; }
.settings-field { display: block; font-size: 13px; color: var(--ink-soft); }
.settings-check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.settings-input {
  width: 100%; margin-top: 4px; padding: 8px;
  border: 1px solid #d6d3cc; border-radius: var(--radius);
  font-family: inherit; font-size: 14px; background: var(--surface); color: var(--ink);
}
.settings-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.settings-row { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.settings-row-tight { gap: 8px; margin-top: 6px; }
.settings-grow { flex: 1; min-width: 0; }
.settings-nowrap { white-space: nowrap; }
.settings-mini { font-size: 12px; padding: 2px 8px; }
.settings-actions { display: flex; gap: 0.5em; justify-content: flex-end; margin-top: 12px; }
.settings-dialog-title { font-size: 16px; margin: 0; }

/* ---- settings: signed-in devices ---- */
/* The pane is wide now, so a row puts its detail on the left and its action on
   the right instead of stacking the button underneath. */
.sessions-tools {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 6px;
}
.sessions-filters { display: flex; gap: 4px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink-soft);
  font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer;
}
.chip-btn:hover { background: rgba(43, 42, 40, 0.05); color: var(--ink); }
.chip-btn.is-on { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.chip-count { font-size: 11px; opacity: 0.75; }

.sessions-list { list-style: none; margin: 0; padding: 0; }
.sessions-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid #e3e1dc;
}
.sessions-row[hidden] { display: none; }
.sessions-row:last-child { border-bottom: 0; }
.sessions-info { min-width: 0; }
.sessions-main { display: flex; align-items: center; font-size: 14px; }
.sessions-device { font-weight: 500; }
.sessions-meta {
  font-size: 12px; color: var(--ink-soft); margin-top: 2px; word-break: break-word;
}
.sessions-actions { flex-shrink: 0; }
.sessions-actions .ghost-btn { padding: 4px 10px; font-size: 12px; }
.settings-card .sessions-empty { font-size: 13px; color: var(--ink-soft); margin: 0; padding: 12px 0; }

/* Below the rail's width, the nav becomes a horizontal strip above the pane
   and a device row goes back to stacking its action underneath. */
@media (max-width: 720px) {
  .settings-card { padding: 20px 18px 24px; }
  .settings-body { grid-template-columns: 1fr; gap: 18px; }
  .settings-nav {
    flex-direction: row; flex-wrap: wrap; gap: 6px;
    padding-bottom: 14px; border-bottom: 1px solid var(--line);
  }
  .settings-nav-item { border-left: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; }
  .settings-nav-item.is-active { border-color: transparent; }
  .sessions-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .sessions-actions { display: flex; justify-content: flex-end; }
}
