/* TaskFlow — личный менеджер задач. Тема адаптируется под систему. */

:root {
  color-scheme: light dark;

  --bg: #f4f5f8;
  --bg-elev: #ffffff;
  --bg-sunken: #eceef3;
  --line: #dfe2ea;
  --line-soft: #e9ebf1;
  --text: #171a20;
  --text-dim: #626a7a;
  --text-faint: #8a92a3;

  --accent: #5b5bd6;
  --accent-soft: #eceafd;
  --accent-text: #ffffff;

  --p1: #e5484d;
  --p2: #e8930c;
  --p3: #3b82f6;
  --p4: #9aa2b1;

  --ok: #2ba36a;
  --warn: #e8930c;
  --danger: #e5484d;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 8px 24px rgba(16, 20, 30, .07);
  --shadow-lg: 0 12px 48px rgba(16, 20, 30, .22);

  --sidebar-w: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-elev: #171a21;
    --bg-sunken: #12141a;
    --line: #262b35;
    --line-soft: #1f242d;
    --text: #e8eaf0;
    --text-dim: #9aa3b2;
    --text-faint: #6b7482;

    --accent: #7c7cf0;
    --accent-soft: #23234a;

    --p1: #f2555a;
    --p2: #f0a02a;
    --p3: #5b9bf8;
    --p4: #78808f;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, .55);
  }
}

/* Явный выбор темы в настройках перебивает системный */
:root[data-theme="light"] {
  --bg: #f4f5f8; --bg-elev: #fff; --bg-sunken: #eceef3;
  --line: #dfe2ea; --line-soft: #e9ebf1;
  --text: #171a20; --text-dim: #626a7a; --text-faint: #8a92a3;
  --accent: #5b5bd6; --accent-soft: #eceafd;
  --p1: #e5484d; --p2: #e8930c; --p3: #3b82f6; --p4: #9aa2b1;
  --shadow: 0 1px 2px rgba(16,20,30,.06), 0 8px 24px rgba(16,20,30,.07);
  --shadow-lg: 0 12px 48px rgba(16,20,30,.22);
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-elev: #171a21; --bg-sunken: #12141a;
  --line: #262b35; --line-soft: #1f242d;
  --text: #e8eaf0; --text-dim: #9aa3b2; --text-faint: #6b7482;
  --accent: #7c7cf0; --accent-soft: #23234a;
  --p1: #f2555a; --p2: #f0a02a; --p3: #5b9bf8; --p4: #78808f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
.muted { color: var(--text-dim); }
.hidden { display: none !important; }

/* ---------- Каркас ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100%;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: calc(18px + var(--safe-t)) 14px 16px;
  background: var(--bg-sunken);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 2px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: linear-gradient(140deg, var(--accent), #b06cf0);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 0;
  background: no-repeat center/13px 13px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12.5 9.5 18 20 6'/%3E%3C/svg%3E");
}
.brand-name { font-weight: 640; letter-spacing: -.2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim);
  text-align: left; font-weight: 500;
}
.nav-item:hover { background: var(--line-soft); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; flex: none; }
.nav-item .count {
  margin-left: auto; font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--text-faint); background: var(--bg-elev);
  padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line);
}
.nav-item[aria-current="page"] .count { color: var(--accent); background: transparent; border-color: transparent; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sync-line { font-size: 12px; color: var(--text-faint); padding: 0 4px; line-height: 1.4; }
.sync-line b { font-weight: 600; color: var(--text-dim); }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; }

.topbar {
  display: flex; align-items: flex-end; gap: 12px;
  padding: calc(18px + var(--safe-t)) 24px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 22px; font-weight: 680; letter-spacing: -.4px; }
.topbar-title p { font-size: 12.5px; margin-top: 2px; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--text-dim); font-size: 16px;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); border-color: var(--line); }
.icon-btn.spin { animation: spin .9s linear infinite; }
.icon-btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.icon-btn.active {
  color: var(--accent); border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
@keyframes spin { to { transform: rotate(360deg); } }

.content {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px 24px calc(80px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}
.content > * { max-width: 780px; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--text);
  font-weight: 550; font-size: 14px;
}
.btn:hover { border-color: var(--text-faint); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-sunken); color: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--line); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Поле добавления ---------- */

.composer {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.composer input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 15px;
}
.composer input::placeholder { color: var(--text-faint); }
.composer .plus {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 16px; line-height: 1;
  background: var(--accent); color: #fff; border: 0;
}
.composer-hint { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }
@media (max-width: 620px) { .composer-hint { display: none; } }

/* ---------- Список задач ---------- */

.group { margin-bottom: 22px; }
.group-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12px; font-weight: 660; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); padding: 0 4px 8px;
}
.group-head .n { font-weight: 500; letter-spacing: 0; text-transform: none; }
.group-head.overdue { color: var(--p1); }

.task-list {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.task {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 13px 11px 0;
  border-bottom: 1px solid var(--line-soft);
  position: relative;
  /* Строка тянется удержанием пальца, а iOS на то же удержание показывает
     всплывающее меню «Скопировать» — оно перебило бы жест. */
  -webkit-touch-callout: none;
}
.task:last-child { border-bottom: 0; }
.task:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.task::before {
  content: ""; width: 3px; align-self: stretch; flex: none;
  background: var(--prio, transparent); border-radius: 0 3px 3px 0;
}
.task[data-p="1"] { --prio: var(--p1); }
.task[data-p="2"] { --prio: var(--p2); }
.task[data-p="3"] { --prio: var(--p3); }
.task[data-p="4"] { --prio: transparent; }

.check {
  flex: none; width: 20px; height: 20px; margin-top: 1px;
  border: 1.8px solid var(--text-faint); border-radius: 50%;
  background: transparent; padding: 0;
  display: grid; place-items: center; transition: background .12s, border-color .12s;
}
.check:hover { border-color: var(--accent); }
.task[data-p="1"] .check { border-color: var(--p1); }
.task[data-p="2"] .check { border-color: var(--p2); }
.task.done .check { background: var(--ok); border-color: var(--ok); }
.check::after {
  content: ""; width: 11px; height: 11px; opacity: 0;
  background: no-repeat center/11px 11px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12.5 9.5 18 20 6'/%3E%3C/svg%3E");
}
.task.done .check::after { opacity: 1; }

.task-body { flex: 1; min-width: 0; }
.task-title { word-break: break-word; }
.task.done .task-title { color: var(--text-faint); text-decoration: line-through; }

.task-meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 9px;
  margin-top: 3px; font-size: 12px; color: var(--text-faint);
}
.task-meta .due.is-overdue { color: var(--p1); font-weight: 600; }
.task-meta .due.is-today { color: var(--accent); font-weight: 600; }
.task-meta .chip-p {
  font-weight: 700; font-size: 10.5px; letter-spacing: .3px;
  padding: 1px 5px; border-radius: 5px;
  color: #fff; background: var(--prio, var(--p4));
}
.task[data-p="4"] .chip-p { background: var(--p4); }
.task-meta .synced { color: var(--ok); }
.task-meta .syncerr { color: var(--danger); }

.task-open {
  position: absolute; inset: 0 0 0 32px;
  background: transparent; border: 0; padding: 0;
  font: inherit; color: transparent; text-align: left;
}

/* ---------- Перетаскивание задач ---------- */

.drag-handle {
  /* поверх .task-open, который перекрывает всю строку */
  position: relative; z-index: 2;
  flex: none; align-self: center;
  width: 26px; height: 26px; margin-right: -4px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px; padding: 0;
  background: transparent; color: var(--text-faint);
  font-size: 15px; line-height: 1;
  cursor: grab; touch-action: none;
  opacity: 0; transition: opacity .12s, background .12s, color .12s;
}
.task:hover .drag-handle, .drag-handle:focus-visible { opacity: 1; }
.drag-handle:hover { background: var(--bg-sunken); color: var(--text-dim); }
.drag-handle:active { cursor: grabbing; }
/* На тач-экранах наведения нет — ручка всегда видна. Строку там можно тянуть
   и за любое место, но ручка берёт её сразу, без удержания. */
@media (hover: none) { .drag-handle { opacity: .6; } }
[data-no-drag] .drag-handle { display: none; }

body.is-dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
body.is-dragging .task:hover { background: transparent; }
body.is-dragging .task-open { pointer-events: none; }

/* Оригинальная строка остаётся в потоке и показывает место вставки.
   Прячем её прозрачностью, а не visibility: скрытый элемент теряет pointer capture. */
.task.drag-src {
  opacity: .3;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  outline: 1.5px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -3px;
}

/* Копия, летящая за курсором. */
.task.drag-ghost {
  position: fixed; z-index: 60; margin: 0;
  pointer-events: none; border-bottom: 0;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
  transform: scale(1.015); opacity: .96;
}
.task.drag-ghost .drag-handle { opacity: 1; }

.empty {
  text-align: center; padding: 54px 20px; color: var(--text-faint);
}
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .55; }
.empty p { font-size: 14px; }

/* ---------- Баннеры ---------- */

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 12px 24px 0; padding: 10px 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-elev); font-size: 13px; color: var(--text-dim);
  max-width: 780px;
}
.banner.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: color-mix(in srgb, var(--warn) 9%, var(--bg-elev)); }
.banner b { color: var(--text); font-weight: 600; }
.banner .close { margin-left: auto; background: none; border: 0; color: var(--text-faint); font-size: 16px; line-height: 1; padding: 0 2px; }

/* ---------- Модалки / шторки ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 10, 16, .5);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade .14s ease-out;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  width: min(560px, 100%);
  max-height: min(86vh, 760px);
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: rise .18s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft); flex: none;
}
.sheet-head h2 { font-size: 15px; font-weight: 640; }
.sheet-head .spacer { margin-left: auto; }
.sheet-body { padding: 16px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line-soft); flex: none;
  background: var(--bg-elev);
}
.sheet-foot .spacer { margin-left: auto; }

@media (max-width: 640px) {
  .overlay { padding: 0; align-items: flex-end; }
  .sheet {
    width: 100%; max-height: 92vh;
    border-radius: 18px 18px 0 0; border-bottom: 0;
  }
  .sheet-foot { padding-bottom: calc(12px + var(--safe-b)); }
}

/* ---------- Формы ---------- */

.field { margin-bottom: 15px; }
.field > label, .field-label {
  display: block; font-size: 11.5px; font-weight: 650; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px;
}
.input, .textarea, .select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 74px; line-height: 1.5; }
.input-title { font-size: 17px; font-weight: 600; padding: 6px 0; border: 0; background: transparent; }
.input-title:focus { border: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 130px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 520;
  border: 1px solid var(--line); background: var(--bg); color: var(--text-dim);
}
.chip:hover { border-color: var(--text-faint); color: var(--text); }
.chip[aria-pressed="true"], .chip.active {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 620;
}
.chip.chip-clear { color: var(--text-faint); }

.prio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.prio-btn {
  display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text-dim);
}
.prio-btn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.prio-btn .lbl { font-weight: 660; font-size: 13px; color: var(--c); }
.prio-btn .sub { font-size: 11.5px; color: var(--text-faint); }
.prio-btn[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 11%, transparent); }
.prio-btn > div { min-width: 0; }

.subtasks { display: flex; flex-direction: column; gap: 2px; }
.subtask { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.subtask .check { width: 17px; height: 17px; border-radius: 5px; }
.subtask.done .check { background: var(--ok); border-color: var(--ok); }
.subtask.done .st-title { color: var(--text-faint); text-decoration: line-through; }
.subtask .st-title { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 2px 0; }
.subtask .rm { border: 0; background: none; color: var(--text-faint); font-size: 15px; line-height: 1; padding: 2px 4px; opacity: 0; }
.subtask:hover .rm { opacity: 1; }
.subtask .rm:hover { color: var(--danger); }
.subtask-add { display: flex; align-items: center; gap: 9px; padding: 4px 0; color: var(--text-faint); }
.subtask-add span { width: 17px; text-align: center; }
.subtask-add input { flex: 1; border: 0; background: transparent; outline: none; padding: 2px 0; }

.hint { font-size: 12px; color: var(--text-faint); margin-top: 6px; line-height: 1.45; }

/* ---------- Moments ---------- */

.moments-progress { height: 3px; background: var(--line-soft); border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.moments-progress i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.moments-task { margin-bottom: 18px; }
.moments-task h3 { font-size: 18px; font-weight: 640; line-height: 1.3; word-break: break-word; }
.moments-task .notes { font-size: 13px; color: var(--text-dim); margin-top: 6px; white-space: pre-wrap; }
.moments-task .cur { font-size: 12px; color: var(--text-faint); margin-top: 7px; }
.when-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.when-btn {
  padding: 12px; border-radius: 11px; text-align: left;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-weight: 560; font-size: 14px;
}
.when-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.when-btn small { display: block; font-weight: 450; font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.when-btn:hover small { color: inherit; opacity: .8; }
.daypart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-top: 7px; }

/* ---------- Календарь ---------- */

.cal-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.cal-day { margin-bottom: 16px; }
.cal-day h3 {
  font-size: 12px; font-weight: 660; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); padding: 0 4px 7px;
}
.ev-list { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ev {
  display: flex; gap: 11px; padding: 10px 13px;
  border-bottom: 1px solid var(--line-soft); align-items: flex-start;
}
.ev:last-child { border-bottom: 0; }
.ev .t { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text-dim); width: 82px; flex: none; }
.ev .b { min-width: 0; flex: 1; }
.ev .b .s { word-break: break-word; }
.ev .b .c { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.ev .bar { width: 3px; align-self: stretch; border-radius: 3px; background: var(--accent); flex: none; }

.embed-wrap {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--bg-elev); height: min(70vh, 680px);
}
.embed-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- Настройки ---------- */

.settings-section { margin-bottom: 22px; }
.settings-section > h3 {
  font-size: 12px; font-weight: 660; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); margin-bottom: 10px;
}
.kv { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 13.5px; }
.kv .k { color: var(--text-dim); }
.kv .v { margin-left: auto; font-weight: 550; }
.dot-status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-faint); }
.dot-status.on { background: var(--ok); }
.dot-status.off { background: var(--text-faint); }
.dot-status.err { background: var(--danger); }
.switch-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.switch-row label { flex: 1; font-size: 14px; }
.switch-row .hint { margin-top: 2px; }

/* ---------- Тосты ---------- */

.toast-root {
  position: fixed; z-index: 90;
  left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b));
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 9px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 520;
  box-shadow: var(--shadow-lg); pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  animation: rise .16s ease-out;
}
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Мобильная навигация ---------- */

.tabbar { display: none; }
.fab { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }

  .topbar { padding: calc(14px + var(--safe-t)) 16px 10px; }
  .topbar-title h1 { font-size: 20px; }
  .content { padding: 14px 16px calc(164px + var(--safe-b)); }
  .banner { margin: 10px 16px 0; }

  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + var(--safe-b));
  }
  .tabbar .nav-item {
    flex-direction: column; gap: 2px; padding: 5px 2px;
    font-size: 10.5px; font-weight: 550; justify-content: center; align-items: center;
    border-radius: 10px;
  }
  .tabbar .nav-item .ico { font-size: 17px; width: auto; }
  .tabbar .nav-item .count { display: none; }
  .tabbar .nav-item[aria-current="page"] { background: transparent; }

  .fab {
    display: grid; place-items: center;
    position: fixed; right: 16px; bottom: calc(74px + var(--safe-b)); z-index: 25;
    width: 52px; height: 52px; border-radius: 50%; border: 0;
    background: var(--accent); color: #fff; font-size: 27px; line-height: 1; font-weight: 300;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  .toast-root { bottom: calc(152px + var(--safe-b)); }
  .prio-grid { grid-template-columns: 1fr; }
  .when-grid { grid-template-columns: 1fr; }

  /* Пальцем целиться труднее, чем курсором, и держат телефон дальше от глаз,
     чем смотрят в монитор. На узких экранах увеличиваем и текст, и иконки,
     и сами зоны нажатия. Настольной вёрстки это не касается. */
  body { font-size: 16.5px; }

  .topbar-title h1 { font-size: 23px; }
  .topbar-title p { font-size: 13.5px; }
  .icon-btn { width: 40px; height: 40px; font-size: 19px; }

  .composer { padding: 13px 14px; }
  /* Ровно 17px, а не 15: Safari на iOS увеличивает всю страницу при фокусе
     на поле мельче 16px — экран дёргался при каждом добавлении задачи. */
  .composer input { font-size: 17px; }
  .composer .plus { width: 27px; height: 27px; font-size: 20px; }

  .task { padding: 14px 13px 14px 0; gap: 13px; }
  .task-title { font-size: 16.5px; }
  .task-meta { font-size: 13px; gap: 5px 10px; margin-top: 4px; }
  .task-meta .chip-p { font-size: 11.5px; padding: 2px 6px; }
  .check { width: 24px; height: 24px; border-width: 2px; }
  .check::after { width: 13px; height: 13px; background-size: 13px 13px; }
  .drag-handle { width: 34px; height: 34px; font-size: 19px; }

  .group-head { font-size: 13px; }
  .empty .big { font-size: 42px; }
  .empty p { font-size: 15px; }

  .tabbar .nav-item { font-size: 11.5px; padding: 7px 2px; gap: 3px; }
  .tabbar .nav-item .ico { font-size: 22px; }

  .fab {
    width: 60px; height: 60px; font-size: 32px;
    bottom: calc(82px + var(--safe-b)); right: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; transition-duration: .001s !important; }
}
