:root {
  color-scheme: light dark;

  /* Slack client palette — light surfaces. This is also the base for `auto`,
     whose dark branch is supplied by the prefers-color-scheme block below. */
  --bg: #f8f8f8;
  --panel: #ffffff;
  --panel-2: #f8f8f8;
  /* Write mode gets a white sheet; preview mode a slightly tinted page. */
  --editor-bg: #ffffff;
  --preview-bg: #f8f8f8;
  --text: #1d1c1d;
  --muted: #454447;
  --faint: #5e5d60;
  --border: rgba(29,28,29,.13);
  --border-soft: rgba(29,28,29,.075);

  /* Brand is identity/container; blue is current/interactive; green acts. */
  --brand: #4a154b;
  --brand-hover: #611f69;
  --role-b: #a34ba8;
  --accent: #1264a3;
  --link: var(--accent);
  --accent-strong: #0d5590;
  --accent-soft: #e8f5fa;
  --accent-contrast: #ffffff;
  --cta: #007a5a;
  --cta-hover: #148567;
  --cta-contrast: #ffffff;
  --success: #007a5a;
  --success-bg: #e9f7f1;
  --warning: #ecb22e;
  --warning-ink: #6b5000;
  --warning-bg: #fff8e1;
  --danger: #c01343;
  --danger-soft: #fdf0f4;
  --focus: rgba(18,100,163,.30);

  /* Aubergine sidebar; the neutral `light` theme overrides these below. */
  --sidebar-bg: #4a154b;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: #1264a3;
  --sidebar-text: rgba(255,255,255,.78);
  --sidebar-text-strong: #ffffff;
  --sidebar-border: rgba(255,255,255,.14);
  --vault-chip-bg: var(--sidebar-hover);
  --vault-chip-ink: var(--sidebar-text-strong);
  --vault-chip-border: var(--sidebar-border);

  /* Shape, depth and motion. */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-pill: 9999px;
  --radius: var(--radius-xl);
  --shadow-sm: 0 1px 2px rgba(29,28,29,.10), 0 1px 3px rgba(29,28,29,.06);
  --shadow-md: 0 4px 12px rgba(29,28,29,.12), 0 2px 4px rgba(29,28,29,.06);
  --shadow-lg: 0 12px 32px rgba(29,28,29,.18), 0 4px 10px rgba(29,28,29,.10);
  --shadow: var(--shadow-lg);
  --dur-fast: 80ms;
  --dur-base: 160ms;

  --editor-space: 0.3em;
  /* Material 4dp/8dp spacing scale — all layout spacing uses these. */
  --sp-1: 4px;    /* micro: badge/icon gaps, hint offsets */
  --sp-2: 8px;    /* compact: adjacent buttons, chips, toolbar controls */
  --sp-3: 12px;   /* medium: field internals, small card padding, list items */
  --sp-4: 16px;   /* default container inset: sections, dropdowns, cards */
  --sp-6: 24px;   /* primary content inset: topbar, sidebar sections, modal, editor, graph */
  --sp-8: 32px;   /* generous: gate card, empty state, large separation */
  --sp-12: 48px;  /* large: trailing scroll space under long previews */
  --editor-inset: 9px; /* = 0.3em × 30px .title-input font-size (K1) */
  /* Slack whitespace aliases — reuse --sp-*; no new off-grid pixels. */
  --ws-row-y: var(--sp-2);
  --ws-row-group-y: var(--sp-1);
  --ws-pane-x: var(--sp-6);
  --ws-leaf-x: var(--sp-3);
  --ws-card: var(--sp-4);
  --ws-card-lg: var(--sp-8);
  --ws-section: var(--sp-6);
  --ws-scroll-tail: var(--sp-12);
  /* Text controls share one box so text never sits against the border. */
  --input-height: 40px;
  --input-pad-x: var(--sp-3);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* `auto` has no [data-theme] override, so this block stays in charge under a
   dark system preference; the explicit themes below beat it by specificity. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1a1d21;
    --panel: #212428;
    --panel-2: #212428;
    --editor-bg: #212428;
    --preview-bg: #1a1d21;
    --text: #f8f8f8;
    --muted: #b9babd;
    --faint: #9a9b9e;
    --border: rgba(121,124,129,.42);
    --border-soft: rgba(121,124,129,.28);
    --brand: #4a154b;
    --brand-hover: #611f69;
    --accent: #2ba5ce;
    --link: var(--accent);
    --accent-strong: #5cc2e4;
    --accent-soft: rgba(43,165,206,.16);
    --accent-contrast: #1a1d21;
    --cta: #3daa7c;
    --cta-hover: #5fc39a;
    --cta-contrast: #1a1d21;
    --success: #3daa7c;
    --success-bg: rgba(61,170,124,.14);
    --warning: #dea700;
    --warning-ink: #f0cf74;
    --warning-bg: rgba(222,167,0,.14);
    --danger: #de678a;
    --danger-soft: rgba(222,103,138,.12);
    --focus: rgba(43,165,206,.32);
    --sidebar-bg: #4a154b;
    --sidebar-hover: rgba(255,255,255,.08);
    --sidebar-active: #1264a3;
    --sidebar-text: rgba(255,255,255,.78);
    --sidebar-text-strong: #ffffff;
    --sidebar-border: rgba(255,255,255,.14);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.40);
    --shadow-md: 0 4px 12px rgba(0,0,0,.48), 0 2px 4px rgba(0,0,0,.32);
    --shadow-lg: 0 16px 40px rgba(0,0,0,.60), 0 4px 12px rgba(0,0,0,.40);
  }
}

:root[data-theme="slack"] {
  color-scheme: light;
  --bg: #f8f8f8;
  --panel: #ffffff;
  --panel-2: #f8f8f8;
  --editor-bg: #ffffff;
  --preview-bg: #f8f8f8;
  --text: #1d1c1d;
  --muted: #454447;
  --faint: #5e5d60;
  --border: rgba(29,28,29,.13);
  --border-soft: rgba(29,28,29,.075);
  --brand: #4a154b;
  --brand-hover: #611f69;
  --accent: #1264a3;
  --link: var(--accent);
  --accent-strong: #0d5590;
  --accent-soft: #e8f5fa;
  --accent-contrast: #ffffff;
  --cta: #007a5a;
  --cta-hover: #148567;
  --cta-contrast: #ffffff;
  --success: #007a5a;
  --success-bg: #e9f7f1;
  --warning: #ecb22e;
  --warning-ink: #6b5000;
  --warning-bg: #fff8e1;
  --danger: #c01343;
  --danger-soft: #fdf0f4;
  --focus: rgba(18,100,163,.30);
  --sidebar-bg: #4a154b;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: #1264a3;
  --sidebar-text: rgba(255,255,255,.78);
  --sidebar-text-strong: #ffffff;
  --sidebar-border: rgba(255,255,255,.14);
  --shadow-sm: 0 1px 2px rgba(29,28,29,.10), 0 1px 3px rgba(29,28,29,.06);
  --shadow-md: 0 4px 12px rgba(29,28,29,.12), 0 2px 4px rgba(29,28,29,.06);
  --shadow-lg: 0 12px 32px rgba(29,28,29,.18), 0 4px 10px rgba(29,28,29,.10);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f8f8;
  --panel: #ffffff;
  --panel-2: #f8f8f8;
  --editor-bg: #ffffff;
  --preview-bg: #f8f8f8;
  --text: #1d1c1d;
  --muted: #454447;
  --faint: #5e5d60;
  --border: rgba(29,28,29,.13);
  --border-soft: rgba(29,28,29,.075);
  --brand: #4a154b;
  --brand-hover: #611f69;
  --accent: #1264a3;
  --link: var(--accent);
  --accent-strong: #0d5590;
  --accent-soft: #e8f5fa;
  --accent-contrast: #ffffff;
  --cta: #007a5a;
  --cta-hover: #148567;
  --cta-contrast: #ffffff;
  --success: #007a5a;
  --success-bg: #e9f7f1;
  --warning: #ecb22e;
  --warning-ink: #6b5000;
  --warning-bg: #fff8e1;
  --danger: #c01343;
  --danger-soft: #fdf0f4;
  --focus: rgba(18,100,163,.30);
  /* Neutral light sidebar: hover darkens instead of lightening. */
  --sidebar-bg: #f8f8f8;
  --sidebar-hover: rgba(29,28,29,.06);
  --sidebar-active: #1264a3;
  --sidebar-text: #454447;
  --sidebar-text-strong: #1d1c1d;
  --sidebar-border: rgba(29,28,29,.10);
  --vault-chip-bg: var(--brand);
  --vault-chip-ink: #ffffff;
  --vault-chip-border: var(--brand);
  --shadow-sm: 0 1px 2px rgba(29,28,29,.10), 0 1px 3px rgba(29,28,29,.06);
  --shadow-md: 0 4px 12px rgba(29,28,29,.12), 0 2px 4px rgba(29,28,29,.06);
  --shadow-lg: 0 12px 32px rgba(29,28,29,.18), 0 4px 10px rgba(29,28,29,.10);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1d21;
  --panel: #212428;
  --panel-2: #212428;
  --editor-bg: #212428;
  --preview-bg: #1a1d21;
  --text: #f8f8f8;
  --muted: #b9babd;
  --faint: #9a9b9e;
  --border: rgba(121,124,129,.42);
  --border-soft: rgba(121,124,129,.28);
  --brand: #4a154b;
  --brand-hover: #611f69;
  --accent: #2ba5ce;
  --link: var(--accent);
  --accent-strong: #5cc2e4;
  --accent-soft: rgba(43,165,206,.16);
  --accent-contrast: #1a1d21;
  --cta: #3daa7c;
  --cta-hover: #5fc39a;
  --cta-contrast: #1a1d21;
  --success: #3daa7c;
  --success-bg: rgba(61,170,124,.14);
  --warning: #dea700;
  --warning-ink: #f0cf74;
  --warning-bg: rgba(222,167,0,.14);
  --danger: #de678a;
  --danger-soft: rgba(222,103,138,.12);
  --focus: rgba(43,165,206,.32);
  --sidebar-bg: #4a154b;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: #1264a3;
  --sidebar-text: rgba(255,255,255,.78);
  --sidebar-text-strong: #ffffff;
  --sidebar-border: rgba(255,255,255,.14);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.40);
  --shadow-md: 0 4px 12px rgba(0,0,0,.48), 0 2px 4px rgba(0,0,0,.32);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.60), 0 4px 12px rgba(0,0,0,.40);
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

[hidden] {
  display: none !important;
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur-base), border-color var(--dur-base), transform var(--dur-fast);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: var(--cta);
  border-color: var(--cta);
  color: var(--cta-contrast);
}

.btn.primary:hover:not(:disabled) {
  background: var(--cta-hover);
  border-color: var(--cta-hover);
}

.btn.ghost {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn.danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}

.btn.danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn.wide {
  width: 100%;
  height: 42px;
}

.linkish {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.linkish:hover {
  color: var(--accent-strong);
}

/* Every text-entry control gets the same height and horizontal padding, so
   text never touches the border. This also covers type="email" and inputs
   with no explicit type (the restore-vault key/salt fields). Borderless
   editor fields (.title-input, .tags-input, .body-input) override this box
   further down the file. */
input:not([type="checkbox"]):not([type="radio"]),
textarea {
  width: 100%;
  height: var(--input-height);
  padding: 0 var(--input-pad-x);
  line-height: 1.4;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-base), box-shadow var(--dur-base);
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

input[type="file"] {
  height: auto;
  padding: var(--sp-3);
  font-size: 13px;
}

input[type="file"]::file-selector-button {
  margin-right: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

/* Focus is a double ring: a saturated 1px edge plus a translucent halo. */
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--focus);
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

.btn:focus-visible,
.note-item:focus-visible,
.tag-row:focus-visible,
.tab:focus-visible,
.linkish:focus-visible,
.view-btn:focus-visible,
.chip:focus-visible,
.tab-open:focus-visible,
.tab-close:focus-visible,
.menu-item:focus-visible,
.wiki-link:focus-visible,
.graph-node:focus-visible,
.dropdown-item:focus-visible,
.empty-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Brand --------------------------------------------------------------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, var(--brand-hover), var(--brand));
  box-shadow: var(--shadow-sm);
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  line-height: 1;
  user-select: none;
}

.brand-name {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-small .brand-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-lg);
  font-size: 18px;
}

.brand-small .brand-name {
  font-size: 16px;
}

/* --- Gate / onboarding --------------------------------------------------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--sp-8) var(--sp-6);
  background:
    radial-gradient(1100px 560px at 50% -12%, var(--accent-soft), transparent 62%),
    var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 520px;
  padding: var(--ws-card-lg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-md);
}

.gate-card.wide-card {
  max-width: 680px;
}

.gate-card h1 {
  margin: var(--sp-6) 0 var(--sp-3);
  font-size: 34px;
  line-height: 1.14;
  letter-spacing: -0.035em;
  font-weight: 780;
}

.lede {
  margin: 0 0 var(--sp-6);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.62;
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* Welcome choices: two equal-width buttons per row. */
.gate-actions .btn {
  flex: 1 1 calc(50% - var(--sp-2));
  min-width: 0;
}

/* Account form: sign-in / sign-up selector sits above the fields. */
.account-switch.tabs {
  display: flex;
  width: 100%;
}

.account-switch .tab {
  flex: 1 1 0;
  font-weight: 600;
}

.gate-form {
  margin-top: var(--sp-6);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--border);
}

.gate-form:empty {
  display: none;
}

.gate-footer {
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  text-align: center;
}

.stack {
  display: grid;
  gap: var(--sp-4);
}

.field {
  display: grid;
  gap: var(--ws-row-y);
}

/* Author styles override the UA [hidden] rule, so make it explicit. */
.field[hidden] {
  display: none;
}

.field label {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.hint {
  margin: 0;
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.55;
}

.hint.warning {
  margin-top: var(--sp-6);
  padding: var(--sp-3) var(--ws-card);
  border: 1px solid var(--warning);
  border-radius: var(--radius-lg);
  background: var(--warning-bg);
  color: var(--warning-ink);
}

.form-error {
  margin: 0;
  padding: var(--ws-row-group-y) var(--ws-row-y);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.45;
}

.form-error:empty {
  display: none;
}

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.pin-input {
  height: calc(var(--input-height) + var(--sp-1));
  font-family: var(--mono);
  font-size: 18px;
  letter-spacing: 0.35em;
  text-align: center;
}

.inline-code {
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 12.5px;
}

.busy {
  opacity: 0.75;
}

/* --- Recovery kit -------------------------------------------------------- */

.recovery-list {
  display: grid;
  gap: var(--sp-3);
  margin: var(--sp-6) 0;
}

.recovery-list > div {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: start;
}

.recovery-list dt {
  padding-top: var(--sp-2);
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.recovery-list dd {
  margin: 0;
  min-width: 0;
}

.recovery-list code {
  display: block;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  user-select: all;
}

.recovery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* --- App shell ----------------------------------------------------------- */

.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: 64px;
  padding: var(--sp-2) var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

/* Left and right groups take equal flex space so the view switch in the
   middle stays centered regardless of their content widths. */
.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex: 1 1 0;
  min-width: 0;
}

.topbar-search {
  flex: 1 1 auto;
  max-width: 460px;
}

.topbar-search input {
  height: 36px;
  border-radius: var(--radius-pill);
  background: var(--panel-2);
  padding: 0 var(--sp-4);
  font-size: 13.5px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  flex: 1 1 0;
  margin-left: 0;
}

.workspace {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 0;
}

/* --- Sidebar ------------------------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-6) var(--sp-3);
}

.vault-chip {
  padding: var(--ws-row-group-y) var(--ws-leaf-x);
  border: 1px solid var(--vault-chip-border);
  border-radius: var(--radius-pill);
  background: var(--vault-chip-bg);
  color: var(--vault-chip-ink);
  font-family: var(--mono);
  font-size: 11.5px;
  user-select: all;
}

.vault-label {
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-6) var(--sp-3);
  border-bottom: 1px solid var(--border);
  max-height: 34%;
  overflow-y: auto;
}

.tag-row {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 32px;
  padding: var(--ws-row-y) var(--ws-leaf-x);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-base), border-color var(--dur-base);
}

.tag-row:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tag-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.tag-count {
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
}

.note-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.note-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--ws-row-y) var(--ws-leaf-x);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-base), border-color var(--dur-base);
}

/* Consecutive notes compress to a 4px continuation row (Slack grouping cue). */
.note-item + .note-item {
  padding-top: var(--ws-row-group-y);
}

.note-item:hover {
  border-color: var(--border);
  background: var(--panel);
}

.note-item.active {
  border-color: var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.note-item-title {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item-snippet {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}

.note-date {
  color: var(--faint);
  font-size: 11px;
}

.mini-tag {
  padding: var(--ws-row-group-y) var(--ws-row-y);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 10.5px;
  font-weight: 600;
}

.list-empty {
  padding: var(--ws-card-lg) var(--ws-pane-x);
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.65;
  text-align: center;
}

/* --- Editor -------------------------------------------------------------- */

.editor {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0.5em;
  background: var(--editor-bg);
}

.editor.preview-mode {
  background: var(--preview-bg);
}

.editor-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0 var(--ws-pane-x);
}

.title-input {
  /* width:auto lets the flex container stretch the input without overflowing
     its 0.3em margins (a width:100% would add the margins on top). */
  width: auto;
  margin: var(--editor-space);
  height: 2em;
  line-height: 2em;
  padding: 0 var(--sp-4);
  text-align: center;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 30px;
  font-weight: 760;
  letter-spacing: -0.03em;
  outline: none;
}

.title-input:focus {
  border-color: transparent;
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--focus);
}

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

.editor-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4) var(--sp-2);
  margin-inline: var(--editor-inset);
  border-bottom: 1px solid var(--border);
}

.tags-field {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 32px;
}

.tags-input {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  outline: none;
}

.tags-input:focus {
  border-color: transparent;
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--focus);
}

.tags-field.blurred .tags-input {
  display: none;
}

.tag-chips {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  width: 100%;
  min-width: 0;
  cursor: text;
}

.tag-chips:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

.tags-field.blurred .tag-chips {
  display: flex;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 24px;
  margin-right: 0.6em;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-pill);
  color: #fff;
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* CSP-safe palette (style-src 'self' blocks inline styles). Keep in sync with
   TAG_COLORS in app.js. */
.tag-chip.color-0 { background: #1d4ed8; }
.tag-chip.color-1 { background: #0f766e; }
.tag-chip.color-2 { background: #7c3aed; }
.tag-chip.color-3 { background: #be123c; }
.tag-chip.color-4 { background: #b45309; }
.tag-chip.color-5 { background: #15803d; }
.tag-chip.color-6 { background: #334155; }
.tag-chip.color-7 { background: #9333ea; }
.tag-chip.color-8 { background: #0369a1; }
.tag-chip.color-9 { background: #a21caf; }

.tags-placeholder {
  color: var(--faint);
  font-size: 12.5px;
}

.save-status {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 11px;
  white-space: nowrap;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--sp-3) var(--editor-inset) var(--sp-2);
  padding: 0 var(--ws-card);
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  padding: var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
}

.tab {
  padding: var(--sp-2) var(--sp-3);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.body-input {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: var(--ws-card);
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.72;
  outline: none;
  resize: none;
}

.body-input:focus {
  border-color: transparent;
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--focus);
}

.preview {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--ws-card) var(--ws-card) var(--ws-scroll-tail);
  background: var(--preview-bg);
}

.editor-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--sp-4);
  height: 100%;
  padding: var(--sp-6);
  color: var(--muted);
  text-align: center;
}

.empty-mark {
  font-size: 44px;
  line-height: 1;
  opacity: 0.35;
}

.editor-empty p {
  margin: 0 0 var(--sp-2);
  font-size: 13.5px;
}

.editor-empty .hint {
  max-width: 430px;
  margin-bottom: var(--sp-4);
}

/* --- Markdown ------------------------------------------------------------ */

.markdown {
  color: var(--text);
  font-size: 15px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 1.45em 0 0.55em;
  font-weight: 730;
  line-height: 1.28;
  letter-spacing: -0.02em;
}

.markdown h1 { font-size: 1.85em; }
.markdown h2 { font-size: 1.5em; }
.markdown h3 { font-size: 1.25em; }
.markdown h4 { font-size: 1.08em; }
.markdown h5,
.markdown h6 { font-size: 1em; color: var(--muted); }

.markdown p {
  margin: 0 0 1em;
}

.markdown ul,
.markdown ol {
  margin: 0 0 1em;
  padding-left: 1.45em;
}

.markdown li {
  margin: 0.22em 0;
}

.markdown blockquote {
  margin: 1em 0;
  padding: 0.15em 0 0.15em 1em;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.markdown code {
  padding: 0.12em 0.35em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 0.87em;
}

.markdown pre {
  margin: 0 0 1em;
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
}

.markdown pre code {
  padding: 0;
  border: none;
  background: none;
  font-size: 12.5px;
  line-height: 1.65;
}

.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown hr {
  margin: 1.6em 0;
  border: none;
  border-top: 1px solid var(--border);
}

.markdown del {
  opacity: 0.7;
}

/* --- View switch, tabs and graph ---------------------------------------- */

.view-switch {
  display: inline-flex;
  flex: 0 0 auto;
  margin-inline: auto;
  padding: var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
}

.view-btn {
  padding: var(--sp-2) var(--sp-3);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.view-btn.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.editor-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.tabbar {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: var(--sp-1);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-6) 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  overflow-x: auto;
}

.tabbar-empty {
  align-self: center;
  padding: 0 var(--sp-2);
  color: var(--faint);
  font-size: 11.5px;
}

.note-tab {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  max-width: 210px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  color: var(--muted);
}

.note-tab.active {
  border-color: var(--border);
  background: var(--bg);
  color: var(--text);
}

.tab-open {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  max-width: 180px;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-3);
  border: none;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.tab-close {
  flex: 0 0 auto;
  width: 24px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--faint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.tab-close:hover {
  color: var(--danger);
}

.editor-hint {
  color: var(--faint);
  font-size: 11px;
  white-space: nowrap;
}

.wiki-link {
  color: var(--accent) !important;
  border-bottom: 1px dashed var(--accent);
  text-decoration: none !important;
}

.wiki-missing {
  color: var(--faint);
  border-bottom: 1px dotted var(--faint);
}

.graph-view {
  display: grid;
  grid-column: 1 / -1;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: var(--sp-4);
  background: var(--bg);
}

.graph-focus {
  display: flex;
  flex-direction: column;
  width: min(1600px, 100%);
  height: min(92dvh, 980px);
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-md);
}

.graph-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6) var(--sp-3);
}

.graph-toolbar h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.graph-toolbar .hint {
  margin: var(--sp-1) 0 0;
  font-size: 11.5px;
}

.graph-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.chip {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.graph-canvas {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  touch-action: none;
  cursor: grab;
}

.graph-canvas:active {
  cursor: grabbing;
}

.graph-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-lg);
}

.graph-edge {
  stroke: var(--faint);
  stroke-width: 1.2;
  opacity: 0.4;
}

.graph-edge.link {
  stroke: var(--accent);
  stroke-width: 2;
  opacity: 0.85;
}

/* Graph state colours: thinking = blue, mood/behavior = role B, running = amber. */
.graph-node.thinking circle,
.graph-edge.thinking {
  fill: var(--accent);
  stroke: var(--accent);
}

.graph-node.mood circle,
.graph-node.behavior circle {
  fill: var(--role-b);
}

.graph-node.running circle,
.graph-edge.running {
  fill: var(--warning);
  stroke: var(--warning);
}

.graph-node {
  cursor: pointer;
}

.graph-node circle {
  stroke: var(--panel);
  stroke-width: 2;
  opacity: 0.9;
}

.graph-node:hover circle {
  stroke: var(--text);
  opacity: 1;
}

.graph-node text {
  fill: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 650;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  pointer-events: none;
}

.graph-note {
  margin: 0;
  padding: var(--sp-2) var(--sp-6) var(--sp-3);
  font-size: 11.5px;
  text-align: center;
}

/* Floating, collapsible graph in the bottom-left corner */
.graph-widget {
  position: absolute;
  left: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: 340px;
  max-width: calc(100vw - var(--sp-8));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}

.graph-widget.collapsed {
  width: auto;
  border-radius: var(--radius-pill);
}

.graph-widget-head {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex: 0 0 auto;
  min-height: 40px;
  padding: var(--sp-1) var(--sp-2);
}

.graph-widget-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--sp-2) var(--sp-3);
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.graph-widget-toggle:hover {
  background: var(--panel-2);
}

.graph-widget-icon {
  color: var(--accent);
  font-size: 14px;
}

.graph-widget-chevron {
  color: var(--faint);
  font-size: 10px;
  transition: transform var(--dur-base);
}

.graph-widget.collapsed .graph-widget-chevron {
  transform: rotate(180deg);
}

.graph-widget-count {
  color: var(--faint);
  font-size: 11px;
  white-space: nowrap;
}

.graph-widget-max {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.graph-widget-max:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.graph-widget.collapsed .graph-widget-max,
.graph-widget.collapsed .graph-widget-count {
  display: none;
}

.graph-widget-body {
  display: flex;
  flex-direction: column;
  height: 272px;
  min-height: 0;
  border-top: 1px solid var(--border);
}

.graph-widget.collapsed .graph-widget-body {
  display: none;
}

.graph-widget-tags {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  max-height: 48px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}

.graph-widget-tags .chip {
  flex: 0 0 auto;
  padding: var(--sp-1) var(--sp-3);
  font-size: 10.5px;
}

.graph-widget .graph-stage {
  flex: 1 1 auto;
  min-height: 0;
  margin: var(--sp-1) var(--sp-3) 0;
}

.graph-widget .graph-controls {
  top: var(--sp-1);
  right: var(--sp-2);
  gap: var(--sp-1);
}

.graph-widget .graph-controls button {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

.graph-widget .graph-legend {
  display: none;
}

.graph-widget-foot {
  flex: 0 0 auto;
  padding: var(--sp-1) var(--sp-3);
}

.graph-widget-foot .hint {
  font-size: 10.5px;
}

/* --- Chrome, menus and status -------------------------------------------- */

.topbar-actions {
  flex-wrap: nowrap;
}

.data-menu {
  position: relative;
  flex: 0 0 auto;
}

.data-dropdown {
  position: absolute;
  top: calc(100% + var(--sp-2));
  right: 0;
  z-index: 60;
  width: 290px;
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-md);
}

.dropdown-item {
  display: grid;
  gap: var(--sp-1);
  width: 100%;
  padding: var(--sp-3);
  border: none;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.dropdown-item:hover {
  background: var(--panel-2);
}

.dropdown-item.danger strong {
  color: var(--danger);
}

.dropdown-item strong {
  font-size: 12.5px;
  font-weight: 650;
}

.dropdown-item span {
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.4;
}

.status-pill {
  flex: 0 0 auto;
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

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

.status-pill.warn,
.status-pill.partial {
  border-color: var(--warning);
  background: var(--warning-bg);
  color: var(--warning-ink);
}

.status-pill.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.ok {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-6) var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.filter-bar:empty {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--ws-row-group-y) var(--ws-leaf-x);
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
}

.filter-clear {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.tag-warning {
  margin: 0;
  padding: 0 var(--ws-pane-x) var(--sp-2);
  color: var(--warning-ink);
  font-size: 11.5px;
}

.recovery-gate {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  margin: var(--sp-1) 0 var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
  font-size: 12.5px;
  line-height: 1.45;
  cursor: pointer;
}

.recovery-gate input {
  margin-top: var(--sp-1);
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.modal-card .btn.danger-ghost {
  color: var(--danger);
}

.choice-explain {
  display: block;
  margin-top: var(--sp-1);
  color: var(--faint);
  font-size: 11px;
  line-height: 1.4;
}

.conflict-body-preview {
  max-height: 92px;
  overflow: auto;
  margin: var(--sp-2) 0;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.conflict-row summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
}

.graph-controls {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-6);
  display: flex;
  gap: var(--sp-2);
}

.graph-controls button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.graph-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.graph-legend {
  position: absolute;
  left: var(--sp-6);
  bottom: var(--sp-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--faint);
  font-size: 11px;
}

.graph-legend i {
  display: inline-block;
  width: 14px;
  height: 2px;
  margin-right: var(--sp-2);
  vertical-align: middle;
  background: var(--faint);
}

.graph-legend i.link {
  height: 3px;
  background: var(--accent);
}

.wiki-suggest {
  position: absolute;
  z-index: 55;
  max-width: 320px;
  max-height: 220px;
  overflow-y: auto;
  padding: var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-md);
}

.wiki-suggest button {
  display: block;
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.wiki-suggest button:hover,
.wiki-suggest button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.editor-body-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  margin-inline: var(--editor-inset);
}

.sidebar-toggle {
  display: none;
}

.empty-action {
  margin-top: var(--sp-2);
}

.toast-action {
  margin-left: var(--sp-3);
  padding: 0;
  border: none;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* --- Settings, conflict dialog and drop overlay -------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
  background: rgba(10, 12, 18, 0.55);
}

.modal-card {
  width: min(460px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  padding: var(--ws-pane-x);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

.modal-card h2 {
  margin: 0 0 var(--sp-2);
  font-size: 19px;
  letter-spacing: -0.02em;
}

.modal-card .hint {
  margin: 0 0 var(--sp-4);
  font-size: 12px;
  line-height: 1.55;
}

.setting-heading {
  margin: 0 0 var(--sp-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.setting-options {
  display: grid;
  gap: var(--sp-2);
  margin-bottom: var(--ws-section);
}

.setting-option {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--ws-row-y) var(--ws-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.setting-option .hint {
  margin: 0 0 0 auto;
  font-weight: 400;
}

.setting-option.setting-toggle {
  align-items: flex-start;
}

.setting-option .setting-toggle-note {
  display: block;
  margin-top: var(--sp-1);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--ws-section);
}

.conflict-list {
  display: grid;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.conflict-row {
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
}

.conflict-info {
  display: grid;
  gap: var(--sp-1);
  margin-bottom: var(--sp-2);
  font-size: 13px;
}

.conflict-info .hint {
  margin: 0;
}

.conflict-choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  font-size: 12px;
}

.conflict-choices label {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}

.drop-overlay {
  position: fixed;
  inset: var(--sp-3);
  z-index: 90;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--accent-soft) 88%, transparent);
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  pointer-events: none;
}

/* --- Toast --------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--sp-6);
  z-index: 50;
  max-width: min(560px, calc(100vw - 32px));
  padding: var(--sp-3) var(--sp-6);
  border-radius: var(--radius-lg);
  background: #1a1d21;
  box-shadow: var(--shadow-lg);
  color: #f4f5f7;
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity var(--dur-base), transform var(--dur-base);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: #7c2020;
}

.toast.warn {
  background: #74430f;
}

/* --- Sidebar palette -------------------------------------------------------
   Colour only: the aubergine sidebar uses translucent-white hover and the blue
   accent for the current item; the neutral light sidebar uses dark ink. No
   display, overflow, flex or position declaration is changed here. */
.sidebar .vault-label,
.sidebar .filter-clear,
.sidebar .list-empty,
.sidebar .note-date,
.sidebar .note-item-snippet {
  color: var(--sidebar-text);
}

.sidebar .filter-bar,
.sidebar .tag-list {
  border-bottom-color: var(--sidebar-border);
}

.sidebar .tag-row {
  border-color: var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-text);
}

.sidebar .tag-row:hover {
  border-color: var(--accent);
  background: var(--sidebar-hover);
  color: var(--sidebar-text-strong);
}

.sidebar .tag-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar .filter-chip {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar .note-item {
  color: var(--sidebar-text);
}

.sidebar .note-item:hover {
  border-color: var(--sidebar-border);
  background: var(--sidebar-hover);
}

.sidebar .note-item.active {
  border-color: var(--sidebar-active);
  background: var(--sidebar-active);
  color: #ffffff;
}

.sidebar .mini-tag {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-strong);
}

.sidebar .tag-warning {
  color: var(--warning);
}

:root[data-theme="light"] .sidebar .tag-warning {
  color: var(--warning-ink);
}

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 900px) {
  :root {
    --editor-inset: 7.8px; /* = 0.3em × 26px title font in the existing query */
  }

  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .title-input {
    font-size: 26px;
  }
}

.sidebar.collapsed {
  display: none;
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4);
  }

  /* On narrow screens the search moves to its own row; restore the flat
     topbar flow so the controls still fit. */
  .topbar-left {
    display: contents;
  }

  .topbar-actions {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .view-switch {
    margin-inline: 0;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .brand-name {
    display: none;
  }

  .topbar-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .topbar-actions {
    gap: var(--sp-1);
  }

  .topbar-actions .btn {
    padding: 0 var(--sp-2);
  }

  .view-btn {
    padding: var(--sp-2);
  }

  .editor-hint {
    font-size: 10px;
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .graph-view {
    padding: var(--sp-2);
  }

  .graph-focus {
    height: min(86dvh, 760px);
  }

  .graph-toolbar {
    padding: var(--sp-3) var(--sp-4) var(--sp-2);
  }

  .graph-widget {
    left: var(--sp-3);
    bottom: var(--sp-3);
    width: min(340px, calc(100vw - var(--sp-6)));
  }

  .graph-widget-body {
    height: min(40dvh, 260px);
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    max-height: 38dvh;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .tag-list {
    max-height: 82px;
  }

  .gate-card {
    padding: var(--sp-6) var(--sp-4);
    border-radius: var(--radius-xl);
  }

  .gate-card h1 {
    font-size: 28px;
  }

  .recovery-list > div {
    grid-template-columns: 70px minmax(0, 1fr);
    gap: var(--sp-2);
  }

  .modal-backdrop {
    padding: var(--sp-3);
  }
}

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