/* Базовые стили. Оформление «Минимал»: цвета, шрифты, радиусы и плотность заданы токенами ниже. */
:root {
  color-scheme: light;
  --font: "Manrope", "Segoe UI", Arial, sans-serif;
  --font-head: var(--font);
  --fs: 14px;
  --h-weight: 800;
  --h-spacing: -.02em;
  --radius: 6px;
  --radius-sm: 5px;
  --pad: 18px;
  --gap: 16px;

  --bg: #fafafa;
  --panel: #ffffff;
  --panel-2: #f6f6f6;
  --text: #111111;
  --muted: #737373;
  --line: #e8e8e8;
  --field-bg: #ffffff;
  --field-line: #dcdcdc;
  --row-hover: #f7f7f7;
  --chip-bg: #f1f1f1;
  --chip-text: #404040;

  --accent: #111111;
  --accent-hover: #333333;
  --accent-ink: #ffffff;
  --accent-soft: #efefef;
  --accent-line: #d6d6d6;

  --side-bg: #ffffff;
  --side-text: #3f3f3f;
  --side-muted: #6e6e6e;
  --side-hover: #f3f3f3;
  --side-active-bg: #111111;
  --side-active-text: #ffffff;
  --side-line: #ececec;
  --brand: #111111;

  --ok: #137a3f;
  --ok-soft: #e3f5ea;
  --warn: #8f5500;
  --warn-soft: #fff3dd;
  --danger: #c53030;
  --danger-soft: #fdeaea;

  --shadow: none;
  --shadow-pop: 0 8px 24px rgba(16, 24, 40, .14);
  --overlay: rgba(15, 18, 30, .45);
  --auth-glow: #ececec;
  --toast-bg: #111111;
  --toast-text: #ffffff;
  --viewer-bg: #525659;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs); }
a { color: var(--accent); text-decoration: none; }
h1, h2 { font-family: var(--font-head); font-weight: var(--h-weight); letter-spacing: var(--h-spacing); }
h1 { font-size: 1.6em; margin: 0; }
h2 { font-size: 1.15em; margin: 0 0 12px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Layout --- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side-bg); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--side-line); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--brand); font-family: var(--font-head); font-weight: 700; font-size: 1.3em; padding: 4px 10px 18px; }
.side a { color: var(--side-text); padding: 9px 12px; border-radius: var(--radius-sm); display: flex; gap: 10px; align-items: center; }
.side a:hover { background: var(--side-hover); }
.side a.active { background: var(--side-active-bg); color: var(--side-active-text); }
.side .sep { border-top: 1px solid var(--side-line); margin: 10px 4px; }
.side .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted); padding: 6px 12px 2px; }
.side-more summary { list-style: none; cursor: pointer; color: var(--side-text); padding: 9px 12px; border-radius: var(--radius-sm); }
.side-more summary::-webkit-details-marker { display: none; }
.side-more summary::after { content: " ▸"; color: var(--side-muted); }
.side-more[open] summary::after { content: " ▾"; }
.side-more summary:hover { background: var(--side-hover); }
.side-more a { padding-left: 22px; }
.side .bottom { margin-top: auto; font-size: 12px; color: var(--side-muted); padding: 8px 12px; }
.side .bottom a { padding: 6px 0; background: none; }
.main { padding: 24px 28px 60px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--pad); }
.card + .card { margin-top: var(--gap); }
.card.hint-card { margin-bottom: var(--gap); border-color: var(--accent-line); background: var(--accent-soft); }

/* --- Верхняя панель: переключатель страны --- */
.content { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: flex-end; align-items: center; padding: 14px 28px 0; }
.topbar + .main { padding-top: 8px; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; padding: 5px 14px; border-radius: calc(var(--radius-sm) - 2px); cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- Controls --- */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: var(--radius-sm); padding: 8px 14px; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--field-line); background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: .93em; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .tabs button:focus-visible, .side a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: inherit; border: 1px solid var(--field-line); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--field-bg); color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: .9em; color: var(--muted); }
label.f .hint { font-size: .85em; color: var(--warn); }
.grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.grid .w2 { grid-column: span 2; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: auto; }

/* --- Tables --- */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 600; font-size: .86em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:hover td { background: var(--row-hover); }
table.list tr.click { cursor: pointer; }
.table-wrap { overflow-x: auto; }

table.items { width: 100%; border-collapse: collapse; min-width: 700px; }
table.items th { font-size: .86em; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 4px; }
table.items td { padding: 3px 4px; }
table.items input, table.items select { padding: 6px 8px; }
table.items .n { width: 28px; color: var(--muted); text-align: center; }

/* --- Bits --- */
.pill { display: inline-block; font-size: .86em; padding: 2px 9px; border-radius: 99px; background: var(--chip-bg); color: var(--chip-text); white-space: nowrap; }
.pill.paid, .pill.signed { background: var(--ok-soft); color: var(--ok); }
.pill.sent { background: var(--accent-soft); color: var(--accent); }
.pill.cancelled { background: var(--danger-soft); color: var(--danger); }
select.status { width: auto; padding: 3px 8px; font-size: .9em; border-radius: 99px; border-color: transparent; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stats .card { margin-top: 0; padding: 14px 16px; }
.stat .v { font-family: var(--font-head); font-size: 1.6em; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .9em; color: var(--muted); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer; font: inherit; color: var(--muted); }
.tabs button:hover { color: var(--text); }
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 40px; }
.totals { margin-left: auto; min-width: 280px; }
.totals div { display: flex; justify-content: space-between; gap: 20px; padding: 3px 0; }
.totals .grand { font-weight: 700; font-size: 1.15em; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.words { color: var(--muted); font-size: .93em; margin-top: 6px; text-align: right; }

.menu { position: relative; display: inline-block; }
.drop { position: fixed; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: 6px; z-index: 60; min-width: 220px; max-height: 80vh; overflow: auto; font-family: var(--font); font-size: var(--fs); }
.drop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: inherit; padding: 8px 10px; border-radius: 6px; font: inherit; cursor: pointer; }
.drop button:hover { background: var(--accent-soft); }
.drop .sep { border-top: 1px solid var(--line); margin: 4px 0; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.editor.with-preview { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.preview { position: sticky; top: 16px; height: calc(100vh - 40px); padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.preview .bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.pv-pages { flex: 1; overflow: auto; background: var(--viewer-bg); padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pv-pages canvas { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.pv-pages iframe { border: 0; width: 100%; height: 100%; }
.actions-bar { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(4px); padding: 12px 0; display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: var(--gap); z-index: 5; }

.img-slot { border: 1px dashed var(--field-line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center; font-size: .9em; color: var(--muted); }
.img-slot img { max-width: 100%; max-height: 90px; object-fit: contain; background: #fff; border-radius: 6px; }
.img-slot .ph { height: 90px; display: flex; align-items: center; justify-content: center; font-size: 30px; opacity: .5; }

.notice { background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .92em; }
/* Пошаговый мастер нового документа */
.wiz-steps { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; padding: 0; }
.wiz-steps button { display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: .92em; padding: 7px 12px 7px 8px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); cursor: pointer; }
.wiz-steps button:disabled { cursor: default; opacity: .7; }
.wiz-steps .wiz-n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--chip-bg); color: var(--chip-text); font-size: 12px; font-weight: 600; }
.wiz-steps .on button { border-color: var(--accent); color: var(--text); font-weight: 600; }
.wiz-steps .on .wiz-n { background: var(--accent); color: var(--accent-ink); }
.wiz-steps .done button { color: var(--text); }
@media (max-width: 640px) {
  .wiz-steps { flex-wrap: nowrap; }
  .wiz-steps li:not(.on) .wiz-l { display: none; }        /* на телефоне — номера, название только у текущего шага */
  .wiz-steps li:not(.on) button { padding: 6px; }
  .wiz-steps li.on { flex: 1; min-width: 0; }
  .wiz-steps li.on button { width: 100%; }
  .wiz-steps li.on .wiz-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.wiz-hint { margin: 0 0 14px; color: var(--muted); max-width: 70ch; }
.wiz-nav { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.party-sum { display: grid; gap: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--field-bg); }
.party-sum > div:last-child { margin-top: 6px; }
.wiz-done h2 { margin-top: 0; }
.wiz-done .kv { display: grid; gap: 6px; }
.wiz-done .kv > div { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.editor[data-wiz="org"] [data-step]:not([data-step~="org"]) { display: none !important; }
.editor[data-wiz="to"] [data-step]:not([data-step~="to"]) { display: none !important; }
.editor[data-wiz="items"] [data-step]:not([data-step~="items"]) { display: none !important; }
.editor[data-wiz="rest"] [data-step]:not([data-step~="rest"]) { display: none !important; }
.editor[data-wiz="done"] [data-step]:not([data-step~="done"]) { display: none !important; }
.dialog { max-width: 560px; display: grid; gap: 12px; }
.dialog > * { min-width: 0; }
.dialog .btn { white-space: normal; }
.dialog h2 { margin: 0; }
.dialog p { margin: 0; }
.dialog .steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.pick-list { display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
.pick { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; text-align: left; width: 100%;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; cursor: pointer; }
.pick:hover { background: var(--row-hover); }
.rel { font-size: 12px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.sign-slots { display: grid; gap: 10px; border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px 14px; }
.sign-slots .row { flex-wrap: wrap; }
.lookup { background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.lookup-title { font-weight: 600; margin-bottom: 8px; }
.lookup-msg { font-size: .9em; margin-top: 6px; color: var(--muted); min-height: 1em; }
.lookup-msg.ok { color: var(--ok); }
.lookup-msg.bad { color: var(--danger); }

/* --- Auth --- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, var(--auth-glow) 0, transparent 60%), var(--bg); }
.auth .box { width: 100%; max-width: 400px; }
.auth .brand { color: var(--text); justify-content: center; font-size: 1.7em; padding-bottom: 6px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.auth form { display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--danger); font-size: .93em; }
.features { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: .9em; color: var(--muted); margin-top: 18px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-text); padding: 10px 18px; border-radius: var(--radius); box-shadow: var(--shadow-pop); z-index: 100; font-family: var(--font); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

.modal-bg { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); color: var(--text); border-radius: calc(var(--radius) + 2px); width: 100%; max-width: 720px; max-height: 90vh; overflow: auto; padding: 20px; }

/* --- Фильтры, выделение, архив --- */
.filters { margin-bottom: 10px; }
.filters #q { max-width: 300px; flex: 1 1 200px; }
.filters select, .filters input[type=date] { width: auto; }
.selbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--radius-sm); }
th.chk, td.chk { width: 34px; padding-right: 0; }
td.chk input, th.chk input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
table.list tfoot td { border-bottom: 0; padding-top: 12px; }
.modal.archive { max-width: 460px; display: flex; flex-direction: column; gap: 14px; }
.modal.archive h2 { margin: 0; }
.f-label { font-size: .9em; color: var(--muted); margin-bottom: 6px; }

.mobile-top { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: var(--shadow-pop); }
  /* подложка под открытым меню: нажатие мимо меню закрывает его */
  .side-backdrop { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 39; }
  .side.open + .side-backdrop { display: block; }
  .mobile-top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--side-bg); color: var(--brand); font-weight: 700; border-bottom: 1px solid var(--side-line); position: sticky; top: 0; z-index: 30; }
  .mobile-top button { background: transparent; border: 0; color: var(--brand); font-size: 22px; cursor: pointer; }
  .main { padding: 16px; }
  .topbar { padding: 12px 16px 0; }
  .editor.with-preview { grid-template-columns: 1fr; }
  .preview { position: static; height: 80vh; }
  .grid .w2 { grid-column: 1 / -1; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .v { font-size: 1.2em; }
  .head h1 { font-size: 1.35em; }
  .totals { min-width: 0; width: 100%; }
}

/* Минималистичный бренд и кнопка меню без эмодзи */
.brand::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); flex: none; }
#burger { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; }
#burger span, #burger span::before, #burger span::after { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; position: relative; content: ""; }
#burger span::before { position: absolute; top: -6px; }
#burger span::after { position: absolute; top: 6px; }
.img-slot .ph { font-size: .9em; }

/* --- Просмотр документа и миниатюры форм --- */
body.noscroll { overflow: hidden; }
.viewer-bg { padding: 24px; }
.viewer { background: var(--panel); border-radius: calc(var(--radius) + 2px); width: 100%; max-width: 900px; height: min(92vh, 1100px);
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-pop); }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.viewer-title { font-family: var(--font-head); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { flex-wrap: nowrap; }
.viewer .pv-pages { flex: 1; }
.viewer-wait { color: var(--muted); font-size: .9em; padding: 24px; text-align: center; }
.pv-pages .viewer-wait { color: #e8e8e8; }
.forms-grid { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; padding: 16px; background: var(--panel-2); }
.form-card { border: 2px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px; font: inherit; color: var(--text); text-align: left; }
.form-card:hover { border-color: var(--field-line); }
.form-card.on { border-color: var(--accent); }
.form-thumb { aspect-ratio: 1 / 1.3; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.form-thumb canvas { width: 100% !important; height: auto; display: block; }
.form-card span { font-size: .88em; line-height: 1.3; }

/* --- Нижняя панель (только телефон) --- */
.tabbar { display: none; }

@media (max-width: 640px) {
  /* поля от 16px — iOS не увеличивает страницу при вводе */
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .hide-mobile { display: none !important; }
  .main { padding: 12px 12px calc(88px + env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 12px 0; }
  .head { margin-bottom: 12px; }
  .head .row .btn { flex: 1; justify-content: center; }
  .card { padding: 14px; }
  .filters > * { flex: 1 1 100%; max-width: none !important; }

  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px 7px;
    font: inherit; font-size: 11px; color: var(--muted); background: none; border: 0; cursor: pointer; text-decoration: none; }
  .tabbar .on { color: var(--text); font-weight: 700; }
  .ti { width: 22px; height: 22px; background: currentColor;
    -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; }
  .ti-archive { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='5' rx='1'/%3E%3Cpath d='M5 9v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9M10 13h4'/%3E%3C/svg%3E"); }
  .ti-plus { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='4'/%3E%3Cpath d='M12 8v8M8 12h8'/%3E%3C/svg%3E"); }
  .ti-people { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='8' r='3.5'/%3E%3Cpath d='M2.5 20c.8-3.6 3.4-5.5 6.5-5.5s5.7 1.9 6.5 5.5M16 4.8a3.5 3.5 0 0 1 0 6.4M18 14.8c1.9.7 3.1 2.4 3.5 5.2'/%3E%3C/svg%3E"); }
  .ti-menu { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E"); }
  .actions-bar { bottom: calc(58px + env(safe-area-inset-bottom)); margin-left: -12px; margin-right: -12px; padding: 10px 12px; }
  .actions-bar .btn { flex: 1 1 calc(25% - 8px); justify-content: center; padding-left: 6px; padding-right: 6px; }
  .actions-bar .btn.primary { flex-basis: 100%; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* архив: карточки вместо таблицы */
  table.doclist, table.doclist tbody { display: block; }
  table.doclist thead { display: none; }
  table.doclist tr.click { display: grid; grid-template-columns: 26px 1fr auto; grid-template-areas:
      "chk doc sum" "chk party party" "chk date status" "chk act act";
    gap: 4px 8px; padding: 12px 4px; border-bottom: 1px solid var(--line); align-items: center; }
  table.doclist tr.click td { padding: 0; border: 0; background: none !important; }
  table.doclist .c-chk { grid-area: chk; align-self: start; padding-top: 3px; }
  table.doclist .c-doc { grid-area: doc; }
  table.doclist .c-sum { grid-area: sum; font-weight: 700; }
  table.doclist .c-party { grid-area: party; }
  table.doclist .c-date { grid-area: date; color: var(--muted); font-size: .9em; }
  table.doclist .c-status { grid-area: status; justify-self: end; }
  table.doclist .c-act { grid-area: act; text-align: left; display: flex; gap: 8px; }
  table.doclist .c-act .btn { flex: 1; justify-content: center; }
  table.doclist tfoot, table.doclist tfoot tr { display: block; }
  table.doclist tfoot td { display: inline-block; padding: 10px 4px 0; }

  /* редактор: позиции и строки карточками */
  table.items { min-width: 0 !important; display: block; }
  table.items thead { display: none; }
  table.items tbody { display: block; }
  table.items tr[data-i] { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; position: relative;
    padding: 12px 36px 12px 10px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
  table.items tr[data-i] td { padding: 0; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  table.items tr[data-i] td[data-label]::before { content: attr(data-label); font-size: 12px; color: var(--muted); }
  table.items tr[data-i] td.cell-name { grid-column: 1 / -1; }
  table.items tr[data-i] td.n { position: absolute; top: 10px; right: 10px; display: none; }
  table.items tr[data-i] td:last-child { position: absolute; top: 4px; right: 2px; }
  table.items tr[data-i] td.num { justify-content: flex-end; font-weight: 700; }

  /* предпросмотр в редакторе и окно просмотра — на весь экран */
  .preview { position: fixed !important; inset: 0; z-index: 45; height: auto !important; border-radius: 0; border: 0; }
  .viewer-bg { padding: 0; }
  .viewer { max-width: none; height: 100%; border-radius: 0; }
  .viewer-bar { padding: 8px 10px calc(8px) 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .viewer-actions .btn:not([data-close]) { padding: 0 10px; }
  .forms-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
  .modal { max-height: 100%; }
}

/* --- Профиль --- */
.danger-zone { border-color: var(--danger-soft); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #a82828; }
input:disabled { background: var(--panel-2); color: var(--muted); }

/* единица и её код ОКЕИ в одной ячейке: «шт» + «796»; можно вписать свои */
.unit-cell{display:flex;gap:4px;align-items:center}
.unit-cell .unit-in{min-width:0;flex:1 1 70px}
.unit-cell .okei-in{width:52px;flex:0 0 52px;text-align:center}
