/* bulkqr — class-driven, minimal, responsive. No framework. */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #4f46e5;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --gap: 16px;
  --maxw: 1280px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0e;
    --surface: #17171b;
    --border: #2a2a31;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --accent: #818cf8;
    --danger: #f87171;
    --ok: #4ade80;
    --warning: #fbbf24;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* width:100% matters: as a flex item with auto margins the container would
   otherwise shrink-wrap to its content's min-width and wide tables would
   stretch the page instead of scrolling inside .table-wrap. */
.container { max-width: var(--maxw); width: 100%; margin: 0 auto; padding: 0 20px; flex:1; }
main.container { padding-bottom: 32px; }

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
}

.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.02em; }
.brand span { color: var(--accent); }
/* Padded for ~44px tap targets within the 60px header. */
.nav {
  display: flex;
  align-items: center; /* Vertically centers all children */
}
.nav a { 
  margin-left: 6px;
  padding: 12px;
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  height: 100%;
}
.nav a:hover { color: var(--text); }
/* The page you're on. Colour alone would be invisible to anyone who can't see
   it, so carry the same signal in the underline — and in aria-current. */
.nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-decoration-color: var(--accent);
}
/* Help icon at the right end of the nav. Inherits .nav a's colour, hover and
   aria-current underline; this just centres the SVG within the tap target. */
.nav-help { display: inline-flex; align-items: center; }
.nav-help svg { display: block; }

/* Brand + four links won't share a 375px line — the link text alone is ~280px.
   Drop the nav onto its own full-width row rather than let the inline links'
   padding spill out of the header. */
@media (max-width: 640px) {
  .site-header .container { flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
  /* Four links total ~384px against 335px of phone, so they wrap. Centre the
     rows rather than space-between, which strands the last link on its own. */
  .nav { display: flex; flex-wrap: wrap; justify-content: center; width: 100%; }
  .nav a { margin-left: 0; padding: 6px; font-size: 0.8rem; }
}
.hero { text-align: center; padding: 48px 0 24px; }
.hero h1 { font-size: 2rem; margin: 0 0 8px; letter-spacing: -0.03em; }
.hero p { color: var(--muted); margin: 0; font-size: 1.05rem; }

main { padding-bottom: 64px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.generator {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 720px) {
  .generator { grid-template-columns: 1fr; }
  /* .preview-pane { order: -1; } */
  .row { flex-direction: column; gap: 0; }
}

.field { margin-bottom: var(--gap); }
.field label, .layout-helper { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.field .hint, .layout-helper .hint { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.field label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 0; cursor: pointer; }
.field label.check input { width: auto; margin: 0; }
.field label.check-disabled { opacity: 0.55; cursor: not-allowed; }
/* Reserves one hint line before auth resolves; padding (not child margin)
   keeps the height stable whether the slot is empty or showing a hint. */
.auth-hint-slot { padding-top: 6px; min-height: calc(0.82rem * 1.5 + 6px); }
.send-email-hint { margin: 0; font-size: 0.82rem; color: var(--muted); }

textarea, input, select {
  width: 100%;
  /* A select's automatic min-width is its widest option — the long Avery preset
     names would otherwise stretch the grid column past the card on a phone. */
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
/* 16px floor: sub-16px inputs trigger iOS zoom-on-focus. */
textarea { min-height: 30vh; resize: vertical; font-family: ui-monospace, monospace; font-size: 1rem; }
input[type="color"] { padding: 4px; height: 40px; }

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
  width: 100%;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { cursor: progress; opacity: 0.75; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); }
.btn + .btn { margin-top: 10px; }
.btn#previewBtn { margin-top: 8px; }

.preview-pane { 
  /* position: sticky; */
  /* top: 20px; */
  text-align: center;
}
.preview {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  margin-top: 6px;
}
.preview img { max-width: 100%; height: auto; image-rendering: pixelated; }
/* Transparency is visible against a checkerboard, like image editors. */
.preview img {
  background: repeating-conic-gradient(#e4e4e7 0% 25%, #ffffff 0% 50%) 0 0 / 16px 16px;
}
.preview .placeholder { color: var(--muted); font-size: 0.9rem; }

.leave-note { font-size: 0.85rem; margin: 10px 0 0; }

.status { margin-top: 14px; font-size: 0.9rem; min-height: 1.4em; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }
.status.busy { color: var(--muted); }

.credits-hint { margin: 0; font-size: 0.82rem; color: var(--muted); }
.credits-hint.warn { color: var(--danger); }

.notice {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

footer.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 12px 0;
  text-align: center;
}

/* Account / history table */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; }
.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }

/* Narrow single-card pages (account auth, password reset) */
.auth-shell { max-width: 640px; width: 100%; margin: 40px auto 0; padding: 0 20px; }
.container-narrow { max-width: 640px; }
.card-title { margin: 0 0 16px; font-size: 1.4rem; }
.hidden { display: none; }
.invisible { visibility: hidden; } /* keeps its layout box, unlike .hidden */

/* Account dashboard layout (org switcher, org card, credits, jobs) */
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn-auto { width: auto; }
.btn-auto + .btn-auto { margin-top: 0; margin-left: 6px; }
.btn-wide { width: 100%; }
.btn#newOrgBtn { align-self: flex-end; }
.mt-lg { margin-top: 40px; }
.mt-md { margin-top: 20px; }
.title-sm { margin: 0; font-size: 1.3rem; }
.title-card { margin: 0 0 12px; font-size: 1.1rem; }
.title-sub { margin: 20px 0 10px; font-size: 0.95rem; }
.muted { color: var(--muted); }
.credit-line { margin: 0; color: var(--muted); }
.field-inline { flex: 1; min-width: 200px; margin-bottom: 0; }

/* Admin back-office (tabs, sortable tables, email viewer) */
.brand a { color: inherit; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: baseline; }
.tab-btn { width: auto; padding: 8px 14px; }
.tab-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.table-wrap { overflow-x: auto; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable::after { content: " ↕"; color: var(--muted); font-weight: 400; }
th.sortable.sort-asc::after { content: " ↑"; color: var(--text); }
th.sortable.sort-desc::after { content: " ↓"; color: var(--text); }
.pager { display: flex; gap: 8px; margin-top: 12px; }
.pager .btn { margin: 0; }
.delta-pos { color: var(--ok); }
.delta-neg { color: var(--danger); }
.email-body { max-height: 420px; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.email-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, monospace; font-size: 0.8rem; }
/* Sandboxed preview iframe; white base so emails without a body colour read as intended. */
.email-frame { display: block; width: 100%; height: 480px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.email-view-toggle { display: flex; gap: 8px; margin: 0 0 12px; }

/* Prominent page-level banner (post-checkout thank-you). */
.banner {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  transition: opacity 0.5s ease;
}
.banner strong { display: block; font-size: 1.05rem; margin-bottom: 2px; }
.banner-success {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 10%, var(--surface));
}
.banner-fade { opacity: 0; }

/* Card that needs the user's attention (e.g. verify your email). */
.card-attention {
  border-color: var(--warning);
  border-left: 4px solid var(--warning);
  background: color-mix(in srgb, var(--warning) 7%, var(--surface));
}

/* Danger zone (account deletion) */
.card-danger { border-color: var(--danger); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--accent-contrast); }

/* Modal — class-toggled overlay (CSP forbids inline styles). */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-overlay.hidden { display: none; }
.modal-overlay.modal-open { opacity: 1; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.modal-title { margin: 0 0 8px; font-size: 1.25rem; }
.modal-actions { margin-top: 16px; }

/* Drag-n-drop target state for the data field. */
#dataField.dragover textarea {
  outline: 2px dashed #6366f1;
  outline-offset: 2px;
}

/* Big-file mode: rows live in memory, the textarea is a readonly summary. */
#dataField.big-data textarea {
  border-style: dashed;
  cursor: default;
}
.clear-big { margin-top: 8px; }

/* Collapsed advanced options — native disclosure, no JS. */
details.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--gap);
}
details.advanced > summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 14px;
  color: var(--muted);
}
details.advanced[open] > summary {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.advanced-body {
  padding: 14px 14px 0;
}
.sub-check {
  margin-top: 6px;
  font-weight: 400;
}

/* --- Legal pages (privacy / terms) --- */
.legal { padding-top: 24px; padding-bottom: 48px; }
.legal h1 { margin-bottom: 4px; }
.legal h2 { margin-top: 28px; margin-bottom: 8px; font-size: 1.1rem; }
.legal p, .legal li { line-height: 1.6; }
.legal ul { padding-left: 20px; margin: 8px 0; }
.legal li { margin-bottom: 6px; }

/* --- /support page ---------------------------------------------------- */
.support-intro { text-align: center; padding: 24px 0 8px; }
.support-intro h1 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: -0.02em; }
.support-intro p { color: var(--muted); margin: 0; }

.faq { margin-top: 40px; }
.faq h2 { font-size: 1.1rem; margin: 28px 0 10px; }
/* Jump-link table of contents for the FAQ categories. */
.faq-toc { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 8px 0 4px; padding: 0; list-style: none; }
.faq-toc a { color: var(--accent); font-size: 0.95rem; }

.faq details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.faq summary {
  cursor: pointer;
  font-weight: 600;
  padding: 12px 14px;
  line-height: 1.4;
}
.faq details[open] > summary { border-bottom: 1px solid var(--border); }
.faq-answer { padding: 12px 14px; }
.faq-answer p { margin: 0 0 8px; line-height: 1.6; }
.faq-answer p:last-child { margin-bottom: 0; }

/* --- /labels designer ------------------------------------------------- */
/* Scoped to wide viewports: an unconditional rule would outrank the
   max-width:720px `.generator { 1fr }` collapse — same specificity, declared
   later — and leave the designer two-column on a phone. */
@media (min-width: 721px) {
  .labels-designer { grid-template-columns: 2fr 1fr; }
}
/* Label above, controls in one row beneath it. */
.saved-configs > .row > * { flex: 1; }
/* min-width:0 lets the grid column shrink past the mock's intrinsic width;
   without it the 392px frame (PREVIEW_MAX_W + padding) pushes the whole page
   into a horizontal scroll on phones and narrow tablets. */
.labels-preview-pane { position: sticky; top: 1rem; align-self: start; display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.layout-helper {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
  text-align: left;
}
label.check.preview-borders-toggle {
  display: flex;
  align-items: center;
  width: fit-content;
  gap: 6px;
  white-space: nowrap;
  font-size: 0.85em;
}

/* The label mock: geometry rules (size, positions) are injected at runtime
   via a constructed stylesheet (CSP forbids inline styles); these are the
   static parts only. */
.label-preview-frame { display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: 8px; padding: 1rem; min-height: 10rem; max-width: 100%; overflow-x: auto; }
.label-preview { position: relative; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.15); overflow: hidden; }
.lp-qr, .lp-logo, .lp-text { position: absolute; }
.lp-qr img, .lp-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lp-qr.rot-90 img { transform: rotate(90deg); }
.lp-qr.rot-180 img { transform: rotate(180deg); }
.lp-qr.rot-270 img { transform: rotate(270deg); }
/* text-align: left resets the centring .preview-pane inherits down — the
   align-* classes below override it, but align-left has no rule to. */
.lp-text { overflow: hidden; font-family: Helvetica, Arial, sans-serif; line-height: 1.25; text-align: left; }
.lp-text .lp-row { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-text .lp-row.align-center { text-align: center; }
.lp-text .lp-row.align-right { text-align: right; }

/* Show-borders flag: 1px outlines on every placed element. */
.show-borders .label-preview { outline: 1px solid #f43f5e; }
.show-borders .lp-qr, .show-borders .lp-logo, .show-borders .lp-text { outline: 1px dashed #3b82f6; }

#pageSchematic { align-self: center; background: transparent; border: 1px solid var(--border); border-radius: 4px; width: 100%; height: auto; }
/* Wraps rather than forcing a 302px min-content on the whole form — the pinned
   .size/.align bases below can't shrink, and the form is a grid item. */
.text-row-editor { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; margin-bottom: 0.5rem; }
.text-row-editor .grow { flex: 1; }
/* Inputs are width:100%, so their auto flex-basis eats the row and squeezes
   .grow (basis 0) to nothing. Pin the two fixed controls instead. */
.text-row-editor .size { flex: 0 0 5rem; }
.text-row-editor .align { flex: 0 0 8rem; }
#previewIssues:empty { display: none; }
#previewIssues { color: var(--danger); }

/* Google sign-in button + "or" divider on the account auth card. */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  font-weight: 500;
}
.btn-google:hover {
  background: #f7f8f8;
}
.btn-google .google-g {
  flex: 0 0 auto;
}
/* One-shot attention cue, added by account.js when a Google-only account tries
   to log in with a password. Pulses the button's border and an accent ring so
   it's unmistakable; removed on animationend so it can replay. The ring colour
   starts at the accent hue with 0 alpha (not `transparent`) so it fades in/out
   cleanly instead of muddying through grey. */
.btn-google.cue {
  animation: cue-pulse 0.6s ease-in-out 3;
}
.shake {
  animation: shake 0.5s ease-in-out 2;
  transform-origin: center;
}
@keyframes cue-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent);
    border-color: #dadce0;
  }
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 65%, transparent);
    border-color: var(--accent);
  }
}
/* Reduced motion: no repeated pulsing — show the ring once and fade it out.
   Still runs an animation (not `none`) so animationend fires and account.js
   clears the class. */
@media (prefers-reduced-motion: reduce) {
  .btn-google.cue { animation: cue-fade 0.9s ease-out 1; }
  @keyframes cue-fade {
    from {
      box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 65%, transparent);
      border-color: var(--accent);
    }
    to {
      box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent);
      border-color: #dadce0;
    }
  }
}
@keyframes shake {
  0%, 100% {
    transform: translateX(0) rotate(0);
  }
  20% {
    transform: translateX(-3px) rotate(-2deg);
  }
  40% {
    transform: translateX(3px) rotate(2deg);
  }
  60% {
    transform: translateX(-2px) rotate(-1deg);
  }
  80% {
    transform: translateX(2px) rotate(1deg);
  }
}
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  margin: 1rem 0;
  font-size: 0.85rem;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.auth-divider span {
  padding: 0 0.75rem;
}

/* Sequence generator panel */
.seq-summary { font-size: 0.85rem; color: var(--muted); min-height: 1.3em; margin: 2px 0 12px; }
/* ::before glyph: errors must not be colour-only (WCAG 1.4.1) */
.seq-summary.err { color: var(--danger); }
.seq-summary.err::before { content: "⚠ "; }
