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

:root {
  --bg:           #111317;
  --surface:      #1a1d23;
  --surface-2:    #22262e;
  --surface-3:    #2b3039;
  --border:       #2e333d;
  --text:         #f3efe9;
  --muted:        #a3a9b4;
  --primary:      #c94420; /* weiß darauf: Kontrast 4,8 : 1 (WCAG AA) */
  --primary-h:    #e65b33;
  --primary-soft: rgba(214, 74, 36, .14);
  --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);
  --radius:       14px;
  --radius-sm:    10px;
  --shadow:       0 10px 30px rgba(0, 0, 0, .35);
  /* getönte Schrift auf getönten Flächen, Kopf/Leisten, Abstufungen */
  --ok-text:      #9fe6bf;
  --err-text:     #ffb3b3;
  --warn-text:    #ffe0a6;
  --primary-text: #ffb39c;
  --pdf-text:     #ffd08a;
  --faint:        #80868f;
  --desc:         #cfcac2;
  --header-bg:    rgba(17, 19, 23, .92);
  --bar-bg:       rgba(26, 29, 35, .96);
  --row-hover:    rgba(255, 255, 255, .02);
  color-scheme: dark;
  --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: 750; letter-spacing: -.01em; }
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: 700;
  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: #b13a1a; 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, .btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.secondary:hover, .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;
}
.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-links { margin-top: 22px; display: grid; gap: 6px; font-size: 15px; color: var(--muted); text-align: center; }
.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; }


/* ---------- Helles Design ----------
   data-theme="light": immer hell · data-theme="auto": nach Einstellung des Geräts ·
   ohne Angabe (öffentliche Seiten mit Foto): dunkel */
:root[data-theme="light"] {
  --bg:           #f5f3f0;
  --surface:      #ffffff;
  --surface-2:    #f1eee9;
  --surface-3:    #e6e1da;
  --border:       #e0dad2;
  --text:         #1f2328;
  --muted:        #5c636e;
  --primary-h:    #c2401c;
  --primary-soft: rgba(214, 74, 36, .10);
  --ok-soft:      rgba(47, 163, 107, .12);
  --err-soft:     rgba(220, 60, 60, .10);
  --warn-soft:    rgba(222, 150, 30, .14);
  --ok-text:      #17693f;
  --err-text:     #a42a20;
  --warn-text:    #7a4e00;
  --primary-text: #a8361a;
  --pdf-text:     #7a4e00;
  --faint:        #666c76;
  --desc:         #4b5159;
  --header-bg:    rgba(255, 255, 255, .92);
  --bar-bg:       rgba(255, 255, 255, .96);
  --row-hover:    rgba(0, 0, 0, .025);
  --shadow:       0 10px 30px rgba(31, 35, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg:           #f5f3f0;
    --surface:      #ffffff;
    --surface-2:    #f1eee9;
    --surface-3:    #e6e1da;
    --border:       #e0dad2;
    --text:         #1f2328;
    --muted:        #5c636e;
    --primary-h:    #c2401c;
    --primary-soft: rgba(214, 74, 36, .10);
    --ok-soft:      rgba(47, 163, 107, .12);
    --err-soft:     rgba(220, 60, 60, .10);
    --warn-soft:    rgba(222, 150, 30, .14);
    --ok-text:      #17693f;
    --err-text:     #a42a20;
    --warn-text:    #7a4e00;
    --primary-text: #a8361a;
    --pdf-text:     #7a4e00;
    --faint:        #666c76;
    --desc:         #4b5159;
    --header-bg:    rgba(255, 255, 255, .92);
    --bar-bg:       rgba(255, 255, 255, .96);
    --row-hover:    rgba(0, 0, 0, .025);
    --shadow:       0 10px 30px rgba(31, 35, 40, .08);
    color-scheme: light;
  }
}

/* ---------- 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-links 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; }
