/* Кабинет на телефоне и планшете.
   Подключается последним и только переопределяет: десктоп (шире 1100 px) этот файл не трогает,
   кроме нескольких общих мелочей в самом начале.

   Пороги:  телефон  — до 640 px (нижняя панель разделов, окна-листы снизу, таблицы карточками);
            планшет  — 641–1100 px (верхнее меню, две колонки, крупные зоны нажатия).

   Экраны-модули рисуют разметку строками с инлайн-стилями, поэтому здесь много !important:
   иначе правило из файла не перебьёт style="…". Крючки — классы вида .fn-*, .wz-*, .m-*. */

:root {
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* ---------- Общие элементы оболочки (скрыты на десктопе) ---------- */
.tabbar, .tb-back, .tb-title, .tb-acct { display: none; }

/* Шторка этапа: шапка с крестиком остаётся на виду при прокрутке */
.drawer-head {
  position: sticky; top: -30px; z-index: 3; margin: -30px -28px 0; padding: 24px 20px 10px 28px;
  display: flex; align-items: flex-start; gap: 12px; background: var(--bg-card);
}
.drawer-head .dh-title { flex: 1; min-width: 0; }
.drawer-head h3 { margin: 4px 0 0; }
.drawer .drawer-close {
  position: static; flex: none; width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 0;
}
.drawer .drawer-close:hover { background: var(--bg-raise); }
.drawer-head + .chip { display: inline-block; margin-top: 6px; }

/* Галочка внутри .field наследовала вид подписи поля (капс, разрядка) */
.field label.check { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 14px; }

/* Список этапов с галочками в окне «Новый этап» */
.dep-list { border: 1px solid var(--line-bright); border-radius: 10px; background: var(--bg); padding: 2px 12px; max-height: 216px; overflow-y: auto; }
.field .dep-list .dep-row {
  display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 9px 0; cursor: pointer;
  font-size: 14px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink);
}
.field .dep-list .dep-row + .dep-row { border-top: 1px solid var(--line); }
.field .dep-list .dep-row input { width: 18px; height: 18px; padding: 0; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.dep-row span { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.dep-row b { font-weight: 600; }
.dep-row i { font-style: normal; font-size: 12px; color: var(--ink-faint); }
.dep-none { padding: 12px 0; font-size: 13px; color: var(--ink-faint); }

/* Лист «Ещё» / профиль */
.modal.sheet-menu { max-width: 380px; padding: 18px; }
.sm-user { display: flex; align-items: center; gap: 12px; padding: 6px 6px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.sm-who { min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.sm-who b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-who span { font-size: 12.5px; color: var(--ink-dim); overflow-wrap: anywhere; }
.sm-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 10px;
  border: none; background: none; border-radius: 10px; text-align: left;
  font: 600 15px var(--body); color: var(--ink); cursor: pointer;
}
.sm-item > span { flex: 1; }
.sm-item > .ic:first-child { color: var(--ink-dim); }
.sm-item > .ic:last-child { color: var(--ink-faint); }
.sm-item:hover, .sm-item.on { background: var(--bg-raise); }
.sm-item.on, .sm-item.on > .ic:first-child { color: var(--accent); }
.sm-item.danger, .sm-item.danger > .ic:first-child { color: var(--red); }
.modal.sheet-menu .actions { margin-top: 10px; }

/* ============================================================
   ПЛАНШЕТ И ТЕЛЕФОН (до 1100 px)
   ============================================================ */
@media (max-width: 1100px) {
  /* Верхняя панель не помещалась: страница получала прокрутку вбок на всех экранах.
     Поддомен и имя уходят в кнопку профиля (инициалы), меню занимает освободившееся место. */
  .topbar { gap: 12px; padding: 0 16px; }
  .topbar .ws, .topbar .user, .topbar #logout { display: none; }
  .topbar .nav { margin-left: 4px; min-width: 0; }
  .tb-acct {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-bright);
    background: var(--bg-card); color: var(--navy); font: 800 13px var(--body); letter-spacing: .02em;
  }
  .tb-acct:hover { border-color: var(--accent); }

  /* Мелкий текст инлайн-стилей модулей (10–11.5 px) на сенсорном экране не читается */
  [style*="font-size:9px"], [style*="font-size:9.5px"],
  [style*="font-size:10px"], [style*="font-size:10.5px"], [style*="font-size:11px"], [style*="font-size:11.5px"],
  [style*="font-size: 10px"], [style*="font-size: 10.5px"], [style*="font-size: 11px"], [style*="font-size: 11.5px"] {
    font-size: 12px !important;
  }
  .chip, .field label, .tool-group > .lbl, .branch-head .type, .branch-head .blocking, .stage-card .deps,
  .stage-card .sub-count, .stage-card .stage-dates, .drawer .sec, .muted-mono, .flag, .grade-chip, .og-type,
  .skill-tag, .act, .proj-card .deal, .sc-ava.sm { font-size: 12px; }
  .chip { letter-spacing: .04em; }
  .drawer .sec { letter-spacing: .1em; }

  /* Зоны нажатия: общие кнопки кабинета */
  .btn-ghost, .btn-amber, .btn-tr, .og-act, .act-del, .act-toggle, .act, .at-tab, .view-toggle a,
  .inline-add button, .t-btn { min-height: 44px; }
  .og-act.icon-only { min-width: 44px; padding: 0; }
  .drawer .drawer-close { width: 44px; height: 44px; }
  .inline-add button { min-width: 44px; }
  /* «Крошки»: ссылки в строку текста — увеличиваем зону нажатия, не сдвигая вёрстку */
  .crumb a { display: inline-block; padding: 13px 6px; margin: -13px -6px; }
  /* Поля ввода и списки на страницах */
  .page input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]),
  .page select { min-height: 44px; }
  .btn-ghost, .btn-amber, .btn-tr, .og-act, .act, .act-del, .act-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
  .act, .act-del, .act-toggle, .og-act { padding-left: 12px; padding-right: 12px; }
  .act-del { min-width: 44px; font-size: 18px; line-height: 1; }
  .person .p-edit, .t-edit-mini { min-width: 44px; min-height: 44px; }
  .inline-add input, .stage-dates-edit input { min-height: 44px; }
  .modal .check input, .check input { width: 20px; height: 20px; }
  .modal .check, .skill-toggles .check.sm { min-height: 44px; }
}

/* На сенсорных экранах любого размера поля не должны вызывать авто-зум iOS */
@media (max-width: 640px), (pointer: coarse) and (max-width: 1100px) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select, textarea { font-size: 16px !important; }
}

/* ============================================================
   ПЛАНШЕТ (641–1100 px)
   ============================================================ */
@media (min-width: 641px) and (max-width: 1100px) {
  .topbar .brand-mark { font-size: 0; gap: 0; flex: none; }   /* остаётся знак */
  .nav a { padding: 11px 12px; display: inline-flex; align-items: center; min-height: 44px; }
  .page { padding: 24px 20px 64px; }
  .drawer { width: min(480px, 70vw); }
}
@media (min-width: 641px) and (max-width: 760px) {
  .nav a { padding: 11px 9px; font-size: 13px; white-space: nowrap; flex: none; }
  /* на самых узких планшетах шесть разделов не помещаются — меню листается вбок, страница не шире экрана */
  .topbar .nav { flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
  .topbar .nav::-webkit-scrollbar { display: none; }
  .topbar .spacer { display: none; }
}

/* ============================================================
   ТЕЛЕФОН (до 640 px)
   ============================================================ */
@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: rgba(10,77,166,.12); }

  /* --- Верхняя панель: знак + название раздела, на вложенных экранах — «Назад» --- */
  .topbar { height: calc(50px + var(--safe-t)); padding: var(--safe-t) 12px 0 14px; gap: 10px; }
  .topbar .nav, .topbar .tb-acct { display: none; }
  .topbar .brand-mark { font-size: 0; gap: 0; flex: none; }
  .topbar .tb-title { display: block; font: 700 16px var(--disp); color: var(--ink); min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar.nested { padding-left: 4px; }
  .topbar.nested .brand-mark { display: none; }
  .topbar.nested .tb-title { color: var(--ink-faint); font-weight: 600; font-size: 14px; margin-left: auto; padding-right: 4px; }
  .topbar.nested .spacer { display: none; }
  .tb-back {
    display: inline-flex; align-items: center; gap: 2px; height: 44px; padding: 0 12px 0 6px; margin: 0;
    border: none; background: none; border-radius: 10px; color: var(--accent); font: 600 16px var(--body);
  }
  .tb-back:active { background: rgba(10,77,166,.08); }
  /* «Назад» теперь всегда в верхней панели — дубли на самих экранах и «крошки» убираем */
  .page [data-nav-back] { display: none !important; }
  .page-head .crumb { display: none; }

  /* --- Нижняя панель разделов --- */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 4px var(--safe-b);
    background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(16,24,40,.06);
  }
  .tabbar > * {
    flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; border: none; background: none; padding: 0 2px; color: var(--ink-faint);
    font: 600 12px var(--body); letter-spacing: -.01em; position: relative;
  }
  .tabbar > * > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar > .on { color: var(--accent); }
  .tabbar > .on::before {
    content: ""; position: absolute; top: 0; left: 50%; width: 28px; height: 3px; margin-left: -14px;
    border-radius: 0 0 3px 3px; background: var(--accent);
  }
  .tabbar > *:active { background: rgba(10,77,166,.06); }
  body.kb-open .tabbar { display: none; }           /* клавиатура открыта — панель не мешает */
  body[data-route="wizard"] .tabbar { display: none; }  /* мастер сметы ведёт своя нижняя панель */

  .page { padding: 14px 14px calc(var(--tabbar-h) + var(--safe-b) + 28px); }
  body.kb-open .page { padding-bottom: 24px; }
  .page-head { gap: 10px 12px; margin-bottom: 16px; align-items: center; }
  .page-head h2 { font-size: 22px; line-height: 1.25; }
  .toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 130; }
  body.kb-open .toast, body[data-route="wizard"] .toast { bottom: 84px; }
  .offline-chip { top: calc(var(--safe-t) + 56px); font-size: 12px; }

  /* --- Зоны нажатия 44 px --- */
  .btn-ghost, .btn-amber, .btn-tr, .og-act, .act-del, .act-toggle, .act, .at-tab, .view-toggle a,
  .inline-add button, .t-btn, .btn-ghost.sm, .btn-ghost.xs, .btn-amber.sm { min-height: 44px; }
  .btn-ghost.sm, .btn-ghost.xs, .btn-amber.sm { font-size: 13.5px; padding-left: 14px; padding-right: 14px; margin-top: 0; }
  .act { font-size: 13px; }
  .act-del { min-width: 44px; }
  .person .p-edit, .t-edit-mini { min-width: 44px; min-height: 44px; }
  .inline-add button { min-width: 48px; font-size: 18px; }
  .field input, .modal select { padding: 12px 14px; min-height: 48px; }
  .view-toggle { width: 100%; }
  .view-toggle a { flex: 1; display: inline-flex; align-items: center; justify-content: center; }

  /* --- Окна: лист снизу, кнопки всегда на виду над клавиатурой --- */
  .modal-veil {
    inset: auto 0 auto 0; top: var(--vvt, 0px); height: var(--vvh, 100dvh);
    padding: 0; display: flex; align-items: flex-end; justify-content: center; overflow: hidden;
  }
  .modal {
    width: 100%; max-width: none !important; max-height: calc(var(--vvh, 100dvh) - 20px - var(--safe-t)) !important;
    border-radius: 18px 18px 0 0; border-bottom: none; padding: 22px 16px 0;
    overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    animation: sheet-up .26s cubic-bezier(.2,.9,.3,1) both; position: relative;
  }
  .modal::before {   /* «ручка» листа */
    content: ""; position: absolute; top: 8px; left: 50%; width: 38px; height: 4px; margin-left: -19px;
    border-radius: 4px; background: var(--line-bright);
  }
  .modal h3 { font-size: 18px; margin-bottom: 16px; padding-right: 4px; }
  .modal .row2 { grid-template-columns: 1fr !important; gap: 0 !important; }
  .modal .row2.keep2 { grid-template-columns: 1fr 1fr !important; gap: 0 10px !important; align-items: end; }
  .modal .row2:not(.keep2) > div:not(.field) + div:not(.field) { margin-top: 14px; }
  .modal .actions {
    position: sticky; bottom: 0; z-index: 2; margin: 16px -16px 0 !important; padding: 10px 16px calc(10px + var(--safe-b));
    background: var(--bg-card); border-top: 1px solid var(--line);
    display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px;
  }
  .modal .actions > * { flex: 1 1 40%; width: auto; min-height: 48px; margin: 0; }
  .modal .actions > .spacer { display: none; }
  .modal .actions > .btn-amber { order: 5; }        /* главное действие — справа, под большим пальцем */
  .modal.sheet-menu { padding: 22px 12px 0; }
  .modal.sheet-menu .actions { margin: 8px -12px 0 !important; padding-left: 12px; padding-right: 12px; }
  body.kb-open .modal .actions { padding-bottom: 10px; }
  .skill-matrix { max-height: none; }
  .skill-row { flex-wrap: wrap; gap: 4px 10px; padding: 6px 8px; }

  /* --- Шторка этапа: на весь экран, действие «что дальше» прибито к низу --- */
  .drawer-veil { backdrop-filter: none; }
  .drawer {
    width: 100vw; border-left: none; padding: 20px 16px 0; display: flex; flex-direction: column;
    overscroll-behavior: contain; animation: sheet-up .26s cubic-bezier(.2,.9,.3,1) both;
  }
  .drawer > * { flex: none; }
  body.kb-open .drawer { bottom: var(--kb, 0px); }
  .drawer-head { top: -20px; margin: -20px -16px 0; padding: calc(14px + var(--safe-t)) 8px 10px 16px; border-bottom: 1px solid var(--line); }
  .drawer .drawer-close { width: 44px; height: 44px; background: var(--bg-raise); color: var(--ink-dim); }
  .drawer-head + .chip { align-self: flex-start; margin-top: 14px; }
  .drawer .sec { margin: 22px 0 10px; }
  .drawer-next {
    order: 99; position: sticky; bottom: 0; z-index: 3; margin: 22px -16px 0;
    padding: 10px 16px calc(10px + var(--safe-b)); background: var(--bg-card);
    border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(16,24,40,.06);
  }
  .drawer-next .sec { display: none; }
  .drawer-next .transitions { gap: 8px; }
  .drawer-next .btn-tr { flex: 1 1 auto; min-height: 48px; font-size: 14px; }
  .drawer-next .btn-tr.primary { flex: 1 1 100%; order: -1; font-size: 15px; }
  .drawer-next .muted { font-size: 12.5px; }
  .drawer #reopen-stage { margin: 8px 0 0 !important; width: 100%; }
  .stage-dates-edit input { font-size: 16px; padding: 10px; }
  .substage { padding: 10px 12px; gap: 8px 10px; }
  .substage .nm { flex: 1 1 100%; font-size: 14.5px; }
  .substage .st-dot { margin-right: -2px; }
  .substage .act.danger, .act[data-del-sub] { min-width: 44px; padding: 0; font-size: 18px; }
  .substage .nm { order: 0; flex-basis: calc(100% - 24px); }
  .assigned-row, .roster-row { flex-wrap: wrap; padding: 8px 10px; }
  .assigned-row .ar-id, .roster-row .ar-id { flex: 1; min-width: 0; }
  .drawer .assigned-row > .ar-id { flex: 1 1 calc(100% - 46px); }
  .drawer .assigned-row > .act { flex: 1 1 auto; }
  .assigned-row > .muted-mono:empty { display: none; }
  .ap-scope { min-height: 44px; }
  .ap-scopes { flex-wrap: wrap; }
  .assign-list { max-height: none !important; }
  .dep-list { max-height: none; }
  .field .dep-list .dep-row { padding: 12px 0; font-size: 15px; }
  .field .dep-list .dep-row input { width: 22px; height: 22px; margin-top: 0; }
  .assigned-row > .spacer, .roster-row > .spacer { display: none; }
  .rg-head { flex-wrap: wrap; }
  .assign-pick { min-height: 52px; flex-wrap: wrap; row-gap: 0; }
  .assign-pick > .nm { flex: 1 1 60%; }
  .assign-pick > .muted-mono { flex: 1 1 100%; padding-left: 38px; margin-top: -6px; }
  #ac-regen { min-width: 48px; }
  .assign-pick .muted-mono { margin-top: 0; }
  #assign-stage, #add-participant { width: 100%; }
}
@keyframes sheet-up { from { transform: translateY(28px); opacity: 0; } }
@media (max-width: 350px) {
  .tabbar > * { font-size: 11px; }
}

/* Заголовок периода календаря: capitalize делал «12–18 Октября 2026, Вторник» */
.cal-period { text-transform: none !important; }
.cal-period::first-letter { text-transform: uppercase; }

/* Поле поиска: родной вид iOS (скругление, тень) ломал общий стиль полей */
input[type=search] { -webkit-appearance: none; appearance: none; }

/* ============================================================
   ТАБЛИЦЫ → КАРТОЧКИ (телефон)
   table.m-stack: строка становится карточкой, ячейки — строками «подпись — значение».
   Классы ячеек: .m-title (заголовок карточки), .m-half (две в ряд), .m-wide (на всю ширину
   без подписи), .m-end (значение справа), .m-acts (кнопки), .m-hide (не показывать);
   подпись берётся из data-l. Строка-заголовок группы — tr.m-group.
   ============================================================ */
@media (max-width: 640px) {
  .page table.m-stack, table.m-stack { display: block; min-width: 0 !important; width: 100% !important; overflow: visible; }
  table.m-stack > thead { display: none; }
  table.m-stack > tbody { display: block; }
  table.m-stack > tbody > tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 13px 14px;
    border-top: 1px solid var(--line);
  }
  table.m-stack > tbody > tr:first-child { border-top: none; }
  table.m-stack > tbody > tr > td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 1 1 100%;
    min-width: 0; width: auto !important; padding: 0 !important; text-align: left !important;
    white-space: normal !important; border: none !important;
  }
  table.m-stack td[data-l]::before {
    content: attr(data-l); flex: none; font: 500 12.5px var(--body); color: var(--ink-faint);
    letter-spacing: 0; text-transform: none;
  }
  table.m-stack td.m-title { display: block; font-size: 15px; }
  table.m-stack td.m-half { flex: 1 1 40%; justify-content: flex-start; }
  table.m-stack td.m-half.m-end, table.m-stack td.m-end { justify-content: flex-end; }
  table.m-stack td.m-wide { display: block; }
  table.m-stack td.m-hide, table.m-stack tr.m-hide { display: none !important; }
  table.m-stack td.m-acts { justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
  table.m-stack tr.m-group { padding: 10px 14px; background: var(--surface-sunken); }
  table.m-stack tr.m-group > td { display: block; }
  table.m-stack tr.m-total { background: var(--surface-sunken); }
  /* обёртки таблиц с собственной прокруткой больше не нужны */
  .m-stack-wrap { overflow: visible !important; }
}

/* ============================================================
   ПРОЕКТЫ: воронка и список
   ============================================================ */
@media (max-width: 1100px) {
  #fn-search { height: 44px !important; }
}
@media (max-width: 640px) {
  /* название раздела уже стоит в верхней панели */
  body[data-route="funnel"] .page-head h2, body[data-route="projects"] .page-head h2,
  body[data-route="staff"] .page-head h2, body[data-route="hr"] .page-head h2,
  body[data-route="settings"] .page-head h2, body[data-route="automation"] .page-head h2 { display: none; }
  /* в шапке страницы не осталось ничего, кроме скрытого заголовка, — убираем и её отступ */
  body:is([data-route="hr"], [data-route="settings"], [data-route="automation"], [data-route="staff"], [data-route="funnel"], [data-route="projects"])
    .page-head:not(:has(> :not(:first-child):not(.spacer))) { display: none; }

  .pv-toggle { display: flex !important; flex: 1 1 100%; }
  .pv-seg { flex: 1; min-height: 44px; font-size: 14px !important; }
  .page-head > .btn-amber { flex: 1 1 100%; min-height: 48px; font-size: 15px; }
  .page-head > .btn-ghost { flex: 1 1 auto; }
  .page-head > .spacer { display: none; }

  /* Воронка: вместо пяти колонок с прокруткой вбок — столбик разделов по статусам */
  .fn-wrap { display: block !important; height: auto !important; min-height: 0 !important; }
  .fn-bar { gap: 10px !important; margin-bottom: 12px !important; }
  .fn-stats { order: 2; gap: 6px 14px !important; font-size: 13px !important; width: 100%; }
  .fn-search { margin: 0 !important; width: 100%; order: 1; }
  #fn-search { width: 100% !important; max-width: none !important; height: 46px !important; }
  .fn-board { display: block !important; overflow: visible !important; padding: 0 !important; background: none !important;
    border: none !important; }
  .fn-col {
    width: auto !important; min-width: 0 !important; height: auto !important; display: block !important;
    border-right: none !important; margin-bottom: 10px;
  }
  .fn-col:last-child { margin-bottom: 0; }
  .fn-col .fn-strip { display: none; }
  .fn-col-head { padding: 6px 12px 6px 4px !important; border-bottom: none !important; }
  .fn-col-head > div + div { padding: 0 0 6px 44px !important; margin-top: -6px !important; }
  .fn-collapse { width: 44px; height: 44px; align-items: center; justify-content: center; padding: 0 !important; }
  .fn-col-head span[style*="font-size:13px"] { font-size: 15px !important; }
  .fn-col-body { overflow: visible !important; padding: 2px 12px 14px !important; gap: 10px !important; }
  .fn-col-min .fn-expand {
    flex-direction: row !important; align-items: center !important; gap: 10px !important;
    padding: 0 14px 0 14px !important; min-height: 50px;
  }
  .fn-col-min .fn-expand span { writing-mode: horizontal-tb !important; transform: none !important; }
  .fn-col-min .fn-expand span:nth-child(2) { font-size: 15px !important; }
  .fn-col-min .fn-expand span:last-child { margin-left: auto; font-size: 13px !important; }
  .fn-card { padding: 13px 14px !important; border-radius: 11px !important; }
  .fn-card > div:first-child { font-size: 15px !important; }
  .fn-card span[style*="font-size:12.5px"] { font-size: 14px !important; }
  .fn-more { min-height: 46px; font-size: 14px !important; }

  /* Список проектов карточками */
  .pl-row { cursor: pointer; }
  body[data-route="projects"] .page-head > .chip { display: none; }
  .pl-row .m-title > div:first-child { font-size: 15.5px !important; }
}
@media (min-width: 641px) and (max-width: 1100px) {
  /* Планшет: доска листается вбок, колонка «прилипает» к краю */
  .fn-board { scroll-snap-type: x mandatory !important; }
  .fn-col:not(.fn-col-min) { min-width: 280px !important; }
  .fn-col-min { width: 52px !important; }
  /* Редактор сметы: суммы и количества не переносятся на вторую строку */
  .est-table td { padding-left: 10px !important; padding-right: 10px !important; }
  .est-table td.e-price, .est-table td.e-sum, .est-table .qty-cell { white-space: nowrap; }
  .fn-card { padding: 12px 13px !important; }
  .fn-card > div:first-child { font-size: 14px !important; }
  .fn-collapse { align-items: center; justify-content: center; margin: -10px -4px -10px -12px; }
}

/* ============================================================
   ПРОЕКТ: панель разделов, ветки, этапы
   ============================================================ */
@media (max-width: 1100px) {
  .t-btn { padding: 9px 12px; font-size: 13.5px; }
  .add-stage { min-width: 52px; height: 52px; }
  .stage .node { width: 22px; height: 22px; }
}
@media (max-width: 640px) {
  .deal-head { align-items: flex-start !important; }
  .deal-head h2 { font-size: 20px; }
  .deal-meta { width: 100%; justify-content: space-between; }
  .deal-prog { flex: 1; justify-content: flex-end; }
  .deal-prog .bar { width: auto; flex: 1; max-width: 180px; }
  .deal-prog .pctn { font-size: 13px; }

  /* Одиннадцать ссылок занимали целый экран — плитки по четыре в ряд */
  .deal-toolbar { gap: 8px; margin-bottom: 18px; }
  .tool-group {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; width: 100%;
    padding: 8px 6px 6px; border-radius: 14px;
  }
  .tool-group > .lbl { grid-column: 1 / -1; margin: 0 0 2px 6px; }
  .t-btn {
    flex-direction: column; gap: 5px; padding: 8px 2px; min-height: 58px; font-size: 12px; line-height: 1.2;
    white-space: normal; text-align: center; justify-content: flex-start; border-radius: 10px;
  }
  .t-btn .ic { width: 22px; height: 22px; color: var(--accent); opacity: 1; }
  .t-btn:active { background: var(--bg-card); }

  /* Шапка ветки: название и удаление — первой строкой, статусы — второй, прогресс — третьей */
  .branch { border-radius: 14px; }
  .branch-head { gap: 8px 10px; padding: 12px 8px 12px 14px; }
  .branch-head .lane-dot { order: -3; }
  .branch-head h4 { order: -3; flex: 1 1 calc(100% - 80px); min-width: 0; font-size: 16px; line-height: 1.3; }
  .branch-head:not(:has(.act-del)) h4 { flex-basis: calc(100% - 30px); }
  .branch-head .act-del { order: -2; border-color: transparent; color: var(--ink-faint); }
  .branch-head .type { margin-left: 21px; }
  .branch-head .spacer { flex: 1 1 100%; height: 0; order: 5; }
  .branch-head .progress { order: 9; flex: 1; width: auto; margin-left: 21px; }
  .branch-head .pctn { order: 10; width: auto; padding-right: 8px; font-size: 13px; }
  .branch-head:not(:has(.act-del)) { padding-right: 14px; }

  /* Этапы — вертикальной лентой: не нужно листать вбок, видно всю ветку сразу */
  .stages { flex-direction: column; overflow: visible; padding: 14px 12px 12px 14px; }
  .stage { min-width: 0; padding: 0 0 12px 34px; }
  .stage::before { top: 22px; bottom: -8px; left: 10px; right: auto; width: 2px; height: auto; }
  .stage:last-of-type::before { display: none; }
  .stage .node { position: absolute; left: 0; top: 14px; margin: 0; }
  .stage .node::after { content: ""; position: absolute; inset: -12px; }   /* зона нажатия */
  .stage-card {
    margin: 0; padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px;
    align-items: start; background: var(--bg-raise);
  }
  .stage-card:hover { transform: none; }
  .stage-card .nm { margin: 0; font-size: 15px; line-height: 1.3; }
  .stage-card .chip { grid-column: 2; grid-row: 1; white-space: nowrap; }
  .stage-card .sub-count, .stage-card .stage-dates, .stage-card .deps { margin-top: 2px; }
  .stage-card .deps { grid-column: 1 / -1; }
  .add-stage { width: 100%; min-width: 0; height: 46px; margin: 0; font-size: 20px; }
  .add-stage::after { content: " этап"; font-size: 14px; font-weight: 600; vertical-align: 2px; }
  .add-branch { padding: 16px; min-height: 52px; }
  .danger-zone { margin-top: 36px; }
  .danger-zone button { width: 100%; }
}

/* ============================================================
   ОБЩИЕ КРЮЧКИ ЭКРАНОВ-МОДУЛЕЙ
   .scr-head — шапка экрана (заголовок + действия); .m-float-main — главное действие,
   на телефоне прибитое над нижней панелью; .pm-ovl/.pm-sheet — окна модулей (задачи,
   замеры), на телефоне — лист снизу; .card-acts — ряд действий карточки.
   ============================================================ */
.m-only, .doc-note-m { display: none; }

@media (max-width: 1100px) {
  .t-filter, .m-status, .m-del, .t-status, .t-del, .gen-preset, .bm-skill, .doc-fmt, .wz-rtab, .cal-mode,
  .docref-noop, .pm-acc-mass .mq, .pv-seg, .bm-free { min-height: 44px; }
  .t-filter, .m-status, .m-del, .t-status, .t-del, .gen-preset, .bm-skill, .doc-fmt, .docref-noop { padding-left: 14px !important; padding-right: 14px !important; }
  .cal-navbtn { width: 44px !important; height: 44px !important; }
  #cal-today { min-height: 44px; }
  .row-del, #room-add, .wz-room-edit, .wz-room-del, .pay-toggle, .pay-del, .pl-edit, .pl-cat-add, .pl-cat-edit, .pl-cat-del,
  .hrd-del-val, .hrd-del-dict, .fn-collapse { width: 44px !important; height: 44px !important; }
  .page .qty-cell { min-height: 44px !important; min-width: 64px !important; }
  .page .est-topbar button { min-height: 44px !important; }
  .g-toggle > * { min-height: 44px; }
  .wi-row { min-height: 44px; }
  /* В сетке месяца название события — не кнопка: нажатие по ячейке открывает день целиком */
  .cal-cell:not(.cal-cell-m) > .cal-ev { pointer-events: none; }
  .cal-more { min-height: 28px; }
  .cal-cell > div > .cal-ev { min-height: 44px; }   /* события в колонках недели */
  #bm-target { height: 44px !important; }
  body .pm-acc-new #pm-acc-add { min-width: 44px; justify-content: center; }
  .wi-row input, .tf-mck { width: 20px !important; height: 20px !important; }
}

@media (max-width: 640px) {
  .m-only { display: inline; }
  .m-hide-phone { display: none !important; }
  .empty { padding: 34px 18px; border-radius: 14px; }

  /* Поля: высота под палец (шрифт 16 px задан выше — без авто-зума iOS) */
  .page input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]),
  .page select, .modal input:not([type=checkbox]):not([type=radio]):not([type=file]), .modal select,
  .pm-sheet input:not([type=checkbox]):not([type=radio]), .pm-sheet select { min-height: 46px; }
  .modal textarea, .pm-sheet textarea, .page textarea { min-height: 78px; }

  /* --- Шапка экрана --- */
  .scr-head { flex-wrap: wrap !important; gap: 10px 12px !important; }
  .scr-title { flex: 1 1 100%; }
  .scr-head h2 { font-size: 22px !important; line-height: 1.25 !important; white-space: normal !important; max-width: none !important; }
  .scr-name { max-width: none !important; white-space: normal !important; }
  .scr-head > .btn-amber { flex: 1 1 100%; min-height: 48px; font-size: 15px; justify-content: center; }
  .scr-head > .btn-ghost { flex: 1 1 auto; justify-content: center; }
  .scr-head > span[style*="flex:1"], .scr-head > .spacer, .scr-head > .chip { display: none; }
  .scr-title .crumb { display: none; }

  /* --- Главное действие экрана — всегда под большим пальцем --- */
  .m-float-main {
    position: fixed !important; left: 14px; right: 14px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px);
    z-index: 55; width: auto !important; min-height: 52px; justify-content: center; flex: none !important;
    font-size: 15.5px !important; border-radius: 14px !important; box-shadow: 0 10px 28px rgba(10,77,166,.36) !important;
  }
  body.kb-open .m-float-main { bottom: calc(var(--kb, 0px) + 10px); }
  .page:has(.m-float-main) { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 96px); }

  /* --- Плитки итогов --- */
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .kpi-grid > *, .est-kpi > * { padding: 12px !important; gap: 8px !important; min-width: 0 !important; }
  .kpi-grid > *:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpi-grid [style*="font-size:26px"], .est-kpi [style*="font-size:26px"] { font-size: 19px !important; letter-spacing: -.02em !important; }
  .kpi-grid span[style*="white-space:nowrap"], .est-kpi span[style*="white-space:nowrap"] { white-space: normal !important; }

  /* --- Ряд действий карточки --- */
  .card-acts { gap: 8px !important; }
  .card-acts > button { min-height: 44px; flex: 1 1 auto; justify-content: center; font-size: 13px !important; padding: 0 14px !important; }
  .card-acts > .spacer { display: none; }
  .card-acts > .ca-label { flex: 1 1 100%; }
  .chip-scroll { flex-wrap: nowrap !important; overflow-x: auto; margin: 0 -14px; padding: 0 14px 2px; scrollbar-width: none; }
  .chip-scroll::-webkit-scrollbar { display: none; }
  .t-filter { min-height: 44px; flex: none; font-size: 13.5px !important; padding: 0 15px !important; }

  /* --- Окна модулей: лист снизу --- */
  .pm-ovl { align-items: flex-end !important; padding: 0 !important; top: var(--vvt, 0px) !important; bottom: auto !important; height: var(--vvh, 100dvh); }
  .pm-sheet {
    max-width: none !important; max-height: calc(var(--vvh, 100dvh) - 20px - var(--safe-t)) !important;
    border-radius: 18px 18px 0 0 !important; border-bottom: none !important; padding: 22px 16px 0 !important;
    overscroll-behavior: contain; animation: sheet-up .26s cubic-bezier(.2,.9,.3,1) both;
  }
  .pm-sheet-acts {
    position: sticky; bottom: 0; z-index: 2; margin: 18px -16px 0 !important;
    padding: 10px 16px calc(10px + var(--safe-b)); background: var(--bg-card); border-top: 1px solid var(--line);
  }
  body.kb-open .pm-sheet-acts { padding-bottom: 10px; }
  .pm-sheet-acts > button { flex: 1; min-height: 48px; justify-content: center; }
  .pm-row2 { flex-wrap: wrap; }
  .pm-row2 > div { flex: 1 1 140px !important; min-width: 0; }
  .tf-pick { min-height: 50px; }
  #tf-mlist { max-height: none !important; }

  /* --- Ещё о таблицах-карточках --- */
  table.m-stack td.m-auto { flex: 0 0 auto; }
  table.m-stack td.m-push { margin-left: auto; }
  table.m-stack td.m-order2 { order: 2; }
  table.m-stack td.m-order3, table.m-stack td.m-acts { order: 3; }
  table.m-stack td.m-big, table.m-stack td.m-big > * { font-size: 15.5px !important; }
  table.m-stack td:empty { display: none; }
  table.m-stack td.m-acts button { min-height: 44px; min-width: 44px; }

  /* ============ Сотрудники ============ */
  .staff-filter { gap: 8px !important; }
  .sf-search { flex: 1 1 100% !important; max-width: none !important; min-width: 0 !important; }
  #staff-search, #staff-fstatus, #staff-fgrade, #staff-fposition { height: 46px !important; }
  #staff-fstatus, #staff-fgrade { flex: 1 1 40%; min-width: 0; }
  #staff-fposition { flex: 1 1 100%; min-width: 0; max-width: none !important; font-size: 16px !important; }
  .staff-filter > .chip { display: none; }
  .staff-filter > .btn-ghost { flex: 1 1 100%; }
  .staff-table .m-title .sc-ava.sm { width: 40px; height: 40px; border-radius: 11px; font-size: 13px; }
  .staff-table .m-title > div > div > div:first-child { font-size: 15.5px !important; }
  .staff-table .m-acts { justify-content: flex-start; }
  .staff-table .m-acts .btn-ghost { flex: 1 1 auto; }
  body[data-route="staff"] .page-head > .btn-ghost { flex: 1 1 30%; }

  .org-tree { gap: 12px; }
  .og-head { flex-wrap: wrap; gap: 8px; padding: 12px 10px 10px 14px; }
  .og-name { flex: 1 1 calc(100% - 44px); font-size: 16px; line-height: 1.3; }
  .og-head > .spacer { flex: 1 1 100%; height: 0; }
  .og-act { flex: 1 1 auto; }
  .og-act.icon-only, .og-head .act-del { flex: 0 0 44px; padding: 0; }
  .og-children { padding: 4px 6px 10px 8px; margin-left: 10px; }
  .og-members { padding: 4px 6px; }
  .person { flex-wrap: wrap; gap: 2px 10px; padding: 6px; }
  .person .p-name { flex: 1 1 0; min-width: 0; font-size: 14.5px; }
  .person > .spacer { order: 2; flex: 1 1 100%; height: 0; }
  .person .grade-chip { order: 3; margin-left: 38px; }
  .person .muted-mono { order: 3; margin: 0; align-self: center; }
  .person .dot { margin-left: auto; }

  /* ============ Задачи / замеры ============ */
  .t-card { padding: 14px !important; }
  .t-open { min-width: 0 !important; flex: 1 1 100% !important; }

  /* ============ Календарь ============ */
  .cal-root { gap: 14px !important; }
  .cal-title { display: none !important; }
  .cal-head { gap: 10px !important; margin-bottom: 0 !important; }
  .cal-head > .spacer { display: none; }
  .cal-nav { width: 100%; }
  .cal-period { flex: 1; min-width: 0 !important; font-size: 15px !important; }
  .cal-modes { display: flex !important; width: 100%; }
  .cal-mode { flex: 1; justify-content: center; min-height: 44px; padding: 0 4px !important; font-size: 13.5px !important; }
  .cal-mode svg { display: none; }
  .cal-body > div:has(.cal-cell-m) { padding: 6px !important; }
  .cal-agenda { padding: 2px 14px 10px !important; }
  .cal-ag-group { flex-direction: column; gap: 8px !important; padding: 12px 0 !important; }
  .cal-ag-group:first-child { border-top: none !important; }
  .cal-ag-date { width: auto !important; text-align: left !important; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
  .cal-ag-date > div { margin-top: 0 !important; font-size: 13px !important; }
  .cal-ag-date > div:first-child { font-size: 20px !important; }
  .cal-ev { min-height: 44px; }
  .cal-ev b { font-size: 14.5px !important; }
  .cal-legend { gap: 8px 14px !important; }

  /* ============ Акты / оплаты ============ */
  .scr-sub { margin: -8px 0 14px !important; }
  .panel-card { padding: 14px !important; margin-bottom: 14px !important; border-radius: 14px !important; }
  .panel-head { flex-wrap: wrap; }
  .panel-head > .act-new { flex: 1 1 100%; margin-top: 8px; min-height: 46px; justify-content: center; font-size: 14px; }
  .panel-head > span[style*="flex:1"] { display: none; }
  .acts-table > tbody > tr { padding-left: 0 !important; padding-right: 0 !important; }
  .acts-table td { border-top: none !important; }
  .pay-toggle, .pay-del { height: 44px !important; min-width: 44px; width: auto !important; border-radius: 10px !important; }
  .pay-toggle { flex: 1; gap: 6px; padding: 0 14px !important; font: 600 13.5px var(--body); }
  .pay-del { flex: none; font-size: 20px !important; margin-left: 0 !important; }
  .pay-toggle[data-paid="0"] { color: var(--ink-dim) !important; }
  .gen-preset { min-height: 44px; font-size: 13px !important; padding: 0 16px !important; }

  /* ============ Гант ============ */
  .g-title { flex-wrap: wrap; }
  .g-toggle { display: flex !important; align-self: stretch !important; }
  .g-toggle > * { flex: 1; justify-content: center; min-height: 44px; }
  .g-summary { grid-template-columns: 1fr !important; }

  /* ============ Подбор бригады ============ */
  .bm-target-badge { display: none; }
  #bm-target { height: 48px !important; }
  .bm-free { height: 44px !important; }
  .bm-free input { width: 20px !important; height: 20px !important; }
  .bm-skill { min-height: 44px; padding: 0 14px !important; font-size: 13px !important; }
  .bm-card { gap: 12px !important; padding: 14px !important; align-items: flex-start !important; }
  .bm-info { min-width: 0 !important; flex: 1 1 calc(100% - 62px) !important; }
  .bm-load { flex: 1 1 0 !important; width: auto !important; }
  .bm-match { width: auto !important; flex: 0 0 auto !important; text-align: right !important; }
  .bm-assign { flex: 1 1 100% !important; min-height: 48px; justify-content: center; }

  /* ============ Документы ============ */
  .doc-root { gap: 14px !important; padding-bottom: 72px; }
  .doc-grid { gap: 14px !important; }
  .doc-side { gap: 12px !important; }
  .doc-side > div:not(.doc-actions):not(.doc-note-m) { padding: 14px !important; }
  .doc-tpls { gap: 8px !important; }
  .doc-tpl { padding: 10px !important; align-items: center !important; gap: 10px !important; min-height: 60px; }
  .doc-tpl > span:first-child { width: 34px !important; height: 34px !important; }
  .doc-tpl-desc, .doc-tpl-rec { display: none !important; }
  .doc-tpl-top b { font-size: 13.5px !important; line-height: 1.25; }
  .doc-fmts { margin-top: 12px !important; padding-top: 12px !important; }
  .doc-fmt { min-height: 44px; padding: 0 18px !important; font-size: 13px !important; }
  .doc-actions {
    position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 55;
    flex-direction: row !important; align-items: center; gap: 8px !important; padding: 8px 12px !important;
    border-radius: 0 !important; border-width: 1px 0 0 !important; box-shadow: 0 -6px 18px rgba(16,24,40,.08) !important;
  }
  body.kb-open .doc-actions { display: none !important; }
  .doc-actions-2 { display: contents !important; }
  #doc-download { flex: 1.5 1 0; width: auto !important; min-height: 48px; }
  #doc-send { flex: 1 1 0 !important; min-height: 48px; padding: 0 8px !important; }
  #doc-print { flex: 0 0 48px !important; min-height: 48px; padding: 0 !important; }
  .doc-print-t, .doc-send-t, .doc-actions .doc-note { display: none; }
  .doc-note-m { display: block; }
  .kp-paper { padding: 22px 16px !important; }
  .kp-paper h1 { font-size: 20px !important; }

  /* ============ Настройки сметы ============ */
  .set-card-head { flex-wrap: wrap; padding: 13px 14px !important; }
  .set-card-head > span[style*="flex:1"] { display: none; }
  .set-card-head .btn-ghost { flex: 1 1 100%; justify-content: center; }
  .set-margin { flex-wrap: wrap; }
  .set-toggle { min-height: 44px; align-items: center !important; }

  /* ============ Редактор сметы ============ */
  .est-topbar { gap: 8px !important; }
  .est-titlebox { flex: 1 1 100%; flex-wrap: wrap; }
  .est-title { white-space: normal !important; max-width: none !important; font-size: 20px !important; line-height: 1.25; }
  .est-topbar > span[style*="flex:1"] { display: none; }
  .page .est-topbar button { min-height: 44px !important; flex: 1 1 40%; justify-content: center; padding-left: 10px !important; padding-right: 10px !important; }
  .page .est-topbar #est-del { flex: 0 0 auto; }
  .est-split { border-radius: 14px !important; overflow: visible !important; }
  .est-rail { padding: 10px 12px !important; border-radius: 14px 14px 0 0; }
  #room-add { width: 44px !important; height: 44px !important; border-radius: 10px !important; }
  .est-main { padding: 14px 12px !important; overflow: visible !important; }
  .est-roomhead { gap: 6px 12px !important; margin-bottom: 8px !important; }
  .est-geom { flex-wrap: wrap; gap: 4px 14px !important; flex: 1 1 100%; font-size: 12.5px !important; }
  .est-roomhead > span[style*="flex:1"] { display: none; }
  .pm-switch { min-height: 44px; }
  .page table.est-table, table.est-table > tbody { display: block; width: 100%; overflow: visible; }
  table.est-table > thead { display: none; }
  table.est-table tr {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr) 44px; align-items: center; gap: 6px 10px;
    grid-template-areas: "name name name del" "dep dep dep dep" "qty price sum sum"; padding: 12px 0 12px 2px;
  }
  table.est-table > tbody > tr:first-child { border-top: none !important; }
  table.est-table td { display: block; padding: 0 !important; width: auto !important; text-align: left !important; }
  table.est-table td:empty { display: none; }
  table.est-table td[colspan] { grid-column: 1 / -1; padding: 22px 0 !important; text-align: center !important; }
  table.est-table td.e-name { grid-area: name; font-size: 15px; line-height: 1.3; }
  table.est-table td.e-dep { grid-area: dep; margin-top: -4px; }
  table.est-table td.e-qty { grid-area: qty; }
  table.est-table td.e-price { grid-area: price; white-space: nowrap; }
  table.est-table td.e-price::before { content: "× "; color: var(--ink-faint); }
  table.est-table td.e-sum { grid-area: sum; text-align: right !important; font-size: 15.5px !important; white-space: nowrap; padding-right: 12px !important; }
  table.est-table td.e-del { grid-area: del; }
  .row-del { width: 44px !important; height: 44px !important; border: none !important; background: none !important; font-size: 22px !important; }
  .page .qty-cell {
    min-height: 44px !important; min-width: 88px !important; padding: 0 12px !important; font-size: 14px !important;
    border: 1px solid var(--line-bright) !important; border-radius: 9px !important; background: var(--bg-card) !important;
  }
  .qty-edit { width: 112px !important; min-height: 42px; text-align: left !important; border-radius: 9px !important; padding: 0 12px !important; }
  table.est-table tr.e-total { grid-template-areas: "name name sum sum"; margin: 0 -12px; padding: 14px 12px !important; border-radius: 0 0 14px 14px; }
  .est-addwrap { margin: 0 !important; height: 0; }
  .wi-list { max-height: none !important; margin: 0 !important; }
  .wi-row { min-height: 48px; padding: 6px 2px !important; font-size: 14.5px !important; }

  /* ============ Мастер сметы ============ */
  .wz-root { padding-bottom: 84px; }
  .wz-root:has(#wz-open) { padding-bottom: 148px; }
  .wz-head h2 { font-size: 20px !important; }
  .wz-head .scr-name { max-width: 82vw !important; }
  .wz-stepswrap { padding: 12px 0 14px !important; margin-bottom: 16px !important; }
  .wz-steps { flex-wrap: nowrap !important; }
  .wz-step:not(.cur) .wz-step-l { display: none; }
  .wz-step-l { font-size: 14.5px !important; }
  .wz-step > span:first-child { width: 30px !important; height: 30px !important; }
  .wz-step-sep { flex: 1 1 8px !important; width: auto !important; min-width: 6px; margin: 0 8px !important; }
  .wz-body h2 { font-size: 20px !important; }
  .wz-grid2 { gap: 14px 12px !important; }
  .wz-grid2 > label:has(select) { grid-column: 1 / -1; }
  .wz-foot {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55; margin: 0 !important; flex-wrap: wrap; gap: 8px !important;
    padding: 10px 14px calc(10px + var(--safe-b)) !important; background: rgba(255,255,255,.97);
    border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(16,24,40,.07);
  }
  body.kb-open .wz-foot { bottom: var(--kb, 0px); padding-bottom: 10px !important; }
  .wz-foot > span[style*="flex:1"] { display: none; }
  .wz-foot > button { min-height: 50px; justify-content: center; font-size: 15px; }
  .wz-foot > .btn-ghost { flex: 0 1 auto; }
  .wz-foot > .btn-amber { flex: 2 1 0; }
  .wz-foot > #wz-open { order: -1; flex: 1 1 100%; }
  .wz-foot > #wz-kp { flex: 1 1 0; }
  .wz-room { flex-wrap: wrap; gap: 8px 12px !important; padding: 12px !important; }
  .wz-room-main { flex: 1 1 calc(100% - 60px) !important; }
  .wz-room-main > div:first-child { white-space: normal !important; }
  .wz-room-area { flex: 1 1 0 !important; text-align: left !important; display: flex; flex-wrap: wrap; gap: 2px 12px; padding-left: 52px; }
  .wz-room-edit, .wz-room-del { width: 44px !important; height: 44px !important; border-radius: 10px !important; }
  #wz-room-add { min-height: 52px; }
  .wz-rtabs { flex-wrap: nowrap !important; overflow-x: auto; margin: 0 -14px 14px !important; padding: 0 14px 2px; scrollbar-width: none; }
  .wz-rtabs::-webkit-scrollbar { display: none; }
  .wz-rtab { min-height: 44px; flex: none; font-size: 14px !important; padding: 0 16px !important; }
  .wz-geo-grid { gap: 14px !important; }
  .wz-geo-grid > div:first-child { padding: 14px !important; }
  .wz-works-wrap { overflow: visible !important; }
  .page table.wz-works, table.wz-works > tbody { display: block; min-width: 0 !important; width: 100% !important; overflow: visible; }
  table.wz-works > thead { display: none; }
  table.wz-works tr.wz-wgroup, table.wz-works tr.wz-wgroup > td { display: block; }
  table.wz-works tr.wz-wrow {
    display: grid; grid-template-columns: 30px minmax(0, 1fr) auto auto; align-items: center; gap: 4px 10px;
    grid-template-areas: "chk name name sum" "chk dep qty price"; padding: 11px 12px; min-height: 60px;
  }
  table.wz-works tr.wz-wrow > td { display: block; padding: 0 !important; width: auto !important; text-align: left !important; }
  tr.wz-wrow > td:nth-child(1) { grid-area: chk; }
  tr.wz-wrow > td:nth-child(1) > span { width: 24px !important; height: 24px !important; border-radius: 7px !important; }
  tr.wz-wrow > td:nth-child(2) { grid-area: name; font-size: 14.5px; line-height: 1.3; }
  tr.wz-wrow > td:nth-child(3) { grid-area: dep; }
  tr.wz-wrow > td:nth-child(4) { grid-area: qty; white-space: nowrap; }
  tr.wz-wrow > td:nth-child(5) { grid-area: price; white-space: nowrap; }
  tr.wz-wrow > td:nth-child(5)::before { content: "× "; color: var(--ink-faint); }
  tr.wz-wrow > td:nth-child(6) { grid-area: sum; text-align: right !important; font-size: 14.5px !important; white-space: nowrap; }
  .wz-works-total { flex-wrap: wrap; }
  .wz-exist { min-height: 60px; }

  /* ============ Прайс-лист ============ */
  .pl-search { flex: 1 1 100%; order: 3; }
  #pl-search { width: 100% !important; height: 46px !important; }
  body[data-route="pricelist"] .page-head > .btn-ghost { order: 4; flex: 0 0 auto; }
  body[data-route="pricelist"] .page-head > .btn-amber { order: 5; flex: 1 1 0; white-space: nowrap; }

  /* ============ Справочники ============ */
  .hrd-nav { min-height: 64px; }
  .hrd-cat-toggle { min-height: 54px; }
  .hrd-cat-toggle > span[style*="margin-left:auto"] { display: none; }
  .hrd-cat-toggle > span[style*="font-size:13.5px"] { font-size: 15px !important; flex: 1; }
  .hrd-val { min-height: 44px; padding: 6px 6px 6px 14px !important; }
  .hrd-val span[style*="font-size:13px"] { font-size: 14.5px !important; white-space: normal !important; }
  .hrd-del-val, .hrd-del-dict, .pl-cat-edit, .pl-cat-del { width: 44px !important; height: 44px !important; font-size: 20px !important; }
  .hrd-add, .hrd-more, .hrd-add-dict { min-height: 48px; font-size: 14px !important; }
  .docref-noop { min-height: 44px; font-size: 13.5px !important; padding: 0 14px !important; }

  /* ============ Вход ============ */
  .login-wrap { min-height: 100dvh; padding: max(7vh, 24px) 16px 24px; place-items: start center; }
  .login-card { padding: 28px 20px 24px; }
  .login-card h1 { font-size: 24px; }
  .login-sub { margin-bottom: 22px; }
  .btn-primary { min-height: 52px; font-size: 16px; }
}

/* Документы на планшете в портрете: настройки двумя колонками, лист — на всю ширину */
@media (min-width: 641px) and (max-width: 900px) {
  .doc-grid { grid-template-columns: 1fr !important; }
  .doc-tpls { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .doc-tpl { flex-direction: column; gap: 8px !important; }
  .doc-tpl-desc, .doc-tpl-rec { display: none !important; }
  .doc-tpl-top { align-items: flex-start !important; }
  .doc-actions { flex-direction: row !important; flex-wrap: wrap; align-items: center; }
  #doc-download { width: auto !important; flex: 1 1 200px; }
  .doc-actions-2 { flex: 2 1 320px; }
  .doc-actions .doc-note { flex: 1 1 100%; }
  .kp-paper { max-width: 680px !important; }

  /* Сотрудники: таблица из семи колонок не помещается — карточки в две колонки */
  .m-stack-wrap:has(> .staff-table) { overflow: visible !important; }
  table.staff-table { display: block; min-width: 0 !important; }
  table.staff-table > thead { display: none; }
  table.staff-table > tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  table.staff-table > tbody > tr {
    display: flex; flex-wrap: wrap; align-items: center; align-content: flex-start; gap: 8px 10px; padding: 14px;
    border-top: 1px solid var(--line) !important; border-right: 1px solid var(--line);
  }
  table.staff-table > tbody > tr:nth-child(2n) { border-right: none; }
  table.staff-table > tbody > tr > td {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: 1 1 100%; min-width: 0;
    padding: 0 !important; text-align: left !important; white-space: normal !important; width: auto !important;
  }
  table.staff-table td[data-l]::before { content: attr(data-l); font: 500 12.5px var(--body); color: var(--ink-faint); flex: none; }
  table.staff-table td.m-title { display: block; }
  table.staff-table td.m-auto { flex: 0 0 auto; }
  table.staff-table td.m-push { margin-left: auto; }
  table.staff-table td.m-wide { display: block; }
  table.staff-table td.m-order2 { order: 2; }
  table.staff-table td.m-acts { order: 3; justify-content: flex-start; margin-top: auto; }
  table.staff-table td.m-hide { display: none !important; }
  .staff-table .m-acts .btn-ghost { flex: 1 1 auto; }
  .staff-table .m-title .sc-ava.sm { width: 38px; height: 38px; border-radius: 10px; font-size: 13px; }
}

/* ============================================================
   СИСТЕМНЫЕ НАСТРОЙКИ (стили модуля вставляются в <head> позже этого файла,
   поэтому селекторы усилены префиксом body)
   ============================================================ */
@media (max-width: 1100px) {
  body .pm-sys-input, body .pm-sys-select { height: 44px; }
  body .pm-set-rail a, body .pm-acc-role { min-height: 44px; }
  body .pm-seg .sg { min-height: 44px; padding: 0 14px; font-size: 13px; }
  body .pm-acc-mass .mq { padding: 0 12px; font-size: 12.5px; }
  body .pm-sw { width: 52px; height: 32px; }
  body .pm-sw .kn { width: 26px; height: 26px; }
  body .pm-sw.on .kn { left: 22px; }
  body .pm-sw::after { content: ""; position: absolute; inset: -7px -4px; }
  body .pm-sys-cp { min-height: 44px; padding: 0 12px; font-size: 13px; }
  body .pm-acc-trash { min-width: 44px; min-height: 44px; align-items: center; justify-content: center; }
  body .pm-acc-role .sys, body .pm-acc-syslbl, body .pm-sub-badge-cur, body .pm-acc-legend, body .pm-acc-mass,
  body .pm-acc-rl .rl-desc, body .pm-sys-field > label, body .pm-sys-subhead, body .pm-sub-plan .pl,
  body .pm-sys-hook .hk-lbl, body .pm-acc-role .cnt { font-size: 12px; }
  body .pm-acc-new .pm-sys-input { height: 44px; }
}
@media (min-width: 641px) and (max-width: 900px) {
  body .pm-acc-row { flex-wrap: wrap; gap: 8px 14px; }
  body .pm-acc-rl { flex: 1 1 230px; }
  body .pm-acc-rc { margin-left: auto; }
  .pay-table td.m-big, .pay-table td.m-title { white-space: nowrap; }
  body .pm-set { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  body .pm-set-rail { position: static; flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
}
@media (max-width: 640px) {
  body .pm-set { gap: 12px; grid-template-columns: minmax(0, 1fr); }
  body .pm-set > * { min-width: 0; }
  body .pm-sys-hook .hk-url { flex: 1 1 100%; white-space: normal; overflow-wrap: anywhere; order: 2; }
  body .pm-sys-hook .pm-sys-cp { order: 3; min-height: 44px; }
  body .pm-set-rail {
    position: sticky; top: calc(50px + var(--safe-t)); z-index: 20; margin: -14px -14px 0; padding: 8px 14px;
    background: var(--bg); scrollbar-width: none; border-bottom: 1px solid var(--line);
  }
  body .pm-set-rail::-webkit-scrollbar { display: none; }
  body .pm-set-rail a { min-height: 44px; padding: 0 14px; font-size: 14px; flex: none; }
  body .pm-sys-wrap { gap: 16px; }
  body .pm-sys-sec, body .pm-acc { overflow: clip; }
  body .pm-sys-sec > .pm-sys-head { padding: 13px 14px; }
  body .pm-sys-sec > .pm-sys-body { padding: 14px; }
  body .pm-sys-input, body .pm-sys-select { height: 48px; }
  body .pm-sys-save { margin-top: 14px; }
  body .pm-sys-save > button, body .pm-sys-actions > button { width: 100%; min-height: 48px; justify-content: center; }
  body .pm-sys-hook { flex-wrap: wrap; gap: 6px 10px; }
  body .pm-sys-hook .hk-lbl { width: auto; flex: 1 1 100%; }
  body .pm-sys-kv { grid-template-columns: 1fr; gap: 2px 0; }
  body .pm-sys-kv .k { margin-top: 8px; white-space: normal; }
  body .pm-acc-pane { padding: 14px 12px; }
  body .pm-acc-rolehd > span[style*="flex:1"] { display: none; }
  body .pm-acc-rolehd #pm-acc-rolename { max-width: none !important; flex: 1 1 0; min-width: 0; }
  body .pm-acc-legend { flex-wrap: wrap; gap: 6px 12px; flex: 1 1 100%; }
  body .pm-acc-grp-head { gap: 8px 10px; }
  body .pm-acc-mass { margin-left: 0; flex: 1 1 100%; flex-wrap: wrap; }
  body .pm-acc-mass .mq { min-height: 44px; flex: 1 1 auto; }
  body .pm-acc-row { flex-wrap: wrap; gap: 8px 12px; padding: 12px; }
  body .pm-acc-rl { flex: 1 1 170px; }
  body .pm-acc-rl .rl-lbl { font-size: 14.5px; }
  body .pm-acc-rc { margin-left: auto; }
  body .pm-seg .sg { min-height: 44px; }
  body .pm-acc-savebar {
    position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); z-index: 5; flex-wrap: wrap; gap: 8px;
    margin: 14px -4px 0; padding: 10px 12px; background: var(--bg-card); border: 1px solid var(--line-bright);
    border-radius: 12px; box-shadow: 0 8px 24px rgba(16,24,40,.14);
  }
  body .pm-acc-savebar > button { flex: 1 1 100%; min-height: 48px; justify-content: center; }
  /* пока менять нечего, панель не висит поверх списка прав */
  body .pm-acc-savebar:has(> button:disabled) { position: static; border: none; box-shadow: none; padding: 14px 0 0; margin: 14px 0 0; border-top: 1px solid var(--line); border-radius: 0; }
  body .pm-acc-new #pm-acc-add { min-width: 48px; justify-content: center; }
  body .pm-sub-cur .plan-meta { margin-left: 0; text-align: left; flex: 1 1 100%; }
  body .pm-sub-plans { grid-template-columns: 1fr 1fr; }
  body .pm-sub-plan > button { min-height: 44px; }
}
