/* ==========================================================================
   QR Code Generator — style.css
   Vanilla CSS, no framework, no build step. Light/dark editor.
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --danger: #dc2626;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 3px rgba(17, 24, 39, .08), 0 8px 24px rgba(17, 24, 39, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1c1f24;
  --surface-2: #23262c;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #2f333a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App bar ---------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-bar__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.app-bar__logo {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 13px;
}
.app-bar__actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn--sm { padding: 6px 10px; font-size: 13px; }
.btn--icon { padding: 8px 10px; line-height: 1; }
.btn--ghost-danger { border-color: transparent; color: var(--danger); background: transparent; }
.btn--ghost-danger:hover { background: rgba(220, 38, 38, .1); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(380px, 500px) 1fr;
  gap: 20px;
  padding: 20px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}
.editor {
  display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 72px;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
  padding-right: 4px;
}

/* ---------- Editor group heading ---------- */
.editor__group {
  flex: none;
  margin: 8px 0 -4px 2px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); opacity: .75;
}
.editor__group:first-child { margin-top: 0; }

/* ---------- Panels ---------- */
.panel {
  flex: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel > summary {
  list-style: none; cursor: pointer;
  padding: 12px 14px;
  font-weight: 700; font-size: 13px;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); user-select: none;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after { content: "+"; float: right; font-size: 15px; }
.panel[open] > summary::after { content: "\2212"; }
.panel__body { padding: 4px 14px 16px; }

/* ---------- Fields ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field--full { grid-column: 1 / -1; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field--check { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 10px; }
.field--check > span { color: var(--text); font-weight: 500; }

/* iOS-style on/off switch — restyles the native checkbox, no markup change */
.field--check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  flex: none;
  width: 40px; height: 24px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  position: relative;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.field--check input[type="checkbox"]::before {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.field--check input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.field--check input[type="checkbox"]:checked::before { transform: translateX(16px); }
.field--check input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
[data-theme="dark"] .field--check input[type="checkbox"]::before { background: #e8eaed; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 1px; border-color: var(--accent);
}
input[type="color"] { padding: 4px; height: 38px; }
input[type="file"] { padding: 6px; background: transparent; border-style: dashed; }
input[type="checkbox"] { width: auto; }
textarea { resize: vertical; }

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
/* A hint that closes a field must not crowd the next one */
.field > .hint:last-child { margin-bottom: 16px; }
.hint--warn { color: var(--danger); font-weight: 600; }

.form-block { margin-top: 12px; }

/* ---------- Saved styles list ---------- */
.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.saved-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.saved-list__meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.saved-list__swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--border); flex: none; }
.saved-list__meta b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-list__btns { display: flex; gap: 4px; flex: none; }
.saved-list__empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

/* ---------- Preview ---------- */
.preview-wrap { display: flex; justify-content: center; padding-bottom: 40px; }
.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  position: sticky; top: 92px;
  width: 372px;
}
.qr-stage {
  width: 324px; height: 324px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--surface-2);
  transition: background .15s;
}
/* the chequerboard only earns its place when the background really is transparent */
.qr-stage--alpha {
  background-color: transparent;
  background-image:
    linear-gradient(45deg, rgba(128,128,128,.13) 25%, transparent 25%, transparent 75%, rgba(128,128,128,.13) 75%),
    linear-gradient(45deg, rgba(128,128,128,.13) 25%, transparent 25%, transparent 75%, rgba(128,128,128,.13) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}
.qr-stage svg { width: 100%; height: 100%; display: block; border-radius: 8px; }

/* empty / error state — calm, not alarming */
.qr-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted); text-align: center; padding: 24px; max-width: 250px;
}
.qr-empty svg { width: 44px; height: 44px; opacity: .35; border-radius: 0; }
.qr-empty p { margin: 0; font-size: 13px; line-height: 1.5; }
.qr-empty--error { color: var(--danger); }
.qr-empty--error svg { opacity: .5; }

.qr-meta {
  margin: 0; font-size: 12px; color: var(--muted); text-align: center;
  letter-spacing: .01em;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #14181f; color: #fff;
  padding: 10px 18px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .editor { position: static; max-height: none; overflow: visible; }
  .preview-card { position: static; }
}
@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  .app-bar { flex-direction: column; align-items: stretch; }
  .preview-card { padding: 18px; }
  .qr-stage { width: min(300px, 80vw); height: min(300px, 80vw); }
}

/* ---------- Scannability checks ---------- */
.checks { display: flex; flex-direction: column; gap: 6px; max-width: 340px; width: 100%; }
.check {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  padding: 8px 10px 8px 26px;
  border-radius: var(--radius-sm);
  position: relative;
}
.check::before {
  position: absolute; left: 9px; top: 8px;
  font-weight: 700; font-size: 12px;
}
.check--ok    { background: rgba(22, 163, 74, .10);  color: #15803d; }
.check--warn  { background: rgba(217, 119, 6, .12);  color: #b45309; }
.check--bad   { background: rgba(220, 38, 38, .12);  color: #b91c1c; font-weight: 600; }
.check--ok::before   { content: "\2713"; }
.check--warn::before { content: "!"; }
.check--bad::before  { content: "\00d7"; }

[data-theme="dark"] .check--ok   { background: rgba(34, 197, 94, .14);  color: #4ade80; }
[data-theme="dark"] .check--warn { background: rgba(245, 158, 11, .16); color: #fbbf24; }
[data-theme="dark"] .check--bad  { background: rgba(248, 113, 113, .16); color: #fca5a5; }

/* ---------- Button row ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Mode switch ---------- */
.mode-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.mode-switch__btn {
  appearance: none; border: 0; background: transparent;
  font: inherit; font-weight: 600; font-size: 13px;
  color: var(--muted);
  padding: 6px 18px; border-radius: 999px; cursor: pointer;
  transition: background .14s, color .14s;
}
.mode-switch__btn:hover { color: var(--text); }
.mode-switch__btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

/* ---------- Mode visibility ---------- */
body[data-mode="single"] .only-batch,
body[data-mode="batch"]  .only-single { display: none !important; }

/* ---------- Batch sheet ---------- */
.batch-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 900px;
  align-content: start;
}
.batch-sheet > .qr-empty,
.batch-sheet > .hint { grid-column: 1 / -1; }
.batch-sheet > .qr-empty {
  justify-self: center;
  max-width: 340px;
  padding: 48px 24px;
}
.batch-sheet code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 4px; font-size: 11.5px;
}

.batch-cell {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  break-inside: avoid;
}
.batch-cell svg { width: 100%; height: auto; display: block; }
.batch-cell figcaption {
  font-size: 12px; font-weight: 600; color: var(--text);
  text-align: center; word-break: break-word; line-height: 1.35;
}
.batch-cell--bad { border-color: var(--danger); }
.batch-cell__err {
  color: var(--danger); font-size: 12px; font-weight: 600;
  padding: 28px 0;
}

/* ---------- Print ---------- */
@media print {
  .app-bar, .editor, .no-print, .checks, .qr-meta { display: none !important; }
  body { background: #fff; }
  .layout { display: block; padding: 0; max-width: none; }
  .preview-wrap { display: block; padding: 0; }
  .batch-sheet {
    max-width: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 10mm;
  }
  .batch-cell { border-color: #ccc; padding: 6mm; }
  .preview-card { border: 0; box-shadow: none; position: static; width: auto; }
  .qr-stage { background: none !important; }
  @page { size: A4; margin: 12mm; }
}

/* Location confirmation — plain-language replacement for raw coordinates */
.pinned {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
}
.pinned__icon { color: #16a34a; font-size: 11px; }
.pinned__text { flex: 1; color: var(--muted); }
.pinned__text b { color: var(--text); font-variant-numeric: tabular-nums; }

/* A disclosure for the settings only a power user opens */
details.subtle { margin-top: 4px; }
details.subtle > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
  list-style: none;
}
details.subtle > summary::-webkit-details-marker { display: none; }
details.subtle > summary::before { content: "\25B8"; display: inline-block; margin-right: 6px; transition: transform .15s; }
details.subtle[open] > summary::before { transform: rotate(90deg); }
details.subtle > summary:hover { color: var(--accent); }
details.subtle > .grid-2 { padding-top: 6px; }

/* One-line explanation at the top of a panel */
.lede {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

/* ---------- Segmented control (matches image tool & invoice) ---------- */
.seg-row {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg-row button {
  appearance: none; flex: 1 1 auto; min-width: 52px;
  padding: 7px 8px; border: 0;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer; transition: background .12s, color .12s;
}
.seg-row button:hover { color: var(--text); }
.seg-row button.is-active {
  background: var(--surface); color: var(--accent);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .12);
}
[data-theme="dark"] .seg-row button.is-active { background: #2a2f3a; }

/* ---------- Help modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 20px;
  background: rgba(10, 13, 18, .55);
}
.modal__box {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  padding: 20px 22px; max-width: 620px; width: 100%;
}
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal__head h3 { margin: 0; font-size: 17px; }
.modal__lead { color: var(--muted); margin: 0 0 6px; }
.modal__scroll { max-height: 64vh; overflow-y: auto; padding-right: 4px; }
.modal__scroll h4 {
  margin: 16px 0 4px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.modal__scroll p { margin: 4px 0; }
.modal__scroll b { color: var(--text); }
.modal__actions { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ---------- Password field with reveal toggle ---------- */
.pw-field { position: relative; display: flex; }
.pw-field input { padding-right: 60px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  appearance: none; border: 0; background: transparent;
  color: var(--accent); font: inherit; font-weight: 600; font-size: 12px;
  cursor: pointer; padding: 4px 6px; border-radius: 5px;
}
.pw-toggle:hover { background: var(--surface-2); }
