:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --bg-muted: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #111111;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --accent: #18181b;

  /* Statusfarben – sachlich, klar, hoher Kontrast */
  --ok-bg: #f0fdf4;
  --ok-border: #16a34a;
  --ok-text: #14532d;

  --err-bg: #fef2f2;
  --err-border: #dc2626;
  --err-text: #7f1d1d;

  --warn-bg: #fffbeb;
  --warn-border: #d97706;
  --warn-text: #78350f;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.brand-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-btn {
  text-decoration: none;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 500;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--bg-muted);
}

.nav-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #16a34a;
}

/* Layout */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem;
}

.scanner-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
  align-items: start;
}

.scanner-layout-stacked {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.5rem;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.scanner-layout-stacked > .card {
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 840px) {
  .scanner-layout {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

/* Ausklappbare Reihen-Auswahl */
.series-select-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.series-select-card-header:hover {
  background: var(--bg-muted);
  border-color: var(--border-strong);
}

.series-header-main {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.series-header-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.series-header-chevron {
  color: var(--text-secondary);
  transition: transform 0.2s ease;
}

.series-header-chevron.open {
  transform: rotate(180deg);
}

.series-dropdown-container {
  margin-bottom: 0.75rem;
  animation: slideDownFade 0.16s ease-out;
}

@keyframes slideDownFade {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reihen-Auswahl Tabs */
.series-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.series-tab {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.65rem 0.5rem;
  cursor: pointer;
  text-align: left;
  padding-left: 0.85rem;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.series-tab:hover {
  border-color: var(--border-strong);
}

.series-tab .series-name {
  font-weight: 600;
  font-size: 0.9rem;
  display: block;
}

.series-tab .series-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.series-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.series-tab.active .series-sub {
  color: #d4d4d8;
}

/* Zähler */
.counter-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.counter-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.counter-numbers {
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.counter-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.25s ease;
}

/* Ergebnis-Feld */
.scan-result-panel {
  position: relative;
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.scan-result-panel.panel-fade-out {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.scan-result-panel.status-idle {
  color: var(--text-secondary);
}

/* Anleitung ausblenden sobald die Kamera aktiv ist */
body.camera-is-active .scan-result-panel.status-idle,
body.camera-is-active .scan-result-panel.is-instruction {
  display: none !important;
}

.scan-result-panel.status-allowed {
  background: var(--ok-bg);
  border: 1.5px solid var(--ok-border);
  color: var(--ok-text);
  padding: 0.55rem 0.85rem;
  padding-right: 3.1rem;
  margin-bottom: 0.65rem;
  border-radius: 8px;
}

/* Kreisrunder 5-Sekunden Countdown Timer (oben rechts nur bei Einlass gültig) */
.result-countdown-circle {
  position: absolute;
  top: 0.5rem;
  right: 0.65rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

.countdown-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.countdown-bg {
  fill: rgba(255, 255, 255, 0.55);
  stroke: rgba(22, 163, 74, 0.22);
  stroke-width: 2.8;
}

.countdown-bar {
  fill: none;
  stroke: var(--ok-border);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-dasharray: 94.25;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.08s linear;
}

.countdown-text {
  position: relative;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ok-text);
  line-height: 1;
  user-select: none;
}

/* Kompakte Darstellung der Einlass-Gültig Zeilen */
.compact-allowed-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.98rem !important;
  font-weight: 700;
  margin-bottom: 0.18rem !important;
  line-height: 1.25;
}

.compact-allowed-badge {
  background: #16a34a;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}

.compact-allowed-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
  color: var(--ok-text);
  font-size: 1.02rem;
}

.compact-allowed-series {
  font-size: 0.74rem;
  background: rgba(22, 163, 74, 0.14);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
}

.compact-allowed-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem !important;
  color: var(--ok-text);
  line-height: 1.25;
}

.compact-allowed-sub .dot-sep {
  opacity: 0.45;
}

.compact-allowed-sub .time-label {
  opacity: 0.85;
}

.btn-undo-compact {
  background: transparent;
  border: 1px solid rgba(22, 101, 52, 0.35);
  color: var(--ok-text);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 0.2rem;
  transition: all 0.12s ease;
}

.btn-undo-compact:hover {
  background: rgba(22, 101, 52, 0.12);
  border-color: var(--ok-border);
}

.scan-result-panel.status-denied {
  background: var(--err-bg);
  border: 2px solid var(--err-border);
  color: var(--err-text);
}

.scan-result-panel.status-warning {
  background: var(--warn-bg);
  border: 2px solid var(--warn-border);
  color: var(--warn-text);
}

.result-status-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.result-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.result-message {
  font-size: 0.9rem;
}

.result-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding-top: 0.75rem;
  margin-top: 0.85rem;
}

.meta-item-label {
  font-size: 0.72rem;
  color: inherit;
  opacity: 0.75;
}

.meta-item-value {
  font-size: 0.92rem;
  font-weight: 600;
}

/* Formularelemente & Buttons */
.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.input-field, .select-field {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.88rem;
  width: 100%;
}

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

.btn {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  padding: 0.55rem 0.95rem;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.86rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: #27272a;
}

.btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--bg-muted);
}

.btn-sm {
  padding: 0.32rem 0.65rem;
  font-size: 0.78rem;
}

/* Kamera Button – Highlight in Blau */
.btn-camera {
  background: #2563eb;
  color: #ffffff;
  border: 1px solid #1d4ed8;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-camera:hover {
  background: #1d4ed8;
  border-color: #1e40af;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.btn-camera:active {
  background: #1e40af;
  transform: translateY(0);
}

.btn-camera.camera-active {
  background: #dc2626;
  border-color: #b91c1c;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2);
}

.btn-camera.camera-active:hover {
  background: #b91c1c;
  border-color: #991b1b;
}

/* Neu initialisieren Button – kreisrundes Icon ohne Text für Mobile-Optimierung */
.btn-reinit {
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  color: var(--text);
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  transition: all 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.btn-reinit:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--text-secondary);
  transform: translateY(-1px);
}

.btn-reinit:active {
  transform: translateY(0);
}

.btn-reinit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spin-icon {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Badges */
.series-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  color: var(--text);
}

/* Test-Karten */
.sim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.5rem;
}

.sim-pass-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sim-pass-btn:hover {
  border-color: var(--text);
  background: var(--bg-subtle);
}

.sim-pass-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.86rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.sim-pass-seat {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.sim-pass-status {
  font-size: 0.72rem;
  font-weight: 500;
  margin-top: 0.1rem;
}

.sim-pass-status.checked {
  color: #dc2626;
}

.sim-pass-status.free {
  color: #16a34a;
}

/* Kamera */
.camera-container {
  width: 100%;
  margin-bottom: 0.85rem;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  display: none;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.camera-container.active {
  display: block;
}

.camera-container.scan-flash {
  box-shadow: 0 0 0 3px #22c55e, 0 0 20px rgba(34, 197, 94, 0.45) !important;
  border-color: #22c55e !important;
  transition: all 0.15s ease;
}

#cameraVideo {
  width: 100%;
  display: block;
  max-height: 280px;
  object-fit: cover;
  pointer-events: none;
}

.camera-focus-indicator {
  position: absolute;
  width: 58px;
  height: 58px;
  margin-left: -29px;
  margin-top: -29px;
  border: 2px solid #38bdf8;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.75);
  pointer-events: none;
  z-index: 10;
  animation: focusPulse 0.75s ease-out forwards;
}

.camera-focus-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #f4f4f5;
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  pointer-events: none;
  z-index: 6;
  letter-spacing: 0.01em;
}

/* Zielkasten / Sucherrahmen für ultra-schnelle Zentrierung */
.camera-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 170px;
  height: 170px;
  max-width: 60%;
  max-height: 60%;
  pointer-events: none;
  z-index: 5;
}

.reticle-corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(56, 189, 248, 0.85);
}

.reticle-corner.top-left {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 6px;
}

.reticle-corner.top-right {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
  border-top-right-radius: 6px;
}

.reticle-corner.bottom-left {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 6px;
}

.reticle-corner.bottom-right {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 6px;
}

.reticle-laser {
  position: absolute;
  left: 6px;
  right: 6px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #38bdf8, transparent);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.9);
  animation: reticleScan 1.6s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes reticleScan {
  0% {
    top: 10%;
    opacity: 0.35;
  }
  50% {
    opacity: 0.95;
  }
  100% {
    top: 90%;
    opacity: 0.35;
  }
}

.camera-reticle.reticle-matched .reticle-corner {
  border-color: #22c55e !important;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.9) !important;
  transform: scale(1.08);
  transition: all 0.12s ease;
}

.camera-reticle.reticle-matched .reticle-laser {
  background: linear-gradient(90deg, transparent, #22c55e, transparent);
  box-shadow: 0 0 12px #22c55e;
}

@keyframes focusPulse {
  0% {
    transform: scale(1.4);
    opacity: 0.9;
  }
  35% {
    transform: scale(1);
    opacity: 1;
  }
  70% {
    transform: scale(1);
    opacity: 0.85;
  }
  100% {
    transform: scale(0.9);
    opacity: 0;
  }
}

/* Tabellen */
.table-wrap {
  overflow-x: auto;
}

table.passes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

table.passes-table th,
table.passes-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.passes-table th {
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 600;
  background: var(--bg-subtle);
}

/* Druckansicht Abo-Ausweis */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 17, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 250;
}

.modal-backdrop.open {
  display: flex;
}

.printable-pass-card {
  background: #ffffff;
  color: #111111;
  width: 100%;
  max-width: 440px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #111111;
}

.pass-print-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #111111;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.pass-print-body {
  padding: 1.25rem;
  display: grid;
  grid-template-columns: 1fr 135px;
  gap: 1rem;
  align-items: center;
}

.pass-qr-box {
  width: 135px;
  height: 135px;
  border: 1px solid var(--border);
  padding: 6px;
  background: #fff;
}

.pass-qr-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pass-print-footer {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 0.7rem 1.25rem;
  border-top: 1px solid var(--border);
}

@media print {
  body * {
    visibility: hidden;
  }
  #printModal, #printModal * {
    visibility: visible;
  }
  #printModal {
    position: absolute;
    inset: 0;
    background: #fff;
    align-items: flex-start;
  }
  .no-print {
    display: none !important;
  }
}
