/* Dunkles Theme fuer eine dunkle Bar: hoher Kontrast, wenige Farben.
   Farbe traegt immer Status (gruen/orange/rot) und kommt nie ohne Text/Symbol. */
:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: rgba(255, 255, 255, 0.1);
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --series: #3987e5;
  --series-wash: rgba(57, 135, 229, 0.12);
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --btn-in: #0b8a2e;
  --btn-out: #c4332f;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.4;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 1.05rem; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Bausteine ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.form-card { display: flex; flex-direction: column; gap: 14px; }
.form-card h1, .form-card h2, .form-card p { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.field > span { font-size: 0.85rem; color: var(--ink-2); }

input {
  font: inherit;
  font-size: 1rem;
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--axis);
  border-radius: 10px;
  padding: 12px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 600;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--axis);
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: transparent; border-color: var(--critical); color: #ff8a80; }
.btn-ghost { background: transparent; color: var(--ink-2); border-radius: 999px; }
.btn-small { min-height: 34px; padding: 4px 12px; font-size: 0.85rem; }

.form-error { color: #ff8a80; min-height: 1.2em; }
.form-msg { color: var(--ink-2); min-height: 1.2em; margin: 0; }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  white-space: nowrap;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
[data-status="ok"] .dot { background: var(--good); }
[data-status="pending"] .dot { background: var(--warning); }
[data-status="error"] .dot { background: var(--critical); }
[data-status="error"] { border-color: var(--critical); }

.meter {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--good);
  transition: width 0.3s ease, background-color 0.3s ease;
}
[data-level="warn"] .meter-fill { background: var(--warning); }
[data-level="full"] .meter-fill { background: var(--critical); }

.center-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.center-screen .card { width: 100%; max-width: 380px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal .card { width: 100%; max-width: 400px; }
.modal-top { z-index: 60; background: rgba(0, 0, 0, 0.92); } /* Rueckfrage liegt ueber allen anderen Fenstern */

/* ---------- Zaehler-Seite ---------- */

.counter-body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  transition: background-color 0.3s ease;
}
.counter-body[data-level="warn"] { background: #3a2c04; }
.counter-body[data-level="full"] { background: #5a1010; }

.counter {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.counter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}
.event-name {
  font-size: 1rem;
  color: var(--ink-2);
  padding: 8px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 40%;
}

.counter-top .sync-pill { min-width: 0; overflow: hidden; }
.counter-top #syncText { overflow: hidden; text-overflow: ellipsis; }

.auth-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 14px 6px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #3a2a05;
  color: #f6d27a;
  font-size: 0.95rem;
}

.stand { text-align: center; padding: 0 16px 8px; }
.stand-number {
  font-size: min(24vw, 22vh, 180px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}
.stand-number.unknown { color: var(--muted); }
.stand-sub { font-size: clamp(1rem, 4.5vw, 1.5rem); color: var(--ink-2); margin-top: 4px; }
.stand .meter { max-width: 520px; margin: 10px auto 0; }
.stand-alert {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--critical);
  color: #fff;
  font-weight: 800;
  font-size: clamp(1rem, 4.5vw, 1.4rem);
}
[data-level="full"] .stand-alert { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* Rein oben, Raus unten, beide ueber die volle Breite */
.tap-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 8px 14px;
  min-height: 0;
}
.tap {
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font: inherit;
  font-size: min(11vw, 64px);
  font-weight: 800;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  cursor: pointer;
  touch-action: none; /* keine Browser-Gesten (Zoom/Scroll) auf den Zaehltasten */
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, filter 0.06s ease;
}
.tap:active { transform: scale(0.97); filter: brightness(0.85); }
.tap-in { background: var(--btn-in); }
.tap-out { background: var(--btn-out); }
.tap-sym { font-size: 1.5em; line-height: 1; }
.tap.flash { animation: flash 0.25s ease-out; }
@keyframes flash { from { box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.35); } to { box-shadow: none; } }

.counter-bottom { display: flex; justify-content: center; padding: 6px 14px 14px; }

/* Querformat (nur im normalen Browser moeglich, die App ist auf Hochformat
   fixiert): dort ist zu wenig Hoehe zum Stapeln, also nebeneinander */
@media (orientation: landscape) {
  .tap-area { flex-direction: row; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .stand-number { font-size: 22vh; }
}

/* ---------- Ticket-Umtausch (eigene Seite, Bernstein statt Gruen zum Unterscheiden) ---------- */

/* Dunkles Indigo: klar anders als der Einlass (schwarz) und dessen Warnfarben (gelb/rot) */
.exchange-body { background: #161a36; }
.exchange-body .sync-pill { background: #22274a; }
.exchange-title { color: #f0b54a; font-weight: 600; }
.tap-exchange { background: #b36b00; flex: 3; font-size: min(8.5vw, 56px); }
.tap-correct {
  flex: 1;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--axis);
  font-size: min(7vw, 36px);
}
.exchange-body .meter-fill { background: #e0a020; }

/* ---------- Dashboard ---------- */

.page-body { min-height: 100%; }

.dash {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
  grid-template-areas: "head" "hero" "tiles" "exchange" "chart" "gates" "foot";
}
.dash-head { grid-area: head; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.dash-head h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2.2rem); overflow-wrap: anywhere; }
.hero { grid-area: hero; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.chart-card { grid-area: chart; display: flex; flex-direction: column; }
.tiles { grid-area: tiles; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.gates-card { grid-area: gates; }
.dash-foot { grid-area: foot; text-align: center; }

@media (min-width: 1000px) {
  .dash {
    grid-template-columns: minmax(340px, 1fr) 2fr;
    grid-template-areas:
      "head  head"
      "hero  chart"
      "tiles tiles"
      "exchange exchange"
      "gates gates"
      "foot  foot";
  }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Ticket-Umtausch-Karte */
.exchange-card { grid-area: exchange; border-color: rgba(224, 160, 32, 0.45); display: flex; flex-direction: column; gap: 14px; }
.exchange-card h2 { margin: 0; color: #f0b54a; }
.exchange-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: stretch; }
.exchange-main { grid-column: 1 / -1; display: flex; flex-direction: column; justify-content: center; gap: 8px; min-width: 0; }
.exchange-number { font-size: clamp(2.6rem, 8vw, 4.5rem); font-weight: 700; line-height: 1; }
.exchange-unit { font-size: 1.1rem; font-weight: 400; color: var(--ink-2); margin-left: 10px; }
.exchange-fill { background: #e0a020; }
.exchange-tile { background: var(--surface-2); }
@media (min-width: 1000px) {
  .exchange-grid { grid-template-columns: 2fr 1fr 1fr; }
  .exchange-main { grid-column: auto; }
}

.hero-label { color: var(--ink-2); font-size: 1.1rem; }
.hero-number {
  font-size: clamp(5rem, 16vw, 11rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.03em;
}
.hero-sub { color: var(--ink-2); font-size: clamp(1rem, 2.5vw, 1.35rem); }
.hero[data-level="full"] { border-color: var(--critical); }
.hero[data-level="warn"] { border-color: var(--warning); }

.status-badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 600;
}
.status-badge[data-level="ok"] .status-icon { color: var(--good); }
.status-badge[data-level="warn"] .status-icon { color: var(--warning); }
.status-badge[data-level="full"] .status-icon { color: var(--critical); }

.chart-box { position: relative; flex: 1; min-height: 260px; }
@media (min-width: 1000px) { .chart-box { min-height: 340px; } }
.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.tile { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; }
/* "Im Laden + offene Tickets": doppelt breit, Rahmen zeigt, ob es eng wird */
.tile-wide { grid-column: span 2; }
.tile-wide .tile-value { font-size: clamp(2.2rem, 5.5vw, 3.4rem); }
.tile-wide .tile-note { font-size: 0.95rem; color: var(--ink-2); }
.tile-wide[data-level="warn"] { border-color: var(--warning); }
.tile-wide[data-level="full"] { border-color: var(--critical); }
.tile-label { color: var(--ink-2); font-size: 0.9rem; }
.tile-value { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 600; line-height: 1.1; }
.tile-note { color: var(--muted); font-size: 0.85rem; }

.gates { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.gate {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.gate .dot { background: var(--good); }
.gate-stale { border-color: var(--critical); }
.gate-stale .dot { background: var(--critical); }
.gate-label { font-weight: 600; }
.gate-status { color: var(--ink-2); font-size: 0.9rem; }

@media (max-width: 480px) {
  .dash { padding: 12px 16px; gap: 12px; }
  .card { padding: 16px; }
  .tiles { gap: 12px; }
}

/* ---------- Admin ---------- */

.admin {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#adminContent { display: flex; flex-direction: column; gap: 16px; }
.admin-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.admin-head h1 { margin: 0; }
.big-line { font-size: 1.3rem; font-weight: 600; margin: 0 0 4px; }
.danger-card { border-color: rgba(208, 59, 59, 0.5); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--grid); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
