:root {
  --accent: #ffd60a;
  --ok: #30d158;
  --bad: #ff453a;
  --muted: rgba(255, 255, 255, 0.6);
  --fill: rgba(255, 255, 255, 0.12);
  --sheet: #1c1c1e;
  --field: #2c2c2e;
  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --sar: env(safe-area-inset-right);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, Roboto, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: #000;
  color: #fff;
  font: 15px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ico {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ───── Камера ───── */

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 56px;
  padding: 0 12px;
  z-index: 5;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-width: 84px;
  padding: 0 14px 0 10px;
  border-radius: 99px;
  background: var(--fill);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}
.chip-btn .ico { width: 18px; height: 18px; }
.chip-btn.on { background: var(--accent); color: #000; }
.chip-btn.on .ico { fill: currentColor; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.icon-btn.round { width: 48px; height: 48px; background: var(--fill); }
.icon-btn:active, .chip-btn:active { opacity: 0.6; }

.gps {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 30px;
  padding: 0 12px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.gps-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.gps[data-state="wait"] .gps-dot { animation: pulse 1.2s ease-in-out infinite; }
.gps[data-state="ok"] .gps-dot { background: var(--ok); }
.gps[data-state="weak"] .gps-dot { background: var(--accent); }
.gps[data-state="off"] .gps-dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.25; } }

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}

.frame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0d0d;
  container-type: size;
}

.frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.frame.mirror video { transform: scaleX(-1); }

/* Превью штампа: те же пропорции, что и на готовом снимке (1cqmin = 1% меньшей стороны кадра) */
.stamp {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 1.6cqmin;
  padding: 8cqmin 4cqmin 4cqmin;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.35) 35%, rgba(0, 0, 0, 0.7));
  color: #fff;
  text-shadow: 0 0 0.6cqmin rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.stamp:empty, .stamp.is-empty { display: none; }

.stamp-pin {
  flex: none;
  width: 2.6cqmin;
  height: 3.64cqmin;
  margin-top: calc((var(--lh1, 4.6cqmin) - 3.64cqmin) / 2);
  overflow: visible;
}

.stamp-lines { min-width: 0; flex: 1; }
.stamp-lines > div {
  line-height: 1.28;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.l-title { font-size: 3.6cqmin; font-weight: 700; }
.l-note { font-size: 2.6cqmin; font-weight: 700; color: var(--accent); }
.l-body, .l-coords, .l-time { font-size: 2.6cqmin; font-weight: 500; color: rgba(255, 255, 255, 0.88); }
.l-coords { font-variant-numeric: tabular-nums; }

.blink {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}
.blink.on { animation: blink 0.22s ease-out; }
@keyframes blink { 0% { opacity: 0.9; } 100% { opacity: 0; } }

.blocker {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  background: #000;
}
.blocker-title { font-size: 19px; font-weight: 700; }
.blocker-text { max-width: 320px; color: var(--muted); white-space: pre-line; }
.blocker .pill-btn { margin-top: 8px; }

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 112px;
  padding: 0 28px 8px;
}

.thumb {
  position: relative;
  justify-self: start;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: #1a1a1a;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 40% { transform: scale(1.12); } }
.thumb-count {
  position: absolute;
  right: 3px;
  bottom: 3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

#switchBtn { justify-self: end; }

.shutter {
  width: 78px;
  height: 78px;
  padding: 5px;
  border-radius: 50%;
  border: 4px solid #fff;
}
.shutter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease, background 0.15s;
}
.shutter:active span { transform: scale(0.88); }
.shutter.busy span { transform: scale(0.7); background: var(--accent); }
.shutter:disabled { opacity: 0.4; }

/* Под видоискателем: сколько ещё снять / кнопка «Далее» */
.flow {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  padding: 0 16px;
}
.flow-hint {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 16px 0 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 14px;
  font-weight: 600;
}
.flow-dots { display: inline-flex; gap: 5px; }
.flow-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); transition: background 0.2s; }
.flow-dots i.on { background: var(--accent); }
.flow-next {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 18px 0 22px;
  font-size: 16px;
  animation: rise 0.25s ease-out;
}
.flow-next .ico { width: 20px; height: 20px; stroke-width: 2.2; }
.flow-count { padding: 2px 9px; border-radius: 99px; background: rgba(0, 0, 0, 0.12); font-size: 13.5px; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

.pill-btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 99px;
  background: var(--fill);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-btn.accent { background: var(--accent); color: #000; }
.pill-btn:active { opacity: 0.7; }
.pill-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:disabled { opacity: 0.25; cursor: default; }

.screenflash {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--sat) + 64px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 16px;
  border-radius: 12px;
  background: rgba(30, 30, 32, 0.94);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  z-index: 90;
  animation: rise 0.2s ease-out;
}

/* ───── Галерея и просмотр ───── */

.panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  background: #000;
}
.viewer { z-index: 30; }

.panel-head {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  height: 52px;
  padding: 0 8px;
  flex: none;
}
.panel-head h2 {
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: start;
  gap: 2px;
  overflow-y: auto;
}
.grid button { aspect-ratio: 1; background: #111; overflow: hidden; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.panel-note { flex: none; padding: 14px 20px; color: var(--muted); font-size: 13px; text-align: center; }

.viewer-img {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }

.viewer-actions {
  flex: none;
  display: flex;
  padding: 8px 12px 12px;
}
.act {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
}
.act:active { background: var(--fill); }
.act.danger { color: var(--bad); }
.act.confirm { background: rgba(255, 69, 58, 0.16); }

/* ───── Заявка ───── */

.wizard { z-index: 25; }
.wizard .panel-head h2 { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }

.wiz-steps {
  flex: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}
.wiz-steps i { height: 4px; border-radius: 2px; background: var(--fill); transition: background 0.25s; }
.wiz-steps i.on { background: var(--accent); }

.wiz-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 32px;
}
.wiz-body > * { max-width: 528px; margin-left: auto; margin-right: auto; }

.wiz-photo-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.wiz-photo-row::-webkit-scrollbar { display: none; }
.wiz-photo, .wiz-add {
  position: relative;
  flex: none;
  width: 68px;
  height: 68px;
  border-radius: 14px;
}
.wiz-photo { background: #1a1a1a; }
.wiz-photo-open { display: block; width: 100%; height: 100%; border-radius: inherit; overflow: hidden; }
.wiz-photo-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.wiz-photo-del {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.wiz-photo-del::after { content: ""; position: absolute; inset: -8px; }
.wiz-photo-del .ico { width: 12px; height: 12px; stroke-width: 2.8; }
.wiz-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1.5px dashed rgba(255, 255, 255, 0.3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.wiz-add .ico { width: 22px; height: 22px; }
.wiz-add:active { background: var(--fill); }
.wiz-photo-note { margin-top: 10px; font-size: 13.5px; font-weight: 600; color: var(--bad); }

.wiz-step { margin-top: 28px; }
.wiz-q { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.wiz-hint { margin-top: 6px; font-size: 15px; color: var(--muted); }

.choices { display: grid; gap: 8px; margin-top: 20px; }
.choices.cols { grid-template-columns: 1fr 1fr; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 0 16px;
  border-radius: 16px;
  background: var(--field);
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow 0.15s, background 0.15s;
}
.choice:active { background: #3a3a3c; }
.choice.active { background: rgba(255, 214, 10, 0.13); box-shadow: inset 0 0 0 2px var(--accent); }
.choice-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.choice > .ico { width: 20px; height: 20px; color: var(--muted); }
.choice > .ico:last-child { display: none; color: var(--accent); stroke-width: 2.4; }
.choice.active > .ico:last-child { display: block; }
.choices.cols .choice { min-height: 52px; padding: 0 12px; gap: 10px; font-size: 15.5px; }
.choices.cols .choice > .ico:last-child { display: none; }
.choices.cols .own { grid-column: 1 / -1; }
.swatch { flex: none; width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.3); }

.input {
  display: block;
  width: 100%;
  height: 58px;
  margin-top: 12px;
  padding: 0 16px;
  border: 0;
  border-radius: 16px;
  background: var(--field);
  color: #fff;
  font: 17px var(--font);
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow 0.15s;
}
.input::placeholder { color: rgba(255, 255, 255, 0.35); }
.input:focus, .input:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.wiz-hint + .input { margin-top: 20px; }
textarea.input { height: 128px; padding: 15px 16px; line-height: 1.4; resize: none; }

.summary-title { margin: 26px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.summary { border-radius: 16px; background: var(--field); overflow: hidden; }
.summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 0 12px 0 16px;
  text-align: left;
}
.summary-row + .summary-row { box-shadow: inset 0 1px rgba(255, 255, 255, 0.08); }
.summary-row:active { background: #3a3a3c; }
.summary-k { flex: none; width: 78px; font-size: 14px; color: var(--muted); }
.summary-v { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-v.empty { color: var(--bad); font-weight: 500; }
.summary-row .ico { width: 16px; height: 16px; color: rgba(255, 255, 255, 0.3); }

.wiz-next { display: block; width: 100%; height: 56px; margin-top: 24px; font-size: 17px; }

.wiz-status {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 28px 64px;
  text-align: center;
}
.status-icon {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-bottom: 14px;
  border-radius: 50%;
}
.status-icon .ico { width: 42px; height: 42px; stroke-width: 2.6; }
.wiz-status[data-kind="busy"] .status-icon { border: 4px solid var(--fill); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
.wiz-status[data-kind="busy"] .status-icon .ico { display: none; }
.wiz-status[data-kind="done"] .status-icon { background: var(--ok); color: #000; animation: pop 0.4s ease-out; }
.wiz-status[data-kind="error"] .status-icon { background: rgba(255, 69, 58, 0.16); color: var(--bad); }
@keyframes spin { to { transform: rotate(360deg); } }
.wiz-status h3 { font-size: 24px; font-weight: 700; }
.wiz-status p { max-width: 330px; color: var(--muted); font-size: 15.5px; }
.status-bar { width: min(260px, 72%); height: 5px; margin-top: 14px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.status-bar span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 0.2s; }
.wiz-status .pill-btn { width: min(320px, 100%); height: 54px; font-size: 17px; }
.wiz-status .pill-btn.accent { margin-top: 22px; }

/* ───── Настройки ───── */

.sheet-wrap { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 8px calc(20px + var(--sar)) calc(24px + var(--sab)) calc(20px + var(--sal));
  border-radius: 20px 20px 0 0;
  background: var(--sheet);
  animation: slide 0.25s ease-out;
}
@keyframes slide { from { transform: translateY(40px); opacity: 0; } }
.sheet-grip { width: 36px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); }
.sheet h2 { font-size: 20px; font-weight: 700; margin-bottom: 18px; }

.field { display: block; margin-bottom: 18px; }
.field-label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { display: block; margin-top: 7px; font-size: 12.5px; color: var(--muted); }

.field input, .field select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--field);
  color: #fff;
  font: 16px var(--font);
}
.field select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, #aaa 50%), linear-gradient(135deg, #aaa 50%, transparent 50%); background-position: right 18px center, right 13px center; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 2px; border-radius: 12px; background: var(--field); }
.seg button { height: 40px; border-radius: 10px; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }
.seg button.active { background: #636366; color: #fff; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; cursor: pointer; }
.row-title { display: block; font-weight: 600; }
.row-hint { display: block; font-size: 12.5px; color: var(--muted); }

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 99px;
  background: #39393d;
  transition: background 0.2s;
  cursor: pointer;
}
.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: var(--ok); }
.switch:checked::before { transform: translateX(20px); }

.install { margin-bottom: 18px; }
.install .pill-btn { width: 100%; height: 46px; }
.credits { font-size: 12px; color: rgba(255, 255, 255, 0.4); }
.credits a { color: inherit; }

/* ───── Телефон боком ───── */

@media (orientation: landscape) and (max-height: 560px) {
  .app { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) 112px; }
  .topbar { position: absolute; top: var(--sat); left: var(--sal); right: calc(112px + var(--sar)); }
  .stage { grid-row: 1; grid-column: 1; }
  .controls {
    grid-row: 1;
    grid-column: 2;
    grid-template-columns: none;
    grid-template-rows: 1fr auto 1fr;
    justify-items: center;
    height: auto;
    padding: 16px 0;
  }
  #switchBtn { grid-row: 1; justify-self: center; align-self: start; }
  .shutter { grid-row: 2; }
  .thumb { grid-row: 3; justify-self: center; align-self: end; }
  .flow { position: absolute; top: calc(var(--sat) + 56px); left: var(--sal); right: calc(112px + var(--sar)); height: auto; pointer-events: none; z-index: 5; }
  .flow > * { pointer-events: auto; }
  .flow-hint { background: rgba(0, 0, 0, 0.55); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
