:root {
  --bg: #e9e6e0;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6f6a62;
  --line: #d9d4cb;
  --accent: #b3261e;
  --accent-ink: #ffffff;
  --focus: #2f6fed;
  --warn: #c2410c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--ui); color: var(--text); background: var(--bg); }
button { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer;
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f6f4f0; }
.btn:disabled { opacity: .55; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: #9c1f18; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--warn { border-color: #f2c4a8; background: #fff4ec; color: var(--warn); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.is-on { background: #1d1b18; color: #fff; border-color: #1d1b18; }

/* ================= Редактор ================= */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 60px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar__brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; text-decoration: none; color: inherit; }
.topbar__logo { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: 20px; }
.topbar__name { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.save-status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-status.is-error { color: var(--accent); }

.hint-bar {
  display: flex; justify-content: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 16px; font-size: 13px; color: var(--muted);
}

.canvas { padding: 8px 24px 140px; }
.sheet-holder {
  --s: 0.5;
  margin: 0 auto 36px;
  width: calc(420mm * var(--s));
}
.sheet-label {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--muted); margin: 0 2px 8px;
}
.sheet-box {
  width: calc(420mm * var(--s));
  height: calc(297mm * var(--s));
  box-shadow: var(--shadow);
  border-radius: 2px;
  overflow: hidden;
}
.sheet-box .sheet { transform: scale(var(--s)); transform-origin: 0 0; }
/* линия сгиба */
.sheet-box .sheet::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px;
  background: linear-gradient(to bottom, rgba(0,0,0,.06), rgba(0,0,0,.12), rgba(0,0,0,.06));
  pointer-events: none;
}

/* Редактируемый текст */
.editing [data-text] { cursor: text; outline: none; transition: box-shadow .12s; border-radius: 1px; }
.editing [data-text]:hover { box-shadow: 0 0 0 0.5mm rgba(47,111,237,.35); }
.editing [data-text]:focus { box-shadow: 0 0 0 0.6mm var(--focus); }
.editing [data-text].is-overflow { box-shadow: 0 0 0 0.6mm var(--warn); background: rgba(194,65,12,.06); }
.editing [data-text]:empty::before { content: "Введите текст"; color: #aaa; font-style: italic; }

/* Фото */
.editing [data-photo] { cursor: grab; touch-action: none; }
.editing [data-photo].is-empty { cursor: pointer; }
.editing [data-photo]:hover { box-shadow: inset 0 0 0 0.6mm rgba(47,111,237,.45); }
.editing [data-photo].is-selected { box-shadow: inset 0 0 0 0.8mm var(--focus); }
.editing [data-photo].is-dragging { cursor: grabbing; }
.editing [data-photo].is-drop { box-shadow: inset 0 0 0 1.2mm var(--focus); background: #dfe8fd; }
.ph-hint {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 3mm;
  font-family: var(--ui); color: #6b665e; text-align: center; padding: 4mm;
  pointer-events: none;
}
.ph-hint svg { width: 14mm; height: 14mm; opacity: .7; }
.ph-hint b { font-size: 13pt; font-weight: 600; }
.ph-hint span { font-size: 9pt; }
.editing .is-empty .ph-hint { display: flex; }
.ph-badge {
  position: absolute; left: 2mm; bottom: 2mm;
  display: none; padding: 1mm 2.5mm; border-radius: 2mm;
  background: var(--warn); color: #fff; font: 600 8pt var(--ui);
  pointer-events: none;
}
.editing .is-lowres .ph-badge { display: block; }
.ph-busy {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(255,255,255,.7); font: 600 12pt var(--ui);
}
.is-busy .ph-busy { display: flex; }

/* Режим просмотра */
.preview [data-text], .preview [data-text]:hover { box-shadow: none !important; background: none !important; cursor: default; }
.preview [data-photo] { box-shadow: none !important; cursor: default; }
.preview .ph-hint, .preview .ph-badge { display: none !important; }

/* Панель фото */
.photo-panel {
  position: fixed; left: 50%; bottom: 20px; z-index: 30;
  transform: translate(-50%, 150%);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 12px; border-radius: 14px;
  background: var(--surface); box-shadow: 0 8px 40px rgba(0,0,0,.18);
  transition: transform .2s ease;
}
.photo-panel.is-open { transform: translate(-50%, 0); }
.photo-panel__title { font-size: 13px; font-weight: 600; padding: 0 6px; }
.photo-panel__zoom { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.photo-panel__zoom input { width: 140px; accent-color: var(--accent); }
.photo-panel__warn { font-size: 12px; color: var(--warn); width: 100%; text-align: center; display: none; }
.photo-panel.is-lowres .photo-panel__warn { display: block; }
.sep { width: 1px; height: 24px; background: var(--line); }

.toast {
  position: fixed; left: 50%; top: 76px; z-index: 40; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 10px; background: #1d1b18; color: #fff; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.is-shown { opacity: 1; }

@media (max-width: 720px) {
  .topbar { gap: 6px; padding: 0 10px; }
  .topbar__brand, .save-status, .btn .lbl-long, .sheet-label span:last-child { display: none; }
  .canvas { padding: 8px 8px 160px; }
  .btn { padding: 0 10px; }
}

/* ================= Страницы покупателя ================= */
.site { background: var(--bg); min-height: 100vh; line-height: 1.45; -webkit-text-size-adjust: 100%; }
.site a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

.site .btn--lg {
  height: auto; min-height: 44px; padding: 10px 18px;
  justify-content: center; text-align: center; white-space: normal;
  font-size: 15px; line-height: 1.2; text-decoration: none;
}
.site a.btn { color: var(--text); }
.site a.btn--primary { color: var(--accent-ink); }
.btn--ghost-line { background: transparent; }
.site .btn:focus-visible, .site a:focus-visible, .input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.site-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1080px; margin: 0 auto; padding: 18px 20px 0;
}
.site-head__logo { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: 24px; text-decoration: none; }
.site-head__link {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  border-radius: 8px; background: var(--surface); box-shadow: 0 0 0 1px var(--line);
  font-size: 15px; font-weight: 500; text-decoration: none;
}
.site-head__link:hover { box-shadow: 0 0 0 1px var(--text); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; }
.actions--stack { flex-direction: column; align-items: stretch; }
.form-error { color: var(--accent); font-size: 14px; margin: 12px 0 0; }

/* Каталог */
.home { max-width: 1080px; margin: 0 auto; padding: 40px 20px 80px; }
.home h1 { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: clamp(32px, 5vw, 52px); line-height: 1.05; margin: 0 0 14px; }
.home .sub { color: var(--muted); font-size: 18px; max-width: 640px; line-height: 1.5; margin: 0 0 40px; }
.tpl-list { display: grid; gap: 24px; }
.tpl-card {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; align-items: center;
  background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: var(--shadow);
}
.tpl-card__preview { position: relative; aspect-ratio: 420 / 297; border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); background: #fff; }
.tpl-card__preview iframe { position: absolute; top: 0; left: 0; border: 0; width: 1588px; height: 2300px; transform-origin: 0 0; pointer-events: none; }
.tpl-card h2 { font-family: "Playfair Display", Georgia, serif; font-size: 30px; margin: 0 0 8px; }
.tpl-card p { color: var(--muted); line-height: 1.5; margin: 0 0 14px; }
.tpl-card .meta { font-size: 14px; color: var(--text); margin-bottom: 22px; }
.tpl-card .btn { height: 44px; font-size: 15px; padding: 0 20px; }
.tpl-card .btn--lg { height: auto; min-height: 48px; padding: 12px 22px; font-size: 16px; }
.tpl-card__owned {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center;
  margin: 0 0 14px; padding: 10px 14px; border-radius: 10px;
  background: #eef5ea; color: #2f5d22; font-size: 15px;
}
.tpl-card__owned-link { font-weight: 600; min-height: 32px; display: inline-flex; align-items: center; }
.tpl-card .tpl-card__note { font-size: 13px; margin: 10px 0 0; }
.tpl-card .form-error { color: var(--accent); }
@media (max-width: 760px) {
  .tpl-card { grid-template-columns: 1fr; gap: 18px; padding: 16px; }
  .tpl-card .btn--lg { width: 100%; }
}

/* Общая страница (кабинет, заказ, код) */
.page { max-width: 760px; margin: 0 auto; padding: 32px 20px 80px; }
.page__title { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: clamp(30px, 6vw, 44px); line-height: 1.08; margin: 0 0 12px; }
.page__lead { font-size: 17px; color: var(--muted); margin: 0 0 24px; max-width: 600px; }
.card { background: var(--surface); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); margin: 0 0 16px; }
.card--soft { background: transparent; box-shadow: 0 0 0 1px var(--line); }
.card__title { font-size: 18px; margin: 0 0 6px; }
.card p { margin: 0 0 8px; }
.section { margin-top: 36px; }
.section__title { font-size: 20px; margin: 0 0 14px; }
.notice { background: var(--surface); border-radius: 14px; padding: 28px 22px; box-shadow: var(--shadow); }
.notice__title { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: 28px; line-height: 1.15; margin: 0 0 10px; }
.notice__text { color: var(--muted); margin: 0; font-size: 16px; }

/* Вход */
.login { display: grid; gap: 8px; }
.field__label { font-weight: 600; font-size: 15px; }
.field__help { font-size: 14px; color: var(--muted); margin: 0; }
.input {
  width: 100%; min-height: 52px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font: inherit; font-size: 17px; color: var(--text);
}
.input:focus { border-color: var(--focus); }
.input--key { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .06em; text-transform: uppercase; font-size: 18px; }
.input--key::placeholder { text-transform: none; color: #b5afa5; }

/* Баннер ключа доступа */
.key-banner {
  position: relative; margin: 0 0 24px; padding: 22px;
  background: #fff8e6; border: 2px solid #e4c36a; border-radius: 14px;
  box-shadow: var(--shadow);
}
.key-banner__title { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: 26px; line-height: 1.15; margin: 0 0 6px; }
.key-banner__lead { margin: 0 0 14px; font-size: 16px; }
.key-banner__key {
  display: block; margin: 0 0 14px; padding: 14px 16px;
  background: #fff; border: 1px dashed #c9a646; border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(18px, 5.4vw, 28px); font-weight: 700; letter-spacing: .06em; text-align: center;
  overflow-wrap: anywhere; user-select: all; -webkit-user-select: all;
}
.key-banner__facts { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 15px; color: #4a4339; }
.key-banner .actions { margin-top: 16px; }
.key-banner__status { margin: 10px 0 0; font-size: 14px; color: #2f5d22; min-height: 1em; }
.key-banner__status:empty { display: none; }

/* Списки газет и заказов */
.rows { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 10px; background: var(--surface); box-shadow: 0 0 0 1px var(--line);
}
.row__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row__title { font-weight: 600; }
.row__meta { font-size: 14px; color: var(--muted); }
.badge { align-self: flex-start; margin-top: 4px; padding: 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 500; }
.badge--wait { background: #fdf1d8; color: #8a5a00; }
.badge--bad { background: #fde7e5; color: var(--accent); }
.grant__title { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: 24px; line-height: 1.15; margin: 0 0 4px; }
.grant__meta { color: var(--muted); font-size: 14px; margin: 0 0 14px !important; }
.grant .rows .row { box-shadow: none; background: #f6f4f0; }
.grant__footer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 14px; }
.grant__footer .form-error { width: 100%; margin: 0; }
.account { padding-top: 24px; border-top: 1px solid var(--line); }

/* Статус заказа / активация */
.status { text-align: center; padding: 32px 22px; }
.status p { max-width: 520px; margin-left: auto; margin-right: auto; }
.status .actions { justify-content: center; }
.status__title { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: clamp(26px, 6vw, 36px); line-height: 1.12; margin: 0 0 10px; }
.status__icon {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; font-size: 28px; font-weight: 700;
  background: #e3f0dc; color: #2f5d22;
}
.status--bad .status__title { color: var(--accent); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 13px; font-weight: 600; color: var(--accent); margin: 0 0 6px; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto 16px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.summary { display: grid; gap: 0; margin: 18px auto 0; max-width: 420px; text-align: left; font-size: 15px; }
.summary > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-top: 1px solid var(--line); }
.summary > div:last-child { border-bottom: 1px solid var(--line); }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; text-align: right; font-weight: 500; overflow-wrap: anywhere; }

/* Тестовая платёжная форма — нейтральный вид, без чужих брендов */
.paymock { background: #eef0f3; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.paymock__test {
  position: sticky; top: 0; z-index: 5;
  padding: 12px 16px; text-align: center; font-size: 15px;
  background: repeating-linear-gradient(-45deg, #ffd84d 0 18px, #ffe27a 18px 36px);
  color: #2b2200; border-bottom: 2px solid #c9a400;
}
.paymock__wrap { max-width: 440px; margin: 0 auto; padding: 28px 16px 60px; }
.paymock__card { background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 10px 30px rgba(20,30,50,.10); }
.paymock__head { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: #4b5563; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid #e5e7eb; }
.paymock__lock { width: 14px; height: 12px; border-radius: 2px; background: #6b7280; position: relative; margin-top: 4px; }
.paymock__lock::before { content: ""; position: absolute; left: 2px; top: -7px; width: 6px; height: 7px; border: 2px solid #6b7280; border-bottom: 0; border-radius: 6px 6px 0 0; }
.paymock__title { font-size: 22px; margin: 0 0 8px; }
.paymock__label { margin: 0; color: #6b7280; font-size: 14px; }
.paymock__amount { margin: 2px 0 6px; font-size: 36px; font-weight: 700; letter-spacing: -.01em; }
.paymock .summary { max-width: none; }
.paymock .summary dt { color: #6b7280; }
.paymock .summary > div { border-color: #e5e7eb; }
.paymock__fake { margin-top: 18px; padding: 12px 14px; border-radius: 8px; background: #f3f4f6; color: #4b5563; font-size: 14px; }
.paymock__fake p { margin: 0; }
.paymock .btn { border-color: #d1d5db; }
.paymock .paymock__pay { background: #1f2937; border-color: #1f2937; color: #fff; min-height: 50px; font-size: 16px; }
.paymock .paymock__pay:hover { background: #111827; }

@media (max-width: 560px) {
  .site-head { padding: 12px 16px 0; }
  .site-head__logo { font-size: 22px; }
  .home { padding: 28px 16px 60px; }
  .home .sub { font-size: 16px; margin-bottom: 28px; }
  .page { padding: 24px 16px 60px; }
  .card, .key-banner { padding: 18px 16px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .btn { width: 100%; }
  .row { flex-direction: column; align-items: stretch; }
  .row .btn { width: 100%; }
  .grant__footer { flex-direction: column; align-items: stretch; }
  .grant__footer .btn { width: 100%; }
  .status { padding: 26px 16px; }
  .summary > div { flex-direction: column; gap: 0; }
  .summary dd { text-align: left; }
  .paymock__card { padding: 20px 16px; }
  .paymock__amount { font-size: 32px; }
}
