:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --surface-2: #f5f8f7;
  --ink: #13211f;
  --ink-2: #51625f;
  --ink-3: #8a9896;
  --line: #dde5e3;
  --accent: #0e4f4a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe8;
  --danger: #b3402e;
  --k-besatz: #2e7d4f;
  --k-entnahme: #1f5fa8;
  --k-verlust: #b3402e;
  --k-umsetzung: #94620f;
  --k-inventur: #5b6670;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 30, 28, .06), 0 2px 10px rgba(10, 30, 28, .04);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1312;
    --surface: #13201f;
    --surface-2: #192a28;
    --ink: #e5eeec;
    --ink-2: #a3b4b1;
    --ink-3: #6d807d;
    --line: #233533;
    --accent: #5fbfb1;
    --accent-ink: #062320;
    --accent-soft: #173936;
    --danger: #ef7d6a;
    --k-besatz: #6fcf94;
    --k-entnahme: #79a9ec;
    --k-verlust: #ef7d6a;
    --k-umsetzung: #e3b25b;
    --k-inventur: #a5b0b8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(var(--safe-top) + 6px) 8px 8px;
  background: var(--accent); color: var(--accent-ink);
}
@media (prefers-color-scheme: dark) { .topbar { background: #0f1e1d; color: var(--ink); border-bottom: 1px solid var(--line); } }
.topbar h1 { grid-column: 2; margin: 0; font-size: 17px; font-weight: 650; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: inherit; padding: 6px; display: grid; place-items: center; }
.topbar-right { grid-column: 3; display: flex; justify-content: flex-end; }
.topbar-right button { background: none; border: 0; color: inherit; padding: 6px; font-weight: 600; }

main { padding: 14px 16px calc(96px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }

/* ---- Tabbar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 0 calc(var(--safe-bottom) + 4px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink-3); font-size: 11px; font-weight: 550; padding: 4px 0; }
.tabbar svg { width: 26px; height: 26px; }
.tabbar a.active { color: var(--accent); }

/* ---- Bausteine ---- */
.section-title { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.section-title a, .section-title button { text-transform: none; letter-spacing: 0; font-size: 15px; font-weight: 500; background: none; border: 0; color: var(--accent); padding: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; min-height: 52px; width: 100%; background: none; border: 0; text-align: left; color: inherit; }
button.row:active, a.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 13.5px; color: var(--ink-2); margin-top: 1px; }
.row .r { text-align: right; flex-shrink: 0; }
.row .r .big { font-weight: 650; }
.row .chev { color: var(--ink-3); flex-shrink: 0; }
.muted { color: var(--ink-2); }
.empty { padding: 26px 18px; text-align: center; color: var(--ink-2); }
.empty b { color: var(--ink); display: block; margin-bottom: 4px; }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.stat .l { font-size: 13px; color: var(--ink-2); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip { font-size: 12.5px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--ink); white-space: nowrap; }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* Aktionsleiste im Teich */
.actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 2px 8px; border: 0; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
  font-size: 11.5px; font-weight: 600; color: var(--ink);
}
.action i { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-style: normal; font-size: 18px; font-weight: 700; line-height: 1; }
.action:active { transform: scale(.97); }

.species-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px 4px; }
.species-head b { font-size: 17px; }
.species-head span { font-size: 13.5px; color: var(--ink-2); }
.cls-row .t { font-weight: 500; }

/* Buchungs-Badges */
.kind { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; color: #fff; font-weight: 700; font-size: 16px; }
.kind-besatz { background: var(--k-besatz); }
.kind-entnahme { background: var(--k-entnahme); }
.kind-verlust { background: var(--k-verlust); }
.kind-umsetzung { background: var(--k-umsetzung); }
.kind-inventur { background: var(--k-inventur); }
@media (prefers-color-scheme: dark) { .kind, .action i { color: #0a1312; } }
.plus { color: var(--k-besatz); }
.minus { color: var(--k-verlust); }
.day { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 18px 4px 6px; }
.note { font-size: 13.5px; color: var(--ink-2); font-style: italic; margin-top: 2px; white-space: pre-wrap; }

/* ---- Formulare ---- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12.5px; }
input[type=text], input[type=password], input[type=date], input[type=number], input:not([type]), select, textarea {
  width: 100%; padding: 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); font-size: 17px; /* >=16px verhindert Zoom auf iOS */
  -webkit-appearance: none; appearance: none; min-height: 48px;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238a9896' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
input[type=date] { display: block; }
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.weight-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.weight-row select { width: auto; min-width: 128px; font-size: 15px; }
.hint { font-size: 13.5px; background: var(--accent-soft); padding: 9px 12px; border-radius: 10px; }
.hint.warn { background: color-mix(in srgb, var(--danger) 15%, transparent); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 14px; border-radius: 12px; border: 0; font-weight: 650; font-size: 17px;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.btn.danger { background: none; color: var(--danger); box-shadow: none; border: 1px solid var(--line); }
.btn:active { opacity: .85; }
.link { background: none; border: 0; color: var(--accent); font-weight: 500; padding: 6px 2px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; border-radius: 8px; padding: 7px 4px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---- Bottom-Sheet ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(4, 16, 15, .42); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: calc(100% - var(--safe-top) - 24px); display: flex; flex-direction: column;
  background: var(--bg); border-radius: 18px 18px 0 0; max-width: 640px; margin: 0 auto;
  animation: up .24s cubic-bezier(.2, .8, .2, 1);
}
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 7px auto 0; }
.sheet-head { display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; padding: 4px 10px 8px; }
.sheet-head h2 { margin: 0; text-align: center; font-size: 17px; }
.sheet-head .link { justify-self: start; }
.sheet-body { overflow-y: auto; padding: 6px 16px calc(var(--safe-bottom) + 20px); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 84px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 500;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); animation: fade .2s;
}
.toast.error { background: var(--danger); color: #fff; }

/* ---- Login ---- */
.login { max-width: 380px; margin: 9vh auto 0; }
.login .logo { width: 76px; height: 76px; border-radius: 18px; display: block; margin: 0 auto 14px; box-shadow: var(--shadow); }
.login h2 { text-align: center; margin: 0 0 4px; font-size: 26px; }
.login p { text-align: center; margin: 0 0 24px; color: var(--ink-2); }

.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { font-size: 11.5px; font-weight: 650; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); margin-left: 6px; vertical-align: 1px; }
.inactive .t { color: var(--ink-3); }
.filter { margin-bottom: 4px; }
