:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #10151c;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f8cff;
  --accent2: #2f6feb;
  --danger: #ff6b6b;
  --ok: #69db7c;
  --paper: #ffffff;
  --paper-text: #111111;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 430px 1fr;
  gap: 20px;
}

.panel,
.preview-panel {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
}

.title-row,
.preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1, h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.privacy-badge,
#countBadge {
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
}

.notice {
  margin: 18px 0;
  padding: 12px 14px;
  background: rgba(79, 140, 255, 0.10);
  border: 1px solid rgba(79, 140, 255, 0.24);
  border-radius: 14px;
  color: #dbe8ff;
  line-height: 1.45;
}

label {
  display: block;
  margin: 0 0 8px;
  font-weight: 650;
}

textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #05080d;
  color: var(--text);
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 16px;
  line-height: 1.45;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.16);
}

.hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  background: #21262d;
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent2);
  border-color: var(--accent2);
}

button.ghost {
  background: transparent;
}

.status {
  min-height: 22px;
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

.screen-preview {
  margin-top: 16px;
  background: #0b0f14;
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 16px;
  min-height: 360px;
  overflow: auto;
}

.screen-preview.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.preview-card {
  background: var(--paper);
  color: var(--paper-text);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 62mm 78.88mm;
  gap: 18mm;
  align-items: center;
  overflow-x: auto;
}

.preview-card:last-child {
  margin-bottom: 0;
}

.preview-code {
  text-align: center;
}

.preview-code svg {
  display: block;
  margin: 0 auto;
  height: 16mm;
  max-width: 100%;
}

.preview-code span {
  display: block;
  margin-top: 2.2mm;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 13pt;
  font-weight: 400;
  letter-spacing: 0;
}

.print-area {
  display: none;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    padding: 14px;
  }
}

@media print {
  html, body {
    width: 210mm;
    min-height: 297mm;
    background: #ffffff !important;
  }

  .app {
    display: none !important;
  }

  .print-area {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }

  .print-sheet {
    position: relative;
    width: 210mm;
    height: 297mm;
    background: #ffffff;
    color: #000000;
    page-break-after: always;
    overflow: hidden;
  }

  .print-sheet:last-child {
    page-break-after: auto;
  }

  /* Layout anti-piega: nessun barcode attraversa x=105mm o y=148.5mm. */
  .barcode-block {
    position: absolute;
    text-align: center;
    color: #000000;
  }

  .barcode-block svg {
    display: block;
    height: 16mm;
    margin: 0 auto;
  }

  .barcode-block .human-text {
    margin-top: 2.2mm;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 13pt;
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0;
  }
}
