:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --inbox-bg: #f1f5f9;
  --drop-highlight: #dbeafe;
  --chrome: #fafafa;
  --header: #ffffff;
  --chrome-bar-height: 36px;
}

html[data-theme="dark"] {
  --bg: #000000;
  --panel: #111111;
  --border: #3f3f46;
  --text: #ffffff;
  --text-muted: #a1a1aa;
  --accent: #93c5fd;
  --accent-bg: #1c1c1f;
  --inbox-bg: #171717;
  --drop-highlight: #27272a;
  --chrome: #3f3f46;
  --header: #3f3f46;
}

html[data-theme="beige"] {
  --bg: #f3e6d4;
  --panel: #faf3e8;
  --border: #d4c4a8;
  --text: #3d2e1e;
  --text-muted: #7a6850;
  --accent: #8b5e34;
  --accent-bg: #efe0c8;
  --inbox-bg: #efe0c8;
  --drop-highlight: #ead7b8;
  --chrome: #e8d9c0;
  --header: #efe4d0;
}

html[data-theme="tiffany"] {
  --bg: #dcefee;
  --panel: #f3fffe;
  --border: #7ec8c3;
  --text: #0f3d3a;
  --text-muted: #4a7a76;
  --accent: #0abab5;
  --accent-bg: #c5ebe8;
  --inbox-bg: #cfe8e6;
  --drop-highlight: #b8e4e0;
  --chrome: #b8e8e4;
  --header: #c5ebe8;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header.app-header {
  min-height: var(--chrome-bar-height, 36px);
  background: var(--header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  position: relative;
  z-index: 100;
}

.header-scroll {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--chrome-bar-height, 36px);
  padding: 2px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  min-width: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  font-weight: 600;
  font-size: 13px;
  cursor: grab;
  user-select: none;
  touch-action: pan-x;
}

.header-scroll::-webkit-scrollbar {
  display: none;
}

.header-scroll.toolbar-grabbing {
  cursor: grabbing;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.theme-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.theme-picker select { font-weight: 500; }

.brand-home {
  color: inherit;
  text-decoration: none;
}
.brand-home:hover { text-decoration: underline; }

.app-version {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  vertical-align: middle;
}

.login-title .app-version {
  margin-left: 6px;
  font-size: 13px;
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.header-fetch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 200px;
  max-width: 560px;
}

.header-fetch-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.header-fetch-input {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: inherit;
  font-size: 13px;
}

.header-fetch-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

.panel-menu {
  position: relative;
}

.panel-menu-trigger { font-weight: 500; }

.panel-menu-dropdown {
  position: fixed;
  top: auto;
  right: auto;
  min-width: 200px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  z-index: 3000;
}

.panel-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 400;
  border-radius: 4px;
  cursor: pointer;
}

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

.panel-menu-item input { cursor: pointer; }

.workbench-panel.panel-hidden { display: none; }
.workbench-panel[data-panel-id="editor"] { z-index: 1; }
.workbench-panel:not([data-panel-id="editor"]) { z-index: 5; }
.workbench-panel#panel-chat:not(.panel-hidden) { z-index: 6; }

.workbench-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.workbench-panel {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
  min-width: 180px;
  min-height: 120px;
  overflow: hidden;
  z-index: 1;
}

.workbench-panel.panel-moving { z-index: 20; opacity: 0.92; }
.workbench-panel.panel-resizing { z-index: 15; }

.panel-chrome {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  min-height: 28px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--chrome);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.panel-chrome:active { cursor: grabbing; }

.panel-drag-handle {
  color: #94a3b8;
  font-size: 14px;
  line-height: 1;
  letter-spacing: -2px;
}

.panel-title { flex: 1; }

.panel-chrome .panel-action-btn {
  margin-left: auto;
  flex: 0 0 auto;
  text-transform: none;
  letter-spacing: 0;
}

.panel-content {
  flex: 1;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-content.editor-pane,
.panel-content.chat-pane { overflow: hidden; }

.pane-header {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--chrome);
  flex-shrink: 0;
}

.resize-handle {
  position: absolute;
  z-index: 5;
}

.resize-e {
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
}

.resize-s {
  left: 0;
  bottom: -3px;
  width: 100%;
  height: 6px;
  cursor: ns-resize;
}

.resize-se {
  right: -3px;
  bottom: -3px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}

/* --- Inbox --- */
.inbox-pane {
  background: var(--inbox-bg);
  overflow: hidden;
}

.clip-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.clip-form input,
.clip-form textarea {
  font: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
}

.clip-form textarea { min-height: 56px; resize: vertical; }
.clip-form button:disabled { opacity: 0.65; cursor: wait; }

.drop-zone {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
}

.drop-zone.drag-over {
  background: var(--drop-highlight);
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

.drop-zone-label {
  display: none;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-bg);
  border-bottom: 1px solid var(--border);
}

.drop-zone.drag-over .drop-zone-label { display: block; }

#inbox-container { min-height: 100px; }

.inbox-trash {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  max-height: 45%;
  display: flex;
  flex-direction: column;
  min-height: 36px;
}

.inbox-trash.drag-over {
  background: var(--drop-highlight);
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

.inbox-trash.drag-over .trash-drop-label { display: block; }

.trash-drop-label {
  display: none;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-bg);
}

.inbox-trash-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  flex-shrink: 0;
}

.inbox-trash-toggle {
  flex: 1;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}

.inbox-trash-toggle:hover { background: var(--panel); border-radius: 4px; }

#trash-container {
  overflow: auto;
  min-height: 48px;
  border-top: 1px solid var(--border);
}

#trash-container[hidden] { display: none; }

.clip-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin: 10px;
  cursor: grab;
}

.clip-card:active { cursor: grabbing; }
.clip-card.selected { border-color: var(--accent); background: var(--accent-bg); }
.clip-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; pointer-events: none; }
.clip-snippet {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  pointer-events: none;
}
.clip-badge {
  display: inline-block;
  font-size: 10px;
  background: #e2e8f0;
  color: #475569;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 6px;
  pointer-events: none;
}

/* --- Folder pane --- */
.folder-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
  touch-action: pan-x pan-y;
}

.folder-pane .folder-root-zone,
.folder-pane .folder-root-docs,
.folder-pane .folder-tree {
  min-width: max-content;
}

.folder-control {
  margin: 8px 8px 4px;
  padding: 8px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-shrink: 0;
}

.folder-control legend {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 4px;
}

.folder-control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.folder-root-zone {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 4px;
  margin: 2px 8px;
  min-height: 28px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
  flex-shrink: 0;
}

/* Same shading as a hovered target folder — only while it is the actual drop target */
.folder-root-zone.drag-active,
.folder-root-zone.drag-over {
  background: var(--accent-bg);
}

.folder-root-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  font-weight: 600;
  cursor: default;
}

.folder-root-row.active {
  background: var(--accent-bg);
  color: var(--accent);
}

.folder-root-zone .folder-icon {
  flex-shrink: 0;
  font-size: 12px;
}

.folder-root-zone .folder-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-root-docs {
  list-style: none;
  margin: 0 8px 6px 20px;
  padding: 0;
}

.folder-pane.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

.folder-node,
.doc-node { list-style: none; }

/* Nested indentation: every level of children shifts right */
.folder-children {
  list-style: none;
  padding-left: 20px;
}

.folder-node.collapsed > .folder-children { display: none; }

/* During a drag, reveal every level so any depth can be a drop target */
.folder-tree.dragging-all-open .folder-node > .folder-children { display: block; }

.folder-row,
.tree-doc-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 4px;
  margin: 2px 6px;
  min-height: 28px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
}

.folder-row:hover,
.tree-doc-row:hover { background: var(--bg); }

/* Selected folder: subtle, for Folder control targeting */
.folder-row.active {
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--border);
  font-weight: 600;
}

/* Open document: the single strong highlight */
.tree-doc-row.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

/* Single, clear highlight for external (chip) drops */
.folder-row.drag-over,
.tree-doc-row.drag-over {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-bg);
}

.tree-doc-row { font-size: 12px; color: var(--text-muted); }
.tree-doc-row .doc-icon { font-size: 11px; flex-shrink: 0; }

/* Documents sit deeper than subfolders: align under the parent folder's name */
.doc-node > .tree-doc-row { margin-left: 22px; }

/* Icons double as drag grips */
.folder-icon.drag-handle,
.doc-icon.drag-handle {
  flex-shrink: 0;
  font-size: 12px;
  cursor: grab;
  user-select: none;
  border-radius: 3px;
  padding: 2px;
}

.folder-icon.drag-handle:hover,
.doc-icon.drag-handle:hover { background: var(--border); }

.folder-icon.drag-handle:active,
.doc-icon.drag-handle:active { cursor: grabbing; }

.folder-toggle {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.folder-toggle.placeholder { visibility: hidden; }

.folder-icon { flex-shrink: 0; font-size: 12px; }

.folder-name,
.tree-doc-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-hide-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-left: 2px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
}

.folder-row:hover .folder-hide-btn,
.folder-row.active .folder-hide-btn {
  opacity: 1;
}

.folder-hide-btn:hover {
  background: var(--border);
  color: var(--text);
}

.tree-hint {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-muted);
  list-style: none;
}

/* Reorder vs nest: top/bottom edge lines vs middle highlight */
.folder-row.reorder-before {
  box-shadow: inset 0 2px 0 0 var(--accent);
}

.folder-row.reorder-after {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

/* Hover-nest indicator (middle zone of a folder row) */
.folder-row.nest-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-bg);
}

.folder-row.nest-target-invalid {
  outline: 2px solid #dc2626;
  outline-offset: -2px;
  background: #fef2f2;
}

/* SortableJS drag feedback: invisible placeholder — the gap shows the landing spot, no blue line */
.sortable-chosen { background: transparent; }

.sortable-ghost { opacity: 0; }

.sortable-ghost > .folder-children { display: none; }

.sortable-ghost > .folder-row,
.sortable-ghost > .tree-doc-row {
  height: 0;
  min-height: 0;
  padding: 0;
  margin: 0 6px;
  border: none;
  overflow: hidden;
  background: transparent;
}

.clip-card.sortable-ghost {
  height: 4px;
  min-height: 4px;
  padding: 0;
  border: none;
  background: transparent;
}

/* --- Editor --- */
.editor-pane {
  background: var(--bg);
  padding: 12px;
  overflow: hidden;
  min-height: 0;
}

.canvas {
  width: 100%;
  max-width: 100%;
  margin: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-pane {
  background: var(--panel);
  padding: 0;
}

.chat-reply-lang {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.chat-reply-lang-label {
  color: var(--text-muted);
  margin-right: 2px;
}

.chat-lang-btn {
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.chat-lang-btn.active {
  background: var(--accent-bg);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
}

.chat-lang-btn:hover:not(.active) {
  background: color-mix(in srgb, var(--border) 35%, var(--panel));
  color: var(--text);
}

.editor-chat-messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-bubble {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent-bg);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}

.chat-bubble.error {
  align-self: stretch;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.chat-bubble-actions {
  margin-top: 6px;
}

.editor-chat-form {
  display: flex;
  gap: 6px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.editor-chat-form textarea {
  flex: 1;
  resize: vertical;
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 64px;
  max-height: 40vh;
}

.editor-chat-hint {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 8px;
}

.editor-sticky {
  flex-shrink: 0;
  padding-bottom: 2px;
}

.editor-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-muted) 38%, var(--border))
    color-mix(in srgb, var(--border) 40%, transparent);
}

.editor-scroll::-webkit-scrollbar {
  width: 8px;
}

.editor-scroll::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--border) 40%, transparent);
  border-left: 1px solid var(--border);
}

.editor-scroll::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-muted) 38%, var(--border));
  border-radius: 3px;
}

.editor-scroll::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-muted) 55%, var(--border));
}

#panel-editor > .panel-chrome {
  flex-wrap: nowrap;
  cursor: default;
}

#panel-editor > .panel-chrome .panel-title {
  flex: 0 0 auto;
  cursor: grab;
}

#panel-editor > .panel-chrome .panel-drag-handle {
  cursor: grab;
}

.editor-toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  touch-action: pan-x;
}

.editor-toolbar.toolbar-grabbing {
  cursor: grabbing;
}

.toolbar-icon-btn {
  min-width: 32px;
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1.2;
}

.editor-toolbar::-webkit-scrollbar { display: none; }

.editor-toolbar > * { flex-shrink: 0; }

.app-header,
.workbench-panel:not(#panel-editor),
#panel-editor > .panel-chrome,
.modal-overlay,
.editor-context-menu {
  zoom: var(--chrome-zoom, 1);
}

.editor-pane {
  zoom: var(--page-zoom, 1);
}

.block-menu { position: relative; }

.block-menu-dropdown {
  position: fixed;
  min-width: 160px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  z-index: 200;
}

.block-menu-item {
  display: block;
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  background: none;
  border: none;
  border-radius: 4px;
  color: inherit;
  cursor: pointer;
}

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

.block-menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

.vault-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}

.vault-title-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.vault-title-btn:hover { filter: brightness(0.92); }

.vault-title-btn-muted {
  color: var(--text-muted);
  font-weight: 500;
}

.editor-block.vault-body-locked {
  display: none;
}

.block-shell.vault-block.vault-locked .block-trash-btn {
  visibility: hidden;
  pointer-events: none;
}

.vault-modal-card { width: min(440px, 100%); }

.vault-modal-warning {
  color: #b45309;
  font-size: 13px;
  line-height: 1.45;
}

html[data-theme="dark"] .vault-modal-warning { color: #fbbf24; }

.vault-modal-hint-display {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.vault-modal-error {
  display: block;
  margin-top: 4px;
  color: #b91c1c;
}

html[data-theme="dark"] .vault-modal-error { color: #f87171; }

.toolbar-select {
  padding: 4px 6px;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
}

.toolbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
}

.highlight-swatches {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 0 2px;
}

.hl-swatch {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.hl-swatch.hl-yellow { background: #fef08a; }
.hl-swatch.hl-green { background: #bbf7d0; }
.hl-swatch.hl-blue { background: #bfdbfe; }
.hl-swatch.hl-pink { background: #fbcfe8; }

.doc-title-input {
  font-size: 20px;
  font-weight: 700;
  border: none;
  background: transparent;
  width: 100%;
  outline: none;
  margin-bottom: 8px;
  padding: 2px 0;
  color: inherit;
}

.block-list { min-height: 200px; padding-bottom: 48px; }

.page-stamps {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 2px 0 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.page-stamps[hidden] { display: none; }

.block-shell {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
  scroll-margin-block: 12px 48px;
  position: relative;
}

.block-gutter {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: auto;
  height: 1.6em;
  margin-top: 8px;
  flex-shrink: 0;
  user-select: none;
}

.block-shell.collapsed .block-gutter {
  margin-top: 4px;
}

.block-handle {
  color: #94a3b8;
  font-size: 12px;
  line-height: 1;
  letter-spacing: -2px;
  cursor: grab;
  padding: 0 1px;
}

.block-handle:active { cursor: grabbing; }

.block-fold,
.block-trash-btn {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

.block-trash-btn {
  align-self: flex-start;
  margin-top: 8px;
}

.block-shell.collapsed .block-trash-btn {
  margin-top: 4px;
}

.block-fold:hover,
.block-trash-btn:hover { background: var(--border); color: var(--text); }

.block-shell.trashed .block-trash-btn { display: none; }

.block-shell.dragging { opacity: 0.4; }
.block-shell.drop-before { box-shadow: inset 0 2px 0 0 var(--accent); }
.block-shell.drop-after { box-shadow: inset 0 -2px 0 0 var(--accent); }

.block-shell.collapsed .editor-block {
  min-height: 0;
  max-height: var(--collapsed-block-max, 40px);
  padding-top: var(--collapsed-preview-pad, 6px);
  padding-bottom: var(--collapsed-preview-pad, 6px);
  overflow: hidden;
  opacity: 0.85;
  cursor: pointer;
  box-sizing: border-box;
}

.block-shell.collapsed .editor-block > * {
  display: none;
}

.block-shell.collapsed .editor-block > :first-child {
  display: block;
  margin: 0 !important;
  padding: 0 !important;
  max-height: none;
  line-height: var(--collapsed-preview-line-height, 1.25);
  font-size: var(--collapsed-preview-size, inherit);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.block-trash {
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.block-trash.drag-over { background: var(--accent-bg); border-color: var(--accent); }

.block-trash-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
}

#block-trash-list {
  padding: 4px 6px 8px;
  border-top: 1px solid var(--border);
}

#block-trash-list[hidden] { display: none; }

.block-content-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.block-content-wrap > .editor-block {
  width: 100%;
  box-sizing: border-box;
}

.block-shell.has-custom-height:not(.has-image-block):not(:has(.table-block)):not(:has(.spreadsheet-block))
  .block-content-wrap > .editor-block {
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-muted) 38%, var(--border)) transparent;
}

.block-shell.has-custom-height:not(.has-image-block):not(:has(.table-block)):not(:has(.spreadsheet-block))
  .block-content-wrap > .editor-block::-webkit-scrollbar {
  width: 6px;
}

.block-shell.has-custom-height:not(.has-image-block):not(:has(.table-block)):not(:has(.spreadsheet-block))
  .block-content-wrap > .editor-block::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-muted) 38%, var(--border));
  border-radius: 3px;
}

.block-shell.has-image-block.has-custom-height .block-content-wrap > .editor-block.image-fit-block {
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
}

.block-shell.has-image-block.has-custom-height .block-content-wrap > .editor-block.image-fit-block img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  margin: 0;
}

.editor-block {
  padding: 8px 16px 8px 12px;
  margin-bottom: 0;
  min-width: 0;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid transparent;
  min-height: 32px;
  outline: none;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.editor-block.table-block {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 4px 0;
  cursor: default;
  user-select: auto;
  -webkit-user-select: auto;
}

.editor-block.table-block:focus {
  border-color: transparent;
  box-shadow: none;
}

.editor-block:focus { border-color: var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

.block-shell:has(.table-block):not(.has-custom-width) {
  width: 100%;
  max-width: 100%;
}

.block-shell:has(.table-block) .block-gutter {
  align-self: flex-start;
}

.block-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  margin-bottom: 8px;
}

.block-row > .block-shell {
  margin-bottom: 0;
  min-width: 0;
}

.block-shell:has(.table-block),
.block-shell:has(.spreadsheet-block) {
  position: relative;
}

.block-shell.has-custom-width {
  max-width: 100%;
}

.block-content-wrap > .block-size-resize {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  z-index: 2;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.block-content-wrap > .block-size-resize::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 8px 8px;
  border-color: transparent transparent color-mix(in srgb, var(--text-muted) 65%, transparent) transparent;
  opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.block-shell:hover .block-content-wrap > .block-size-resize::after,
.block-shell:focus-within .block-content-wrap > .block-size-resize::after,
.block-content-wrap > .block-size-resize:hover::after {
  opacity: 1;
  border-bottom-color: var(--accent);
}

.block-shell.collapsed .block-content-wrap > .block-size-resize {
  display: none;
}

body.is-block-resizing {
  user-select: none;
  cursor: nwse-resize !important;
}

body.is-block-resizing * {
  cursor: nwse-resize !important;
}

.block-shell.is-resizing .block-content-wrap > .editor-block {
  overflow: hidden;
}

.block-shell.is-resizing .block-content-wrap > .block-size-resize::after {
  display: none;
}

.block-shell.is-resizing .block-content-wrap > .block-size-resize {
  width: 1px;
  height: 1px;
  opacity: 0;
}

.block-shell.drop-left { box-shadow: inset 3px 0 0 0 var(--accent); }
.block-shell.drop-right { box-shadow: inset -3px 0 0 0 var(--accent); }

.editor-block.spreadsheet-block {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 4px 0;
  cursor: default;
  user-select: auto;
  -webkit-user-select: auto;
}

.editor-block.spreadsheet-block:focus {
  border-color: transparent;
  box-shadow: none;
}

.block-shell:has(.spreadsheet-block):not(.has-custom-width) {
  width: 100%;
  max-width: 100%;
}

.block-shell:has(.spreadsheet-block) .block-gutter {
  align-self: flex-start;
}

.spreadsheet-block-shell {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--border) 88%, var(--accent) 12%);
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, var(--panel) 0%, color-mix(in srgb, var(--panel) 92%, var(--bg) 8%) 100%);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.04),
    0 8px 24px rgba(15, 23, 42, 0.04);
}

.spreadsheet-header {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
}

.spreadsheet-header .grid-height-controls {
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.spreadsheet-header-edit {
  flex: 1;
  min-width: 0;
  padding: 4px 12px;
  outline: none;
  min-height: 26px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text);
}

.spreadsheet-header-edit:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-weight: 500;
}

.spreadsheet-header.is-active,
.spreadsheet-footer.is-active {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: -2px;
}

.spreadsheet-host {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background: transparent;
}

.spreadsheet-footer {
  padding: 4px 12px;
  outline: none;
  min-height: 26px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text);
  border-top: 1px solid var(--border);
  background: transparent;
}

.spreadsheet-footer:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

.spreadsheet-host.tabulator {
  font-size: 13px;
  line-height: 1.35;
  border: none;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--panel);
  color: var(--text);
}

.spreadsheet-host.tabulator .tabulator-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 400;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col {
  border-right: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  min-height: 0;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col.tabulator-range-row-header,
.spreadsheet-host.tabulator .tabulator-header .tabulator-col.spreadsheet-col-num-group,
.spreadsheet-host.tabulator .tabulator-header .tabulator-col .tabulator-col {
  background: var(--panel);
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col-group-cols .tabulator-col {
  background: color-mix(in srgb, var(--inbox-bg) 70%, var(--panel) 30%);
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col.tabulator-col-group .tabulator-col-group-cols {
  border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
  padding: 1px 4px;
  min-height: 0;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col.tabulator-sortable .tabulator-col-title {
  padding-right: 14px;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col .tabulator-header-filter {
  margin-top: 0;
  padding: 0;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input {
  font-size: 8px;
  line-height: 1;
  padding: 0 3px;
  min-height: 0;
  height: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  border-radius: 2px;
  background: var(--panel);
  color: var(--text);
  box-shadow: none;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--border) 85%, transparent);
  box-shadow: none;
}

.spreadsheet-host.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input::placeholder {
  font-size: 8px;
  color: var(--text-muted);
}

.spreadsheet-host.tabulator .tabulator-tableholder {
  overflow-y: auto;
  overflow-x: auto;
  background: var(--panel);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-muted) 38%, var(--border)) transparent;
}

.spreadsheet-host.tabulator .tabulator-tableholder::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.spreadsheet-host.tabulator .tabulator-tableholder::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-muted) 38%, var(--border));
  border-radius: 3px;
}

.spreadsheet-host.tabulator .tabulator-tableholder::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-muted) 55%, var(--border));
}

.spreadsheet-host.tabulator .tabulator-row .tabulator-cell[tabulator-field="__row"] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--panel);
  user-select: none;
  cursor: default;
  padding: 5px 6px;
}

.spreadsheet-host.tabulator .tabulator-row.tabulator-row-even .tabulator-cell[tabulator-field="__row"] {
  background: color-mix(in srgb, var(--inbox-bg) 70%, var(--panel) 30%);
}

.spreadsheet-host .tabulator-col {
  min-width: 0;
}

.spreadsheet-host .tabulator-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  vertical-align: top;
}

.spreadsheet-host.tabulator .tabulator-row .tabulator-cell:not([tabulator-field="__row"]) {
  background: var(--panel);
}

.spreadsheet-host .spreadsheet-col-num {
  text-align: center;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  user-select: none;
  padding: 0;
  line-height: 1.2;
}

.spreadsheet-host .spreadsheet-col-num-group .tabulator-col-sorter {
  display: none;
}

.spreadsheet-host .spreadsheet-col-header-edit {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 0;
  padding: 0;
  outline: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
  color: var(--text-muted);
}

.spreadsheet-host .spreadsheet-col-header-edit:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-weight: 600;
}

.spreadsheet-host.tabulator .tabulator-row.tabulator-row-even .tabulator-cell:not([tabulator-field="__row"]) {
  background: color-mix(in srgb, var(--inbox-bg) 70%, var(--panel) 30%);
}

.spreadsheet-host.tabulator .tabulator-range-overlay {
  display: none !important;
}

.spreadsheet-host .tabulator-cell.spreadsheet-cell-selected {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--accent);
  background: color-mix(in srgb, var(--accent-bg) 88%, var(--panel) 12%) !important;
}

.spreadsheet-host .tabulator-cell.tabulator-editing {
  border-color: transparent;
  padding: 5px 8px;
}

.spreadsheet-host .tabulator-cell.spreadsheet-cell-selected.tabulator-editing {
  box-shadow: inset 0 0 0 1px var(--accent);
  border-color: transparent;
}

.spreadsheet-host.tabulator:focus {
  outline: none;
}

.editor-block.drop-target { border: 2px dashed var(--accent) !important; background: var(--accent-bg); }

.editor-block ul,
.editor-block ol {
  margin: 0.4em 0;
  padding-left: 1.75em;
}

.editor-block ul { list-style: disc; }
.editor-block ol { list-style: decimal; }
.editor-block ul ul { list-style: circle; }
.editor-block li { margin: 0.15em 0; }

.editor-block p,
.editor-block div,
.editor-block h1,
.editor-block h2,
.editor-block h3,
.editor-block h4,
.editor-block h5,
.editor-block h6 {
  margin-left: 0 !important;
  text-indent: 0 !important;
}

.editor-block table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

.editor-block th,
.editor-block td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.editor-block th {
  background: var(--bg);
  font-weight: 600;
}

.editor-block caption {
  caption-side: top;
  text-align: left;
  font-size: 12px;
  color: var(--text-muted);
  padding-bottom: 6px;
}

.editor-block img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 8px 0;
  border-radius: 4px;
}

.editor-block h1 { font-size: 1.6em; margin: 8px 0 6px; }
.editor-block h2 { font-size: 1.3em; margin: 8px 0 6px; }
.editor-block h3 { font-size: 1.1em; margin: 8px 0 6px; }
.editor-block h4 { font-size: 1em; margin: 8px 0 6px; }
.editor-block h5 { font-size: 0.92em; margin: 8px 0 6px; }
.editor-block h6 { font-size: 0.85em; margin: 8px 0 6px; color: var(--text-muted); }

.editor-block blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 0 6px 6px 0;
}

.editor-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.editor-block pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  white-space: pre-wrap;
}

.editor-block .text-size-sm { font-size: 0.85em; }
.editor-block .text-size-lg { font-size: 1.25em; }

.editor-block .text-hl-yellow { background: #fef08a; }
.editor-block .text-hl-green { background: #bbf7d0; }
.editor-block .text-hl-blue { background: #bfdbfe; }
.editor-block .text-hl-pink { background: #fbcfe8; }

.editor-block hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.editor-block a {
  color: var(--accent);
  text-decoration: underline;
}

.grid-table-shell {
  width: 100%;
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--border) 88%, var(--accent) 12%);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel) 0%, color-mix(in srgb, var(--panel) 92%, var(--bg) 8%) 100%);
  overflow: hidden;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.04),
    0 8px 24px rgba(15, 23, 42, 0.04);
}

.grid-toolbar {
  display: none;
}

.grid-caption {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.grid-caption-edit {
  flex: 1;
  min-width: 0;
  padding: 4px 12px;
  outline: none;
  min-height: 26px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text);
}

.grid-caption-edit:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

.grid-height-controls {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.grid-height-btn {
  flex: 1;
  width: 22px;
  min-height: 13px;
  border: none;
  background: var(--panel);
  color: var(--text-muted);
  font-size: 9px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.grid-height-btn:hover:not(:disabled) {
  background: var(--inbox-bg);
  color: var(--text);
}

.grid-height-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.grid-footer {
  padding: 4px 12px;
  outline: none;
  min-height: 26px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text);
  border-top: 1px solid var(--border);
}

.grid-footer:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

.grid-caption.is-active,
.grid-footer.is-active {
  background: color-mix(in srgb, var(--accent-bg) 55%, var(--panel) 45%);
}

.grid-wrap {
  display: flex;
  align-items: stretch;
  position: relative;
}

.grid-scroller {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-muted) 38%, var(--border)) transparent;
}

.grid-scroller::-webkit-scrollbar {
  width: 0;
  height: 8px;
}

.grid-scroller::-webkit-scrollbar:vertical {
  width: 0;
  display: none;
}

.grid-scroller::-webkit-scrollbar:horizontal {
  height: 8px;
}

.grid-scroller::-webkit-scrollbar-thumb:horizontal {
  background: color-mix(in srgb, var(--text-muted) 38%, var(--border));
  border-radius: 3px;
}

.grid-scroller::-webkit-scrollbar-thumb:horizontal:hover {
  background: color-mix(in srgb, var(--text-muted) 55%, var(--border));
}

.grid-vscroll {
  width: 8px;
  flex-shrink: 0;
  position: relative;
  background: color-mix(in srgb, var(--border) 40%, transparent);
  border-left: 1px solid var(--border);
}

.grid-vscroll.is-hidden {
  display: none;
}

.grid-vscroll-thumb {
  position: absolute;
  left: 1px;
  right: 1px;
  top: 0;
  min-height: 20px;
  background: color-mix(in srgb, var(--text-muted) 38%, var(--border));
  border-radius: 3px;
  cursor: pointer;
}

.grid-vscroll-thumb:hover {
  background: color-mix(in srgb, var(--text-muted) 55%, var(--border));
}

body.is-col-resizing { cursor: col-resize; user-select: none; }
body.is-grid-panning { cursor: grabbing; user-select: none; }

.grid-table-shell table.grid {
  width: auto;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: max-content;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
}

.grid-table-shell thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--bg) 82%, var(--panel) 18%);
  border-bottom: 1px solid var(--border);
  padding: 5px 8px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.grid-table-shell thead th[aria-sort="ascending"]::after {
  content: " ↑";
  color: var(--accent);
}

.grid-table-shell thead th[aria-sort="descending"]::after {
  content: " ↓";
  color: var(--accent);
}

.grid-table-shell thead th .col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}

.grid-table-shell tbody td {
  padding: 5px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  vertical-align: top;
  background: var(--panel);
  cursor: default;
}

.grid-table-shell tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--inbox-bg) 70%, var(--panel) 30%);
}

.grid-table-shell tbody tr:hover td {
  background: color-mix(in srgb, var(--accent-bg) 82%, var(--panel) 18%);
}

.grid-table-shell tbody td.is-selected {
  background: color-mix(in srgb, var(--accent-bg) 90%, var(--panel) 10%) !important;
}

.grid-table-shell table.grid:focus { outline: none; }

.grid-table-shell .name { font-weight: 600; }

.grid-table-shell .notes {
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.grid-table-shell .mono {
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 13px;
}

.grid-table-shell .right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.grid-table-shell .pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.grid-table-shell .pill.open { background: #ece4d4; color: #5b5043; }
.grid-table-shell .pill.doing { background: #f3e2c0; color: #9a6b12; }
.grid-table-shell .pill.done { background: #d8eedc; color: #2f7d4a; }

.grid-table-shell td.is-editing,
.grid-table-shell th.is-editing {
  padding: 6px 8px !important;
  background: var(--panel) !important;
}

.grid-table-shell .cell-editor {
  width: 100%;
  display: block;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 6px 8px;
  outline: none;
  resize: none;
  box-sizing: border-box;
}

.grid-table-shell textarea.cell-editor {
  min-height: 72px;
  line-height: 1.45;
}

.grid-table-shell .edit-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.grid-table-menu {
  position: fixed;
  z-index: 120;
  min-width: 168px;
  padding: 4px;
  font-size: 12px;
  line-height: 1.3;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  display: none;
}

.grid-table-menu.open { display: block; }

.grid-table-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
  cursor: pointer;
}

.grid-table-menu button:hover {
  background: color-mix(in srgb, var(--accent-bg) 70%, var(--panel) 30%);
}

.grid-table-menu button.danger { color: #9a2e1a; }

.grid-table-menu hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 3px 4px;
}

.grid-table-menu-meta {
  padding: 3px 8px 4px;
  font-size: 10px;
  line-height: 1.25;
  color: var(--text-muted);
}

.grid-table-menu.has-block-section hr[data-scope="block"] {
  margin: 2px 4px;
}

.grid-table-menu.has-block-section button[data-scope="block"] {
  padding: 2px 8px;
  font-size: 11px;
  line-height: 1.2;
}

.grid-table-menu button:disabled {
  opacity: 0.45;
  cursor: default;
}

.grid-table-menu button:disabled:hover {
  background: transparent;
}

.editor-block.table-block {
  padding: 0;
  border: none;
  background: transparent;
}

.fetch-report-block {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--inbox-bg);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}

.fetch-report-block.ok { border-color: #86efac; background: #f0fdf4; }
.fetch-report-block.warn { border-color: #fcd34d; background: #fffbeb; }
.fetch-report-block.err { border-color: #fca5a5; background: #fef2f2; }

html[data-theme="dark"] .fetch-report-block.ok { background: #14532d; }
html[data-theme="dark"] .fetch-report-block.warn { background: #78350f; }
html[data-theme="dark"] .fetch-report-block.err { background: #7f1d1d; }

.fetch-report-block ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.fetch-report-block p { margin: 0; }

.import-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-bg);
  font-size: 12px;
  color: var(--text-muted);
}

.import-bar[hidden] { display: none; }

.import-bar-status { flex: 1; min-width: 140px; color: var(--text); }

.import-bar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.import-skipped {
  list-style: none;
  width: 100%;
  margin: 4px 0 0;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  max-height: 120px;
  overflow: auto;
}

.import-skipped li { padding: 2px 0; }

.text-annotation {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  cursor: pointer;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.text-annotation:hover { background: #fde047; }

.editor-context-menu {
  position: fixed;
  z-index: 1100;
  min-width: 160px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.editor-context-menu[hidden] { display: none; }

.editor-context-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.editor-context-item:hover:not(:disabled) { background: var(--accent-bg); color: var(--accent); }

.editor-context-item:disabled {
  opacity: 0.45;
  cursor: default;
  color: var(--text-muted);
}

.folder-row.move-pending,
.tree-doc-row.move-pending {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  outline: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--border));
}

.linked-node-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #dcfce7;
  border: 1px solid #16a34a;
  color: #15803d;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  cursor: grab;
  margin: 0 2px;
  vertical-align: baseline;
}

.linked-node-chip:active { cursor: grabbing; }
.linked-node-chip.dragging { opacity: 0.45; }

.block-links-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 12px 8px 44px;
  border-top: 1px dashed var(--border);
  user-select: none;
  -webkit-user-select: none;
}

.block-links-footer[hidden] { display: none !important; }

.block-link-footer-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: #4338ca;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.block-link-footer-btn:hover { color: #3730a3; }

.block-link-footer-btn.is-deleted {
  color: #991b1b;
  text-decoration: none;
  cursor: not-allowed;
}

html[data-theme="dark"] .block-link-footer-btn { color: #a5b4fc; }

.block-shell.block-link-target-flash {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
  transition: outline-color 0.2s ease;
}

.editor-context-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

/* --- Context --- */
.context-pane { padding: 0; min-height: 0; }

.context-scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.scrapbook {
  flex: 0 0 auto;
  max-height: 42%;
  overflow: auto;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.scrapbook-body { padding: 10px 16px 16px; }

.scrapbook-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.4;
}

.scrapbook-actions { margin-bottom: 10px; }

.scrapbook-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scrapbook-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: var(--bg);
}

.scrapbook-item img {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--panel);
}

.scrapbook-item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.scrapbook.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }

.context-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--bg);
  margin: 16px;
}

.context-card h4 { font-size: 15px; margin-bottom: 8px; }
.context-card p { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; line-height: 1.5; }
.context-card a { font-size: 12px; color: var(--accent); }
.backlink-item { font-size: 12px; padding: 8px 0; border-top: 1px solid var(--border); }

.annotation-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.annotation-term {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.annotation-term:hover { background: var(--accent-bg); color: var(--accent); }

.annotation-term.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

/* --- Shared --- */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  flex-wrap: wrap;
}

.toolbar-btn {
  padding: 2px 7px;
  font-size: 12px;
  line-height: 1.3;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: inherit;
}

.toolbar-btn:hover { background: var(--bg); }
.toolbar-btn.active {
  background: var(--accent-bg);
  border-color: #bfdbfe;
}

a.toolbar-btn.sign-out,
button.toolbar-btn.sign-out {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-pill:empty { display: none; }

.empty-hint { padding: 16px; font-size: 12px; color: var(--text-muted); }

/* --- Image zoom viewer (no backdrop) --- */
.image-zoom-viewer {
  position: fixed;
  inset: 0;
  z-index: 1100;
  pointer-events: none;
}

.image-zoom-viewer[hidden] { display: none !important; }

.image-zoom-panel {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 960px);
  height: min(82vh, 720px);
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.image-zoom-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.image-zoom-close:hover { background: var(--bg); }

.image-zoom-stage {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: grab;
  padding: 44px 16px 16px;
}

.image-zoom-stage.is-dragging { cursor: grabbing; }

.image-zoom-img {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  will-change: transform;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.modal-title {
  font-size: 16px;
  margin-bottom: 10px;
}

.modal-message {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 14px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-muted);
}

.modal-field[hidden] {
  display: none;
}

.modal-field input {
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.modal-field-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-field-hint.duplicate {
  color: #dc2626;
}

.modal-field-hint[hidden] {
  display: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-confirm {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.modal-confirm:hover { filter: brightness(0.95); }

.modal-confirm.danger {
  background: #dc2626;
  border-color: #dc2626;
}

.library-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 4px 0 8px;
}

.library-tree {
  flex: 1;
  min-height: 80px;
  overflow: auto;
  padding: 0 8px 8px;
}

.library-tree .library-context-item {
  opacity: 0.72;
}

.library-tree .library-context-item .folder-name,
.library-tree .library-context-item .folder-icon {
  font-style: italic;
}

.library-tree .library-hidden-item .folder-name,
.library-tree .library-hidden-item .tree-doc-name {
  font-weight: 600;
}

@media (max-width: 900px) {
  :root {
    --chrome-bar-height: 32px;
  }

  .workbench-panel { min-width: 0; }

  .header-scroll {
    gap: 8px;
    padding: 1px 8px;
  }

  .header-fetch {
    min-width: 160px;
  }

  .panel-chrome {
    padding: 3px 6px;
    min-height: 24px;
    gap: 4px;
  }

  .toolbar-btn {
    padding: 1px 6px;
    font-size: 11px;
  }

  .toolbar-icon-btn {
    min-width: 28px;
    padding: 2px 6px;
    font-size: 14px;
  }

  .editor-toolbar {
    gap: 2px;
  }

  html[data-phone-portrait="1"] #panel-folders .folder-pane,
  html[data-phone-portrait="1"] #panel-inbox .panel-content,
  html[data-phone-portrait="1"] #panel-library .panel-content,
  html[data-phone-portrait="1"] #panel-chat .panel-content,
  html[data-phone-portrait="1"] #panel-context .panel-content {
    overflow-x: auto;
    overflow-y: auto;
    touch-action: pan-x pan-y;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  :root {
    --chrome-bar-height: 30px;
  }
}

#app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#app-shell[hidden] { display: none; }

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 2000;
  padding: 24px;
}

.login-overlay[hidden] { display: none; }

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.login-title {
  font-size: 22px;
  font-weight: 650;
}

.login-copy {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.45;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.login-field[hidden] {
  display: none;
}

.login-field input {
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.login-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#login-copy-pending {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#login-copy-pending[hidden] {
  display: none;
}

.login-error {
  font-size: 13px;
  color: #dc2626;
}

.install-panel {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.4);
}

.install-panel[hidden] { display: none; }

.install-panel-card {
  width: min(420px, 100%);
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.16);
}

.install-panel-card h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

.install-panel-card p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 14px;
}

.install-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

