:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #17212f;
  --muted: #5f6b7a;
  --accent: #1f6feb;
  --ok: #0d7a2f;
  --error: #9f1239;
  --border: #d7dfeb;
}

[data-theme="dark"] {
  --bg: #0f1724;
  --card: #1a2434;
  --text: #ecf1f8;
  --muted: #9fb0c4;
  --accent: #66aaff;
  --ok: #32d074;
  --error: #f87171;
  --border: #2d3a4f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar nav { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
a, button { color: var(--accent); text-decoration: none; }
.container { max-width: 1100px; margin: 1rem auto; padding: 0 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.card.small { max-width: 420px; margin: 3rem auto; }
label { display: block; margin-top: .8rem; font-weight: 600; }
input, select, button {
  width: 100%;
  margin-top: .3rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .65rem;
  background: transparent;
  color: var(--text);
}
.event-switcher { margin: 0; }
.event-switcher select { width: min(260px, 70vw); margin-top: 0; padding: .45rem .55rem; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
button, .button {
  background: var(--accent);
  color: white;
  padding: .65rem .9rem;
  border: none;
  border-radius: 8px;
  display: inline-block;
  margin-top: .9rem;
  width: auto;
}
.button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
.small-button { padding: .35rem .55rem; margin-top: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--border); padding: .5rem; text-align: left; font-size: .92rem; }
.alert { padding: .8rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-success { background: #dff7e6; color: #0b5d27; }
.alert-error { background: #fde4ea; color: #7a1d3b; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.scan-result { font-size: 1.15rem; font-weight: 700; }

.reader-wrapper {
  border: 3px solid transparent;
  border-radius: 14px;
  padding: .35rem;
  transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.reader-idle {
  border-color: var(--border);
  background: var(--card);
}
.reader-ok {
  border-color: var(--ok);
  box-shadow: 0 0 0 4px rgba(13, 122, 47, 0.2);
}
.reader-error {
  border-color: var(--error);
  box-shadow: 0 0 0 4px rgba(159, 18, 57, 0.2);
}
.actions { margin: 1rem 0; display: flex; gap: .75rem; flex-wrap: wrap; }
.inline-form { margin-top: 1rem; }
.inline-action-form { display: inline-block; margin: 0; }
.ticket-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.compact-grid { gap: .5rem; }
.event-form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .35rem; }

.ticket-preview {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: var(--ticket-preview-ratio, 1.414 / 1);
  background-color: #eef2f7;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ticket-preview-card { margin-top: 1rem; }
.ticket-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}
.ticket-preview[style*="background-image"] .ticket-placeholder,
.pdf-ticket[style*="background-image"]::before { display: none; }
.drag-handle,
.pdf-ticket-number,
.pdf-ticket-qr {
  position: absolute;
  transform: translate(-50%, -50%);
}
.drag-handle {
  width: auto;
  touch-action: none;
  cursor: grab;
  border: 2px solid white;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.ticket-number-handle {
  line-height: 1;
  position: absolute;
}
.qr-handle {
  display: grid;
  place-items: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  position: absolute;
}
.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 16px;
  height: 16px;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--accent);
  cursor: nwse-resize;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.ticket-pages {
  display: grid;
  gap: 1rem;
}
.pdf-sheet {
  width: min(100%, 1122px);
  aspect-ratio: 1.414 / 1;
  display: grid;
  grid-template-columns: repeat(var(--ticket-columns, 2), minmax(0, 1fr));
  grid-template-rows: repeat(var(--ticket-rows, 3), minmax(0, 1fr));
  place-items: center;
  gap: 14px;
  padding: 18px;
  background: white;
  border: 1px solid var(--border);
  page-break-after: always;
}
.pdf-ticket {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--ticket-ratio, 1.414 / 1);
  width: auto;
  height: 100%;
  max-width: 100%;
  background-color: white;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border: 1px solid var(--border);
}
.pdf-ticket-number {
  color: #111827;
  font-weight: 800;
  background: rgba(255,255,255,.88);
  padding: 4px 8px;
  border-radius: 4px;
}
.pdf-ticket-qr {
  background: white;
  padding: 8px;
}

@media print {
  .topbar,
  .no-print { display: none; }
  .container { margin: 0; padding: 0; max-width: none; }
}

.modal {
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.modal-content {
  background-color: #fefefe;
  margin: 15% auto; /* 15% from the top and centered */
  padding: 20px;
  border: 1px solid #888;
  width: max(40%, 290px); /* Could be more or less, depending on screen size */
}

.btnScanClass {
  position: fixed;      /* Flota respecte la finestra */
  top: 46%;             /* 50% des de dalt */
  left: 50%;            /* 50% des de l'esquerra */
  transform: translate(-50%, -50%); /* Centrat real */
  
  z-index: 9999;        /* Per davant de tot */

  background: var(--ok);
  color: white;
  padding: .65rem .9rem;
  border: none;
  border-radius: 8px;
  width: 260px;
  aspect-ratio: 1;
  font-size: 38px;
}

