* { box-sizing: border-box; }

:root {
  --bg: #1a1b1e;
  --surface: #242528;
  --border: #3a3b3f;
  --text: #e8e6e3;
  --muted: #9a9895;
  --accent: #e8a54b;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

.app {
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.tagline {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.main { flex: 1; }

.form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.field {
  margin-bottom: 1rem;
}

.field:last-of-type { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.field input[type="text"],
.field input[type="password"],
.field select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.field select {
  cursor: pointer;
  appearance: none;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239a9895' d='M6 8L1 3h10z'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
  padding-right: 2rem;
}

.field.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field.row label { margin-bottom: 0; cursor: pointer; }

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.btn {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.primary {
  margin-top: 1rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
}

.btn.primary:hover { filter: brightness(1.1); }

.output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
}

.output[hidden] { display: none; }

.qr-wrap {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  display: inline-block;
  margin-bottom: 1rem;
}

.qr-wrap #qrcode canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.print-credentials { display: none; }

.output .hint { margin: 0 0 0.75rem; }

.actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.actions .btn { width: auto; min-width: 120px; }

.footer {
  margin-top: auto;
  padding-top: 1.5rem;
  text-align: center;
}

.footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

@media print {
  /* A4: 210mm x 297mm = 8.27in x 11.69in. iOS often ignores @page; body size in both units helps. */
  @page {
    size: A4;
    size: 8.27in 11.69in;
    margin: 0;
  }
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    width: 210mm;
    width: 8.27in;
    min-height: 297mm;
    min-height: 11.69in;
    height: 297mm;
    height: 11.69in;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .header, .form, .footer, .output .hint, .actions { display: none !important; }
  .app { max-width: none; padding: 0; min-height: 297mm; min-height: 11.69in; height: 297mm; height: 11.69in; }
  .main { height: 100%; }
  .output {
    display: flex !important;
    flex-direction: column !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 210mm !important;
    width: 8.27in !important;
    height: 297mm !important;
    height: 11.69in !important;
    margin: 0 !important;
    background: #fff !important;
    border: none;
    padding: 0;
  }
  .print-credentials {
    display: block !important;
    flex-shrink: 0;
    padding: 8mm;
    padding: 0.31in;
    text-align: center;
    font-size: 5mm;
    font-size: 0.2in;
    color: #000;
    border-top: 1px solid #333;
  }
  .print-credentials .credential-line { margin: 1mm 0; margin: 0.04in 0; }
  .print-credentials .credential-label { font-weight: 600; margin-right: 2mm; margin-right: 0.08in; }
  /* QR area: 160mm ≈ 6.3in. Explicit size in both units for iOS. */
  .qr-wrap {
    flex: 1 !important;
    min-height: 180mm;
    min-height: 7.09in;
    margin: 0;
    padding: 0;
    background: #fff;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  .qr-wrap #qrcode {
    width: 160mm !important;
    width: 6.3in !important;
    height: 160mm !important;
    height: 6.3in !important;
    min-width: 160mm;
    min-width: 6.3in;
    min-height: 160mm;
    min-height: 6.3in;
    display: block !important;
  }
  .qr-wrap #qrcode canvas {
    width: 160mm !important;
    width: 6.3in !important;
    height: 160mm !important;
    height: 6.3in !important;
    min-width: 160mm;
    min-width: 6.3in;
    min-height: 160mm;
    min-height: 6.3in;
    object-fit: contain;
    -webkit-object-fit: contain;
  }
}
