/* ─── Токены ──────────────────────────────────────────────────────────────── */

:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f2f0ea;
  --surface-3: #eae7de;
  --border: #e3ded2;
  --border-strong: #d2ccbc;
  --text: #1f231f;
  --text-2: #565c53;
  --text-3: #8a8f83;
  --accent: #3d6b5c;
  --accent-strong: #2b5245;
  --accent-soft: #e7f0ea;
  --accent-soft-border: #cadfd0;
  /* Текст поверх заливки акцентом — свой в каждой теме, чтобы контраст не ломался */
  --on-accent: #ffffff;
  --warn: #a4652a;
  --warn-soft: #f6ead9;
  --danger: #a4402f;
  --danger-soft: #f6e0da;
  --shadow-sm: 0 1px 2px rgba(30, 30, 20, .05);
  --shadow: 0 1px 2px rgba(30, 30, 20, .04), 0 6px 20px -8px rgba(30, 30, 20, .12);
  --shadow-lg: 0 4px 8px rgba(30, 30, 20, .06), 0 20px 50px -12px rgba(30, 30, 20, .22);
  --radius: 10px;
  --sans: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141613;
    --surface: #1b1e1a;
    --surface-2: #22261f;
    --surface-3: #2b2f27;
    --border: #33372f;
    --border-strong: #444a3e;
    --text: #eceee7;
    --text-2: #a9ada0;
    --text-3: #767c6d;
    --accent: #7bb59b;
    --accent-strong: #96cdb2;
    --accent-soft: #1e2a23;
    --accent-soft-border: #2e4536;
    --on-accent: #10150f;
    --warn: #d99a56;
    --warn-soft: #2e2417;
    --danger: #dd8672;
    --danger-soft: #2f1e19;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -10px rgba(0, 0, 0, .5);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, .35), 0 24px 60px -12px rgba(0, 0, 0, .65);
  }
}

[data-theme="dark"] {
  --bg: #141613;
  --surface: #1b1e1a;
  --surface-2: #22261f;
  --surface-3: #2b2f27;
  --border: #33372f;
  --border-strong: #444a3e;
  --text: #eceee7;
  --text-2: #a9ada0;
  --text-3: #767c6d;
  --accent: #7bb59b;
  --accent-strong: #96cdb2;
  --accent-soft: #1e2a23;
  --accent-soft-border: #2e4536;
  --on-accent: #10150f;
  --warn: #d99a56;
  --warn-soft: #2e2417;
  --danger: #dd8672;
  --danger-soft: #2f1e19;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -10px rgba(0, 0, 0, .5);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, .35), 0 24px 60px -12px rgba(0, 0, 0, .65);
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любой display у класса.
   Без этого правила .login-screen{display:grid} перебивает браузерное
   [hidden]{display:none}, и форма входа остаётся висеть поверх приложения
   даже после успешного входа — выглядит так, будто пароль не сработал. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
  text-wrap: balance;
}

button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { background: var(--surface); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* ─── Общие элементы ──────────────────────────────────────────────────────── */

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.text-btn {
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px 0;
  font-size: 13px;
  text-align: left;
}
.text-btn:hover { color: var(--accent-strong); }

input[type="text"], input[type="password"], input[type="date"],
input[type="datetime-local"], textarea, select {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 11px;
  width: 100%;
  transition: border-color .12s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  outline: none;
}
textarea { resize: vertical; min-height: 70px; font-family: inherit; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-bottom: 5px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── Вход ────────────────────────────────────────────────────────────────── */

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
  z-index: 100;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 34px 30px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 25px; }
.login-sub { color: var(--text-2); margin: -8px 0 4px; font-size: 14px; }
.login-error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 9px 12px;
  border-radius: 8px;
  margin: 0;
  font-size: 14px;
}

/* ─── Каркас ──────────────────────────────────────────────────────────────── */

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

.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.brand {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  padding-left: 8px;
}
.sidebar-close { display: none; }

.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-2);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14.5px;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-item .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.nav-item.active .count { color: var(--accent-strong); }
.nav-item .count.alert { color: var(--danger); font-weight: 600; }
.nav-item .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.nav-item .glyph { width: 18px; text-align: center; flex-shrink: 0; opacity: .85; }

.nav-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-3);
  padding: 0 10px 7px;
}
.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 8px; }
.tag-pill {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
}
.tag-pill:hover, .tag-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent-soft-border);
  color: var(--accent-strong);
}

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.menu-btn { display: none; }
.capture { flex: 1; display: flex; gap: 8px; min-width: 0; }
.capture input { flex: 1; min-width: 0; }

.content { flex: 1; overflow-y: auto; padding: 26px 28px 60px; }
.view { max-width: 940px; }
.view-head { margin-bottom: 22px; }
.view-head h1 { font-size: 27px; margin-bottom: 3px; }
.view-sub { color: var(--text-3); font-size: 14px; font-family: var(--mono); }

.sidebar-scrim, .bottom-nav { display: none; }

/* ─── Задачи ──────────────────────────────────────────────────────────────── */

.task-list { display: flex; flex-direction: column; gap: 5px; }

.task {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .12s ease, box-shadow .12s ease, opacity .2s ease;
}
.task:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.task.done { opacity: .5; }
.task.done .task-title { text-decoration: line-through; }
.task.leaving { opacity: 0; transform: translateX(8px); }

.checkbox {
  width: 19px;
  height: 19px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.checkbox:hover { border-color: var(--accent); }
.checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
  animation: pop .18s ease;
}
.checkbox svg { width: 12px; height: 12px; stroke: var(--on-accent); opacity: 0; }
.checkbox.checked svg { opacity: 1; }

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

.task-body { flex: 1; min-width: 0; }
.task-title { display: block; word-break: break-word; }
.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip.mono { font-family: var(--mono); }
.chip.due-soon { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.chip.overdue { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.chip.tag { font-family: var(--mono); }
.chip.author { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-strong); }
.chip.untriaged { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

.prio { font-family: var(--mono); font-size: 11.5px; font-weight: 600; letter-spacing: .04em; }
.prio-3 { color: var(--danger); }
.prio-2 { color: var(--warn); }
.prio-1 { color: var(--text-3); }

.flag-btn { color: var(--text-3); font-size: 14px; }
.flag-btn.on { color: var(--warn); }

.subtask-progress {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 24px 0 9px;
  font-family: var(--mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-3);
}
.group-head:first-child { margin-top: 0; }
.group-head .line { flex: 1; height: 1px; background: var(--border); }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-3);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text-2); margin-bottom: 4px; font-weight: 600; }

/* ─── Дашборд ─────────────────────────────────────────────────────────────── */

.greeting { font-family: var(--serif); font-size: 30px; margin-bottom: 4px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 11px;
  margin-bottom: 26px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
}
.stat .label {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-bottom: 3px;
}
.stat .value {
  font-family: var(--serif);
  font-size: 27px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat.alert { border-color: var(--danger); background: var(--danger-soft); }
.stat.alert .value, .stat.alert .label { color: var(--danger); }
.stat.good { border-color: var(--accent-soft-border); background: var(--accent-soft); }
.stat.good .value, .stat.good .label { color: var(--accent-strong); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 19px;
  margin-bottom: 16px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
  gap: 10px;
}
.panel-head h3 { font-size: 16px; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }

/* Мини-график недели */
.spark { display: flex; align-items: flex-end; gap: 6px; height: 74px; }
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.spark-bar {
  width: 100%;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  transition: height .3s ease;
}
.spark-col.today .spark-bar { background: var(--accent); border-color: var(--accent); }
.spark-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
}
.spark-value {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* Здоровье проектов */
.project-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.project-row:last-child { border-bottom: none; }
.project-row:hover .project-name { color: var(--accent-strong); }
.project-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-track {
  width: 88px;
  height: 5px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
  flex-shrink: 0;
}
.progress-fill { height: 100%; border-radius: 99px; transition: width .3s ease; }
.project-counts {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  width: 54px;
  text-align: right;
  flex-shrink: 0;
}

/* ─── Доска Now / Next / Later ────────────────────────────────────────────── */

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.board-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 180px;
}
.board-col.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.board-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-3);
  margin-bottom: 10px;
}
.board-col .task { cursor: grab; }
.board-col .task.dragging { opacity: .4; }

/* ─── Панель задачи ───────────────────────────────────────────────────────── */

.drawer-scrim, .modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 19, .42);
  z-index: 50;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100%);
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 51;
  overflow-y: auto;
  padding: 22px 24px 60px;
  animation: slide-in .2s ease;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.drawer h2 { font-size: 20px; }
.drawer-section { margin-top: 22px; }
.drawer-section > h4 {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-bottom: 9px;
  font-weight: 500;
}
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.subtask {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.subtask:last-child { border-bottom: none; }
.subtask.done span { text-decoration: line-through; opacity: .55; }
.subtask span { flex: 1; font-size: 14px; }

/* ─── Модальные окна ──────────────────────────────────────────────────────── */

.modal-scrim { display: grid; place-items: center; padding: 20px; }
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 24px 26px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slide-up .2s ease;
}
@keyframes slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 20px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

/* Ответ ИИ */
.ai-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 15px 18px;
  margin-top: 14px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-output h1, .ai-output h2, .ai-output h3 { font-size: 16px; margin: 12px 0 6px; }
.ai-output ul { margin: 6px 0; padding-left: 20px; }
.ai-output a { color: var(--accent-strong); }
.ai-output code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  padding: .1em .35em;
  border-radius: 4px;
}
.ai-sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--text-3);
}
.ai-sources li { margin-bottom: 3px; }

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid var(--accent-soft-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  padding: 14px 0;
  font-size: 14px;
}

/* ─── Уведомления ─────────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 9px 17px;
  border-radius: 99px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
  max-width: 90vw;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── Мобильная версия ────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 272px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding-top: max(18px, env(safe-area-inset-top));
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: inline-flex; }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 22, 19, .42);
    z-index: 59;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }

  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .capture input { font-size: 16px; } /* 16px не даёт iOS зумить при фокусе */
  .capture .btn { padding: 7px 11px; }

  .content { padding: 18px 14px 96px; }
  .view-head h1, .greeting { font-size: 23px; }

  .board { grid-template-columns: 1fr; }
  .panel-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .drawer {
    width: 100%;
    top: auto;
    height: 92vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    animation: slide-up-sheet .22s ease;
    padding-bottom: max(60px, env(safe-area-inset-bottom));
  }
  @keyframes slide-up-sheet { from { transform: translateY(100%); } to { transform: none; } }

  /* Нижняя навигация — основной способ переключения на телефоне */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav button {
    flex: 1;
    border: none;
    background: none;
    padding: 9px 4px 7px;
    color: var(--text-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    font-size: 10.5px;
  }
  .bottom-nav button .glyph { font-size: 17px; }
  .bottom-nav button.active { color: var(--accent-strong); }

  .toast-stack { bottom: 76px; }
}

@media (max-width: 400px) {
  .capture #capture-ai-btn { display: none; }
}
