/* Handgeschriebenes CSS, mobil zuerst. Keine externen Abhängigkeiten. */

:root {
  --rot: #e30613;        /* DLRG-Rot */
  --rot-dunkel: #b00510;
  --gelb: #ffed00;       /* DLRG-Gelb */
  --blau: #004b8d;
  --grau-hell: #f4f4f5;
  --grau: #d4d4d8;
  --grau-dunkel: #52525b;
  --text: #18181b;
  --gruen: #15803d;
  --orange: #c2410c;
  --radius: 10px;
  --schatten: 0 1px 3px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--grau-hell);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Kopfzeile ---------- */

.kopf {
  background: var(--rot);
  color: #fff;
  box-shadow: var(--schatten);
}

.kopf-innen {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
}

.marke {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 18px;
  padding: 12px 0;
}

.navi {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.navi a {
  color: #fff;
  text-decoration: none;
  padding: 12px 10px;
  min-height: 44px;
  display: flex;
  align-items: center;
  border-radius: var(--radius) var(--radius) 0 0;
}

.navi a:hover { background: var(--rot-dunkel); }

/* ---------- Inhalt ---------- */

.inhalt {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 12px 32px;
}

h1 { font-size: 24px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 0 0 8px; }

.hinweis { color: var(--grau-dunkel); }
.leer { color: var(--grau-dunkel); font-style: italic; margin: 4px 0; }

/* ---------- Karten ---------- */

.karten {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .karten { grid-template-columns: 1fr 1fr; }
}

.karte {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  padding: 16px;
  min-width: 0; /* Grid-Kinder dürfen schmaler werden als ihr Inhalt (nowrap + ellipsis) */
}

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

label {
  display: block;
  font-weight: 600;
  margin: 12px 0 4px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 16px; /* verhindert Auto-Zoom auf iOS */
  border: 1px solid var(--grau);
  border-radius: var(--radius);
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--blau);
  outline-offset: 1px;
}

/* ---------- Knöpfe: mindestens 44px, nasse Finger ---------- */

.knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--grau);
  color: var(--text);
}

.knopf-primaer {
  background: var(--rot);
  border-color: var(--rot);
  color: #fff;
}

.knopf-primaer:hover { background: var(--rot-dunkel); }

.knopf:disabled { opacity: 0.6; cursor: wait; }

form .knopf { margin-top: 16px; width: 100%; }

@media (min-width: 640px) {
  form .knopf { width: auto; }
}

/* ---------- Meldungen ---------- */

.meldung {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 12px 0;
}

.meldung-fehler { background: #fee2e2; color: #991b1b; }
.meldung-ok { background: #dcfce7; color: #166534; }

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

.login-karte {
  max-width: 400px;
  margin: 24px auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  padding: 24px;
}

/* ---------- Seitenkopf mit Aktion ---------- */

.seitenkopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}

.seitenkopf h1 { margin: 0; }

/* ---------- Filterleiste ---------- */

.filterleiste {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.filterleiste input[type="search"] { grid-column: 1 / -1; }
.filterleiste .knopf { margin: 0; width: 100%; }

@media (min-width: 640px) {
  .filterleiste { grid-template-columns: 2fr 1fr 1fr auto; }
  .filterleiste input[type="search"] { grid-column: auto; }
}

/* ---------- Listen ---------- */

.liste {
  list-style: none;
  margin: 0;
  padding: 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  overflow: hidden;
}

.liste li + li { border-top: 1px solid var(--grau-hell); }

.liste-schlicht { box-shadow: none; border: 1px solid var(--grau-hell); }

.zeile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  min-height: 64px;
  text-decoration: none;
  color: var(--text);
}

.zeile:hover { background: var(--grau-hell); }

.zeile-haupt {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.zeile-haupt strong,
.zeile-haupt small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zeile-haupt small { color: var(--grau-dunkel); }

.thumb-platz {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--grau-hell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  overflow: hidden;
}

.thumb-platz img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Badges ---------- */

.badge {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.badge-ok { background: #dcfce7; color: var(--gruen); }
.badge-warn { background: #ffedd5; color: var(--orange); }
.badge-neutral { background: var(--grau-hell); color: var(--grau-dunkel); }

/* ---------- Detailseite ---------- */

.abschnitt { margin-top: 16px; }

.fakten {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
}

.fakten dt {
  font-size: 13px;
  color: var(--grau-dunkel);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fakten dd { margin: 0; }

.fakt-zahl {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
}

.fakt-zahl.warn { color: var(--orange); }
.fakt-zahl.blau { color: var(--blau); }

/* Kategorie / Ort / Schrank untereinander */

.meta-liste {
  list-style: none;
  margin: 8px 0;
  padding: 0;
}

.meta-liste li {
  display: flex;
  gap: 12px;
  padding: 6px 0;
}

.meta-liste li + li { border-top: 1px solid var(--grau-hell); }

.meta-liste span {
  flex: 0 0 90px;
  color: var(--grau-dunkel);
  font-size: 14px;
  padding-top: 2px;
}

.notiz { white-space: pre-line; }
.klein { font-size: 14px; color: var(--grau-dunkel); }
.klein a { color: var(--grau-dunkel); }
.feld-hinweis { margin-top: -4px; }

/* ---------- Karte (Standort) ---------- */

.karte-adresse { margin-top: 0; margin-bottom: 10px; }
.ort-karte {
  height: 280px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid #d4d4d8;
  z-index: 0; /* Leaflet-Bedienelemente unter der Kopfzeile halten */
}
.ort-karte .leaflet-container { font: inherit; }

.meldung-warn { background: #fef9c3; color: #854d0e; }

/* ---------- Historie ---------- */

.historie {
  list-style: none;
  margin: 0;
  padding: 0;
}

.historie li { padding: 8px 0; }
.historie li + li { border-top: 1px solid var(--grau-hell); }

.bewegung-typ {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  margin-right: 4px;
}

.typ-zugang, .typ-rueckgabe, .typ-repariert { background: #dcfce7; color: var(--gruen); }
.typ-ausgabe { background: #dbeafe; color: var(--blau); }
.typ-defekt, .typ-verlust { background: #fee2e2; color: #991b1b; }
.typ-korrektur, .typ-entsorgt { background: var(--grau-hell); color: var(--grau-dunkel); }

/* ---------- Buchen: Typ-Auswahl als Pills ---------- */

.typ-wahl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.typ-wahl label { margin: 0; font-weight: normal; }

.typ-wahl input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.typ-wahl span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--grau);
  border-radius: var(--radius);
  background: #fff;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.typ-wahl input:checked + span {
  background: var(--blau);
  border-color: var(--blau);
  color: #fff;
}

.typ-wahl input:focus-visible + span {
  outline: 2px solid var(--blau);
  outline-offset: 1px;
}

.buchen-zeile {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
}

.wahl-2 { grid-template-columns: 1fr 1fr; }

.verwalten-bereich {
  margin-top: 16px;
  padding-top: 4px;
  border-top: 1px solid var(--grau-hell);
}

/* ---------- Offene Ausleihen ---------- */

.ausleihen {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ausleihen li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 0;
}

.ausleihen li + li { border-top: 1px solid var(--grau-hell); }
.ausleihen form .knopf { margin: 0; width: auto; }

.ausleihe-info {
  flex: 1 1 200px;
  min-width: 0;
}

.ausleihe-info small {
  display: block;
  color: var(--grau-dunkel);
}

.rueckgabe-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.rueckgabe-form input[type="number"] {
  width: 72px;
  min-height: 44px;
  text-align: center;
}

/* ---------- Erklärung unter den Buchen-Buttons ---------- */

.typ-erklaerung {
  margin: 8px 2px 0;
  min-height: 2.6em;
}

/* ---------- Defektfälle ---------- */

.defekt-liste {
  list-style: none;
  margin: 0;
  padding: 0;
}

.defekt-fall { padding: 12px 0; }
.defekt-fall + .defekt-fall { border-top: 1px solid var(--grau-hell); }

.defekt-kopf {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.status-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.status-form input { flex: 1; }
.status-form .knopf { margin: 0; width: auto; flex: 0 0 auto; }

.defekt-aktionen {
  display: flex;
  gap: 8px;
}

.defekt-aktionen form { flex: 1; }
.defekt-aktionen .knopf { margin: 0; width: 100%; }

/* ---------- Kompakte Dashboard-Zeilen ---------- */

.zeile-kompakt { min-height: 52px; padding: 8px 4px; }

.thumb-klein {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  font-size: 18px;
}

/* ---------- Fotogalerie ---------- */

.galerie {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.foto-kachel {
  margin: 0;
  position: relative;
}

.foto-kachel a { display: block; }

.foto-kachel img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
}

.titelbild-marke {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--gelb);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.foto-aktionen {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.foto-aktionen form { flex: 1; }

.knopf-klein {
  min-height: 44px;
  padding: 4px 10px;
  font-size: 14px;
  width: 100%;
  margin: 0;
}

/* Datei-Auswahl */

input[type="file"] {
  width: 100%;
  padding: 10px 0;
  font-size: 15px;
}

.foto-vorschau {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.foto-vorschau:not(:empty) { margin: 8px 0; }

.vorschau-kachel {
  position: relative;
  width: 80px;
  height: 80px;
}

.vorschau-kachel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.vorschau-entfernen {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--rot);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* Fotos in der Historie */

.historie-fotos {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.historie-fotos img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

/* ---------- Einklappbare Abschnitte ---------- */

.einklapp summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.einklapp hr {
  border: none;
  border-top: 1px solid var(--grau-hell);
  margin: 16px 0;
}

/* ---------- Zählmodus ---------- */

.zaehl-liste {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  overflow: hidden;
}

.zaehl-zeile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: 64px;
}

.zaehl-zeile + .zaehl-zeile { border-top: 1px solid var(--grau-hell); }

/* Alt- und Neu-Feld nebeneinander. Die Breite liegt bewusst auf dem
   .zaehl-feld-Wrapper – der Input erbt die globale width:100% und bleibt
   so schmal, statt die globale input-Regel zu überschreiben. */
.zaehl-felder {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.zaehl-feld {
  flex: 0 0 62px;
  width: 62px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  margin: 0;
  font-weight: normal;
}

.zaehl-kopf {
  text-align: center;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--grau-dunkel);
}

.zaehl-zahl {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  padding-left: 4px;
  padding-right: 4px;
}

.zaehl-alt,
.zaehl-zahl:disabled { background: var(--grau-hell); color: var(--grau-dunkel); }

.zaehl-neu:focus { border-color: var(--blau); }

/* Beim Zählen den vollen Namen zeigen (statt abzuschneiden), damit sich
   ähnliche Positionen – z. B. Flossengrößen – unterscheiden lassen.
   Gleiches gilt für die Werte-Zeile darunter. */
.zaehl-zeile .zeile-haupt strong,
.zaehl-zeile .zeile-haupt small {
  overflow: visible;
  white-space: normal;
}

/* Soll / Defekt / Verliehen unter dem Materialnamen */
.zaehl-werte {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
}

.zaehl-werte .wert-warn {
  color: var(--rot);
  font-weight: 600;
}

.zaehl-gruppe {
  font-size: 16px;
  margin: 16px 0 8px;
  color: var(--grau-dunkel);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.brotkrume { margin: 4px 0 0; }

.abschnitt-klein { margin-top: 12px; }

/* Absende-Knopf klebt unten – ein Ort mit 20 Positionen ohne Hochscrollen */
.zaehl-aktion {
  position: sticky;
  bottom: 12px;
}

.zaehl-aktion .knopf {
  width: 100%;
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* ---------- Inventur-Detail ---------- */

/* Kopf einer Inventur: vorherige Zaehlung -> diese Zaehlung */
.datum-vergleich {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.datum-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.datum-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--grau-dunkel);
}

.datum-wert { font-size: 20px; line-height: 1.2; }
.datum-neu .datum-wert { color: var(--rot); }
.datum-leer { color: var(--grau-dunkel); }

.datum-pfeil {
  font-size: 22px;
  color: var(--grau-dunkel);
}

/* Datum unter der Spaltenueberschrift – ordnet jede Zahl ihrem Datum zu */
.spalten-datum {
  display: block;
  font-size: 11px;
  font-weight: normal;
  color: var(--grau-dunkel);
  white-space: nowrap;
}

/* Hinweis, wenn der Altwert ausnahmsweise aus einer anderen Zaehlung stammt */
.alt-quelle {
  display: block;
  font-size: 11px;
  font-weight: normal;
  color: var(--grau-dunkel);
  white-space: nowrap;
}

.inventur-tabelle {
  width: 100%;
  border-collapse: collapse;
}

.inventur-tabelle th,
.inventur-tabelle td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--grau-hell);
}

.inventur-tabelle th { font-size: 13px; color: var(--grau-dunkel); }
.inventur-tabelle .zahl { text-align: right; width: 68px; white-space: nowrap; }
.inventur-tabelle .alt { color: var(--grau-dunkel); }
.inventur-tabelle tr:last-child td { border-bottom: none; }
.inventur-tabelle .zeile-geaendert td { background: #fff7ed; }
.inventur-tabelle .diff { font-weight: 700; }

/* Die Tabelle darf notfalls in sich scrollen – die Seite selbst nie. */
.tabelle-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 480px) {
  /* Auf dem Smartphone stapeln, Pfeil zeigt dann nach unten */
  .datum-vergleich { flex-direction: column; align-items: flex-start; gap: 6px; }
  .datum-pfeil { transform: rotate(90deg); margin-left: 4px; }

  .inventur-tabelle th,
  .inventur-tabelle td { padding: 8px 6px; }
  .inventur-tabelle .zahl { width: 56px; }
  .spalten-datum { font-size: 10px; }
}

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

.qr-anzeige {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.qr-anzeige img {
  border: 1px solid var(--grau);
  border-radius: var(--radius);
  background: #fff;
}

.qr-blatt {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.qr-karte {
  background: #fff;
  border: 1px dashed var(--grau);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  break-inside: avoid;
}

.qr-karte img {
  width: 100%;
  max-width: 220px;
  height: auto;
}

.qr-verein {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--grau-dunkel);
}

.qr-ort {
  margin: 8px 0 0;
  font-weight: 700;
  font-size: 18px;
}

@media print {
  .kopf, .fuss, .nur-bildschirm { display: none !important; }
  body { background: #fff; }
  .inhalt { max-width: none; padding: 0; }
  .qr-blatt { grid-template-columns: repeat(2, 1fr); gap: 10mm; }
  .qr-karte { border: 1px dashed #999; }
}

/* ---------- Fußzeile ---------- */

.fuss {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--grau-dunkel);
  font-size: 14px;
}

.fuss a {
  color: var(--grau-dunkel);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.fuss-links { display: flex; gap: 16px; }

/* ---------- Einstellungen ---------- */

.fakten-liste {
  list-style: none;
  margin: 0;
  padding: 0;
}

.fakten-liste li { padding: 6px 0; }
.fakten-liste li + li { border-top: 1px solid var(--grau-hell); }

.fakten-liste code,
.karte code {
  background: var(--grau-hell);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 14px;
}

.export-knoepfe {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Kategorien umbenennen */

.kategorie-liste {
  list-style: none;
  margin: 0;
  padding: 0;
}

.kategorie-liste li { padding: 10px 0; }
.kategorie-liste li + li { border-top: 1px solid var(--grau-hell); }

.kategorie-zeile {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
}

.kategorie-zeile input[type="text"] { margin: 0; }
.kategorie-zeile .knopf { margin: 0; width: 100%; }

.kategorie-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (min-width: 640px) {
  .kategorie-zeile { grid-template-columns: 1fr 1fr auto; }
  .kategorie-zeile .knopf { width: auto; }
}
