/* ============================================================================
   FC Viktoria Heiden -- Rechte & Login
   Mobile-first. Jede Farbe ausschliesslich ueber var(--...) -- kein einziger
   direkter Farbwert irgendwo sonst im Stylesheet.
   ============================================================================ */

:root {
  color-scheme: light dark;

  --touch: 48px;
  --radius: 10px;
  --safe-oben: env(safe-area-inset-top, 0px);
  --safe-unten: env(safe-area-inset-bottom, 0px);
  --safe-links: env(safe-area-inset-left, 0px);
  --safe-rechts: env(safe-area-inset-right, 0px);

  /* --- Hell (Standard) --- */
  --bg: #f2f4f7;
  --flaeche: #ffffff;
  --flaeche-erhoeht: #ffffff;
  --text: #101828;
  --text-schwach: #667085;
  --rand: #d0d5dd;
  --primaer: #17356b;
  --primaer-hell: #2c5aa0;
  --primaer-text: #ffffff;

  --erfolg-bg: #d1fadf;
  --erfolg-text: #17803d;
  --warnung-bg: #fef0c7;
  --warnung-text: #93370d;
  --fehler-bg: #fee4e2;
  --fehler-text: #b42318;
  --info-bg: #d1e9ff;
  --info-text: #2c5aa0;
}

/* System-Praeferenz greift nur, wenn der Benutzer nichts explizit gewaehlt hat */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f1319;
    --flaeche: #1a2029;
    --flaeche-erhoeht: #232a35;
    --text: #e4e7ec;
    --text-schwach: #94a3b8;
    --rand: #2d3542;
    --primaer: #7da2d9;
    --primaer-hell: #9db8e3;
    --primaer-text: #0f1319;

    --erfolg-bg: #0f3324;
    --erfolg-text: #4ade80;
    --warnung-bg: #3a2a0f;
    --warnung-text: #fbbf24;
    --fehler-bg: #3a1412;
    --fehler-text: #f87171;
    --info-bg: #10243d;
    --info-text: #7da2d9;
  }
}

/* Explizite Wahl "dunkel" -- unabhaengig vom OS */
:root[data-theme="dunkel"] {
  --bg: #0f1319;
  --flaeche: #1a2029;
  --flaeche-erhoeht: #232a35;
  --text: #e4e7ec;
  --text-schwach: #94a3b8;
  --rand: #2d3542;
  --primaer: #7da2d9;
  --primaer-hell: #9db8e3;
  --primaer-text: #0f1319;

  --erfolg-bg: #0f3324;
  --erfolg-text: #4ade80;
  --warnung-bg: #3a2a0f;
  --warnung-text: #fbbf24;
  --fehler-bg: #3a1412;
  --fehler-text: #f87171;
  --info-bg: #10243d;
  --info-text: #7da2d9;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

a, button, input, select, textarea { -webkit-tap-highlight-color: transparent; }

/* ---------------------------------------------------------------------------
   Kopfbereich
   --------------------------------------------------------------------------- */

header.top {
  background: var(--primaer);
  color: var(--primaer-text);
  padding: calc(10px + var(--safe-oben)) calc(14px + var(--safe-rechts)) 10px calc(14px + var(--safe-links));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 30;
}

header.top h1 {
  font-size: 0.95rem;
  margin: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kopf-aktionen { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.nutzer-name { display: none; }

header.top button {
  background: var(--primaer-hell);
  color: var(--primaer-text);
  border: none;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

/* Theme-Umschalter: drei Tasten hell/system/dunkel */
.theme-schalter { display: flex; background: var(--primaer-hell); border-radius: 8px; overflow: hidden; }
.theme-schalter button {
  background: none; min-height: 40px; min-width: 40px; padding: 0 10px;
  border: none; color: var(--primaer-text); opacity: 0.6; cursor: pointer; font-size: 1rem;
}
.theme-schalter button.aktiv { opacity: 1; background: rgba(0,0,0,0.15); }

/* ---------------------------------------------------------------------------
   Reiternavigation
   --------------------------------------------------------------------------- */

nav.tabs {
  display: flex;
  gap: 2px;
  background: var(--flaeche);
  border-bottom: 1px solid var(--rand);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky;
  top: 0;
  z-index: 20;
  padding-left: var(--safe-links);
  padding-right: var(--safe-rechts);
}
nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs button {
  border: none; background: none; min-height: var(--touch); padding: 0 16px;
  cursor: pointer; font-size: 0.9rem; color: var(--text-schwach);
  border-bottom: 3px solid transparent; white-space: nowrap; flex-shrink: 0; font-family: inherit;
}
nav.tabs button.active { color: var(--primaer); border-bottom-color: var(--primaer); font-weight: 600; }

/* ---------------------------------------------------------------------------
   Hauptbereich, Karten
   --------------------------------------------------------------------------- */

main { padding: 12px calc(12px + var(--safe-rechts)) calc(28px + var(--safe-unten)) calc(12px + var(--safe-links)); }

.card {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h3, .card h4 { margin-top: 0; }
.card h3 { font-size: 1.05rem; }
.card h4 { font-size: 0.95rem; }

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

label { font-size: 0.85rem; color: var(--text-schwach); display: block; margin-bottom: 4px; }

input, select, textarea {
  width: 100%; min-height: var(--touch); padding: 10px 12px;
  border: 1px solid var(--rand); border-radius: 8px; margin-bottom: 12px;
  font-family: inherit; background: var(--flaeche-erhoeht); color: var(--text);
  font-size: 16px; /* mind. 16px -- sonst zoomt iOS Safari beim Fokussieren */
  -webkit-appearance: none; appearance: none;
}

select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 40px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primaer-hell); outline-offset: -1px; border-color: var(--primaer-hell);
}

/* Die Regel oben nimmt jedem Feld das Systemaussehen ("appearance: none",
   noetig gegen die iOS-Eigenheiten bei Text- und Auswahlfeldern). Damit
   verschwindet aber auch das Haekchen im Ankreuzfeld -- angekreuzt sah aus
   wie leer. Es wird deshalb hier selbst gezeichnet. */
input[type="checkbox"] {
  width: 22px; height: 22px; min-height: 22px; flex-shrink: 0;
  margin: 0; padding: 0; cursor: pointer;
  border: 1px solid var(--rand); border-radius: 6px;
  background: var(--flaeche-erhoeht);
  display: inline-grid; place-content: center;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
input[type="checkbox"]::before {
  content: ""; width: 13px; height: 13px;
  transform: scale(0); transition: transform 0.12s ease-in-out;
  background-color: var(--primaer-text);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
input[type="checkbox"]:checked {
  background: var(--primaer); border-color: var(--primaer);
}
input[type="checkbox"]:checked::before { transform: scale(1); }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--primaer-hell); outline-offset: 2px; }
input[type="checkbox"]:disabled { opacity: 0.5; cursor: not-allowed; }

label.check {
  display: flex; align-items: center; gap: 10px; min-height: var(--touch);
  font-size: 0.95rem; cursor: pointer; margin-bottom: 4px;
}

/* ---------------------------------------------------------------------------
   Schaltflaechen
   --------------------------------------------------------------------------- */

button.primary, button.secondary {
  width: 100%; min-height: var(--touch); border-radius: 8px; cursor: pointer;
  font-size: 1rem; font-family: inherit; padding: 0 18px; margin-bottom: 8px;
}
button.primary { background: var(--primaer); color: var(--primaer-text); border: none; font-weight: 600; }
button.primary:disabled { opacity: 0.5; }
button.secondary { background: var(--flaeche); color: var(--primaer); border: 1px solid var(--primaer); font-weight: 500; }

button.danger {
  color: var(--fehler-text); background: var(--flaeche); border: 1px solid var(--fehler-text);
  min-height: 40px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; font-family: inherit;
}

.btn-reihe { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-reihe button { width: auto; flex: 1 1 auto; min-width: 120px; }

/* ---------------------------------------------------------------------------
   Tabellen -> Karten auf dem Handy, echte Tabelle ab Tablet
   --------------------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
thead { display: none; }

tbody tr {
  display: block; border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 10px; background: var(--flaeche);
}
tbody td {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 5px 0; border: none; font-size: 0.95rem;
}
tbody td::before {
  content: attr(data-label); font-size: 0.78rem; text-transform: uppercase;
  color: var(--text-schwach); font-weight: 600; flex-shrink: 0;
}
tbody td:not([data-label]) { justify-content: stretch; padding-top: 8px; }
tbody td:not([data-label])::before { content: none; }

/* ---------------------------------------------------------------------------
   Statusmarken, Hinweise
   --------------------------------------------------------------------------- */

.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 0.78rem; font-weight: 600; }
.badge.aktiv, .badge.ok { background: var(--erfolg-bg); color: var(--erfolg-text); }
.badge.inaktiv { background: var(--fehler-bg); color: var(--fehler-text); }
.badge.sensibel { background: var(--warnung-bg); color: var(--warnung-text); }
.badge.info { background: var(--info-bg); color: var(--info-text); }

.error {
  background: var(--fehler-bg); color: var(--fehler-text); padding: 12px 14px;
  border-radius: 8px; margin-bottom: 12px; font-size: 0.92rem;
  /* Mehrere Feldfehler kommen zeilenweise -- Umbrueche sollen stehen bleiben. */
  white-space: pre-line;
}
.erfolg-meldung {
  background: var(--erfolg-bg); color: var(--erfolg-text); padding: 12px 14px;
  border-radius: 8px; margin-bottom: 12px; font-size: 0.92rem;
}
.hinweis { color: var(--text-schwach); font-size: 0.85rem; margin: 6px 0; }

/* Rechte-Matrix: Ankreuzfelder je Rolle/Recht */
.rechte-liste { display: flex; flex-direction: column; gap: 2px; }
.rechte-zeile {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--rand); min-height: var(--touch);
}
.rechte-zeile:last-child { border-bottom: none; }
.rechte-zeile .recht-name { flex: 1; font-size: 0.9rem; }

/* ---------------------------------------------------------------------------
   Login-Seite
   --------------------------------------------------------------------------- */

.login-wrap {
  min-height: 100svh; display: flex; align-items: center; justify-content: center;
  background: var(--primaer);
  padding: calc(16px + var(--safe-oben)) calc(16px + var(--safe-rechts)) calc(16px + var(--safe-unten)) calc(16px + var(--safe-links));
}
.login-card { background: var(--flaeche); border-radius: 14px; padding: 26px 22px; width: 100%; max-width: 400px; }
.login-card h1 { color: var(--primaer); font-size: 1.15rem; margin: 0 0 4px; }

/* ============================================================================
   Ab 600px
   ============================================================================ */

@media (min-width: 600px) {
  main { padding: 16px; max-width: 760px; margin: 0 auto; }
  .card { padding: 18px; }
  header.top h1 { font-size: 1.05rem; }
  .nutzer-name { display: inline; font-size: 0.85rem; opacity: 0.9; }
  button.primary, button.secondary { width: auto; min-width: 150px; }

  thead { display: table-header-group; }
  tbody tr { display: table-row; border: none; border-bottom: 1px solid var(--rand); border-radius: 0; padding: 0; margin: 0; }
  tbody td { display: table-cell; padding: 11px 8px; vertical-align: middle; }
  tbody td::before { content: none; }
  th {
    text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--rand);
    color: var(--text-schwach); font-weight: 600; font-size: 0.78rem; text-transform: uppercase;
  }
}

@media (hover: hover) {
  button.primary:hover { background: var(--primaer-hell); }
  button.secondary:hover { background: var(--bg); }
  nav.tabs button:hover { color: var(--primaer); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------------------
   Oeffentliches Antragsformular (antrag.html)
   Eigener Abschnitt, damit das Fundament unveraendert bleibt.
--------------------------------------------------------------------------- */

.antrag-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px calc(12px + var(--safe-rechts)) calc(32px + var(--safe-unten)) calc(12px + var(--safe-links));
}

.antrag-kopf {
  text-align: center;
  padding: 18px 12px 6px;
}
.antrag-kopf h1 { color: var(--primaer); font-size: 1.2rem; margin: 0 0 4px; }
.antrag-kopf p { margin: 0; }

/* Zwei Felder nebeneinander ab Tablet, am Handy untereinander */
.feld-paar { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 600px) { .feld-paar { grid-template-columns: 1fr 1fr; } }

.pflicht { color: var(--fehler-text); }

/* Sportart-Auswahl als grosse, mit dem Daumen treffbare Kacheln */
.wahl-kacheln { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.wahl-kachel {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: var(--touch); padding: 10px 8px;
  border: 1px solid var(--rand); border-radius: var(--radius);
  background: var(--flaeche-erhoeht); color: var(--text);
  font-size: 0.9rem; cursor: pointer;
}
.wahl-kachel.gewaehlt { border-color: var(--primaer); background: var(--info-bg); color: var(--info-text); font-weight: 600; }

/* Unterschrift: der Canvas muss Touch-Gesten selbst verarbeiten,
   sonst scrollt die Seite beim Schreiben weg (touch-action: none). */
.unterschrift-flaeche {
  position: relative;
  border: 1px dashed var(--rand);
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}
canvas.unterschrift { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; }
.unterschrift-linie {
  position: absolute; left: 16px; right: 16px; bottom: 42px;
  border-bottom: 1px solid #c8ccd4; pointer-events: none;
}
.unterschrift-hinweis {
  position: absolute; left: 16px; bottom: 20px;
  color: #98a2b3; font-size: 0.8rem; pointer-events: none;
}

.familien-zeile {
  border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 10px; margin-bottom: 10px; background: var(--flaeche-erhoeht);
}

.beitrag-zeile { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 0.9rem; }
.beitrag-zeile.summe {
  border-top: 1px solid var(--primaer); margin-top: 6px; padding-top: 8px;
  font-weight: 700; font-size: 1rem;
}
.beitrag-zeile .abzug { color: var(--erfolg-text); }

.erfolg-gross { text-align: center; padding: 20px 10px; }
.erfolg-gross .haken {
  font-size: 2.6rem; line-height: 1;
  color: var(--erfolg-text);
}

/* Honigtopf: fuer Menschen unsichtbar, fuer Bots verlockend.
   Kein display:none -- manche Bots ueberspringen genau das. */
.honigtopf {
  position: absolute; left: -9999px; width: 1px; height: 1px;
  overflow: hidden; opacity: 0;
}

/* Der PDF-Link nach dem Absenden soll wie ein Knopf aussehen und sich wie
   ein Link verhalten (neuer Tab, Download durch den Browser). */
a.btn-link {
  display: block; text-align: center; text-decoration: none;
  min-height: var(--touch); padding: 12px 14px; border-radius: var(--radius);
  background: var(--primaer); color: var(--primaer-text); font-weight: 600;
}

/* Unterschrift im Backoffice -- auf weissem Grund, damit die schwarze
   Tinte auch im dunklen Erscheinungsbild lesbar bleibt. */
.unterschrift-anzeige {
  background: #ffffff; border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 6px; display: inline-block; max-width: 100%;
}
.unterschrift-anzeige img { display: block; max-width: 100%; height: auto; }

.feld-zeile { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--rand); font-size: 0.9rem; }
.feld-zeile:last-child { border-bottom: none; }
.feld-zeile .feld-name { color: var(--text-schwach); flex-shrink: 0; }
.feld-zeile .feld-wert { text-align: right; word-break: break-word; }
