/* КвитQR — минималистичный интерфейс. Системные шрифты, один акцентный цвет. */
:root {
  --accent: #2b59e8;
  --accent-press: #2149c9;
  --accent-soft: #eef2fe;
  --ink: #0f1419;
  --ink-2: #4b5563;
  --ink-3: #8a929e;
  --line: #e4e7ec;
  --surface: #f6f7f9;
  --bg: #ffffff;
  --danger: #c4321f;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; overscroll-behavior: none; }
body { touch-action: manipulation; overscroll-behavior: none; }
/* на стартовом экране — обычный «потянуть вниз для обновления» */
html.on-start, html.on-start body { overscroll-behavior-x: none; overscroll-behavior-y: auto; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
h1 { font-size: 28px; line-height: 1.18; letter-spacing: -0.02em; font-weight: 700; margin: 0 0 12px; text-wrap: balance; }
p { margin: 0; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Шапка */
.bar {
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; font-weight: 650; font-size: 17px; letter-spacing: -0.01em;
}
.brand-mark { width: 28px; height: 28px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: #fff; }

main { flex: 1; width: 100%; max-width: 520px; margin: 0 auto; padding: 8px 20px calc(32px + var(--safe-b)); }
.screen { animation: enter .22s ease-out both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.lead { color: var(--ink-2); font-size: 17px; line-height: 1.5; }
.hint { color: var(--ink-3); font-size: 14px; line-height: 1.45; }
.center { text-align: center; }

/* Кнопки */
.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 22px;
  border: 0; border-radius: var(--radius);
  font: 600 17px/1 var(--font); letter-spacing: -0.01em;
  text-decoration: none; cursor: pointer; user-select: none;
  transition: background-color .15s, color .15s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.985); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, .brand:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}
.btn .icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-press); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-secondary:hover { background: #e3e9fd; }
.btn-link { background: none; color: var(--accent); min-height: 44px; padding: 0 8px; font-weight: 550; font-size: 16px; }
.btn-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.btn-xl { width: 100%; min-height: 64px; font-size: 18px; border-radius: 18px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-back { background: none; color: var(--ink-2); padding: 0 6px 0 0; min-height: 44px; font-weight: 500; font-size: 16px; margin: 0 0 12px -4px; gap: 2px; }
.btn-back .icon { width: 22px; height: 22px; }

/* Старт */
.screen-start { display: flex; flex-direction: column; min-height: calc(100dvh - 140px); }
.start-copy { padding-top: 7vh; }
.start-copy h1 { font-size: 32px; margin-bottom: 14px; }
.start-action { margin-top: 40px; display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
.start-action .btn-link { align-self: center; margin-top: 4px; }
.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) { .desktop-only { display: revert; } button.desktop-only { display: inline-flex; } }
.start-action.drag { outline: 2px dashed var(--accent); outline-offset: 8px; border-radius: 16px; }
input[type=file]:focus-visible + label { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 3px; }

.steps {
  list-style: none; padding: 0; margin: auto 0 0; padding-top: 48px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.steps li { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--ink-2); font-size: 13px; line-height: 1.3; }
.step-n {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px;
}
.fineprint { margin-top: 28px; text-align: center; color: var(--ink-3); font-size: 13px; }

.progress { padding: 4px 2px 0; }
.progress-track { height: 4px; background: var(--surface); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .35s ease; }
.progress-fill { transition: none; }
.progress-text { margin-top: 10px; text-align: center; color: var(--ink-2); font-size: 15px; }
.error-text { color: var(--danger); text-align: center; font-size: 15px; }

/* Форма */
.screen-form .lead { margin-bottom: 28px; font-size: 16px; }
.field { margin-bottom: 18px; min-width: 0; }
.field label { display: block; font-size: 14px; font-weight: 550; color: var(--ink-2); margin-bottom: 6px; }
input, textarea {
  width: 100%; display: block;
  font: 400 17px/1.35 var(--font); color: var(--ink);
  background: var(--surface);
  border: 1px solid transparent; border-radius: 12px;
  padding: 13px 14px; min-height: 50px;
  transition: border-color .15s, background-color .15s;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 84px; }
textarea.grow { resize: none; overflow: hidden; min-height: 50px; overflow-wrap: anywhere; white-space: pre-wrap; field-sizing: content; }
#f-purpose { min-height: 76px; }
.field.is-check label::after { content: " · проверьте"; color: #a5422f; font-weight: 500; }
.field.is-check textarea.grow { border-width: 2px; padding: 12px 13px; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:hover, textarea:hover { border-color: var(--line); }
input:focus, textarea:focus { outline: none; background: var(--bg); border-color: var(--accent); }
input[inputmode=numeric] { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.field.is-check input, .field.is-check textarea { background: #fff; border-color: #f0b4ab; }
.field.is-error input, .field.is-error textarea { background: #fff; border-color: var(--danger); }
.field-msg { font-size: 13px; line-height: 1.35; margin-top: 6px; color: var(--ink-3); min-height: 0; }
.field-msg:empty { display: none; }
.field.is-check .field-msg { color: #a5422f; }
.field.is-todo input { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.is-todo .field-msg { color: var(--accent); font-weight: 500; }
.field.is-error .field-msg { color: var(--danger); }
.grid-2 { display: block; } /* каждое поле — своей строкой во всю ширину */

.more { border-top: 1px solid var(--line); margin: 8px 0 0; padding-top: 4px; }
.more summary {
  list-style: none; cursor: pointer; color: var(--ink-2); font-weight: 550; font-size: 15px;
  min-height: 48px; display: flex; align-items: center; justify-content: space-between;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: ""; width: 8px; height: 8px; border-right: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; transform: rotate(45deg) translate(-2px, -2px); transition: transform .15s; }
.more[open] summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.more[open] summary { margin-bottom: 8px; }

.form-actions {
  position: sticky; bottom: 0; z-index: 20;
  margin: 12px -20px 0; padding: 14px 20px calc(14px + var(--safe-b));
  background: linear-gradient(to bottom, rgba(255,255,255,0), #fff 28%);
}

/* Результат */
.screen-result { display: flex; flex-direction: column; align-items: center; padding-top: 8px; }
.qr-card {
  /* высоту задаёт сама картинка (квадрат): без aspect-ratio/height:100% у рамки — Safari иначе
     считает высоту рамки короче QR, и код вылезает за низ */
  margin: 0; width: 100%; max-width: 340px; box-sizing: border-box;
  padding: clamp(10px, 4vw, 16px); border-radius: 24px; background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 32px -12px rgba(16, 24, 40, .14);
}
.qr-card img { display: block; width: 100%; height: auto; aspect-ratio: 1; max-width: 100%; image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; border-radius: 8px; }
.summary { text-align: center; margin: 28px 0 24px; max-width: 420px; }
.summary-sum { font-size: 34px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.summary-name { margin-top: 10px; font-size: 16px; font-weight: 550; color: var(--ink); }
.summary-purpose { margin-top: 4px; font-size: 15px; color: var(--ink-2); }
.result-actions { width: 100%; max-width: 420px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.result-links { display: flex; gap: 16px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

/* Тост */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 16px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Десктоп */
@media (min-width: 768px) {
  .bar { padding: 22px 40px; }
  main { padding-top: 24px; }
  h1 { font-size: 32px; }
  .start-copy { padding-top: 9vh; text-align: center; }
  .start-copy h1 { font-size: 44px; }
  .start-copy .lead { font-size: 18px; max-width: 460px; margin: 0 auto; }
  .start-action { max-width: 400px; width: 100%; margin: 44px auto 0; }
  .screen-start { min-height: calc(100dvh - 180px); }
  .steps { max-width: 440px; margin-left: auto; margin-right: auto; }
  .screen-form { max-width: 520px; margin: 0 auto; }
  .form-actions { position: static; margin: 20px 0 0; padding: 0; background: none; }
  .qr-card { max-width: 320px; }
  .screen-result { padding-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.summary-sum.muted { font-size: 20px; font-weight: 600; color: var(--ink-2); }
h1[tabindex="-1"]:focus { outline: none; }
.hint { text-wrap: balance; }
.screen-result > .hint { width: 100%; max-width: 420px; }

/* Кропы полей с фото квитанции: изображение всегда целиком (без object-fit/обрезки) */
.crop { display: block; width: 100%; max-width: 100%; box-sizing: border-box; margin: 2px 0 6px; padding: 3px; border: 1px solid #d9dde3; border-radius: 8px; background: #fff; cursor: zoom-in; line-height: 0; text-align: left; overflow: hidden; position: relative; z-index: 0; -webkit-tap-highlight-color: transparent; }
.crop img { display: block; width: 100%; max-width: 100%; height: auto; object-fit: contain; border-radius: 5px; }
.crop:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 2px; }
.crop-low { border: 2px solid #e8b400; background: #fff6cc; }
.field.is-low input, .field.is-low textarea { background: #fff8d6; border-color: #e8b400; }
.photo-view { position: fixed; left: 0; right: 0; top: 0; height: 100dvh; z-index: 1000; background: rgb(15, 18, 24); display: flex; flex-direction: column; overscroll-behavior: contain; }
.photo-view.hidden { display: none; }
.photo-scroll { flex: 1 1 auto; min-height: 80px; overflow: hidden; padding: 60px 8px 8px; display: flex; align-items: center; justify-content: center; touch-action: none; }
.photo-box { position: relative; display: inline-block; line-height: 0; transform-origin: 0 0; will-change: transform; touch-action: none; }
.photo-box img { display: block; max-width: calc(100vw - 16px); max-height: 50dvh; width: auto; height: auto; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; pointer-events: none; }
.photo-mark { position: absolute; border: 3px solid #ffcc00; border-radius: 4px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35); pointer-events: none; }
.photo-close { position: fixed; top: 10px; right: 12px; width: 44px; height: 44px; border-radius: 22px; border: 0; background: #fff; color: #111; font-size: 28px; line-height: 44px; cursor: pointer; z-index: 1001; }
body.no-scroll { overflow: hidden; }
.optional { font-weight: 400; color: var(--ink-3); }
/* Экран реквизитов кончается кнопкой: без отступа и пустоты под ней */
main:has(#screen-form:not(.hidden)) { padding-bottom: 0; }
.photo-hint { text-align: center; color: var(--ink-3); font-size: 12px; margin: 8px 0 0; }
@media (min-width: 768px) { main:has(#screen-form:not(.hidden)) { padding-bottom: calc(32px + var(--safe-b)); } }
textarea.digits { font-variant-numeric: tabular-nums; letter-spacing: .01em; word-break: break-all; min-height: 50px; }
/* Редактор поля под фото */
.ed-box { flex: 0 0 auto; background: var(--bg, #fff); border-radius: 16px 16px 0 0; padding: 14px 16px calc(12px + var(--safe-b)); touch-action: manipulation; }
.ed-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.ed-label { font-weight: 600; font-size: 15px; }
.ed-count { color: var(--ink-3); font-size: 13px; }
.ed-input { resize: none; overflow: hidden; min-height: 50px; overflow-wrap: anywhere; word-break: break-word; white-space: pre-wrap; font-size: 17px; }
.ed-box.is-low .ed-input { background: #fff8d6; border-color: #e8b400; }
.ed-msg { font-size: 13px; color: #a5422f; margin: 6px 0 0; }
.ed-msg:empty { display: none; }
.ed-actions { display: grid; grid-template-columns: 56px 56px 1fr; gap: 8px; margin-top: 10px; }
.ed-actions .btn { min-height: 48px; padding: 0; }
.ed-actions .btn:disabled { opacity: .4; }

/* Компактнее: меньше прокрутки (поля по-прежнему по одному в строке) */
main { padding-top: max(10px, env(safe-area-inset-top)); }
h1 { font-size: 24px; margin-bottom: 6px; }
.btn-back { min-height: 36px; margin-bottom: 4px; }
.screen-form .lead { margin-bottom: 14px; font-size: 15px; line-height: 1.4; }
.field { margin-bottom: 12px; }
.field label { margin-bottom: 4px; }
.field-msg { margin-top: 4px; }
input, textarea { padding: 11px 13px; min-height: 46px; }
textarea.grow { min-height: 46px; }
.crop { margin: 0 0 4px; }

/* Экран результата целиком в один экран: высота QR — от свободного места */
main:has(#screen-result:not(.hidden)) {
  height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
  padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: calc(10px + var(--safe-b));
}
.screen-result { flex: 1 1 auto; min-height: 0; padding-top: 0; gap: 8px; }
.qr-card {
  /* без рамки, подложки и отступов: у картинки уже есть белое поле 4 модуля (нужно для сканирования) */
  flex: 0 0 auto; width: 100%; max-width: none; margin: 0; padding: 0;
  border: 0; border-radius: 0; box-shadow: none; background: none;
  display: flex; justify-content: center;
}
.qr-card img { width: 100%; height: auto; max-width: none; aspect-ratio: 1; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: #fff; }
.summary { margin: 0; width: 100%; flex: 0 0 auto; text-align: left; }
.summary-sum { font-size: 22px; text-align: center; }
.summary-sum.muted { font-size: 15px; }
.r-info { margin: 4px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 0 8px; font-size: 13px; line-height: 1.25; }
.r-info dt { color: var(--ink-3); white-space: nowrap; }
.r-info dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.result-actions { flex: 0 0 auto; margin: 0; gap: 8px; max-width: none; }
.result-actions .btn { min-height: 44px; }
.result-links { flex: 0 0 auto; margin: 0; gap: 8px; }
.result-links .btn-link { min-height: 34px; }
.screen-result { gap: 8px; }
main:has(#screen-result:not(.hidden)) { height: auto; min-height: 0; overflow: visible; }
@media (min-width: 768px) { main:has(#screen-result:not(.hidden)) { padding-top: 24px; padding-bottom: 24px; } }
.result-actions { grid-template-columns: 1fr; }
.result-note { margin: 0; flex: 0 0 auto; text-align: center; font-size: 13px; color: var(--ink-3); }

/* Каждое поле — отдельная карточка: синяя шапка с подписью, внутри кроп и поле ввода */
.field {
  padding: 0 10px 10px; margin-bottom: 12px; border-top: 0;
  background: color-mix(in srgb, var(--accent) 7%, #fff);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, #fff); border-radius: 14px; overflow: hidden;
}
#form > .field:first-child { padding-top: 0; border-top: 1px solid color-mix(in srgb, var(--accent) 28%, #fff); }
.field label {
  display: block; margin: 0 -10px 8px; padding: 7px 12px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 650; letter-spacing: -0.005em;
}
.field label .optional { color: rgba(255, 255, 255, .8); font-weight: 400; font-size: 13px; }
.field input, .field textarea { background: #fff; }
.field.is-check, .field.is-low { border-color: #e8b400; background: #fffbe8; }
.field.is-check label, .field.is-low label { background: #e8b400; color: #2b2100; }
.field.is-check label::after { color: #2b2100; font-size: 13px; font-weight: 600; }
.field.is-error { border-color: var(--danger); }
.field.is-error label { background: var(--danger); color: #fff; }
.field.is-todo label { background: var(--accent); }
.field-msg { margin-top: 6px; }
/* Кнопка «Создать QR-код» — отдельным зелёным цветом; липкая панель на белом с тенью сверху */
#make { background: #16a34a; color: #fff; font-weight: 700; box-shadow: 0 2px 6px rgba(22, 163, 74, .35), 0 8px 18px -8px rgba(21, 128, 61, .45); }
#make:hover { background: #15803d; }
#make:active { background: #15803d; transform: translateY(1px); box-shadow: 0 1px 3px rgba(21, 128, 61, .4); }
#make:disabled { background: #6fbf8b; box-shadow: none; }
#make:focus-visible { outline: 3px solid rgba(22, 163, 74, .45); outline-offset: 3px; }
.form-actions { background: #fff; box-shadow: 0 -6px 16px -6px rgba(16, 24, 40, .18); }
@media (min-width: 768px) { .form-actions { box-shadow: none; } }
/* Редактор при открытой клавиатуре: сверху неподвижный кроп поля, ничего не прыгает */
.photo-view { transition: none !important; }
.ed-crop { display: none; flex: 1 1 auto; min-height: 90px; padding: 56px 8px 8px; align-items: center; justify-content: center; overflow: hidden; }
.ed-crop img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; border-radius: 6px; background: #fff; }
.photo-view.kb .ed-crop { display: flex; }
.photo-view.kb .photo-scroll { display: none; }
.photo-view.kb .photo-hint { display: none; }
.photo-view.kb .photo-close { top: 6px; }
.photo-view .photo-close { position: absolute; }
.ed-input { font-size: 17px !important; }
/* Две кнопки-иконки внизу результата в один ряд: ← изменить, + новая квитанция */
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-actions .btn-icon { min-height: 50px; padding: 0; }
.result-actions .btn-icon .icon { width: 28px; height: 28px; stroke-width: 2.4; }
.btn-outline { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
.btn-outline:active { background: var(--accent-soft); }
/* Сведения слева на всю оставшуюся ширину, справа — две компактные кнопки-иконки столбиком */
.result-row { display: flex; align-items: flex-start; gap: 10px; width: 100%; flex: 0 0 auto; }
.result-row .summary { flex: 1 1 auto; min-width: 0; }
.result-row .result-actions { display: flex; flex-direction: column; gap: 8px; width: auto; flex: 0 0 auto; }
.result-row .result-actions .btn-icon { width: 46px; height: 46px; min-height: 46px; border-radius: 12px; padding: 0; }
.result-row .result-actions .btn-icon .icon { width: 26px; height: 26px; }
.result-row .summary-sum { text-align: left; }
/* Зебра в сведениях результата: чётные строки (dt+dd) на бледно-сером фоне во всю ширину.
   Ровные внешние отступы 7px, между колонками 6px; подписи переносятся (до 7.5em), чтобы значения не рвались. */
.r-info { gap: 0; grid-template-columns: minmax(0, max-content) 1fr; }
.r-info dt, .r-info dd { padding: 2px 7px 2px 0; }
.r-info dt { padding-left: 7px; padding-right: 6px; white-space: normal; max-width: 7.5em; }
.r-info dt:nth-of-type(odd), .r-info dd:nth-of-type(odd) { background: #f1f3f5; }
.r-info dt:nth-of-type(odd) { border-radius: 6px 0 0 6px; }
.r-info dd:nth-of-type(odd) { border-radius: 0 6px 6px 0; }
.result-row { gap: 12px; }
.screen-result > .summary-sum { text-align: left; padding-left: 7px; width: 100%; margin: 0; flex: 0 0 auto; }
.result-row .r-info { margin-top: 0; }
/* Экран формы на телефоне: прокручивается не документ, а #app фиксированной высоты без «резинки».
   Документ iOS Safari тянет rubber-band даже при overscroll-behavior:none, а 100dvh меняется при сворачивании
   панели браузера — отсюда дёрганье у кнопки. Внутренний скроллер с overscroll-behavior:none просто встаёт в конце. */
@media (max-width: 767px) {
  html.on-form, html.on-form body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  html.on-form body { position: fixed; inset: 0; min-height: 0; }
  html.on-form main#app { height: 100%; overflow-y: auto; overscroll-behavior: none; -webkit-overflow-scrolling: touch; padding-bottom: 0; }
}
