/* Gemeinsames Theme fuer Scanner (index.html) und Admin (admin.html).
   Schuetzenverein: Weiss mit Schuetzengruen, Gold als Akzent.
   Baendchen-Farben (--herren/--damen/--beide) bei Bedarf an die echten
   Baendchen anpassen, dann erkennt das Einlass-Team sie sofort wieder. */
:root {
  /* Vereinsfarben */
  --brand: #1e5a32;        /* Schuetzengruen */
  --brand-dark: #143f23;   /* Header */
  --brand-tint: #e6f0e8;
  --gold: #b8912f;
  --gold-tint: #f6efdb;
  --on-brand: #ffffff;

  /* Flaechen & Text */
  --bg: #f1f4f0;
  --surface: #ffffff;
  --field: #f8faf7;
  --border: #d5dfd4;
  --text: #16261b;
  --text-dim: #5c6e61;

  /* Baendchen */
  --herren: var(--brand);
  --herren-tint: var(--brand-tint);
  --damen: #8e2340;        /* Weinrot */
  --damen-tint: #f6e5ea;
  --beide: #8a6a12;        /* Gold, dunkel genug fuer Text auf Weiss */
  --beide-tint: var(--gold-tint);
  --count: var(--brand);
  --count-tint: var(--brand-tint);

  /* Status */
  --ok: #2e7d32;
  --ok-tint: #e3f1e4;
  --red: #b3261e;
  --red-tint: #fbe7e5;
  --warn: #a35a00;
  --warn-tint: #fdf0dc;

  --disabled-bg: #eef1ed;
  --disabled: #dde3dc;
  --disabled-text: #a3ada5;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 63, 35, .06), 0 1px 1px rgba(20, 63, 35, .04);
  color-scheme: light;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  padding: 0 env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  display: flex;
  flex-direction: column;
}

button, input, select { font: inherit; color: inherit; }

/* Header: dunkelgruen mit Goldlinie */
.header {
  background: var(--brand-dark);
  color: var(--on-brand);
  border-bottom: 3px solid var(--gold);
  padding: calc(12px + env(safe-area-inset-top, 0)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-emblem { width: 30px; height: 30px; flex: 0 0 auto; }
.header-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1.1;
}
.header-sub {
  display: block;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .7);
}
.header-status {
  font-size: 11px;
  color: rgba(255, 255, 255, .8);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  text-align: right;
  line-height: 1.25;
}
.header .btn { background: transparent; border-color: rgba(255, 255, 255, .35); color: var(--on-brand); }
.header .btn:hover:not(:disabled) { background: rgba(255, 255, 255, .1); }
.dot {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .35);
}
.dot.ok  { background: #7fd894; box-shadow: 0 0 0 3px rgba(127, 216, 148, .25); }
.dot.err { background: #ff7a70; box-shadow: 0 0 0 3px rgba(255, 122, 112, .25); }

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#admin-views { display: flex; flex-direction: column; gap: 12px; }
.view-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--brand);
  text-transform: uppercase;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.view-label::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--gold);
  transform: rotate(45deg);
  flex: 0 0 auto;
}

/* Kamera */
.reader-wrap {
  position: relative;
  background: #0d1a11;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  max-height: 38dvh;
  width: 100%;
}
/* Das Video MUSS sein natuerliches Seitenverhaeltnis behalten: html5-qrcode
   skaliert Breite und Hoehe getrennt (videoWidth/clientWidth,
   videoHeight/clientHeight). Ein per CSS erzwungenes 4:3 (object-fit: cover)
   verzerrt das ausgewertete Bild, bei Hochkant-Streams (iPhone) so stark, dass
   nichts erkannt wird. Deshalb nur zentrieren und vom Container abschneiden. */
#reader {
  position: absolute;
  left: 0; right: 0; top: 50%;
  transform: translateY(-50%);
}
#reader video { display: block; width: 100% !important; height: auto !important; }
/* Zielrahmen (nur Optik, ausgewertet wird das ganze Kamerabild) */
.reader-frame {
  position: absolute;
  top: 50%; left: 50%;
  width: min(62%, 70vw); aspect-ratio: 1;
  max-height: 80%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  --l: 26px;   /* Laenge der Ecken */
  --t: 4px;    /* Staerke */
  background:
    linear-gradient(var(--gold), var(--gold)) top left / var(--l) var(--t),
    linear-gradient(var(--gold), var(--gold)) top left / var(--t) var(--l),
    linear-gradient(var(--gold), var(--gold)) top right / var(--l) var(--t),
    linear-gradient(var(--gold), var(--gold)) top right / var(--t) var(--l),
    linear-gradient(var(--gold), var(--gold)) bottom left / var(--l) var(--t),
    linear-gradient(var(--gold), var(--gold)) bottom left / var(--t) var(--l),
    linear-gradient(var(--gold), var(--gold)) bottom right / var(--l) var(--t),
    linear-gradient(var(--gold), var(--gold)) bottom right / var(--t) var(--l);
  background-repeat: no-repeat;
  border-radius: 6px;
}
/* Kamera aus -> Rahmen ausblenden */
.reader-frame:has(~ .reader-placeholder:not(.hidden)) { display: none; }
.reader-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: rgba(255, 255, 255, .7); font-size: 13px; text-align: center; padding: 16px;
}

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

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { background: var(--field); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn.good    { border-color: var(--brand); color: var(--brand); }
.btn.danger  { border-color: rgba(179, 38, 30, .45); color: var(--red); }
.btn.active  { background: var(--brand-tint); }
.btn.grow    { flex: 1; }

.input {
  flex: 1;
  min-width: 0;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px; /* >= 16px verhindert Auto-Zoom auf iOS */
  font-family: 'Courier New', monospace;
  letter-spacing: .05em;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.row { display: flex; gap: 8px; align-items: center; }

/* Member-Info Bar */
.member-bar {
  background: var(--field);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
}
.member-id {
  font-family: 'Courier New', monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .05em;
}
.member-id.dim { color: var(--text-dim); font-weight: 400; font-family: inherit; font-size: 13px; }
.member-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-active   { background: var(--ok-tint);   color: var(--ok);   border: 1px solid rgba(46, 125, 50, .3); }
.badge-inactive { background: var(--red-tint);  color: var(--red);  border: 1px solid rgba(179, 38, 30, .3); }
.badge-adult    { background: var(--surface);   color: var(--text-dim); border: 1px solid var(--border); }
.badge-minor    { background: var(--warn-tint); color: var(--warn); border: 1px solid rgba(163, 90, 0, .3); }

.message {
  font-size: 14px;
  text-align: center;
  min-height: 20px;
  color: var(--text-dim);
}
.message.ok   { color: var(--ok); font-weight: 700; }
.message.err  { color: var(--red); font-weight: 700; }
.message.warn { color: var(--warn); font-weight: 700; }

/* Ticket-Buttons */
.btn-grid { display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 10px; }

.btn-ticket {
  --c: var(--brand);
  --c-tint: var(--brand-tint);
  flex: 1;
  background: var(--c-tint);
  border: 2px solid var(--c);
  border-radius: 12px;
  padding: 18px 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform .1s, background .15s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.btn-ticket:active:not(:disabled) { transform: scale(.97); background: var(--c); }
.btn-ticket:active:not(:disabled) .btn-label,
.btn-ticket:active:not(:disabled) .btn-icon { color: var(--on-brand); }
.btn-ticket.wide {
  width: 100%;
  flex-direction: row;
  justify-content: center;
  gap: 10px;
  padding: 14px;
}
.btn-ticket.wide .btn-icon { font-size: 20px; }
.btn-ticket.wide .btn-label { font-size: 15px; text-transform: none; letter-spacing: .04em; }

.btn-icon { font-size: 42px; line-height: 1; display: block; color: var(--c); font-weight: 700; }
.btn-label { font-size: 13px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--c); }

.style-herren { --c: var(--herren); --c-tint: var(--herren-tint); }
.style-damen  { --c: var(--damen);  --c-tint: var(--damen-tint); }
.style-beide  { --c: var(--beide);  --c-tint: var(--beide-tint); }
.style-count  { --c: var(--count);  --c-tint: var(--count-tint); }
.style-count .btn-label { font-size: 24px; }

.btn-ticket:disabled {
  background: var(--disabled-bg);
  border-color: var(--disabled);
  cursor: not-allowed;
}
.btn-ticket:disabled .btn-label { color: var(--disabled-text); }
.btn-ticket:disabled .btn-icon { filter: grayscale(1); opacity: .35; }
.btn-ticket.issued:disabled::after {
  content: '✓';
  position: absolute;
  top: 6px; right: 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--disabled-text);
}

/* Vollbild-Flash als Rueckmeldung */
.flash {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .35s;
  z-index: 50;
}
.flash.ok  { background: rgba(46, 125, 50, .3); opacity: 1; transition: none; }
.flash.err { background: rgba(179, 38, 30, .35); opacity: 1; transition: none; }

details.settings summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  list-style: none;
}
details.settings summary::-webkit-details-marker { display: none; }
details.settings[open] summary { margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.hidden { display: none !important; }

/* Admin */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim); }
td.mono { font-family: 'Courier New', monospace; font-weight: 700; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--brand-tint); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.kpi { background: var(--field); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: 8px; padding: 10px; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--brand-dark); font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }
.bars { display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
.bar-row { display: grid; grid-template-columns: 44px 1fr 32px; gap: 8px; align-items: center; }
.bar-track { background: var(--field); border-radius: 3px; height: 14px; overflow: hidden; display: flex; gap: 2px; }
.bar-seg { height: 100%; }
.bar-num { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 12px; font-size: 11px; color: var(--text-dim); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
label.check { display: flex; gap: 6px; align-items: center; font-size: 14px; }
label.check input { accent-color: var(--brand); width: 16px; height: 16px; }

/* Segment-Auswahl (z.B. 1 / 2 Baendchen) */
.seg { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg .btn { flex: 1; border: none; border-radius: 0; background: var(--surface); color: var(--text-dim); }
.seg .btn + .btn { border-left: 1px solid var(--border); }
.seg .btn.active { background: var(--brand); color: var(--on-brand); }

/* QR-Anzeige */
.qr-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--field); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.qr-card img {
  width: min(78vw, 320px); height: auto; aspect-ratio: 1;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; image-rendering: pixelated;
}
.qr-card .member-id { font-size: 16px; word-break: break-all; text-align: center; }
.qr-card .row { width: 100%; }
a.btn { text-decoration: none; text-align: center; color: var(--brand); }

/* Scanner: Statuszeile + Zurueck-Button */
.status-line { padding: 4px 16px; }
.status-line:empty { display: none; }
.btn-back { width: 100%; padding: 14px; font-size: 15px; }

/* Vollbild-Overlay: rotes Kreuz / gruener Haken, kraeftige Flaechen mit Weiss */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}
.overlay.deny { background: var(--red); }
.overlay.ok   { background: var(--brand); }
.overlay-icon { font-size: min(55vw, 280px); line-height: 1; font-weight: 900; }
.overlay-text { font-size: 28px; font-weight: 800; }
.overlay-sub  { font-family: 'Courier New', monospace; font-size: 15px; color: rgba(255, 255, 255, .75); }
.overlay-bar  { width: min(70vw, 320px); height: 5px; background: rgba(255, 255, 255, .25); border-radius: 3px; overflow: hidden; }
.overlay-bar i { display: block; height: 100%; width: 100%; background: #fff; transform-origin: left; }
.overlay.ok .overlay-bar i { background: var(--gold); }
.overlay-hint { font-size: 12px; color: rgba(255, 255, 255, .7); }
@keyframes ov-countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
