:root {
  --color-brand: #003f65;
  --color-brand-light: #3f7196;
  --color-bg: #f4f6f5;
  --color-surface: #ffffff;
  --color-border: #dbe2df;
  --color-text: #1c2422;
  --color-text-muted: #5c6864;
  --color-danger: #b3312c;
  --color-warning: #a8681a;
  --color-ok: #2f7a4d;
  --radius: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --tab-bar-height: 54px;
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 var(--space-2); }
p { margin: 0 0 var(--space-2); }

.app-header {
  background: var(--color-brand);
  color: #fff;
  padding: env(safe-area-inset-top) var(--space-3) var(--space-2);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-2);
}

.app-title { font-size: 1.15rem; font-weight: 600; display: flex; align-items: center; gap: 10px; margin: 0; }
.app-logo-mark { height: 28px; width: auto; display: block; }

/* Bottom-Tab-Bar (iOS-typisch): fixiert am unteren Bildschirmrand,
   Icon+Label je Ziel, Blur-Hintergrund wie native Tab-Bars. Ersetzt die
   vorherige horizontale Linkleiste oben im Header. */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--color-border);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  font: inherit;
  text-decoration: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px 2px 0;
}
.tab-item svg { width: 24px; height: 24px; }
.tab-item span { font-size: 0.68rem; font-weight: 500; }
.tab-item.active { color: var(--color-brand); }
.tab-item.active span { font-weight: 700; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-offline { background: var(--color-danger); color: #fff; }
.badge-syncing { background: var(--color-warning); color: #fff; }
.badge-ok { background: var(--color-ok); color: #fff; }

.app-view {
  flex: 1;
  padding: var(--space-3);
  padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + var(--space-3));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.field {
  margin-bottom: var(--space-3);
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: var(--space-1);
  font-size: 0.9rem;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: #fff;
  color: var(--color-text);
}
.field .hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: var(--space-1); }

.btn {
  display: inline-block;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-brand);
  color: #fff;
  text-align: center;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--color-brand); border: 1px solid var(--color-brand); }
.btn-danger { background: var(--color-danger); }
.btn-block { display: block; width: 100%; }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* Gruppierte Liste im iOS-Stil: EIN abgerundeter Container mit
   Schatten statt einzeln beabstandeter Karten je Eintrag; die Zeilen
   darin trennt nur eine dezente Linie (siehe .list-item). */
.list {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--color-border);
}
.list-item:last-child { border-bottom: none; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; }
.list-item-sub { font-size: 0.85rem; color: var(--color-text-muted); }

/* Chevron-Markierung nur für Einträge, die reine Navigation sind
   (ein Tap = weiter zur nächsten Ansicht) – Einträge mit eigenen
   Aktions-Buttons (z.B. Ablesen/Verlauf/Wechsel) bekommen keine, damit
   nicht zwei Interaktionsarten in derselben Zeile konkurrieren. */
.list-item-nav { position: relative; padding-right: 34px; }
.list-item-nav::after {
  content: "";
  position: absolute;
  right: var(--space-3);
  top: 50%;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--color-text-muted);
  border-right: 2px solid var(--color-text-muted);
  transform: translateY(-50%) rotate(45deg);
}
.list-item-nav:active { background: rgba(0, 0, 0, 0.04); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.tag-complete { background: #e3f3e8; color: var(--color-ok); }
.tag-missing { background: #fbeceb; color: var(--color-danger); }
.tag-pending { background: #fdf1e0; color: var(--color-warning); }
.tag-photo { background: #e6edf2; color: var(--color-brand); }
.tag-nophoto { background: #f0f0f0; color: var(--color-text-muted); }

/* Team-Liste (Benutzerverwaltung) */
.team-item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.team-item:last-child { border-bottom: none; }
.team-item .team-name { font-weight: 600; }
.team-item .team-status { font-size: 0.75rem; color: var(--color-text-muted); margin-top: 3px; }
.team-item .team-status .tag { font-size: 0.7rem; }
.team-item .team-sub { font-size: 0.8rem; color: var(--color-text-muted); overflow-wrap: anywhere; }
.team-item .btn { padding: 6px 12px; font-size: 0.85rem; flex: 0 0 auto; }
.team-geloescht summary { cursor: pointer; color: var(--color-text-muted); font-size: 0.9rem; margin-top: var(--space-3); }
.befehl-box { background: #fdf1e0; border-radius: var(--radius); padding: var(--space-3); margin-bottom: var(--space-3); font-size: 0.85rem; }
.befehl-box code { display: block; white-space: pre-wrap; word-break: break-all; background: #fff; padding: 8px; border-radius: 6px; margin: 6px 0; font-size: 0.75rem; }

/* Verbrauchsvergleich aktuelles Jahr / Vorjahr in der Zählerübersicht */
.verbrauch-vergleich { display: flex; align-items: center; gap: var(--space-3); padding: 8px 10px; border-radius: var(--radius); background: var(--color-surface); border: 1px solid var(--color-border); font-size: 0.85rem; min-height: 44px; }
.verbrauch-vergleich .vv-spalte { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.verbrauch-vergleich .vv-label { font-size: 0.75rem; color: var(--color-text-muted); white-space: nowrap; }
.verbrauch-vergleich .vv-stand { font-size: 0.7rem; }
.verbrauch-vergleich .vv-wert { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.verbrauch-vergleich .vv-abweichung { flex: 0 0 auto; }
.verbrauch-vergleich .vv-leer { color: var(--color-text-muted); font-size: 0.8rem; }

.stat-row { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.stat-box { flex: 1; min-width: 120px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-3); text-align: center; }
.stat-box .value { font-size: 1.4rem; font-weight: 700; }
.stat-box .label { font-size: 0.8rem; color: var(--color-text-muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--color-border); }
th { color: var(--color-text-muted); font-weight: 600; }

/* Foto-Link steht als eigene, schmale Zeile direkt UNTER dem Ablese-Eintrag
   (statt in einer eigenen Spalte) – so bleibt die Tabelle auf dem Smartphone
   ohne horizontales Scrollen lesbar. Die Datenzeile darüber verliert dafür
   ihren unteren Rahmen, damit Eintrag + Foto-Link optisch zusammengehören. */
tr.has-foto > td { border-bottom: none; }
td.foto-cell { padding-top: 0; font-size: 0.85rem; }

.photo-preview { width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--color-border); margin-bottom: var(--space-2); background: #000; }

.ocr-suggestion {
  background: #e6edf2;
  border: 1px solid var(--color-brand-light);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-size: 0.9rem;
}

.empty-state { text-align: center; color: var(--color-text-muted); padding: var(--space-5) var(--space-3); }

.back-link { display: inline-block; margin-bottom: var(--space-3); color: var(--color-brand); text-decoration: none; font-weight: 600; }

.toast-root {
  position: fixed;
  bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + var(--space-3));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
  width: calc(100% - var(--space-4));
  max-width: 480px;
  align-items: center;
}
.toast {
  background: #1c2422;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.toast-error { background: var(--color-danger); }
.toast-ok { background: var(--color-ok); }

.chart-svg { width: 100%; height: auto; }

@media (max-width: 420px) {
  :root { font-size: 15px; }
}

/* Stammdatenpflege (Bearbeiten/Entfernen, nur Admins) */
.gefahrenzone { margin-top: var(--space-3); border: 1px solid #f0c9c7; }
.gefahrenzone h3 { color: var(--color-danger); margin-top: 0; }
.btn-icon { flex: 0 0 auto; padding: 12px 14px; text-decoration: none; font-size: 1.05rem; line-height: 1; display: inline-flex; align-items: center; }
.field input[type="radio"], .field input[type="checkbox"] { width: auto; flex: 0 0 auto; margin: 0; }
.btn-row[style*="nowrap"] > .btn { padding-left: 10px; padding-right: 10px; min-width: 0; }

/* Rollen auf der Team-Seite */
.team-aktionen { display: flex; flex-direction: column; gap: 6px; align-items: stretch; flex: 0 0 auto; max-width: 46%; }
.team-aktionen .btn { white-space: normal; text-align: center; line-height: 1.2; }
.team-name .tag { font-size: 0.7rem; vertical-align: 2px; margin-left: 4px; }
.tag-rolle-admin { background: #e6edf2; color: var(--color-brand); }
.tag-rolle-super { background: var(--color-brand); color: #fff; }
