/* Meine Herde Web-App — Design "Weide" (identisch zur Android-App).
   0 externe Requests: Systemschriften, eigene Icons. */

:root {
  --primary: #176B3D;
  --on-primary: #FFFFFF;
  --primary-container: #D8F0E2;
  --on-primary-container: #0B3A22;
  --secondary: #5D6B63;
  --secondary-container: #E3E9E5;
  --tertiary: #BC6B3B;
  --tertiary-container: #F6DECB;
  --on-tertiary-container: #8A3E22;
  --background: #F2F5F3;
  --surface: #FFFFFF;
  --surface-variant: #E7ECE9;
  --on-surface-variant: #48524C;
  --outline: #8B958F;
  --outline-variant: #DBE2DE;
  --text: #141A17;
  --error: #B3261E;
  --error-container: #F6DACF;
  --on-error-container: #410E0B;
  --radius: 12px;
  --radius-card: 14px;
  --shadow: 0 1px 3px rgba(20, 26, 23, .10), 0 1px 2px rgba(20, 26, 23, .06);
  --login-bg: #2F3237;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  min-height: 100%;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}
img { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }
[hidden] { display: none !important; }

/* ---------- Grundlayout ---------- */
#main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ---------- Top-Bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 0 10px;
  padding-top: calc(14px + env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 5;
  background: var(--background);
}
.topbar h1 { font-size: 22px; font-weight: 700; flex: 1; letter-spacing: .2px; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back {
  border: none; background: none; padding: 6px; margin-left: -6px;
  display: flex; align-items: center; color: var(--text);
}
.herdchip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--outline-variant);
  border-radius: 20px; padding: 5px 12px 5px 6px;
  font-size: 14px; font-weight: 600; color: var(--text);
  box-shadow: var(--shadow);
}
.herdchip img { width: 26px; height: 26px; object-fit: contain; }

/* ---------- Karten & Sektionen ---------- */
.sektion {
  font-size: 12.5px; font-weight: 700; letter-spacing: 1.1px;
  text-transform: uppercase; color: var(--primary);
  margin: 20px 2px 8px;
}
.card {
  background: var(--surface); border-radius: var(--radius-card);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
.card.klick { cursor: pointer; }
.card.klick:active { background: var(--surface-variant); }

/* Dashboard-Statistik-Kacheln */
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  background: var(--surface); border-radius: var(--radius-card);
  box-shadow: var(--shadow); padding: 14px; display: flex; align-items: center; gap: 12px;
}
.stat img { width: 44px; height: 44px; object-fit: contain; }
.stat .zahl { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat .label { font-size: 13px; color: var(--on-surface-variant); }

/* ---------- Listenzeilen ---------- */
.zeile {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px; cursor: pointer;
  border-bottom: 1px solid var(--outline-variant);
}
.zeile:last-child { border-bottom: none; }
.zeile:active { background: var(--surface-variant); }
.zeile .avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: none;
  object-fit: cover; background: var(--surface-variant);
  display: flex; align-items: center; justify-content: center;
}
.zeile .avatar.icon { object-fit: contain; padding: 7px; background: var(--primary-container); }
.zeile .mitte { flex: 1; min-width: 0; }
.zeile .titel { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zeile .unter { font-size: 13.5px; color: var(--on-surface-variant); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zeile .rechts { flex: none; text-align: right; font-size: 13.5px; color: var(--on-surface-variant); }
.chevron { flex: none; color: var(--outline); }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 2px 9px; border-radius: 8px;
  background: var(--secondary-container); color: var(--secondary);
}
.badge.warn { background: var(--tertiary-container); color: var(--on-tertiary-container); }
.badge.gruen { background: var(--primary-container); color: var(--on-primary-container); }
.badge.rot { background: var(--error-container); color: var(--on-error-container); }

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip {
  border: 1px solid var(--outline-variant); background: var(--surface);
  color: var(--text); border-radius: 9px; padding: 6px 14px;
  font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
}
.chip.aktiv { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chip.aktiv::before { content: "✓"; font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--primary); color: var(--on-primary);
  border: none; border-radius: var(--radius); padding: 12px 20px;
  font-size: 15.5px; font-weight: 700; width: 100%;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.sekundaer { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); }
.btn.leise { background: var(--surface-variant); color: var(--text); }
.btn.gefahr { background: var(--error); }
.btn.klein { width: auto; padding: 8px 16px; font-size: 14px; }
.btn-reihe { display: flex; gap: 10px; margin-top: 14px; }
.btn-reihe .btn { flex: 1; }
.textbtn { background: none; border: none; color: var(--primary); font-weight: 600; padding: 8px; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 17px; border: none;
  background: var(--primary); color: var(--on-primary); font-size: 30px; line-height: 1;
  box-shadow: 0 4px 12px rgba(11, 58, 34, .35); z-index: 6;
  display: flex; align-items: center; justify-content: center;
}
@media (min-width: 700px) { .fab { right: calc(50% - 320px + 18px); } }

/* ---------- Formulare ---------- */
.feld { margin-bottom: 14px; }
.feld label { display: block; font-size: 13px; font-weight: 600; color: var(--on-surface-variant); margin-bottom: 5px; }
.feld input, .feld select, .feld textarea {
  width: 100%; padding: 12px 13px; border: 1.5px solid var(--outline-variant);
  border-radius: var(--radius); background: var(--surface); font-size: 15.5px;
}
.feld input:focus, .feld select:focus, .feld textarea:focus {
  outline: none; border-color: var(--primary);
}
.feld textarea { min-height: 84px; resize: vertical; }
.feld .hinweis { font-size: 12.5px; color: var(--on-surface-variant); margin-top: 4px; }
.feld-reihe { display: flex; gap: 10px; }
.feld-reihe .feld { flex: 1; }

/* ---------- Login ---------- */
body.login-modus { background: var(--login-bg); }
.login {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 28px 24px;
  max-width: 420px; margin: 0 auto;
}
.login img.logo { width: 170px; height: auto; margin-bottom: 6px; }
.login h1 { color: #fff; font-size: 26px; margin-bottom: 2px; }
.login .unterzeile { color: #B9BDC3; font-size: 14px; text-align: center; margin-bottom: 26px; }
.login form { width: 100%; }
.login .feld label { color: #B9BDC3; }
.login .feld input {
  background: #3A3E44; border-color: #4A4F56; color: #fff;
}
.login .feld input:focus { border-color: #fff; }
.login .btn { background: #fff; color: var(--login-bg); margin-top: 4px; }
.login .textbtn { color: #C9E5D4; width: 100%; }
.login .fusszeile { color: #8E939A; font-size: 13px; margin-top: 30px; text-align: center; }
.login .fusszeile b { color: #C6CBD1; }
.login .fehler {
  background: rgba(179, 38, 30, .18); color: #F5B7B1;
  border-radius: 10px; padding: 10px 13px; font-size: 14px; margin-bottom: 12px; width: 100%;
}

/* ---------- Demo-Banner ---------- */
#banner .demo {
  background: var(--tertiary-container); color: var(--on-tertiary-container);
  font-size: 14px; font-weight: 600; text-align: center;
  padding: 9px 14px; padding-top: calc(9px + env(safe-area-inset-top)); cursor: pointer;
}
#banner .demo + * { margin-top: 0; }
#banner .offline {
  background: var(--secondary-container); color: var(--secondary);
  font-size: 13.5px; font-weight: 600; text-align: center; padding: 7px 14px;
}

/* ---------- Bottom-Navigation ---------- */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  background: var(--surface); border-top: 1px solid var(--outline-variant);
  display: flex; justify-content: space-around;
  padding: 6px 0 calc(8px + env(safe-area-inset-bottom));
}
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11.5px; font-weight: 600; color: var(--on-surface-variant);
  padding: 4px 0; border-radius: 12px; max-width: 120px;
}
#bottomnav a img, #bottomnav a svg { width: 26px; height: 26px; object-fit: contain; }
#bottomnav a img { filter: grayscale(1) opacity(.55); }
#bottomnav a.aktiv { color: var(--primary); }
#bottomnav a.aktiv img { filter: none; }

/* ---------- Overlay / Sheets / Dialoge ---------- */
#overlay { position: fixed; inset: 0; z-index: 20; display: none; }
#overlay.offen { display: block; }
#overlay .schleier { position: absolute; inset: 0; background: rgba(20, 26, 23, .45); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; max-height: 85vh; overflow-y: auto;
  animation: hoch .2s ease-out;
}
@keyframes hoch { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet .griff { width: 38px; height: 4px; border-radius: 2px; background: var(--outline-variant); margin: 4px auto 14px; }
.sheet h2 { font-size: 18px; margin-bottom: 12px; }
.dialog {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--surface); border-radius: 18px; padding: 20px;
  width: min(92vw, 400px); max-height: 86vh; overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.dialog h2 { font-size: 18px; margin-bottom: 10px; }
.dialog p { color: var(--on-surface-variant); font-size: 14.5px; margin-bottom: 8px; }

/* Herden-Wechsler */
.herdwahl .zeile img.avatar { background: var(--primary-container); padding: 8px; object-fit: contain; border-radius: 14px; }

/* ---------- Tier-Detail ---------- */
.hero { display: flex; flex-direction: column; align-items: center; padding: 18px 16px 14px; }
.hero .avatar {
  width: 112px; height: 112px; border-radius: 50%; object-fit: cover;
  background: var(--primary-container); cursor: pointer;
}
.hero .avatar.icon { object-fit: contain; padding: 18px; }
.hero h2 { font-size: 22px; margin-top: 10px; }
.hero .badges { display: flex; gap: 8px; margin-top: 8px; }
.inforeihe { display: flex; padding: 8px 2px; border-bottom: 1px solid var(--outline-variant); font-size: 14.5px; }
.inforeihe:last-child { border-bottom: none; }
.inforeihe .l { color: var(--on-surface-variant); width: 128px; flex: none; }
.inforeihe .w { flex: 1; font-weight: 500; word-break: break-word; }
.inforeihe .w a { font-weight: 600; }

/* Foto-Galerie */
.galerie { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.galerie .foto {
  aspect-ratio: 1; border-radius: 10px; object-fit: cover; width: 100%;
  background: var(--surface-variant); cursor: pointer;
}
.galerie .neu {
  aspect-ratio: 1; border-radius: 10px; border: 2px dashed var(--outline-variant);
  background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--on-surface-variant); font-size: 12px; gap: 4px;
}
.galerie .neu img { width: 30px; height: 30px; opacity: .6; }

/* Vollbild-Foto */
.fotoview { position: absolute; inset: 0; background: rgba(0,0,0,.92); display: flex; flex-direction: column; }
.fotoview img { flex: 1; object-fit: contain; min-height: 0; }
.fotoview .leiste { display: flex; gap: 10px; padding: 14px calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-bottom)); }
.fotoview .btn { background: rgba(255,255,255,.14); color: #fff; }

/* ---------- Finanzen ---------- */
.saldi { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.saldi .card { margin: 0; padding: 12px; text-align: center; }
.saldi .betrag { font-size: 17px; font-weight: 800; }
.saldi .plus { color: var(--primary); }
.saldi .minus { color: var(--error); }
.saldi .label { font-size: 12px; color: var(--on-surface-variant); }

/* ---------- Mehr-Menü ---------- */
.navzeile { display: flex; align-items: center; gap: 14px; padding: 12px 4px; cursor: pointer; border-bottom: 1px solid var(--outline-variant); }
.navzeile:last-child { border-bottom: none; }
.navzeile:active { background: var(--surface-variant); }
.navzeile .ikon {
  width: 42px; height: 42px; border-radius: 11px; background: var(--primary-container);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.navzeile .ikon img { width: 28px; height: 28px; object-fit: contain; }
.navzeile .t { flex: 1; min-width: 0; }
.navzeile .t .titel { font-weight: 600; }
.navzeile .t .unter { font-size: 13px; color: var(--on-surface-variant); }
.navzeile .zaehler {
  background: var(--error); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
}

/* Support-Chat */
.chat { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 90px; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 16px; font-size: 14.5px; position: relative; }
.bubble.ich { align-self: flex-end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 4px; }
.bubble.admin { align-self: flex-start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.bubble .zeit { display: block; font-size: 10.5px; opacity: .65; margin-top: 3px; text-align: right; }
.chateingabe {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  background: var(--surface); border-top: 1px solid var(--outline-variant);
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
}
.chateingabe .innen { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; }
.chateingabe input { flex: 1; border: 1.5px solid var(--outline-variant); border-radius: 22px; padding: 10px 16px; }
.chateingabe button {
  width: 46px; height: 46px; border-radius: 14px; border: none; flex: none;
  background: var(--primary); color: var(--on-primary); font-size: 19px;
}

/* ---------- Leerzustände ---------- */
.leer-state { text-align: center; padding: 38px 20px; color: var(--on-surface-variant); }
.leer-state img { width: 90px; height: 90px; object-fit: contain; margin-bottom: 10px; opacity: .9; }
.leer-state.glyph img { opacity: .35; }
.leer-state p { font-size: 14.5px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 30;
  background: #2A302C; color: #fff; font-size: 14px; font-weight: 500;
  padding: 11px 18px; border-radius: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 88vw; text-align: center;
}
#toast.zeigen { opacity: 1; }

/* ---------- Ahnentafel-Overlay ---------- */
.ahnenview { position: absolute; inset: 0; background: #DED9CE; display: flex; flex-direction: column; }
.ahnenview iframe { flex: 1; border: none; width: 100%; background: #DED9CE; }
.ahnenview .leiste {
  display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--outline-variant);
}

.zentriert { text-align: center; }
.abstand { height: 16px; }
.klein-grau { font-size: 13px; color: var(--on-surface-variant); }

/* ---------- Einstellungen: Design / Icon-Stil / Tierarten ---------- */
.designzeile {
  display: flex; align-items: center; gap: 12px; padding: 10px 2px;
  cursor: pointer; border-bottom: 1px solid var(--outline-variant);
}
.designzeile:last-of-type { border-bottom: none; }
.designzeile .dname { flex: 1; font-weight: 600; }
.farbkreis {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 3px solid var(--outline-variant); display: inline-block;
}
.farbkreis.waehlbar { cursor: pointer; border-color: transparent; padding: 0; }
.farbkreis.waehlbar.gewaehlt { border-color: var(--text); }
.tablett { display: flex; flex-wrap: wrap; gap: 8px; }
.tablett .farbkreis { box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }

.stilwahl { display: flex; gap: 10px; }
.stilkarte {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border-radius: var(--radius); cursor: pointer;
  border: 2px solid var(--outline-variant); background: var(--surface);
  font-size: 13.5px; font-weight: 600; color: var(--text);
}
.stilkarte img { width: 52px; height: 52px; object-fit: contain; }
.stilkarte.gewaehlt { border-color: var(--primary); background: var(--primary-container); color: var(--on-primary-container); }

.schalterzeile { display: flex; align-items: center; gap: 12px; padding: 8px 2px; }
.schalterzeile img { width: 34px; height: 34px; object-fit: contain; }
.schalterzeile .sname { flex: 1; font-weight: 600; }
.schalter {
  width: 50px; height: 30px; border-radius: 15px; border: none; flex: none;
  background: var(--surface-variant); position: relative; cursor: pointer; transition: background .15s;
}
.schalter span {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .15s;
}
.schalter.an { background: var(--primary); }
.schalter.an span { left: 23px; }
.schalter:disabled { opacity: .5; cursor: default; }

.checkzeile { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 14.5px; font-weight: 600; }
.checkzeile input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--primary); flex: none; }

/* Hilfe-Bot */
.bubble.bot { padding-left: 44px; position: relative; }
.bubble .botavatar { position: absolute; left: 10px; top: 10px; width: 26px; height: 26px; object-fit: contain; }
#botChat .chips { margin: 4px 0 0; }

/* ---------- Mehrfachauswahl ---------- */
.zeile.gewaehlt { background: var(--primary-container); border-radius: 10px; }
.wahlkreis {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 2px solid var(--outline); display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 800; color: var(--on-primary);
}
.wahlkreis.an { background: var(--primary); border-color: var(--primary); }
.aktionsleiste {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 8;
  background: var(--surface); border-top: 1px solid var(--outline-variant);
  box-shadow: 0 -2px 10px rgba(0,0,0,.08);
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; max-width: 640px; margin: 0 auto;
}
.aktionsleiste .anzahl { flex: 1; font-size: 13.5px; font-weight: 700; color: var(--on-surface-variant); }
