/* «Тихая бумага»: тёплая нейтраль как основа, синий — только для действий,
   ссылок, фокуса и статуса «в обработке». Цвет здесь — дефицитный ресурс. */

:root {
  color-scheme: light dark;

  /* Поверхности и текст (тёплая нейтраль, hue ~40). */
  --paper: #F7F5F1;
  --surface: #FFFFFF;
  --surface-2: #F1EEE9;
  --surface-3: #E9E5DE;
  --text: #1A1917;
  --text-2: #55524C;
  --text-3: #7A756E;
  --line: #E4DFD7;
  --line-strong: #D4CDC2;

  /* Роли. */
  --accent: #2C5AA0;
  --accent-hover: #234A87;
  --accent-soft: #E9EEF7;
  --accent-line: #C0D0E9;
  --accent-on: #FFFFFF;
  --success: #3E7A5E;
  --success-soft: #E6F0EA;
  --warning: #8A6114;
  --warning-soft: #F7EDD8;
  --danger: #A63A32;
  --danger-soft: #F8E9E5;
  --danger-on: #FFFFFF;
  --focus-ring: rgb(44 90 160 / 30%);
  --scrim: rgb(26 25 23 / 40%);

  /* Тени: мягкие, тёплые, почти без цвета. */
  --shadow-xs: 0 1px 2px rgb(33 28 20 / 5%);
  --shadow-sm: 0 1px 2px rgb(33 28 20 / 4%), 0 2px 6px rgb(33 28 20 / 4%);
  --shadow-md: 0 2px 4px rgb(33 28 20 / 4%), 0 12px 28px -8px rgb(33 28 20 / 10%);
  --shadow-lg: 0 4px 10px -4px rgb(33 28 20 / 8%), 0 30px 60px -24px rgb(33 28 20 / 18%);
  --panel-inset: 0 0 rgb(0 0 0 / 0%);

  /* Радиусы. */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 22px;
  --r-full: 999px;

  /* Ритм: всё кратно 4. */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-14: 56px;
  --sp-18: 72px;
  --sp-24: 96px;
  --shell-max: 1060px;

  /* Движение. */
  --ease: cubic-bezier(.2, .6, .3, 1);
  --t-fast: 120ms;
  --t: 160ms;
  --t-slow: 220ms;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

/* Тёмная тема — тёплый уголь, а не чёрный и не синий.
   :not([data-theme="light"]) оставляет задел под ручной переключатель кукой. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141312;
    --surface: #1C1B19;
    --surface-2: #232220;
    --surface-3: #2C2A27;
    --text: #F0EEEA;
    --text-2: #B4AFA7;
    --text-3: #8A857D;
    --line: #2E2C29;
    --line-strong: #3E3B37;
    --accent: #8FB4F5;
    --accent-hover: #AEC9FA;
    --accent-soft: #1A2434;
    --accent-line: #32456A;
    --accent-on: #10192B;
    --success: #6FBF95;
    --success-soft: #172820;
    --warning: #DCAE55;
    --warning-soft: #2B2313;
    --danger: #E88C80;
    --danger-soft: #2E1B18;
    --danger-on: #221310;
    --focus-ring: rgb(143 180 245 / 38%);
    --scrim: rgb(0 0 0 / 55%);
    --shadow-xs: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%), 0 2px 8px rgb(0 0 0 / 22%);
    --shadow-md: 0 2px 6px rgb(0 0 0 / 28%), 0 16px 32px -10px rgb(0 0 0 / 40%);
    --shadow-lg: 0 40px 70px -28px rgb(0 0 0 / 60%);
    --panel-inset: inset 0 1px 0 rgb(255 255 255 / 4%);
  }
}

/* Явный светлый набор — задел под ручной переключатель кукой: перекрывает
   системную тёмную, даже если системная схема говорит обратное. */
:root[data-theme="light"] {
  color-scheme: light; /* иначе системная тёмная перекрасит нативные чекбоксы и скроллбары */
  --paper: #F7F5F1;
  --surface: #FFFFFF;
  --surface-2: #F1EEE9;
  --surface-3: #E9E5DE;
  --text: #1A1917;
  --text-2: #55524C;
  --text-3: #7A756E;
  --line: #E4DFD7;
  --line-strong: #D4CDC2;
  --accent: #2C5AA0;
  --accent-hover: #234A87;
  --accent-soft: #E9EEF7;
  --accent-line: #C0D0E9;
  --accent-on: #FFFFFF;
  --success: #3E7A5E;
  --success-soft: #E6F0EA;
  --warning: #8A6114;
  --warning-soft: #F7EDD8;
  --danger: #A63A32;
  --danger-soft: #F8E9E5;
  --danger-on: #FFFFFF;
  --focus-ring: rgb(44 90 160 / 30%);
  --scrim: rgb(26 25 23 / 40%);
  --shadow-xs: 0 1px 2px rgb(33 28 20 / 5%);
  --shadow-sm: 0 1px 2px rgb(33 28 20 / 4%), 0 2px 6px rgb(33 28 20 / 4%);
  --shadow-md: 0 2px 4px rgb(33 28 20 / 4%), 0 12px 28px -8px rgb(33 28 20 / 10%);
  --shadow-lg: 0 4px 10px -4px rgb(33 28 20 / 8%), 0 30px 60px -24px rgb(33 28 20 / 18%);
  --panel-inset: 0 0 rgb(0 0 0 / 0%);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141312;
  --surface: #1C1B19;
  --surface-2: #232220;
  --surface-3: #2C2A27;
  --text: #F0EEEA;
  --text-2: #B4AFA7;
  --text-3: #8A857D;
  --line: #2E2C29;
  --line-strong: #3E3B37;
  --accent: #8FB4F5;
  --accent-hover: #AEC9FA;
  --accent-soft: #1A2434;
  --accent-line: #32456A;
  --accent-on: #10192B;
  --success: #6FBF95;
  --success-soft: #172820;
  --warning: #DCAE55;
  --warning-soft: #2B2313;
  --danger: #E88C80;
  --danger-soft: #2E1B18;
  --danger-on: #221310;
  --focus-ring: rgb(143 180 245 / 38%);
  --scrim: rgb(0 0 0 / 55%);
  --shadow-xs: 0 1px 2px rgb(0 0 0 / 30%);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%), 0 2px 8px rgb(0 0 0 / 22%);
  --shadow-md: 0 2px 6px rgb(0 0 0 / 28%), 0 16px 32px -10px rgb(0 0 0 / 40%);
  --shadow-lg: 0 40px 70px -28px rgb(0 0 0 / 60%);
  --panel-inset: inset 0 1px 0 rgb(255 255 255 / 4%);
}

/* ── База ─────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
  hyphens: manual;
}

/* Базовый текст — 15px/1.62; root остаётся 16px, чтобы rem-шкала заголовков
   считалась от системного размера. */
body { margin: 0; min-width: 320px; overflow-x: hidden; font-size: 15px; line-height: 1.62; }

a { color: inherit; text-decoration: none; }
a:not([class]) { color: var(--accent); }

button, input, select, textarea { font: inherit; color: var(--text); }
button, select, summary { cursor: pointer; }
svg { display: block; flex: none; }

h1, h2, h3, p, dl, dd, figure { margin-top: 0; }

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

/* Голый :focus не подсвечиваем — иначе кольцо ловит мышь. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.muted { color: var(--text-3); }

.shell { width: min(var(--shell-max), 100%); margin-inline: auto; padding: 0 var(--sp-4); }
main.shell { padding-top: var(--sp-6); padding-bottom: var(--sp-18); }

/* ── Шапка ────────────────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper); /* фолбэк до color-mix (Safari < 16.2) */
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  border-bottom: 1px solid var(--line);
  border-bottom-color: color-mix(in srgb, var(--line) 70%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
}

@supports not (backdrop-filter: blur(1px)) {
  .site-header { background: var(--paper); }
}

.nav { min-height: 56px; display: flex; align-items: center; gap: var(--sp-3); }
.nav form { margin: 0; }

.brand { display: inline-flex; align-items: center; gap: var(--sp-2); }
.brand-text { font-size: 15px; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: var(--paper);
  background: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.nav-links { display: flex; align-items: center; gap: 2px; margin-left: auto; }

.nav-links a {
  padding: var(--sp-2) 10px;
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: 13.5px;
  font-weight: 500;
  transition: color var(--t) var(--ease), background-color var(--t) var(--ease);
}

.nav-links a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.nav-actions { display: flex; align-items: center; gap: var(--sp-1); }

.review-counter {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 5px var(--sp-2);
  border-radius: var(--r-full);
  color: var(--text-2);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.review-counter::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--warning);
}

.review-counter b { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--text-3);
  background: transparent;
  transition: color var(--t) var(--ease), background-color var(--t) var(--ease);
}

/* ── Заголовки страниц ────────────────────────────────────────────────── */

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 1.15rem + 2.6vw, 2.5rem);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -.028em;
}

h2 { margin-bottom: var(--sp-3); font-size: 17px; line-height: 1.3; font-weight: 600; letter-spacing: -.012em; }

.eyebrow {
  margin-bottom: 6px;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.page-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: 28px;
}

.page-heading > div { min-width: 0; }
.count-label { flex: none; color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ── Панели ───────────────────────────────────────────────────────────── */

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--panel-inset), var(--shadow-sm);
}

.panel > h2 { margin-bottom: 18px; }
.panel p, .panel .prose { max-width: 68ch; }

.section-title { display: flex; align-items: start; justify-content: space-between; gap: var(--sp-3); margin-bottom: 18px; }
.section-title h2 { margin-bottom: 0; }
.section-title p, .section-title > span { margin: 2px 0 0; color: var(--text-3); font-size: 13px; line-height: 1.45; }
.section-title.ruled { padding-bottom: var(--sp-3); border-bottom: 1px solid var(--line); }

/* ── Быстрое добавление ───────────────────────────────────────────────── */

.quick-add {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 52px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--panel-inset), var(--shadow-sm);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.quick-add input[type="text"] {
  flex: 1;
  min-width: 0;
  height: auto;
  padding: var(--sp-2) 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.quick-add input[type="text"]:focus { outline: 0; box-shadow: none; }
.quick-add input::placeholder { color: var(--text-3); }

/* Фокус подсвечивает весь композер, а не одно поле внутри него. */
.quick-add:focus-within {
  border-color: var(--accent-line);
  box-shadow: var(--shadow-sm), 0 0 0 3px var(--focus-ring);
}

.quick-add .button { flex: none; height: 38px; }
.quick-add .button .icon { display: none; }

/* ── Фильтры ──────────────────────────────────────────────────────────── */

/* Не карточка: у фильтров нет ни фона, ни рамки, ни тени. */
.filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: var(--sp-4) 0 var(--sp-3);
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

.chips {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  color: var(--text-2);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease), background-color var(--t) var(--ease);
}

.chip.active { border-color: transparent; color: var(--paper); background: var(--text); font-weight: 600; }

.category-filter { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--sp-2); }
.category-filter label { color: var(--text-2); font-size: 12.5px; font-weight: 600; letter-spacing: .006em; }

.select-wrap { position: relative; min-width: 0; }

.select-wrap::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--text-3);
  border-bottom: 1.5px solid var(--text-3);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select-wrap select { height: 34px; padding-right: var(--sp-8); border-radius: var(--r-sm); appearance: none; -webkit-appearance: none; }

/* ── Список задач: одна карточка с хайрлайнами ────────────────────────── */

.task-list {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--panel-inset), var(--shadow-sm);
  overflow: hidden;
}

.task-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--sp-3);
  padding: 14px;
  transition: background-color var(--t-fast) var(--ease);
}

.task-row + .task-row { border-top: 1px solid var(--line); }
.task-row:active { background: var(--surface-3); transform: translateY(.5px); }

.source-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  color: var(--text-3);
  background: var(--surface-2);
}

.task-main { min-width: 0; display: grid; gap: 6px; }

.task-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-size: 15.5px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -.008em;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.45;
  gap: var(--sp-2) 0;
}

.task-meta > * + * { margin-left: var(--sp-2); }
.task-meta > * + *::before { content: "·"; margin-right: var(--sp-2); color: var(--line-strong); }
.task-meta .owner { color: var(--text-2); }
.task-meta .lang { font-family: var(--font-mono); font-size: 12px; text-transform: uppercase; }
.task-meta time { font-variant-numeric: tabular-nums; }

.tag-line { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); color: var(--text-3); font-size: 12px; }
.tag::before { content: "#"; color: var(--line-strong); }

.flags { display: flex; align-items: center; gap: var(--sp-2); }
.flag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.flag.urgent { color: var(--danger); }
.flag.urgent::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-full); background: currentColor; }
.flag.important { padding: 2px var(--sp-2); border: 1px solid var(--line-strong); border-radius: var(--r-full); color: var(--text-2); }
.chevron { color: var(--line-strong); transition: color var(--t) var(--ease); }
.row-action { display: flex; align-items: center; }
.row-action form { margin: 0; }

/* ── Статусы: четыре смысла вместо семи цветов ────────────────────────── */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  padding: 3px 9px;
  border-radius: var(--r-full);
  color: var(--text-2);
  background: var(--surface-2);
  font-size: 11.5px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: .01em;
}

.status .dot { width: 5px; height: 5px; border-radius: var(--r-full); background: currentColor; }
.status-ready .dot { background: var(--success); }
.status-archived { opacity: .7; }

.status-recorded, .status-transcribed, .status-enriching { color: var(--accent); background: var(--accent-soft); }
.status-recorded .dot, .status-transcribed .dot, .status-enriching .dot { animation: pulse 1.8s ease-in-out infinite; }

.status-needs_review, .status-error { color: var(--warning); background: var(--warning-soft); }
.status-deleted { color: var(--danger); background: var(--danger-soft); }

/* Внутри пилюли фон уже не --surface: приглушённый --text-3 там не читается. */
.task-meta .status { color: var(--text-2); }
.task-meta .status-recorded, .task-meta .status-transcribed, .task-meta .status-enriching { color: var(--accent); }
.task-meta .status-needs_review, .task-meta .status-error { color: var(--warning); }
.task-meta .status-deleted { color: var(--danger); }
.task-meta .status::before { content: none; margin: 0; }

/* ── Пустые состояния ─────────────────────────────────────────────────── */

.empty { padding: 64px var(--sp-6); text-align: center; }
.empty .empty-icon { margin: 0 auto var(--sp-3); color: var(--line-strong); stroke-width: 1.5; }
.empty h2 { margin: 0 0 var(--sp-1); font-size: 16px; font-weight: 600; color: var(--text); }
.empty p { margin: 0 auto; max-width: 34ch; color: var(--text-3); font-size: 14px; }
.empty .button { margin-top: var(--sp-4); }

/* ── Матрица ──────────────────────────────────────────────────────────── */

.matrix { display: grid; gap: var(--sp-3); }
.quadrant { display: grid; align-content: start; }
.quadrant > header { display: flex; align-items: start; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.quadrant h2 { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: 0; }
.quadrant h2::before { content: ""; width: 8px; height: 8px; border-radius: var(--r-full); background: var(--text-3); }
.quadrant-urgent_important h2::before { background: var(--danger); }
.quadrant-important h2::before { background: var(--accent); }
.quadrant-urgent h2::before { background: var(--warning); }
.quadrant header p { margin: 2px 0 0; color: var(--text-3); font-size: 13px; }

.quadrant header > .count {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 24px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  color: var(--text-2);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.quadrant-items { display: grid; gap: var(--sp-2); }

.matrix-card {
  display: grid;
  gap: var(--sp-1);
  padding: var(--sp-3);
  border-radius: 12px;
  background: var(--surface-2);
  transition: background-color var(--t) var(--ease);
}

.matrix-card strong { font-size: 14px; line-height: 1.35; font-weight: 600; }
.matrix-card span, .matrix-card small { color: var(--text-3); font-size: 12px; }
.quadrant-empty { margin: 0; padding: var(--sp-5) 0; text-align: center; color: var(--text-3); font-size: 13px; }

/* ── Карточка задачи ──────────────────────────────────────────────────── */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--sp-5);
  color: var(--text-3);
  font-size: 13.5px;
  font-weight: 500;
  transition: color var(--t) var(--ease);
}

.task-heading { display: flex; flex-direction: column; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.task-heading > div { min-width: 0; }
.heading-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }

.task-heading h1 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2rem);
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -.024em;
}

.task-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.task-actions form { margin: 0; display: contents; }
/* Действия карточки — компактный ряд; главное действие всегда первым. */
.task-actions .button { height: 34px; padding: 0 11px; font-size: 12.5px; }
.task-actions .button.primary { order: -1; }

.card-layout, .main-column, .side-column { display: grid; gap: var(--sp-4); align-content: start; }

.audio-wrap { padding: var(--sp-2); border-radius: var(--r-sm); background: var(--surface-2); }
.audio-wrap audio { display: block; width: 100%; height: 40px; }

/* ── Формы ────────────────────────────────────────────────────────────── */

.form-stack { display: grid; gap: 18px; }
.form-stack > label, .category-fields label { display: grid; gap: 6px; color: var(--text-2); font-size: 12.5px; line-height: 1.3; font-weight: 600; letter-spacing: .006em; }
.form-grid { display: grid; gap: var(--sp-3); }

input, select, textarea {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: 16px; /* на iOS всё, что меньше 16px, зумит страницу при фокусе */
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

input, select { height: 44px; padding: 0 var(--sp-3); }
textarea { min-height: 160px; max-width: 68ch; padding: var(--sp-3); line-height: 1.62; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px var(--focus-ring);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) input,
  :root:not([data-theme="light"]) select,
  :root:not([data-theme="light"]) textarea { background: var(--surface-2); }
  :root:not([data-theme="light"]) .quick-add input[type="text"] { background: transparent; }
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea { background: var(--surface-2); }
:root[data-theme="dark"] .quick-add input[type="text"] { background: transparent; }

.check-row { display: flex; flex-wrap: wrap; gap: var(--sp-5); }
.check { display: flex; align-items: center; gap: var(--sp-2); color: var(--text); font-size: 14px; font-weight: 400; letter-spacing: 0; }
.check input { width: 18px; height: 18px; padding: 0; accent-color: var(--accent); }

/* Тот же композер, что и быстрое добавление: рамка вокруг всего блока,
   поле внутри без собственной рамки, фокус подсвечивает блок целиком. */
.refine-form {
  display: grid;
  gap: var(--sp-2);
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.refine-form input {
  min-width: 0;
  height: 38px;
  padding: 0 var(--sp-2);
  border: 0;
  background: transparent;
  box-shadow: none;
}

.refine-form input:focus-visible { outline: 0; box-shadow: none; }
.refine-form input::placeholder { color: var(--text-3); }
.refine-form:focus-within { border-color: var(--accent-line); box-shadow: var(--shadow-xs), 0 0 0 3px var(--focus-ring); }
.refine-form .button { height: 38px; }

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  background: var(--surface);
  font-size: 13.5px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: -.004em;
  white-space: nowrap;
  transition: color var(--t) var(--ease), background-color var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.button.primary { border-color: transparent; color: var(--accent-on); background: var(--accent); font-weight: 600; box-shadow: var(--shadow-xs); }
.button.quiet { border-color: transparent; color: var(--text-2); background: transparent; }
/* Фолбэк строкой выше color-mix — Safari < 16.2 иначе останется без рамки. */
.button.danger-quiet { color: var(--danger); border-color: var(--line-strong); background: transparent; }
.button.danger-quiet { border-color: color-mix(in srgb, var(--danger) 26%, transparent); }
.button.danger { border-color: transparent; color: var(--danger-on); background: var(--danger); font-weight: 600; }
.button.small { height: 34px; padding: 0 11px; font-size: 12.5px; }
.button.wide { width: 100%; height: 48px; }
.button[disabled], .button.disabled { opacity: .5; pointer-events: none; }

/* ── Транскрипт, сведения, история, вложения ──────────────────────────── */

.transcript summary { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); font-size: 15px; font-weight: 600; }
.transcript summary span { color: var(--text-3); font-size: 13px; font-weight: 400; }
.transcript .transcript-text { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); color: var(--text-2); font-size: 15px; line-height: 1.62; white-space: pre-wrap; }

.facts dl, .history dl { margin: 0; }
.facts dl > div { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); min-height: 38px; border-bottom: 1px solid var(--line); }
.facts dl > div:last-child { border-bottom: 0; }
.facts dt { color: var(--text-3); font-size: 13px; }
.facts dd { margin: 0; color: var(--text); font-size: 13.5px; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts .platform-link { display: inline-flex; align-items: center; justify-content: flex-end; gap: var(--sp-1); color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 3px; }
.facts .platform-link:hover { color: var(--accent-hover); text-decoration-color: currentColor; }
.facts .platform-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--r-xs); }

.history { display: grid; }
.history details { padding: var(--sp-3) 0; }
.history details + details { border-top: 1px solid var(--line); }
.history summary { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); font-size: 13px; font-weight: 600; }
.history time { color: var(--text-3); font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }
.history .command { margin: var(--sp-2) 0 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); color: var(--text-2); background: var(--surface-2); font-size: 13.5px; font-style: italic; }
.history dl { margin-top: var(--sp-2); }
.history dl > div { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 5px 0; font-size: 12.5px; }
.history dt { color: var(--text-3); }
.history dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.attachment-list { display: grid; gap: 6px; }

.attachment-list a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: 44px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  transition: background-color var(--t) var(--ease);
}

.attachment-list a > svg { color: var(--text-3); }
.attachment-list .file { min-width: 0; display: grid; }
.attachment-list strong { overflow: hidden; font-size: 13.5px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.attachment-list small { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── Флеш-сообщения ───────────────────────────────────────────────────── */

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--sp-4);
  padding: var(--sp-3) 14px;
  border-radius: var(--r-md);
  border-left: 3px solid var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 13.5px;
  font-weight: 500;
}

.flash.success { border-left-color: var(--success); color: var(--success); background: var(--success-soft); }
.flash.error { border-left-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.flash.compact { margin-bottom: var(--sp-4); }

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

.settings-layout { display: grid; gap: var(--sp-4); }
.category-list { display: grid; gap: var(--sp-3); }
.category-item { display: grid; gap: 10px; padding: 14px; border-radius: var(--r-md); background: var(--surface-2); }
.category-item.inactive { opacity: .6; }
.category-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.category-item .state { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 12px; }
.category-item.active .state::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-full); background: var(--success); }
.category-fields { display: grid; gap: var(--sp-2); }
.category-fields label { color: var(--text-2); }
.category-buttons { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

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

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding-block: var(--sp-8) !important; }

.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: var(--sp-3);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--panel-inset), var(--shadow-lg);
}

.login-card .brand-mark { width: 32px; height: 32px; border-radius: var(--r-sm); font-size: 15px; }
.login-brand { margin-bottom: var(--sp-2); }
.login-card h1 { margin-bottom: var(--sp-1); font-size: 28px; font-weight: 600; letter-spacing: -.024em; }
.login-card .login-lead { margin-bottom: var(--sp-6); color: var(--text-3); font-size: 14px; }
.login-card .button.wide { justify-content: flex-start; gap: 10px; }
.login-admin { margin-top: var(--sp-5); }
.login-admin > summary { color: var(--text-3); font-size: 13px; }
.login-admin .form-stack { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); }

/* ── htmx: видимая, но не мельтешащая индикация ───────────────────────── */

#hx-bar {
  position: fixed;
  top: 56px;
  left: 0;
  z-index: 30;
  width: 100%;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  pointer-events: none;
}

#hx-bar.htmx-request { opacity: 1; animation: hxbar 1.4s var(--ease) infinite; }

.htmx-request .button[type="submit"] { color: transparent; pointer-events: none; position: relative; }

.htmx-request .button[type="submit"]::after {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: var(--r-full);
  border: 2px solid var(--line-strong); /* фолбэк до color-mix */
  border-color: color-mix(in srgb, var(--accent-on) 40%, transparent);
  border-top-color: var(--accent-on);
  animation: spin 700ms linear infinite;
}

.htmx-request .button[type="submit"]:not(.primary)::after {
  border-color: color-mix(in srgb, var(--text) 25%, transparent);
  border-top-color: var(--text);
}

.htmx-swapping { opacity: .55; transition: opacity var(--t-fast) var(--ease); }
.htmx-settling { opacity: 1; }
/* Регион поллинга обновляется сам раз в 8 с — гасить его нельзя, замигает. */
#task-list-region.htmx-swapping { opacity: 1; }

/* Появление строк — только когда список сменился по действию пользователя
   (добавление задачи, чип, фильтр: innerHTML в #inbox-content, класс settling
   достаётся самому #inbox-content). У поллинга своп outerHTML, и htmx вешает
   settling на новый #task-list-region — общий селектор .htmx-settling .task-row
   переигрывал бы анимацию каждые 8 с, то есть ровно тот моргающий список,
   который запрещён. Поэтому правило привязано к #inbox-content. */
#inbox-content.htmx-settling .task-row { animation: rise 180ms var(--ease) both; }

@keyframes hxbar {
  0% { transform: scaleX(0); }
  60% { transform: scaleX(.8); }
  100% { transform: scaleX(1); opacity: .2; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

/* ── Ховеры: только там, где есть настоящий курсор ────────────────────── */

@media (hover: hover) and (pointer: fine) {
  .nav-links a:hover { color: var(--text); background: var(--surface-2); }
  .icon-button:hover { color: var(--text); background: var(--surface-2); }
  .chip:hover { border-color: var(--line-strong); color: var(--text); }
  .chip.active:hover { border-color: transparent; color: var(--paper); }
  .task-row:hover { background: var(--surface-2); }
  .task-row:hover .chevron { color: var(--text-3); }
  .matrix-card:hover { background: var(--surface-3); }
  .back-link:hover { color: var(--text); }
  .attachment-list a:hover { background: var(--surface-3); }
  .button:hover { background: var(--surface-2); }
  .button.primary:hover { background: var(--accent-hover); }
  .button.quiet:hover { background: var(--surface-2); color: var(--text); }
  .button.danger-quiet:hover { background: var(--danger-soft); }
  .button.danger:hover { filter: brightness(.94); }
  .review-counter:hover { background: var(--surface-3); }
}

/* ── Адаптив ──────────────────────────────────────────────────────────── */

@media (max-width: 479px) {
  /* Композер узкий: кнопка схлопывается до плюса, подпись уходит в sr-only. */
  .quick-add .button { width: 38px; padding: 0; }
  .quick-add .button .icon { display: block; }
  .quick-add .button .button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
}

@media (max-width: 619px) {
  .brand-text { display: none; }
  .login-brand .brand-text { display: inline; }
  .brand, .nav-actions { flex: none; }

  /* У админа в шапке четыре пункта: на 320px они не влезают и срезали бы
     кнопку выхода. Ряд ссылок скроллится так же, как ряд чипов. */
  .nav-links {
    margin-left: 0;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
  }

  .nav-links::-webkit-scrollbar { display: none; }
  .nav-links a { flex: none; padding-inline: 6px; font-size: 13px; }
  .review-counter span { display: none; }
  .task-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
  .task-actions .button { width: 100%; height: 44px; font-size: 13.5px; }
  .task-actions .button.primary { grid-column: 1 / -1; }
}

@media (min-width: 640px) {
  .shell { padding-inline: var(--sp-6); }
  main.shell { padding-top: var(--sp-8); }
  .nav { min-height: 68px; }
  #hx-bar { top: 68px; }
  .page-heading { margin-bottom: 36px; }
  .panel { padding: var(--sp-6); }
  .filters { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--sp-3); }
  .chips { mask-image: none; padding-bottom: 0; }
  .category-filter { flex: none; min-width: 260px; }
  .task-row { padding: var(--sp-4) 18px; align-items: center; }
  .source-icon { width: 30px; height: 30px; }
  .task-title { font-size: 16px; }
  .matrix { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
  .task-heading { flex-direction: row; align-items: end; justify-content: space-between; }
  .task-actions { justify-content: flex-end; }
  .form-grid, .category-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .refine-form { grid-template-columns: minmax(0, 1fr) auto; align-items: center; min-height: 52px; padding: 6px 6px 6px var(--sp-2); }
  input, select, textarea { font-size: 15px; }
  input, select { height: 42px; }
  .select-wrap select { height: 34px; }
  .login-card { padding: var(--sp-8); }
}

@media (min-width: 900px) {
  .card-layout { grid-template-columns: minmax(0, 1.7fr) minmax(300px, .8fr); }
  .settings-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-models { grid-column: 1 / -1; }
}

/* ── Меньше движения ──────────────────────────────────────────────────── */

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

  /* Смысл состояния должен читаться цветом и наличием элемента, не движением. */
  #hx-bar.htmx-request { opacity: 1; transform: scaleX(1); }
  .status .dot { opacity: 1; }
}
