/* Card - Gestaltung. Gleiche Tokens, Rundungen und Schrift wie Copy (gitmi/copy),
 * hell und dunkel per data-theme am <html>. Die Akzentfarben kommen aus CARD_ACCENT
 * (Palette wie bei Copy) und stehen als <style> im <head> jeder Seite.
 * Der QR-Code liegt immer schwarz auf weiss: invertierte Codes scheitern an Scannern.
 */

:root, [data-theme=light] {
  --paper: #e7ebe8;
  --card: #fdfefd;
  --field: #ffffff;
  --ink: #16211f;
  --muted: #5f706c;
  --line: #cdd6d1;
  --accent: #145c52;
  --accent-hover: #0f4b43;
  --accent-soft: #dbe8e4;
  --on-accent: #ffffff;
  --warn: #8a4a1f;
  --warn-bg: #fdf4ec;
  --danger: #b91c1c;
  --toast: #16211f;
  --toast-ink: #ffffff;
  --radius: 10px;
  --radius-sm: 8px;
  --gap: 1rem;
  --fs: 16px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
}

[data-theme=dark] {
  --paper: #151a19;
  --card: #1e2624;
  --field: #243030;
  --ink: #e6ece9;
  --muted: #93a39e;
  --line: #354441;
  --accent: #4fb3a3;
  --accent-hover: #6cc7b8;
  --accent-soft: #213a36;
  --on-accent: #0f1e1b;
  --warn: #e0a26a;
  --warn-bg: #2d251c;
  --danger: #f87171;
  --toast: #e6ece9;
  --toast-ink: #151a19;
}

* { box-sizing: border-box; }

/* Muss nach den Anzeige-Regeln greifen: mehrere Elemente werden per
   hidden-Attribut geschaltet, haben aber ein eigenes display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  max-width: 33rem;
  margin: 0 auto;
  min-height: 100dvh;
}

.view { display: none; }
body[data-view="install"] .view-install,
body[data-view="enrol"] .view-enrol,
body[data-view="card"] .view-card,
body[data-view="edit"] .view-edit,
body[data-view="stages"] .view-stages,
body[data-view="settings"] .view-settings { display: block; }

body[data-view="card"] .view-card {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: calc(100dvh - 2rem);
}

/* ------------------------------------------------------------------ Typo */

h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h2 {
  margin: 0 0 0.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}

.head { margin-bottom: 1.2rem; }

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Sprache und Thema, gleiche Optik wie bei Copy */
.prefs { display: flex; gap: 0.4rem; font-size: 0.8rem; }
.prefs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.2rem;
  height: 2.2rem;
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}
.prefs a:hover { color: var(--accent); border-color: var(--accent); }
.prefs a.icon { padding: 0; }

/* Version und Releasedatum, unten rechts */
.version {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.5rem, env(safe-area-inset-bottom));
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.8;
  pointer-events: none;
  z-index: 10;
}
body.is-fullscreen .version { display: none; }

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.lead, .note, .hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.note { margin-top: 0.6rem; font-size: 0.85rem; }

a { color: var(--accent); }

/* --------------------------------------------------------------- Profile */

.tabs {
  display: flex;
  gap: 0.4rem;
}

.tab {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  min-height: 44px;
  cursor: pointer;
}

.tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

#card-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--gap);
  flex: 1;
}

/* ------------------------------------------------------------- QR-Kachel */

.qr-tile {
  background: #FFFFFF;
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  touch-action: pan-y;
  align-self: center;
  width: 100%;
  max-width: 22rem;
}

#qr { width: 100%; }

.qr-tile svg {
  display: block;
  width: 100%;
  height: auto;
  shape-rendering: crispEdges;
}

.card-name {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
}

/* ------------------------------------------------------------- Stufenbar */

.stage-bar {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.stage-middle { flex: 1; text-align: center; min-width: 0; }

.step {
  width: 48px;
  height: 48px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.step:disabled { opacity: 0.3; cursor: default; }

.dots {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.4rem 0 0.5rem;
}

.dot {
  width: 26px;
  height: 6px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--line);
  cursor: pointer;
}

.dot.is-active { background: var(--accent); }

/* Was gerade im Code steckt: die Angaben selbst, nicht ihre Namen. */
.stage-fields {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Alle Angaben, die im Code stecken, in voller Textfarbe - nicht nur die neuen. */
.stage-fields li { word-break: break-word; color: var(--ink); }

/* ------------------------------------------------------------- Vollbild */

body.is-fullscreen { padding: 0; max-width: none; }
body.is-fullscreen .tabs,
body.is-fullscreen .foot,
body.is-fullscreen .card-name { display: none; }
body.is-fullscreen .qr-tile {
  max-width: none;
  border-radius: 0;
  padding: 1.25rem;
}
body.is-fullscreen #card-body { justify-content: center; }
body.is-fullscreen .stage-bar { padding: 0 1rem 1rem; }

/* --------------------------------------------------------------- Formular */

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.panel + .panel { margin-top: var(--gap); }

.field { margin-bottom: 0.9rem; }

.field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: max(16px, var(--fs));
}

.field input.big {
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: 0.2em;
  text-align: center;
  min-height: 56px;
}

.field input:focus-visible,
.field select:focus-visible,
.button:focus-visible,
.tab:focus-visible,
.dot:focus-visible,
.link:focus-visible,
.step:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.check input {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

.edit-group {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.edit-group:last-child { border-bottom: 0; }

/* -------------------------------------------------------------- Buttons */

.button {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0.6rem 0.9rem;
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: max(16px, var(--fs));
  cursor: pointer;
}

.button:disabled { opacity: 0.55; cursor: default; }

.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 500;
}

.button-primary:hover { background: var(--accent-hover); }

.button-danger { color: var(--danger); }

.actions { margin-top: 1.25rem; }
.actions-stack { display: flex; flex-direction: column; }

.foot {
  display: flex;
  justify-content: space-between;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.link {
  border: 0;
  background: none;
  padding: 0.5rem 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.link:hover { color: var(--accent); }

/* -------------------------------------------------------------- Stufen */

.stage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stage-table td {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.stage-table td:last-child { text-align: right; width: 9rem; }

.stage-kinds { display: grid; gap: 1rem; }
@media (min-width: 640px) { .stage-kinds { grid-template-columns: 1fr 1fr; } }
.stage-kind h3 { margin: 0 0 0.5rem; font-size: 0.95rem; font-weight: 600; }
.stage-count { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.4rem; }
.stage-count select {
  min-height: 40px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
}

.stage-table select {
  min-height: 40px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
}

/* ---------------------------------------------------------------- Sonstiges */

.notice {
  border-left: 3px solid var(--warn);
  background: var(--warn-bg);
  padding: 0.7rem 0.9rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.steps { margin: 0; padding-left: 1.2em; color: var(--muted); font-size: 0.9rem; }
.steps li { margin-bottom: 0.5rem; }
.steps li::marker { color: var(--accent); }

#scan-video {
  width: 100%;
  margin-top: 0.6rem;
  border-radius: var(--radius-sm);
  background: #000;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
  font-size: 0.9rem;
}

.info dt { color: var(--muted); }
.info dd { margin: 0; word-break: break-word; }

.sheet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(6, 9, 11, 0.7);
  z-index: 25;
}

.sheet-inner {
  width: 100%;
  max-width: 33rem;
  margin: 0 auto;
  padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--card);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(1rem);
  max-width: calc(100% - 2rem);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: var(--toast);
  color: var(--toast-ink);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
