/* ---- Colour themes -----------------------------------------------------------------------
 * The UI follows the operating system's light/dark setting (prefers-color-scheme), e.g. the
 * Windows "Choose your mode" setting. Only the app chrome changes: the QR preview, the print
 * preview and every export are drawn with their own colours on white "paper", so downloads and
 * printouts never come out dark. All pairs below meet WCAG 2.1 AA (text >= 4.5:1, borders and
 * focus >= 3:1) in both themes; tests/e2e/a11y.spec.js runs axe in light and dark. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #ffffff;          /* popovers, buttons, inputs */
  --surface-hover: #f3f4f6;
  --button-bg: #f0f0f0;        /* main action buttons */
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --text-sub: #666666;
  --border-control: #767676;   /* borders of interactive controls (>= 3:1) */
  --border-soft: #dddddd;      /* decorative separators */
  --border-strong: #1f2937;
  --focus: #1d4ed8;
  --pill-checked-bg: #1a1a1a;
  --pill-checked-text: #ffffff;
  --shadow: rgba(0, 0, 0, 0.12);
  --paper: #ffffff;            /* QR and print previews: always white, like the output */
  --notice-text: #6b4f12; --notice-bg: #fcf3e3; --notice-border: #f0dfb5;
  --error-text: #9b1c1c; --error-bg: #fdecec; --error-border: #f5c2c2;
  --status-text: #4b5563; --status-bg: #f9fafb; --status-border: #e5e7eb;
  --ok-text: #14532d; --ok-bg: #f0fdf4; --ok-border: #bbf7d0; --ok-icon: #15803d;
  --warn-text: #78350f; --warn-bg: #fffbeb; --warn-border: #fde68a; --warn-icon: #b45309;
  --fail-text: #7f1d1d; --fail-bg: #fef2f2; --fail-border: #fecaca; --fail-icon: #dc2626;
  --qr-error: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1c1f24;
    --surface-hover: #2a2f36;
    --button-bg: #2f343c;
    --text: #e8eaed;
    --text-muted: #a3a9b3;
    --text-sub: #b3b9c2;
    --border-control: #8b9099;
    --border-soft: #353a42;
    --border-strong: #e8eaed;
    --focus: #8ab4f8;
    --pill-checked-bg: #e8eaed;
    --pill-checked-text: #121417;
    --shadow: rgba(0, 0, 0, 0.5);
    --notice-text: #f5dfae; --notice-bg: #33280f; --notice-border: #6b5520;
    --error-text: #fecaca; --error-bg: #3b1515; --error-border: #7f2a2a;
    --status-text: #c9ced6; --status-bg: #1c1f24; --status-border: #353a42;
    --ok-text: #bbf7d0; --ok-bg: #0d2a18; --ok-border: #1f6b3a; --ok-icon: #15803d;
    --warn-text: #fde68a; --warn-bg: #2e230a; --warn-border: #7a5a12; --warn-icon: #b45309;
    --fail-text: #fecaca; --fail-bg: #3b1515; --fail-border: #7f2a2a; --fail-icon: #dc2626;
    --qr-error: #ff8a80;
  }
}

/* Printing the page itself (Ctrl+P) always uses the light theme. The real print layouts are
 * PDFs built by js/print-layouts.js and are not affected by CSS at all. */
@media print {
  :root {
    color-scheme: light;
    --bg: #ffffff; --surface: #ffffff; --text: #1a1a1a; --text-muted: #4b5563; --text-sub: #4b5563;
    --border-control: #767676; --border-soft: #dddddd; --button-bg: #f0f0f0;
    --pill-checked-bg: #1a1a1a; --pill-checked-text: #ffffff;
    --notice-text: #6b4f12; --notice-bg: #fcf3e3; --notice-border: #f0dfb5;
    --error-text: #9b1c1c; --error-bg: #fdecec; --error-border: #f5c2c2;
    --status-text: #4b5563; --status-bg: #f9fafb; --status-border: #e5e7eb;
    --ok-text: #14532d; --ok-bg: #f0fdf4; --ok-border: #bbf7d0;
    --warn-text: #78350f; --warn-bg: #fffbeb; --warn-border: #fde68a;
    --fail-text: #7f1d1d; --fail-bg: #fef2f2; --fail-border: #fecaca;
    --surface-hover: #f3f4f6; --border-strong: #1f2937; --focus: #1d4ed8; --shadow: rgba(0, 0, 0, 0.12);
    --paper: #ffffff; --qr-error: #c0392b;
    --ok-icon: #15803d; --warn-icon: #b45309; --fail-icon: #dc2626;
  }
  /* The Wi-Fi password is never printed, not even when "Show" or "Create a strong password"
   * has turned the field into plain text (AGENTS.md rule 2). */
  #pswd { visibility: hidden; }
}

  * { box-sizing: border-box; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px 60px;
    color: var(--text);
    background: var(--bg);
  }
  .top-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
  .lang-picker { position: relative; }
  .lang-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border-control);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }
  .lang-btn img { width: 20px; height: 15px; border-radius: 2px; display: block; }
  .lang-btn .lang-caret { font-size: 10px; color: var(--text-muted); margin-left: 2px; }
  .lang-popover {
    display: none;
    position: absolute;
    top: 42px;
    right: 0;
    z-index: 40;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    box-shadow: 0 8px 24px var(--shadow);
    padding: 6px;
    min-width: 150px;
  }
  .lang-popover.open { display: block; }
  .lang-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    border: none;
    background: none;
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
  }
  .lang-option:hover { background: var(--surface-hover); }
  .lang-option img { width: 20px; height: 15px; border-radius: 2px; }
  .layout { display: flex; gap: 32px; align-items: flex-start; }
  .form-col { flex: 1; min-width: 0; }
  .preview-col {
    width: 320px;
    flex-shrink: 0;
    position: sticky;
    top: 20px;
  }
  @media (max-width: 760px) {
    .layout { display: block; }
    .preview-col {
      width: 100%;
      position: sticky;
      top: 0;
      z-index: 30;
      background: var(--bg);
      padding-bottom: 12px;
      margin-bottom: 8px;
      box-shadow: 0 6px 12px -8px var(--shadow);
    }
    #qrcode { max-width: 280px; margin: 0 auto; }
  }
  h1 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
  p.sub { color: var(--text-sub); font-size: 14px; margin-top: 0; margin-bottom: 24px; }
  details {
    border-top: 1px solid var(--border-soft);
    margin-top: 20px;
    padding-top: 4px;
  }
  details summary {
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    padding: 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
  }
  details summary::-webkit-details-marker { display: none; }
  details summary::after {
    content: "▾";
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.15s ease;
  }
  details[open] summary::after { transform: rotate(180deg); }
  details .details-body { padding-bottom: 8px; }
  label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    margin-top: 16px;
  }
  input[type=text], input[type=password], input[type=number], input[type=email], input[type=tel], textarea, select {
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    border: 1px solid var(--border-control);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
  }
  input[type=date], input[type=time] {
    padding: 9px 12px;
    font-size: 15px;
    border: 1px solid var(--border-control);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
  }
  input[type=range] { width: 100%; }
  .color-picker { position: relative; display: inline-block; }
  .color-swatch-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    box-shadow: 0 0 0 2px var(--border-control);
    cursor: pointer;
    padding: 0;
  }
  .color-popover {
    display: none;
    position: absolute;
    top: 48px;
    left: 0;
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    padding: 12px;
    width: 200px;
  }
  .color-popover.open { display: block; }
  .swatch-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 10px;
  }
  .swatch-grid button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    box-shadow: 0 0 0 1px var(--border-control);
    cursor: pointer;
    padding: 0;
  }
  .swatch-grid button.selected { box-shadow: 0 0 0 2px var(--text); }
  .brand-grid { padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); }
  .hex-input-row .brand-add { flex: none; width: 32px; padding: 4px 0; font-weight: bold; }
  .brand-palette-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 12px; }
  .brand-palette-row .hint { flex-basis: 100%; margin: 0; }
  .hex-input-row { display: flex; align-items: center; gap: 8px; }
  .hex-input-row input[type=text] {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    margin: 0;
  }
  .row { display: flex; gap: 12px; align-items: flex-end; }
  .row > div { flex: 1; }
  .pwd-wrap { position: relative; }
  .pwd-wrap button {
    position: absolute;
    right: 6px;
    top: 6px;
    bottom: 6px;
    border: none;
    background: var(--button-bg);
    color: var(--text);
    border-radius: 6px;
    padding: 0 12px;
    font-size: 12px;
    cursor: pointer;
  }
  .btn-row { display: flex; gap: 10px; margin-top: 20px; }
  .btn-row button {
    flex: 1;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
  }
  #download { background: var(--button-bg); color: var(--text); }
  #download:disabled { opacity: 0.4; cursor: not-allowed; }
  .qr-box { margin-top: 28px; text-align: center; }
  #qrcode {
    display: block;
    padding: 16px;
    background: var(--paper);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
  }
  #qrcode canvas { display: block; width: 100%; height: auto; }
  .qr-error { color: var(--qr-error); font-weight: 700; }
  .scan-status {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    border-radius: 8px;
    border: 1px solid var(--status-border);
    background: var(--status-bg);
    color: var(--status-text);
  }
  .scan-status[hidden] { display: none; }
  .scan-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    color: #fff;
    background: #6b7280;
  }
  .scan-status[data-state=ok] { color: var(--ok-text); background: var(--ok-bg); border-color: var(--ok-border); }
  .scan-status[data-state=ok] .scan-icon { background: var(--ok-icon); }
  .scan-status[data-state=warn] { color: var(--warn-text); background: var(--warn-bg); border-color: var(--warn-border); }
  .scan-status[data-state=warn] .scan-icon { background: var(--warn-icon); }
  .scan-status[data-state=fail] { color: var(--fail-text); background: var(--fail-bg); border-color: var(--fail-border); }
  .scan-status[data-state=fail] .scan-icon { background: var(--fail-icon); }
  .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
  .notice {
    font-size: 12px;
    color: var(--notice-text);
    background: var(--notice-bg);
    border: 1px solid var(--notice-border);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 10px;
  }
  .notice-error {
    color: var(--error-text);
    background: var(--error-bg);
    border-color: var(--error-border);
  }
  .inline-check { margin-top: 12px; }
  .inline-check input { width: auto; display: inline-block; margin-right: 6px; }
  .logo-row { display: flex; align-items: center; gap: 12px; }
  .logo-preview {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
  }
  .logo-preview img { max-width: 100%; max-height: 100%; }
  .logo-none { font-size: 10px; color: #6b7280; }
  .file-btn {
    padding: 8px 14px;
    font-size: 13px;
    border: 1px solid var(--border-control);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }
  .small-btn {
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid var(--border-control);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }

/* Utility classes replacing former inline styles (inline styles are blocked by the CSP). */
.is-hidden { display: none; }
.btn-row-top { margin-top: 0; }
.demo-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.hex-prefix { font-size: 13px; color: var(--text-muted); }
.inline-check-spaced { margin-top: 16px; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 8px 0; }
.template-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-control); border-radius: 10px; cursor: pointer;
}
.template-btn:hover, .template-btn:focus-visible { border-color: var(--border-strong); }
.template-thumb { display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 1; background: var(--paper); border-radius: 6px; overflow: hidden; }
.template-thumb canvas { max-width: 100%; max-height: 100%; }
.template-label { font-size: 13px; text-align: center; }
.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.preset-row .field-label { width: 100%; margin: 0; }
#captionSuggestions { margin-top: 10px; }
.gen-pwd-btn { margin-top: 8px; }
.design-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.design-row .file-btn { margin: 0; font-weight: 600; font-family: inherit; }
.small-btn:hover, .small-btn:focus-visible { border-color: var(--border-strong); }
.logo-row .file-btn { margin: 0; }
.lang-btn img, .lang-option img { object-fit: cover; }

/* ---- Accessibility (WCAG 2.1 AA) ----------------------------------------------------------
 * Colors above were chosen for >= 4.5:1 text contrast and >= 3:1 for component borders (1.4.3, 1.4.11). */

/* Captions for the custom color pickers look like labels but name the controls via aria-labelledby. */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  margin-top: 16px;
}

/* Firefox renders placeholders at reduced opacity (~3.4:1); make them explicit. */
::placeholder { color: var(--text-muted); opacity: 1; }

/* One clearly visible focus indicator for every interactive element (2.4.7). */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.color-swatch-btn:focus-visible,
.swatch-grid button:focus-visible { outline-offset: 3px; }

/* Keeps the file input focusable and announced while the styled label acts as the button (2.1.1). */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
#logoFile:focus-visible + .file-btn,
#designFile:focus-visible + .file-btn {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  details summary::after { transition: none; }
}

/* ---- Print layouts ---------------------------------------------------------------------- */
.print-preview {
  margin-top: 16px;
  max-width: 280px;
}
.print-preview canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border-soft);
  box-shadow: 0 4px 14px var(--shadow);
}
#printDownload { background: var(--button-bg); color: var(--text); }
#printDownload:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- QR type picker (native radios, styled as a segmented control) ----------------------- */
.type-picker {
  border: 0;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.type-picker legend {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  padding: 0;
}
.type-option {
  position: relative;
  display: inline-flex;
  margin: 0;
  font-weight: 500;
}
.type-option input {
  /* Visually hidden but focusable: arrow keys move between radios natively. */
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.type-option span {
  display: inline-block;
  padding: 7px 12px;
  font-size: 13px;
  border: 1px solid var(--border-control);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.type-option input:checked + span {
  background: var(--pill-checked-bg);
  border-color: var(--pill-checked-bg);
  color: var(--pill-checked-text);
}
.type-option input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.type-panel[hidden] { display: none; }
textarea {
  font-family: inherit;
  line-height: 1.4;
  resize: vertical;
}
