/* ── Grundlagen ─────────────────────────────────────────────── */
:root {
  --bg:          #f2f2f7;
  --surface:     #ffffff;
  --surface-2:   #f7f7fa;
  --border:      #e3e3ea;
  --text:        #14141a;
  --text-dim:    #6c6c78;
  --accent:      #2f6df6;
  --accent-soft: #e8f0ff;
  --ok:          #1a8f52;
  --ok-soft:     #e3f5eb;
  --warn:        #b26a00;
  --warn-soft:   #fdf0dc;
  --danger:      #d0342c;
  --danger-soft: #fdeae9;
  --radius:      14px;
  --shadow:      0 1px 2px rgba(20, 20, 30, .06), 0 8px 24px rgba(20, 20, 30, .06);
  --tap:         44px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #000000;
    --surface:     #1c1c1e;
    --surface-2:   #2c2c2e;
    --border:      #38383c;
    --text:        #f5f5f7;
    --text-dim:    #98989f;
    --accent:      #5c9bff;
    --accent-soft: #1b2c4d;
    --ok:          #48d38a;
    --ok-soft:     #14331f;
    --warn:        #f0b357;
    --warn-soft:   #3a2c11;
    --danger:      #ff6961;
    --danger-soft: #3d1a19;
    --shadow:      0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── Kopfzeile ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(env(safe-area-inset-top), 8px) 16px 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.02em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}
.topbar .icon-btn:active { background: var(--surface-2); }

/* ── Seitenaufbau ───────────────────────────────────────────── */
main {
  padding: 14px 16px calc(78px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.section-title {
  margin: 22px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
}
.section-title:first-child { margin-top: 4px; }

/* ── Karten & Listen ────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 11px 16px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row.static { cursor: default; }
.row.static:active { background: none; }

.row-main { flex: 1; min-width: 0; }
.row-title {
  font-weight: 550;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub.wrap { white-space: normal; }

.chevron { color: var(--text-dim); flex-shrink: 0; opacity: .6; }

/* ── Kennzahlen ─────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 520px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  border: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.stat:active { background: var(--surface-2); }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.stat-label { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.stat.alert .stat-value { color: var(--danger); }

/* ── Statusanzeigen ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge.ok     { background: var(--ok-soft);     color: var(--ok); }
.badge.warn   { background: var(--warn-soft);   color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info   { background: var(--accent-soft); color: var(--accent); }
.badge.muted  { background: var(--surface-2);   color: var(--text-dim); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

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

/* ── Schaltflächen ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
}
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.wide { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: none; color: var(--accent); }
.btn.small { min-height: 34px; padding: 0 13px; font-size: 14px; border-radius: 9px; }

.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

/* ── Formulare ──────────────────────────────────────────────── */
.field { padding: 10px 16px; border-top: 1px solid var(--border); }
.field:first-child { border-top: 0; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 3px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 0;
  background: none;
  padding: 4px 0;
  font-size: 16px; /* verhindert Auto-Zoom auf iOS */
  outline: none;
}
.field textarea { resize: vertical; min-height: 60px; }
.field .hint { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.field.inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.field.inline label { margin: 0; font-size: 16px; font-weight: 450; color: var(--text); }

.split { display: flex; gap: 0; }
.split .field { flex: 1; }
.split .field + .field { border-left: 1px solid var(--border); }

/* Umschalter im iOS-Stil */
.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border-radius: 999px;
  transition: background .18s;
  pointer-events: none;
}
.switch span::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .18s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ── Modale Blätter ─────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .2s ease;
}
@media (min-width: 640px) { .sheet-backdrop { align-items: center; } }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: rise .26s cubic-bezier(.32, .72, 0, 1);
}
@media (min-width: 640px) { .sheet { border-radius: 18px; max-height: 86vh; } }

.sheet-grip {
  width: 38px; height: 5px;
  border-radius: 3px;
  background: var(--border);
  margin: 6px auto 12px;
}
.sheet h2 { margin: 0 4px 14px; font-size: 20px; letter-spacing: -.02em; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }

/* ── Fußnavigation ──────────────────────────────────────────── */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 0 6px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  position: relative;
}
.tabbar a.active { color: var(--accent); }
.tabbar a svg { width: 25px; height: 25px; }
.tabbar .pip {
  position: absolute;
  top: 5px;
  margin-left: 17px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* ── Hinweise & Zustände ────────────────────────────────────── */
.notice {
  padding: 11px 14px;
  border-radius: 11px;
  font-size: 14px;
  margin-bottom: 12px;
}
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok    { background: var(--ok-soft);     color: var(--ok); }
.notice.warn  { background: var(--warn-soft);   color: var(--warn); }
.notice.info  { background: var(--accent-soft); color: var(--accent); }

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-dim);
  font-size: 14.5px;
}

.skeleton {
  height: 56px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.3s infinite;
  margin-bottom: 8px;
}
@keyframes shimmer { to { background-position: -300% 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 460px);
  padding: 11px 18px;
  border-radius: 12px;
  background: #24242a;
  color: #fff;
  font-size: 14.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  animation: rise .2s ease;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-all;
}

.copy-box {
  background: var(--surface-2);
  border-radius: 9px;
  padding: 9px 11px;
  margin-top: 5px;
  cursor: pointer;
}
.copy-box:active { opacity: .7; }

/* ── Anmeldeseiten ──────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  max-width: 420px;
  margin: 0 auto;
}
.auth-logo {
  width: 68px; height: 68px;
  margin: 0 auto 16px;
  border-radius: 17px;
  background: var(--accent);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(47, 109, 246, .3);
}
.auth-wrap h1 { text-align: center; font-size: 25px; margin: 0 0 4px; letter-spacing: -.02em; }
.auth-wrap .lead { text-align: center; color: var(--text-dim); font-size: 14.5px; margin: 0 0 22px; }
.auth-wrap .card { margin-bottom: 14px; }

/* ── Verlaufskurven ─────────────────────────────────────────── */
.chart {
  width: 100%;
  height: 56px;
  display: block;
  margin-top: 8px;
  color: var(--accent);
  overflow: visible;
}
.chart-line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-area { fill: currentColor; opacity: .12; stroke: none; }
.chart.warn   { color: var(--warn); }
.chart.danger { color: var(--danger); }

.chart-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}
.chart-empty {
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 14px 0 6px;
}

/* ── Kennzahl mit Verlauf ───────────────────────────────────── */
.gauge { padding: 13px 16px; border-top: 1px solid var(--border); }
.gauge:first-child { border-top: 0; }
.gauge-head { display: flex; align-items: baseline; gap: 8px; }
.gauge-title { font-weight: 550; flex: 1; }
.gauge-value { font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.gauge-note { font-size: 12.5px; color: var(--text-dim); }

/* ── Protokollausgabe ───────────────────────────────────────── */
.logbox {
  background: #101014;
  color: #d8d8e0;
  border-radius: 11px;
  padding: 11px 13px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  max-height: 46vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 8px;
}

/* ── Segmentierte Umschalter ────────────────────────────────── */
.segments {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  margin: 10px 0 4px;
}
.segments button {
  flex: 1;
  border: 0;
  background: none;
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-dim);
  cursor: pointer;
}
.segments button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ── Filterleiste ───────────────────────────────────────────── */
.filter-input {
  width: 100%;
  border: 0;
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 11px 14px;
  font-size: 16px;
  margin-bottom: 10px;
  outline: none;
}
