/* ==========================================================================
   Ответ на требование ФНС — стили.
   Принципы: системный шрифт, сдержанная палитра, полупрозрачные панели поверх контента,
   мгновенный отклик на нажатие, пружинные переходы; учёт prefers-reduced-motion /
   prefers-contrast и тёмной темы; поверхности — сплошная заливка.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafc;
  --surface-sunken: #ececf0;
  /* Поверхности хрома и всплывающих окон — сплошная заливка: сквозь них не просвечивает содержимое. */
  --material: #fbfbfd;
  --material-strong: #ffffff;
  --text: #1d1d1f;
  --text-2: #55555a;
  --text-3: #69696e;
  --separator: rgba(60, 60, 67, 0.12);
  --border: #d2d2d7;
  /* Граница полей ввода — единственное, что очерчивает поле на карточке: не ниже 3:1. */
  --field-border: #8e8e93;
  --accent: #0071e3;
  --accent-press: #005bbf;
  /* Заливка кнопок с белым текстом; наведение — темнее. */
  --accent-fill: #0071e3;
  --accent-fill-press: #005bbf;
  --accent-tint: rgba(0, 113, 227, 0.1);
  --accent-text: #005bb8;
  --on-accent: #ffffff;
  --danger: #c00012;
  --danger-fill: #c00012;
  --danger-tint: rgba(215, 0, 21, 0.08);
  --ok: #1a7431;
  --ok-tint: rgba(36, 138, 61, 0.1);
  --warn: #a35200;
  --warn-tint: rgba(255, 149, 0, 0.14);
  --ph-fill: #ffe58f;
  --ph-check: #ffd2cc;
  --changed: rgba(255, 214, 10, 0.32);
  --paper: #ffffff;
  --paper-text: #141414;
  --user-bubble: var(--accent-fill);
  --user-text: #ffffff;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
  --shadow-paper: 0 1px 2px rgba(0, 0, 0, 0.06), 0 16px 48px rgba(0, 0, 0, 0.08);
  --shadow-thumb: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.06);

  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 18px;
  --radius-xl: 26px;
  /* Пункты списков и меню, сегменты, поиск. */
  --radius-item: 10px;
  --radius-pill: 999px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  /* Шкала размеров интерфейса. */
  --fs-2xs: 0.6875rem;
  --fs-xs: 0.75rem;
  --fs-s: 0.8125rem;
  --fs-sm: 0.875rem;
  --fs-md: 0.9375rem;
  --fs-body: 1rem;
  --fs-lg: 1.0625rem;
  --fs-xl: 1.25rem;
  --font-paper: "Times New Roman", Times, "PT Serif", "Liberation Serif", serif;

  /* Пружина без перелёта (damping 1, response 0.35), посчитанная в linear(). Перелёт — только у жестов с инерцией (шторка, JS). */
  --spring: linear(0, 0.09, 0.263, 0.441, 0.593, 0.711, 0.8, 0.863, 0.908, 0.938, 0.959, 0.973, 0.982, 0.989, 0.993, 0.995, 0.997, 0.998, 1);
  --dur: 0.5s;
  --press: 90ms;
  --t-fast: 0.15s;
  --t: 0.2s;

  --topbar-h: 52px;

  /* Ритм страницы: заголовок → содержимое, секция → секция; поле у края на телефоне. */
  --space-head: 24px;
  --space-section: 32px;
  --gutter: 16px;

  /* Наведение и нажатие — полупрозрачная заливка поверх любой поверхности (как systemFill в iOS):
     заметна одинаково на фоне, карточке и подложке. Бегунок — выбранный сегмент и пункт навигации. */
  --fill-hover: rgba(120, 120, 128, 0.12);
  --fill-press: rgba(120, 120, 128, 0.2);
  --fill-track: rgba(118, 118, 128, 0.12);
  --thumb: #ffffff;
  --hover-layer: linear-gradient(var(--fill-hover), var(--fill-hover));
  --press-layer: linear-gradient(var(--fill-press), var(--fill-press));

  /* Слои: от поднятого бара до тостов. Других значений z-index в стилях нет. */
  --z-raised: 2;
  --z-dropdown: 20;
  --z-topbar: 30;
  --z-sheet-scrim: 39;
  --z-sheet: 40;
  --z-overlay: 60;
  --z-popover: 61;
  --z-toast: 70;
  --z-skip: 100;

  /* Совместимость со старыми экранами (пошаговый режим, профиль). */
  --muted: var(--text-2);
  --accent-hover: var(--accent-press);
  --danger-bg: var(--danger-tint);
  --warn-bg: var(--warn-tint);
  --warn-border: #f0c75e;

  font-family: var(--font);
  font-size: 100%;
  line-height: 1.5;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  caret-color: var(--accent);
  scrollbar-color: color-mix(in srgb, var(--text-3) 55%, transparent) transparent;
}
::selection { background: color-mix(in srgb, var(--accent) 26%, transparent); }

/* Тёмная тема: data-theme ставит js/theme.js — по умолчанию как в системе, дальше по выбору пользователя. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #232325;
  --surface-sunken: #111113;
  --material: #161618;
  --material-strong: #2c2c2e;
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #8e8e93;
  --separator: rgba(84, 84, 88, 0.55);
  --border: #3a3a3c;
  --field-border: #6e6e73;
  --danger-fill: #d70015;
  --fill-hover: rgba(120, 120, 128, 0.24);
  --fill-press: rgba(120, 120, 128, 0.36);
  --fill-track: rgba(118, 118, 128, 0.24);
  --thumb: #636366;
  --accent-fill: #0a6fd6;
  --accent-fill-press: #085fb8;
  --accent: #0a84ff;
  --accent-press: #409cff;
  --accent-tint: rgba(10, 132, 255, 0.18);
  --accent-text: #4aa3ff;
  --danger: #ff453a;
  --danger-tint: rgba(255, 69, 58, 0.16);
  --ok: #32d74b;
  --ok-tint: rgba(50, 215, 75, 0.14);
  --warn: #ffb340;
  --warn-tint: rgba(255, 159, 10, 0.18);
  --ph-fill: #6b5a12;
  --ph-check: #6e2a26;
  --changed: rgba(255, 214, 10, 0.18);
  /* Лист остаётся светлым, чуть приглушённым: это документ, а не интерфейс. */
  --paper: #ececec;
  --paper-text: #141414;
  --user-bubble: var(--accent-fill);
  --shadow-1: 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.1);
  --shadow-paper: 0 0 0 0.5px rgba(255, 255, 255, 0.08), 0 16px 48px rgba(0, 0, 0, 0.6);
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.6), 0 0 0 0.5px rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] .paper mark.ph-fill { background: #ffe58f; }
[data-theme="dark"] .paper mark.ph-check { background: #ffd2cc; }


* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100dvh; background: var(--bg); display: flex; flex-direction: column; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--text-2); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: var(--z-skip); background: var(--surface); padding: 8px 12px; border-radius: var(--radius-s); box-shadow: var(--shadow-2); }
.skip-link:focus { top: 8px; }

/* --- верхняя панель (материал поверх контента) ------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--material);
  border-bottom: 0.5px solid var(--separator);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 6px; }
.nav { display: flex; gap: 2px; flex: 1; justify-content: center; }
.nav a {
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; padding: 6px 12px; border-radius: var(--radius-pill); white-space: nowrap;
  transition: background-color var(--t), color var(--t);
}
.nav a:hover { color: var(--text); background: var(--fill-hover); text-decoration: none; }
.nav a:active { background: var(--fill-press); }
.nav a[aria-current="page"] { color: var(--text); background: var(--thumb); box-shadow: var(--shadow-1); }
.user { display: flex; gap: 12px; align-items: center; font-size: var(--fs-s); }
.theme-btn { width: 32px; height: 32px; }
.user-email { color: var(--text-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
  .brand span, .user-email { display: none; }
  .topbar { gap: 8px; }
  .nav { justify-content: flex-start; }
  .nav a { padding: 6px 9px; font-size: var(--fs-s); }
}

/* --- компании: переключатель в шапке, меню, «От: …» ----------------------------------------------- */
.org-switch:empty { display: none; }
.org-switch-btn {
  display: inline-flex; align-items: center; gap: 6px; max-width: 260px; min-height: 32px; padding: 4px 8px 4px 12px;
  border: 0; border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--shadow-1); color: var(--text); font-size: var(--fs-sm); font-weight: 500;
}
.org-switch-btn:hover { background-image: var(--hover-layer); }
.org-switch-btn:active { background-image: var(--press-layer); }
.org-switch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-switch-kind { flex: none; padding: 1px 7px; border-radius: var(--radius-pill); background: var(--accent-tint); color: var(--accent-text); font-size: var(--fs-xs); font-weight: 500; }
.org-switch-btn .icon, .from-chip .icon { flex: none; color: var(--text-3); }
@media (max-width: 720px) { .org-switch { display: none; } }

.org-scrim { position: fixed; inset: 0; z-index: var(--z-overlay); }
.org-menu {
  position: fixed; z-index: var(--z-popover); width: 320px; max-height: min(480px, 70dvh); overflow: auto; padding: 6px;
  border-radius: var(--radius-l); background: var(--material-strong); box-shadow: var(--shadow-2);
  transform-origin: top left; animation: pop-in 0.32s var(--spring) both;
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.96) translateY(-4px); } }
.org-menu, .feed, .doc-scroll, .menu-versions { scrollbar-width: thin; }
.org-search-wrap { display: flex; align-items: center; gap: 8px; margin: 2px 2px 6px; padding: 0 10px; border-radius: var(--radius-item); background: var(--surface-sunken); color: var(--text-3); }
.org-search { border: 0; background: transparent; box-shadow: none; padding: 8px 0; min-height: 36px; font-size: var(--fs-md); }
.org-search:focus { box-shadow: none; }
.org-group { margin: 8px 10px 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); letter-spacing: 0.01em; }
.org-row {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 6px 10px 6px 4px;
  border: 0; border-radius: var(--radius-item); background: transparent; color: var(--text); font-size: var(--fs-md); text-align: left;
}
.org-row:hover, .org-row:focus-visible { background: var(--fill-hover); }
.org-row:active { background: var(--fill-press); }
.org-check { display: grid; place-items: center; width: 20px; flex: none; color: var(--accent-text); }
.org-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-row.is-current .org-name { font-weight: 600; }
.org-hint { flex: none; font-size: var(--fs-s); color: var(--text-3); font-variant-numeric: tabular-nums; }
.org-hint.is-soon { color: var(--warn); }
.org-hint.is-urgent, .org-hint.is-over { color: var(--danger); font-weight: 500; }
.org-empty { margin: 12px; color: var(--text-2); font-size: var(--fs-sm); }
.org-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; padding: 10px 10px 6px; border-top: 0.5px solid var(--separator); font-size: var(--fs-sm); }
.org-foot a { display: inline-flex; align-items: center; gap: 4px; }
/* Телефон: меню — шторка снизу. */
@media (max-width: 600px) {
  .org-scrim { background: rgba(0, 0, 0, 0.32); }
  .org-menu {
    top: auto !important; left: 0 !important; right: 0; bottom: 0; width: auto; max-height: 75dvh;
    padding: 10px 10px max(14px, env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0;
    transform-origin: bottom center; animation-name: sheet-in;
  }
  .org-row { min-height: 48px; }
}
@keyframes sheet-in { from { transform: translateY(100%); } }

.from-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 60%; min-height: 32px; padding: 4px 8px 4px 12px;
  border: 0; border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--text-2); font-size: var(--fs-s);
}
.from-chip:hover { color: var(--text); background-image: var(--hover-layer); }
.from-chip:active { background-image: var(--press-layer); }
.from-name { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.case-head-text { flex: 1; min-width: 0; }
.case-org { margin: 1px 0 0; font-size: var(--fs-s); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 var(--space-head); }
.filter-chip { padding: 5px 12px; border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--shadow-1); color: var(--text); font-size: var(--fs-sm); }
.filter-chip:hover { text-decoration: none; background-image: var(--hover-layer); }
.filter-chip:active { background-image: var(--press-layer); }
.filter-chip[aria-current="true"] { background: var(--accent-fill); color: var(--on-accent); box-shadow: none; }

/* «Реквизиты»: первый вход — выбор, для кого ответы; дальше — своя компания и клиенты. */
.choices { display: grid; gap: 12px; margin-bottom: var(--space-section); }
.choice {
  display: flex; align-items: center; gap: 14px; padding: 16px 14px 16px 16px; min-height: 72px;
  border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); color: var(--text);
}
.choice:hover { text-decoration: none; background-image: var(--hover-layer); }
.choice:active { background-image: var(--press-layer); }
.choice-icon { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 12px; background: var(--accent-tint); color: var(--accent-text); }
.choice-text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.choice-title { font-weight: 600; }
.choice-sub { font-size: var(--fs-sm); color: var(--text-2); }
.empty-clients { display: grid; gap: 12px; justify-items: start; padding: 16px; border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); }
.empty-clients p { margin: 0; color: var(--text-2); }
.back-link { display: inline-block; margin-bottom: 8px; font-size: var(--fs-md); }
.form-hint { margin: -8px 0 0; font-size: var(--fs-sm); color: var(--text-2); }
.segmented-wide { display: flex; }
.segmented-wide button { flex: 1; min-height: 34px; }
.segmented button[aria-pressed="true"], .segmented button[aria-pressed="true"]:hover { background: var(--thumb); box-shadow: var(--shadow-thumb); }
.actions-spacer { flex: 1; }

/* Модальное окно (<dialog>). */
.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 20px 22px 22px;
  border: 0; border-radius: var(--radius-xl); background: var(--surface); color: var(--text); box-shadow: var(--shadow-2);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.36); }
.dialog[open] { animation: pop-in 0.34s var(--spring) both; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: var(--fs-xl); letter-spacing: -0.015em; }

/* --- общий контейнер страниц --------------------------------------------------------------------- */
main { flex: 1; width: 100%; }
main:focus { outline: none; }
#view { max-width: 760px; margin: 0 auto; padding: 32px 16px 56px; }
body[data-route="c"] #view { max-width: none; padding: 0; }
body[data-route="home"] #view { max-width: 720px; }
#view:has(.review) { max-width: 1180px; }
.boot { color: var(--text-2); }
.footer { padding: 0 16px 24px; text-align: center; font-size: var(--fs-s); color: var(--text-3); }
body[data-route="c"] .footer { display: none; }
/* Экран входа по приглашению (стенд РФ): разделов и «Выйти» ещё нет. */
body[data-route="login"] :is(.nav, .org-switch, #logout) { display: none; }
.page { padding: 32px 16px; max-width: 760px; margin: 0 auto; }

h1 { font-family: var(--font-display); font-size: 1.75rem; line-height: 1.15; letter-spacing: -0.022em; font-weight: 700; margin: 0 0 8px; }
/* Заголовок страницы без подзаголовка отделён от содержимого так же, как вместе с ним. */
#view h1:not(.display, .case-title):not(:has(+ .lead, + .filter-chips)) { margin-bottom: var(--space-head); }
#view h1:has(+ .filter-chips) { margin-bottom: 12px; }
h1, h2, h3, .display, .choice-title, .demo-offer-title { text-wrap: balance; }
p, li, .hint, .msg-assistant, .choice-sub { text-wrap: pretty; }
h2 { font-size: var(--fs-lg); line-height: 1.3; letter-spacing: -0.01em; margin: 8px 0 0; }
h3 { font-size: var(--fs-body); margin: 8px 0 0; }
.lead { margin: 0 0 var(--space-head); color: var(--text-2); font-size: var(--fs-lg); letter-spacing: -0.005em; }
.display { font-size: clamp(2rem, 5.5vw, 3rem); line-height: 1.06; letter-spacing: -0.028em; font-weight: 700; }

/* --- кнопки ------------------------------------------------------------------------------------- */
:where(button) { font: inherit; color: inherit; }
button, .btn {
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform var(--press) ease-out, background-color var(--t), opacity var(--t), box-shadow var(--t);
}
button:active:not(:disabled), .btn:active { transform: scale(0.97); }
button:disabled { cursor: default; opacity: 0.4; }

/* Основная кнопка — только по явному классу .btn: у каждой кнопки в интерфейсе свой класс. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 18px; border-radius: var(--radius-pill); border: 0;
  background: var(--accent-fill); color: var(--on-accent); font-weight: 500; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--accent-fill-press); text-decoration: none; }
.btn-small { min-height: 32px; padding: 4px 12px; font-size: var(--fs-sm); }
button.secondary, .btn-secondary {
  min-height: 40px; padding: 8px 18px; border-radius: var(--radius-pill); border: 0;
  background: var(--accent-tint); color: var(--accent-text); font-weight: 500;
}
button.secondary:hover:not(:disabled), .btn.btn-secondary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-text); }
button.secondary:active:not(:disabled), .btn.btn-secondary:active:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.btn-icon {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--text-2);
}
.btn-icon:hover:not(:disabled) { background: var(--fill-hover); color: var(--text); }
.btn-icon:active:not(:disabled) { background: var(--fill-press); }
.btn-icon-sm { width: 28px; height: 28px; }
button.icon { padding: 2px 10px; border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--text); border: 0; min-height: 28px; }
button.link-danger { background: none; border: none; padding: 0; color: var(--danger); font-size: var(--fs-sm); }
.icon { flex: none; display: block; }
.deadline-pill, .dl-date, .dl-left, .deadline-date, .row-sub, .doc-meta, .version-meta, .pill, .attach-detail,
.composer-hint, .norm-meta, .summary dd, .case-org { font-variant-numeric: tabular-nums; }

/* --- формы и карточки (профиль, пошаговый режим) ------------------------------------------------ */
.card { background: var(--surface); border-radius: var(--radius-l); padding: 24px; box-shadow: var(--shadow-1); }
.form { display: grid; gap: 20px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) {
  .row { grid-template-columns: 1fr; }
  .card { padding: 20px var(--gutter); }
}
/* Метка, поле и подсказка — сверху вниз; поле не сползает, если соседняя подсказка в ряду длиннее. */
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-weight: 500; font-size: var(--fs-sm); }
.field .hint, .hint { font-size: var(--fs-s); color: var(--text-2); margin: 0; }
.field .error { font-size: var(--fs-s); color: var(--danger); }
.field .error:empty { display: none; }
input, select, textarea {
  font: inherit; font-size: var(--fs-body); color: inherit; width: 100%;
  padding: 10px 12px; border: 1px solid var(--field-border); border-radius: var(--radius-s); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea { resize: vertical; min-height: 72px; }
/* Однострочные поля и выпадающие списки — одной высоты. */
input:not([type="checkbox"], [type="radio"], [type="file"]), select { height: 44px; }
::placeholder { color: var(--text-3); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-tint); }
[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-tint); }
input:disabled { background: var(--surface-sunken); color: var(--text-2); }
.actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.status-ok { color: var(--ok); }
.status-error { color: var(--danger); }
.notice { padding: 12px 16px; border-radius: var(--radius); background: var(--warn-tint); margin-bottom: 16px; }
.stack { display: grid; gap: 16px; }
.stack > p:empty { display: none; }

.dropzone {
  display: grid; gap: 4px; justify-items: center; text-align: center; cursor: pointer;
  padding: 36px 16px; border: 1.5px dashed var(--border); border-radius: var(--radius-l); background: var(--surface-2);
  transition: border-color var(--t), background-color var(--t);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-tint); }
#file-input:focus-visible + .dropzone { outline: 3px solid var(--accent-tint); outline-offset: 2px; }
.file-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.file-list:empty { display: none; }
.file-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.file-row.invalid .file-name { color: var(--danger); }
.file-name { overflow-wrap: anywhere; }
.file-actions { margin-left: auto; display: flex; gap: 4px; }

.progress-line { display: flex; align-items: center; gap: 12px; margin: 0; font-weight: 500; }
.spinner, .spinner-sm { border-radius: 50%; border: 2px solid var(--separator); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.spinner { width: 20px; height: 20px; }
.spinner-sm { width: 16px; height: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.review { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .review { grid-template-columns: 1fr; } .pages { order: -1; } }
.pages { display: grid; gap: 12px; position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100dvh - 100px); overflow: auto; }
@media (max-width: 900px) { .pages { position: static; max-height: none; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); } }
.page-thumb { display: grid; gap: 4px; font-size: var(--fs-s); }
.page-thumb img { width: 100%; border-radius: var(--radius-s); background: #fff; box-shadow: var(--shadow-1); }

.badge { display: inline-block; font-size: var(--fs-xs); font-weight: 500; padding: 1px 8px; border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--text-2); vertical-align: 1px; }
.badge-low { background: var(--warn-tint); color: var(--warn); }
.badge-missing { background: var(--danger-tint); color: var(--danger); }
.field.low input, .field.low select, .field.low textarea, .item.low textarea { background: var(--warn-tint); border-color: var(--warn-border); }

.items { margin: 0; padding-left: 20px; display: grid; gap: 12px; }
.item { display: grid; gap: 6px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.item-meta select, .item-meta input { width: auto; }
.item-meta input { flex: 1; min-width: 140px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--material-strong); padding: 12px 0; border-top: 0.5px solid var(--separator); }
@media (max-width: 700px) { .sticky-actions { position: static; } }

.deadline { margin-bottom: 16px; display: grid; gap: 8px; }
.deadline p { margin: 0; }
.deadline-label { font-size: var(--fs-sm); color: var(--text-2); }
.deadline-date { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.deadline details { font-size: var(--fs-sm); }
.deadline summary { cursor: pointer; color: var(--accent-text); }
.summary { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.summary dt { color: var(--text-2); }
.summary dd { margin: 0; }
@media (max-width: 600px) { .summary { grid-template-columns: 1fr; } .summary dd { margin-bottom: 8px; } }
.items-summary { margin: 0; padding-left: 20px; display: grid; gap: 4px; }

.positions { margin: 0; padding-left: 20px; display: grid; gap: 16px; }
.position { display: grid; gap: 8px; }
.position-text { margin: 0; font-weight: 500; }
.position.unset .position-text::after { content: " — выберите позицию"; color: var(--danger); font-weight: 400; font-size: var(--fs-s); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-pill); font-size: var(--fs-sm); cursor: pointer; background: var(--surface-sunken); }
.chip:has(input:checked) { background: var(--accent-tint); color: var(--accent-text); }
.chip input { width: auto; margin: 0; accent-color: var(--accent); }
.chip:focus-within { outline: 3px solid var(--accent-tint); }
.position-extra { display: grid; gap: 4px; max-width: 560px; }
.position-extra input[type="number"] { max-width: 140px; }
.draft-head { display: flex; align-items: center; gap: 12px; }
.draft-text { display: grid; gap: 12px; font-family: var(--font-paper); font-size: var(--fs-lg); line-height: 1.5; }
.para-edit { font: inherit; min-height: 80px; resize: vertical; }
.draft-counter { margin: 0; font-size: var(--fs-sm); font-weight: 500; }
.draft-counter.warn { color: var(--warn); }
.draft-counter.ok { color: var(--ok); }
.checklist { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.checklist .badge { margin-left: 8px; }

.delete-line { margin-top: 24px; font-size: var(--fs-sm); }
.extra-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.extra-list:empty { display: none; }
.extra-row { display: flex; gap: 8px; align-items: center; }
.extra-row input[type="number"] { width: 110px; flex: none; }

/* --- плейсхолдеры (общие для листа и пошагового режима) ---------------------------------------- */
mark.ph { border-radius: 4px; padding: 0 3px; color: inherit; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
mark.ph-fill { background: var(--ph-fill); }
mark.ph-check { background: var(--ph-check); }
.para { padding: 6px 10px; border-radius: var(--radius-s); text-indent: 1.25em; white-space: pre-wrap; }

/* ================================================================================================
   Главный экран
   ================================================================================================ */
.home { display: grid; padding-top: clamp(8px, 6dvh, 64px); }
.home-hero { display: grid; gap: 12px; text-align: center; margin-bottom: var(--space-section); }
.home .composer + .suggestions { margin-top: 12px; }
.home-lead { margin: 0 auto; max-width: 560px; color: var(--text-2); font-size: var(--fs-lg); line-height: 1.5; letter-spacing: -0.005em; }
.home .display { animation: rise var(--dur) var(--spring) both; }
.home .composer { animation: rise var(--dur) var(--spring) 60ms both; }
.home .suggestions { justify-content: center; animation: rise var(--dur) var(--spring) 120ms both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.home-foot { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; margin: var(--space-section) 0 0; color: var(--text-2); font-size: var(--fs-sm); text-align: center; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.suggestion {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: var(--radius-pill); padding: 8px 14px; min-height: 36px;
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); box-shadow: var(--shadow-1);
}
.suggestion:hover { background-image: var(--hover-layer); }
.suggestion:active { background-image: var(--press-layer); }
.suggestion-accent { color: var(--accent-text); }

.recent { margin-top: 40px; }

/* --- сгруппированный список (недавние, история) ------------------------------------------------ */
.list-section { margin-top: var(--space-section); }
:is(h1, .lead, .filter-chips) + .list-section { margin-top: 0; }
.list-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; padding: 0 4px; }
.list-section-head h2 { margin: 0; font-size: var(--fs-xl); letter-spacing: -0.015em; }
.list-section-head a { font-size: var(--fs-md); }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-1); overflow: hidden; }
.list-row { position: relative; display: flex; align-items: center; transition: background-color var(--t-fast); }
/* Разделитель с отступом — от начала текста, как в списках iOS. */
.list-row + .list-row::before { content: ""; position: absolute; top: 0; left: 60px; right: 0; border-top: 0.5px solid var(--separator); }
.list-row:hover { background: var(--fill-hover); }
.row-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 11px 10px 11px 14px; min-height: 62px; color: var(--text); }
a.row-link:hover { text-decoration: none; }
a.row-link:active { background: var(--fill-press); }
.row-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-item); flex: none; background: var(--surface-sunken); color: var(--text-2); }
.row-icon.is-chat { background: var(--accent-tint); color: var(--accent-text); }
.row-main { display: grid; min-width: 0; flex: 1; gap: 1px; }
.row-title { font-weight: 500; letter-spacing: -0.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: var(--fs-s); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub .is-action { color: var(--accent-text); font-weight: 500; }
.row-sub .is-danger { color: var(--danger); }
.row-sub .is-warn { color: var(--warn); }
.row-sub .is-progress { color: var(--text-2); font-style: italic; }
.row-chevron { color: var(--text-3); flex: none; }
/* Шеврон — последний элемент строки; если справа кнопки действий, строку выделяет наведение, шеврон лишний. */
@media (min-width: 601px) { .list-row:has(.row-actions) .row-chevron { display: none; } }
.row-actions { display: flex; gap: 2px; padding-right: 10px; flex: none; }
.row-actions .btn-icon { color: var(--text-3); }
.row-actions .btn-icon:hover { color: var(--text); }
.row-actions .btn-icon.is-danger:hover { color: var(--danger); background: var(--danger-tint); }
.list-row.is-deleted .row-title { color: var(--text-2); font-weight: 400; }
.list-row.is-deleted .row-icon { background: transparent; color: var(--text-3); }
.list-more { display: block; margin: 8px auto 0; border: 0; background: transparent; color: var(--accent-text); font-weight: 500; padding: 8px 14px; border-radius: var(--radius-pill); }
.list-more:hover:not(:disabled) { background: var(--accent-tint); }
.list-more:active:not(:disabled) { background: color-mix(in srgb, var(--accent) 20%, transparent); }
@media (max-width: 600px) {
  /* На телефоне действия — внутри диалога или требования: строке нужна ширина под заголовок. */
  .row-actions { display: none; }
  .list-row + .list-row::before { left: 58px; }
}

.list-skeleton .row-icon { background: var(--surface-sunken); }
.list-skeleton i { display: block; height: 10px; border-radius: 5px; background: var(--surface-sunken); animation: breathe 1.6s ease-in-out infinite; }
.list-skeleton i.w60 { width: 60%; }
.list-skeleton i.w40 { width: 40%; margin-top: 6px; }

.page-footnote { display: flex; align-items: flex-start; gap: 8px; margin: var(--space-section) 4px 0; font-size: var(--fs-s); line-height: 1.45; color: var(--text-3); }
.page-footnote .icon { margin-top: 1px; }

/* ================================================================================================
   Поле ввода
   ================================================================================================ */
.composer {
  display: grid; gap: 4px;
  background: var(--surface); border-radius: var(--radius-xl); padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-2);
  transition: box-shadow var(--t);
}
.composer:focus-within { box-shadow: var(--shadow-2), 0 0 0 4px var(--accent-tint); }
.composer.is-drop { box-shadow: var(--shadow-2), 0 0 0 3px var(--accent); }
.composer textarea {
  border: 0; padding: 8px 0 4px; min-height: 0; resize: none; background: transparent; box-shadow: none;
  font-size: var(--fs-body); line-height: 1.45; max-height: 40dvh;
}
.composer textarea:focus { box-shadow: none; }
.composer-large { padding: 12px 12px 10px 20px; }
.composer-large textarea { font-size: var(--fs-lg); min-height: 56px; }
.composer-bar { display: flex; align-items: center; gap: 6px; margin-left: -8px; }
.composer-hint { flex: 1; font-size: var(--fs-xs); color: var(--text-3); }
.btn-send {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-pill); border: 0; padding: 0;
  background: var(--accent-fill); color: var(--on-accent);
}
.btn-send:hover:not(:disabled) { background: var(--accent-fill-press); }
.toast-action:active { background: rgba(255, 255, 255, 0.34); }
.btn-send:disabled { background: var(--surface-sunken); color: var(--text-3); opacity: 1; }
.btn-send.is-stop { background: var(--text); color: var(--surface); }
.composer-attachments:empty { display: none; }
.composer-attachments { margin: 4px 0 0 -6px; }

.attach-chip, .msg-attachment {
  display: inline-flex; align-items: center; gap: 10px; max-width: 100%;
  padding: 8px 8px 8px 10px; border-radius: var(--radius); background: var(--surface-sunken);
}
.attach-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--surface); color: var(--accent-text); flex: none; }
.attach-text { display: grid; min-width: 0; line-height: 1.25; }
.attach-name { font-size: var(--fs-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-detail { font-size: var(--fs-xs); color: var(--text-2); }
.attach-chip.is-failed .attach-icon, .msg-attachment.is-failed .attach-icon { color: var(--danger); }
.attach-chip.is-failed .attach-detail { color: var(--danger); }

/* ================================================================================================
   Экран дела: диалог + документ
   ================================================================================================ */
.case-loading { display: flex; align-items: center; justify-content: center; gap: 12px; height: calc(100dvh - var(--topbar-h)); }
.case {
  display: grid; grid-template-columns: minmax(360px, 5fr) minmax(0, 7fr);
  height: calc(100dvh - var(--topbar-h));
}
.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); border-right: 0.5px solid var(--separator); container: chat / inline-size; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px 10px; min-height: 52px;
}
.case-title { font-size: var(--fs-lg); line-height: 1.3; letter-spacing: -0.012em; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.demo-strip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 20px 4px; padding: 8px 12px;
  border-radius: var(--radius); background: var(--accent-tint); color: var(--text); font-size: var(--fs-sm); line-height: 1.35;
}
.demo-strip .icon { flex: none; color: var(--accent-text); }
.demo-strip > span { flex: 1; min-width: 180px; }
.demo-strip > .demo-strip-short { display: none; }
@container chat (max-width: 600px) {
  .demo-strip { flex-wrap: nowrap; }
  .demo-strip > .demo-strip-short { display: inline; min-width: 0; }
  .demo-strip > .demo-strip-long { display: none; }
}
.demo-strip-link { font-weight: 600; white-space: nowrap; }

.demo-offer {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 0 0 16px; padding: 16px 18px;
  border-radius: var(--radius-l); background: var(--accent-tint);
}
.demo-offer-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--surface); color: var(--accent-text); }
.demo-offer-text { flex: 1; min-width: 220px; }
.demo-offer-text p { margin: 0; color: var(--text-2); font-size: var(--fs-md); }
.demo-offer-text .demo-offer-title { color: var(--text); font-weight: 600; margin-bottom: 2px; }

.deadline-pill {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  padding: 3px 10px; border-radius: var(--radius-pill); border: 0; font-size: var(--fs-s); font-weight: 600; white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-2); min-height: 26px;
}
.deadline-pill.is-ok { background: var(--ok-tint); color: var(--ok); }
.deadline-pill.is-soon { background: var(--warn-tint); color: var(--warn); }
.deadline-pill.is-urgent, .deadline-pill.is-over { background: var(--danger-tint); color: var(--danger); }

/* лента */
.feed-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.feed { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 20px 24px; scroll-padding-bottom: 24px; }
.feed:focus-visible { outline-offset: -3px; }
.feed-inner, .feed-tail { display: grid; gap: 14px; max-width: 720px; margin: 0 auto; }
.feed-tail:not(:empty) { margin-top: 14px; }
.feed-jump {
  position: absolute; left: 50%; bottom: 12px; translate: -50% 0;
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-pill); border: 0;
  background: var(--material-strong);
  color: var(--text); box-shadow: var(--shadow-2);
}

.msg { display: flex; animation: msg-in 0.45s var(--spring) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  display: grid; gap: 8px; max-width: min(82%, 560px);
  padding: 9px 14px; border-radius: 20px 20px 6px 20px;
  background: var(--user-bubble); color: var(--user-text);
  transform-origin: bottom right;
}
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-user .msg-attachment { background: rgba(255, 255, 255, 0.16); margin: 0 -6px; }
.msg-user .msg-attachment .attach-icon { background: rgba(255, 255, 255, 0.92); }
.msg-user .attach-detail { color: rgba(255, 255, 255, 0.82); }

.turn { display: grid; gap: 8px; }
.msg-assistant { max-width: 62ch; overflow-wrap: anywhere; }
.rich p { margin: 0 0 8px; }
.rich p:last-child, .rich ul:last-child, .rich ol:last-child { margin-bottom: 0; }
.rich ul, .rich ol { margin: 0 0 8px; padding-left: 20px; display: grid; gap: 4px; }
.caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 1px; vertical-align: -0.15em; background: var(--accent); border-radius: 1px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.tool-row { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); }
.tool-row .icon { color: var(--ok); }
.tool-row.is-muted .icon { color: var(--text-3); }
.tool-row.is-error .icon { color: var(--warn); }
.tool-row.is-new { animation: msg-in 0.4s var(--spring) both; }

.msg-notice {
  display: flex; align-items: flex-start; gap: 10px; max-width: 62ch;
  padding: 10px 14px; border-radius: var(--radius); background: var(--surface-sunken); color: var(--text-2);
  font-size: var(--fs-md); animation: msg-in 0.4s var(--spring) both;
}
.msg-notice .icon { flex: none; margin-top: 1px; color: var(--text-3); }
.msg-notice { flex-wrap: wrap; }
.msg-notice > span { flex: 1; min-width: 200px; }
.msg-notice .btn { flex: none; margin-left: auto; }

.live-status { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-md); color: var(--text-2); min-height: 24px; }
.live-hint { flex-basis: 100%; font-size: var(--fs-s); color: var(--text-3); animation: msg-in 0.4s var(--spring) both; }
.shimmer { color: var(--text-2); animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.55; } }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--text-3); animation: dot 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.notice-card {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px 10px 14px; border-radius: var(--radius); background: var(--warn-tint); color: var(--text);
  animation: msg-in 0.4s var(--spring) both;
}
.notice-card .icon { color: var(--warn); }
.notice-card span { flex: 1; min-width: 160px; }

.assume-card {
  display: grid; gap: 10px; padding: 14px; border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1);
  animation: msg-in 0.5s var(--spring) both;
}
.assume-title { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.assume-title .icon { color: var(--accent-text); }
.assume-card ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.assume-card li { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.assume-text { flex: 1; min-width: 200px; }
.segmented { display: inline-flex; padding: 2px; border-radius: var(--radius-item); background: var(--fill-track); }
.segmented button {
  border: 0; background: transparent; padding: 5px 12px; min-height: 30px; border-radius: 8px; font-size: var(--fs-sm); font-weight: 500; color: var(--text);
}
.segmented button:not([aria-pressed="true"]):hover:not(:disabled) { background: var(--fill-hover); color: var(--text); }
.segmented button:not([aria-pressed="true"]):active:not(:disabled) { background: var(--fill-press); }

.intro { display: grid; gap: 12px; padding: 24px 0; justify-items: start; }
.intro-title { margin: 0; color: var(--text-2); }

.composer-dock { padding: 8px 20px max(12px, env(safe-area-inset-bottom)); }
.composer-dock .composer { max-width: 720px; margin: 0 auto; }
.dock-note { margin: 6px 0 0; text-align: center; font-size: var(--fs-2xs); color: var(--text-3); }

/* документ */
.doc-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--surface-sunken); position: relative; }
.doc-bar {
  position: relative; z-index: var(--z-raised);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px; min-height: 56px;
  background: var(--material);
  border-bottom: 0.5px solid var(--separator);
}
.doc-bar:focus-visible { outline-offset: -3px; }
.grabber { display: none; }
.doc-bar-title { display: grid; line-height: 1.2; min-width: 0; }
.doc-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.doc-meta { font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }
.doc-pills { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 4px; border: 0; border-radius: var(--radius-pill); padding: 3px 10px; font-size: var(--fs-s); font-weight: 500; min-height: 26px; }
/* Цвета маркеров одинаковы в обеих темах: так же выглядят пометки на листе. */
.pill-fill { background: #ffe58f; color: #4d3d00; }
.pill-check { background: #ffd2cc; color: #6b1a12; }
.pill-ok { background: var(--ok-tint); color: var(--ok); }
.doc-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.doc-actions .btn-small { background: var(--accent-fill); }
.doc-actions .btn-small:hover { background: var(--accent-fill-press); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: var(--z-dropdown); min-width: 260px;
  display: grid; padding: 6px; border-radius: var(--radius);
  background: var(--material-strong);
  box-shadow: var(--shadow-2); transform-origin: top right;
  animation: menu-in 0.32s var(--spring) both;
}
@keyframes menu-in { from { opacity: 0; transform: scale(0.92); } }
.menu button { display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; min-height: 40px; padding: 8px 10px; border: 0; border-radius: var(--radius-item); background: transparent; color: var(--text); font-weight: 400; text-align: left; font-size: var(--fs-md); }
.menu button:hover:not(:disabled) { background: var(--accent-fill); color: var(--on-accent); }
.menu button.danger { color: var(--danger); }
.menu-versions { min-width: 300px; max-height: min(60dvh, 460px); overflow-y: auto; }
.menu-title { margin: 4px 10px 6px; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
.menu-note { margin: 6px 10px 4px; font-size: var(--fs-xs); color: var(--text-3); }
.menu button.version { align-items: flex-start; gap: 8px; }
.menu button.version:disabled { opacity: 1; cursor: default; }
.menu button.version.is-current:hover { background: transparent; color: inherit; }
.version-check { width: 16px; flex: none; padding-top: 2px; color: var(--accent-text); }
.version-main { display: grid; gap: 1px; }
.version-title { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.version-current { font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent-text); }
.version-meta { font-size: var(--fs-s); color: var(--text-2); }
.menu button.version:hover:not(:disabled) .version-meta, .menu button.version:hover:not(:disabled) .version-current { color: inherit; }
.menu button.danger:hover { background: var(--danger-fill); color: #fff; }

.doc-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 20px 24px 48px; display: grid; gap: 16px; align-content: start; justify-items: center; }
.doc-scroll > * { width: 100%; max-width: 760px; }

.deadline-card { display: grid; gap: 8px; padding: 14px 16px; border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); }
.dl-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dl-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--surface-sunken); color: var(--text-2); }
.deadline-card.is-ok .dl-icon { background: var(--ok-tint); color: var(--ok); }
.deadline-card.is-soon .dl-icon { background: var(--warn-tint); color: var(--warn); }
.deadline-card.is-urgent .dl-icon, .deadline-card.is-over .dl-icon { background: var(--danger-tint); color: var(--danger); }
.dl-label { font-size: var(--fs-xs); color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.dl-date { font-family: var(--font-display); font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.dl-left { margin-left: auto; font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.deadline-card.is-urgent .dl-left, .deadline-card.is-over .dl-left { color: var(--danger); }
.dl-details { font-size: var(--fs-sm); color: var(--text-2); }
.dl-details summary { cursor: pointer; color: var(--accent-text); width: fit-content; }
.dl-details ol { padding-left: 20px; margin: 8px 0; display: grid; gap: 4px; }
.dl-details p { margin: 6px 0 0; }
.dl-unverified, .dl-warn { color: var(--warn); }

/* лист бумаги */
.paper-slot { display: grid; }
.paper {
  background: var(--paper); color: var(--paper-text);
  font-family: var(--font-paper); font-size: var(--fs-lg); line-height: 1.5;
  padding: clamp(24px, 6%, 64px) clamp(20px, 8%, 72px) clamp(32px, 7%, 72px);
  border-radius: 4px; box-shadow: var(--shadow-paper);
  min-height: 60dvh;
}
.paper.is-appearing { animation: paper-in 0.6s var(--spring) both; }
@keyframes paper-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } }
.paper p { margin: 0; }
.paper-stamp {
  font-family: var(--font); font-size: var(--fs-2xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: #c00000; border: 1.5px solid currentColor; border-radius: 4px; padding: 3px 8px; width: fit-content; margin: 0 0 28px;
}
.paper-head { margin-left: auto; width: min(100%, 52%); display: grid; gap: 2px; margin-bottom: 28px; }
.paper-head .gap { margin-top: 10px; }
@media (max-width: 1100px) { .paper-head { width: 100%; } }
.paper-out { margin-bottom: 6px !important; }
.paper-reply { margin-bottom: 24px !important; }
.paper-title { text-align: center; font-size: 1em; font-weight: 700; letter-spacing: 0.02em; margin: 8px 0 0; font-family: var(--font-paper); }
.paper-subtitle { text-align: center; font-weight: 700; margin-bottom: 20px !important; }
.paper-body { display: grid; gap: 8px; margin-top: 16px; }
.paper .para { padding: 2px 6px; margin: 0 -6px; text-align: justify; hyphens: auto; }
.paper-attachments { margin-top: 16px; }
.paper-attachments ol { margin: 4px 0 0; padding-left: 2.2em; display: grid; gap: 2px; }
.paper-sign { margin-top: 40px; display: grid; gap: 4px; }
.sign-line { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.paper-writing { display: flex; align-items: center; gap: 6px; font-family: var(--font); font-size: var(--fs-sm); color: #5f5f64; margin-top: 16px !important; }

.editable { border-radius: 4px; transition: background-color var(--t), box-shadow var(--t); }
.paper.is-editable .editable { cursor: text; }
.paper.is-editable .editable:hover { background: rgba(0, 113, 227, 0.06); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.06); }
.editable.is-editing { background: #fff; box-shadow: 0 0 0 2px #0071e3, 0 0 0 6px rgba(0, 113, 227, 0.15) !important; outline: none; text-indent: 0; white-space: pre-wrap; }
.editable.is-empty { color: #5f5f64; font-style: italic; }
.paper:not(.is-editable) .editable.is-empty { display: none; }
.paper mark.ph { cursor: pointer; }
.paper mark.ph.is-pulse { animation: ph-pulse 1.2s var(--spring) 2; }
@keyframes ph-pulse { 50% { box-shadow: 0 0 0 5px rgba(255, 196, 0, 0.45); } }
.para.is-changed { animation: changed 2.4s ease-out both; }
@keyframes changed { 0%, 30% { background: var(--changed); } 100% { background: transparent; } }
.doc-pane.is-writing .paper { cursor: progress; }

.paper-empty { display: grid; align-content: start; gap: 28px; }
.skeleton { display: grid; gap: 12px; }
.skeleton i { display: block; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #ececf0, #f5f5f7, #ececf0); background-size: 200% 100%; animation: skeleton 2.4s ease-in-out infinite; }
.skeleton i.w30 { width: 30%; } .skeleton i.w40 { width: 40%; } .skeleton i.w50 { width: 50%; } .skeleton i.w60 { width: 60%; } .skeleton i.w80 { width: 80%; }
.skeleton i.right { margin-left: auto; } .skeleton i.center { margin: 12px auto; } .skeleton i.gap { margin-top: 28px; margin-bottom: 20px; }
@keyframes skeleton { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.paper-empty-text { font-family: var(--font); color: #5f5f64; text-align: center; max-width: 380px; margin: 0 auto !important; font-size: var(--fs-md); }

.side-cards { display: grid; gap: 16px; }
.side-card { padding: 16px 18px; border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); display: grid; gap: 10px; }
.side-card h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--fs-md); }
.side-card h2 .icon { color: var(--text-2); }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius-item); cursor: pointer; }
.check:hover { background: var(--fill-hover); }
.check input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--ok); }
.check span:nth-child(2) { flex: 1; }
.check:has(input:checked) span:nth-child(2) { color: var(--text-3); text-decoration: line-through; }
.kind { font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); padding-top: 3px; white-space: nowrap; }
.check-unknown { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; color: var(--warn); }
.check-unknown .icon { margin-top: 3px; }
.side-warn { margin: 0; font-size: var(--fs-sm); color: var(--warn); }
.norms { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; font-size: var(--fs-md); }
.norms li { display: grid; gap: 2px; }
.norm-head { display: flex; align-items: center; gap: 8px; }
.norm-title { color: var(--text-2); font-size: var(--fs-sm); }
.norm-badge { font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 7px; border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--text-2); }
.norm-badge.is-verified, .norm-badge.is-auto { background: var(--ok-tint); color: var(--ok); }
.norm-badge.is-stale { background: var(--warn-tint); color: var(--warn); }
.norm-badge.is-unverified, .norm-badge.is-missing { background: var(--danger-tint); color: var(--danger); }
.norms-summary { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: var(--fs-sm); color: var(--text-2); }
.norms-summary .icon { color: var(--ok); margin-top: 2px; }
.norms-summary.has-issue .icon { color: var(--warn); }
.check-link { border: 0; background: none; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.check-link:hover b { text-decoration: underline; }
/* Абзац со ссылкой, не прошедшей проверку: волнистое подчёркивание, как у орфографии. */
.paper .para.has-issue { text-decoration: underline wavy rgba(255, 149, 0, 0.7); text-decoration-thickness: 1px; text-underline-offset: 4px; }
.paper .para.is-pulse { animation: ph-pulse 1.2s var(--spring) 2; }
.norm-source { display: inline-flex; align-items: center; gap: 2px; font-size: var(--fs-s); width: fit-content; }
.norm-meta { font-size: var(--fs-xs); color: var(--text-3); }

.sheet-scrim { display: none; }

/* Сенсорный экран: зона нажатия мелких элементов — около 44 px, внешний вид не меняется. */
@media (pointer: coarse) {
  .nav a, .user a, .brand, .back-link, .demo-strip-link, .deadline-pill, .doc-pills button, .deadline-card summary, .segmented button,
  .btn-icon, .btn-send, .btn-small, .suggestion, .filter-chip, .from-chip, .list-section-head a, .org-foot a { position: relative; }
  .nav a::after, .segmented button::after, .suggestion::after, .filter-chip::after, .from-chip::after, .btn-small::after { content: ""; position: absolute; inset: -7px 0; }
  .btn-icon::after, .btn-send::after { content: ""; position: absolute; inset: -5px; border-radius: var(--radius-pill); }
  .user a::after, .brand::after, .back-link::after, .demo-strip-link::after, .deadline-pill::after, .doc-pills button::after, .deadline-card summary::after,
  .list-section-head a::after, .org-foot a::after { content: ""; position: absolute; inset: -10px -6px; }
}

/* --- телефон: документ — нижняя шторка ------------------------------------------------------------ */
@media (max-width: 899px) {
  .case { display: block; position: relative; height: calc(100dvh - var(--topbar-h)); }
  .chat-pane { height: 100%; border-right: 0; padding-bottom: var(--sheet-peek, 76px); }
  .chat-head { padding: 10px var(--gutter) 6px; }
  .demo-strip { margin: 0 var(--gutter) 4px; padding: 6px 10px; }
  .feed { padding: 8px var(--gutter) 20px; }
  .composer-dock { padding: 6px var(--gutter) 10px; }
  .dock-note { display: none; }
  .sheet-scrim { display: block; position: fixed; inset: 0; z-index: var(--z-sheet-scrim); background: #000; opacity: 0; pointer-events: none; }
  .doc-pane {
    position: fixed; z-index: var(--z-sheet); left: 0; right: 0; bottom: 0;
    height: calc(100dvh - var(--topbar-h) - 12px);
    border-radius: 16px 16px 0 0; overflow: hidden;
    box-shadow: var(--shadow-sheet);
    touch-action: none;
  }
  .doc-scroll { touch-action: pan-y; padding: 16px var(--gutter) calc(32px + env(safe-area-inset-bottom)); }
  .doc-bar { cursor: grab; padding: 18px var(--gutter) 10px; min-height: 68px; user-select: none; -webkit-user-select: none; touch-action: none; }
  .doc-bar:active { cursor: grabbing; }
  .grabber { display: block; position: absolute; top: 6px; left: 50%; translate: -50% 0; width: 36px; height: 5px; border-radius: 3px; background: var(--text-3); opacity: 0.45; }
  .doc-pane[data-detent="closed"] .doc-actions { display: none; }
  /* Свёрнутая шторка стоит над полосой «домой»; под шапкой — тот же материал, а не начало листа. */
  .doc-pane[data-detent="closed"] .doc-bar::after {
    content: ""; position: absolute; left: 0; right: 0; top: 100%; height: env(safe-area-inset-bottom, 0px); background: inherit;
  }
  .paper { font-size: var(--fs-body); min-height: 0; padding: 24px 18px 32px; }
  .paper-head { width: 100%; }
}

/* --- уведомления ---------------------------------------------------------------------------------- */
.toast-region { position: fixed; z-index: var(--z-toast); left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); translate: -50% 0; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 18px; border-radius: var(--radius-pill);
  background: #2c2c2e; color: #fff; font-size: var(--fs-md); box-shadow: var(--shadow-2);
  opacity: 0; transform: translateY(16px) scale(0.96); pointer-events: auto;
  transition: opacity 0.25s ease, transform var(--dur) var(--spring);
}
.toast.in { opacity: 1; transform: none; }
.toast-action { border: 0; background: rgba(255, 255, 255, 0.16); color: #fff; border-radius: var(--radius-pill); padding: 5px 12px; font-weight: 600; font-size: var(--fs-sm); }
.toast-action:hover { background: rgba(255, 255, 255, 0.26); }

.empty-state { display: grid; justify-items: center; text-align: center; gap: 12px; padding-top: 12dvh; color: var(--text-2); }
.empty-state h1 { color: var(--text); }

/* ================================================================================================
   Доступность: меньше движения, меньше прозрачности, больше контраста
   ================================================================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .toast { transition: opacity var(--t) ease !important; transform: none; }
  .shimmer { animation: none; }
  .caret { animation: none; }
  .spinner, .spinner-sm { animation-duration: 3s !important; animation-iteration-count: infinite !important; }
}
@media (prefers-contrast: more) {
  :root { --separator: rgba(0, 0, 0, 0.45); --text-2: #3a3a3c; --text-3: #48484a; --material: var(--surface); }
  .composer, .card, .side-card, .deadline-card, .list, .assume-card, .msg-notice, .org-menu, .choice, .filter-chip, .org-switch-btn, .dialog { box-shadow: 0 0 0 1px var(--text); }
}
@media (prefers-contrast: more) {
  :root[data-theme="dark"] { --separator: rgba(255, 255, 255, 0.5); --text-2: #d1d1d6; --text-3: #aeaeb2; }
}
@media (forced-colors: active) {
  mark.ph { forced-color-adjust: none; }
  .btn-send, .deadline-pill, .pill { border: 1px solid CanvasText; }
}
