:root { --ink: #1b2430; --muted: #5d6b7a; --bg: #f5f7fa; --card: #fff; --accent: #1f3a5f; --err: #b3261e; }
@media (prefers-color-scheme: dark) {
  :root { --ink: #e6ebf1; --muted: #9aa7b4; --bg: #11161c; --card: #1a212a; --accent: #8fb3e0; --err: #f2b8b5; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.center .card { max-width: 380px; }
.card { background: var(--card); border-radius: 14px; padding: 20px; width: 100%;
  display: grid; gap: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
h1 { margin: 0; font-size: 22px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid rgba(127,127,127,.35); border-radius: 10px; padding: 12px; width: 100%; }
button { font: inherit; border: 0; border-radius: 10px; padding: 12px 16px; background: var(--accent);
  color: #fff; min-height: 44px; cursor: pointer; }
button.link { background: none; color: var(--accent); padding: 8px; }
.error { color: var(--err); margin: 0; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px;
  background: var(--card); position: sticky; top: 0; }
.brand { font-weight: 600; }
.page { padding: 16px; max-width: 900px; margin: 0 auto; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
a { color: var(--accent); }
.top a { text-decoration: none; }
.top nav { display: flex; gap: 8px; align-items: center; }
h1 { margin: 8px 0 12px; } h2 { margin: 24px 0 8px; font-size: 18px; } h3 { margin: 16px 0 6px; font-size: 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.btn { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 10px;
  background: var(--accent); color: #fff; text-decoration: none; }
.search { margin: 8px 0 12px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item { display: grid; gap: 2px; padding: 12px 14px; background: var(--card); border-radius: 12px; text-decoration: none;
  color: var(--ink); min-height: 44px; }
.item-title { font-weight: 500; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 8px 2px; }
.card { margin-bottom: 8px; }
.form { display: grid; gap: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0;
  border-bottom: 1px solid rgba(127,127,127,.15); }
.kv:last-child { border-bottom: 0; }
.kv b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.money { background: var(--card); border-radius: 12px; padding: 8px 14px; margin-bottom: 8px; }
.due b { color: var(--accent); } .over b { color: var(--err); }
.late { color: var(--err); }
.pre { white-space: pre-wrap; margin: 4px 0 0; }
.back { display: inline-block; padding: 8px 0; text-decoration: none; }
details.add { margin-top: 8px; }
details.add summary { cursor: pointer; color: var(--accent); padding: 10px 0; min-height: 44px; list-style: none; }
details.add[open] { background: var(--card); border-radius: 12px; padding: 0 14px 14px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 16px; align-items: center; }
legend { color: var(--muted); font-size: 14px; padding: 0; margin-bottom: 6px; }
label.inline { display: flex; align-items: center; gap: 6px; color: var(--ink); }
label.inline input { width: auto; }
button.small { min-height: 36px; padding: 6px 12px; font-size: 14px; justify-self: start; }
.task form { margin-top: 6px; }
.error:empty { display: none; }
@media (min-width: 720px) { .page { padding: 24px; } }
.pair > *, input, select, textarea { min-width: 0; }
.list a.item { color: var(--ink); }
.top nav a { padding: 8px 4px; }
details.fix summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; list-style: none; }
details.fix[open] { margin-top: 6px; display: grid; gap: 10px; }
button.danger { background: var(--err); }
button.link.danger { background: none; color: var(--err); }   /* второстепенное опасное действие – надпись, не заливка */
/* поле даты дд.мм.гггг и свой календарь (флаг date_ru): кнопка – внутри поля справа, календарь – по центру экрана
   (в узкой колонке «Дата / Оплатить до» под полем он ушёл бы за край) */
.date-field { position: relative; display: block; }
.date-field input { width: 100%; padding-right: 46px; }
.date-field .date-pick { position: absolute; top: 0; right: 0; bottom: 0; width: 44px; padding: 0; background: none;
  color: var(--accent); display: grid; place-items: center; border-radius: 0 10px 10px 0; }
.cal { position: fixed; z-index: 50; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--card);
  color: var(--ink); border-radius: 14px; box-shadow: 0 8px 32px rgba(0,0,0,.35); padding: 10px; width: 320px;
  max-width: calc(100vw - 32px); }
.cal-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.cal-nav { background: none; color: var(--accent); font-size: 26px; min-width: 44px; min-height: 44px; padding: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-dow { color: var(--muted); font-size: 12px; padding: 4px 0; }
.cal-day { background: none; color: var(--ink); padding: 0; min-height: 44px; border-radius: 8px; font-size: 17px; }
.cal-today { box-shadow: inset 0 0 0 1px var(--accent); }
.cal-sel { background: var(--accent); color: var(--card); }
/* компании клиента (флаг multi_company) */
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.row-actions button.link { min-height: 44px; padding: 0 8px 0 0; font-size: 14px; }
.similar { display: grid; gap: 6px; }
/* делёж прибыли (флаг split_view): имя партнёра под строкой доли – мельче */
label.sub { font-size: 13px; margin-top: -6px; }
/* список получателей под полем (флаг payee_suggest) */
.suggest-field { position: relative; }
.suggest { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--card); border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.22); max-height: 240px; overflow-y: auto; }
.suggest li { min-height: 44px; display: flex; align-items: center; padding: 0 12px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.suggest li:hover { background: var(--bg); }
.suggest .suggest-add { color: var(--accent); }
.suggest[hidden], .suggest li[hidden] { display: none; }
/* «Удалить клиента целиком» (флаг client_delete): окно подтверждения, смахивание строки и «⋯» в «Клиентах» */
.btn.ghost { background: none; color: var(--err); padding: 0 8px; }
dialog.sheet { border: 0; border-radius: 14px; padding: 20px; background: var(--card); color: var(--ink);
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
dialog.sheet::backdrop { background: rgba(0,0,0,.45); }
dialog.sheet h2 { margin: 0; overflow-wrap: anywhere; }
dialog.sheet p { margin: 0; }
.swipe-row { position: relative; display: flex; align-items: stretch; gap: 4px; border-radius: 12px; overflow: hidden; }
.swipe-row .item { flex: 1; min-width: 0; position: relative; z-index: 1; touch-action: pan-y; }
.swipe-row .row-more { display: none; align-items: center; justify-content: center; min-width: 44px; border-radius: 12px;
  background: var(--card); color: var(--muted); text-decoration: none; font-size: 20px; }
.swipe-row .swipe-acts { position: absolute; top: 0; right: 0; bottom: 0; display: flex; }
.swipe-row .swipe-act { min-width: 96px; padding: 0 12px; display: flex; align-items: center;
  justify-content: center; background: var(--err); color: #fff; text-decoration: none; font-weight: 500; }
.swipe-row .swipe-act.merge { background: var(--accent); }
.swipe-row:not(.swiped) .swipe-acts { visibility: hidden; }
.swipe-row.swiped .swipe-acts { visibility: visible; }
@media (hover: hover) and (pointer: fine) { .swipe-row .row-more { display: flex; } }
/* длинное имя в несколько строк – «Удалить» вровень с первой строкой, а не посреди имени (Ревизор 2) */
.head-top { align-items: flex-start; }
/* длинное слово в имени не выталкивает кнопку за край: имя сжимается и переносится, кнопка – нет */
.head-top h1 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.head-top .btn { margin-top: 6px; flex-shrink: 0; }
/* «Объединить с…» (флаг merge_menu): строка действий под именем, выбор второй карточки поиском */
.btn.quiet { background: none; color: var(--accent); padding: 0 8px; }
.head-acts { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: -4px 0 8px -8px; }
.pick-list { display: grid; gap: 6px; max-height: 40dvh; overflow: auto; }
.pick { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg); border-radius: 10px;
  color: var(--ink); min-height: 44px; cursor: pointer; }
.pick input { width: auto; flex-shrink: 0; }
.pick > span { display: grid; gap: 2px; min-width: 0; }
.pick:has(input:checked) { outline: 2px solid var(--accent); }
/* оболочка (nav_shell) красит любую кнопку в основной цвет – опасное и тихое действие должно остаться своим:
   «Удалить» в шапке и окне было тёмно-синим, как «Сохранить» (снимок iPhone, dev 29.11). Специфичность выше, чем
   у правил shell.css, без !important */
html.shell .btn.ghost { background: none; color: var(--err); }
html.shell .btn.quiet { background: none; color: var(--brand, var(--accent)); }
html.shell button.danger:not(.link):not(.shell-menu):not(.shell-tile):not(.date-pick):not(.cal-nav) {
  background: var(--err); color: var(--primary-fg, #fff); }
/* в тёмной теме --err светло-розовый: текст – тёмный --primary-fg, а не белый */
html.shell .swipe-row .swipe-act { color: var(--primary-fg, #fff); }
html.shell .swipe-row .swipe-act.merge { background: var(--primary-bg); }
/* книга фонда (флаг fund_book): одна форма «＋», поля – по выбранному виду (вид – переключатель) */
.fund-form .seg { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.fund-form .f-rate, .fund-form .f-cat, .fund-form .f-payee, .fund-form .f-sure, .fund-form .f-src { display: none; }
.fund-form:has(input[name="kind"][value="contribution"]:checked):has(select[name="currency"] option[value="USDT"]:checked) .f-src { display: flex; }
.fund-form:has(input[name="kind"][value="contribution"]:checked) .f-rate,
.fund-form:has(input[name="kind"][value="expense"]:checked) .f-rate,
.fund-form:has(input[name="kind"][value="payout"]:checked) .f-rate,
.fund-form:has(input[name="kind"]:not([value="opening"]):checked) .f-sure { display: block; }
/* валюта USDT – без курса: селектор сильнее правила вида (иначе «Курс» оставался виден при USDT – снимок iPhone 30.11) */
.fund-form:has(select[name="currency"] option[value="USDT"]:checked):has(input[name="kind"]:checked) .f-rate,
.fund-form:has(select[name="currency"] option[value="USDT"]:checked):has(input[name="kind"]:checked) .f-sure { display: none; }
.fund-form:has(input[name="kind"][value="expense"]:checked) .f-cat { display: block; }
.fund-form:has(input[name="kind"][value="payout"]:checked) .f-payee { display: block; }
.fund-form:has(input[name="kind"][value="opening"]:checked) .f-cur { display: none; }

/* общая форма (entity.js Endless, флаг ent_ui): поля сеткой, вид – переключатель, кнопки внизу; тост «… · Отменить» */
.ent-sheet { display: grid; gap: 12px; }
.ent-sheet label { display: grid; gap: 4px; color: var(--muted); }
.ent-sheet label.row { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.ent-sheet .hidden { display: none; }
.ent-sheet .seg { display: flex; flex-wrap: wrap; gap: 6px; }
html .ent-sheet .seg button, html.shell .ent-sheet .seg button { min-height: 36px; padding: 6px 12px; background: var(--card); color: var(--ink); border-radius: 18px; }
/* вид записи – переключатель: выбранный залит, остальные – тихие (снимок LT 01.12: все были залиты одинаково) */
html .ent-sheet .seg button.active, html.shell .ent-sheet .seg button.active, html.shell .ent-sheet .seg button.link.active { background: var(--accent); color: #fff; }
.ent-sheet .ent-quick { margin-top: -6px; }
/* поле даты на iOS шире контейнера (своя ширина системного поля) – по ширине листа (снимок LT iPhone 30.11) */
.ent-sheet input[type="date"] { display: block; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box;
  -webkit-appearance: none; appearance: none; text-align: left; }
html .ent-sheet .ent-quick button, html.shell .ent-sheet .ent-quick button { min-height: 32px; padding: 4px 12px; font-size: 14px; background: var(--card); color: var(--accent);
  border-radius: 16px; }
.ent-sheet .ent-bar { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.ent-sheet .ent-ro { display: grid; gap: 2px; }
.ent-sheet .ent-hint { margin-top: -6px; }
/* плашка – вне <body> (перерисовка её не уносит), шрифт body не наследует – свой тот же (снимок LT: был с засечками) */
.mg-toast, .mg-toast button { font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.mg-toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90;
  max-width: calc(100vw - 32px); background: #1c1c1e; color: #f4f3ee; border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 12px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.mg-toast[hidden] { display: none; }
.mg-toast .mg-toast-act { background: none; color: #9cc3ff; min-height: 32px; padding: 4px 6px; font-weight: 600; }

/* «‹ родитель» в шапке страницы (флаг head_back): по иерархии, на телефоне и ноутбуке; при открытом листе его место
   занимает «‹» листа (drill.js syncHeader) */
header.shell-top a.shell-back { color: var(--brand, var(--accent)); text-decoration: none; font-size: 16px; min-height: 44px;
  display: inline-flex; align-items: center; padding: 0 6px 0 0; max-width: 38%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex-shrink: 1; }
header.shell-top a.shell-back + .shell-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.mg-sheet-open header.shell-top a.shell-back { display: none; }

/* «Есть новая версия» (флаг auto_reload): если тихо перезагрузить нельзя – начат ввод */
.mg-new-v { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--shell-bottom-h, 0px) + 16px);
  z-index: 120; display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 14px;
  background: var(--card); color: var(--ink); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }

/* оплата: поле нового получателя – только при «+ Новый получатель» (флаг cp_pick) */
form:not(:has(select[name="payer"] option[value="cp"]:checked)) .payer-new { display: none; }

/* поле «Имя или название» выбора контрагента – только после «+ Новый» (стиль label выше перебивал атрибут hidden – снимок LT) */
.cp-new[hidden] { display: none !important; }

/* «Финансы» – доля к выплате (флаг payout_clear, жалоба 01.12): галочка крупно слева, строка – вся нажимается */
.pay-pick { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); cursor: pointer; }
.pay-pick input[type="checkbox"] { width: 22px; height: 22px; flex-shrink: 0; margin: 0; }
.pay-all { margin: 4px 0 8px; font-weight: 600; }

/* «Повторить» при сбое (флаг net_retry, план экрана п. 6) */
.mg-net-fail { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--shell-bottom-h, 0px) + 16px);
  z-index: 121; display: flex; gap: 10px; align-items: center; padding: 10px 12px 10px 14px; border-radius: 14px;
  background: var(--card); color: var(--ink); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px); }
.mg-net-fail button.link { background: none; color: var(--muted); min-width: 36px; }
.mg-sheet-wait button.mg-retry { display: inline; padding: 0; min-height: 0; background: none; color: var(--accent);
  text-decoration: underline; }

/* галка «так и нужно» / «Да, всё верно» – только после вопроса сервера (mg-future): label.inline задаёт display и
   перебивал атрибут hidden – галка была видна сразу (LT Mac 02.12, «+ Проводка», правка условий) */
.future-ok[hidden] { display: none !important; }
/* быстрый отклик касания (флаг tap_fast): без серой вспышки iOS и без ожидания двойного касания (зум), кнопка
   сжимается под пальцем – только transform (урок Endless 4), при «Уменьшении движения» – без сжатия */
.tap-fast a, .tap-fast button, .tap-fast summary, .tap-fast label, .tap-fast [role="button"], .tap-fast [hx-get],
.tap-fast [hx-post], .tap-fast input[type="submit"], .tap-fast select { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.tap-fast button, .tap-fast input[type="submit"], .tap-fast a.item, .tap-fast .shell-tile { transition: transform .08s ease-out; }
.tap-fast button:active, .tap-fast input[type="submit"]:active, .tap-fast .shell-tile:active { transform: scale(.97); }
.tap-fast a.item:active { transform: scale(.99); }
@media (prefers-reduced-motion: reduce) { .tap-fast button:active, .tap-fast input[type="submit"]:active, .tap-fast .shell-tile:active, .tap-fast a.item:active { transform: none; } }

