/* ИзиБизи — «плотный реестр на пергаменте»: язык Claude (пергамент, чернила,
   единственный акцент — clay), но с плотностью рабочей таблицы, а не лендинга. */

:root {
  /* ── CDS-минимализм: серые поверхности, вся линия и заливка — alpha ink ── */
  color-scheme: light;

  --paper: #ffffff;            /* surface-2: таблица, карточки */
  --paper-2: #fafafa;          /* surface-sidebar: рейл, подложки */
  --page: #f9f9f9;             /* surface-0: фон за пределами панелей */
  --card: #ffffff;             /* surface-2: поповеры, редакторы */
  --popover: #ffffff;          /* surface-popover */

  --ink: #0b0b0b;              /* neutral-900, не чистый чёрный */
  --ink-1: #0b0b0be6;          /* text-primary */
  --ink-2: #0b0b0b99;          /* text-secondary 60% */
  --ink-3: #0b0b0b73;          /* text-muted 45% */
  --ink-4: #0b0b0b59;          /* text-faint 35% */

  --alpha-1: #0b0b0b0d;        /* 5%  — hover, мягкая заливка */
  --alpha-2: #0b0b0b1a;        /* 10% — рамка, активный hover */
  --alpha-3: #0b0b0b33;        /* 20% — активная рамка */
  --alpha-4: #0b0b0b59;        /* 35% — disabled */

  --line: var(--alpha-2);
  --line-2: var(--alpha-2);
  --rule: var(--alpha-3);

  --clay: #d97757;             /* подпись бренда, не кнопка */
  --clay-ink: #b4502c;
  --clay-soft: #f7e9e3;
  --ok: #2f7d5b;
  --warn: #9a6b1f;
  --danger: #b0443a;
  --focus: #2f6ea8;
  --focus-ring: color-mix(in srgb, var(--focus) 24%, transparent);

  /* системные скроллбары перекрашиваются в тон интерфейса */
  --scrollbar-thumb: #0b0b0b2e;
  --scrollbar-thumb-hover: #0b0b0b4d;
  --scrollbar-track: transparent;

  --shadow: 0 1px 0 rgba(0, 0, 0, .02), 0 8px 24px -16px rgba(0, 0, 0, .28);
  --shadow-composer: 0 6px 24px -10px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .04);
  --ring-composer: #0b0b0b1f;

  --font-ui: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-voice: 'Source Serif 4', ui-serif, Georgia, 'Times New Roman', serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;

  --rail-w: 244px;
  --row-h: 44px;
  --radius: .5rem;
  --radius-card: calc(var(--radius) + .25rem);
  --radius-composer: .875rem;
  --radius-dialog: calc(var(--radius) + .5rem);
  --h-control: 32px;
  --text-body: .875rem;  --leading-body: 1.25rem;
  --text-prose: .9375rem; --leading-prose: 1.3125rem;
  --text-caption: .75rem; --leading-caption: 1.0625rem;
  --dur-fast: 60ms;
  --dur-snap: 120ms;
  --dur-base: 200ms;
  --dur-sheet: 300ms;
  --dur-slow: 450ms;
  --ease-out: cubic-bezier(.165, .84, .44, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
::selection { background: color-mix(in srgb, var(--clay) 24%, transparent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ── скроллбары: тонкие, в цвет чернил, без системной «полосы» ── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--scrollbar-track); }
*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: padding-box; }
*::-webkit-scrollbar-corner { background: transparent; }

/* ── каркас ─────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-width: 760px;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--page);
}

/* ── левый рейл ─────────────────────────────────────────── */
#rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 10px 12px;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand-mark {
  width: 26px; height: 26px;
  display: inline-grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #e0916e, #c65e3d);
  color: #fdf7f2;
  font-size: 14px;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18);
}
.brand-mark svg { width: 15px; height: 15px; display: block; }
.brand-mark .spark { color: #ffe6d5; }

/* Переключатель листов: на десктопе список виден целиком, кнопка не нужна. */
.rail-sheets { display: none; }
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.012em;
}

.rail-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 7px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.rail-icon {
  width: 27px;
  height: 27px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--ink-3);
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.rail-icon:hover { background: var(--alpha-1); color: var(--ink); }
.rail-icon svg { width: 15px; height: 15px; }

#sheetList { list-style: none; margin: 0; padding: 0 2px; flex: 1; min-height: 0; overflow: auto; }

#sheetList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 10px;
  margin-bottom: 1px;
  border-radius: var(--radius);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 13.5px;
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
#sheetList li:hover { background: var(--alpha-1); color: var(--ink-1); }
#sheetList li.active {
  background: var(--alpha-2);
  color: var(--ink);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px var(--line);
}
#sheetList li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sheetList li .count { font-size: 11.5px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
#sheetList li .menu-btn {
  border: 0; background: none; padding: 2px 3px; border-radius: 4px; color: var(--ink-3); opacity: 0; line-height: 1;
}
#sheetList li:hover .menu-btn, #sheetList li.active .menu-btn { opacity: 1; }
#sheetList li .menu-btn:hover { background: var(--alpha-1); color: var(--ink); }

.rail-foot { display: flex; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 6px; }

#themeBtn .i-moon { display: none; }
:root[data-theme="night"] #themeBtn .i-moon { display: block; }
:root[data-theme="night"] #themeBtn .i-sun { display: none; }

/* ── основная область ───────────────────────────────────── */
#main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--paper);
}

#topbar { display: flex; align-items: flex-end; gap: 20px; padding: 24px 28px 14px; position: relative; }
.title-block { min-width: 0; flex: 1 1 auto; }

.eyebrow {
  font-size: 10.5px; font-weight: 600; letter-spacing: .075em;
  text-transform: uppercase; color: var(--ink-4); white-space: nowrap;
}

.title-block h1 {
  margin: 4px 0 0;
  font-family: var(--font-ui);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.014em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}
.title-block h1[contenteditable="true"] { outline: none; box-shadow: inset 0 -1px 0 var(--clay); }

.meta { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--text-caption); color: var(--ink-3); }
.meta b { font-weight: 500; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.toolbar { display: flex; align-items: center; gap: 5px; flex: none; }

/* ── контролы ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-snap) var(--ease-out),
              color var(--dur-snap) var(--ease-out),
              border-color var(--dur-snap) var(--ease-out),
              box-shadow var(--dur-snap) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--alpha-1); color: var(--ink); }
.btn:active { background: var(--alpha-2); transform: translateY(.5px); }
.btn:disabled { opacity: .4; cursor: default; background: none; transform: none; }
.btn svg { width: 15px; height: 15px; }

.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover { background: #242424; border-color: #242424; }
.btn.primary:active { background: #000; }

.btn.ghost { border-color: var(--line-2); }
.btn.ghost:hover { border-color: var(--rule); }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.92); }
.btn.danger-text { color: var(--danger); }

.search-box {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px; min-width: 200px;
  border-radius: var(--radius);
  background: var(--alpha-1);
  color: var(--ink-3);
  transition: background var(--dur-snap) var(--ease-out), box-shadow var(--dur-snap) var(--ease-out);
}
.search-box:hover { background: var(--alpha-2); }
.search-box:focus-within {
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--rule), 0 0 0 3px var(--focus-ring);
  color: var(--ink);
}
.search-box input { border: 0; background: none; outline: none; width: 100%; font-size: 13.5px; }
.search-box input::placeholder { color: var(--ink-4); }
.search-box kbd {
  font-family: var(--font-mono); font-size: 10.5px; padding: 1px 5px;
  border-radius: 4px; background: var(--card); color: var(--ink-4); box-shadow: 0 0 0 1px var(--line);
}

.view-tabs {
  display: flex; align-items: center; gap: 2px;
  height: 32px; padding: 3px;
  border-radius: var(--radius);
  background: var(--alpha-1);
}
.view-tabs button {
  border: 0; background: none; height: 26px; padding: 0 11px;
  border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--ink-3);
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.view-tabs button:hover { color: var(--ink-1); }
.view-tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 0 0 1px var(--line); }

/* ── таблица ────────────────────────────────────────────── */
#gridWrap {
  flex: 1 1 auto; min-height: 0; overflow: auto;
  padding: 0 20px 8px; position: relative;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

#grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; table-layout: fixed; }

#grid thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--paper);
  border-bottom: 1px solid var(--line-2);
  text-align: left; vertical-align: bottom; padding: 0; font-weight: 500;
}
#grid thead th .head { display: flex; align-items: flex-end; gap: 6px; padding: 11px 8px 9px 12px; min-height: 50px; }
#grid thead th .head .label { flex: 1; min-width: 0; overflow: hidden; }
#grid thead th .title {
  display: block; font-size: 12px; font-weight: 600; color: var(--ink-2);
  letter-spacing: .005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#grid thead th .type { display: block; margin-top: 2px; font-size: 10.5px; color: var(--ink-4); }
#grid thead th.required .title::after {
  content: ""; display: inline-block; width: 5px; height: 5px; margin-left: 5px;
  border-radius: 50%; background: var(--clay); vertical-align: 1px;
}
#grid thead th .head .tools { display: flex; gap: 1px; opacity: 0; transition: opacity var(--dur-snap) var(--ease-out); }
#grid thead th:hover .head .tools, #grid thead th:focus-within .head .tools { opacity: 1; }
#grid thead th .mini { border: 0; background: none; padding: 3px; border-radius: 4px; color: var(--ink-4); line-height: 0; }
#grid thead th .mini:hover { background: var(--alpha-1); color: var(--ink); }
#grid thead th .mini svg { width: 13px; height: 13px; }
#grid thead th .resizer { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 4; }
#grid thead th .resizer:hover, #grid thead th .resizer.dragging { background: var(--clay); opacity: .3; }

#grid tbody td {
  border-bottom: 1px solid var(--line);
  padding: 0;
  vertical-align: top;
  background: var(--paper);
  height: var(--row-h);
  transition: background var(--dur-fast) linear;
}
#grid tbody tr:hover td { background: var(--alpha-1); }
#grid tbody tr.selected td { background: var(--clay-soft); }

#grid tbody td.gutter {
  width: 58px; min-width: 58px; padding: 0 6px 0 12px;
  text-align: right; font-size: 11px; color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  background: var(--paper);
  position: sticky; left: 0; z-index: 2; vertical-align: middle;
}
#grid tbody tr:hover td.gutter { background: color-mix(in srgb, var(--paper) 92%, var(--ink)); }
#grid tbody tr.selected td.gutter { background: var(--clay-soft); }
#grid tbody td.gutter .num { display: inline-block; min-width: 16px; }

.row-menu-btn {
  margin-left: 4px; width: 24px; height: 24px;
  border: 0; border-radius: 6px; background: none; color: var(--ink-4);
  font-size: 14px; line-height: 1; vertical-align: middle;
  opacity: 0;
  transition: opacity var(--dur-snap) var(--ease-out),
              background var(--dur-snap) var(--ease-out),
              color var(--dur-snap) var(--ease-out);
}
#grid tbody tr:hover .row-menu-btn,
#grid tbody tr.selected .row-menu-btn,
.row-menu-btn:focus-visible { opacity: 1; }
.row-menu-btn:hover { background: var(--alpha-2); color: var(--ink); }

#grid thead th.gutter {
  width: 58px; min-width: 58px;
  position: sticky; left: 0; z-index: 6; background: var(--paper);
}
#grid thead th.gutter .head {
  min-height: 50px; padding: 0 8px;
  align-items: center; justify-content: flex-end;
  font-size: 10.5px; color: var(--ink-4);
}

.cell { position: relative; width: 100%; min-height: var(--row-h); display: flex; align-items: center; }

.cell .value {
  flex: 1; padding: 11px 12px; min-height: var(--row-h);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: text; color: var(--ink);
}
.cell .value.multi { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cell .value.number { font-variant-numeric: tabular-nums; text-align: right; }
.cell .value.date { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.cell .value.empty::before { content: "—"; color: var(--alpha-3); }
.cell .value .tick { color: var(--ok); font-weight: 600; }

/* Активная ячейка (мышь или клавиатура) получает кольцо, но не сдвигает сетку. */
#grid td.active-cell { box-shadow: inset 0 0 0 2px var(--focus); }
#grid td.active-cell:focus-visible { outline: none; }

/* редактор ячейки заполняет её целиком: никаких белых коробок и двойных рамок.
   Важно: у select и полей ввода цвет фона и текста заданы явно и с !important —
   иначе нативная отрисовка (особенно в ночной теме) берёт системный белый фон. */
.cell .cell-editor {
  width: 100%;
  min-height: var(--row-h);
  border: 0;
  border-radius: 0;
  background: var(--card) !important;
  background-color: var(--card) !important;
  color: var(--ink) !important;
  padding: 11px 12px;
  margin: 0;
  outline: none;
  font-size: 14px;
  box-shadow: inset 0 0 0 1.5px var(--clay);
  -webkit-appearance: none;
  appearance: none;
  color-scheme: inherit;
}
.cell .cell-editor::placeholder { color: var(--ink-4) !important; }

.cell select.cell-editor {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%) !important;
  background-position: calc(100% - 16px) calc(50% - 2px), calc(100% - 11px) calc(50% - 2px) !important;
  background-size: 5px 5px, 5px 5px !important;
  background-repeat: no-repeat !important;
  background-color: var(--card) !important;
  border: 0 !important;
  padding-right: 30px;
}
.cell select.cell-editor option { background: var(--card) !important; color: var(--ink) !important; }

.cell textarea.cell-editor { resize: vertical; min-height: 76px; }

.cell input[type="checkbox"].cell-editor {
  box-shadow: none !important; padding: 0 !important; min-height: 0 !important;
  width: 16px; height: 16px; margin: 14px 12px; accent-color: var(--clay);
  background: none !important;
}
.cell input[type="date"].cell-editor { font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 6px;
  font-size: 12.5px; font-weight: 500;
  background: var(--alpha-1); color: var(--ink-2); white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--line);
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--clay); }
.pill[data-v="Обычная"]::before { background: var(--ink-4); }
.pill[data-v="Готов"]::before, .pill[data-v="Отгружен"]::before { background: var(--ok); }
.pill[data-v="В работе"]::before { background: var(--warn); }
.pill[data-v="Отменён"] { color: var(--ink-4); text-decoration: line-through; }

.check { width: 16px; height: 16px; accent-color: var(--clay); }

tr.add-row td { background: var(--paper) !important; border-bottom: 0; }

.add-strip {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; margin: 4px 0 6px;
  color: var(--ink-3); font-size: 13.5px;
  border-radius: var(--radius); cursor: pointer; width: max-content;
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.add-strip .add-plus {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border-radius: 6px;
  background: var(--alpha-2); color: var(--ink-2);
  font-size: 14px; line-height: 1;
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.add-strip .add-text { color: var(--ink-2); }
.add-strip .add-hint {
  font-size: 11px; color: var(--ink-4);
  padding-left: 8px; border-left: 1px solid var(--line);
}
.add-strip:hover { background: var(--alpha-1); color: var(--clay-ink); }
.add-strip:hover .add-plus { background: var(--clay-soft); color: var(--clay-ink); }
.add-strip:hover .add-text { color: var(--clay-ink); }

/* ── панель колонок ─────────────────────────────────────── */
#colsPanel {
  position: absolute; right: 28px; top: calc(100% + 8px); z-index: 20;
  width: 290px; padding: 12px;
  border-radius: var(--radius-card);
  background: var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 18px 40px -20px rgba(0, 0, 0, .35);
  animation: panelIn var(--dur-snap) var(--ease-out);
}
#colsPanel h4 { margin: 2px 4px 10px; font-size: 14px; font-weight: 600; }
#colsList {
  max-height: min(46vh, 380px); overflow: auto;
  margin: 0 -4px; padding: 0 4px;
  overscroll-behavior: contain;
}
#colsPanel .col-row {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 4px; border-radius: 7px;
  transition: background var(--dur-snap) var(--ease-out);
}
#colsPanel .col-row:hover { background: var(--alpha-1); }
#colsPanel .col-row .drag {
  width: 16px; flex: none; text-align: center;
  cursor: grab; color: var(--ink-4); font-size: 12px; user-select: none;
}
#colsPanel .col-row .drag:active { cursor: grabbing; }
#colsPanel .col-toggle {
  display: flex; align-items: center; gap: 8px;
  flex: 1; min-width: 0; padding: 4px 0; cursor: pointer;
}
#colsPanel .col-row .grow {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; color: var(--ink-1);
}
#colsPanel .col-row.hidden-col .grow { color: var(--ink-4); text-decoration: line-through; }
#colsPanel .col-row.dragover { box-shadow: inset 0 2px 0 var(--clay); }
#colsPanel input[type="checkbox"] { accent-color: var(--clay); width: 15px; height: 15px; flex: none; }
#colsPanel .col-edit {
  width: 26px; height: 26px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 6px; background: none; color: var(--ink-4);
  opacity: 0;
  transition: opacity var(--dur-snap) var(--ease-out),
              background var(--dur-snap) var(--ease-out),
              color var(--dur-snap) var(--ease-out);
}
#colsPanel .col-row:hover .col-edit,
#colsPanel .col-edit:focus-visible { opacity: 1; }
#colsPanel .col-edit:hover { background: var(--alpha-2); color: var(--ink); }
#colsPanel .col-edit svg { width: 13px; height: 13px; }
.cols-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ── командная строка и строка-итог ──────────────────────── */
/* Док живёт в потоке под таблицей: системный горизонтальный скроллбар
   таблицы больше не прячется за капсулой и не торчит из-под неё. */
#dock {
  position: relative; z-index: 30; flex: none;
  padding: 8px 20px max(14px, env(safe-area-inset-bottom));
  display: flex; justify-content: center;
  background: var(--paper);
  /* искра крутится и свечение выходит за кнопку — не даём этому
     растягивать документ шире экрана */
  overflow: hidden;
}
.dock-inner {
  width: min(600px, 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
#dock.is-collapsed .dock-inner { align-items: center; }

.result-strip {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 8px 10px 14px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow-composer), 0 0 0 1px var(--line);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink-2);
  animation: stripIn var(--dur-sheet) var(--ease-out);
}
@keyframes stripIn { from { opacity: 0; transform: translateY(6px) scale(.99) } to { opacity: 1; transform: none } }

.result-strip[hidden] { display: none; }
.result-icon { width: 14px; flex: none; text-align: center; color: var(--ok); font-weight: 600; padding-top: 1px; }
.result-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.result-actions { display: flex; align-items: center; gap: 1px; flex: none; }
.result-strip.is-error { color: var(--danger); box-shadow: 0 0 0 1px color-mix(in srgb, var(--danger) 35%, transparent); }
.result-strip.is-error .result-icon { color: var(--danger); }
.result-strip.is-pending .result-icon::after {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  border-top-color: var(--ink-3);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.result-text { color: var(--ink-1); overflow-wrap: anywhere; }
.result-strip.is-pending .result-text { color: var(--ink-3); }

/* Уточняющий вопрос: карточка с вариантами, а не уведомление на пару секунд. */
.result-strip.is-question {
  padding: 12px 8px 12px 14px;
  box-shadow: var(--shadow-composer), 0 0 0 1px var(--line);
}
.result-strip.is-question .result-icon { color: var(--clay-ink); }
.result-strip.is-question .result-text { color: var(--ink); font-size: 13.5px; line-height: 1.4; }
.result-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choice-chip {
  border: 1px solid var(--line-2);
  background: var(--paper);
  color: var(--ink-1);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 30px;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-snap) var(--ease-out),
              border-color var(--dur-snap) var(--ease-out),
              color var(--dur-snap) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.choice-chip:hover { background: var(--alpha-1); border-color: var(--rule); color: var(--ink); }
.choice-chip:active { transform: scale(.97); }
.choice-chip.is-own { border-style: dashed; color: var(--ink-3); }

.result-retry, .result-undo {
  border: 0; background: none; padding: 3px 8px; min-height: 24px;
  border-radius: 6px; color: var(--ink-2); font-size: 12px; font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.result-retry:hover, .result-undo:hover { background: var(--alpha-2); color: var(--ink-1); }
.result-retry[hidden], .result-undo[hidden] { display: none; }
.result-retry { color: var(--danger); }
.result-close {
  border: 0; background: none; width: 22px; height: 22px;
  border-radius: 6px; color: var(--ink-4); font-size: 15px; line-height: 1;
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.result-close:hover { background: var(--alpha-2); color: var(--ink-1); }

#composer {
  display: flex; align-items: center;
  width: max-content; max-width: 100%;
  min-height: 42px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-composer), 0 0 0 1px var(--ring-composer);
  transition: width var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
#composer:focus-within {
  box-shadow: var(--shadow-composer), 0 0 0 1px var(--alpha-3), 0 0 0 4px var(--focus-ring);
}

/* Свёрнутая кнопка ассистента: тихая, но заметная точка входа. */
#dock.is-collapsed #composer {
  background: transparent;
  box-shadow: none;
  min-height: 0;
}
#dock.is-collapsed #composer:focus-within { box-shadow: none; }
#dock.is-collapsed .composer-field { display: none; }

.ai-fab {
  position: relative;
  flex: none;
  width: 50px; height: 50px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%;
  background: linear-gradient(135deg, #e0916e, #c65e3d);
  color: #fff8f2;
  box-shadow: 0 10px 22px -10px rgba(198, 94, 61, .65), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform var(--dur-base) var(--ease-out),
              background var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
.ai-fab:hover { transform: translateY(-1px) scale(1.04); }
.ai-fab:active { transform: scale(.96); }
.ai-fab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring), 0 10px 22px -10px rgba(198, 94, 61, .65); }
.ai-spark { width: 23px; height: 23px; fill: currentColor; stroke: none; }
.ai-fab-glow {
  position: absolute; inset: -9px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--clay) 34%, transparent), transparent 66%);
  opacity: .5; pointer-events: none;
  animation: aiBreathe 4.4s ease-in-out infinite;
}
.ai-fab-ring {
  position: absolute; inset: -3px; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 52%, var(--clay) 68%, transparent 86%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  opacity: .9; pointer-events: none;
  animation: aiOrbit 5.5s linear infinite;
}
@keyframes aiOrbit { to { transform: rotate(360deg) } }
@keyframes aiBreathe {
  0%, 100% { opacity: .32; transform: scale(.94) }
  50% { opacity: .7; transform: scale(1.06) }
}
#dock.is-busy .ai-fab-ring { animation-duration: 1.3s; }
#dock.is-busy .ai-fab { background: var(--clay-ink); color: #fff; }

/* Развёрнутая строка: искра становится маленьким знаком слева и сворачивает. */
#dock:not(.is-collapsed) #composer { width: 100%; animation: composerIn var(--dur-base) var(--ease-out); }
@keyframes composerIn { from { opacity: .35; transform: scale(.965) } to { opacity: 1; transform: none } }
#dock:not(.is-collapsed) .ai-fab {
  width: 30px; height: 30px; margin-left: 5px;
  background: none; color: var(--clay-ink); box-shadow: none;
}
#dock:not(.is-collapsed) .ai-fab:hover { background: var(--clay-soft); transform: none; }
#dock:not(.is-collapsed) .ai-fab-glow,
#dock:not(.is-collapsed) .ai-fab-ring { display: none; }
#dock:not(.is-collapsed) .ai-spark { width: 17px; height: 17px; }

.composer-field {
  display: flex; align-items: center; gap: 2px;
  flex: 1; min-width: 0;
  padding: 4px 6px 4px 4px;
}

#assistInput {
  flex: 1; min-width: 0;
  border: 0; outline: none; background: none;
  padding: 8px 6px;
  font-family: inherit; font-size: 15px; line-height: 1.4;
  color: var(--ink-1);
}
#assistInput::placeholder { color: var(--ink-3); }

.mic-btn {
  width: 32px; height: 32px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: none; color: var(--ink-3);
  position: relative;
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.mic-btn:hover { background: var(--alpha-1); color: var(--ink-1); }
.mic-btn svg { width: 16px; height: 16px; }
.mic-btn.rec { background: var(--danger); color: #fff; }
.mic-btn.rec::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  border: 1px solid var(--danger); animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(.95); opacity: .9 } 100% { transform: scale(1.2); opacity: 0 } }

.send-btn {
  width: 32px; height: 32px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: var(--ink); color: var(--card);
  transition: background var(--dur-snap) var(--ease-out), opacity var(--dur-snap) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.send-btn:hover { background: #242424; }
.send-btn:active { transform: scale(.96); }
.send-btn svg { width: 16px; height: 16px; }
.send-btn:disabled { opacity: .3; cursor: default; }
.send-btn.stop { background: var(--danger); }

.meter { display: block; width: 48px; flex: none; height: 3px; border-radius: 2px; background: var(--alpha-2); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--clay); transition: width .08s linear; }

.hint-line { font-size: var(--text-caption); color: var(--ink-4); white-space: nowrap; }
.hint-line b { font-weight: 500; }
.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;
}

/* ── пустое состояние / доска ───────────────────────────── */
.empty-state { margin: 56px auto; max-width: 440px; text-align: center; color: var(--ink-3); }
.empty-state::before {
  content: "✳"; display: block; margin-bottom: 14px;
  color: var(--clay); font-size: 22px; line-height: 1;
}
.empty-state h3 { margin: 0 0 7px; font-size: 19px; font-weight: 600; letter-spacing: -.012em; color: var(--ink-1); }
.empty-state p { margin: 0; font-size: 14px; line-height: 1.6; }

.board { display: flex; gap: 14px; padding: 16px 12px 40px; align-items: flex-start; min-width: max-content; }
.board-col {
  width: 250px; flex: none; border-radius: var(--radius-card);
  background: var(--alpha-1); padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.board-col > header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 2px 4px 8px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3);
}
.board-col > header b { font-weight: 500; color: var(--ink-4); }
.board-card {
  background: var(--card); border-radius: 10px; padding: 11px 12px; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, .03);
  transition: box-shadow var(--dur-snap) var(--ease-out), transform var(--dur-snap) var(--ease-out);
}
.board-card:hover { box-shadow: 0 0 0 1px var(--rule), 0 4px 12px -8px rgba(0, 0, 0, .25); transform: translateY(-1px); }
.board-card .bc-client { font-weight: 500; font-size: 13.5px; }
.board-card .bc-item { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.board-card .bc-due { font-size: 11.5px; color: var(--clay-ink); margin-top: 5px; }
.board-empty { font-size: 12.5px; color: var(--ink-4); margin: 4px; }

/* ── меню ───────────────────────────────────────────────── */
.menu {
  position: fixed; z-index: 120; min-width: 218px; padding: 5px;
  border-radius: 12px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 18px 40px -18px rgba(0, 0, 0, .4);
  animation: panelIn var(--dur-snap) var(--ease-out);
}
@keyframes panelIn { from { opacity: 0; transform: translateY(-3px) scale(.99) } to { opacity: 1; transform: none } }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: none; padding: 8px 10px; border-radius: 8px;
  font-size: 13.5px; color: var(--ink); text-align: left;
}
.menu-item span { flex: 1; }
.menu-item kbd { opacity: .7; }
.menu-item:hover, .menu-item:focus-visible { background: var(--alpha-1); outline: none; }
.menu-item.danger { color: var(--danger); }
.menu-item .menu-check { flex: none; width: 12px; color: var(--clay); }
.menu-sep { height: 1px; margin: 5px 7px; background: var(--line); }

/* ── диалоги ────────────────────────────────────────────── */
dialog {
  border: 0; border-radius: var(--radius-dialog);
  background: var(--card); color: var(--ink);
  padding: 0; width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 24px);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .5), 0 0 0 1px var(--line);
}
dialog[open] { display: flex; flex-direction: column; animation: dlgIn var(--dur-base) var(--ease-out); }
dialog > form { display: flex; flex-direction: column; min-height: 0; }
@keyframes dlgIn { from { opacity: 0; transform: translateY(8px) scale(.985) } to { opacity: 1; transform: none } }
dialog::backdrop { background: rgba(18, 18, 18, .32); backdrop-filter: blur(3px); }

.dlg-head { display: flex; align-items: center; gap: 10px; padding: 20px 24px 12px; flex: none; }
.dlg-head h2 { margin: 0; flex: 1; font-size: 17px; font-weight: 600; letter-spacing: -.012em; }
.dlg-body {
  flex: 1 1 auto; min-height: 0;
  padding: 6px 24px 20px; max-height: min(70vh, 640px);
  overflow: auto; overscroll-behavior: contain;
}
.dlg-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 24px calc(13px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
  flex: none;
  border-radius: 0 0 var(--radius-dialog) var(--radius-dialog);
}
.dlg-foot .left { margin-right: auto; }

.field { margin-bottom: 14px; }
.field > label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 500; color: var(--ink-3); }

.field input[type=text], .field input[type=password], .field input[type=number],
.field select, .field textarea {
  width: 100%; padding: 9px 11px; min-height: 38px;
  border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--paper); outline: none; font-size: 14px;
  transition: border-color var(--dur-snap) var(--ease-out), box-shadow var(--dur-snap) var(--ease-out);
}
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--rule); }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--rule); box-shadow: 0 0 0 3px var(--focus-ring);
}
.field .hint { margin-top: 5px; font-size: 12px; line-height: 1.45; color: var(--ink-4); }
.field.check-row { display: flex; align-items: flex-end; gap: 16px; padding-bottom: 6px; }
.section-split { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-gap { display: flex; gap: 6px; margin-top: 8px; }
.row-end { display: flex; align-items: flex-end; gap: 8px; }
.inline-row { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.inline-row .hint { margin-top: 0; flex: 1; min-width: 160px; }

label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ink-2); }
label.inline input[type=checkbox], label.inline input[type=radio] { accent-color: var(--clay); }
input[type=checkbox], input[type=radio] { accent-color: var(--clay); }

.choices { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.choice-row { display: flex; gap: 6px; align-items: center; }
.choice-row input { flex: 1; padding: 7px 10px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--paper); }

.profile-list { display: flex; flex-direction: column; gap: 6px; }
.profile-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  box-shadow: inset 0 0 0 1px var(--line); cursor: pointer;
  transition: background var(--dur-snap) var(--ease-out), box-shadow var(--dur-snap) var(--ease-out);
}
.profile-item:hover { background: var(--alpha-1); }
.profile-item.active { box-shadow: inset 0 0 0 1.5px var(--clay); }
.profile-item .nm { flex: 1; font-weight: 500; font-size: 13.5px; }
.profile-item .det { font-size: 11px; color: var(--ink-4); }
.profile-item .badge { font-size: 10.5px; color: var(--clay-ink); }

.confirm-dialog { width: min(420px, calc(100vw - 32px)); }
.confirm-text { margin: 0; color: var(--ink-3); font-size: 14px; line-height: 1.55; }

/* переключатель листов */
.sheets-dialog { width: min(460px, calc(100vw - 24px)); }
.sheet-switch-list { display: flex; flex-direction: column; gap: 3px; }
.sheet-switch-item {
  display: flex; align-items: center; gap: 2px;
  padding: 2px; border-radius: 12px;
  transition: background var(--dur-snap) var(--ease-out);
}
.sheet-switch-item:hover { background: var(--alpha-1); }
.sheet-switch-item.active { background: var(--alpha-2); box-shadow: inset 0 0 0 1px var(--line); }
.switch-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 1px;
  padding: 9px 12px; border: 0; border-radius: 10px;
  background: none; text-align: left;
}
.switch-name {
  font-size: 14px; font-weight: 500; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-switch-item.active .switch-name::after { content: "✓"; margin-left: 8px; color: var(--clay-ink); font-size: 12px; }
.switch-meta { font-size: 11.5px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.switch-icon {
  width: 34px; height: 34px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 9px; background: none; color: var(--ink-4);
  transition: background var(--dur-snap) var(--ease-out), color var(--dur-snap) var(--ease-out);
}
.switch-icon:hover { background: var(--alpha-2); color: var(--ink); }
.switch-icon.danger:hover { color: var(--danger); }
.switch-icon svg { width: 15px; height: 15px; }
.sheet-switch-empty { margin: 6px 4px; color: var(--ink-3); font-size: 13.5px; line-height: 1.5; }
.sheet-switch-hint { margin: 12px 6px 0; color: var(--ink-4); font-size: 11.5px; line-height: 1.45; }
.empty-state .empty-action { margin-top: 16px; }

/* ── тосты / служебное ──────────────────────────────────── */
.toast-host {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 140; pointer-events: none;
}
.toast {
  padding: 9px 16px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 13px; box-shadow: 0 8px 24px -12px rgba(0, 0, 0, .5);
  animation: toastIn .18s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

kbd {
  font-family: var(--font-mono); font-size: 10.5px; padding: 1px 5px;
  border-radius: 4px; background: var(--alpha-1); color: var(--ink-4);
}

.hidden { display: none !important; }

@media (max-width: 1320px) {
  #topbar { flex-wrap: wrap; row-gap: 12px; }
  .title-block { flex: 1 1 100%; }
  .toolbar { flex: 1 1 100%; }
  #colsBtn > span { display: none; }
  #addRowBtn > span { display: none; }
}

/* ── телефон ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; min-width: 0; grid-template-rows: auto minmax(0, 1fr); }
  #main { min-height: 0; }
  #rail {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
  }
  .brand { padding: 0 4px 0 0; flex: none; order: 1; }
  .brand-mark { width: 24px; height: 24px; border-radius: 7px; font-size: 13px; }
  .brand h1 { font-size: 16px; }
  .rail-label { display: flex; padding: 0; flex: none; order: 3; }
  .rail-label > span { display: none; }
  #sheetList { display: none; }
  .rail-sheets {
    order: 2;
    flex: 1 1 auto; min-width: 0;
    display: flex; align-items: center; gap: 7px;
    height: 36px; padding: 0 9px;
    border: 0; border-radius: 10px;
    background: var(--alpha-1);
    color: var(--ink-1);
    text-align: left;
    transition: background var(--dur-snap) var(--ease-out);
  }
  .rail-sheets:hover { background: var(--alpha-2); }
  .rail-sheets > svg { width: 15px; height: 15px; flex: none; color: var(--ink-3); }
  .rail-sheets-name {
    flex: 1; min-width: 0;
    font-size: 13.5px; font-weight: 500;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .rail-sheets-count {
    flex: none; font-size: 11px; color: var(--ink-4);
    min-width: 10px; text-align: right; font-variant-numeric: tabular-nums;
  }
  .rail-sheets-chev { color: var(--ink-4); }
  .rail-foot { border-top: 0; padding: 0; margin: 0; flex: none; order: 4; }
  .rail-foot .rail-icon, #newSheetBtn { width: 32px; height: 32px; }

  /* на телефоне листы выбираются через меню-хаб в шапке */
  #topbar { padding: 12px 16px 8px; gap: 10px; }
  .title-block { flex: 1 1 auto; }
  .title-block h1 { font-size: 22px; }
  .meta { font-size: 12px; gap: 2px 10px; }

  .toolbar {
    flex: 1 1 100%;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar .btn { flex: none; height: 34px; }
  .search-box { min-width: 150px; flex: 1 0 150px; height: 34px; }
  .search-box kbd { display: none; }

  #gridWrap { padding: 0 8px 6px; scrollbar-width: none; overscroll-behavior-x: contain; }
  #gridWrap::-webkit-scrollbar { display: none; }
  #grid thead th .head { padding: 8px 8px 7px 10px; min-height: 44px; }
  #grid tbody td.gutter, #grid thead th.gutter { width: 44px; min-width: 44px; padding-left: 8px; }
  .row-menu-btn { opacity: .7; }
  .add-strip { padding: 9px 10px; }
  .add-strip .add-hint { display: none; }

  #dock { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .dock-inner { gap: 6px; }
  .result-strip { font-size: 12.5px; padding: 9px 10px; border-radius: 11px; }
  #composer { min-height: 46px; }
  #assistInput { font-size: 16px; } /* 16px: iOS не зумит поле */
  .hint-line { display: none; }

  #colsPanel { position: fixed; left: 8px; right: 8px; width: auto; top: auto; bottom: calc(84px + env(safe-area-inset-bottom)); }

  dialog { width: calc(100vw - 16px); }
  .dlg-head { padding: 18px 18px 10px; }
  .dlg-body { padding: 4px 18px 16px; }
  .dlg-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .two { grid-template-columns: 1fr; gap: 0; }
  .toast-host { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

/* Очень узкие телефоны: оставляем знак, а название прячем — место нужно имени листа. */
@media (max-width: 360px) {
  .brand h1 { display: none; }
  .brand { padding-right: 2px; }
}

/* Пальцем сложнее попасть: минимальная высота интерактивных элементов. */
@media (pointer: coarse) {
  .btn { height: 38px; }
  .btn.icon { width: 38px; }
  .rail-icon { width: 34px; height: 34px; }
  .view-tabs { height: 38px; padding: 4px; }
  .view-tabs button { height: 30px; }
  .search-box { height: 38px; }
  #grid thead th .head .tools { opacity: 1; }
}

@media (hover: none) {
  #sheetList li .menu-btn { opacity: .75; }
  .row-menu-btn { opacity: .75; }
}

/* Ландшафт телефона: места по вертикали мало — сжимаем шапку и док. */
@media (max-width: 900px) and (max-height: 520px) {
  #rail { padding-top: 6px; padding-bottom: 6px; }
  .brand { padding-bottom: 0; }
  #topbar { padding: 8px 14px 6px; }
  .title-block h1 { font-size: 18px; }
  .meta { display: none; }
  #gridWrap { padding-bottom: 2px; }
  #dock { padding-top: 4px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  #composer { min-height: 40px; height: 40px; }
  .result-strip { position: fixed; left: 12px; right: 12px; bottom: calc(56px + env(safe-area-inset-bottom)); }
}

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