:root {
  color-scheme: light dark;
  --bg-lt: #f6f7fb;
  --bg-dk: #0f1720;
  --panel-lt: #fafbff;
  --panel-dk: #111827;
  --navbar-bg-lt: #3f5d6f;
  --navbar-bg-dk: #0f1a24;
  --notes-bg-lt: #fff4e7;
  --notes-bg-dk: #1a222e;
  --editor-bg-lt: #fffcf8;
  --editor-bg-dk: #111926;
  --editor-inactive-bg-lt: #fffdf8;
  --editor-inactive-bg-dk: #0d141d;
  --navbar-text-lt: #e5e7eb;
  --navbar-text-dk: #dbe5f0;
  --border-lt: #d9deea;
  --border-dk: #2a3443;
  --text-lt: #1f2937;
  --text-dk: #e5e7eb;
  --muted-text-lt: #6b7280;
  --muted-text-dk: #94a3b8;
  --accent-lt: #5d7684;
  --accent-dk: #7ea3b6;
  --home-btn-bg-lt: #3c4a61;
  --home-btn-bg-dk: #243447;
  --home-btn-hover-lt: #2f3a4d;
  --home-btn-hover-dk: #1f2c3c;
  --login-label-lt: #4b5563;
  --login-label-dk: #9ca3af;
  --login-input-border-lt: #cbd5e1;
  --login-input-border-dk: #3b4b5d;
  --error-text-lt: #b91c1c;
  --error-text-dk: #fca5a5;
  --banner-bg-lt: #fee2e2;
  --banner-bg-dk: #3b1f24;
  --banner-text-lt: #7f1d1d;
  --banner-text-dk: #fecaca;
  --banner-border-lt: #fecaca;
  --banner-border-dk: #7f1d1d;
  --note-meta-text-lt: #5b6474;
  --note-meta-text-dk: #93a1b6;
  --sync-icon-lt: #667085;
  --sync-icon-dk: #94a3b8;
  --note-hover-bg-lt: #dee2e4;
  --note-hover-bg-dk: #253142;
  --note-tag-chip-bg-lt: #D0B28E;
  --note-tag-chip-bg-dk: #3a4752;
  --note-selected-bg-lt: #dee2e4;
  --note-selected-bg-dk: #2b3b4f;
  --progress-track-lt: #e2e9e5;
  --progress-track-dk: #334155;
  --progress-fill-lt: #64927b;
  --progress-fill-dk: #6bb89a;
  --table-border-lt: #cfd5e2;
  --table-border-dk: #334155;
  --table-cell-border-lt: #d8deea;
  --table-cell-border-dk: #3a475a;
  --table-header-bg-lt: #DEE2E4;
  --table-header-bg-dk: #243040;
  --checkbox-check-lt: #64927b;
  --checkbox-check-dk: #6bb89a;
  --checkbox-checked-border-lt: #b6c9bf;
  --checkbox-checked-border-dk: #5f8b76;
  --slash-hover-bg-lt: #eef2ff;
  --slash-hover-bg-dk: #25344a;

  --bg: var(--bg-lt);
  --panel: var(--panel-lt);
  --navbar-bg: var(--navbar-bg-lt);
  --notes-bg: var(--notes-bg-lt);
  --editor-bg: var(--editor-bg-lt);
  --editor-inactive-bg: var(--editor-inactive-bg-lt);
  --navbar-text: var(--navbar-text-lt);
  --border: var(--border-lt);
  --text: var(--text-lt);
  --muted-text: var(--muted-text-lt);
  --accent: var(--accent-lt);
  --home-btn-bg: var(--home-btn-bg-lt);
  --home-btn-hover: var(--home-btn-hover-lt);
  --login-label: var(--login-label-lt);
  --login-input-border: var(--login-input-border-lt);
  --error-text: var(--error-text-lt);
  --banner-bg: var(--banner-bg-lt);
  --banner-text: var(--banner-text-lt);
  --banner-border: var(--banner-border-lt);
  --note-meta-text: var(--note-meta-text-lt);
  --sync-icon: var(--sync-icon-lt);
  --note-hover-bg: var(--note-hover-bg-lt);
  --note-tag-chip-bg: var(--note-tag-chip-bg-lt);
  --note-selected-bg: var(--note-selected-bg-lt);
  --progress-track: var(--progress-track-lt);
  --progress-fill: var(--progress-fill-lt);
  --table-border: var(--table-border-lt);
  --table-cell-border: var(--table-cell-border-lt);
  --table-header-bg: var(--table-header-bg-lt);
  --checkbox-check: var(--checkbox-check-lt);
  --checkbox-checked-border: var(--checkbox-checked-border-lt);
  --slash-hover-bg: var(--slash-hover-bg-lt);
}

:root[data-theme="dark"] {
  --bg: var(--bg-dk);
  --panel: var(--panel-dk);
  --navbar-bg: var(--navbar-bg-dk);
  --notes-bg: var(--notes-bg-dk);
  --editor-bg: var(--editor-bg-dk);
  --editor-inactive-bg: var(--editor-inactive-bg-dk);
  --navbar-text: var(--navbar-text-dk);
  --border: var(--border-dk);
  --text: var(--text-dk);
  --muted-text: var(--muted-text-dk);
  --accent: var(--accent-dk);
  --home-btn-bg: var(--home-btn-bg-dk);
  --home-btn-hover: var(--home-btn-hover-dk);
  --login-label: var(--login-label-dk);
  --login-input-border: var(--login-input-border-dk);
  --error-text: var(--error-text-dk);
  --banner-bg: var(--banner-bg-dk);
  --banner-text: var(--banner-text-dk);
  --banner-border: var(--banner-border-dk);
  --note-meta-text: var(--note-meta-text-dk);
  --sync-icon: var(--sync-icon-dk);
  --note-hover-bg: var(--note-hover-bg-dk);
  --note-tag-chip-bg: var(--note-tag-chip-bg-dk);
  --note-selected-bg: var(--note-selected-bg-dk);
  --progress-track: var(--progress-track-dk);
  --progress-fill: var(--progress-fill-dk);
  --table-border: var(--table-border-dk);
  --table-cell-border: var(--table-cell-border-dk);
  --table-header-bg: var(--table-header-bg-dk);
  --checkbox-check: var(--checkbox-check-dk);
  --checkbox-checked-border: var(--checkbox-checked-border-dk);
  --slash-hover-bg: var(--slash-hover-bg-dk);
}

html,
body {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Figtree", sans-serif !important;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.notes-page {
  height: 100dvh;
  overflow: hidden;
}

.mobile-nav-overlay {
  display: none;
}

.home-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.home-title {
  margin: 0;
  font-size: clamp(3.2rem, 11vw, 6.8rem);
  color: var(--navbar-bg-lt);
}

.brand-logo-font {
  font-family: "Caveat", cursive;
  letter-spacing: 0.02em;
}

.home-notes-link {
  text-decoration: none;
  color: var(--navbar-text);
  background: var(--home-btn-bg);
  border-radius: 8px;
  padding: 10px 16px;
}

.home-notes-link:hover {
  background: var(--home-btn-hover);
}

.home-login-form {
  display: flex;
  flex-direction: column;
  width: min(360px, 90vw);
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.home-login-label {
  font-size: 0.9rem;
  color: var(--login-label);
}

.home-login-input {
  width: 100%;
  border: 1px solid var(--login-input-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
}

.home-login-button {
  border: none;
  color: var(--navbar-text);
  background: var(--home-btn-bg);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
}

.home-login-button:hover {
  background: var(--home-btn-hover);
}

.home-login-error {
  min-height: 1.25rem;
  color: var(--error-text);
  font-size: 0.85rem;
}

.home-session-cta {
  display: inline-flex;
  justify-content: center;
  text-decoration: none;
}

.notes-load-error {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--banner-bg);
  color: var(--banner-text);
  border: 1px solid var(--banner-border);
  border-radius: 8px;
  padding: 8px 12px;
  z-index: 50;
}

.app-layout {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  margin: 0px;
  padding: 0px;
}

#navbar-container {
  background: var(--navbar-bg);
  margin: 0px;
  color: var(--navbar-text);
}

.navbar-elem {
  font-size: 21px;
  padding: 16px;
  cursor: pointer;
  font-weight: bold;
}

.navbar-elem:hover {
  background: var(--accent);
}

.navbar-header {
  font-size: 15px;
  padding: 12px 16px;
  font-weight: bold;
}

.navbar-top-menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.navbar-brand {
  color: var(--navbar-text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.navbar-user-menu {
  position: relative;
}

.navbar-user-avatar {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: var(--navbar-text);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.navbar-user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 130px;
  z-index: 120;
}

.navbar-user-dropdown[hidden] {
  display: none !important;
}

.user-menu-dropdown {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  padding: 6px;
}

.tags-tree {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px 12px 10px;
  overflow-y: auto;
}

.tag-tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tag-tree-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tag-tree-name-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-tree-indent {
  display: inline-block;
  width: 14px;
}

.tag-tree-toggle {
  display: inline-block;
  width: 10px;
  font-size: 0.7rem;
}

.tag-tree-name {
  color: var(--navbar-text);
  font-size: 0.85rem;
}

.tag-tree-count {
  color: var(--navbar-text);
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 1px 7px;
}

#notes-container {
  border-right: 1px solid var(--border);
  background: var(--notes-bg);
  margin: 0px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-pull-refresh {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-text);
  transition: height 140ms ease;
  flex-shrink: 0;
}

.notes-pull-refresh .material-symbols-outlined {
  font-size: 1.3rem;
}

.notes-pull-refresh.active .material-symbols-outlined {
  animation: note-pull-refresh-spin 1s linear infinite;
}

@keyframes note-pull-refresh-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

#notes-menu {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notes-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notes-search-input-wrap {
  position: relative;
}

.notes-search-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 34px 8px 12px;
  outline: none;
}

.notes-search-input:focus {
  border-color: var(--accent);
}

.notes-search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

.notes-search-clear:hover {
  background: var(--note-hover-bg);
}

.notes-search-clear[hidden] {
  display: none !important;
}

.mobile-nav-toggle {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text);
}

#notes-menu-title {
  font-size: 18px;
  font-weight: bold;
}

.notes-menu-item {
  font-size: 18px;
  cursor: pointer;
}

#notes-menu-item:hover {
  color: var(--accent);
}

#notes-menu-items,
#notes-list {
  display: flex;
  flex-direction: column;
}

#notes-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.note-list-item {
  margin: 0px;
  padding: 15px 15px;
  background: var(--notes-bg);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.note-list-item {
  border-bottom: 1px solid var(--border);
}

.note-list-item-title {
  font-weight: bold;
}

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

.note-list-item-selected {
  background: var(--note-selected-bg);
  border-right: 5px solid var(--navbar-bg);
}

.note-list-item-title {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-list-item-preview {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--muted-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-list-item-tags {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.note-list-item-tag-chip {
  max-width: 100%;
  font-size: 0.74rem;
  padding: 3px 9px;
}

.note-list-item-updated {
  font-size: 0.78rem;
  color: var(--note-meta-text);
}

.note-list-item-meta {
  margin-top: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.note-list-item-sync {
  min-width: 1.1rem;
  font-size: 1rem;
  color: var(--sync-icon);
}

.note-list-item-progress {
  margin-top: 15px;
}

.note-list-item-progress-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--progress-track);
  overflow: hidden;
}

.note-list-item-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--progress-fill);
  transition: width 150ms ease;
}

.note-list-item-progress-text {
  margin-top: 5px;
  font-size: 0.72rem;
  color: var(--muted-text);
}

.note-context-menu {
  position: fixed;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  padding: 6px;
  z-index: 60;
  display: none;
}

.note-context-menu:not([hidden]) {
  display: block;
}

.note-context-menu-item {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
}

.note-context-menu-item--with-icon {
  display: flex;
  align-items: center;
  gap: 10px;
}

.note-context-menu-item--with-trail .note-context-menu-trail-icon {
  margin-left: auto;
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.65;
  flex-shrink: 0;
}

/* `hidden` must win over flex layout on menu items (e.g. admin-only AST row). */
.note-context-menu-item[hidden] {
  display: none !important;
}

.feather-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.note-context-menu-icon {
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.92;
  flex-shrink: 0;
}

.note-context-menu-label {
  min-width: 0;
}

.note-context-menu-item:hover {
  background: var(--slash-hover-bg);
}

.note-context-menu-item.note-context-menu-item--disabled,
.note-context-menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.note-context-menu-item.note-context-menu-item--disabled:hover,
.note-context-menu-item:disabled:hover {
  background: transparent;
}

#editor-note-view-outline:disabled {
  pointer-events: auto;
}

.editor-appearance-menu-back {
  margin-bottom: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}

.editor-note-link-preview {
  position: fixed;
  z-index: 70;
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  padding: 10px 12px 12px;
  max-width: min(320px, calc(100vw - 16px));
  box-sizing: border-box;
}

.editor-note-link-preview-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.editor-note-link-preview-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--editor-bg);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.editor-note-link-preview-btn .material-symbols-outlined {
  font-size: 1.125rem;
  line-height: 1;
}

.editor-note-link-preview-btn:hover {
  background: var(--slash-hover-bg);
}

.editor-note-link-preview-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
  line-height: 1.3;
}

.editor-note-link-preview-snippet {
  font-size: 0.88rem;
  color: var(--muted-text);
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: 8.5em;
  overflow-y: auto;
}

#editor-container { 
  padding: 0px;
  position: relative;
  background: var(--editor-bg);
  min-height: 0;
  /* Let wide tables scroll inside the editor instead of expanding the grid column. */
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

.editor-empty-brand {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--navbar-bg);
  font-size: clamp(2.4rem, 7vw, 4.5rem);
  line-height: 1;
  user-select: none;
  pointer-events: none;
  z-index: 0;
}

.editor-empty-brand[hidden] {
  display: none !important;
}

#editor-mobile-menu {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-shrink: 0;
  padding: 10px clamp(24px, 12vw, 250px) 8px;
  border-bottom: 1px solid var(--border);
}

#editor-back-button {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
  padding: 4px;
  line-height: 1;
}

.editor-top-bar-spacer {
  display: none;
}

#editor-note-menu-button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  padding: 6px;
  line-height: 1;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#editor-note-menu-button:hover {
  background: var(--note-hover-bg);
}

.editor-mobile-title {
  font-weight: 600;
}

#editor-body {
  min-height: 0;
  min-width: 0;
  flex: 1;
  outline: none;
  line-height: 1.62;
  font-size: 1rem;
  margin: 30px clamp(24px, 12vw, 250px);
  margin-top: 0px;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.editor-title-input {
  margin: 30px clamp(24px, 12vw, 250px) 0;
  padding: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 0;
  -webkit-text-size-adjust: 100%;
}

.editor-title-input[hidden] {
  display: none !important;
}

.editor-title-input::placeholder {
  color: color-mix(in srgb, var(--text) 45%, transparent);
}

#editor-body .editor-line {
  flex-shrink: 0;
  min-height: 1.15em;
  outline: none;
  position: relative;
}

/* Reorder gutter: same left inset for title + body so the note is flush; drag handle is desktop-only (see below). */
@media (min-width: 1025px) {
  #editor-body .editor-line {
    padding-left: 2.25rem;
  }
}

@media (max-width: 1024px) {
  .feather-backlinks-modal {
    padding: 10px;
  }

  .feather-backlinks-modal__panel {
    width: min(96vw, 520px);
    max-height: min(86dvh, 860px);
  }

  .feather-backlinks-modal__results {
    padding: 8px 10px 10px;
  }

  .feather-backlinks-modal__filters,
  .feather-backlinks-modal__header {
    padding-left: 10px;
    padding-right: 10px;
  }

  #editor-body .editor-line {
    padding-left: 0;
  }
}

#editor-body .editor-line-drag {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: color-mix(in srgb, var(--text) 45%, transparent);
  cursor: grab;
  padding: 2px 4px;
  border-radius: 6px;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
  z-index: 2;
}

@media (min-width: 1025px) {
  #editor-body .editor-line:not(.editor-line--title) .editor-line-drag {
    display: inline-flex;
  }
}

#editor-body .editor-line-drag:active {
  cursor: grabbing;
}

#editor-body .editor-line-drag-icon {
  font-size: 1.25rem;
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
}

@media (min-width: 1025px) and (hover: hover) and (pointer: fine) {
  #editor-body .editor-line:not(.editor-line--title):hover .editor-line-drag {
    opacity: 1;
  }

  #editor-body .editor-line-drag:hover {
    color: var(--text);
    background: var(--note-hover-bg);
  }
}

#editor-body.editor-reorder-active .editor-line--reorder-drop-target {
  outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  outline-offset: 2px;
  border-radius: 4px;
}

#editor-body.editor-reorder-active .editor-line--reorder-source-active {
  opacity: 0.35;
}

body.editor-reorder-dragging {
  user-select: none;
  -webkit-user-select: none;
}

.feather-backlinks-modal {
  position: fixed;
  inset: 0;
  z-index: 200100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(24px, 4vw);
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.feather-backlinks-modal[hidden] {
  display: none !important;
}

.feather-note-outline-modal {
  position: fixed;
  inset: 0;
  z-index: 200110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(24px, 4vw);
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.feather-note-outline-modal[hidden] {
  display: none !important;
}

.feather-note-outline-modal__panel {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: min(80vh, 760px);
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.feather-note-outline-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.feather-note-outline-modal__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.feather-note-outline-modal__close {
  border: none;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.feather-note-outline-modal__close:hover {
  background: var(--note-hover-bg);
  color: var(--text);
}

.feather-note-outline-modal__list {
  overflow: auto;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feather-note-outline-modal__item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.35;
}

.feather-note-outline-modal__item:hover {
  background: var(--slash-hover-bg);
  border-color: var(--border);
}

.feather-note-outline-modal__item-empty {
  color: var(--muted-text);
  font-size: 0.9rem;
  padding: 8px 2px;
}

.feather-backlinks-modal__panel {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.feather-backlinks-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.feather-backlinks-modal__heading {
  min-width: 0;
}

.feather-backlinks-modal__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.feather-backlinks-modal__note-context {
  margin-top: 2px;
  color: var(--muted-text);
  font-size: 0.82rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feather-backlinks-modal__close {
  border: none;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.feather-backlinks-modal__close:hover {
  background: var(--note-hover-bg);
  color: var(--text);
}

.feather-backlinks-modal__filters {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feather-backlinks-modal__search,
.feather-backlinks-modal__tag-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}

.feather-backlinks-modal__search:focus,
.feather-backlinks-modal__tag-input:focus {
  border-color: var(--accent);
}

.feather-backlinks-modal__tag-filter-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feather-backlinks-modal__tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feather-backlinks-tag-chip {
  border: none;
  background: var(--note-tag-chip-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.74rem;
  line-height: 1.2;
  cursor: pointer;
}

.feather-backlinks-tag-chip-label {
  line-height: 1;
}

.feather-backlinks-tag-chip-remove {
  font-size: 0.82rem;
  line-height: 1;
  opacity: 0.75;
}

.feather-backlinks-modal__tag-suggestion-menu {
  top: calc(100% + 6px);
  left: 0;
  right: 0;
}

.feather-backlinks-modal__status {
  padding: 10px 14px 4px;
  color: var(--muted-text);
  font-size: 0.84rem;
}

.feather-backlinks-modal__results {
  overflow: auto;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feather-backlinks-card {
  margin: 0;
}

body.feather-backlinks-modal-open {
  overflow: hidden;
}

/* Password protect notes modals */
.feather-note-password-modal {
  position: fixed;
  inset: 0;
  z-index: 200010;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(24px, 4vw);
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.feather-note-password-modal[hidden] {
  display: none !important;
}

.feather-note-password-modal__panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(440px, 100%);
  max-height: min(90vh, 720px);
  width: 100%;
  padding: 14px 16px 16px;
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  overflow: auto;
}

.feather-note-password-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.feather-note-password-modal__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.feather-note-password-modal__close {
  border: none;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.feather-note-password-modal__close:hover {
  background: var(--note-hover-bg);
  color: var(--text);
}

.feather-note-password-modal__warn,
.feather-note-password-modal__hint {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted-text);
}

.feather-note-password-modal__label {
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 4px;
}

.feather-note-password-modal__input,
.feather-note-password-modal__textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.feather-note-password-modal__textarea {
  resize: vertical;
  min-height: 80px;
}

.feather-note-password-modal__check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  margin-top: 6px;
  cursor: pointer;
}

.feather-note-password-modal__decoy {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feather-note-password-modal__error {
  margin: 4px 0 0;
  font-size: 0.84rem;
  color: #dc2626;
}

.feather-note-password-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.feather-note-password-modal__btn {
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
}

.feather-note-password-modal__btn--secondary {
  background: transparent;
  color: var(--text);
}

.feather-note-password-modal__btn--primary {
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  border-color: transparent;
}

body.feather-note-password-modal-open {
  overflow: hidden;
}

/* Admin-only: read-only AST JSON modal (desktop) */
.feather-admin-ast-modal {
  position: fixed;
  inset: 0;
  z-index: 200000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(24px, 4vw);
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.feather-admin-ast-modal[hidden] {
  display: none !important;
}

.feather-admin-ast-modal__panel {
  display: flex;
  flex-direction: column;
  max-width: min(960px, 100%);
  max-height: min(88vh, 900px);
  width: 100%;
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.feather-admin-ast-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.feather-admin-ast-modal__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.feather-admin-ast-modal__close {
  border: none;
  background: transparent;
  color: var(--muted-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.feather-admin-ast-modal__close:hover {
  background: var(--note-hover-bg);
  color: var(--text);
}

.feather-admin-ast-modal__pre {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  flex: 1;
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre;
  tab-size: 2;
  background: color-mix(in srgb, var(--editor-bg) 92%, var(--border));
}

body.feather-admin-ast-modal-open {
  overflow: hidden;
}

#editor-body.editor-hide-completed-cbs .editor-line--checkbox[data-cb-checked="true"] {
  display: none;
}

::highlight(feather-md-sel) {
  background-color: color-mix(in srgb, var(--accent) 24%, transparent);
}

#editor-body .editor-line.editor-line--md-sel-paint {
  background-color: color-mix(in srgb, var(--accent) 14%, transparent);
}

.note-tags-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: var(--editor-bg);
  padding: 8px 50px 20px 50px;
  position: relative;
  z-index: 1;
}

.note-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--note-tag-chip-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.note-tag-remove {
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}

.note-tag-input {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  min-width: 130px;
  font: inherit;
  font-size: 0.8rem;
  outline: none;
}

.note-tag-input:focus {
  border-color: var(--accent);
}

.note-tag-input-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.note-tag-suggestion-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  min-width: min(280px, 90vw);
  max-height: min(240px, 45vh);
  overflow-y: auto;
  overflow-x: hidden;
}

#editor-container.editor-inactive {
  background: var(--editor-inactive-bg);
}

#editor-body.editor-disabled {
  cursor: not-allowed;
  opacity: 0.75;
  pointer-events: none;
}

#editor-body span:not(.md-table-raw) + br {
  font-size: 0rem;
  line-height: 2rem;
}

/* Heading shells are <span> in the editor; they must be block-level so margin-top/bottom apply. */
.md-h1,
.md-h2,
.md-h3,
.md-h4,
.md-h5,
.md-h6 {
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.md-h1 {
  font-size: 1.85rem;
  font-weight: 750;
  line-height: 1.28;
  letter-spacing: -0.02em;
  margin: 0.15em 0 0.35em;
}

.md-h2 {
  font-size: 1.45rem;
  font-weight: 720;
  line-height: 1.32;
  letter-spacing: -0.015em;
  margin: 0.65em 0 0.28em;
}

.md-h3 {
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.38;
  margin: 0.55em 0 0.22em;
}

.md-h4,
.md-h5,
.md-h6 {
  font-size: 1.05rem;
  font-weight: 680;
  line-height: 1.42;
  margin: 0.48em 0 0.18em;
  color: color-mix(in srgb, var(--text) 92%, var(--muted-text));
}

/* ProseMirror heading styling parity with legacy markdown heading styles */
#editor-body .ProseMirror h1,
#editor-body .ProseMirror h2,
#editor-body .ProseMirror h3,
#editor-body .ProseMirror h4,
#editor-body .ProseMirror h5,
#editor-body .ProseMirror h6 {
  display: block;
  width: 100%;
  box-sizing: border-box;
}

#editor-body .ProseMirror h1 {
  font-size: 1.85rem;
  font-weight: 750;
  line-height: 1.28;
  letter-spacing: -0.02em;
  margin: 0.15em 0 0.35em;
}

#editor-body .ProseMirror h2 {
  font-size: 1.45rem;
  font-weight: 720;
  line-height: 1.32;
  letter-spacing: -0.015em;
  margin: 0.65em 0 0.28em;
}

#editor-body .ProseMirror h3 {
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.38;
  margin: 0.55em 0 0.22em;
}

#editor-body .ProseMirror h4,
#editor-body .ProseMirror h5,
#editor-body .ProseMirror h6 {
  font-size: 1.05rem;
  font-weight: 680;
  line-height: 1.42;
  margin: 0.48em 0 0.18em;
  color: color-mix(in srgb, var(--text) 92%, var(--muted-text));
}

.md-marker {
  display: inline-block;
  width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  user-select: none;
}

#editor-slash-menu {
  position: absolute;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

#editor-slash-menu:not([hidden]) {
  display: flex;
}

.editor-tag-menu {
  position: absolute;
  min-width: 140px;
  max-width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 11;
}

.editor-tag-menu:not([hidden]) {
  display: flex;
}

.tag-option,
.note-link-option {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 10px;
  cursor: pointer;
}

.note-link-option-icon {
  font-size: 1rem;
  line-height: 1;
  color: var(--muted-text);
}

.note-link-option-label {
  min-width: 0;
}

.tag-option:hover,
.note-link-option:hover {
  background: var(--slash-hover-bg);
}

.tag-option.active,
.note-link-option.active {
  background: var(--slash-hover-bg);
}

.slash-option {
  appearance: none;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  font-size: 0.95rem;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* The class rule above sets `display: flex`, which has equal specificity to the
   UA `[hidden] { display: none }` rule and would otherwise win on cascade origin,
   leaving filtered-out options visible. Re-apply hiding explicitly. */
.slash-option[hidden] {
  display: none !important;
}

.slash-option-icon {
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.92;
  flex-shrink: 0;
}

.slash-option-label {
  min-width: 0;
}

.slash-option:hover,
.slash-option.active {
  background: var(--slash-hover-bg);
}

.md-table-raw + br {
  font-size: 0rem;
  line-height: 0rem;
}

.md-table-wrap {
  margin: 0.35rem 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

#editor-body .ProseMirror {
  outline: none;
  border: none;
  /* Flex item: allow shrinking so .tableWrapper gets a bounded width and can scroll horizontally. */
  min-width: 0;
  width: 100%;
  max-width: 100%;
  user-select: text;
  -webkit-user-select: text;
}

#editor-body .ProseMirror:focus-visible {
  outline: none;
  border: none;
}

/* ProseMirror table styling parity with legacy .md-table */
#editor-body .ProseMirror .tableWrapper {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

#editor-body .ProseMirror table {
  /* Enable horizontal scrolling even when tables are rendered as direct
     children of the ProseMirror root (no wrapper div). */
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
}

#editor-body .ProseMirror th,
#editor-body .ProseMirror td {
  border: 1px solid var(--table-cell-border);
  padding: 8px 10px;
  width: 160px;
  min-width: 160px;
  vertical-align: top;
  text-align: left;
}

#editor-body .ProseMirror th {
  background: var(--table-header-bg);
  font-weight: 600;
}

/* ProseMirror task list styling parity with legacy checkbox rows */
#editor-body .ProseMirror .pm-task-list {
  list-style: none;
  margin: 0.35rem 0;
  padding-left: 0;
}

#editor-body .ProseMirror .pm-task-item {
  list-style: none;
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0.2rem 0;
}

#editor-body .ProseMirror .pm-task-item[data-indent="1"] { margin-left: 1.25rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="2"] { margin-left: 2.5rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="3"] { margin-left: 3.75rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="4"] { margin-left: 5rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="5"] { margin-left: 6.25rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="6"] { margin-left: 7.5rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="7"] { margin-left: 8.75rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="8"] { margin-left: 10rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="9"] { margin-left: 11.25rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="10"] { margin-left: 12.5rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="11"] { margin-left: 13.75rem; }
#editor-body .ProseMirror .pm-task-item[data-indent="12"] { margin-left: 15rem; }

#editor-body .ProseMirror .pm-task-label {
  display: inline-flex;
  align-items: center;
  margin-top: 0;
}

#editor-body .ProseMirror .pm-task-checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: var(--checkbox-check);
}

#editor-body .ProseMirror .pm-task-content {
  flex: 1;
}

#editor-body .ProseMirror .pm-task-content p {
  margin: 0;
}

#editor-body.feather-editor-hide-completed-cbs .ProseMirror .pm-task-item[data-checked="true"] {
  display: none;
}

/* Inline date chip (ProseMirror atom + NodeView) */
#editor-body .ProseMirror .pm-feather-date-chip-wrap {
  display: inline-flex;
  align-items: center;
  vertical-align: baseline;
  margin: 0 1px;
}

#editor-body .ProseMirror .pm-feather-date-chip {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  color: var(--text);
  border-radius: 999px;
  padding: 0.1em 0.55em 0.12em;
  font-size: 0.88em;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.35;
  max-width: 100%;
  margin-inline-end: 0.2em;
}

#editor-body .ProseMirror .pm-feather-date-chip:hover {
  background: color-mix(in srgb, var(--accent) 20%, var(--panel));
}

#editor-body .ProseMirror .pm-feather-date-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#editor-body .ProseMirror .pm-feather-date-picker-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  display: none;
}

#editor-body .ProseMirror .pm-feather-date-picker-input[style*="block"] {
  pointer-events: auto;
  position: fixed;
  left: 0;
  top: 0;
  width: auto;
  height: auto;
  opacity: 1;
  z-index: 300000;
}

.feather-date-insert-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(24px, 4vw);
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.feather-date-insert-backdrop[hidden] {
  display: none !important;
}

.feather-date-insert-panel {
  width: 100%;
  max-width: 380px;
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feather-date-insert-title {
  font-size: 1rem;
  font-weight: 600;
}

.feather-date-insert-field {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
}

.feather-date-insert-error {
  min-height: 1.25em;
  font-size: 0.85rem;
  color: #c62828;
}

.feather-date-insert-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.feather-date-insert-cancel,
.feather-date-insert-ok {
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.feather-date-insert-ok {
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  font-weight: 600;
}

.feather-date-chip-edit-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200101;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: min(24px, 4vw);
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.feather-date-chip-edit-backdrop[hidden] {
  display: none !important;
}

.feather-date-chip-edit-panel {
  width: 100%;
  max-width: 380px;
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feather-date-chip-edit-title {
  font-size: 1rem;
  font-weight: 600;
}

.feather-date-chip-edit-field {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
}

.feather-date-chip-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.feather-date-chip-edit-cancel,
.feather-date-chip-edit-done {
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.feather-date-chip-edit-done {
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  font-weight: 600;
}

/* ProseMirror code block + inline code parity with legacy markdown styles */
#editor-body .ProseMirror pre {
  margin: 0.45rem 0;
  padding: 10px 12px 12px;
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 92%, var(--editor-bg));
}

#editor-body .ProseMirror pre code {
  display: block;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
  background: color-mix(in srgb, var(--editor-bg) 55%, var(--panel));
  border-radius: 6px;
  padding: 0;
}

#editor-body .ProseMirror :not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: color-mix(in srgb, var(--note-hover-bg) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 5px;
  padding: 0.08em 0.32em;
}

.pm-inline-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.14);
}

.pm-inline-toolbar[hidden] {
  display: none !important;
}

.pm-inline-toolbar button {
  appearance: none;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 6px;
  cursor: pointer;
}

.pm-inline-toolbar button:hover {
  background: var(--slash-hover-bg);
}

.pm-inline-link-input {
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  padding: 5px 8px;
}

.pm-inline-link-input[hidden] {
  display: none !important;
}

/* Line breaks immediately after a table map ambiguously to opaque table markdown;
   clicks pass through so the caret lands in real body content below. */
.md-table-wrap + br {
  pointer-events: none;
}

.md-table {
  /* TODO: Revisit responsive overflow when tables support many columns. */
  width: max-content;
  min-width: 360px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--table-border);
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
}

.md-table th,
.md-table td {
  border-right: 1px solid var(--table-cell-border);
  border-bottom: 1px solid var(--table-cell-border);
  min-width: 160px;
  padding: 8px 10px;
  text-align: left;
  position: relative;
  vertical-align: top;
}

.md-table tr th:last-child,
.md-table tr td:last-child {
  border-right: none;
}

.md-table tbody tr:last-child td {
  border-bottom: none;
}

.md-table th {
  background: var(--table-header-bg);
  font-weight: 700;
}

table p {
  margin: 0px;
}

.md-table-cell-menu-btn {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-text);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 10px 1px !important;
  z-index: 2;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.md-table-cell-menu-btn:hover {
  background: var(--slash-hover-bg);
  color: var(--text);
  border-color: var(--table-cell-border);
}

.pm-table-cell-menu-btn {
  position: fixed;
  opacity: 1;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  border-color: color-mix(in srgb, var(--table-cell-border) 75%, transparent);
  color: color-mix(in srgb, var(--muted-text) 92%, var(--text));
  box-shadow: 0 2px 8px color-mix(in srgb, black 12%, transparent);
  backdrop-filter: blur(1px);
}

.pm-table-cell-menu-btn[hidden] {
  display: none !important;
}

.pm-table-cell-menu-btn:hover {
  background: color-mix(in srgb, var(--slash-hover-bg) 80%, var(--panel));
  border-color: var(--table-cell-border);
  color: var(--text);
}

.pm-table-cell-menu-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 1px;
}

.md-table-cell-content {
  display: block;
  min-height: 1em;
  padding-right: 20px;
  white-space: pre-wrap;
}

.editor-table-menu {
  position: absolute;
  z-index: 40;
  min-width: 0;
  width: max-content;
  max-width: min(220px, calc(100% - 8px));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}

.editor-table-menu[hidden] {
  display: none !important;
}

.editor-table-menu .note-context-menu-item {
  display: flex;
  width: 100%;
  white-space: nowrap;
}

.md-cell-menu-icon,
.md-block-menu-icon {
  font-size: 1.1rem;
  line-height: 1;
  vertical-align: middle;
  display: inline-block;
}

.md-table-cell-menu-btn,
.md-code-block-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 2px;
}

.editor-code-block-menu {
  position: absolute;
  z-index: 40;
  min-width: 0;
  width: max-content;
  max-width: min(220px, calc(100% - 8px));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}

.editor-code-block-menu[hidden] {
  display: none !important;
}

.editor-format-toolbar {
  position: absolute;
  z-index: 45;
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}

.editor-format-toolbar[hidden] {
  display: none !important;
}

.editor-format-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--editor-bg);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 32px;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.editor-format-btn:hover {
  background: var(--slash-hover-bg);
}

.editor-format-u {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-inline-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: color-mix(in srgb, var(--note-hover-bg) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 5px;
  padding: 0.08em 0.32em;
}

.md-fmt-bold {
  font-weight: 700;
}

.md-fmt-italic {
  font-style: italic;
}

.md-fmt-strike {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.md-fmt-underline {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-code-fence-wrap {
  position: relative;
  margin: 0.45rem 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 92%, var(--editor-bg));
  overflow: hidden;
}

.md-code-fence-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 4px 6px 0;
  background: color-mix(in srgb, var(--panel) 70%, var(--editor-bg));
  border-bottom: 1px solid var(--border);
}

.md-code-block-menu-btn {
  width: 22px;
  height: 22px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-text);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.md-code-fence-wrap:hover .md-code-block-menu-btn,
.md-code-fence-wrap:focus-within .md-code-block-menu-btn,
.md-code-block-menu-btn:focus-visible {
  opacity: 1;
}

.md-code-block-menu-btn:hover {
  background: var(--slash-hover-bg);
  color: var(--text);
  border-color: var(--border);
}

.md-code-block {
  margin: 0;
  padding: 10px 12px 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  background: color-mix(in srgb, var(--editor-bg) 55%, var(--panel));
  color: var(--text);
}

.md-code-block-inner {
  display: block;
  white-space: pre-wrap;
  min-height: 1.2em;
  outline: none;
}

.md-table-cell:focus-visible {
  outline: none;
}

/* Touch / coarse pointers: only the cell with caret or focused menu button shows the control
   (hover is unreliable and can stick). Desktop hover is below with (hover: hover) + fine pointer. */
.md-table-cell:focus-within .md-table-cell-menu-btn,
.md-table-cell-menu-btn:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 1025px) and (hover: hover) and (pointer: fine) {
  .md-table-cell:hover .md-table-cell-menu-btn {
    opacity: 1;
    pointer-events: auto;
  }
}

.md-table-raw {
  display: none;
}

.md-checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.md-checkbox-marker {
  display: inline-block;
  width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  user-select: none;
}

.md-checkbox-toggle {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 5px;
  border: 2px solid var(--border);
  background: transparent;
}

input[type="checkbox"]:checked::after {
  content: "✓";
  font-size: 12px;
  color: var(--checkbox-check);
}

.md-checkbox-toggle:checked {
  border: 2px solid var(--checkbox-checked-border);
}

.md-checkbox-label {
  line-height: 1.45;
}

.md-list-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
}

.md-list-marker {
  display: inline-block;
  width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  user-select: none;
}

.md-list-bullet {
  color: var(--text);
  opacity: 0.5;
  font-weight: 700;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.md-list-content {
  line-height: 1.45;
}

.md-list-bullet-ordered {
  min-width: 1.45em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.md-list-bullet-ordered::before {
  content: attr(data-ol-num) ".";
}

a.md-note-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  margin: 0 0.06em;
  padding: 0.1em 0.45em 0.12em 0.42em;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 0.92em;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  vertical-align: baseline;
  max-width: 100%;
  user-select: none;
  -webkit-user-select: none;
}

a.md-note-link .md-note-link-icon {
  font-size: 1.05em;
  line-height: 1;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
  flex-shrink: 0;
}

a.md-note-link:hover {
  background: var(--slash-hover-bg);
  border: 1px solid var(--border);
}

.md-arrow {
  display: inline-block;
  font-weight: 700;
  color: var(--text);
}

.md-tag-token {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--note-hover-bg);
  color: var(--text);
  padding: 0 6px;
  line-height: 1.3;
}

.md-inline-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.md-inline-link:hover {
  filter: brightness(1.08);
}

a.md-inline-link:not(.md-note-link):visited {
  color: var(--accent);
}

@media (max-width: 1024px) {
  .notes-page {
    overflow: hidden;
    overscroll-behavior-x: none;
  }

  .notes-page .app-layout {
    grid-template-columns: 1fr;
    height: 100dvh;
    min-height: 0;
    position: relative;
  }

  .notes-page #navbar-container {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: 2px 0 14px rgba(0, 0, 0, 0.2);
  }

  .notes-page.mobile-nav-open #navbar-container {
    transform: translateX(0);
  }

  .notes-page.mobile-nav-open .mobile-nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 25;
  }

  .notes-page #notes-container,
  .notes-page #editor-container {
    width: 100%;
    border-right: none;
    min-height: 0;
    overflow-x: hidden;
  }

  .notes-page #notes-container {
    display: flex;
    flex-direction: column;
    touch-action: pan-y;
  }

  .notes-page #editor-container {
    display: none;
    padding: 0px;
  }

  .notes-page.mobile-editor-open #notes-container {
    display: none;
  }

  .notes-page.mobile-editor-open #editor-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
  }

  .notes-page #notes-menu-title {
    flex: 1;
    text-align: center;
  }

  .notes-page .mobile-nav-toggle {
    display: inline-block;
  }

  .notes-page #editor-mobile-menu {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    padding: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }

  .notes-page #editor-back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .notes-page .editor-top-bar-spacer {
    display: block;
    flex: 1;
    min-width: 8px;
  }

  .notes-page #editor-body {
    margin: 18px 16px;
    line-height: 1.52;
    gap: 0.55em;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .notes-page .editor-title-input {
    margin-left: 16px;
    margin-right: 16px;
  }

  .notes-page .note-tag-input,
  .notes-page .notes-search-input {
    font-size: 16px;
  }

  .note-tags-panel {
    flex-shrink: 0;
    padding: 8px 16px 14px 16px;
  }

  .note-tag-input-wrap {
    width: 100%;
    min-width: 0;
  }

  .notes-page .note-tag-input-wrap .note-tag-input {
    width: 100%;
    min-width: 0;
  }

  .note-tag-suggestion-menu {
    left: 0;
    right: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(38dvh, 280px);
    z-index: 1200;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  }

  .notes-page #editor-body span:not(.md-table-raw) + br {
    line-height: 1.05rem;
  }

  .notes-page .md-list-content,
  .notes-page .md-checkbox-label {
    line-height: 1.5;
  }

  .notes-page .md-h1 {
    font-size: 1.38rem;
    line-height: 1.22;
    margin: 0.2em 0 0.32em;
  }

  .notes-page #editor-body .ProseMirror h1 {
    font-size: 1.38rem;
    line-height: 1.22;
    margin: 0.2em 0 0.32em;
  }

  .notes-page .md-h2 {
    font-size: 1.2rem;
    line-height: 1.28;
    margin: 0.55em 0 0.24em;
  }

  .notes-page #editor-body .ProseMirror h2 {
    font-size: 1.2rem;
    line-height: 1.28;
    margin: 0.55em 0 0.24em;
  }

  .notes-page .md-h3 {
    font-size: 1.08rem;
    line-height: 1.34;
    margin: 0.48em 0 0.2em;
  }

  .notes-page #editor-body .ProseMirror h3 {
    font-size: 1.08rem;
    line-height: 1.34;
    margin: 0.48em 0 0.2em;
  }

  .notes-page .md-h4,
  .notes-page .md-h5,
  .notes-page .md-h6 {
    font-size: 1.01rem;
    line-height: 1.38;
    margin: 0.42em 0 0.16em;
  }

  .notes-page #editor-body .ProseMirror h4,
  .notes-page #editor-body .ProseMirror h5,
  .notes-page #editor-body .ProseMirror h6 {
    font-size: 1.01rem;
    line-height: 1.38;
    margin: 0.42em 0 0.16em;
  }

  .notes-page .md-checkbox-toggle {
    width: 1.2rem;
    height: 1.2rem;
    min-width: 1.3rem;
    min-height: 1.3rem;
    border-width: 2px;
    margin-top: 0.08rem;
    -webkit-tap-highlight-color: transparent;
  }

  .notes-page input[type="checkbox"]:checked::after {
    font-size: 14px;
  }

  .notes-page .md-code-block-menu-btn {
    opacity: 1;
  }

  /* Centered “sheet” menus on narrow viewports (readable, scrollable; dim via shadow). */
  #editor-slash-menu,
  #editor-note-link-menu,
  .editor-tag-menu,
  .note-context-menu,
  .editor-note-link-preview {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(92vw, 420px) !important;
    max-width: min(92vw, 420px) !important;
    box-sizing: border-box !important;
    max-height: min(calc(75dvh - env(safe-area-inset-bottom, 0px)), 520px);
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    z-index: 1100 !important;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    box-shadow:
      0 0 0 100vmax rgba(0, 0, 0, 0.42),
      0 12px 28px rgba(0, 0, 0, 0.18);
  }

  /* Inline toolbar: same centered sheet, but no full-viewport dim — it would cover the editor and hide the selection highlight. */
  .pm-inline-toolbar {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(92vw, 420px) !important;
    max-width: min(92vw, 420px) !important;
    box-sizing: border-box !important;
    max-height: min(calc(75dvh - env(safe-area-inset-bottom, 0px)), 520px);
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    z-index: 1100 !important;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
  }

  .editor-table-menu .note-context-menu-item {
    white-space: normal;
  }

  .pm-inline-toolbar .pm-inline-link-input {
    flex: 1 1 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .pm-list-indent-menu {
    position: fixed;
    left: 0;
    top: 0;
    bottom: auto;
    transform: none;
    z-index: 1101;
    display: none;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
  }

  .pm-list-indent-menu[hidden] {
    display: none !important;
  }

  .pm-list-indent-btn {
    appearance: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--editor-bg);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .pm-list-indent-btn .material-symbols-outlined {
    font-size: 1.15rem;
    line-height: 1;
  }

  .pm-list-indent-btn:disabled {
    opacity: 0.45;
  }
}
