/* Листы в глубину (флаг drill_ui): лист поверх экрана со стеком уровней, чипы статуса, строки-переходы, «⋯».
   Приёмы Endless (styles.css .sheet, .chip), цвета – наши (палитра app.css и shell.css); без backdrop-filter (урок 2),
   движение – только transform и opacity (урок 4), без него при «Уменьшении движения» (урок 5). */
:root { --mg-ok: #1e7a46; --mg-ok-bg: rgba(30,122,70,.12); --mg-warn: #8a5a00; --mg-warn-bg: rgba(184,122,0,.16);
  --mg-bad-bg: rgba(179,38,30,.12); --mg-neutral-bg: rgba(27,36,48,.08); --mg-sheet-bg: var(--card); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --mg-ok: #7fd3a1; --mg-ok-bg: rgba(127,211,161,.14);
  --mg-warn: #f0c36a; --mg-warn-bg: rgba(240,195,106,.16); --mg-bad-bg: rgba(242,184,181,.14); --mg-neutral-bg: rgba(230,235,241,.1); } }
:root[data-theme="dark"] { --mg-ok: #7fd3a1; --mg-ok-bg: rgba(127,211,161,.14); --mg-warn: #f0c36a;
  --mg-warn-bg: rgba(240,195,106,.16); --mg-bad-bg: rgba(242,184,181,.14); --mg-neutral-bg: rgba(230,235,241,.1); }

/* чип: слово и цвет вместе */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.5;
  white-space: nowrap; background: var(--mg-neutral-bg); color: var(--ink); }
.chip.ok { background: var(--mg-ok-bg); color: var(--mg-ok); }
.chip.warn { background: var(--mg-warn-bg); color: var(--mg-warn); }
.chip.bad { background: var(--mg-bad-bg); color: var(--err); }

/* строка-переход: вся строка – ссылка; сумма справа крупно, дата и вторичное – мелкой серой строкой */
.drill-row { display: flex; align-items: center; gap: 10px; }
.drill-main { display: grid; gap: 2px; flex: 1; min-width: 0; }
.drill-side { display: grid; justify-items: end; gap: 4px; flex-shrink: 0; text-align: right; }
.drill-side b { font-weight: 600; white-space: nowrap; }
.drill-go { color: var(--muted); font-size: 20px; flex-shrink: 0; }
.drill .small, .drill-li .small { font-size: 13px; }
.drill-li { display: flex; align-items: stretch; gap: 4px; }
.drill-li > .item { flex: 1; min-width: 0; }
.drill-li button.link.drill-more { background: var(--card); color: var(--muted); min-width: 44px; padding: 0; border-radius: 12px; font-size: 20px;
  line-height: 1; }
.drill-list { margin-bottom: 4px; }

/* лист: поверх экрана, снизу на телефоне, по центру на широком; экран под ним не перерисовывается */
.mg-sheet { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; justify-content: center; }
.mg-sheet[hidden] { display: none; }
.mg-sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.mg-sheet-card { position: relative; width: min(560px, 100%); max-height: 88vh; max-height: 88dvh; overflow: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--bg); color: var(--ink);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); outline: none; }
@media (min-width: 861px) { .mg-sheet { align-items: center; } .mg-sheet-card { border-radius: 18px; } }
.mg-sheet.sheet-in .mg-sheet-card { animation: mg-sheet-up .24s cubic-bezier(.32,.72,0,1) backwards; }
.mg-sheet.sheet-in .mg-sheet-bg { animation: mg-sheet-fade .2s ease-out backwards; }
.mg-sheet-card.stack-in > .drill { animation: mg-stack-in .14s ease-out backwards; }
@keyframes mg-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes mg-sheet-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mg-stack-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .mg-sheet.sheet-in .mg-sheet-card, .mg-sheet.sheet-in .mg-sheet-bg,
  .mg-sheet-card.stack-in > .drill { animation: none; } }
html.mg-sheet-open { overflow: hidden; }   /* только html: overflow у body ломал прилипание шапки (sticky) – шапка уезжала вместе со страницей */

/* шапка листа: ручка (закрыть) и «‹ родитель» (уровень назад); кнопки листа – .link: заливку кнопок оболочки
   (shell.css, html.shell button:not(.link)…) не берут, вес правил ниже – выше button.link */
/* ручка прилипает к верху листа: лист прокрутили – тянуть всё равно есть за что (LT 30.11: ручка уезжала с содержимым) */
.mg-sheet button.link.mg-sheet-grip { display: block; height: 32px; padding: 0; margin: -8px -16px 0; width: calc(100% + 32px); touch-action: none; background: var(--bg); border-radius: 0;
  position: sticky; top: -8px; z-index: 2; }
.mg-sheet-grip::before { content: ""; position: absolute; left: 50%; top: 13px; width: 40px; height: 5px; margin-left: -20px;
  border-radius: 3px; background: var(--muted); opacity: .45; }
.mg-sheet button.link.mg-sheet-back { background: none; color: var(--accent); padding: 8px 0; min-height: 44px; font-size: 15px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-sheet-wait { color: var(--muted); padding: 24px 0; text-align: center; }

.drill-head { margin: 4px 0 6px; font-size: 20px; overflow-wrap: anywhere; }
.drill h4 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.drill-sum { display: grid; gap: 8px; margin: 10px 0 4px; }
.drill-stat { display: grid; gap: 2px; background: var(--card); border-radius: 12px; padding: 12px 14px; }
.drill-stat b { font-size: 20px; font-weight: 600; }
.drill-stat b.bad { color: var(--err); }
/* карточка «Долг / Переплата» – нажимается: счета и оплаты этой валюты уровнем глубже */
a.drill-stat.drill-tap { color: var(--ink); text-decoration: none; position: relative; padding-right: 32px; }
a.drill-stat.drill-tap::after { content: "›"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 20px; }
.drill-acts { display: grid; gap: 6px; margin: 8px 0; }
.mg-sheet button.link.drill-act { background: var(--card); color: var(--ink); text-align: left; min-height: 48px; border-radius: 12px; }
.mg-sheet button.link.drill-act.danger { color: var(--err); }
/* шапка приложения на время листа – шапка листа (drill.js syncHeader): над подложкой, «‹ родитель» слева */
html.shell.mg-sheet-open header.shell-top { z-index: 75; }
.mg-sheet button.link.mg-head-back, header.shell-top button.link.mg-head-back { background: none; color: var(--brand, var(--accent));
  padding: 0 4px 0 0; min-height: 44px; font-size: 16px; max-width: 38%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex-shrink: 1; }
html.shell.mg-sheet-open .shell-title { flex: 1; min-width: 0; text-overflow: ellipsis; }
/* «⋯» в шапке (п. (а)) и опасное действие отдельной группой внизу листа действий */
header.shell-top button.link.shell-more { background: none; color: var(--text, var(--ink)); font-size: 22px; min-width: 44px;
  min-height: 44px; padding: 0; margin-left: auto; }
.drill-acts.drill-danger { margin-top: 18px; }
html.mg-sheet-open header.shell-top .shell-more { visibility: hidden; }   /* лист открыт – «⋯» шапки не к нему */
/* телефон: лист кончается над нижним меню – разделы и ассистент доступны, не закрывая лист (п.1: ушёл в ассистента –
   вернулся к тем же листам); высоту меню меряет оболочка (shell.js, --shell-bottom-h) */
@media (max-width: 860px) {
  html.shell .mg-sheet { bottom: var(--shell-bottom-h, 0px); }
  /* LT iPhone 30.11: высокий лист (чат) над нижним меню уходил верхом под шапку – грип и вкладки не видны */
  html.shell .mg-sheet-card { max-height: calc(100dvh - var(--shell-bottom-h, 0px) - var(--mg-head-h, 0px) - 8px); }
  html.shell .mg-sheet-card.mg-sheet-tall { height: calc(100dvh - var(--shell-bottom-h, 0px) - var(--mg-head-h, 0px) - 8px); }
  html.shell .mg-sheet-card { padding-bottom: 16px; }
}
/* «Делёж и условия» в листе: раскрывашки – строками с ›; форма правила – строки «имя – %» */
.drill-terms details.add > summary, .drill-terms details.fix > summary { background: var(--card); border-radius: 12px;
  padding: 12px 14px; min-height: 48px; list-style: none; color: var(--ink); position: relative; padding-right: 32px; }
.drill-terms details.add > summary::after, .drill-terms details.fix > summary::after { content: "›"; position: absolute;
  right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 20px; }
.drill-terms details[open] > summary::after { content: "⌄"; }
.split-row { display: grid; gap: 6px; }
.split-who { display: grid; grid-template-columns: 1fr 96px; align-items: center; gap: 10px; color: var(--ink); font-size: 16px; }
.split-ext > summary { color: var(--accent); cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.split-example { background: var(--card); border-radius: 12px; padding: 10px 12px; }
/* человек печатает – нижнее меню спрятано (shell.js, body.shell-typing): лист опускается до низа, без щели со страницей */
@media (max-width: 860px) { html.shell body.shell-typing .mg-sheet { bottom: 0; } }
/* ассистент поверх экрана (agent_over): лист чата во весь рост, поле ввода прилипает к низу листа */
.mg-sheet-card.mg-sheet-tall { height: 88vh; height: 88dvh; display: flex; flex-direction: column; }
.mg-sheet-card.mg-sheet-tall > .mg-sheet-level { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.mg-sheet-card .drill-chat { flex: 1; display: flex; flex-direction: column; }
.mg-sheet-card .drill-chat .chat-page { min-height: 0; flex: 1; max-width: none; }
.mg-sheet-card .drill-chat .chat-form { bottom: 0; background: var(--bg); }
/* «+» в заголовке раздела (п. (б)): раскрывашка «+ …» под списком спрятана, форма – листом */
.drill-plus-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
html.shell .drill-plus-h button.link.drill-plus { min-width: 44px; min-height: 44px; padding: 0; border-radius: 50%;
  background: var(--card); color: var(--accent); font-size: 26px; line-height: 1; font-weight: 400; flex-shrink: 0; }
details.drill-plus-src:not(.drill-plus-moved) { display: none; }
.mg-sheet details.drill-plus-moved > summary { display: none; }
/* «⋯» строки денег (п. (в)): справа сверху в строке, «Исправить» – листом */
li.item.drill-rowmore-li { position: relative; padding-right: 52px; }
html.shell li.item button.link.drill-rowmore { position: absolute; right: 4px; top: 4px; min-width: 44px; min-height: 44px;
  padding: 0; background: none; color: var(--muted); font-size: 20px; }
.mg-sheet details.drill-plus-moved.fix form + form { margin-top: 18px; }
.mg-sheet details.drill-plus-moved.fix button.danger { color: var(--err); }
/* заголовок и родитель листа – только в шапке (владелец 30.11, снимки общей: «‹ клиент | компания» в шапке, а в теле
   снова компания крупно и клиент ссылкой): в оболочке шапка уже показывает уровень и родителя – тело начинается сразу с содержимого;
   чипы состояния из заголовка («в корзине», «оплачен») остаются строкой */
html.shell .mg-sheet .drill-head { font-size: 0; line-height: 0; margin: 0; }
html.shell .mg-sheet .drill-head .chip { font-size: 13px; line-height: 1.4; display: inline-block; margin: 0 0 8px; }
html.shell .mg-sheet .drill-parent { display: none; }
/* «⋯» листа записи (row_sheet, task_sheet, exchange_sheet, trash_sheet) живёт в заголовке – а заголовок в оболочке
   спрятан нулевым шрифтом; LT Mac 02.12: «⋯» не видно. Кнопка – справа сверху карточки, своим размером */
html.shell .mg-sheet .drill-head:has(.row-more) { position: relative; min-height: 36px; padding-right: 48px; }
html.shell .mg-sheet .drill-head .row-more { position: absolute; top: -4px; right: -8px; float: none; margin: 0;
  font-size: 24px; line-height: 1; padding: 6px 12px; color: var(--accent, var(--fg)); }
/* «⋯» чата: «Сводка», «Выгрузить», «Стереть» – меню справа сверху, не строкой над беседой */
details.chat-more { position: sticky; top: 0; z-index: 3; align-self: flex-end; margin: 0 0 -44px auto; width: max-content; }
details.chat-more > summary { list-style: none; min-width: 44px; min-height: 44px; display: flex; align-items: center;
  justify-content: center; font-size: 22px; color: var(--muted); cursor: pointer; }
details.chat-more > summary::-webkit-details-marker { display: none; }
details.chat-more .chat-more-list { position: absolute; right: 0; top: 44px; display: flex; flex-direction: column;
  align-items: stretch; gap: 0; min-width: 220px; background: var(--card); border-radius: 12px; padding: 6px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
details.chat-more .chat-more-list > * { display: block; padding: 12px 16px; min-height: 44px; text-align: left;
  text-decoration: none; color: var(--ink); background: none; }
/* «⋯» у правила дележа (флаг split_future): справа в строке правила */
.list li.item button.link.rule-more { float: right; min-width: 44px; min-height: 44px; margin: -10px -6px -10px 8px;
  padding: 0; background: none; color: var(--muted); font-size: 20px; }
.split-now { margin: 4px 0 10px; }
/* сворачивание разделов (флаг sections_coll, план экрана п. 5): заголовок нажимается, свёрнутое – «›», пустое – строкой */
html.sections-coll main.page .coll-h { cursor: pointer; -webkit-user-select: none; user-select: none; }
html.sections-coll main.page .coll-h:not(.coll-empty)::before { content: "⌄"; display: inline-block; width: 1.1em;
  color: var(--muted); font-weight: 400; transition: transform .15s ease; }
html.sections-coll main.page .coll-h.coll-closed::before { transform: rotate(-90deg); }
html.sections-coll main.page .coll-h.coll-empty { color: var(--muted); cursor: default; }
html.sections-coll main.page .coll-note { color: var(--muted); font-weight: 400; }
html.sections-coll main.page .coll-hidden { display: none !important; }
/* лист записи (флаг row_sheet): «⋯» – справа в шапке листа; строка денег в сделке – целиком ссылка */
.drill-head .row-more { float: right; margin: -8px -6px -8px 8px; padding: 8px 10px; font-size: 1.2em; line-height: 1; }
.list a.row-sheet { display: block; color: inherit; text-decoration: none; }
/* проводка через партнёра (флаг partner_flow): карточка – заголовок с «⋯», строки расчёта, кто кому должен */
.pflow.card { padding: 12px 14px; margin: 0 0 12px; }
.pflow-head { display: flex; align-items: center; gap: 8px; }
.pflow-head .item-title { flex: 1; min-width: 0; }
.pflow-head button.rule-more { float: none; margin: -10px -8px -10px 0; }
.pflow-lines .pflow-strong span, .pflow-lines .pflow-strong b { font-weight: 700; }
.pflow-lines .pflow-muted span { color: var(--muted); }
.pflow-gap { height: 8px; }
/* «+ Проводка»: поля обмена или проводки – по переключателю вида (без скрипта – :has) */
.pflow-form:has(input[name=kind][value=exchange]:checked) .pflow-t { display: none; }
.pflow-form:has(input[name=kind][value=transit]:checked) .pflow-x { display: none; }
/* обмен (0054, жалоба владельца 02.12): курс выдачи и фиксация – только когда выдаём не в USDT; поля курса клиента –
   каждое при своём источнике (ABCEX – курс ABCEX, «прямой» – прямой курс без «минус %») */
.pflow-form:has(select[name=dst_currency] option[value=USDT]:checked) .pflow-pay { display: none; }
.pflow-form:not(:has(select[name=client_source] option[value=abcex]:checked)) .pflow-abcex { display: none; }
.pflow-form:not(:has(select[name=client_source] option[value=direct]:checked)) .pflow-direct { display: none; }
.pflow-form:has(select[name=client_source] option[value=direct]:checked):not(:has(input[name=payout_fix][value=src]:checked)) .pflow-disc { display: none; }
.pflow-form:has(input[name=payout_fix][value=src]:checked):not(:has(select[name=dst_currency] option[value=USDT]:checked)) :is(.pflow-cs, .pflow-abcex, .pflow-direct) { display: none; }
.pflow-calc:not(:empty) { margin: 8px 0 12px; }
/* «Финансы»: долги по проводкам – строка с «⋯» */
.pflow-debt { align-items: center; }
.pflow-debt button.rule-more { float: none; margin: -10px -8px -10px 4px; }
/* действие листа – подзаголовком; заголовок (шапка) = где я, запись (жалоба владельца 02.12) */
.drill-sub { margin: 0 0 10px; color: var(--muted); font-size: 15px; font-weight: 600; }

/* ui_tidy (03.12, iPhone): строка с несколькими суммами справа – на узком экране суммы под названием, название не
   рвётся по буквам («Поставк / а оборудо / вания»); класс – для всех списков на .drill-row/.drill-side */
@media (max-width: 560px) {
  .ui-tidy .drill-row:has(.drill-side > :nth-child(3)) { flex-wrap: wrap; }
  .ui-tidy .drill-row:has(.drill-side > :nth-child(3)) .drill-main { flex: 1 1 60%; min-width: 0; }
  .ui-tidy .drill-row:has(.drill-side > :nth-child(3)) .drill-side { order: 3; flex: 1 1 100%; justify-items: start;
    text-align: left; }
}
.ui-tidy .drill-main { min-width: 0; overflow-wrap: normal; word-break: normal; }
/* шаги проводки галочками (flow_steps, владелец 03.12): строка во всю ширину, касание – галочка; 44px – палец */
.pflow-steps { margin-top: 8px; display: grid; gap: 6px; }
.pflow-step { margin: 0; }
.pflow-step .error:empty { display: none; }
.step-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 10px;
  text-align: left; background: transparent; color: var(--ink); border: 1px solid color-mix(in srgb, var(--muted) 40%, transparent);
  border-radius: 10px; font: inherit; }
.step-box { flex: none; width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--muted);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; line-height: 1; }
.step-btn.on .step-box { background: var(--accent); border-color: var(--accent); color: var(--card); }
.step-btn.on .step-text { color: var(--muted); }
.step-btn.part .step-box { border-color: var(--accent); color: var(--accent); }
.step-text { flex: 1; min-width: 0; }
.pflow-how { margin-top: 4px; }
.pflow-how > summary { color: var(--muted); cursor: pointer; list-style: none; min-height: 32px; display: flex; align-items: center; }
.pflow-how > summary::-webkit-details-marker { display: none; }
/* «+ Расход» (deal_expense): кнопка на виду, не в «⋯» (координатор 03.12); 44px – палец */
.add-btn { min-height: 44px; padding: 8px 14px; margin: 6px 0 12px; border-radius: 10px; font: inherit;
  background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.expense-form .payee-other { display: none; }
.expense-form:has(select[name=payee] option[value=other]:checked) .payee-other { display: block; }
