/* ============================================================
   app.css — Central stylesheet for Notizen App
   Midnight palette: deep navy dark mode + amber accent
   ============================================================ */

/* ============================================================
   1. DESIGN TOKENS
   ============================================================ */

:root {
  --bg: #f7f6f2;
  --surface: #fdfcf8;
  --surface-2: #f1efe9;
  --line: #e6e3da;
  --line-strong: #d9d5c8;
  --ink: #1a1916;
  --ink-2: #45433d;
  --ink-3: #79766c;
  --ink-4: #a8a59a;
  --accent: oklch(0.62 0.16 55);
  --accent-soft: oklch(0.93 0.05 65);
  --accent-ink: oklch(0.4 0.12 50);
  --lock: oklch(0.78 0.14 80);
  --danger: #dc2626;
  --shadow: 0 1px 0 rgba(20, 18, 12, 0.03), 0 8px 24px -12px rgba(20, 18, 12, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --content-width: 1280px;

  /* Bootstrap compat aliases */
  --bg-color: var(--bg);
  --text-color: var(--ink);
  --card-bg: var(--surface);
  --border-color: var(--line);
  --navbar-bg: var(--surface);
  --navbar-text: var(--ink);
  --sidebar-bg: var(--surface-2);
  --input-bg: var(--surface);
  --input-border: var(--line);
  --tag-bg: var(--accent-soft);
  --tag-text: var(--accent-ink);
  --preview-bg: var(--surface-2);
  --collection-card-bg: var(--surface);
  --collection-card-hover: var(--surface-2);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0f1c;
  --surface: #101728;
  --surface-2: #161e33;
  --line: #1f2a44;
  --line-strong: #2c3a5a;
  --ink: #e8edf7;
  --ink-2: #b3bdd1;
  --ink-3: #9098ad;
  --ink-4: #4e5a76;
  --accent: #f59e3b;
  --accent-soft: oklch(0.3 0.08 50);
  --accent-ink: oklch(0.85 0.15 60);
  --lock: oklch(0.78 0.14 80);
  --danger: #f87171;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 12px 32px -16px rgba(0, 0, 0, 0.5);

  --bg-color: var(--bg);
  --text-color: var(--ink);
  --card-bg: var(--surface);
  --border-color: var(--line);
  --navbar-bg: var(--surface);
  --navbar-text: var(--ink);
  --sidebar-bg: var(--surface-2);
  --input-bg: var(--surface);
  --input-border: var(--line);
  --tag-bg: var(--accent-soft);
  --tag-text: var(--accent-ink);
  --preview-bg: var(--surface-2);
  --collection-card-bg: var(--surface);
  --collection-card-hover: var(--surface-2);
}

/* ============================================================
   2. BASE & RESET
   ============================================================ */

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.2s ease, color 0.2s ease;
  overflow-x: hidden;
  word-wrap: break-word;
  min-height: 100vh;
}

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

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
  border: 2px solid var(--bg);
}

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

/* ============================================================
   3. TYPOGRAPHY
   ============================================================ */

a {
  text-decoration: none;
}

a:hover,
a:focus {
  text-decoration: none;
}

a:not([class]):hover,
a:not([class]):focus {
  text-decoration: underline;
  text-underline-offset: 3px;
  color: color-mix(in oklab, var(--accent) 85%, #fff);
}

a {
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

code {
  color: var(--accent);
  font-family: 'JetBrains Mono', 'Fira Mono', ui-monospace, monospace;
}

.mono {
  font-family: 'JetBrains Mono', 'Fira Mono', ui-monospace, monospace;
}

/* ============================================================
   4. LAYOUT
   ============================================================ */

.container-fluid {
  max-width: var(--content-width);
  margin-left: auto;
  margin-right: auto;
}

@media (max-width: 1280px) {
  .container-fluid {
    max-width: 100%;
  }
}

.main-content {
  min-height: calc(100vh - 56px);
  padding: clamp(.25rem, 1vw, .75rem) clamp(.5rem, 2vw, 1.5rem) ;
  max-width: var(--content-width);
  margin: 0 auto;
}

/* ============================================================
   5. TOPBAR & SIDEBAR
   ============================================================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 clamp(.5rem, 2vw, 1.5rem);
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}

.topbar-logo:hover {
  text-decoration: none;
  color: var(--ink);
}

.topbar-logo-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.topbar-logo-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.topbar-sep {
  color: var(--ink-4);
  font-size: 18px;
  line-height: 1;
  margin: 0 -4px;
}

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

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
  white-space: nowrap;
}

.topbar-btn:hover,
.topbar-btn:focus {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  outline: none;
}

.topbar-spacer {
  flex: 1;
}

.topbar-icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-2);
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
  font-family: inherit;
}

.topbar-icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.topbar-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #1a1208;
  border: none;
  padding: 7px 12px 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08), 0 6px 16px -4px color-mix(in oklab, var(--accent) 40%, transparent);
  transition: background 0.12s, box-shadow 0.12s, color 0.12s;
  white-space: nowrap;
  font-family: inherit;
  flex-shrink: 0;
}

.topbar-btn-primary:hover,
.topbar-btn-primary:focus {
  background: color-mix(in oklab, var(--accent) 90%, #fff);
  color: #1a1208;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08), 0 0 12px color-mix(in oklab, var(--accent) 60%, transparent);
}

.topbar-keycap {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, .12);
  margin-left: 4px;
  opacity: 0.65;
}

.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--line);
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
  transition: background 0.12s;
  flex-shrink: 0;
}

.topbar-user:hover {
  background: var(--surface-2);
}

.topbar-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
}

/* Topbar dropdown */
.topbar-dropdown {
  position: relative;
}

.topbar-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 40;
}

.topbar-dropdown-menu.align-right {
  left: auto;
  right: 0;
}

.topbar-dropdown-menu.is-open {
  display: block;
}

.topbar-dropdown-label {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 8px 4px;
  display: block;
}

.topbar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
  text-decoration: none;
  transition: background 0.1s;
  text-align: left;
}

.topbar-dropdown-item:hover,
.topbar-dropdown-item:focus {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  outline: none;
}

.topbar-dropdown-item .item-sub {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 1px;
}

.topbar-dropdown-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}

/* Hamburger (mobile only) */
.topbar-hamburger {
  display: none;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-2);
  font-family: inherit;
}

/* Mobile nav flyout */
.topbar-mobile-menu {
  display: none;
  flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px 16px;
  gap: 2px;
}

.topbar-mobile-menu.is-open {
  display: flex;
}

.topbar-mobile-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 14px;
  text-decoration: none;
  transition: background 0.1s;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  width: 100%;
  text-align: left;
}

.topbar-mobile-item:hover {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}

.topbar-mobile-sub {
  padding-left: 44px;
  font-size: 13px;
}

.topbar-mobile-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}


.note-detail-grid,
.note-form-grid {
  display: grid;
  grid-template-columns: 5fr minmax(0, 2fr);
  gap: clamp(1rem, 2vw, 1.5rem);
  align-items: start;
}

.note-detail-content,
.note-detail-grid > *:first-child,
.note-form-grid > *:first-child {
  min-width: 0;
}

.note-detail-sidebar {
  display: grid;
  gap: clamp(0.75rem, 3vw, 1rem);
  min-width: 0;
  overflow-wrap: anywhere;
}

.note-detail-sidebar img {
  max-width: 100%;
  height: auto;
}

.note-detail-sidebar .card {
  margin-bottom: 0;
}

.note-action-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 767px) {
  .note-detail-grid {
    grid-template-columns: 1fr;
  }
  .topbar-logo-name {
    display: none;
  }
  .topbar-user > span,
  .topbar-user > i {
    display: none;
  }
  .topbar-user {
    padding: 3px;
  }
}

.centered-form {
  max-width: 540px;
  margin-inline: auto;
}

.centered-form--narrow {
  max-width: 400px;
  margin-inline: auto;
}
.revision-item-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: clamp(0.5rem, 3vw, 1rem);
  align-items: start;
}

.notes-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: clamp(1rem, 4vw, 1.5rem);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn-stack {
  display: grid;
  gap: 0.5rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: clamp(1rem, 4vw, 1.5rem);
}

.hide-sm {
  display: none;
  margin-left: 0.25rem;
}

.hide-md {
  display: none;
}

.immich-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.5rem;
}

.immich-picker-placeholder {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-3);
  padding: 1.5rem 0;
}

.immich-search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.immich-search-bar button {
  flex-shrink: 0;
}

.alert-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.alert-row--start {
  align-items: flex-start;
}

.lightbox-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
}

.immich-selected-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

@media (max-width: 991px) {
  .note-form-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 576px) {
  .hide-sm { display: inline; }
}

@media (min-width: 768px) {
  .hide-md { display: inline; }
}

.sidebar-column .tag-link,
.note-detail-sidebar .tag-link {
  margin-bottom: .4em;
}

.sidebar-column .tag-link:hover,
.note-detail-sidebar .tag-link:hover {
  text-decoration: none;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-item {
  margin-bottom: .4em;
  line-height: 1.2;
  list-style: none;
}

.toc-level-1 { padding-left: 0; }
.toc-level-2 { padding-left: 1rem; }
.toc-level-3 { padding-left: 2rem; font-size: 0.875em; }
.toc-level-4 { padding-left: 3rem; }
.toc-level-5 { padding-left: 4rem; }
.toc-level-6 { padding-left: 5rem; }


/* ============================================================
   6. COMPONENTS
   ============================================================ */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.4rem 0.85rem;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s, box-shadow 0.12s;
  vertical-align: middle;
  user-select: none;
  -webkit-user-select: none;
}

.btn:focus {
  outline: none;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  pointer-events: none;
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1208;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-primary:hover,
.btn-primary:focus {
  background: color-mix(in oklab, var(--accent) 90%, #fff);
  border-color: color-mix(in oklab, var(--accent) 90%, #fff);
  color: #1a1208;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 0 12px color-mix(in oklab, var(--accent) 60%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.btn-primary:active {
  background: color-mix(in oklab, var(--accent) 85%, #000);
  border-color: color-mix(in oklab, var(--accent) 85%, #000);
  color: #1a1208;
  text-decoration: none;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink-2);
}

.btn-secondary:hover,
.btn-secondary:focus {
  background: var(--line);
  color: var(--ink);
  text-decoration: none;
}

.btn-danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.btn-danger:hover,
.btn-danger:focus {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
  text-decoration: none;
}

.btn-success {
  background: #059669;
  border-color: #059669;
  color: #fff;
}

.btn-success:hover,
.btn-success:focus {
  background: #047857;
  border-color: #047857;
  color: #fff;
  text-decoration: none;
}

.btn-saved {
  background: color-mix(in oklab, var(--accent) 90%, #fff) !important;
  border-color: color-mix(in oklab, var(--accent) 90%, #fff) !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18), 0 0 12px color-mix(in oklab, var(--accent) 60%, transparent), inset 0 1px 0 rgba(255,255,255,0.22) !important;
  pointer-events: none;
}

.btn-dark {
  background: #1a1a1a;
  border-color: #1a1a1a;
  color: #fff;
}

.btn-dark:hover,
.btn-dark:focus {
  background: #333;
  border-color: #333;
  color: #fff;
  text-decoration: none;
}

.btn-outline-primary {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
  background: var(--accent);
  color: #1a1208;
  text-decoration: none;
}

.btn-outline-secondary {
  color: var(--ink-2);
  border-color: var(--line);
  background: transparent;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
  text-decoration: none;
}

.btn-outline-danger {
  color: #dc2626;
  border-color: #dc2626;
  background: transparent;
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
  text-decoration: none;
}

.btn-outline-success {
  color: #059669;
  border-color: #059669;
  background: transparent;
}

.btn-outline-success:hover,
.btn-outline-success:focus {
  background: #059669;
  border-color: #059669;
  color: #fff;
  text-decoration: none;
}

.btn-outline-info {
  color: #0891b2;
  border-color: #0891b2;
  background: transparent;
}

.btn-outline-info:hover,
.btn-outline-info:focus {
  background: #0891b2;
  border-color: #0891b2;
  color: #fff;
  text-decoration: none;
}

.btn-outline-dark {
  color: var(--ink);
  border-color: var(--line-strong);
  background: transparent;
}

.btn-outline-dark:hover,
.btn-outline-dark:focus {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}

.btn-outline-light {
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(255, 255, 255, 0.4);
  background: transparent;
}

.btn-outline-light:hover,
.btn-outline-light:focus {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  text-decoration: none;
}

[data-theme="dark"] .btn-secondary {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink-2);
}

[data-theme="dark"] .btn-secondary:hover {
  background: var(--line);
  color: var(--ink);
}

[data-theme="dark"] .btn-outline-danger {
  color: #f87171;
  border-color: #f87171;
}

[data-theme="dark"] .btn-outline-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.btn-group {
  display: inline-flex;
}

.btn-group>.btn {
  border-radius: 0;
}

.btn-group>.btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.btn-group>.btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-group>.btn+.btn {
  margin-left: -1px;
}

.btn-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-2);
  opacity: 0.65;
  border-radius: 4px;
  transition: opacity 0.12s, background 0.12s;
  font-size: 20px;
  line-height: 1;
  font-family: inherit;
}

.btn-close::before {
  content: '×';
}

.btn-close:hover {
  opacity: 1;
  background: var(--surface-2);
}

.btn-close-white {
  color: rgba(255, 255, 255, 0.85);
}

.btn-close-white:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  overflow: clip;
}

.card-header {
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.card-header h5,
.card-header h4 {
  margin: 0;
  font-size: 15px;
}

.card-body {
  padding: 1rem;
}

.card-body p {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.card-body p:last-child {
  margin-bottom: 0;
}

.card-footer {
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
}

.card-title {
  margin-bottom: 0.5rem;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.card-text {
  color: var(--ink-2);
  margin-bottom: 0.5rem;
}

/* --- Alerts --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  margin-bottom: 1rem;
}

.alert-info {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
}

.alert-success {
  background: #d1fae5;
  border-color: #6ee7b7;
  color: #065f46;
}

.alert-warning {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}

.alert-danger {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.alert-dismissible {
  padding-right: 3rem;
  position: relative;
}

.alert-dismissible .btn-close {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
}

.fade {
  transition: opacity 0.15s;
}

[data-theme="dark"] .alert-info {
  background: color-mix(in oklab, #3b82f6 10%, var(--surface));
  border-color: color-mix(in oklab, #3b82f6 30%, var(--line));
  color: #93c5fd;
}

[data-theme="dark"] .alert-success {
  background: color-mix(in oklab, #10b981 10%, var(--surface));
  border-color: color-mix(in oklab, #10b981 30%, var(--line));
  color: #6ee7b7;
}

[data-theme="dark"] .alert-warning {
  background: color-mix(in oklab, #f59e0b 10%, var(--surface));
  border-color: color-mix(in oklab, #f59e0b 30%, var(--line));
  color: #fcd34d;
}

[data-theme="dark"] .alert-danger {
  background: color-mix(in oklab, #ef4444 10%, var(--surface));
  border-color: color-mix(in oklab, #ef4444 30%, var(--line));
  color: #fca5a5;
}

/* --- Form controls --- */
.form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.form-text {
  display: block;
  margin-top: 0.25rem;
  font-size: 12px;
  color: var(--ink-3);
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  appearance: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent);
}

.form-control::placeholder {
  color: var(--ink-4);
}

.form-control-lg {
  padding: 0.55rem 0.9rem;
  font-size: 16px;
}

/* --- Badge --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2em 0.6em;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
  line-height: 1.2;
}

.bg-primary {
  background: var(--accent) !important;
  color: #1a1208 !important;
}

.bg-success {
  background: #059669 !important;
  color: #fff !important;
}

.bg-warning {
  background: #d97706 !important;
  color: #1a1208 !important;
}

.bg-dark {
  background: #111 !important;
  color: #fff !important;
}

.bg-light {
  background: var(--surface-2) !important;
  color: var(--ink) !important;
}

/* --- Breadcrumb --- */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 0;
  margin: .5rem 0 .8rem;
  list-style: none;
  font-size: 13px;
  background: transparent;
}

.breadcrumb-item+.breadcrumb-item::before {
  content: '/';
  padding: 0 0.4rem;
  color: var(--ink-4);
}

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

.breadcrumb-item a:hover {
  text-decoration: underline;
}

.breadcrumb-item.active {
  color: var(--ink-3);
}

/* --- Table --- */
.table {
  width: 100%;
  border-collapse: collapse;
  color: var(--ink);
}

.table th,
.table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.table th {
  font-weight: 600;
  background: var(--surface-2);
}

.table-striped tbody tr:nth-of-type(odd) {
  background: color-mix(in oklab, var(--surface-2) 50%, transparent);
}

[data-theme="dark"] .table {
  color: var(--ink);
}

[data-theme="dark"] .table th,
[data-theme="dark"] .table td {
  border-color: var(--line);
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: center;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 4px;
}

.page-item {
  display: flex;
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.12s;
}

.page-link:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}

.page-item.active .page-link {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1208;
  font-weight: 600;
}

.page-item.disabled .page-link {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-4);
  pointer-events: none;
}

/* --- Modal --- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1050;
  background: rgba(0, 0, 0, 0.55);
  align-items: flex-start;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.modal.show {
  opacity: 1;
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 1.5rem auto;
  pointer-events: none;
}

.modal-dialog-centered {
  display: flex;
  align-items: center;
  min-height: calc(100% - 3rem);
}

.modal-dialog-scrollable {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
}

.modal-dialog-scrollable .modal-content {
  overflow: hidden;
  max-height: inherit;
}

.modal-dialog-scrollable .modal-body {
  overflow-y: auto;
}

.modal-xl {
  max-width: 1140px;
}

.modal-fullscreen {
  max-width: 100%;
  width: 100%;
  margin: 0;
  min-height: 100vh;
  padding: 0;
}

.modal-fullscreen .modal-content {
  min-height: 100vh;
  border-radius: 0;
}

.modal-content {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  color: var(--ink);
  width: 100%;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--line);
  gap: 0.5rem;
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.modal-body {
  padding: 1rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* --- Dropdown --- */
.dropdown-menu {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.dropdown-item {
  color: var(--ink);
  border-radius: 6px;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--surface-2);
  color: var(--ink);
}

.dropdown-divider {
  border-top: 1px solid var(--line);
}

/* --- Misc --- */
.text-muted {
  color: var(--ink-3) !important;
}

[data-theme="dark"] a:not([class]){
  color: var(--accent);
}

[data-theme="dark"] a:not([class]):hover {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ============================================================
   7. TAG CHIPS
   ============================================================ */

.tag-chip,
.tag-link,
.tag-display {
  display: inline-flex;
  align-items: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-3);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  user-select: auto;
}

.tag-link:hover,
.tag-chip:hover {
  background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 30%, var(--line));
  color: var(--accent-ink);
  text-decoration: none;
}

.tag-chip.is-active,
.tag-link.is-active {
  background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 30%, var(--line));
  color: var(--accent-ink);
}

.tag-autocomplete-dropdown {
  position: fixed;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 9999;
  min-width: 160px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 0;
}

.tag-ac-item {
  padding: 6px 12px;
  cursor: pointer;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.82rem;
  color: var(--ink-2);
  line-height: 1.4;
}

.tag-ac-item:hover,
.tag-ac-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ============================================================
   8. COLLECTION HERO
   ============================================================ */

.collection-hero {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(6px, 2vw, 24px) clamp(8px, 1.5vw, 28px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.collection-hero-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

.collection-hero-title {
  margin: 0;
  font-size: clamp(32px, 5.5vw, 44px);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--ink);
}

.collection-hero-desc {
  margin: 10px 0 0;
  color: var(--ink-3);
  font-size: 15px;
  max-width: 560px;
}

.collection-hero-count {
  text-align: right;
  flex-shrink: 0;
}

.collection-hero-count-num {
  font-size: clamp(28px, 4.5vw, 36px);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1;
}

.collection-hero-count-label {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-4);
  margin-top: 6px;
}

/* ============================================================
   9. TOOLBAR
   ============================================================ */

.notes-toolbar {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(8px, 1.5vw, 28px);
}

.notes-toolbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.toolbar-search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  box-sizing: border-box;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.toolbar-search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent);
}

.toolbar-search-icon {
  color: var(--ink-3);
  flex-shrink: 0;
}

.toolbar-search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  min-width: 0;
}

.toolbar-search-input::placeholder {
  color: var(--ink-4);
}

@media (max-width: 768px) {
  .toolbar-search-input {
    width: 100%;
  }
}

.toolbar-search-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-3);
  padding: 0;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.toolbar-search-keycap {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink-4);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 5px;
  flex-shrink: 0;
}

.toolbar-sort-wrap {
  position: relative;
}

.toolbar-tag-suggestions:not([hidden]) {
  display: flex;
}
.toolbar-tag-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px color-mix(in oklab, var(--ink) 10%, transparent);
  padding: 6px;
  flex-wrap: wrap;
  gap: 6px;
}
.toolbar-tag-suggestion {
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.toolbar-tag-suggestion:hover,
.toolbar-tag-suggestion.is-focused {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.toolbar-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  box-sizing: border-box;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 13px;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.12s;
}

.toolbar-sort-btn:hover {
  background: var(--surface-2);
}

.toolbar-sort-btn.active {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line-strong);
}

.toolbar-sort-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}

.toolbar-sort-menu.is-open {
  display: block;
}

.toolbar-sort-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  transition: background 0.1s;
}

.toolbar-sort-option:hover,
.toolbar-sort-option:focus {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}

.toolbar-sort-option.active {
  background: var(--surface-2);
}

.toolbar-view-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
  height: 36px;
}

.toolbar-view-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-3);
  transition: background 0.12s, color 0.12s;
}

.toolbar-view-btn.active {
  background: var(--surface-2);
  color: var(--ink);
}

/* ============================================================
   10. NOTE GRID / LIST
   ============================================================ */

.notes-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(6px, 2vw, 22px) clamp(8px, 1.5vw, 28px) clamp(40px, 8vw, 80px);
}

.notes-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.note-card {
  --card-pad-x: clamp(16px, 2.5vw, 20px);
  --card-pad-y: clamp(14px, 2.25vw, 18px);
  position: relative;
  padding: var(--card-pad-y) var(--card-pad-x);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  color: var(--ink);
}

.note-card:hover,
.todo-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in oklab, var(--accent) 35%, var(--line));
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04),
    0 12px 24px -16px color-mix(in oklab, var(--accent) 50%, transparent);
  color: var(--ink);
  text-decoration: none;
}

.note-card-link {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.note-card-tags,
.note-card-menu-btn,
.note-card-badges {
  position: relative;
  z-index: 2;
}

.note-card-pinstripe {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
}

.note-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.note-card-title,
.todo-title {
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.35;
  color: var(--ink);
}
.note-card-title {
  margin: 0;
  font-size: 20px;
  color: var(--ink) !important; /* beats [data-theme="dark"] a */
}

.note-card-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-3);
  flex-shrink: 0;
}

.note-card-lock {
  color: var(--lock);
}

.note-card-excerpt,
.todo-desc {
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-card-excerpt {
  margin: 0;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.note-card-tags,
.todo-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  pointer-events: none;
}

.note-card-tags .tag-chip,
.todo-tags .tag-chip,
.todo-tags .ctx-chip,
.todo-tags .note-link-row-chip {
  pointer-events: auto;
}

.note-card-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-3);
  font-size: 11.5px;
}

.note-card-footer-time {
  display: flex;
  align-items: center;
  gap: 5px;
}

.note-card-footer-date {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--ink-4);
  transition: color 0.15s;
}

.note-card:hover .note-card-footer-date {
  color: var(--accent);
}

.note-card-menu-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-4);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.note-card-menu-btn:hover,
.note-card-menu-btn.is-active {
  background: var(--line);
  color: var(--ink);
}

.note-card-dropdown {
  position: fixed;
  z-index: 300;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 4px;
  min-width: 150px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: none;
}


.note-card-dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--ink-2);
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}

.note-card-dropdown-item:hover {
  background: var(--line);
  color: var(--ink);
  text-decoration: none;
}

/* List view */
.notes-list-inner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.note-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s;
  text-decoration: none;
  color: inherit;
}

.note-row:last-child {
  border-bottom: none;
}

[data-theme="dark"] a.note-row,
[data-theme="dark"] a.note-row:hover,
[data-theme="dark"] a.note-row:visited {
  color: var(--ink);
  text-decoration: none;
}

.note-row:hover {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}

.note-row-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
}

.note-row-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.note-row-body {
  min-width: 0;
}

.note-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}

.note-row-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.note-row-excerpt {
  font-size: 12.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row-meta {
  font-size: 12px;
  color: var(--ink-3);
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Custom image on card */
.note-card-image {
  width: calc(100% + 2 * var(--card-pad-x));
  height: 180px;
  object-fit: cover;
  object-position: center;
  margin: calc(-1 * var(--card-pad-y)) calc(-1 * var(--card-pad-x)) 0;
  border-bottom: 1px solid var(--line);
  display: block;
}

/* ============================================================
   11. EMPTY STATE
   ============================================================ */

.empty-state {
  padding: 80px 20px;
  text-align: center;
  color: var(--ink-3);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 20px;
  color: var(--ink-3);
}

.empty-state-title {
  font-size: 16px;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.empty-state-desc {
  font-size: 13px;
}

/* ============================================================
   12. COLLECTION CARDS (dashboard)
   ============================================================ */

.collections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.collection-card {
  position: relative;
  padding: clamp(14px, 2.5vw, 20px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--ink);
}

.collection-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in oklab, var(--accent) 35%, var(--line));
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04),
    0 12px 24px -16px color-mix(in oklab, var(--accent) 50%, transparent);
}

.collection-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.collection-card-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.collection-card-header .collection-icon {
  font-size: 20px;
  margin-right: 0;
  color: var(--accent);
}

.collection-card-header .collection-icon-img {
  width: 22px;
  height: 22px;
  margin-right: 0;
}

.collection-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}

.collection-card-desc {
  font-size: 13px;
  color: var(--ink-3);
  margin: 0;
  line-height: 1.5;
  flex: 1;
}

.collection-card-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--ink-3);
}

.collection-card-meta {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}

.collection-card-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: color-mix(in oklab, var(--accent) 12%, transparent);
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.collection-card-action:hover {
  background: color-mix(in oklab, var(--accent) 25%, transparent);
  color: var(--accent);
  text-decoration: none;
}

/* Topbar / sidebar icon sizes (used outside cards) */
.collection-icon {
  font-size: 0.9em;
  margin-right: 4px;
  color: var(--accent);
}

.collection-icon-img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 2px;
}

/* ============================================================
   13. NOTE CONTENT (detail & revision views)
   ============================================================ */

.note-content {
  font-size: 1em;
  line-height: 1.5;
}

h1 {
  margin-top: .5rem;
  margin-bottom: .5rem;
  padding-bottom: 0.5rem;
  font-weight: 600;
  line-height: 1.3;
}

h2 {
  color: var(--ink-3);
  margin-top: .5rem;
  margin-bottom: .5em;
  line-height: 1.3;
}

.note-content blockquote {
  border-left: 4px solid var(--line-strong);
  padding-left: 1rem;
  margin: 1rem 0;
  font-style: italic;
  color: var(--ink-3);
}

.note-content img {
  max-width: 100%;
  height: auto;
  border-radius: 0.375rem;
  margin: 1rem 0;
}

.note-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.note-content th,
.note-content td {
  border: 1px solid var(--line);
  padding: 0.5rem;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.note-content th {
  background-color: var(--surface-2);
  font-weight: 600;
}

.note-content pre[class*="language-"] {
  background-color: #121212;
  padding: 0;
  margin: 1rem 0 1.5rem;
  border-radius: 4px;
}

.note-content pre[class*="language-"] code {
  padding: 1rem 1.5rem;
  margin: 0;
}

.note-content pre code {
  display: block;
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 0.5rem;
  overflow-x: auto;
  line-height: 1.5;
  font-weight: 500;
  font-size: .85rem;
}

.note-content pre {
  padding: 0;
  margin: 1rem 0;
  max-width: 100%;
  overflow-x: auto;
}

.note-content code:not(pre code) {
  background-color: color-mix(in oklab, var(--surface-2) 80%, transparent);
  border-radius: 0.25rem;
  padding: 0.3em 0.5em;
  font-weight: 500;
  border: 1px solid color-mix(in oklab, var(--line) 70%, transparent);
  color: var(--accent);
}

.note-content code {
  font-size: .85rem;
}

.note-content ul, 
.note-content ol {
  margin-top: 0;
  padding-left: 1.5rem;
}

.note-content ul p, 
.note-content ol p {
  margin-bottom: 0;
}

/* Task lists */
.note-content ul.task-list {
  list-style: none;
  padding-left: 0;
}

.note-content ul.task-list li {
  display: flex;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  padding-left: 0;
}

.note-content ul.task-list li input[type="checkbox"] {
  margin-right: 0.75rem;
  margin-top: 0.25rem;
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 0.25rem;
  border: 2px solid var(--line-strong);
  appearance: none;
  -webkit-appearance: none;
  background-color: transparent;
  position: relative;
}

.note-content ul.task-list li input[type="checkbox"]:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

.note-content ul.task-list li input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  color: #1a1208;
  font-size: 14px;
  font-weight: bold;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  line-height: 1;
}

.note-content ul.task-list li input[type="checkbox"]:hover {
  border-color: var(--accent);
}

.note-content ul.task-list li span {
  flex: 1;
}

.note-content ul.task-list li input[type="checkbox"]:checked+span {
  text-decoration: line-through;
  opacity: 0.6;
}

/* Immich photo gallery */
.immich-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

@media (min-width: 576px) {
  .immich-gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 992px) {
  .immich-gallery-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.immich-gallery-item img {
  transition: opacity 0.15s;
}

.immich-gallery-item img:hover {
  opacity: 0.85;
}

.copy-feedback {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1050;
  min-width: 250px;
}

/* ============================================================
   14. NOTE FORM — Tiptap editor
   ============================================================ */

.tiptap-editor .ProseMirror{
	padding: clamp(0.5em, 2vw, 1em);
  min-height: 300px;
  max-height: calc(100dvh - 325px);
  overflow-y: auto;
}

.tiptap-editor img{
	max-width: 100%;
	height: auto;
}

.field-label {
  display: none;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0;
  padding: 0 .1rem;
}

.button-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.note-form-buttons-mobile {
  display: none;
}

.note-form-buttons-desktop {
  display: flex;
}

.note-form-buttons {
  gap: 0.5rem;
  flex-wrap: wrap;
  max-width: 100%;
}

.note-form-buttons .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.15s ease;
}

.tiptap-wrapper {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background-color: var(--surface);
}

.tiptap-wrapper.drag-over {
  border: 2px dashed var(--accent);
  background-color: color-mix(in oklab, var(--accent) 5%, transparent);
}

.tiptap-editor.drag-over {
  background-color: color-mix(in oklab, var(--accent) 5%, transparent);
}

.tiptap-menubar {
  display: flex;
  align-items: center;
  gap: 0.27rem;
  padding: 0.25rem;
  background-color: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  border-radius: 0.5rem;
}

.menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.menu-button:hover {
  background: var(--line);
  color: var(--ink);
  border-color: var(--line-strong);
}

.menu-button.is-active {
  background: color-mix(in oklab, var(--accent) 18%, var(--surface-2));
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 40%, var(--line));
}

.menu-divider {
  width: 1px;
  height: 22px;
  background: var(--line-strong);
  margin: 0 2px;
  flex-shrink: 0;
}

.language-selector {
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
}

.ProseMirror table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  table-layout: fixed;
}

.ProseMirror th,
.ProseMirror td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-width: 2rem;
  position: relative;
}

.ProseMirror th {
  background-color: var(--surface-2);
  font-weight: 600;
}

.ProseMirror .selectedCell::after {
  content: '';
  position: absolute;
  inset: 0;
  background-color: color-mix(in oklab, var(--accent) 20%, transparent);
  pointer-events: none;
}

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

.ProseMirror pre {
  background: #272822;
  color: #f8f8f2;
  font-family: 'JetBrains Mono', 'Monaco', 'Courier New', monospace;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 1rem 0;
}

.ProseMirror pre code {
  background: none;
  color: inherit;
  font-size: 0.875rem;
  padding: 0;
}

.ProseMirror .hljs-comment,
.ProseMirror .hljs-quote {
  color: #75715e;
  font-style: italic;
}

.ProseMirror .hljs-keyword,
.ProseMirror .hljs-selector-tag,
.ProseMirror .hljs-literal,
.ProseMirror .hljs-section,
.ProseMirror .hljs-link {
  color: #f92672;
}

.ProseMirror .hljs-string,
.ProseMirror .hljs-title,
.ProseMirror .hljs-name,
.ProseMirror .hljs-type,
.ProseMirror .hljs-attribute,
.ProseMirror .hljs-symbol,
.ProseMirror .hljs-bullet,
.ProseMirror .hljs-built_in,
.ProseMirror .hljs-addition,
.ProseMirror .hljs-variable,
.ProseMirror .hljs-template-variable {
  color: #e6db74;
}

.ProseMirror .hljs-number,
.ProseMirror .hljs-selector-attr,
.ProseMirror .hljs-selector-pseudo {
  color: #ae81ff;
}

.ProseMirror .hljs-function,
.ProseMirror .hljs-class .hljs-title {
  color: #a1efe4;
}

.ProseMirror .hljs-tag,
.ProseMirror .hljs-meta {
  color: #f8f8f2;
}

.ProseMirror .hljs-deletion {
  color: #f92672;
}

.ProseMirror .hljs-emphasis {
  font-style: italic;
}

.ProseMirror .hljs-strong {
  font-weight: bold;
}

/* Tiptap task list in editor */
.ProseMirror ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0;
  margin-left: 0;
}

.ProseMirror ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  list-style: none;
  padding-left: 0;
}

.ProseMirror ul[data-type="taskList"] li > label {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding-top: 0.2em;
}

.ProseMirror ul[data-type="taskList"] li > label > input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.ProseMirror ul[data-type="taskList"] li > label > span {
  display: none;
}

.ProseMirror ul[data-type="taskList"] li > div {
  flex: 1;
  min-width: 0;
}

/* Raw markdown modal */
.raw-editor-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.raw-editor-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 95vw;
  max-height: 95vh;
  background-color: var(--surface);
  border-radius: 0.5rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.raw-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.raw-editor-header h5 {
  margin: 0;
  color: var(--ink);
}

.raw-editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 0;
}

#raw-markdown-textarea {
  width: 100%;
  min-height: 100%;
  font-family: 'JetBrains Mono', 'Monaco', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  border: 1px solid var(--line);
  background-color: var(--surface);
  color: var(--ink);
  padding: 1rem;
  box-sizing: border-box;
}

#raw-markdown-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent);
}

.raw-editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* Markdown preview */
.note-preview {
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  padding: 1rem;
  background-color: var(--surface-2);
  max-height: 400px;
  overflow-y: auto;
}

.markdown-editor {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
}

/* ============================================================
   15. REVISIONS
   ============================================================ */

.revision-item:last-child {
  border-bottom: none !important;
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

.revision-item:hover {
  background-color: var(--surface-2);
  border-radius: 0.375rem;
  padding: 1rem;
  margin-left: -1rem;
  margin-right: -1rem;
}

/* ============================================================
   16. JOURNAL TIMELINE
   ============================================================ */

/* Journal layout */
.journal-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 28px;
  align-items: start;
}

.journal-sidebar {
  position: sticky;
  top: 72px;
}

.journal-sidebar-card {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
}

.journal-sidebar-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.journal-sidebar-card-body {
  padding: 10px 12px;
}

.journal-month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 10px;
}

.journal-month-nav-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.journal-month-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.journal-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}

.journal-nav-btn:hover {
  background: var(--line);
  color: var(--ink);
  text-decoration: none;
}

.journal-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #000;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.journal-new-btn:hover {
  opacity: 0.88;
  color: #000;
  text-decoration: none;
}

.journal-result-count {
  font-size: 13px;
  color: var(--ink-3);
  margin-bottom: 16px;
}

/* Timeline */
.journal-timeline {
  position: relative;
  padding-left: 1.25rem;
}

.journal-timeline::before {
  content: '';
  position: absolute;
  left: 0.2rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  background: var(--line);
  border-radius: 1px;
}

.timeline-day {
  position: relative;
  margin-bottom: 1.75rem;
}

.timeline-date-header {
  margin-bottom: 8px;
  position: relative;
}

.timeline-date-header::before {
  content: '';
  position: absolute;
  left: -1.3rem;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

.timeline-date-badge {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.timeline-entry {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.timeline-entry:hover {
  transform: translateY(-1px);
  border-color: color-mix(in oklab, var(--accent) 35%, var(--line));
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04),
    0 12px 24px -16px color-mix(in oklab, var(--accent) 50%, transparent);
}

.timeline-entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timeline-entry-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  flex: 1;
}

/* stretched link — makes the whole card clickable */
.timeline-entry-title::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 8px;
}

.timeline-entry-title:hover {
  color: var(--accent);
  text-decoration: none;
}

.timeline-entry-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.timeline-entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  position: relative;
  z-index: 1;
}

.timeline-entry-badge {
  font-size: 14px;
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.journal-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-4);
  font-size: 11px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.journal-action-btn:hover {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-color: var(--accent);
}

.mini-calendar {
  width: 100%;
  table-layout: fixed;
}

.mini-calendar th {
  font-size: 0.7rem;
  color: var(--ink);
  opacity: 0.6;
  padding: 2px;
  font-weight: 600;
}

.mini-calendar td {
  font-size: 0.9rem;
  padding: 5px 1px;
  border-radius: 4px;
  line-height: 1;
  vertical-align: top;
  min-width: 28px;
}

.mini-calendar td.cal-today {
  background: var(--accent-soft);
  font-weight: 700;
}

.mini-calendar .cal-day-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: inherit;
  text-decoration: none;
  border-radius: 4px;
  padding: 2px 0;
}

.mini-calendar .cal-day-link:hover {
  background: var(--surface-2);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 30%, transparent);
  text-decoration: none!important;
}

.mini-calendar td.has-entries .cal-day-link {
  font-weight: 700;
  color: var(--accent);
}

.mini-calendar td.cal-empty {
  opacity: 0;
  pointer-events: none;
}

.entry-dot {
  display: block;
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  margin: 2px auto 0;
}

/* ============================================================
   17. MOBILE SIDEBAR
   ============================================================ */

.sidebar-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1040;
  background-color: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}

.sidebar-toggle:hover {
  transform: scale(1.05);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.sidebar-toggle:focus {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent);
  outline: none;
}

#back-to-top {
  position: fixed;
  bottom: 6px;
  right: 6px;
  z-index: 1039;
  background-color: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
  opacity: 0;
}

#back-to-top.visible {
  display: flex;
  opacity: 1;
}

#back-to-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  color: var(--ink);
}

#back-to-top:focus {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent);
  outline: none;
}

.sidebar-flyout {
  position: fixed;
  top: 0;
  right: -100%;
  width: 320px;
  max-width: 85vw;
  height: 100vh;
  background-color: var(--surface-2);
  border-left: 1px solid var(--line);
  z-index: 1050;
  overflow-y: auto;
  transition: right 0.3s ease;
  padding: 70px 15px 15px;
}

.sidebar-flyout.show {
  right: 0;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1045;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

.sidebar-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink);
  cursor: pointer;
  padding: 5px;
  line-height: 1;
}

.sidebar-close:hover {
  color: var(--accent);
}

/* ============================================================
   18. MOBILE
   ============================================================ */

@media (max-width: 768px) {

  .topbar-nav,
  .topbar-version {
    display: none;
  }

  .toolbar-search-keycap,
  .collection-hero-count {
    display: none;
  }

  .topbar-hamburger {
    display: flex;
  }

  .topbar-inner {
    gap: 10px;
  }

  .notes-grid-inner {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .journal-layout {
    grid-template-columns: 1fr;
  }

  .journal-sidebar {
    position: static;
  }

  .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
    max-width: 100%;
  }

  body,
  html {
    overflow-x: clip;
  }

  .card-body,
  .note-content,
  .alert {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .editor-container {
    padding: .3rem;
  }

  a[href^="http"],
  a[href^="mailto:"] {
    word-break: break-all;
    overflow-wrap: break-word;
  }

  pre,
  code {
    white-space: pre-wrap !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
  }

  .breadcrumb {
    flex-wrap: wrap;
  }

  .breadcrumb-item {
    word-break: break-all;
  }

  .form-control {
    max-width: 100%;
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  .tag-link,
  .tag-chip {
    word-break: break-word;
    display: inline-flex;
    max-width: 100%;
  }

  .note-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .note-content th,
  .note-content td {
    white-space: normal;
    min-width: 120px;
  }

  .tiptap-menubar {
    position: sticky;
    top: 56px;
    z-index: 200;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
  }

  .raw-editor-modal {
    padding: 0;
  }

  .raw-editor-container {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }

  .sidebar-column {
    display: none !important;
  }

  .note-form-buttons .btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.9375rem;
    white-space: nowrap;
    flex: 0 1 auto;
  }
}

@media (max-width: 480px) {
  .note-form-buttons {
    justify-content: space-between !important;
    gap: 0.375rem;
  }

  .note-form-buttons .btn {
    padding: 0.5rem 1.5rem;
    font-size: 0.875rem;
  }

  .note-form-buttons .btn span {
    display: none;
  }
}

/* ============================================================
   19. GRID
   ============================================================ */

.container {
  width: 100%;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin-left: -0.75rem;
  margin-right: -0.75rem;
}

[class*="col-"] {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  box-sizing: border-box;
  width: 100%;
}

.col-12 {
  flex: 0 0 100%;
  max-width: 100%;
}

.col-4 {
  flex: 0 0 33.333%;
  max-width: 33.333%;
}

@media (min-width: 768px) {
  .col-md-3 {
    flex: 0 0 25%;
    max-width: 25%;
  }

  .col-md-4 {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }

  .col-md-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .col-md-8 {
    flex: 0 0 66.667%;
    max-width: 66.667%;
  }

  .col-md-12 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

@media (min-width: 992px) {
  .col-lg-2 {
    flex: 0 0 16.667%;
    max-width: 16.667%;
  }

  .col-lg-4 {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }

  .col-lg-8 {
    flex: 0 0 66.667%;
    max-width: 66.667%;
  }
}

.order-1 {
  order: 1;
}

/* ============================================================
   20. DISPLAY & FLEXBOX UTILITIES
   ============================================================ */

.d-flex {
  display: flex !important;
}

.d-grid {
  display: grid !important;
}

.d-block {
  display: block !important;
}

.d-none {
  display: none !important;
}

.d-inline {
  display: inline !important;
}

@media (min-width: 576px) {
  .d-sm-inline {
    display: inline !important;
  }
}

@media (min-width: 768px) {
  .d-md-inline {
    display: inline !important;
  }
}

.flex-wrap {
  flex-wrap: wrap !important;
}

.flex-grow-1 {
  flex-grow: 1 !important;
}

.flex-shrink-0 {
  flex-shrink: 0 !important;
}

.flex-column {
  flex-direction: column !important;
}

.justify-content-between {
  justify-content: space-between !important;
}

.justify-content-center {
  justify-content: center !important;
}

.justify-content-end {
  justify-content: flex-end !important;
}

.align-items-center {
  align-items: center !important;
}

.align-items-start {
  align-items: flex-start !important;
}

.gap-1 {
  gap: 0.25rem !important;
}

.gap-2 {
  gap: 0.5rem !important;
}

.g-2 {
  gap: 0.5rem !important;
}

.ms-auto {
  margin-left: auto !important;
}

.me-auto {
  margin-right: auto !important;
}

.mx-auto {
  margin-left: auto !important;
  margin-right: auto !important;
}

/* ============================================================
   21. SPACING UTILITIES
   ============================================================ */

.m-0 {
  margin: 0 !important;
}

.mb-0 {
  margin-bottom: 0 !important;
}

.mb-1 {
  margin-bottom: 0.25rem !important;
}

.mb-2 {
  margin-bottom: clamp(0.375rem, 1.5vw, 0.5rem) !important;
}

.mb-3 {
  margin-bottom: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.mb-4 {
  margin-bottom: clamp(1rem, 3.5vw, 1.5rem) !important;
}

.mt-1 {
  margin-top: 0.25rem !important;
}

.mt-2 {
  margin-top: clamp(0.375rem, 1.5vw, 0.5rem) !important;
}

.mt-3 {
  margin-top: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.mt-4 {
  margin-top: clamp(1rem, 3.5vw, 1.5rem) !important;
}

.ms-1 {
  margin-left: 0.25rem !important;
}

.ms-2 {
  margin-left: clamp(0.375rem, 1.5vw, 0.5rem) !important;
}

.ms-3 {
  margin-left: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.me-1 {
  margin-right: 0.25rem !important;
}

.me-2 {
  margin-right: clamp(0.375rem, 1.5vw, 0.5rem) !important;
}

.me-3 {
  margin-right: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.p-0 {
  padding: 0 !important;
}

.p-1 {
  padding: 0.25rem !important;
}

.p-2 {
  padding: clamp(0.375rem, 1.5vw, 0.5rem) !important;
}

.p-3 {
  padding: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.p-4 {
  padding: clamp(.5rem, 1.5vw, 1.5rem) !important;
}

.pb-3 {
  padding-bottom: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.pt-3 {
  padding-top: clamp(0.625rem, 2.5vw, 1rem) !important;
}

.py-2 {
  padding-top: clamp(0.375rem, 1.5vw, 0.5rem) !important;
  padding-bottom: clamp(0.375rem, 1.5vw, 0.5rem) !important;
}

.py-4 {
  padding-top: clamp(1rem, 3.5vw, 1.5rem) !important;
  padding-bottom: clamp(1rem, 3.5vw, 1.5rem) !important;
}

.px-3 {
  padding-left: clamp(0.625rem, 2.5vw, 1rem) !important;
  padding-right: clamp(0.625rem, 2.5vw, 1rem) !important;
}

/* ============================================================
   22. TEXT & COLOR UTILITIES
   ============================================================ */

.text-center {
  text-align: center !important;
}

.text-decoration-none {
  text-decoration: none !important;
}

.text-secondary {
  color: var(--ink-3) !important;
}

.text-danger {
  color: #dc2626 !important;
}

.text-warning {
  color: #d97706 !important;
}

.text-white {
  color: #fff !important;
}

.text-dark {
  color: var(--ink) !important;
}

.fw-normal {
  font-weight: 400 !important;
}

.small,
small {
  font-size: 0.875em;
}

@media (min-width: 768px) {
  .text-md-end {
    text-align: right !important;
  }
}

/* ============================================================
   23. BORDER, IMAGE & SIZE UTILITIES
   ============================================================ */

.border-top {
  border-top: 1px solid var(--line) !important;
}

.border-bottom {
  border-bottom: 1px solid var(--line) !important;
}

.border-0 {
  border: none !important;
}

.rounded {
  border-radius: var(--radius-sm) !important;
}

.img-fluid {
  max-width: 100%;
  height: auto;
}

.img-thumbnail {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
  background: var(--surface);
}

.w-100 {
  width: 100% !important;
}

.h-100 {
  height: 100% !important;
}

.shadow-sm {
  box-shadow: var(--shadow) !important;
}

.position-absolute {
  position: absolute !important;
}

.position-relative {
  position: relative !important;
}

.position-fixed {
  position: fixed !important;
}

.top-0 {
  top: 0 !important;
}

.top-50 {
  top: 50% !important;
}

.start-0 {
  left: 0 !important;
}

.end-0 {
  right: 0 !important;
}

.translate-middle-y {
  transform: translateY(-50%) !important;
}

/* bg-dark used inside lightbox modal */
.modal .bg-dark {
  background: #0a0a0a !important;
}

/* bg-light used in note_delete */
.bg-light {
  background: var(--surface-2) !important;
}

/* ================================================================
   AUFGABEN (TASKS) MODE — component styles
   Hue set inline via style="--ctx-hue: 255"
   ================================================================ */

/* --- Mode switch in topbar --- */
.topbar-mode-switch {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  flex-shrink: 0;
}
.topbar-mode-seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-3);
  text-decoration: none;
  transition: color .12s, background .12s;
  white-space: nowrap;
}
.topbar-mode-seg:hover { color: var(--ink-2); }
.topbar-mode-seg.is-active {
  background: var(--surface);
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

/* --- Kontext tabs --- */
.kontext-section { padding: 0 clamp(8px, 1.5vw, 28px) 0; max-width: 1280px; margin: 0 auto; }

.kontext-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 767px) {
  .kontext-section { overflow: hidden; }
  .kontext-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
  .kontext-tabs::-webkit-scrollbar { display: none; }
  .kontext-tab { flex-shrink: 0; }
}
.kontext-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  text-decoration: none;
  color: var(--ink-2);
  font-size: 13px;
  transition: border-color .12s, background .12s, color .12s;
}
.kontext-tab:hover { background: var(--surface); color: var(--ink); }
.kontext-tab.is-active {
  background: var(--surface);
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .55);
  font-weight: 600;
  color: var(--ink);
}
.kontext-tile {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 13px;
  background: oklch(0.72 0.14 var(--ctx-hue) / .14);
  color: oklch(0.72 0.14 var(--ctx-hue));
  flex-shrink: 0;
}
.kontext-tab.is-active .kontext-tile { background: oklch(0.72 0.14 var(--ctx-hue) / .18); }
.kontext-count {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink-3);
}
.kontext-tab.is-active .kontext-count { color: oklch(0.72 0.14 var(--ctx-hue)); }
.kontext-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
@media (max-width: 767px) {
  .kontext-tag-row { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
  .kontext-tag-row::-webkit-scrollbar { display: none; }
  .kontext-tag-row .tag-chip { flex-shrink: 0; }
}
.kontext-tag-row .tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
}
.kontext-tag-row .kontext-count {
  font-size: 10px;
}
.kontext-tab.drag-over {
  background: oklch(0.72 0.14 var(--ctx-hue) / .12);
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .75);
  color: var(--ink);
  transform: scale(1.04);
  transition: border-color .08s, background .08s, transform .08s;
}
.todo-row.is-dragging, .todo-card.is-dragging { opacity: .45; }
.drag-ctx-badge {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid oklch(0.72 0.14 var(--ctx-hue) / .55);
  color: oklch(0.52 0.16 var(--ctx-hue));
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transform: translate(-50%, 0);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  transition: background .15s, border-color .15s, color .15s;
}
.todo-row.is-drag-target, .todo-card.is-drag-target {
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .7);
  box-shadow: 0 0 0 3px oklch(0.72 0.14 var(--ctx-hue) / .25),
    0 0 20px oklch(0.72 0.14 var(--ctx-hue) / .2);
}

/* --- Context chip --- */
.ctx-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
a.ctx-chip:hover {
  background: oklch(0.72 0.14 var(--ctx-hue) / .1);
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .4);
  color: oklch(0.72 0.14 var(--ctx-hue));
}
.ctx-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: oklch(0.72 0.14 var(--ctx-hue));
  flex-shrink: 0;
}
.ctx-chip.is-active {
  background: oklch(0.72 0.14 var(--ctx-hue) / .14);
  color: oklch(0.72 0.14 var(--ctx-hue));
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .35);
}

/* --- Quick add bar --- */
.quick-add {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 6px 8px;
  transition: border-color .12s, box-shadow .12s;
}
.quick-add:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent);
}
.quick-add-icon { color: var(--ink-3); font-size: 14px; flex-shrink: 0; }
.quick-add input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 14px;
  color: var(--ink);
  min-width: 0;
}
.quick-add input::placeholder { color: var(--ink-4); }
.quick-add-ctx-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 13px;
  transition: background .12s, color .12s, border-color .12s;
}
.quick-add-ctx-btn:hover { background: var(--surface-2); color: var(--ink-2); }
.quick-add-ctx-btn.is-active {
  background: oklch(0.72 0.14 var(--ctx-hue) / .14);
  color: oklch(0.72 0.14 var(--ctx-hue));
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .35);
}
@media (max-width: 767px) {
  .quick-add-ctx-btn { display: none; }
}
.quick-add-submit {
  background: var(--accent);
  color: #1a1208;
  border: 0;
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .12s;
}
.quick-add-submit:hover { opacity: .88; }

/* --- Quick add parse preview --- */
.quick-add-preview {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  overflow: hidden;
  padding: 2px 6px 6px;
  font-size: 12px;
}
.quick-add-preview[hidden] {
  display: none;
}
.quick-add-preview-raw {
  color: var(--ink-3);
  font-size: 13px;
  flex-shrink: 0;
  white-space: nowrap;
}
.quick-add-preview-label {
  color: var(--ink-4);
  font-size: 11px;
  flex-shrink: 0;
}
.qa-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
}
.qa-chip.is-date {
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 35%, transparent);
  background: color-mix(in oklab, var(--accent) 9%, var(--surface));
}
.qa-chip.is-tag  { color: oklch(0.62 0.18 280); border-color: oklch(0.62 0.18 280 / .3); background: oklch(0.62 0.18 280 / .08); }
.qa-chip.is-ctx  { color: oklch(0.58 0.18 150); border-color: oklch(0.58 0.18 150 / .3); background: oklch(0.58 0.18 150 / .08); }

/* --- Time group header --- */
.time-group { margin-bottom: 8px; }
.time-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 0 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.time-group-bullet { width: 8px; height: 8px; transform: rotate(45deg); flex-shrink: 0; }
.time-group-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.time-group-count { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px; color: var(--ink-3); }
.tone-danger .time-group-bullet { background: var(--danger); }
.tone-today  .time-group-bullet { background: var(--accent); }
.tone-soon   .time-group-bullet { background: color-mix(in oklab, var(--accent) 55%, var(--line-strong)); }
.tone-calm   .time-group-bullet { background: var(--line-strong); }

/* --- Todo list / grid --- */
.todos-list { display: flex; flex-direction: column; gap: 6px; }
.todos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }

/* --- Todo card (grid) --- */
.todo-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px 14px 0px;
  display: flex;
  gap: 12px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.todo-card:hover {
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .55);
  box-shadow: 0 0 0 3px oklch(0.72 0.14 var(--ctx-hue) / .12),
    0 6px 18px -10px oklch(0.72 0.14 var(--ctx-hue) / .35);
}
.todo-card[data-done="1"] { opacity: .58; }

/* --- Todo row (list) --- */
.todo-row {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.todo-row:hover {
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .55);
  box-shadow: 0 0 0 2px oklch(0.72 0.14 var(--ctx-hue) / .12);
}
.todo-row-inner {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 5px 10px 10px;
  background: var(--surface);
  position: relative;
  z-index: 1;
  touch-action: pan-y;
  transition: background .12s;
}
.todo-row:hover .todo-row-inner { background: color-mix(in oklab, var(--surface-2) 70%, var(--surface)); }
.todo-row[data-done="1"] { opacity: .58; }

/* Swipe-to-complete background reveal */
.todo-swipe-bg {
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, var(--accent) 16%, var(--surface));
  display: flex;
  align-items: center;
  padding-left: 22px;
  color: var(--accent);
  font-size: 18px;
  z-index: 0;
}

/* --- Burst completion animation (om-*) --- */
@keyframes om-check-pop {
  0%   { transform: scale(0.3) rotate(-12deg); }
  55%  { transform: scale(1.55) rotate(6deg); }
  80%  { transform: scale(0.88) rotate(-2deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes om-flash {
  0%   { transform: scale(0); opacity: .85; }
  60%  { transform: scale(2.2); opacity: .28; }
  100% { transform: scale(3.2); opacity: 0; }
}
@keyframes om-ring {
  0%   { transform: scale(0.3); opacity: .9; }
  60%  { opacity: .45; }
  100% { transform: scale(3.4); opacity: 0; }
}
@keyframes om-spark {
  0%   { transform: rotate(var(--a)) translateY(0); opacity: 1; }
  100% { transform: rotate(var(--a)) translateY(var(--d,-30px)); opacity: 0; }
}

.om-burst {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none; z-index: 10; overflow: visible;
}
.om-flash {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent);
  animation: om-flash .55s cubic-bezier(.2,.6,.4,1) forwards;
}
.om-ring {
  position: absolute; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--accent); background: transparent;
  animation: om-ring .7s cubic-bezier(.2,.6,.4,1) forwards;
}
.om-ring-2 { animation-duration: .85s; animation-delay: .07s; }
.om-spark {
  position: absolute; width: 3px; height: 6px; border-radius: 2px;
  background: var(--accent);
  animation: om-spark .6s cubic-bezier(.2,.6,.4,1) forwards;
}
/* Distance + size variation for organic feel */
.om-spark:nth-child(4)  { --d: -28px; }
.om-spark:nth-child(5)  { --d: -34px; width: 2.5px; }
.om-spark:nth-child(6)  { --d: -26px; background: var(--ink-4); }
.om-spark:nth-child(7)  { --d: -32px; }
.om-spark:nth-child(8)  { --d: -30px; height: 5px; }
.om-spark:nth-child(9)  { --d: -28px; background: var(--ink-4); }
.om-spark:nth-child(10) { --d: -36px; width: 2.5px; }
.om-spark:nth-child(11) { --d: -24px; }
.om-spark:nth-child(12) { --d: -38px; height: 5px; background: var(--ink-4); }
.om-spark:nth-child(13) { --d: -30px; width: 2px; }

.om-check-pop {
  animation: om-check-pop .4s cubic-bezier(.34,1.7,.5,1) forwards;
}
.todo-row.is-completing { pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .om-burst { display: none; }
  .om-check-pop { animation: none; }
}

/* --- Urgency rail --- */
.urgency-danger { border-left-color: var(--danger); }
.urgency-today  { border-left-color: var(--accent); }
.urgency-soon   { border-left-color: color-mix(in oklab, var(--accent) 55%, var(--line-strong)); }
.urgency-calm   { border-left-color: var(--line-strong); }
.urgency-done   { border-left-color: var(--line); }

/* --- Checkbox --- */
.todo-check-btn {
  width: 22px; height: 22px; flex-shrink: 0;
  background: none; border: 0; padding: 0;
  color: var(--ink-4); cursor: pointer;
  display: grid; place-items: center;
  font-size: 15px; transition: color .12s;
  margin-right: 8px;
  position: relative; overflow: visible;
}
.todo-check-btn:hover { color: var(--accent); }
.todo-card[data-done="1"] .todo-check-btn,
.todo-row[data-done="1"] .todo-check-btn { color: var(--accent); }

/* --- Card/row body --- */
.todo-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.todo-header { display: flex; align-items: flex-start; gap: 8px; }
.todo-title { flex: 1; font-size: 15px; cursor: pointer; }
.todo-row .todo-title { font-size: 14px; font-weight: 500; }
.todo-card[data-done="1"] .todo-title,
.todo-row[data-done="1"] .todo-title { text-decoration: line-through; color: var(--ink-4); }
.todo-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; flex-shrink: 0; }
.todo-row:hover .todo-actions { opacity: 1; }
.todo-row .todo-actions { max-width: 0; overflow: hidden; transition: max-width .15s ease, opacity .12s; }
.todo-row:hover .todo-actions { max-width: 180px; opacity: 1; }
.todo-row-menu-btn { flex-shrink: 0; }
.todo-action-btn {
  width: 26px; height: 26px; border: 0; background: none;
  color: var(--ink-3); cursor: pointer; border-radius: 6px;
  display: grid; place-items: center; font-size: 12px;
  transition: background .12s, color .12s;
  align-self: start;
  margin-top: -2px;
}
.todo-action-btn:hover,
.todo-action-btn.is-active { background: var(--surface-2); color: var(--ink); }
.todo-action-btn.danger:hover { color: var(--danger); }
.todo-desc { -webkit-line-clamp: 2; line-clamp: 2; }
.todo-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }

/* --- Anchor chip --- */
.todo-anchor-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; font-size: 12px; color: var(--ink-2);
  cursor: pointer; transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.todo-anchor-chip:hover { background: var(--surface-2); }
.todo-anchor-chip.is-overdue {
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 40%, var(--line));
  background: color-mix(in oklab, var(--danger) 8%, transparent);
}
.todo-anchor-chip.is-today {
  color: var(--accent); background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 30%, var(--line));
}
.todo-anchor-chip.is-empty { border-style: dashed; color: var(--ink-3); }

/* --- Reschedule popover --- */
.reschedule-menu {
  position: fixed; width: 212px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 10px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.35);
  padding: 5px; z-index: 3000; display: none;
}
.reschedule-menu.is-open { display: block; }
.reschedule-caption {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); padding: 6px 8px 4px; display: block;
}
.reschedule-option {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 8px; border-radius: 7px;
  background: none; border: 0; text-align: left;
  font-size: 13px; color: var(--ink); cursor: pointer; transition: background .1s;
}
.reschedule-option:hover { background: var(--surface-2); }
.reschedule-option.danger { color: var(--danger); }
.reschedule-divider { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* --- Composer modal --- */
.todo-composer-overlay {
  position: fixed; inset: 0;
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
  padding: 24px; z-index: 2000;
}
.todo-composer-overlay.is-open { display: flex; }
.todo-composer-card {
  width: min(560px, 100%); max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
}
.composer-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.composer-header-icon {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 13px; flex-shrink: 0;
}
.composer-title { flex: 1; font-size: 14px; font-weight: 600; color: var(--ink); }
.composer-close {
  width: 28px; height: 28px; border: 0; background: none;
  color: var(--ink-3); cursor: pointer; border-radius: 6px;
  display: grid; place-items: center; font-size: 14px;
  transition: background .1s, color .1s;
}
.composer-close:hover { background: var(--surface-2); color: var(--ink); }
.composer-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; flex: 1; }
.composer-field label {
  display: block; font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 11px; font-weight: 500; letter-spacing: 0;
  color: var(--ink-3); margin-bottom: 6px;
}
.composer-input,
.composer-textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; color: var(--ink);
  outline: 0; transition: border-color .12s, box-shadow .12s; box-sizing: border-box;
}
.composer-input.title-input { font-size: 16px; font-weight: 500; }
.composer-title-row { display: flex; align-items: stretch; gap: 8px; }
.composer-title-row .title-input { flex: 1; }
.composer-parse-btn {
  flex: 0 0 auto; width: 40px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--accent); font-size: 15px; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.composer-parse-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.composer-parse-btn:active { transform: scale(0.96); }
.composer-input:focus,
.composer-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent);
}
.composer-textarea { resize: vertical; min-height: 72px; font-family: inherit; }
.composer-ctx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px;overflow-x: scroll; scrollbar-width: none;}
.composer-ctx-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: transparent; cursor: pointer; text-align: left;
  transition: background .12s, border-color .12s;
}
.composer-ctx-btn:hover { background: var(--surface-2); }
.composer-ctx-btn.is-active {
  background: oklch(0.72 0.14 var(--ctx-hue) / .12);
  border-color: oklch(0.72 0.14 var(--ctx-hue) / .45);
}

@media (max-width: 768px) {
  .composer-ctx-grid {display: flex; }
  .composer-ctx-btn {min-width: 170px;max-width: 200px;}
  .composer-ctx-btn .composer-ctx-blurb {white-space:normal;}
}
.composer-ctx-tile {
  width: 28px; height: 28px; border-radius: 7px; display: grid;
  place-items: center; font-size: 14px;
  background: oklch(0.72 0.14 var(--ctx-hue) / .14);
  color: oklch(0.72 0.14 var(--ctx-hue)); flex-shrink: 0;
}
.composer-ctx-name { font-size: 13px; font-weight: 500; color: var(--ink); }
.composer-ctx-blurb { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-toggle-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.composer-toggle-label { font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif; font-size: 11px; font-weight: 500; color: var(--ink-3); }
.composer-toggle-btn { font-size: 11px; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 2px 6px; border-radius: 5px; transition: background .1s; }
.composer-toggle-btn:hover { background: var(--accent-soft); }
.composer-date-row { display: flex; gap: 8px; }
.composer-date-row .composer-input { flex: 3; }
.composer-date-row .composer-input.time { flex: 2; }
.composer-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--line);
  position: sticky; bottom: 0; background: var(--surface);
}
.composer-footer-actions { display: flex; align-items: center; gap: 8px; }
.composer-done {
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--ink-2); font-size: 13px;
  cursor: pointer; transition: background .1s, color .1s;
}
.composer-done:hover { background: #22c55e22; color: #16a34a; border-color: #22c55e66; }
.composer-cancel {
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--ink-2); font-size: 13px;
  cursor: pointer; transition: background .1s;
}
.composer-cancel:hover { background: var(--surface-2); }
.composer-save {
  padding: 7px 16px; border: 0; border-radius: 8px;
  background: var(--accent); color: #1a1208;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity .12s;
}
.composer-save:hover { opacity: .88; }
.composer-save:disabled { opacity: .4; cursor: not-allowed; }
.composer-save-hint { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10px; color: var(--ink-4); }

/* --- Tag editor --- */
.tag-editor-wrap {
  display: flex; flex-wrap: wrap; gap: 5px; padding: 6px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); cursor: text; min-height: 36px;
  transition: border-color .12s, box-shadow .12s;
}
.tag-editor-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent);
}
.tag-editor-pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px;
}
.tag-editor-pill button {
  background: none; border: 0; color: inherit; cursor: pointer;
  padding: 0 0 0 2px; font-size: 10px; opacity: .7; line-height: 1;
}
.tag-editor-pill button:hover { opacity: 1; }
.tag-editor-input { flex: 1; min-width: 80px; border: 0; outline: 0; background: transparent; font-size: 13px; color: var(--ink); }
.tag-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag-suggestion {
  border: 1px dashed var(--line-strong); border-radius: 999px; padding: 2px 8px;
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px;
  color: var(--ink-3); background: none; cursor: pointer; transition: background .1s, color .1s;
}
.tag-suggestion:hover { background: var(--surface-2); color: var(--ink-2); }

/* --- Note link picker (in composer) --- */
.note-link-chip-wrap {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.note-link-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in oklab, var(--accent) 30%, transparent);
  font-size: 13px; text-decoration: none; flex: 1; min-width: 0;
  transition: background .1s;
}
.note-link-chip:hover { background: color-mix(in oklab, var(--accent) 20%, transparent); }
.note-link-chip i { font-size: 12px; flex-shrink: 0; }
.note-link-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-link-coll {
  font-size: 11px; opacity: .6; margin-left: 2px;
}
.note-link-coll::before { content: '·'; margin-right: 4px; }
.note-link-clear {
  width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 6px;
  background: none; color: var(--ink-3); cursor: pointer; font-size: 14px;
  display: grid; place-items: center; flex-shrink: 0; transition: background .1s, color .1s;
}
.note-link-clear:hover { background: var(--surface-2); color: var(--ink); }
.note-link-search-wrap { position: relative; }
.note-link-results {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,.25); z-index: 100;
  max-height: 220px; overflow-y: auto;
}
.note-link-result-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  width: 100%; padding: 8px 12px; border: 0; background: none;
  cursor: pointer; text-align: left; transition: background .1s;
}
.note-link-result-item:first-child { border-radius: 9px 9px 0 0; }
.note-link-result-item:last-child { border-radius: 0 0 9px 9px; }
.note-link-result-item:only-child { border-radius: 9px; }
.note-link-result-item:hover,
.note-link-result-item.is-active { background: var(--surface-2); }
.note-link-result-title { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-link-result-coll { font-size: 11px; color: var(--ink-3); white-space: nowrap; flex-shrink: 0; }

/* --- Note link chip in todo row --- */
.note-link-row-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; text-decoration: none;
  transition: background .1s;
}
.note-link-row-chip:hover { background: color-mix(in oklab, var(--accent) 20%, transparent); }
.note-link-row-chip i { font-size: 10px; }

/* --- Tasks toolbar --- */
.todos-toolbar {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(8px, 1.5vw, 28px);
}

.todos-toolbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 0;
}
.status-seg-ctrl { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 8px; padding: 2px; flex-shrink: 0; height: 36px; box-sizing: border-box; }
.status-seg {
  display: inline-flex; align-items: center; gap: 5px; padding:10px; line-height: 1;
  border-radius: 6px; font-size: 12px; color: var(--ink-3);
  text-decoration: none; transition: color .1s, background .1s; white-space: nowrap;
}
.status-seg:hover { color: var(--ink-2); }
.status-seg.is-active { background: var(--surface); font-weight: 600; color: var(--ink); }
.status-seg .seg-count { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10px; }


@media (max-width: 768px) {
  /* Keep everything on a single row */
  .todos-toolbar-row { flex-wrap: nowrap; }
  .todos-toolbar-row .status-seg-ctrl { order: 1; min-width: 0; }
  .todos-toolbar-row .toolbar-view-toggle { order: 2; }
  .todos-toolbar-row .toolbar-sort-wrap { order: 3; }
  .todos-toolbar-row .toolbar-search-outer { order: 4; }

  /* Collapse search to a single icon; tap (or active query) expands it inline.
     !important overrides the inline flex / min-width on the markup. */
  .todos-toolbar-row .toolbar-search-outer {
    flex: 0 1 auto !important;
    min-width: 0 !important;
  }
  .todos-toolbar-row .toolbar-search-wrap {
    position: relative;
    flex: 0 0 38px !important;
    width: 38px;
    min-width: 38px;
    padding: 0;
    overflow: hidden;
    transition: flex-basis 0.18s ease, width 0.18s ease;
  }
  .todos-toolbar-row .toolbar-search-outer:focus-within,
  .todos-toolbar-row .toolbar-search-outer:has(.toolbar-search-input:not(:placeholder-shown)) {
    flex: 1 1 auto !important;
  }
  .todos-toolbar-row .toolbar-search-wrap:focus-within,
  .todos-toolbar-row .toolbar-search-wrap:has(.toolbar-search-input:not(:placeholder-shown)) {
    flex: 1 1 auto !important;
    width: auto;
    min-width: 0;
  }
  /* While the search is active, hand it the whole row so it's typeable. */
  .todos-toolbar-row:has(.toolbar-search-input:focus) .status-seg-ctrl,
  .todos-toolbar-row:has(.toolbar-search-input:not(:placeholder-shown)) .status-seg-ctrl,
  .todos-toolbar-row:has(.toolbar-search-input:focus) .toolbar-sort-wrap,
  .todos-toolbar-row:has(.toolbar-search-input:not(:placeholder-shown)) .toolbar-sort-wrap,
  .todos-toolbar-row:has(.toolbar-search-input:focus) .toolbar-view-toggle,
  .todos-toolbar-row:has(.toolbar-search-input:not(:placeholder-shown)) .toolbar-view-toggle {
    display: none;
  }
  .todos-toolbar-row .toolbar-search-icon {
    position: absolute;
    left: 12px;
    pointer-events: none;
  }
  .todos-toolbar-row .toolbar-search-input {
    width: 100%;
    height: 100%;
    padding: 0 12px 0 34px;
  }
  .todos-toolbar-row .toolbar-search-keycap {
    display: none;
  }

  /* Sort button: icon only (font-size:0 hides the text node;
     the icons keep their own inline font-size). */
  .todos-toolbar-row .toolbar-sort-btn {
    font-size: 0;
    gap: 4px;
    padding: 0 10px;
  }
  .todos-toolbar-row .toolbar-sort-btn .fa-chevron-down {
    display: none;
  }
}

/* --- Active tag filter row --- */
.todos-active-tags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px clamp(8px, 1.5vw, 28px); max-width: 1280px; margin: 0 auto; }
.todos-active-tags-label { font-size: 12px; color: var(--ink-3); }
.active-tag-pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px; text-decoration: none;
}
.active-tag-pill .remove { font-size: 10px; opacity: .7; }
.active-tag-pill:hover .remove { opacity: 1; }

/* --- Tasks main / empty state --- */
.todos-main { max-width: 1280px; margin: 0 auto; padding: 0 clamp(8px, 1.5vw, 28px); }
.todo-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; text-align: center; gap: 12px; }
.todo-empty-icon { width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; font-size: 20px; color: var(--ink-4); }
.todo-empty-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.todo-empty-desc { font-size: 13px; color: var(--ink-3); max-width: 340px; }