/* PDF Worker. Рабочий стол из листов: страницы лежат на сером «столе», у каждой — метка файла, откуда она взята. */
:root {
  --desk: #e6eaee;
  --panel: #ffffff;
  --paper: #ffffff;
  --ink: #17202b;
  --muted: #5b6876;
  --line: #d3d9df;
  --hover: #f1f4f7;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --accent-soft: #d5efe8;
  --danger: #b93a26;
  --shadow: 0 1px 2px rgba(23, 32, 43, .12), 0 4px 14px -6px rgba(23, 32, 43, .25);
  --radius: 10px;
  --tile: 150px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #12161b;
    --panel: #1b2128;
    --paper: #f4f4f1;
    --ink: #e4e9ee;
    --muted: #93a0ad;
    --line: #2e3740;
    --hover: #232a32;
    --accent: #2fb394;
    --accent-ink: #06231c;
    --accent-soft: #163a32;
    --danger: #ef7a63;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 6px 18px -8px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--desk); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20; height: 56px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 17px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand svg { width: 28px; height: 28px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--hover); }
a.btn { color: inherit; text-decoration: none; }
a.btn.primary { color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { width: 38px; padding: 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--hover); }

/* ---------- Раскладка ---------- */
.layout { position: relative; display: grid; grid-template-columns: var(--side, 320px) 1fr; height: calc(100vh - 56px); }
/* Край панели файлов: тянется мышью или стрелками */
.splitter { position: absolute; z-index: 15; top: 0; bottom: 0; left: calc(var(--side, 320px) - 4px); width: 9px; cursor: col-resize; touch-action: none; }
.splitter::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 3px; background: transparent; transition: background .12s; }
.splitter:hover::after, .splitter.active::after, .splitter:focus-visible::after { background: var(--accent); }
.splitter:focus-visible { outline: none; }
.sources { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 14px 12px 40px; }
.workspace { overflow-y: auto; position: relative; }

/* ---------- Файлы слева ---------- */
.sources-head { display: flex; align-items: center; gap: 2px; margin: 0 0 8px; }
.sources h2 { flex: 1; margin: 2px 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.btn.on { background: var(--accent-soft); color: var(--accent); }
.src { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--panel); }
.src-head { display: flex; align-items: center; gap: 10px; padding: 10px; cursor: pointer; }
.src-head:hover { background: var(--hover); border-radius: var(--radius); }
.src-name { flex: 1; min-width: 0; }
.src-name b { display: block; font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-name span { font-size: 12.5px; color: var(--muted); }
.chev { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform .15s; }
.src.open .chev { transform: rotate(90deg); }
.src-body { padding: 0 10px 10px; }
.src-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.src-hint { font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
.src-pages { display: grid; gap: 8px; }
/* Колонки задаёт app.js: сеткой — N в ряд, лентой — одна колонка в долю панели */
.src-pages.list { gap: 14px; justify-content: center; }
.sources-empty { color: var(--muted); font-size: 14px; margin: 6px 4px; }

/* Метка файла: буква и цвет — одни и те же у файла слева и у его страниц в документе */
.tag {
  display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 6px;
  font-size: 12.5px; font-weight: 800; color: #fff; background: var(--c, #64748b);
}

/* ---------- Документ ---------- */
.doc-bar {
  position: sticky; top: 0; z-index: 10; min-height: 56px; padding: 10px 20px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--desk) 88%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid transparent;
}
.doc-bar.sel { background: var(--accent-soft); border-bottom-color: var(--line); }
.doc-title { font-weight: 700; margin-right: auto; }
.doc-title span { color: var(--muted); font-weight: 500; }
.doc-hint { margin-left: 12px; color: var(--muted); font-weight: 500; font-size: 13px; }
.zoom { display: flex; gap: 4px; margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--line); }
.doc { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(var(--tile), 100%), 1fr)); gap: 22px 18px; padding: 8px 20px 120px; min-height: calc(100% - 56px); align-content: start; }

/* ---------- Лист (страница) ---------- */
.tile { position: relative; user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: grab; }
.doc .tile { cursor: zoom-in; }
.doc.one { justify-content: safe center; } /* safe: широкий лист не уезжает за левый край */
.sheet {
  position: relative; width: 100%; aspect-ratio: 1 / 1.1; border-radius: 6px;
  outline: 2px solid transparent; outline-offset: 3px;
}
.sheet > .pg {
  position: absolute; left: 50%; top: 50%; background: var(--paper); box-shadow: var(--shadow);
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); transition: transform .18s ease;
}
.pg > img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.pg { container-type: size; overflow: hidden; }  /* метки меряют шрифт в cqh — долях высоты листа */
.tile.selected .sheet { outline-color: var(--accent); background: var(--accent-soft); }
.tile:hover .sheet { background: var(--hover); }
.tile.selected:hover .sheet { background: var(--accent-soft); }
.tile.dragging { opacity: .35; }
.cap { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.cap .tag { width: 18px; height: 18px; font-size: 11px; border-radius: 4px; }
.cap b { color: var(--ink); font-weight: 650; }
.src-pages .cap { margin-top: 3px; font-size: 12px; }

/* Кнопки на листе — при наведении (на телефоне — у выделенного листа) */
.tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.tile:hover .tools, .tile.selected .tools, .tile:focus-within .tools { opacity: 1; }
.tools button {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow);
}
.tools button:hover { background: var(--hover); }
.tools svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tools .del { color: var(--danger); }

/* Галочка выделения в углу листа: видна при наведении, у выделенных и пока что-то выделено */
.pick {
  position: absolute; top: 6px; left: 6px; width: 28px; height: 28px; padding: 0; display: grid; place-items: center;
  border: 2px solid var(--line); border-radius: 50%; background: var(--panel); color: transparent; cursor: pointer;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .12s;
}
.pick svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.pick:hover { border-color: var(--accent); color: var(--accent); }
.tile:hover .pick, .tile:focus-within .pick, .doc.picking .pick, .tile.selected .pick { opacity: 1; }
.tile.selected .pick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Куда упадут перетаскиваемые листы */
.marker { position: absolute; z-index: 5; width: 4px; border-radius: 2px; background: var(--accent); pointer-events: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.drag-ghost {
  position: fixed; z-index: 50; pointer-events: none; width: 90px; transform: translate(-50%, -60%) rotate(-4deg);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .3));
}
.drag-ghost img, .drag-ghost .blank { display: block; width: 100%; background: #fff; border-radius: 3px; }
.drag-ghost .count {
  position: absolute; top: -10px; right: -10px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px;
}

/* ---------- Пустой документ ---------- */
.empty {
  grid-column: 1 / -1; margin: 40px auto; max-width: 560px; padding: 48px 32px; text-align: center;
  border: 2px dashed var(--line); border-radius: 16px; background: var(--panel);
}
.empty h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.015em; }
.empty p { margin: 0 0 20px; color: var(--muted); }
.empty ul { text-align: left; margin: 24px auto 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; color: var(--muted); max-width: 420px; }
.empty li::before { content: "—"; margin-right: 8px; color: var(--accent); }

.drop-veil {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 22%, transparent); border: 4px dashed var(--accent);
}
.drop-veil p { padding: 14px 22px; border-radius: 12px; background: var(--panel); font-weight: 700; box-shadow: var(--shadow); }

/* ---------- Окна ---------- */
.modal-back { position: fixed; inset: 0; z-index: 55; background: rgba(10, 14, 18, .55); display: grid; place-items: center; padding: 16px; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal h2 { margin: 0 0 16px; font-size: 19px; }
.field { margin-bottom: 16px; }
.field > label:not(.choice), .field > .lbl { display: block; font-weight: 650; margin-bottom: 6px; font-size: 14px; }
.input { width: 100%; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--desk); }
.choice { display: flex; align-items: flex-start; gap: 10px; padding: 6px 10px; line-height: 1.35; border-radius: 8px; cursor: pointer; }
.choice:hover { background: var(--hover); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice small { display: block; color: var(--muted); font-size: 13px; }
.field-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.extras { border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; }
.extras > summary { padding: 10px 2px; font-weight: 650; font-size: 14px; cursor: pointer; }
.extras[open] { padding-bottom: 10px; }
.extras.off { opacity: .55; }
.extra-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 8px 34px; }
.extra-row .input { width: auto; flex: 1 1 140px; min-height: 32px; }
.extra-row .input.small, .extra-row .input.num { flex: 0 1 auto; }
.extra-row .muted { color: var(--muted); font-size: 13px; }
.choice .num { width: 64px; min-height: 30px; margin: 0 4px; padding: 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.progress { height: 8px; border-radius: 4px; background: var(--hover); overflow: hidden; margin: 10px 0 6px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress.busy i { width: 35% !important; animation: slide 1.2s ease-in-out infinite; }

/* Кнопка «Задачи» и её панель */
#btn-tasks { position: relative; }
.tasks-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; line-height: 20px; text-align: center; }
#btn-tasks.busy svg { color: var(--accent); }
.tasks-pop { position: fixed; top: 60px; right: 16px; z-index: 60; width: min(420px, calc(100% - 32px)); max-height: calc(100vh - 80px);
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.tasks-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--line); font-size: 16px; }
.tasks-body { overflow: auto; padding: 4px 18px 14px; }
.tasks-h { margin: 14px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.tasks-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task { display: flex; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--hover); }
.task-ic { flex: none; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.task-ic svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.task.error .task-ic { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.task.queued .task-ic { background: var(--panel); color: var(--muted); }
.task-body { flex: 1; min-width: 0; }
.task-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.task-head b { font-size: 14.5px; }
.task-dl { font-weight: 650; font-size: 14px; color: var(--accent); white-space: nowrap; }
.task-sub { font-size: 13px; color: var(--ink); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-line { font-size: 13px; color: var(--muted); margin-top: 2px; }
.task .progress { margin: 8px 0 2px; height: 6px; }
.task-ok { color: var(--accent); }
.task-err { color: var(--danger); font-weight: 600; }
.tasks-empty { margin: 14px 0 4px; color: var(--muted); }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.stage { color: var(--muted); font-size: 14px; }
.modal.charge { width: min(440px, 100%); }
/* Сравнение версий */
.cmp-view { position: fixed; inset: 0; z-index: 46; display: grid; grid-template-rows: auto auto auto 1fr; background: var(--desk); color: var(--ink); }
.cmp-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.cmp-title { flex: 1; min-width: 220px; }
.cmp-title span { color: var(--muted); }
.cmp-stats { font-weight: 650; }
.cmp-nav { display: flex; align-items: center; gap: 6px; }
.cmp-count { min-width: 60px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }
.cmp-warn { padding: 8px 16px; background: color-mix(in srgb, #d97706 16%, transparent); color: #b45309; font-size: 14px; }
.cmp-legend { display: flex; gap: 14px; padding: 8px 16px; font-size: 13px; color: var(--muted); }
.cmp-scroll { overflow-y: auto; padding: 18px 16px 80px; }
.cmp-text { max-width: 860px; margin: 0 auto; padding: 28px 34px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
  font: 16px/1.75 Georgia, "Times New Roman", serif; }
.cmp-eq { color: var(--muted); }
.cmp-view del, .cmp-legend del { background: color-mix(in srgb, #dc2626 16%, transparent); color: #b91c1c; text-decoration: line-through; padding: 0 2px; border-radius: 3px; }
.cmp-view ins, .cmp-legend ins { background: color-mix(in srgb, #16a34a 18%, transparent); color: #15803d; text-decoration: none; padding: 0 2px; border-radius: 3px; }
.cmp-chg { border-radius: 4px; }
.cmp-chg.cur { outline: 2px solid var(--accent); outline-offset: 2px; }
.cmp-page { display: inline-block; margin-right: 4px; padding: 0 5px; border-radius: 4px; background: var(--hover); color: var(--muted);
  font: 600 11px/18px system-ui, sans-serif; vertical-align: 2px; }
.cmp-more { border: 0; background: none; color: var(--accent); font: inherit; font-style: italic; cursor: pointer; padding: 0 2px; }
/* Меню «Инструменты» */
.menu { position: fixed; z-index: 30; width: 330px; padding: 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.menu-item { display: block; width: 100%; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); text-align: left; cursor: pointer; font: inherit; }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); }
.menu-item b { display: block; font-weight: 650; }
.menu-item small { display: block; color: var(--muted); font-size: 12.5px; }
/* Выпрямить и обрезать: страница с четырьмя углами */
.modal.straighten { width: min(620px, 100%); }
.sq-stage { position: relative; width: min(100%, calc((100vh - 360px) * 0.72)); margin: 0 auto 10px; background: #fff; touch-action: none; user-select: none; }
.sq-stage img { display: block; width: 100%; height: 100%; pointer-events: none; }
.sq-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sq-handle { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: #2fb394; border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4); cursor: grab; touch-action: none; }
.sq-handle:active { cursor: grabbing; }
.charge-sum { margin: 0 0 10px; font-size: 16px; }
.charge-sum b { font-size: 30px; color: var(--accent); letter-spacing: -.02em; }
.charge-note { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.result { padding: 14px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 12px; }
.result b { display: block; word-break: break-all; }
.error-box { padding: 12px 14px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 600; margin-bottom: 12px; }

/* Крупный просмотр */
.viewer { position: fixed; inset: 0; z-index: 45; background: rgba(10, 14, 18, .88); display: grid; grid-template-rows: auto 1fr; color: #fff; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.viewer-bar .grow { flex: 1; font-weight: 650; }
.viewer-bar .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .2); color: #fff; }
.viewer-stage { position: relative; overflow: hidden; display: grid; place-items: center; padding: 0 64px 24px; }
.viewer-stage .pg { position: absolute; left: 50%; top: 50%; background: #fff; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); transition: transform .18s; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; font-size: 26px; }
.viewer-nav:hover { background: rgba(255, 255, 255, .22); }
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 70; display: grid; gap: 8px; width: min(480px, calc(100% - 32px)); }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--panel); box-shadow: var(--shadow); font-weight: 550; }
.toast.err { background: var(--danger); color: #fff; }

.kbd-help { font-size: 12.5px; color: var(--muted); margin: 18px 4px 0; line-height: 1.7; }
kbd { padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; font: 12px ui-monospace, monospace; background: var(--desk); }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); padding: 26px 24px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.login-card .brand { font-size: 19px; gap: 10px; margin-bottom: 22px; }
.login-card .btn { width: 100%; }
.login-about { margin: 14px 0 0; text-align: center; font-size: 14px; }
.login-about a { color: var(--muted); }
.login-error { margin: -4px 0 14px; color: var(--danger); font-weight: 600; font-size: 14px; }

/* ---------- Телефон и узкие окна ---------- */
@media (max-width: 760px) {
  .top { padding: 0 12px; }
  .brand { font-size: 0; gap: 0; }
  .btn span { display: none; }
  .btn:not(.icon) { padding: 0 11px; }
  .layout { display: block; height: auto; }
  .splitter { display: none; }
  .doc-hint { display: none; }
  .pick { opacity: 1; }
  .sources { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; padding: 12px; }
  .workspace { overflow: visible; }
  .doc-bar { top: 56px; padding: 10px 12px; }
  .doc { padding: 8px 12px 100px; gap: 18px 12px; }
  .tools { opacity: 1; }
  .tile:not(.selected) .tools { display: none; }
  .viewer-stage { padding: 0 8px 16px; }
  .viewer-nav { width: 36px; }
  .kbd-help { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet > .pg, .viewer-stage .pg, .chev, .progress i { transition: none; }
  .progress.busy i { animation: none; width: 100% !important; opacity: .5; }
}

/* ---------- Регистрация ---------- */
.login-card.wide { width: min(440px, 100%); }
.login-card a.brand { text-decoration: none; }
.login-title { margin: 0 0 10px; font-size: 21px; }
.login-note { margin: 0 0 16px; font-size: 14px; color: var(--muted); }
.login-note b { color: var(--ink); }
.login-note.small { font-size: 13px; margin-top: 10px; }
.login-wait { padding: 14px; border-radius: 10px; background: var(--accent-soft); font-weight: 600; }
.choice.agree { padding: 6px 0; font-size: 14px; }
.login-card a:not(.btn):not(.brand) { color: var(--accent); }

/* ---------- Админка ---------- */
.admin { max-width: 1440px; margin: 0 auto; padding: 24px 20px 60px; }
.admin h1 { margin: 0 0 16px; font-size: 24px; }
.admin h2 { margin: 32px 0 12px; font-size: 18px; }
.admin-warn { padding: 12px 14px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 600; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.admin-stats .stat { padding: 14px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.admin-stats .stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.admin-stats .stat span { color: var(--muted); font-size: 13px; }
.admin-tools { margin-bottom: 10px; max-width: 320px; }
.admin-add { margin: 0 0 22px; padding: 14px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.admin-add h2 { margin: 0 0 10px; font-size: 16px; }
.admin-add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-add-row .input { width: auto; flex: 1 1 160px; }
.admin-add-row select.input { flex: 0 1 160px; }
.admin-add small { display: block; margin-top: 8px; color: var(--muted); font-size: 13px; }
.input.small { min-height: 30px; padding: 0 6px; width: auto; }
.admin-table td.actions { display: flex; gap: 6px; }
.admin-price { margin: 0 0 22px; padding: 14px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); max-width: 560px; }
.admin-price label { display: block; font-weight: 650; margin-bottom: 8px; }
.admin-price-row { display: flex; gap: 8px; }
.admin-price .num { width: 140px; }
.admin-price small { display: block; margin-top: 8px; color: var(--muted); font-size: 13px; }
.admin-price .choice { padding: 0 0 8px; font-weight: 650; }
.admin-price .choice small { font-weight: 400; margin-top: 2px; }
.admin-unit { align-self: center; color: var(--muted); font-size: 13.5px; }
.admin-kassa { max-width: 900px; }
.admin-kassa h2 { margin: 0 0 12px; font-size: 16px; }
.kassa-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; margin-bottom: 12px; }
.kassa-grid > label:not(.choice) { display: flex; flex-direction: column; gap: 4px; font-weight: 650; font-size: 14px; }
.kassa-grid label small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.kassa-grid .choice { align-self: end; }
.kassa-webhook { margin-bottom: 12px; font-size: 13.5px; color: var(--muted); }
.kassa-webhook code { padding: 2px 6px; border-radius: 6px; background: var(--hover); color: var(--ink); word-break: break-all; }
.kassa-state { align-self: center; font-size: 13.5px; }
.kassa-state.ok { color: var(--accent); }
.kassa-state.off { color: var(--danger); }
/* Кабинет */
.account { max-width: 980px; }
.acc-card { margin: 0 0 18px; padding: 16px 18px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.acc-card h2 { margin: 0 0 10px; font-size: 17px; }
.acc-dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; margin: 0; }
.acc-dl dt { color: var(--muted); }
.acc-dl dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.acc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; margin-bottom: 10px; }
.acc-grid label { display: flex; flex-direction: column; gap: 4px; font-weight: 650; font-size: 14px; }
.np-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.muted.small { font-size: 13px; color: var(--muted); }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table th { color: var(--muted); font-weight: 650; font-size: 13px; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table tr.blocked td { opacity: .6; }
.admin-table tr.blocked td:last-child { opacity: 1; }
.admin-table .muted { color: var(--muted); }
.admin-table .st-failed { color: var(--danger); }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 650; background: var(--hover); color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--accent); margin-left: 0; }
.badge.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

/* ---------- Редактор страницы ---------- */
.marks, .runs, .fields { position: absolute; inset: 0; }
.marks { pointer-events: none; }
.mk { position: absolute; box-sizing: border-box; }
.mk-text { white-space: pre; line-height: 1.2; }
.mk-img img { width: 100%; height: 100%; display: block; pointer-events: none; }
.mk-rect { border: solid #dc2626; }
.mk-hl { opacity: .35; }
.mk-redact { background: #000; }
.mk-edit { display: flex; align-items: flex-end; overflow: visible; outline: .12em solid transparent; }
.mk-edit span { white-space: nowrap; line-height: 1; padding-bottom: 0.08em; }
.mk-arrow { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.mk.sel { outline: 2px dashed #2fb394; outline-offset: 2px; }
.mk .handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 3px;
  background: #2fb394; border: 2px solid #fff; cursor: nwse-resize; }
.run { position: absolute; border: 1px dashed rgba(14, 124, 102, .7); background: rgba(47, 179, 148, .08); cursor: text; border-radius: 2px; }
.run:hover { background: rgba(47, 179, 148, .22); }
.ed-ghost { position: absolute; pointer-events: none; }
.ed-ghost.white { background: rgba(255, 255, 255, .9); outline: 1px dashed #64748b; }
.ed-ghost.hl { background: rgba(255, 230, 0, .4); }
.ed-ghost.rect { border: 2px solid #dc2626; }
.ed-ghost.redact { background: rgba(0, 0, 0, .75); }
.ed-ghost.arrow { border: 1px dashed #dc2626; }
.ed-input { position: absolute; z-index: 3; margin: 0; padding: 0 2px; border: 1px solid #2fb394; outline: none; background: rgba(255, 255, 255, .92);
  line-height: 1.2; resize: none; overflow: hidden; white-space: pre; min-width: 60px; box-shadow: 0 2px 10px rgba(0, 0, 0, .25); }
.pdf-field { position: absolute; margin: 0; padding: 0 3px; border: 1px solid rgba(37, 99, 235, .55); background: rgba(219, 234, 254, .55);
  color: #111; border-radius: 2px; font-family: Arial, sans-serif; resize: none; }
.pdf-field:focus { outline: 2px solid #2563eb; background: rgba(255, 255, 255, .95); }
.pdf-field.check { accent-color: #2563eb; }
.modal.sign { width: min(720px, 100%); }
.modal .lbl { display: block; font-weight: 650; font-size: 14px; margin: 6px 0; }
.sign-pad { display: block; width: 100%; aspect-ratio: 3 / 1; border: 1px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; }
.sign-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 4px; }
.sign-row .grow { flex: 1; }
.sign-recent { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.sign-thumb { width: 110px; height: 54px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.sign-thumb img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Редактор документа с лентой, как в Word ---------- */
.studio { position: fixed; inset: 0; z-index: 45; display: grid; grid-template-rows: auto auto 1fr auto; background: var(--desk); color: var(--ink); }
.rb-top { display: flex; align-items: flex-end; gap: 14px; min-height: 46px; padding: 6px 12px 0; background: var(--accent); color: #fff; }
.rb-back { display: inline-flex; align-items: center; gap: 4px; align-self: center; margin-bottom: 6px; height: 32px; padding: 0 10px 0 4px;
  border: 0; border-radius: 6px; background: rgba(255, 255, 255, .14); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.rb-back:hover { background: rgba(255, 255, 255, .24); }
.rb-back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.rb-tabs { display: flex; gap: 2px; }
.rb-tab { padding: 9px 18px; border: 0; border-radius: 8px 8px 0 0; background: transparent; color: rgba(255, 255, 255, .88); font: inherit; font-weight: 600; cursor: pointer; }
.rb-tab:hover { background: rgba(255, 255, 255, .14); }
.rb-tab.on { background: var(--panel); color: var(--ink); }
.rb-right { display: flex; align-items: center; gap: 4px; margin-left: auto; align-self: center; margin-bottom: 6px; }
.rb-right .btn.primary { background: #fff; color: var(--accent); border-color: #fff; margin-left: 6px; }
.rb-icon { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.rb-icon:hover:not(:disabled) { background: rgba(255, 255, 255, .16); }
.rb-icon:disabled { opacity: .4; cursor: default; }
.rb-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rb-ribbon { display: flex; align-items: stretch; min-height: 96px; padding: 6px 4px 4px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.rb-group { display: flex; flex-direction: column; padding: 0 10px; border-right: 1px solid var(--line); flex: none; }
.rb-items { display: flex; align-items: center; gap: 2px; flex: 1; }
.rb-label { padding-top: 3px; text-align: center; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.rb-big { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 66px; height: 66px; padding: 4px 8px;
  border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink); font: inherit; font-size: 12.5px; line-height: 1.15; cursor: pointer; }
.rb-big svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rb-big:hover:not(:disabled) { background: var(--hover); }
.rb-big.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.rb-big:disabled { opacity: .4; cursor: default; }
.rb-big.busy { cursor: progress; color: var(--accent); }
.rb-col { display: flex; flex-direction: column; gap: 6px; }
.rb-row { display: flex; align-items: center; gap: 4px; }
.rb-select { height: 30px; min-width: 160px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.rb-select.narrow { min-width: 66px; }
.rb-small { width: 32px; height: 30px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; font-weight: 700; font-size: 15px; }
.rb-small.i { font-style: italic; font-family: Georgia, serif; }
.rb-small.u { text-decoration: underline; }
.rb-small:hover { background: var(--hover); }
.rb-small.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.swatch { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.rb-color { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.rb-library { display: flex; align-items: center; gap: 8px; max-width: 470px; overflow-x: auto; padding: 6px 4px; }
.rb-empty { max-width: 210px; font-size: 12.5px; color: var(--muted); }
.lib-item { position: relative; flex: none; }
.lib-thumb { display: block; width: 96px; height: 56px; padding: 4px; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; }
.lib-thumb:hover { border-color: var(--accent); }
.lib-thumb img { width: 100%; height: 100%; object-fit: contain; }
.lib-del { position: absolute; top: -7px; right: -7px; display: none; place-items: center; width: 20px; height: 20px; padding: 0;
  border: 0; border-radius: 50%; background: var(--danger); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }
.lib-item:hover .lib-del, .lib-del:focus-visible { display: grid; }
.rb-note { align-self: center; max-width: 480px; padding: 0 14px; font-size: 13px; color: var(--muted); }
.st-body { display: grid; grid-template-columns: 140px 1fr; min-height: 0; }
.st-thumbs { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 14px 8px 40px; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line); }
.st-thumb { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
.st-thumb-img { position: relative; display: block; overflow: hidden; background: #fff; box-shadow: var(--shadow); outline: 2px solid transparent; outline-offset: 2px; container-type: size; }
.st-thumb-img img { display: block; width: 100%; height: 100%; object-fit: fill; }
.st-thumb.on .st-thumb-img { outline-color: var(--accent); }
.st-thumb.on { color: var(--accent); font-weight: 700; }
.pg-mini { position: absolute; inset: 0; pointer-events: none; }
.st-main { overflow: auto; padding: 8px 32px 80px; }
.st-pages { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: max-content; }
.st-page-num { margin-top: 14px; font-size: 12px; color: var(--muted); }
.st-page { position: relative; flex: none; }
.st-page .pg { position: absolute; left: 50%; top: 50%; background: #fff; box-shadow: var(--shadow); transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); }
.st-page .pg .ov { position: absolute; inset: 0; }
.studio .marks { pointer-events: auto; }
.studio .marks .mk { cursor: move; }
.studio .marks .mk-arrow { pointer-events: none; }
.studio .marks .mk-arrow * { pointer-events: stroke; cursor: move; }
.pg.tool-text { cursor: text; }
.pg.tool-white, .pg.tool-hl, .pg.tool-rect, .pg.tool-arrow, .pg.tool-redact { cursor: crosshair; }
.st-status { display: flex; align-items: center; gap: 16px; height: 34px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.st-pageno { white-space: nowrap; font-weight: 600; color: var(--ink); }
.st-hint { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-zoom { display: flex; align-items: center; gap: 4px; }
.st-zoom .rb-icon.small { width: auto; min-width: 26px; height: 26px; padding: 0 6px; color: var(--ink); font-weight: 700; }
.st-zoom .rb-icon.small.wide { font-weight: 600; font-size: 12.5px; }
.st-zoom .rb-icon.small:hover { background: var(--hover); }
.st-zoom-range { width: 140px; accent-color: var(--accent); }
.st-zoom-val { min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.sign-keep { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.sign-keep .input { flex: 1; min-width: 160px; min-height: 34px; }
@media (max-width: 760px) {
  .st-body { grid-template-columns: 1fr; }
  .st-thumbs, .st-hint, .rb-back span, .st-zoom .wide { display: none; }
  .rb-tab { padding: 9px 10px; }
  .rb-big { min-width: 56px; font-size: 11px; }
  .st-main { padding: 8px 8px 60px; }
}

/* Графики в админке: цвет столбиков проверен валидатором палитры (светлая и тёмная тема) */
:root { --chart: #009073; }
@media (prefers-color-scheme: dark) { :root { --chart: #22a484; } }
.charts { margin: 24px 0 8px; }
.charts-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.charts-head h2 { margin: 0 auto 0 0; font-size: 18px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.chart { margin: 0; padding: 12px 14px 8px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.chart figcaption { font-size: 14px; margin-bottom: 4px; }
.chart figcaption span { color: var(--muted); }
.chart-wrap { position: relative; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg .bar { fill: var(--chart); }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart-svg .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .hit { fill: transparent; }
.chart-svg .hit.on { fill: var(--ink); opacity: .05; }
.chart-tip { position: absolute; pointer-events: none; padding: 5px 9px; border-radius: 7px; background: var(--ink); color: var(--panel);
  font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow); }
.chart-table { margin-top: 8px; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: 13.5px; padding: 4px 0; }
