:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #16191f;
  --muted: #646b78;
  --line: #e2e5ea;
  --soft: #eef0f3;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --accent-soft: #e6edfc;
  --ok: #23774a;
  --ok-soft: #e3f3ea;
  --warn: #9a5a00;
  --warn-soft: #fbf0dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 31, 0.05), 0 4px 16px rgba(20, 24, 31, 0.05);
  --checker: #e9ebef;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2026;
    --ink: #e9ebef;
    --muted: #9aa1ad;
    --line: #2d3139;
    --soft: #262a31;
    --accent: #6d94f5;
    --accent-ink: #0f1420;
    --accent-soft: #24304b;
    --ok: #6fd39b;
    --ok-soft: #1c3428;
    --warn: #f0b764;
    --warn-soft: #3a2e1b;
    --shadow: none;
    --checker: #2a2e35;
    color-scheme: dark;
  }
}

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

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* Анимация нажатия на каждой кнопке */
button, .btn { transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease; }
button:active:not(:disabled), .btn:active { transform: scale(0.95); }

/* ---------- шапка ---------- */
.topbar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }

.tabs {
  display: inline-flex;
  background: var(--soft);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.tab {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 9px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

main { max-width: 1080px; margin: 0 auto; padding: 8px 16px 24px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

/* ---------- раскладка «Создать» ---------- */
.create-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 400px);
  grid-template-areas:
    "input    preview"
    "settings preview";
  align-items: start;
}
.area-input { grid-area: input; }
.area-settings { grid-area: settings; }
.area-preview { grid-area: preview; position: sticky; top: 12px; }

@media (max-width: 820px) {
  .create-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "input" "preview" "settings";
  }
  .area-preview { position: static; }
}

.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--muted);
  margin: 16px 0 8px;
}
.field-label:first-child { margin-top: 0; }
.area-input .seg + div .field-label { margin-top: 14px; }

textarea, input[type="text"], input[type="tel"], input[type="email"], input[type="number"], input:not([type]) {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
textarea { resize: vertical; min-height: 84px; }
textarea:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.hint { color: var(--muted); font-size: 0.83rem; margin-top: 6px; min-height: 0; }
.hint:empty { display: none; }
.hint.warn { color: var(--warn); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 14px; }
.form-grid label span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- сегментные переключатели ---------- */
.seg { display: flex; gap: 6px; }
.seg-wrap { flex-wrap: wrap; }
.seg > button {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.seg > button:hover { border-color: var(--muted); }
.seg > button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--accent);
}
#mode-seg { background: var(--soft); padding: 4px; border-radius: 12px; gap: 4px; }
#mode-seg > button { border: 0; background: transparent; color: var(--muted); font-weight: 600; }
#mode-seg > button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.size-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 110px;
}
.size-custom input { width: 100%; min-width: 70px; padding: 8px 10px; }
.size-custom span { color: var(--muted); font-size: 0.85rem; }

.sw { width: 16px; height: 16px; border-radius: 4px; display: inline-block; border: 1px solid var(--line); flex: none; }
.sw-bw { background: linear-gradient(135deg, #000 50%, #fff 50%); }
.sw-wb { background: linear-gradient(135deg, #fff 50%, #000 50%); }
.sw-custom { background: conic-gradient(#e5484d, #f5a524, #30a46c, #2f5bd3, #8e4ec6, #e5484d); }

.st { width: 16px; height: 16px; display: inline-block; flex: none; background: currentColor; }
.st-square {
  background:
    linear-gradient(currentColor 0 0) 0 0 / 7px 7px no-repeat,
    linear-gradient(currentColor 0 0) 9px 0 / 7px 7px no-repeat,
    linear-gradient(currentColor 0 0) 9px 9px / 7px 7px no-repeat;
}
.st-rounded { border-radius: 5px 1px 5px 1px; }
.st-dots { background: radial-gradient(circle, currentColor 3px, transparent 3.5px) 0 0 / 8px 8px; }

.custom-colors { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.color-pick {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px; padding: 4px 12px 4px 4px; cursor: pointer;
}
.color-pick input { width: 34px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }

.check-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; cursor: pointer; user-select: none; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
#caption { margin-top: 10px; }

.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#logo-thumb {
  width: 44px; height: 44px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line);
  background: repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 0 0 / 12px 12px;
}

details.more { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--muted); }

/* ---------- кнопки ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.done { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.actions .btn { flex: 1 1 auto; }
.actions.center { justify-content: center; }
.actions.center .btn { flex: 0 1 auto; }

/* ---------- превью ---------- */
.preview-box {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 0 0 / 20px 20px;
  border: 1px solid var(--line);
  overflow: hidden;
  padding: 14px;
}
.preview-box.has-frame { aspect-ratio: auto; }
#preview-img { max-width: 100%; max-height: 100%; display: block; image-rendering: auto; }
.preview-empty { color: var(--muted); text-align: center; font-size: 0.9rem; padding: 24px; }

.check {
  margin-top: 12px;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}
.check.ok { background: var(--ok-soft); color: var(--ok); }
.check.bad { background: var(--warn-soft); color: var(--warn); }
.check.pending { background: var(--soft); color: var(--muted); }

.meta { color: var(--muted); font-size: 0.8rem; margin-top: 8px; word-break: break-word; }
.meta:empty { display: none; }

/* ---------- чтение ---------- */
.read-wrap { max-width: 720px; margin: 0 auto; display: grid; gap: 16px; }

.drop {
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 36px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  outline: none;
}
.drop:hover, .drop:focus-visible { border-color: var(--accent); }
.drop.over, body.dragging .drop { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { color: var(--accent); margin-bottom: 8px; }
.drop-title { font-weight: 600; font-size: 1.05rem; }
.drop-sub { color: var(--muted); font-size: 0.86rem; margin-top: 4px; }
kbd {
  font: 600 0.78rem ui-monospace, Consolas, monospace;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--soft);
}

.camera {
  position: relative;
  margin-top: 16px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-frame {
  position: absolute; inset: 0; margin: auto;
  width: 62%; aspect-ratio: 1 / 1; height: auto; top: 50%; transform: translateY(-50%);
  border: 3px solid rgba(255, 255, 255, 0.9); border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
}
.cam-stop { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); }
.cam-stop:active { transform: translateX(-50%) scale(0.95); }

.read-result { display: grid; gap: 16px; }
.source-card { padding: 10px; display: grid; place-items: center; }
#source-canvas { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; }

.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.badge {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 0.78rem; letter-spacing: 0.02em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px;
}
.result-title { font-weight: 700; font-size: 1.05rem; word-break: break-word; }
.result-host { font-size: 1.25rem; font-weight: 700; word-break: break-all; }
.result-sub { color: var(--muted); font-size: 0.85rem; }

.fields { display: grid; gap: 8px; margin: 4px 0 6px; }
.field {
  display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.field:last-child { border-bottom: 0; }
.field .k { color: var(--muted); font-size: 0.85rem; }
.field .v { word-break: break-word; font-weight: 500; white-space: pre-wrap; }
@media (max-width: 480px) {
  .field { grid-template-columns: minmax(0, 1fr) auto; }
  .field .k { grid-column: 1 / -1; margin-bottom: -6px; }
}

.raw {
  width: 100%;
  font: 0.86rem/1.45 ui-monospace, Consolas, monospace;
  min-height: 60px;
  margin-top: 10px;
  background: var(--bg);
}
.raw-label { margin-top: 14px; }

.notice { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 0.85rem; }
.empty-result { text-align: center; color: var(--muted); }
.empty-result b { color: var(--ink); display: block; margin-bottom: 6px; font-size: 1.02rem; }

.foot { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 8px 16px 28px; }

/* ---------- тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  max-width: calc(100vw - 48px);
  background: #22262d;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: #9b2c1c; }
.toast.toast-success { background: #23774a; }
