/* ============================================================
   NodeFlow — v0.dev / Vercel / Apple. Flat. Monochrome.
   Geist + Geist Mono. Плотная типографика. Без градиентов.
   ============================================================ */

:root {
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-pill: 999px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0.33, 1, 0.68, 1);

  --font-sans: 'Geist', 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --font-mono: 'Geist Mono', 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --track-tight: -0.02em;
  --track-tighter: -0.03em;
}

/* ---------- Палитры ---------- */
[data-theme='noir'] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #111111;
  --surface-3: #1a1a1a;
  --border: rgba(255,255,255,.09);
  --border-strong: rgba(255,255,255,.18);
  --text: #ededed;
  --muted: #8f8f8f;
  --accent: #ffffff;
  --accent-fg: #000000;
  --accent-soft: rgba(255,255,255,.10);
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --ring: rgba(255,255,255,.30);
}
[data-theme='snow'] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f5f5f5;
  --surface-3: #ebebeb;
  --border: rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.18);
  --text: #0a0a0a;
  --muted: #666666;
  --accent: #0a0a0a;
  --accent-fg: #ffffff;
  --accent-soft: rgba(0,0,0,.06);
  --ok: #16a34a;
  --warn: #ca8a04;
  --err: #dc2626;
  --ring: rgba(0,0,0,.28);
}
[data-theme='graphite'] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #e8e8ed;
  --border: rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.16);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #1d1d1f;
  --accent-fg: #ffffff;
  --accent-soft: rgba(29,29,31,.07);
  --ok: #16a34a;
  --warn: #ca8a04;
  --err: #dc2626;
  --ring: rgba(29,29,31,.25);
}
[data-theme='azure'] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #e8e8ed;
  --border: rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.16);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --accent-fg: #ffffff;
  --accent-soft: rgba(0,113,227,.10);
  --ok: #16a34a;
  --warn: #ca8a04;
  --err: #dc2626;
  --ring: rgba(0,113,227,.35);
}
[data-theme='violet'] {
  --bg: #faf7ff;
  --surface: #ffffff;
  --surface-2: #f6f2ff;
  --surface-3: #ede5ff;
  --border: rgba(60,20,120,.10);
  --border-strong: rgba(60,20,120,.22);
  --text: #1e1136;
  --muted: #6b5b8a;
  --accent: #7c3aed;
  --accent-fg: #ffffff;
  --accent-soft: rgba(124,58,237,.10);
  --ok: #16a34a;
  --warn: #ca8a04;
  --err: #dc2626;
  --ring: rgba(124,58,237,.32);
}
[data-theme='sage'] {
  --bg: #f3faf5;
  --surface: #ffffff;
  --surface-2: #eef7f1;
  --surface-3: #dcefe1;
  --border: rgba(10,60,30,.10);
  --border-strong: rgba(10,60,30,.22);
  --text: #08240f;
  --muted: #4b7a5e;
  --accent: #16a34a;
  --accent-fg: #ffffff;
  --accent-soft: rgba(22,163,74,.10);
  --ok: #16a34a;
  --warn: #ca8a04;
  --err: #dc2626;
  --ring: rgba(22,163,74,.32);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

html {
  /* Раньше здесь стояло 19px «для масштаба» — но в файле почти нигде не
     используются rem/em, так что это значение ни на что не влияло и только
     путало. Оставляем стандартные 16px и отключаем автоувеличение текста
     мобильными браузерами при повороте экрана. */
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  font-feature-settings: 'ss01', 'cv11', 'cv02';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Было -0.02em по умолчанию для ВСЕГО текста, включая абзацы заметок —
     плотный трекинг уместен в заголовках (там он задан явно отдельными
     классами), но ухудшает читаемость обычного текста. Обычный текст
     теперь идёт с нормальным трекингом. */
  letter-spacing: normal;
  transition: background .25s var(--ease), color .2s var(--ease);
  overscroll-behavior: none;
  overflow-x: hidden;
  max-width: 100%;
}
[hidden] { display: none !important; }

button { font-family: inherit; color: inherit; cursor: pointer; letter-spacing: inherit; }
input, textarea, select { font-family: inherit; color: inherit; font-size: inherit; letter-spacing: inherit; }
svg { display: block; }

/* Touch-friendly: убираем синюю/серую вспышку при тапе на iOS/Android и
   отключаем жест двойного тапа для зума на интерактивных элементах —
   без этого между тапом и реакцией на мобильном ощущалась задержка. */
button, .btn, .icon-btn, .chip, .item-row.clickable, a, .checkbox, .ref-chip, .tool {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
  border-radius: var(--r-sm);
}

/* ============================================================
   Интро (by vzbb)
   ============================================================ */
.intro {
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none;
}
.intro-curtain {
  position: absolute; top: 0; bottom: 0; width: 50.5%;
  background: var(--bg);
  will-change: transform;
}
.intro-left { left: 0; }
.intro-right { right: 0; }
.intro-text {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center;
  color: var(--text);
  will-change: transform, opacity;
}
.intro-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.intro-name {
  display: block;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -.04em;
}

/* ============================================================
   Layout
   ============================================================ */
.app {
  min-height: 100vh;
  min-height: 100dvh; /* dvh учитывает появление/скрытие адресной строки браузера на мобильном — без этого высота "прыгала" */
  display: flex; flex-direction: column; align-items: center;
  padding: calc(26px + env(safe-area-inset-top, 0px)) 20px 100px;
  gap: 16px;
}
.topbar {
  width: 100%; max-width: 1200px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 15px 13px 17px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 600; font-size: 13px;
  letter-spacing: 0;
}
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: var(--track-tight); }
.topbar-actions { display: flex; gap: 5px; flex-wrap: wrap; }

.content-card {
  width: 100%; max-width: 1200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 34px;
}

/* ============================================================
   Кнопки
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px; font-weight: 500;
  letter-spacing: var(--track-tight);
  transition: background .12s var(--ease), border-color .12s var(--ease), color .12s var(--ease), opacity .12s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { background: var(--surface-3); }
.btn.sm { padding: 7px 12px; font-size: 14px; gap: 5px; }

.btn.primary {
  background: var(--accent); color: var(--accent-fg);
  border-color: var(--accent);
}
.btn.primary:hover { opacity: .88; background: var(--accent); border-color: var(--accent); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  transition: background .12s var(--ease), color .12s var(--ease), border-color .12s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

/* ============================================================
   Заголовок вида
   ============================================================ */
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.view-title {
  font-size: 27px; font-weight: 600;
  margin: 0; letter-spacing: var(--track-tighter);
  line-height: 1.15;
}
.view-sub {
  color: var(--muted); font-size: 14px; margin-top: 5px;
  font-family: var(--font-mono);
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.view-actions { display: flex; gap: 8px; align-items: center; }

/* ============================================================
   Панель фильтров (collapsible)
   ============================================================ */
.filters-toggle svg { transition: transform .2s var(--ease); }
.filters-toggle.open svg { transform: rotate(180deg); }

.filters-panel {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height .3s var(--ease), opacity .2s var(--ease), margin-bottom .3s var(--ease);
  margin-bottom: 0;
}
.filters-panel.open {
  max-height: 220px;
  opacity: 1;
  margin-bottom: 20px;
}

.filters-inner {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  flex: 1; min-width: 220px;
  transition: border-color .12s var(--ease);
}
.search-box:focus-within { border-color: var(--border-strong); }
.search-box svg { color: var(--muted); flex-shrink: 0; }
.search-box input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 16px; min-width: 0;
}
.search-box input::placeholder { color: var(--muted); }

.chip-row { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px; font-weight: 500;
  transition: color .12s var(--ease), border-color .12s var(--ease), background .12s var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active {
  color: var(--text);
  border-color: var(--text);
  background: var(--accent-soft);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }

.select-sm {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .12s var(--ease);
}
.select-sm:hover { border-color: var(--border-strong); }

/* ============================================================
   Список
   ============================================================ */
.list { display: flex; flex-direction: column; gap: 8px; }

.section-title {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
  margin: 26px 0 10px;
  display: flex; align-items: center; gap: 10px;
}
.section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.item-row {
  display: flex; align-items: flex-start; gap: 15px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.item-row.clickable { cursor: pointer; }
.item-row.clickable:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.item-row.done .item-body,
.item-row.done .checkbox,
.item-row.done .importance-dot { opacity: .55; }

.importance-dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex-shrink: 0; margin-top: 8px;
}
.importance-dot.red { background: var(--err); }
.importance-dot.yellow { background: var(--warn); }
.importance-dot.green { background: var(--ok); }

.checkbox {
  width: 21px; height: 21px; border-radius: var(--r-xs);
  border: 1.5px solid var(--border-strong);
  flex-shrink: 0; cursor: pointer;
  display: grid; place-items: center;
  margin-top: 1px;
  background: var(--surface);
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.checkbox:hover { border-color: var(--text); }
.checkbox.checked { background: var(--accent); border-color: var(--accent); }
.checkbox svg {
  width: 13px; height: 13px;
  stroke: var(--accent-fg);
  opacity: 0;
  transition: opacity .1s var(--ease);
}
.checkbox.checked svg { opacity: 1; }

.item-body { flex: 1; min-width: 0; }
.item-title {
  font-size: 16.5px; font-weight: 500;
  letter-spacing: var(--track-tight);
  word-break: break-word;
  line-height: 1.4;
}
.item-title.done { text-decoration: line-through; color: var(--muted); }

.item-desc {
  font-size: 14px; color: var(--muted);
  margin-top: 4px; line-height: 1.5;
  word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-meta {
  display: flex; gap: 6px; margin-top: 9px;
  flex-wrap: wrap; align-items: center;
}

.mini-tag {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0;
  padding: 2px 7px; border-radius: var(--r-xs);
  background: var(--surface-3); color: var(--text);
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}
.mini-tag.muted { color: var(--muted); }
.mini-tag.accent {
  color: var(--accent);
  background: var(--accent-soft);
}

.timer {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--muted); letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.timer.soon { color: var(--warn); }
.timer.overdue { color: var(--err); }

.empty-state {
  color: var(--muted); font-size: 13.5px;
  padding: 48px 12px; text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

/* ============================================================
   Модалки
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px;
  z-index: 50;
  opacity: 0; pointer-events: none;
  transition: opacity .15s var(--ease);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  backdrop-filter: blur(8px) saturate(120%);
  overflow-y: auto;
}
[data-theme='snow'] .modal-overlay,
[data-theme='graphite'] .modal-overlay,
[data-theme='azure'] .modal-overlay,
[data-theme='violet'] .modal-overlay,
[data-theme='sage'] .modal-overlay { background: rgba(0,0,0,.25); }
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  width: 100%; max-width: 900px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow:
          0 0 0 1px rgba(0,0,0,.03),
          0 12px 32px -8px rgba(0,0,0,.25),
          0 24px 60px -16px rgba(0,0,0,.2);
  display: flex; flex-direction: column;
  max-height: 88vh; max-height: 88dvh; overflow: hidden;
  transform: translateY(6px) scale(.995);
  transition: transform .18s var(--ease-out);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head-actions { display: flex; align-items: center; gap: 6px; }
.modal-title { font-size: 17.5px; font-weight: 600; margin: 0; letter-spacing: var(--track-tight); }
.modal-body { padding: 24px; overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; scrollbar-width: thin; }
.modal-foot {
  padding: 15px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

/* ============================================================
   Segmented
   ============================================================ */
.segmented {
  display: inline-flex; padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  gap: 2px;
}
.segmented button {
  border: none; background: transparent;
  padding: 6px 14px; border-radius: var(--r-xs);
  font-size: 13px; font-weight: 500;
  color: var(--muted);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: var(--surface); color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 0 0 1px var(--border);
}

/* ============================================================
   Форма
   ============================================================ */
.field-title {
  width: 100%;
  border: none; outline: none; background: transparent;
  font-size: 23px; font-weight: 600;
  letter-spacing: var(--track-tighter);
  padding: 5px 0 15px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  transition: border-color .12s var(--ease);
}
.field-title:focus { border-bottom-color: var(--border-strong); }
.field-title::placeholder { color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field-refs { grid-column: span 2; }
.field-label {
  font-size: 13px; font-weight: 500;
  color: var(--muted);
}
.field input,
.field select,
.modal-body input[type="text"],
.modal-body input[type="password"],
.modal-body input[type="email"],
.modal-body input[type="datetime-local"],
.modal-body select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  /* 16px минимум — иначе iOS Safari при фокусе на поле с меньшим шрифтом
     автоматически зумит всю страницу, и это выглядит как «сломанная»
     мобильная вёрстка. */
  font-size: 16px;
  outline: none;
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.field input:hover,
.field select:hover,
.modal-body input:hover,
.modal-body select:hover { border-color: var(--border-strong); }
.field input:focus,
.field select:focus,
.modal-body input:focus,
.modal-body select:focus {
  border-color: var(--border-strong);
  background: var(--surface);
}
.field input::placeholder,
.modal-body input::placeholder { color: var(--muted); }

.toolbar { display: flex; gap: 4px; margin-bottom: 9px; flex-wrap: wrap; align-items: center; }
.toolbar-sep {
  width: 1px; align-self: stretch;
  background: var(--border);
  margin: 4px 2px;
}
.tool {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px;
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.tool:hover { background: var(--surface-2); border-color: var(--border-strong); }
.tool .mono { font-family: var(--font-mono); font-size: 12px; }

.modal-body textarea {
  width: 100%; min-height: 190px; resize: vertical;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 16px; line-height: 1.6;
  letter-spacing: 0;
  outline: none;
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.modal-body textarea:hover { border-color: var(--border-strong); }
.modal-body textarea:focus { border-color: var(--border-strong); background: var(--surface); }

.preview {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 15px;
  background: var(--surface-2);
  min-height: 44px;
  margin-top: 7px;
}
.preview:empty::before {
  content: 'Здесь появится предпросмотр';
  color: var(--muted); font-size: 14px;
}
.mt-12 { margin-top: 12px; }

.hint { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 16px; }
.hint code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--surface-3); padding: 1px 5px;
  border-radius: var(--r-xs); letter-spacing: 0;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.remember-row {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  margin-top: 4px;
  cursor: pointer;
  font-size: 13.5px; color: var(--text);
  line-height: 1.5;
}
.remember-row input[type="checkbox"] {
  width: 16px; height: 16px; flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--accent);
}
.remember-row span { color: var(--muted); }
.status {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--muted); margin-top: 10px; letter-spacing: 0;
}
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.ref-picker {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  min-height: 44px; align-items: center;
}
.ref-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text);
  font-size: 12px; font-weight: 500;
  transition: border-color .12s var(--ease), background .12s var(--ease), color .12s var(--ease);
}
.ref-chip:hover { border-color: var(--border-strong); }
.ref-chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ============================================================
   Markdown-рендер
   ============================================================ */
.md { font-size: 14px; line-height: 1.65; word-wrap: break-word; }
.md.font-mono { font-family: var(--font-mono); letter-spacing: 0; font-size: 13px; }
.md h1, .md h2, .md h3 {
  letter-spacing: var(--track-tighter);
  margin: 16px 0 8px; font-weight: 600;
}
.md h1 { font-size: 19px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0 8px 20px; padding: 0; }
.md li { margin: 2px 0; }
.md code {
  font-family: var(--font-mono); font-size: 12.5px;
  background: var(--surface-3); padding: 1px 5px;
  border-radius: var(--r-xs); letter-spacing: 0;
}
.md pre {
  margin: 12px 0; border-radius: var(--r-sm);
  border: 1px solid var(--border); overflow-x: auto;
  font-size: 12.5px; padding: 12px 14px;
  background: var(--surface-2); letter-spacing: 0;
}
.md pre code { background: transparent; padding: 0; }
.md blockquote {
  margin: 10px 0; padding: 6px 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--muted);
}
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; text-underline-offset: 3px; }
.md table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-3); font-weight: 600; }
.md .ref {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: var(--r-xs);
  font-size: 12.5px;
  background: var(--accent-soft); color: var(--accent);
  cursor: pointer; text-decoration: none;
}
.md .chart {
  margin: 12px 0; padding: 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border);
}
.md .chart svg { width: 100%; height: 110px; display: block; }
.md .chart .bar { fill: var(--accent); }
.md .chart .axis { stroke: var(--border); }
.md .chart .label { fill: var(--muted); font-size: 9px; font-family: var(--font-mono); }

/* ============================================================
   Аналитика: сетка, карточки, графики
   ============================================================ */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: 20px;
}
.metric {
  padding: 16px 18px;
  background: var(--surface);
}
.metric .k {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.metric .k svg { flex-shrink: 0; }
.metric .v {
  font-size: 26px; font-weight: 600;
  margin-top: 4px; letter-spacing: var(--track-tighter);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.metric .v.err { color: var(--err); }
.metric .v.warn { color: var(--warn); }
.metric .v.ok { color: var(--ok); }
.metric { transition: background .12s var(--ease); }
.metric:hover { background: var(--surface-2); }
.metric-ring { display: flex; flex-direction: column; }
.ring-wrap { position: relative; display: grid; place-items: center; margin-top: 4px; }
.ring-wrap svg { display: block; }
.ring-val {
  position: absolute; font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--text);
}

.metrics-section { margin-bottom: 22px; }
.metrics-section-head {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 10px;
}
.metrics-section-head::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.metrics-chart-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.metrics-chart-card svg { width: 100%; display: block; }

.metrics-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.chart-bar { fill: var(--accent); opacity: .85; }
.chart-bar.dim { fill: var(--muted); opacity: .25; }
.chart-label {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
}
.chart-value {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
}
.chart-line { stroke: var(--accent); fill: none; stroke-width: 1.5; }
.chart-area { fill: var(--accent-soft); }
.chart-axis { stroke: var(--border); stroke-width: 1; }

/* Donut */
.donut-wrap {
  display: flex; align-items: center; gap: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.donut-svg { flex-shrink: 0; }
.donut-total {
  fill: var(--text);
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 600;
}
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.donut-legend-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.donut-swatch {
  width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0;
}
.donut-legend-label { color: var(--text); }
.donut-legend-value {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* Список категорий с барами */
.cat-list { display: flex; flex-direction: column; gap: 10px; }
.cat-row {
  display: grid;
  grid-template-columns: minmax(80px, 140px) 1fr 36px;
  gap: 12px; align-items: center;
  font-size: 13px;
}
.cat-row .name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-row .track {
  height: 6px; border-radius: var(--r-pill);
  background: var(--surface-3); overflow: hidden;
}
.cat-row .fill {
  height: 100%; background: var(--accent);
  border-radius: var(--r-pill);
}
.cat-row .num {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Popover
   ============================================================ */
.popover {
  position: fixed; z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow:
          0 0 0 1px rgba(0,0,0,.03),
          0 12px 32px -8px rgba(0,0,0,.25);
  padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  width: 300px; max-height: 260px; overflow-y: auto;
}
.popover button {
  border: none; background: transparent;
  font-size: 18px; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  transition: background .12s var(--ease);
}
.popover button:hover { background: var(--surface-2); }

/* ---------- Скроллбар ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Адаптив ---------- */
@media (max-width: 720px) {
  .app { padding: calc(16px + env(safe-area-inset-top, 0px)) 10px calc(100px + env(safe-area-inset-bottom, 0px)); gap: 12px; }
  .content-card { padding: 16px; border-radius: var(--r-lg); }
  .brand-name { display: none; }
  .topbar { padding: 10px 10px 10px 12px; gap: 6px; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .btn span:not(#themeLabel):not(#modeLabel) { display: none; }
  .topbar-actions .btn { padding: 8px 10px; }
  .topbar-actions .btn.icon-btn { padding: 8px; }
  .view-head { margin-bottom: 16px; }
  .view-title { font-size: 21px; }

  /* Раньше все кнопки хедера (Фильтры/Аналитика/Черновики/Корзина/+Добавить)
     стояли в один нерастягиваемый ряд с flex:1 каждая — на экране ~360px
     это давало 4 кнопки по ~60px шириной с обрезанным текстом. Теперь они
     переносятся по 2 в ряд, а «+Добавить» — отдельной полноширинной строкой. */
  .view-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .view-actions .btn { flex: 1 1 calc(50% - 4px); justify-content: center; padding: 10px 10px; white-space: nowrap; }
  .view-actions .btn#addBtn { display: none; }

  .form-grid { grid-template-columns: 1fr; }
  .field.span-2, .field-refs { grid-column: span 1; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .metrics-two-col { grid-template-columns: 1fr; }
  .donut-wrap { flex-direction: column; align-items: flex-start; }
  .donut-svg { max-width: 100%; height: auto; }

  /* Панель фильтров: раньше search-box держал min-width:220px и вместе
     с чипами/селектом не помещался в ширину экрана — переносим всё
     в колонку и растягиваем на полную ширину. */
  .filters-inner { flex-direction: column; align-items: stretch; gap: 8px; }
  .search-box { min-width: 0; width: 100%; }
  .select-sm { width: 100%; }

  /* Списки записей — компактнее на маленьком экране */
  .item-row { padding: 12px 14px; gap: 10px; }
  .item-title { font-size: 15.5px; }
  .item-desc { font-size: 13.5px; }
  .cat-row { grid-template-columns: minmax(56px, 96px) 1fr 30px; gap: 8px; font-size: 12px; }

  /* Модалки на мобильном — полноэкранные снизу вверх, без промежутков,
     чтобы было удобно листать пальцем и не мазать по маленьким полям. */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: 100vh; max-height: 100dvh;
    height: 100%;
    border-radius: 0;
    border-left: none; border-right: none; border-bottom: none;
  }
  .modal-head { padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 14px 14px; }
  .modal-body { padding: 18px 16px; }
  .modal-foot {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    position: sticky; bottom: 0;
    background: var(--surface);
  }
  .modal-foot .btn { flex: 1; justify-content: center; padding: 12px 14px; }
  .field-title { font-size: 20px; }

  .toolbar { gap: 6px; }
  .toolbar-sep { display: none; }

  .row-actions .btn { flex: 1 1 calc(50% - 4px); justify-content: center; }

  /* Touch-таргеты: на мобильном подтягиваем интерактивные элементы к
     рекомендуемому минимуму ~44px, чтобы не промахиваться пальцем. */
  .checkbox { width: 26px; height: 26px; }
  .icon-btn { width: 44px; height: 44px; }
  .tool { width: 40px; height: 40px; font-size: 14px; }
  .item-row.clickable { min-height: 44px; }
  .chip { min-height: 36px; padding: 7px 12px; }


  /* Попап эмодзи не должен упираться в край экрана на узких телефонах. */
  .popover { max-width: calc(100vw - 24px); }
}

/* ---------- Совсем маленькие экраны (iPhone SE и т.п.) ---------- */
@media (max-width: 380px) {
  .app { padding-left: 8px; padding-right: 8px; }
  .content-card { padding: 12px; }
  .view-title { font-size: 19px; }
  .brand-mark { width: 30px; height: 30px; }
  .topbar-actions .btn#accountBtn span { display: none; }
  .view-actions .btn { flex-basis: 100%; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
}

/* Auth chip */
.auth-chip { gap: 8px; }
.auth-avatar {
  width: 20px; height: 20px; border-radius: 50%;
  background-size: cover; background-position: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px var(--border);
}
.auth-chip.signed-in { color: var(--text); }

/* Account modal */
.account-user {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  margin-bottom: 16px;
}
.account-user img {
  width: 40px; height: 40px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--border);
}
.account-user .name { font-weight: 600; font-size: 14px; }
.account-user .email { color: var(--muted); font-size: 12.5px; font-family: var(--font-mono); letter-spacing: 0; }

/* ============================================================
   color-scheme по темам — нативные контролы и скроллбары
   ============================================================ */
[data-theme='noir']     { color-scheme: dark; }
[data-theme='snow']     { color-scheme: light; }
[data-theme='graphite'] { color-scheme: light; }
[data-theme='azure']    { color-scheme: light; }
[data-theme='violet']   { color-scheme: light; }
[data-theme='sage']     { color-scheme: light; }

/* ============================================================
   Доступный фокус
   ============================================================ */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ============================================================
   Индикатор синхронизации (топбар)
   ============================================================ */
.sync-status {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
  background: transparent;
  display: flex;
  transition: background .2s var(--ease);
}
.sync-status.ok, .sync-status.busy, .sync-status.err { display: block; }
.sync-status.ok   { background: var(--ok); }
.sync-status.busy { background: var(--warn); animation: sync-pulse 1.1s ease-in-out infinite; }
.sync-status.err  { background: var(--err); }
@keyframes sync-pulse { 50% { opacity: .35; } }

/* ============================================================
   Тост-уведомления
   ============================================================ */
.toast-stack {
  position: fixed; z-index: 120;
  bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: 0 14px 44px rgba(0,0,0,.3);
  font-size: 14px; font-weight: 500;
  max-width: 100%;
  animation: toast-in .24s var(--ease-out);
}
.toast .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.toast.ok   { border-color: var(--ok); }
.toast.err  { border-color: var(--err); }
.toast.info { border-color: var(--accent); }
.toast.ok .dot   { background: var(--ok); }
.toast.err .dot  { background: var(--err); }
.toast.info .dot { background: var(--accent); }
.toast.leaving { animation: toast-out .18s var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ============================================================
   Командная палитра
   ============================================================ */
.palette-overlay {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px;
  opacity: 0; pointer-events: none;
  transition: opacity .16s var(--ease);
}
.palette-overlay.open { opacity: 1; pointer-events: auto; }
.palette {
  width: 100%; max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,.4);
  transform: translateY(-6px) scale(.98);
  transition: transform .18s var(--ease-out);
}
.palette-overlay.open .palette { transform: translateY(0) scale(1); }
.palette-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.palette-input-row svg { color: var(--muted); flex-shrink: 0; }
.palette-input-row input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  font-size: 16px; color: var(--text);
}
.palette-input-row input::placeholder { color: var(--muted); }
.palette-input-row kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 3px 7px; border-radius: var(--r-xs);
  border: 1px solid var(--border); color: var(--muted);
  background: var(--surface-2);
}
.palette-list { max-height: 55vh; overflow-y: auto; padding: 8px; }
.palette-section {
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 10px 10px 6px;
}
.palette-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left;
  padding: 10px 11px; border-radius: var(--r-sm);
  border: none; background: transparent; color: var(--text);
  font-size: 14px; cursor: pointer;
  transition: background .1s var(--ease);
}
.palette-item:hover, .palette-item.active { background: var(--surface-2); }
.palette-item svg { color: var(--muted); flex-shrink: 0; }
.palette-item.active svg { color: var(--accent); }
.palette-item .pi-ico { width: 18px; display: grid; place-items: center; flex-shrink: 0; }
.palette-item .pi-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .pi-hint { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.palette-item mark { background: var(--accent-soft); color: var(--accent); border-radius: 2px; }
.palette-empty { padding: 26px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ============================================================
   FAB — плавающая кнопка добавления (мобильные)
   ============================================================ */
.fab {
  position: fixed; z-index: 40;
  right: 18px; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  transition: transform .15s var(--ease), opacity .15s var(--ease);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.fab:active { transform: scale(.94); }
.fab:hover { opacity: .92; }
@media (min-width: 721px) { .fab { display: none; } }

/* ============================================================
   Мобильная адаптация: тосты не перекрываются FAB
   ============================================================ */
@media (max-width: 720px) {
  .toast-stack { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .palette-overlay { padding-top: 6vh; }
  .palette-list { max-height: 60vh; }
  .char-count { display: none; }
}

/* ============================================================
   Счётчик символов в редакторе
   ============================================================ */
.char-count {
  margin-right: auto; align-self: center;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.char-count:empty { display: none; }

/* ============================================================
   Кнопки-действия внутри карточек (корзина, черновики)
   ============================================================ */
.item-actions {
  display: flex; gap: 6px; align-items: center;
  flex-shrink: 0; margin-left: auto;
}
@media (max-width: 720px) {
  .item-row-actions { flex-wrap: wrap; }
  .item-actions { width: 100%; margin-left: 0; justify-content: flex-end; }
  .item-actions .btn { flex: 1; justify-content: center; padding: 10px 12px; white-space: nowrap; }
}

/* ============================================================
   Навигация в настройках (данные и аналитика)
   ============================================================ */
.settings-nav {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-bottom: 22px;
}
.settings-nav .btn { justify-content: center; gap: 7px; }
.settings-nav .nav-ico { display: grid; place-items: center; color: var(--muted); }
.settings-nav .btn:hover .nav-ico { color: var(--text); }
.badge {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--accent-soft); color: var(--accent);
  padding: 1px 7px; border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 720px) {
  .settings-nav { grid-template-columns: 1fr; }
}

/* ============================================================
   Скролл-лок: когда открыто меню, фон не прокручивается
   ============================================================ */
html.no-scroll, body.no-scroll { overflow: hidden; }
.modal-body { overscroll-behavior: contain; }
.modal { overscroll-behavior: contain; }
.palette-list { overscroll-behavior: contain; }
.search-results { overscroll-behavior: contain; }

/* ============================================================
   Поиск по задачам и заметкам
   ============================================================ */
.search-modal { max-width: 640px; }
.search-input-wrap {
  flex: 1; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  transition: border-color .12s var(--ease);
}
.search-input-wrap:focus-within { border-color: var(--border-strong); }
.search-input-wrap svg { color: var(--muted); flex-shrink: 0; }
.search-input-wrap input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  font-size: 16px; color: var(--text);
}
.search-input-wrap input::placeholder { color: var(--muted); }

.search-filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-filters .segmented { flex-shrink: 0; }
.search-filters-row { display: flex; gap: 6px; flex-wrap: wrap; }
.search-filters .select-sm { min-width: 150px; }
@media (max-width: 720px) {
  .search-filters { padding: 10px 14px; gap: 6px; }
  .search-filters .select-sm { flex: 1; min-width: 0; }
}

.search-hint {
  color: var(--muted); font-size: 14px; text-align: center;
  padding: 40px 12px; line-height: 1.6;
}
.search-hint kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 2px 7px; border-radius: var(--r-xs);
  border: 1px solid var(--border); color: var(--text);
  background: var(--surface-2);
}

.search-section {
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 8px 0 8px;
}
.search-section:first-child { margin-top: 0; }

.search-result {
  display: flex; gap: 12px; align-items: flex-start;
  width: 100%; text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.search-result:last-child { margin-bottom: 0; }
.search-result:hover, .search-result.active { border-color: var(--border-strong); background: var(--surface-2); }
.search-result .sr-type {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted);
  font-size: 12px; flex-shrink: 0; margin-top: 1px;
}
.search-result .sr-body { flex: 1; min-width: 0; }
.search-result .sr-title { font-size: 15.5px; font-weight: 500; display: block; word-break: break-word; }
.search-result .sr-title mark, .search-desc mark { background: var(--accent-soft); color: var(--accent); border-radius: 2px; }
.search-desc {
  font-size: 13.5px; color: var(--muted); margin-top: 3px; line-height: 1.5;
  word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.search-result .sr-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.search-result .sr-none { color: var(--muted); font-style: italic; }

/* ============================================================
   Swipe-to-delete (iOS)
   ============================================================ */
.swipe-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-md);
}
.swipe-item .item-row {
  position: relative;
  z-index: 1;
  margin: 0;
  border-radius: 0;
  background: var(--surface);
  transition: transform .18s var(--ease-out), border-color .12s var(--ease), background .12s var(--ease);
  touch-action: pan-y;
}
.swipe-actions {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 84px;
  display: flex;
}
.swipe-delete {
  flex: 1;
  border: none;
  background: var(--err);
  color: #fff;
  font-size: 14px; font-weight: 600;
  display: grid; place-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.swipe-item.open .item-row { transform: translateX(-84px); }

/* ============================================================
   Action sheet (iOS) — подтверждение удаления
   ============================================================ */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 130;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease);
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 420px;
  background: var(--surface-2);
  border-radius: var(--r-xl);
  padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
  transform: translateY(16px);
  transition: transform .22s var(--ease-out);
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-title {
  text-align: center; font-weight: 600; font-size: 15px;
  padding: 10px 8px 0; letter-spacing: var(--track-tight);
}
.sheet-message {
  text-align: center; color: var(--muted); font-size: 13px;
  padding: 0 8px 4px; line-height: 1.5;
}
.sheet-btn {
  width: 100%; padding: 15px;
  border: none; border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background .12s var(--ease);
}
.sheet-btn:hover { background: var(--surface-3); }
.sheet-btn.sheet-danger { color: var(--err); font-weight: 600; }
.sheet-btn.sheet-cancel { font-weight: 600; }
@media (max-width: 720px) {
  .sheet-overlay { padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
}

/* ============================================================
   Меню добавления (Задача / Заметка / ИИ)
   ============================================================ */
.add-sheet { max-width: 460px; }
.add-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-option {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.add-option:hover { background: var(--surface-3); border-color: var(--border-strong); }
.add-option-ico {
  width: 42px; height: 42px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  flex-shrink: 0;
}
.add-option-text { display: flex; flex-direction: column; min-width: 0; }
.add-option-text strong { font-size: 15px; font-weight: 600; }
.add-option-text small { font-size: 12px; color: var(--muted); }
.add-ai {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: 14px;
}
.add-ai-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; margin-bottom: 10px;
}
.add-ai-head svg { color: var(--accent); flex-shrink: 0; }
.add-ai-row { display: flex; gap: 8px; }
.add-ai-row input {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text); font-size: 15px; outline: none;
  transition: border-color .12s var(--ease);
}
.add-ai-row input:focus { border-color: var(--border-strong); }
.add-ai-row input::placeholder { color: var(--muted); }
@media (max-width: 720px) {
  .add-options { grid-template-columns: 1fr; }
  .add-ai-row { flex-direction: column; }
}

/* ============================================================
   Изображения в markdown
   ============================================================ */
.md .md-img {
  max-width: 100%;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  display: block;
  margin: 10px 0;
}
.md .md-img-block { margin: 8px 0; }
.md p:has(> img.md-img) { margin: 8px 0; }

/* ============================================================
   Аналитика: подписи метрик
   ============================================================ */
.metric .s {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.3;
}
.chart-value { font-size: 10.5px; font-weight: 600; }






/* ============================================================
   Ссылки (закладки)
   ============================================================ */
.links-body { display: flex; flex-direction: column; gap: 16px; }
.links-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 160px 130px;
  gap: 8px;
  align-items: center;
}
.links-search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.links-search svg { color: var(--muted); flex-shrink: 0; }
.links-search input {
  flex: 1; min-width: 0;
  padding: 10px 0;
  border: none; outline: none; background: transparent;
  color: var(--text); font-size: 16px;
}
.links-search input::placeholder { color: var(--muted); }

.links-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 150px auto;
  gap: 8px;
  align-items: center;
}
.links-add-row input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text); font-size: 15px; outline: none;
}
.links-add-row input:focus { border-color: var(--border-strong); }
.links-add-row input::placeholder { color: var(--muted); }

.links-groups { display: flex; flex-direction: column; gap: 8px; }
.group-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.group-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 13px; font-weight: 500;
}
.group-chip .group-del {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 6px;
  border-radius: var(--r-pill);
}
.group-chip .group-del:hover { color: var(--err); }
.group-add { display: flex; gap: 8px; align-items: center; }
.group-add input {
  flex: 1; min-width: 0; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text); font-size: 15px; outline: none;
}
.group-add input:focus { border-color: var(--border-strong); }

.links-blocklist {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 10px 12px;
}
.links-blocklist summary {
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--text); user-select: none;
}
.blocklist-add { display: flex; gap: 8px; margin: 10px 0; align-items: center; }
.blocklist-add input {
  flex: 1; min-width: 0; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: 15px; outline: none;
}
.blocklist-add input:focus { border-color: var(--border-strong); }
.blocklist-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.block-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-family: var(--font-mono); font-size: 12px;
}
.block-chip .block-type { color: var(--muted); }
.block-chip .block-value { color: var(--text); }
.block-chip .group-del {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 6px;
}
.block-chip .group-del:hover { color: var(--err); }

.links-list { display: flex; flex-direction: column; gap: 10px; }
.link-row {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 12px 14px;
}
.link-row-top { display: flex; gap: 12px; align-items: flex-start; }
.link-dot {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 15px;
}
.link-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.link-title-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 15px; font-weight: 600;
  padding: 3px 6px; border-radius: var(--r-xs);
  outline: none;
}
.link-title-input:hover, .link-title-input:focus {
  border-color: var(--border); background: var(--surface);
}
.link-url-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.link-url-line a {
  color: var(--accent); text-decoration: none;
  font-family: var(--font-mono); font-size: 12.5px;
  word-break: break-all;
}
.link-url-line a:hover { text-decoration: underline; text-underline-offset: 3px; }
.link-row-bottom { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.link-tags-input {
  flex: 1; min-width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: 13.5px; outline: none;
}
.link-tags-input:focus { border-color: var(--border-strong); }
.link-group-select { max-width: 180px; }

@media (max-width: 720px) {
  .links-toolbar { grid-template-columns: 1fr 1fr; }
  .links-search { grid-column: span 2; }
  .links-add-row { grid-template-columns: 1fr 1fr; }
  .links-add-row input:first-child { grid-column: span 2; }
  .link-row-bottom { align-items: stretch; }
  .link-tags-input { flex: 1 1 100%; }
  .link-group-select { max-width: none; flex: 1; }
}



/* ============================================================
   Настройки: вкладки
   ============================================================ */
.settings-tabs { margin-bottom: 18px; width: 100%; }
.settings-tabs button { flex: 1; }

/* ============================================================
   Разделы (Задачи / Заметки / Ссылки)
   ============================================================ */
.mode-tabs {
  width: 100%; max-width: 1200px;
  display: flex; gap: 4px; padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.mode-tabs button {
  flex: 1; min-height: 42px;
  border: none; background: transparent;
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 15px; font-weight: 500;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.mode-tabs button:hover { color: var(--text); }
.mode-tabs button.active { background: var(--surface-3); color: var(--text); }

/* ============================================================
   Защита от горизонтального скролла
   ============================================================ */
html { max-width: 100%; overflow-x: hidden; }
.app > * { min-width: 0; }
.content-card { min-width: 0; }
.item-row, .item-body { min-width: 0; }
.item-title, .item-desc, .view-heading { overflow-wrap: anywhere; }
.md img, .md .md-img { max-width: 100%; height: auto; }
.md table { display: block; max-width: 100%; overflow-x: auto; }
.md pre { max-width: 100%; }
.topbar-actions { flex-wrap: nowrap; }

/* ============================================================
   Запись: просмотр и правка в одном окне
   ============================================================ */
.editor-modal { max-width: 720px; }
.editor-modal[data-mode='view'] .edit-only,
.editor-modal[data-mode='edit'] .view-only { display: none !important; }
.editor-modal.busy .modal-body { opacity: .55; pointer-events: none; transition: opacity .15s var(--ease); }

.type-badge {
  font-size: 13px; font-weight: 500; color: var(--muted);
  padding: 5px 11px;
  border: 1px solid var(--border); border-radius: var(--r-pill);
  background: var(--surface-2);
}

/* --- правка --- */
.editor-form { display: flex; flex-direction: column; min-width: 0; }
.editor-form .field-title { margin-bottom: 18px; }
.deadline-field { max-width: 300px; margin-bottom: 18px; }
.modal-body input[type='datetime-local'] {
  min-width: 0; max-width: 100%;
  -webkit-appearance: none; appearance: none;
  min-height: 46px;
}
.editor-form .toolbar { margin: 0 0 8px; }

.editor-form textarea {
  display: block; width: 100%;
  min-height: 160px;
  resize: none; overflow: hidden;      /* высоту ведёт autoGrow — вложенного скролла нет */
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-family: var(--font-sans);
  font-size: 16px; line-height: 1.65; letter-spacing: 0;
}
.editor-form textarea.font-mono { font-family: var(--font-mono); font-size: 15px; }

.ai-hint {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 2px 0;
  font-size: 13px; color: var(--muted);
}
.ai-hint svg { color: var(--accent); flex-shrink: 0; }

.params {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.params > summary {
  list-style: none;
  display: flex; align-items: center; gap: 12px;
  min-height: 46px; padding: 0 14px;
  font-size: 14.5px; font-weight: 500;
  cursor: pointer; user-select: none;
}
.params > summary::-webkit-details-marker { display: none; }
.params > summary small {
  margin-left: auto; min-width: 0;
  font-size: 13px; font-weight: 400; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.params > summary::after {
  content: ''; flex-shrink: 0;
  width: 7px; height: 7px; margin: -3px 2px 0 0;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .15s var(--ease);
}
.params[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
.params .form-grid { padding: 4px 14px 16px; margin: 0; gap: 14px; }

.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opt {
  flex: 1 1 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: color .12s var(--ease), border-color .12s var(--ease), background .12s var(--ease);
}
.seg-opt:hover { color: var(--text); border-color: var(--border-strong); }
.seg-opt.active { color: var(--text); border-color: var(--text); background: var(--accent-soft); }
.seg-opt .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.seg-mono { font-family: var(--font-mono); }

/* --- развёрнутый просмотр --- */
.editor-view { min-width: 0; }
.view-heading {
  margin: 0 0 12px;
  font-size: 24px; line-height: 1.25; font-weight: 600;
  letter-spacing: var(--track-tighter);
}
.view-heading.done { text-decoration: line-through; color: var(--muted); }
.view-deadline {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 12px;
  font-size: 14px; color: var(--muted);
}
.view-deadline svg { flex-shrink: 0; }
.view-deadline.soon { color: var(--warn); }
.view-deadline.overdue { color: var(--err); }
.view-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.view-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px;
  border: 1px solid var(--border); border-radius: var(--r-pill);
  background: var(--surface-2);
  font-size: 13px; color: var(--text);
}
.view-chip.tag { color: var(--muted); }
.view-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.view-chip.imp-red .dot { background: var(--err); }
.view-chip.imp-yellow .dot { background: var(--warn); }
.view-chip.imp-green .dot { background: var(--ok); }
.view-body { font-size: 16px; line-height: 1.7; }
.view-body.md h1 { font-size: 21px; }
.view-body.md h2 { font-size: 18px; }
.view-body.md h3 { font-size: 16px; }
.view-body.md p, .view-body.md li { font-size: inherit; }
.view-body.font-mono { font-size: 14.5px; }
.view-empty { margin: 0; color: var(--muted); }
.view-done { width: 100%; justify-content: center; min-height: 46px; margin-top: 24px; }
.view-done.is-done { color: var(--muted); }
.view-stamp { margin-top: 18px; font-size: 12.5px; color: var(--muted); }

/* ============================================================
   Тост с действием («Отменить»)
   ============================================================ */
.toast .toast-msg { flex: 1; min-width: 0; }
.toast-action {
  flex-shrink: 0;
  min-height: 36px; padding: 0 10px; margin: -6px -8px -6px 0;
  border: none; border-radius: var(--r-sm);
  background: transparent; color: var(--accent);
  font-size: 14px; font-weight: 600;
}
.toast-action:hover { background: var(--accent-soft); }

/* ============================================================
   Настройки ИИ: переключатели
   ============================================================ */
.pref-group {
  margin-bottom: 18px; padding: 4px 14px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
}
.pref-title { padding: 10px 0 4px; font-size: 14px; font-weight: 600; }
.pref { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; cursor: pointer; }
.pref + .pref { border-top: 1px solid var(--border); }
.pref[data-pref-sub] { padding-left: 30px; }
.pref input { flex-shrink: 0; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.pref > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pref b { font-size: 14.5px; font-weight: 500; }
.pref small { font-size: 13px; line-height: 1.45; color: var(--muted); }
.pref input:disabled + span { opacity: .5; }
.pref-note { padding: 6px 0 12px; font-size: 12.5px; color: var(--muted); }

/* ============================================================
   Мобильная версия
   ============================================================ */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .mode-tabs button { min-height: 44px; font-size: 15px; }

  /* Окно записи подстраивается под экранную клавиатуру (см. bindViewport) */
  .modal-overlay { inset: var(--vvt, 0px) 0 auto 0; height: var(--vvh, 100dvh); }
  .modal { max-height: none; height: 100%; }

  .editor-modal .modal-body { padding: 16px 16px 24px; }
  .editor-form .field-title { margin-bottom: 14px; padding-bottom: 12px; }
  .deadline-field { max-width: none; margin-bottom: 14px; }
  .editor-form textarea { min-height: 180px; padding: 12px; }
  .field input, .field select,
  .modal-body input[type='text'], .modal-body input[type='email'], .modal-body input[type='password'] { min-height: 46px; }
  .params .form-grid { padding: 2px 12px 14px; }
  .seg-opt { padding: 8px 10px; }
  .view-heading { font-size: 22px; }
  .view-body { font-size: 16px; }

  .toast-stack { width: calc(100vw - 20px); }
  .pref[data-pref-sub] { padding-left: 24px; }
}
@media (max-width: 380px) {
  .mode-tabs button { font-size: 14px; padding: 0 6px; }
  .seg-opt { font-size: 13px; padding: 8px; gap: 6px; }
}

/* ============================================================
   Кнопка «Изменить через ИИ» и её action-sheet
   ============================================================ */
.tool-ai { color: var(--accent); }
.tool-ai:hover { background: var(--accent-soft); border-color: var(--accent); }
.tool-ai.loading {
  pointer-events: none;
  opacity: .6;
}
.tool-ai.loading svg {
  animation: ai-spin 1s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-edit-sheet { max-width: 460px; }
.ai-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.ai-edit-grid .sheet-btn { padding: 14px; font-size: 15px; }
.ai-edit-grid .sheet-btn:nth-child(5) { grid-column: span 2; }

.ai-edit-custom {
  display: flex;
  gap: 8px;
}
.ai-edit-custom input {
  flex: 1; min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  font-size: 15px; outline: none;
  transition: border-color .12s var(--ease);
}
.ai-edit-custom input:focus { border-color: var(--border-strong); }
.ai-edit-custom input::placeholder { color: var(--muted); }
.ai-edit-custom .btn { padding: 12px 16px; }

@media (max-width: 720px) {
  .ai-edit-grid { grid-template-columns: 1fr; }
  .ai-edit-grid .sheet-btn:nth-child(5) { grid-column: auto; }
  .ai-edit-custom { flex-direction: column; }
}