/* ==========================================================================
   Basis-Styles (Farben, Schrift, Buttons, Formulare)
   Farben zentral über die Variablen in :root anpassen.
   ========================================================================== */

:root {
  --bg:           #eef3f3;
  --surface:      #ffffff;
  --surface-2:    #e3f0f0;
  --surface-3:    #d3e6e6;
  --border:       #dbe5e5;
  --text:         #1b2526;
  --muted:        #556466;
  --primary:      #0f6b70; /* Petrol – weiß darauf: Kontrast 6,4 : 1 */
  --primary-h:    #0c595d;
  --primary-press: #0c595d; /* Knopf beim Überfahren */
  --primary-soft: #e3f0f0;
  --ok:           #2e7d4f;
  --ok-soft:      #e5f3ea;
  --err:          #c0362c;
  --err-soft:     #fcebea;
  --warn:         #b7791f;
  --warn-soft:    #fdf3e2;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 2px rgba(20, 30, 32, .06);
  /* getönte Schrift auf getönten Flächen, Kopf/Leisten, Abstufungen */
  --ok-text:      #1d5a37;
  --err-text:     #8c2219;
  --warn-text:    #6f480c;
  --primary-text: #0d5f63;
  --pdf-text:     #6f480c;
  --faint:        #5f6e70;
  --desc:         #3f4d4f;
  --header-bg:    rgba(238, 243, 243, .94);
  --bar-bg:       rgba(255, 255, 255, .97);
  --row-hover:    #f4f8f8;
  --tint-line:    #c9e1e1;  /* Rand auf getönten Flächen (Bestellschluss) */
  --glow-a:       #dcefef;  /* zarter Farbschimmer der Begrüßung */
  --glow-b:       #fbeee5;
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Basis ---------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--primary-h); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-weight: 680; letter-spacing: -.015em; }
h1 { font-size: clamp(26px, 4.5vw, 34px); }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p  { margin: 0 0 1em; }

img { max-width: 100%; display: block; }

.muted { color: var(--muted); }
.small { font-size: 14px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- Buttons ---------- */
[hidden] { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 620;
  font-size: 15px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--primary-press); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .nav a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary-h);
  outline-offset: 2px;
}
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }

.btn.secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.secondary:hover { background: var(--surface-3); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--err-soft); border-color: rgba(239, 90, 90, .35); color: var(--err-text); }
.btn.danger:hover { background: rgba(239, 90, 90, .25); }
.btn.ok { background: var(--ok-soft); border-color: rgba(63, 185, 122, .35); color: var(--ok-text); }
.btn.ok:hover { background: rgba(63, 185, 122, .25); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 16px; padding: 12px 24px; }

/* ---------- Formulare ---------- */
.form { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

.field { display: grid; gap: 6px; align-content: start; } /* Felder nebeneinander bleiben auf einer Höhe */
.field label, label.lbl { font-size: 14px; font-weight: 600; color: var(--muted); }

input[type=text], input[type=email], input[type=tel], input[type=date], input[type=datetime-local], input[type=search],
input[type=number], input:not([type]), select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* verhindert Zoom auf iOS */
  transition: border-color .15s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }
input[type=date], input[type=datetime-local] { color-scheme: inherit; }
select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a3a9b4' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select option { background: var(--surface); color: var(--text); }
input.otp {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .4em;
  padding-left: calc(14px + .4em);
  font-variant-numeric: tabular-nums;
}
/* Code-Eingabe im Glas-Look: sechs Kästchen über einem einzigen echten Eingabefeld
   (Einfügen, Autofill per SMS/Mail und Bedienung ohne JavaScript bleiben erhalten) */
.otp-glass {
  position: relative;
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px;
  padding: 14px; border-radius: 18px;
  background:
    radial-gradient(70% 120% at 10% 0%, var(--glow-a) 0%, transparent 70%),
    radial-gradient(70% 120% at 95% 100%, var(--glow-b) 0%, transparent 70%),
    var(--surface-2);
  border: 1px solid var(--border);
}
.otp-slot {
  aspect-ratio: 4 / 5; display: grid; place-items: center; position: relative;
  border-radius: 13px;
  font-size: 28px; font-weight: 680; font-variant-numeric: tabular-nums; color: var(--text);
  background: rgba(255, 255, 255, .55);
  border: 1px solid rgba(255, 255, 255, .85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 6px 18px rgba(15, 70, 74, .10);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
          backdrop-filter: blur(10px) saturate(1.4);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.otp-slot:empty::before { content: "•"; color: var(--faint); font-weight: 400; }
.otp-glass.is-focused .otp-slot.is-active {
  border-color: var(--primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 0 0 3px rgba(15, 107, 112, .18), 0 8px 20px rgba(15, 70, 74, .14);
  transform: translateY(-1px);
}
.otp-glass.is-focused .otp-slot.is-active:empty::before { content: ""; width: 2px; height: 1.1em; background: var(--primary); animation: otp-caret 1s steps(1) infinite; }
@keyframes otp-caret { 50% { opacity: 0; } }
.otp-glass.is-filled .otp-slot { border-color: var(--tint-line); }
/* das echte Feld liegt unsichtbar über den Kästchen */
.otp-glass input.otp {
  position: absolute; inset: 0; width: 100%; height: 100%;
  padding: 0; border: 0; border-radius: 18px; background: transparent;
  color: transparent; caret-color: transparent; font-size: 16px; letter-spacing: 0; text-align: left;
  outline: none; box-shadow: none; -webkit-text-fill-color: transparent;
}
.otp-glass input.otp::selection { background: transparent; }
.otp-glass input.otp::placeholder { color: transparent; }
:root[data-theme="dark"] .otp-slot { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 6px 18px rgba(0, 0, 0, .3); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .otp-slot { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 6px 18px rgba(0, 0, 0, .3); } }
/* Nach "Anmelden": Welle durch die Kästchen, bis die nächste Seite lädt */
.otp-glass.is-checking .otp-slot {
  border-color: var(--tint-line); background: var(--primary-soft); color: var(--primary-text);
  animation: otp-wave 1s ease-in-out infinite;
}
.otp-glass.is-checking .otp-slot:nth-child(2) { animation-delay: .08s; }
.otp-glass.is-checking .otp-slot:nth-child(3) { animation-delay: .16s; }
.otp-glass.is-checking .otp-slot:nth-child(4) { animation-delay: .24s; }
.otp-glass.is-checking .otp-slot:nth-child(5) { animation-delay: .32s; }
.otp-glass.is-checking .otp-slot:nth-child(6) { animation-delay: .40s; }
@keyframes otp-wave {
  0%, 60%, 100% { transform: translateY(0); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 4px 12px rgba(15, 70, 74, .08); }
  30% { transform: translateY(-6px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 0 0 3px rgba(15, 107, 112, .16), 0 12px 22px rgba(15, 70, 74, .16); }
}
/* Falscher Code: kurz schütteln, rot umrandet */
.otp-glass.is-error { animation: otp-shake .45s ease-in-out; }
.otp-glass.is-error .otp-slot { border-color: rgba(192, 54, 44, .55); }
@keyframes otp-shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
/* Ladekreis im Knopf statt Pfeil */
.btn.is-loading { pointer-events: none; }
.btn.is-loading::after, .auth2 .auth-box form .btn.is-loading::after {
  content: ""; width: 16px; height: 16px; margin-left: 10px; opacity: 1;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; border-radius: 50%;
  animation: btn-spin .7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .otp-slot, .otp-glass.is-checking .otp-slot, .otp-glass.is-error { transition: none; animation: none; } .btn.is-loading::after, .auth2 .auth-box form .btn.is-loading::after { animation-duration: 2s; } .otp-glass.is-focused .otp-slot.is-active:empty::before { animation: none; } }
@media (max-width: 380px) { .otp-glass { gap: 6px; padding: 10px; } .otp-slot { font-size: 24px; border-radius: 11px; } }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- Hinweise ---------- */
.notice, .alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 16px;
  font-size: 15px;
}
.notice ul, .alert ul { margin: 0; padding-left: 18px; }
.notice.ok,  .alert.success { background: var(--ok-soft);  border-color: rgba(63, 185, 122, .4); color: var(--ok-text); }
.notice.err, .alert.error, .error { background: var(--err-soft); border-color: rgba(239, 90, 90, .4); color: var(--err-text); }
.notice.warn { background: var(--warn-soft); border-color: rgba(240, 180, 76, .4); color: var(--warn-text); }
.error { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; }

/* ---------- Öffentlicher Bereich (neutral, ohne Branding) ---------- */
.public {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.public .auth-panel {
  width: 100%;
  max-width: 420px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.public .auth-box h1 { font-size: 26px; }

.auth-box { width: 100%; margin: 0 auto; }
.auth-box h1 { margin-bottom: 6px; }
.auth-box .lead { color: var(--muted); margin-bottom: 24px; }
.auth-foot { margin-top: 28px; font-size: 13px; color: var(--faint); text-align: center; }

/* ---------- Hinweis Testumgebung (nur bei APP_ENV = 'staging') ---------- */
.env-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 8px 16px;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #1a1300;
  background: repeating-linear-gradient(-45deg, #f0b44c 0 18px, #f6c76a 18px 36px);
  border-bottom: 2px solid #b9821f;
}
.env-banner { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; height: 37px; line-height: 21px; }
.env-banner ~ .app-header { top: 37px; }
.env-banner a { color: inherit; text-decoration: underline; }
.staging-otp { font-size: 1.25em; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
@media (max-width: 860px) { .env-banner-more { display: none; } }

/* ---------- iOS / Safari ---------- */
/* Sichtbare Höhe statt 100vh (Safari zählt sonst die Adressleiste mit) */
@supports (min-height: 100dvh) {
  body, .public { min-height: 100dvh; }
}
/* Nichts darf die Seite breiter als das Fenster machen */
/* nur auf html (wirkt auf das Fenster); auf body würde "hidden" die mitlaufende Kopfzeile stören */
html { overflow-x: hidden; }
@supports (overflow-x: clip) {
  body { overflow-x: clip; }
}
/* Safari-Standardformen von Feldern entfernen */
input[type=text], input[type=email], input[type=tel], input[type=search], input[type=date], input[type=datetime-local],
input[type=number], input:not([type]), textarea {
  -webkit-appearance: none;
  appearance: none;
}
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }
input[type=date], input[type=datetime-local] { min-width: 0; display: block; }
/* iOS zoomt beim Antippen in Felder mit Schrift unter 16 px hinein (und oft nicht wieder heraus) */
@media (pointer: coarse) {
  input:not(.otp), select, textarea { font-size: 16px !important; }
}
/* Lange Wörter/E-Mail-Adressen umbrechen statt über den Rand zu laufen */
body { overflow-wrap: break-word; }


/* ---------- Dunkles Design ----------
   Standard (auch öffentliche Seiten): hell · data-theme="dark": immer dunkel ·
   data-theme="auto": nach Einstellung des Geräts */
:root[data-theme="dark"] {
  --bg:           #111819;
  --surface:      #182123;
  --surface-2:    #1f2a2c;
  --surface-3:    #283537;
  --border:       #2a3638;
  --text:         #ecf1f0;
  --muted:        #a1b1b2;
  --primary:      #137479;
  --primary-h:    #5cc3c8;
  --primary-press: #0f6166;
  --primary-soft: rgba(26, 138, 144, .18);
  --ok:           #3fb97a;
  --ok-soft:      rgba(63, 185, 122, .14);
  --err:          #ef5a5a;
  --err-soft:     rgba(239, 90, 90, .14);
  --warn:         #f0b44c;
  --warn-soft:    rgba(240, 180, 76, .14);
  --shadow:       none;
  --ok-text:      #9fe6bf;
  --err-text:     #ffb3b3;
  --warn-text:    #ffe0a6;
  --primary-text: #8fdade;
  --pdf-text:     #ffd08a;
  --faint:        #8a9a9b;
  --desc:         #c6d1d0;
  --header-bg:    rgba(17, 24, 25, .94);
  --bar-bg:       rgba(24, 33, 35, .97);
  --row-hover:    rgba(255, 255, 255, .025);
  --tint-line:    #2c4547;
  --glow-a:       rgba(26, 138, 144, .22);
  --glow-b:       rgba(214, 140, 100, .10);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg:           #111819;
    --surface:      #182123;
    --surface-2:    #1f2a2c;
    --surface-3:    #283537;
    --border:       #2a3638;
    --text:         #ecf1f0;
    --muted:        #a1b1b2;
    --primary:      #137479;
    --primary-h:    #5cc3c8;
    --primary-press: #0f6166;
    --primary-soft: rgba(26, 138, 144, .18);
    --ok:           #3fb97a;
    --ok-soft:      rgba(63, 185, 122, .14);
    --err:          #ef5a5a;
    --err-soft:     rgba(239, 90, 90, .14);
    --warn:         #f0b44c;
    --warn-soft:    rgba(240, 180, 76, .14);
    --shadow:       none;
    --ok-text:      #9fe6bf;
    --err-text:     #ffb3b3;
    --warn-text:    #ffe0a6;
    --primary-text: #8fdade;
    --pdf-text:     #ffd08a;
    --faint:        #8a9a9b;
    --desc:         #c6d1d0;
    --header-bg:    rgba(17, 24, 25, .94);
    --bar-bg:       rgba(24, 33, 35, .97);
    --row-hover:    rgba(255, 255, 255, .025);
    --tint-line:    #2c4547;
    --glow-a:       rgba(26, 138, 144, .22);
    --glow-b:       rgba(214, 140, 100, .10);
    color-scheme: dark;
  }
}

/* ---------- Sprunglink „Zum Inhalt“ (nur bei Tastaturbedienung sichtbar) ---------- */
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 1000;
  padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font-weight: 700;
}
.skip-link:focus { top: 12px; text-decoration: none; }
main:focus { outline: none; }

/* Sichtbarer Fokus für alle bedienbaren Elemente */
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--primary-h); outline-offset: 2px;
}

/* Links im Fließtext unterstrichen (nicht nur an der Farbe erkennbar) */
p a:not(.btn), li a:not(.btn), .hint a, .auth-foot a, .notice a { text-decoration: underline; text-underline-offset: 2px; }

/* Nur für Screenreader sichtbar */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
