/* ===========================================================================
 * Anwesenheit – PWA Stylesheet
 * Gestaltung nach design/STYLEGUIDE.md (deinferienjob.com / Kober GmbH):
 * Rot = Marke, Blau = Aktion, #202024 = Header, #ECECEC = Fläche, Lato.
 * =========================================================================== */

/* --- Lato, lokal gehostet (keine Abfrage bei Google zur Laufzeit) --------- */

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('fonts/lato-300.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/lato-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/lato-700.woff2') format('woff2');
}

:root {
  /* Marke / Primär */
  --brand-red: #D72C31;          /* „Stempel"-Headlines, aktiver Reiter */
  --accent-red: #FF3B30;         /* Links, Akzente */

  /* Interaktion – kein Blau (Vorgabe Matthias, 23.09.2026) */
  --btn-primary: #D72C31;        /* Primär: Markenrot */
  --btn-primary-active: #B8232A;
  --btn-secondary: #FFFFFF;      /* Sekundär: weiß mit Rahmen */
  --btn-secondary-active: #ECECEC;
  --btn-secondary-text: #202024;
  --btn-secondary-border: #CCCCCC;
  --btn-danger: #202024;         /* Gefahr: dunkel */
  --btn-danger-active: #000000;
  --btn-danger-text: #FFFFFF;
  --focus: #202024;              /* Fokusring auf hellem Grund */
  --focus-on-dark: #FFFFFF;

  /* Status */
  --success: #1D8900;            /* anwesend */
  --success-soft: #E7F3E2;
  --danger: #EC1728;             /* Reset / Gefahr – Flächen, Rahmen */
  --danger-text: #B3141F;        /* dasselbe Rot als Text: AA auf Hell */
  --danger-soft: #FDE7E9;
  --warn: #8A5A00;

  /* Flächen */
  --dark: #202024;               /* Header, immer dunkel */
  --bg: #ECECEC;
  --surface: #FFFFFF;
  --input-bg: #FAFCFC;
  --border: #D9D9D9;

  /* Text */
  --text: #000000;
  --text-muted: #555555;
  --text-faint: #5E5E5E;         /* statt #AAA: erreicht auf #ECECEC WCAG AA */
  --on-dark: #FFFFFF;
  --on-dark-muted: #C7C7CC;

  /* Form */
  --radius-btn: 5px;
  --radius-input: 3px;
  --radius-card: 5px;
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, .08);
  --shadow-medium: 4px 5px 8px 0 rgba(0, 0, 0, .1);

  /* Typo */
  --font: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-red: #D72C31;
    --accent-red: #FF6259;
    --btn-primary: #D72C31;
    --btn-primary-active: #B8232A;
    /* Sekundär/Gefahr im Dark Mode gespiegelt: Sekundär dezent, Gefahr hell-invers */
    --btn-secondary: #23272D;
    --btn-secondary-active: #2C3138;
    --btn-secondary-text: #ECEEF1;
    --btn-secondary-border: #343A42;
    --btn-danger: #ECECEC;
    --btn-danger-active: #FFFFFF;
    --btn-danger-text: #202024;
    --focus: #FFFFFF;
    --success: #3FAA22;
    --success-soft: #162A12;
    --danger: #FF5A52;
    --danger-text: #FF8A84;
    --danger-soft: #34181A;
    --warn: #E0B155;
    --bg: #14161A;
    --surface: #1D2025;
    --input-bg: #1D2025;
    --border: #343A42;
    --text: #ECEEF1;
    --text-muted: #A2AAB6;
    --text-faint: #8A929E;
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, .45);
    --shadow-medium: 4px 5px 8px 0 rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

/* Muss nach den display-Regeln der Overlays gelten. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 300;
  line-height: 22px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

h1, h2, h3 { font-weight: 700; margin: 0; }
h2 { font-size: 20px; line-height: 26px; color: var(--text); margin: 28px 0 10px; }
p { margin: 0 0 12px; }
strong, b { font-weight: 700; }

.lead { font-size: 16px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: 14px; line-height: 19px; margin: -6px 0 18px; }
.footnote { color: var(--text-faint); font-size: 14px; text-align: center; margin-top: 32px; }

.error {
  background: var(--danger-soft);
  color: var(--danger-text);
  border: 1px solid var(--danger);
  border-radius: var(--radius-input);
  padding: 11px 13px;
  font-size: 15px;
  font-weight: 400;
  margin: 0 0 16px;
}

/* --- „Stempel"-Headline: weiß auf Markenrot, leicht gedreht -------------- */

.stamp {
  display: inline-block;
  background: var(--brand-red);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  line-height: 30px;
  padding: 3px 14px 4px;
  transform: rotate(-2deg);
  transform-origin: left center;
  max-width: 100%;
  overflow-wrap: break-word;
}
.stamp-lg { font-size: 30px; line-height: 42px; padding: 4px 18px 6px; transform-origin: center; }

/* --- Screens ------------------------------------------------------------- */

.screen { display: none; min-height: 100%; flex-direction: column; }
.screen.is-active { display: flex; }

.pad {
  padding: 18px calc(16px + var(--safe-r)) calc(32px + var(--safe-b)) calc(16px + var(--safe-l));
  flex: 1;
}
.pad-wide { max-width: 520px; margin: 0 auto; width: 100%; padding-top: 30px; }

.hero { text-align: center; margin-bottom: 30px; }
.hero .lead { margin-top: 16px; }

/* --- Header -------------------------------------------------------------- */

.appbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(9px + var(--safe-t)) calc(10px + var(--safe-r)) 9px calc(14px + var(--safe-l));
  background: var(--dark);
  color: var(--on-dark);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brandlogo { height: 22px; width: auto; display: block; flex: 0 0 auto; }
.appbar-spacer { flex: 1; }
.appbar-main { flex: 1; min-width: 0; padding: 0 6px; }
.appbar-title {
  font-weight: 700;
  font-size: 17px;
  line-height: 24px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Listenkopf: Stempel + Metazeile */
.listhead {
  padding: 18px calc(16px + var(--safe-r)) 14px calc(16px + var(--safe-l));
  background: var(--bg);
}
.listhead-sub {
  margin-top: 12px;
  font-size: 14px;
  line-height: 19px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Formulare ----------------------------------------------------------- */

label {
  display: block;
  font-weight: 700;
  font-size: 15px;
  margin: 0 0 6px;
  color: var(--text);
}

input[type="text"], input[type="search"] {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 13px;
  font-size: 16px;               /* >= 16px: verhindert Zoom auf iOS */
  font-family: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  margin: 0 0 16px;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder { color: #666; opacity: 1; }
input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.appbar :focus-visible { outline-color: var(--focus-on-dark); }

.code-input {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 16px;
  font-family: inherit;
  font-size: 17px;      /* Weiss auf #D72C31 = 4,9:1 -> AA auch als Normaltext */
  font-weight: 700;
  color: var(--btn-secondary-text);
  background: var(--btn-secondary);
  border: 1px solid var(--btn-secondary-border);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); background: var(--btn-secondary-active); box-shadow: none; }
.btn-block { display: flex; width: 100%; margin-bottom: 12px; }
.btn[disabled] { opacity: .55; }

.btn-primary { background: var(--btn-primary); border-color: var(--btn-primary); color: #fff; }
.btn-primary:active { background: var(--btn-primary-active); border-color: var(--btn-primary-active); }

.btn-danger { background: var(--btn-danger); border-color: var(--btn-danger); color: var(--btn-danger-text); }
.btn-danger:active { background: var(--btn-danger-active); border-color: var(--btn-danger-active); }

@media (hover: hover) {
  .btn:hover { background: var(--btn-secondary-active); }
  .btn-primary:hover { background: var(--btn-primary-active); border-color: var(--btn-primary-active); }
  .btn-danger:hover { background: var(--btn-danger-active); border-color: var(--btn-danger-active); }
}

.iconbtn {
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  border-radius: var(--radius-btn);
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.iconbtn svg { fill: currentColor; }

/* --- Statuszeile --------------------------------------------------------- */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l));
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.count { font-size: 17px; font-weight: 700; }
.netstatus {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 17px;
  text-align: right;
}
.netstatus .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); flex: 0 0 auto; }
.netstatus.is-offline .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--text-muted); }
.netstatus.is-pending .dot { background: var(--accent-red); }

/* --- Suche & Reiter ------------------------------------------------------ */

.toolbar { padding: 12px calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l)); }
.searchbox { position: relative; }
.searchbox input { margin-bottom: 10px; padding-right: 46px; }
.searchclear {
  position: absolute;
  top: 0; right: 0;
  width: 46px; height: var(--tap);
  border: 0; background: none;
  color: var(--text-muted);
  font-size: 26px; line-height: 1;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 0 calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l));
}
.tab {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: var(--radius-btn);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab.is-active {
  background: var(--brand-red);
  border-color: var(--brand-red);
  color: #fff;
}
.tabcount { font-weight: 400; opacity: .85; }

/* --- Personenliste ------------------------------------------------------- */

.listwrap { position: relative; flex: 1; padding-bottom: var(--safe-b); }

.people {
  list-style: none;
  margin: 0;
  padding: 0 calc(30px + var(--safe-r)) calc(32px + var(--safe-b)) calc(16px + var(--safe-l));
}
.people li {
  margin-bottom: 8px;
  transition: opacity .2s ease-out, transform .2s ease-out;
}
/* Neu eingeblendeter Eintrag (Rückgängig, Rundenwechsel, fremde Änderung) */
.people li.is-entering { opacity: 0; transform: translateY(-6px); }
/* Eintrag verlässt die Ansicht: Höhe und Deckkraft sanft auf 0 */
.people li.is-leaving {
  overflow: hidden;
  pointer-events: none;
  transition: max-height .34s ease, opacity .28s ease, margin-bottom .34s ease;
}

.person {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  text-align: left;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.person .box {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border: 2px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--input-bg);
}
.person .name { flex: 1; min-width: 0; font-weight: 300; }
.person .name b { font-weight: 700; }
.person .meta { display: block; font-size: 13px; line-height: 18px; color: var(--text-muted); }

.person.is-present {
  background: var(--success-soft);
  border-color: var(--success);
}
.person.is-present .box {
  background: var(--success);
  border-color: var(--success);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 13l4.5 4.5L19 7' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 22px 22px;
  background-position: center;
  background-repeat: no-repeat;
}
.person.is-queued .box { box-shadow: 0 0 0 3px rgba(215, 44, 49, .40); }

@keyframes flashok {
  0%   { background-color: var(--success); border-color: var(--success); }
  100% { background-color: var(--success-soft); border-color: var(--success); }
}
.person.flash { animation: flashok .5s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .person.flash { animation: none; }
  .people li,
  .people li.is-leaving { transition: none; }
  .people li.is-entering { opacity: 1; transform: none; }
}

.empty { padding: 34px 16px; text-align: center; color: var(--text-muted); }

/* --- Buchstabenleiste ---------------------------------------------------- */

.alpha {
  position: absolute;
  top: 0;
  right: calc(2px + var(--safe-r));
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0;
  user-select: none;
}
.alpha button {
  width: 26px;
  min-height: 0;
  padding: 1px 0;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.alpha button.is-active { background: var(--brand-red); color: #fff; }
.alpha button[disabled] { opacity: .35; }

/* --- QR / Kamera --------------------------------------------------------- */

.qrbox {
  background: #fff;              /* für die Lesbarkeit immer weiß, auch im Dark Mode */
  border-radius: var(--radius-card);
  padding: 14px;
  margin: 0 auto 18px;
  width: fit-content;
  box-shadow: var(--shadow-medium);
}
#qr-canvas { display: block; width: min(80vw, 320px); height: auto; image-rendering: pixelated; }
.qrtext { text-align: center; color: var(--text-muted); }

.camwrap {
  position: relative;
  background: #000;
  border-radius: var(--radius-card);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  margin-bottom: 16px;
}
#scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camframe {
  position: absolute;
  inset: 15%;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: var(--radius-card);
}

.result {
  background: var(--success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius-card);
  padding: 13px;
  margin-bottom: 16px;
}

.warnbox {
  background: var(--danger-soft);
  color: var(--danger-text);
  border: 1px solid var(--danger);
  border-radius: var(--radius-card);
  padding: 13px;
  margin-bottom: 20px;
}

.steps { padding-left: 21px; margin: 0 0 16px; }
.steps li { margin-bottom: 7px; }

/* --- Menü-Sheet ---------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 32, 36, .55);
  z-index: 60;
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  padding: 8px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  max-height: 90%;
  overflow: auto;
}
.sheet-grip { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 4px auto 12px; }
.menuitem {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 8px;
  text-align: left;
  font-family: inherit;
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.menuitem-warn { color: var(--danger-text); font-weight: 700; }
.menuversion { padding: 14px 8px; font-size: 13px; color: var(--text-faint); }
.sheet-close { margin-top: 4px; }

/* --- Modal --------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 32, 36, .55);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-medium);
}
.modal h2 { margin: 0 0 8px; font-size: 19px; line-height: 25px; }
.modal p { color: var(--text-muted); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* --- Toasts -------------------------------------------------------------- */

.toasts {
  position: fixed;
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  bottom: calc(12px + var(--safe-b));
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--dark);
  color: #fff;
  border-radius: var(--radius-btn);
  padding: 11px 14px;
  font-size: 15px;
  line-height: 20px;
  font-weight: 400;
  box-shadow: var(--shadow-medium);
  animation: toastin .18s ease-out;
}
.toast.is-going { opacity: 0; transition: opacity .25s; }
.toast.is-ok { background: #1D8900; }
.toast.is-warn { background: var(--brand-red); }
.toast.is-error { background: #9C1016; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* --- Größere Schirme ----------------------------------------------------- */

@media (min-width: 720px) {
  .listwrap, .statusbar, .toolbar, .tabs, .listhead { max-width: 760px; margin-left: auto; margin-right: auto; width: 100%; }
  .pad { max-width: 760px; margin: 0 auto; width: 100%; }
}
