:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2433;
  --muted: #657084;
  --line: #d8dee9;
  --primary: #1f6feb;
  --danger: #c93636;
  --success: #197a44;
  --warning: #9a6700;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: #162033;
  color: #fff;
  padding: 24px 18px;
}

.brand {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 28px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a,
.logout-button {
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #dbe6ff;
  cursor: pointer;
  display: block;
  font: inherit;
  padding: 10px 12px;
  text-align: left;
  width: 100%;
}

.nav a:hover,
.logout-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.content {
  padding: 28px;
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.stats {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: 16px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 750;
}

.muted {
  color: var(--muted);
}

.button,
button {
  align-items: center;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  min-height: 40px;
  padding: 8px 13px;
}

.button.secondary {
  background: #fff;
  color: var(--primary);
}

.button.danger,
button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-form {
  display: grid;
  gap: 10px;
  min-width: 420px;
}

.template-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.template-options label,
.template-remove {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 0.86rem;
  gap: 5px;
}

.template-options input,
.template-remove input {
  min-height: auto;
  width: auto;
}

.template-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.template-background {
  align-items: center;
  display: flex;
  gap: 10px;
}

.template-background img {
  border: 1px solid var(--line);
  border-radius: 4px;
  height: 42px;
  object-fit: cover;
  width: 68px;
}

.ticket-preview-title {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.ticket-preview {
  transform: scale(0.74);
  transform-origin: top left;
}

.qr-placeholder {
  align-items: center;
  aspect-ratio: 1;
  background: repeating-linear-gradient(45deg, #111827 0 3px, #fff 3px 6px);
  border: 1px solid #111827;
  display: grid;
  font-size: 8pt;
  font-weight: 800;
  height: var(--qr-size, 28mm);
  justify-items: center;
  padding: var(--qr-padding, 1mm);
  transform: translate(var(--qr-offset-x, 0), var(--qr-offset-y, 0));
  width: var(--qr-size, 28mm);
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.92rem;
  gap: 6px;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  min-height: 40px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.full {
  grid-column: 1 / -1;
}

.flash {
  border-radius: var(--radius);
  margin-bottom: 16px;
  padding: 12px 14px;
}

.flash.success {
  background: #e7f5ed;
  color: var(--success);
}

.flash.error {
  background: #fdecec;
  color: var(--danger);
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-box {
  max-width: 420px;
  width: 100%;
}

.print-body {
  background: #fff;
  color: #111827;
}

.print-toolbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 12px 18px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.print-sheet {
  display: grid;
  gap: 5mm;
  grid-template-columns: repeat(2, 85mm);
  margin: 12mm auto;
  width: 175mm;
}

.ticket-card {
  align-items: stretch;
  background: #fff;
  border: 0.35mm solid #222;
  border-radius: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  display: grid;
  grid-template-columns: 1fr 31mm;
  height: 55mm;
  overflow: hidden;
  page-break-inside: avoid;
  width: 85mm;
}

.ticket-info {
  background: rgba(255, 255, 255, var(--panel-opacity, 0.88));
  display: grid;
  gap: 1.5mm;
  padding: 5mm 3mm 4mm 5mm;
}

.ticket-event {
  font-size: 12pt;
  font-weight: 800;
  line-height: 1.1;
}

.ticket-meta,
.ticket-type {
  font-size: 7.5pt;
  line-height: 1.25;
}

.ticket-code {
  align-self: end;
  border-top: 0.25mm solid #d1d5db;
  font-size: 10pt;
  font-weight: 800;
  padding-top: 2mm;
}

.ticket-code.no-separator {
  border-top: 0;
  padding-top: 0;
}

.ticket-qr {
  align-items: center;
  background: rgba(255, 255, 255, var(--panel-opacity, 0.92));
  border-left: 0.25mm dashed #9ca3af;
  display: grid;
  justify-items: center;
  padding: 0;
}

.ticket-qr.no-separator {
  border-left: 0;
}

.ticket-qr svg {
  background: #fff;
  display: block;
  height: var(--qr-size, 28mm);
  padding: var(--qr-padding, 1mm);
  transform: translate(var(--qr-offset-x, 0), var(--qr-offset-y, 0));
  width: var(--qr-size, 28mm);
}

.single-ticket-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20mm;
}

.single-ticket-page .ticket-card {
  transform: scale(1.8);
  transform-origin: center;
}

.public-page {
  background: #eef2f7;
  min-height: 100vh;
}

.public-shell {
  margin: 0 auto;
  max-width: 560px;
  padding: 22px;
}

.public-card {
  padding: 22px;
}

.public-card h1 {
  font-size: 1.65rem;
  line-height: 1.15;
  margin: 10px 0;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.84rem;
  font-weight: 750;
  margin: 0;
  padding: 6px 10px;
}

.status-pill.success {
  background: #e7f5ed;
  color: var(--success);
}

.status-pill.danger {
  background: #fdecec;
  color: var(--danger);
}

.ticket-summary {
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 14px 0;
}

.ticket-summary div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.ticket-summary dt {
  color: var(--muted);
  font-weight: 650;
}

.ticket-summary dd {
  font-weight: 750;
  margin: 0;
  text-align: right;
}

.confirmation-box {
  background: #f6f7f9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 16px 0;
  padding: 14px;
}

.confirmation-box h2 {
  font-size: 1.15rem;
  margin: 0 0 10px;
}

.validator-panel {
  display: grid;
  gap: 14px;
}

.scanner-box {
  background: #0f172a;
  border-radius: var(--radius);
  color: #e5e7eb;
  display: grid;
  gap: 10px;
  overflow: hidden;
  padding: 10px;
}

#qr-video {
  aspect-ratio: 4 / 3;
  background: #111827;
  border-radius: 6px;
  object-fit: cover;
  width: 100%;
}

#qr-reader {
  background: #111827;
  border-radius: 6px;
  display: none;
  overflow: hidden;
  width: 100%;
}

#qr-reader video {
  width: 100%;
}

.validation-result {
  border-radius: var(--radius);
  padding: 22px;
}

.validation-result.success {
  background: #e7f5ed;
  border: 1px solid #95d5ad;
  color: #135c35;
}

.validation-result.warning {
  background: #fff8db;
  border: 1px solid #eac54f;
  color: #6f4e00;
}

.validation-result.danger {
  background: #fdecec;
  border: 1px solid #ee9b9b;
  color: #8f2424;
}

@page {
  margin: 10mm;
  size: A4;
}

@media print {
  .print-toolbar {
    display: none;
  }

  .print-sheet {
    margin: 0 auto;
  }

  .ticket-card {
    break-inside: avoid;
  }

  .single-ticket-page {
    min-height: auto;
    padding: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .content {
    padding: 18px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .template-form {
    min-width: 0;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
