/* PrintPoint user app — mobile-first, light theme. */
:root {
  --brand: #0e6bff;
  --brand-dark: #0a4fc2;
  --brand-soft: #e8f0ff;
  --accent: #ffd166;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --warn: #c77700;
  --warn-soft: #fff4e0;
  --err: #d43a3a;
  --err-soft: #fde8e8;
  --text: #1a1f2b;
  --muted: #5f6675;
  --line: #e2e6ee;
  --bg: #f5f7fb;
  --card: #ffffff;
  --radius: 14px;
  --tap: 48px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--sat)) calc(16px + var(--sar)) 10px calc(16px + var(--sal));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--brand); font-weight: 700; font-size: 20px; min-height: 44px; }
.brand-name { letter-spacing: -0.3px; }
.lang select {
  min-height: 44px; min-width: 64px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  font-weight: 600; color: var(--muted);
}

/* Offline banner */
.offline {
  display: flex; gap: 12px; align-items: center; justify-content: center;
  padding: 10px 16px; background: var(--warn-soft); color: var(--warn); font-weight: 600;
}

/* Layout */
.app { max-width: 560px; margin: 0 auto; padding: 16px calc(16px + var(--sar)) calc(24px + var(--sab)) calc(16px + var(--sal)); }
.screen { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
h1 { font-size: 24px; margin: 6px 0 0; line-height: 1.2; }
h2 { font-size: 18px; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; overflow-wrap: break-word; }
.card.soft { background: var(--brand-soft); border-color: transparent; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; }

.card.danger-soft { background: var(--err-soft); border-color: transparent; }
.mt8 { margin-top: 8px; }
.amount { font-size: 22px; }
.center-row { justify-content: center; }
.howto-list { margin: 8px 0 0; padding-left: 22px; }
.link.danger { color: var(--err); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 600; font-size: 17px; text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn:active { opacity: .8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.danger { color: var(--err); border-color: #f3c2c2; background: #fff; }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.busy { pointer-events: none; }
.btn.icon { min-width: var(--tap); padding: 0; font-size: 20px; }
.link { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 8px; min-height: 44px; text-decoration: underline; }

/* Status badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* Price table. minmax(0, …) on both tracks: a long unbreakable word in a cell must never push the other
 * column out of the card (T-057). Amounts never wrap; the label wraps at any character if it has to. */
.price-table { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; }
.price-table > * { min-width: 0; }
.price-table > :nth-child(even) { text-align: right; white-space: nowrap; }
.price-table > :nth-child(odd) { overflow-wrap: anywhere; }
.price-table .total { font-weight: 700; font-size: 20px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }

/* File cards */
.file { display: flex; flex-direction: column; gap: 10px; }
.file-name { font-weight: 600; }
.file-meta { font-size: 14px; color: var(--muted); }
.file-opts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.file-opts > * { min-width: 0; }
.seg { display: inline-flex; min-width: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { min-height: 44px; min-width: 0; flex: 1 1 auto; padding: 0 12px; border: 0; background: var(--card); font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 44px; min-height: 44px; border: 0; background: var(--card); font-size: 22px; font-weight: 600; color: var(--brand); }
.stepper button[disabled] { color: var(--line); }
.stepper output { min-width: 40px; text-align: center; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 14px; color: var(--muted); font-weight: 600; }
/* T-099: двусторонняя печать — отдельная строка на всю ширину, сегмент-переключатель тянется по ширине. */
.file-opts .opt-duplex { grid-column: 1 / -1; }
.file-opts .opt-duplex .seg { width: 100%; }
.hint { font-size: 12px; color: var(--muted); }
.input {
  min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  font-size: 17px; width: 100%;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.input.invalid { border-color: var(--err); }
.file-price { font-weight: 700; font-size: 18px; text-align: right; }
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .2s; }
.progress.ok > span { background: var(--ok); }
.file-add { position: relative; }
.file-add input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; font-size: 0; }
.err-text { color: var(--err); font-size: 14px; font-weight: 600; }
.warn-text { color: var(--warn); font-size: 14px; font-weight: 600; }

/* Sticky footer with the main call to action */
.cta {
  position: sticky; bottom: 0; z-index: 4;
  margin: 8px calc(-16px - var(--sar)) calc(-24px - var(--sab)) calc(-16px - var(--sal));
  padding: 12px calc(16px + var(--sar)) calc(12px + var(--sab)) calc(16px + var(--sal));
  background: linear-gradient(to top, var(--bg) 70%, rgba(245,247,251,0));
}

/* Payment */
.methods { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.methods .btn { min-height: 64px; padding: 8px 10px; flex-direction: column; gap: 2px; text-align: center; }
.methods .btn > * { max-width: 100%; overflow-wrap: anywhere; }
.methods .btn small { font-weight: 500; color: var(--muted); font-size: 13px; }
.methods .btn.primary small { color: #dbe7ff; }
.qr { display: block; width: min(260px, 70vw); height: auto; margin: 0 auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox .mono { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); max-height: 84px; overflow: auto; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.card-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card-form .span2 { grid-column: 1 / -1; }
.mp-field { min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }

/* Spinner */
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(0,0,0,.12); border-top-color: currentColor; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
.btn.primary .spin { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
.spin.big { width: 40px; height: 40px; border-width: 4px; color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Result screens */
.hero { text-align: center; padding: 24px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hero .icon { width: 72px; height: 72px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 36px; }
.hero .icon.ok { background: var(--ok-soft); color: var(--ok); }
.hero .icon.err { background: var(--err-soft); color: var(--err); }
.hero .icon.warn { background: var(--warn-soft); color: var(--warn); }
.hero .icon.info { background: var(--brand-soft); color: var(--brand); }
/* Out-of-service screen (T-085): a calm, branded full-screen state for the kiosk monitor and for the phone entry
 * block. Large and centered so it reads across the room on the AOC monitor. */
.hero.oos { padding: 40px 8px 16px; gap: 14px; }
.hero.oos .oos-mark { width: 120px; height: 120px; border-radius: 28px; display: flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); }
.hero.oos .oos-title { font-size: 28px; margin: 4px 0 0; }
.hero.oos .oos-msg { font-size: 18px; color: var(--text); max-width: 32ch; }
.hero.oos .cta { margin-top: 8px; }
/* Receipt (T-057): the value column (amounts, status) must never wrap or be cut off; the label column takes
 * whatever is left and wraps at any character. `minmax(0, auto)` lets the long payment id shrink (it is
 * .mono with word-break: break-all, so its min-content is one character) instead of widening the table. */
.receipt { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; font-size: 15px; }
.receipt > * { min-width: 0; }
.receipt .k { color: var(--muted); overflow-wrap: anywhere; }
.receipt .v { text-align: right; white-space: nowrap; }
/* The payment id is long and unbreakable: its own full-width row, broken at any character, so it can never
 * widen the value column (an `auto` track would otherwise take max-content and squeeze the labels away). */
.receipt .wide { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px 8px; }
.receipt .wide .mono { word-break: break-all; min-width: 0; }

/* Toasts */
.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(16px + var(--sab)); z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: #222; color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: toastin .2s ease-out; text-align: center; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }
.toast.warn { background: var(--warn); }
.toast.fade { opacity: 0; transition: opacity .4s; }
@keyframes toastin { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,24,34,.5); z-index: 40; display: flex; align-items: flex-end; justify-content: center; padding: 16px; padding-bottom: calc(16px + var(--sab)); }
.modal { background: var(--card); border-radius: 18px; width: 100%; max-width: 480px; padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
.modal .note { color: var(--err); font-size: 14px; font-weight: 600; }
.modal-foot { display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; }
@media (min-width: 600px) { .modal-bg { align-items: center; } }

/* File thumbnails (page-1 preview, ADR-0306): A4 proportion, placeholder with the extension while there is no image */
.file-head { align-items: flex-start; }
.file-head .file-meta { gap: 6px 10px; margin-top: 4px; }
.thumb {
  flex: 0 0 auto; width: 52px; height: 74px; border-radius: 6px; border: 1px solid var(--line); background: #fff;
  display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 0; color: var(--muted);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.thumb.pending { background: linear-gradient(100deg, #fff 30%, var(--bg) 50%, #fff 70%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.thumb.failed { background: var(--err-soft); border-color: transparent; color: var(--err); font-size: 22px; }
.thumb-ext { font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.thumb.failed .thumb-ext { font-size: 24px; }
.thumb .spin { width: 16px; height: 16px; border-width: 2px; color: var(--brand); }
button.thumb { cursor: zoom-in; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; }
@keyframes shimmer { to { background-position: -200% 0; } }
.preview-big { display: block; width: 100%; max-width: 360px; height: auto; margin: 0 auto; border: 1px solid var(--line); border-radius: 8px; }
.file-problem { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 10px; background: var(--err-soft); }
.file-problem .small { color: var(--text); }

/* Payment notices */
.card.warn-soft { background: var(--warn-soft); border-color: transparent; display: flex; flex-direction: column; gap: 4px; }
.card.warn-soft b { color: var(--warn); }
.pay-fail { display: flex; flex-direction: column; gap: 2px; }
.card-pending { padding: 22px 16px; }

/* Footer with legal links (printer.html and the legal pages) */
.foot {
  max-width: 560px; margin: 0 auto; padding: 8px 16px calc(20px + var(--sab));
  display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap;
  font-size: 14px; color: var(--muted);
}
.foot a { color: var(--muted); text-decoration: underline; padding: 10px 4px; }

/* Legal pages (privacy.html, terms.html) */
.legal h1 { font-size: 26px; }
.legal .lead { font-size: 17px; }
.legal section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; scroll-margin-top: 72px; }
.legal section h2 { font-size: 18px; }
.legal p, .legal li { font-size: 16px; line-height: 1.5; }
.legal ul { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 4px; }
.legal a { color: var(--brand); }
.legal .toc { display: flex; flex-direction: column; gap: 0; font-size: 15px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 16px; }
.legal .toc a { padding: 7px 0; text-decoration: none; }

/* QR re-scan overlay (ADR-0314): full screen, dark, camera view with a frame, texts and buttons below. */
body.scanning { overflow: hidden; }
.card.info-soft { background: var(--brand-soft); border-color: var(--brand); }
.scan {
  position: fixed; inset: 0; z-index: 60; background: #000; color: #fff;
  display: flex; flex-direction: column;
  padding: var(--sat) var(--sar) 0 var(--sal);
}
.scan-view { position: relative; flex: 1 1 auto; min-height: 200px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.scan-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; }
.scan.live .scan-video { opacity: 1; }
.scan-frame {
  position: relative; width: min(64vw, 280px); height: min(64vw, 280px); border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.9);
}
.scan-spin { position: absolute; color: #fff; }
.scan.live .scan-spin, .scan.failed .scan-spin, .scan.failed .scan-frame { display: none; }
.scan-panel {
  flex: 0 0 auto; background: #111; padding: 16px 16px calc(16px + var(--sab)); display: flex; flex-direction: column; gap: 8px;
  max-width: 560px; width: 100%; margin: 0 auto;
}
.scan-panel h2 { margin: 0; font-size: 19px; color: #fff; }
.scan-panel p { margin: 0; font-size: 15px; color: rgba(255,255,255,.85); }
.scan-status { font-weight: 600; }
.scan-status.warn { color: var(--accent); }
.scan-error { background: #2a1414; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.scan-error b { color: #ffb4b4; }
.scan-actions { display: flex; gap: 10px; margin-top: 4px; }
.scan-actions .btn { flex: 1; background: #2a2f3a; border-color: #2a2f3a; color: #fff; }
