:root {
  --teal: #0f766e; --teal-d: #0b5b54; --teal-l: #ccfbf1;
  --bg: #f5f7f8; --card: #ffffff; --line: #e2e8f0;
  --text: #1f2937; --muted: #64748b;
  --warn: #b45309; --warn-bg: #fef3c7; --danger: #dc2626; --ok: #15803d;
  --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
}
.center-screen { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--teal-l); border-top-color: var(--teal); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* Sticky Header: oben Logo + Login, darunter die Navigation (umbrechend, kein Scrollen) */
header.topbar {
  background: var(--teal); color: #fff; position: sticky; top: 0; z-index: 1000;
  padding-top: env(safe-area-inset-top); box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.topbar-top {
  max-width: 1120px; margin: 0 auto; width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px;
}
.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-btn { background: rgba(255,255,255,.16); color: #fff; border: 0; padding: 7px 12px; font-size: .85rem; border-radius: 8px; max-width: 48vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn:hover { background: rgba(255,255,255,.26); }
.logout-btn { background: rgba(255,255,255,.16); color: #fff; border: 0; padding: 7px 12px; font-size: .85rem; }
.logout-btn:hover { background: rgba(255,255,255,.26); }
.hamburger { display: none; background: rgba(255,255,255,.16); color: #fff; border: 0; font-size: 1.15rem; padding: 6px 12px; border-radius: 8px; }
.hamburger:hover { background: rgba(255,255,255,.26); }

.mainnav {
  max-width: 1120px; margin: 0 auto; width: 100%;
  display: flex; flex-wrap: wrap; gap: 4px; padding: 0 14px 10px;
}
.mainnav a {
  color: rgba(255,255,255,.92); text-decoration: none; padding: 8px 12px; border-radius: 8px;
  font-size: .9rem; white-space: nowrap; font-weight: 500;
}
.mainnav a:hover { background: rgba(255,255,255,.14); }
.mainnav a.active { background: #fff; color: var(--teal); font-weight: 700; }

main.content { flex: 1; padding: 16px; max-width: 900px; margin: 0 auto; width: 100%; padding-bottom: 40px; }

/* Schmale Darstellung: Navigation ins Hamburger-Menü einklappen */
@media (max-width: 720px) {
  .hamburger { display: inline-flex; align-items: center; }
  .user-btn span { max-width: 24vw; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }
  .mainnav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; flex-wrap: nowrap; background: var(--teal-d);
    padding: 8px; gap: 2px; box-shadow: 0 10px 20px rgba(0,0,0,.25);
    border-radius: 0 0 12px 12px; z-index: 1001;
  }
  .mainnav.open { display: flex; }
  .mainnav a { padding: 12px 14px; font-size: 1rem; }
}

/* Cards / lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 4px; font-size: 1.1rem; }
.card h3 { margin: 0 0 8px; font-size: 1rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.muted { color: var(--muted); font-size: .88rem; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.pill.offen { background: #dbeafe; color: #1d4ed8; }
.pill.abgeschlossen { background: #dcfce7; color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.needs-fill { background: var(--warn-bg); border-left: 4px solid var(--warn); }

/* Forms */
label { display: block; font-size: .82rem; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 1rem; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-l); border-color: var(--teal); }
textarea { min-height: 70px; resize: vertical; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--teal); color: #fff; border: 0; padding: 12px 16px; border-radius: 10px;
  font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { background: var(--teal-d); }
button.secondary, .btn.secondary { background: #fff; color: var(--teal); border: 1px solid var(--teal); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo .badge { width: 56px; height: 56px; border-radius: 14px; background: var(--teal); color: #fff;
  display: grid; place-items: center; font-size: 1.6rem; margin: 0 auto 8px; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .3px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Camera / foto */
.foto-box { border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; }
.foto-box.dragover { border-color: var(--teal); background: var(--teal-l); }
.foto-preview { display: block; max-width: 100%; max-height: 240px; width: auto; height: auto; object-fit: contain; border-radius: 10px; margin-top: 10px; }

/* Großes Zählerstand-Eingabefeld (Vorkomma schwarz / Nachkomma rot getrennt) */
.stand-input { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.stand-input input { font-size: 1.7rem; font-weight: 700; letter-spacing: 2px; text-align: center; padding: 12px 10px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.stand-input .stand-whole { flex: 1 1 auto; min-width: 0; }
.stand-input .stand-dec { flex: 0 0 88px; width: 88px; color: #dc2626; border-color: #fca5a5; background: #fef2f2; }
.stand-input .stand-comma { font-size: 1.7rem; font-weight: 700; color: #dc2626; }

/* Alerts */
.alert { padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-size: .9rem; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.err { background: #fee2e2; color: var(--danger); }
.alert.ok { background: #dcfce7; color: var(--ok); }

.section-title { display: flex; justify-content: space-between; align-items: center; margin: 4px 2px 12px; }
.section-title h1 { font-size: 1.3rem; margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat .n { font-size: 1.5rem; font-weight: 700; color: var(--teal); }
.stat .l { font-size: .8rem; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #111827;
  color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 4000; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }

h4 { font-size: .95rem; }

/* Segmented control */
.seg { display: flex; gap: 4px; background: #eef2f2; border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; background: transparent; color: var(--muted); border: 0; padding: 9px 8px; border-radius: 8px; font-size: .9rem; font-weight: 600; }
.seg button.active { background: #fff; color: var(--teal); box-shadow: var(--shadow); }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 3000; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal { background: var(--card); width: 100%; max-width: 640px; border-radius: 16px 16px 0 0; max-height: 92vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
@media (min-width: 780px) {
  .modal-wrap { align-items: center; }
  .modal { border-radius: 16px; }
}

/* Aufklappbares Modul */
details.collapsible { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; }
details.collapsible > summary { cursor: pointer; font-weight: 600; color: var(--teal); list-style: none; display: flex; align-items: center; gap: 6px; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after { content: '▸'; margin-left: auto; transition: transform .2s; color: var(--muted); }
details.collapsible[open] > summary::after { transform: rotate(90deg); }

/* Karte */
.map { height: 60vh; min-height: 320px; border-radius: 12px; border: 1px solid var(--line); overflow: hidden; }
#dash-map { height: 46vh; min-height: 280px; }
.leaflet-container { font: inherit; }

/* OCR-Auswahl (verschiebbar/größenveränderbar, touch-tauglich) */
.ocr-sel { position: absolute; box-sizing: border-box; border: 2px solid #14b8a6;
  background: rgba(20,184,166,.18); box-shadow: 0 0 0 9999px rgba(15,23,42,.55); cursor: move; touch-action: none; }
.ocr-h { position: absolute; width: 26px; height: 26px; background: #14b8a6; border: 2px solid #fff;
  border-radius: 50%; touch-action: none; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.ocr-h[data-h="nw"] { left: -13px; top: -13px; cursor: nwse-resize; }
.ocr-h[data-h="ne"] { right: -13px; top: -13px; cursor: nesw-resize; }
.ocr-h[data-h="sw"] { left: -13px; bottom: -13px; cursor: nesw-resize; }
.ocr-h[data-h="se"] { right: -13px; bottom: -13px; cursor: nwse-resize; }

/* Einführungs-Tour */
.tour-catch { position: fixed; inset: 0; z-index: 4998; }
.tour-ring { position: fixed; border: 2px solid #fff; border-radius: 8px; box-shadow: 0 0 0 9999px rgba(15,23,42,.6); z-index: 4999; pointer-events: none; transition: top .2s, left .2s, width .2s, height .2s; }
.tour-box { position: fixed; z-index: 5000; background: var(--card); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.35); padding: 14px; }
.tour-h { font-weight: 700; color: var(--teal); margin-bottom: 4px; }
.tour-d { font-size: .9rem; margin-bottom: 12px; line-height: 1.45; }
.tour-f { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tour-box button { padding: 8px 12px; font-size: .88rem; }

/* Anleitung */
.help p { margin: 6px 0; }
.help ul, .help ol { margin: 6px 0 8px 20px; }
.help li { margin: 4px 0; }

/* Fotogalerie */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gal-item { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; box-shadow: var(--shadow); }
.gal-item img { width: 100%; height: 150px; object-fit: contain; display: block; background: #eef2f2; }
.gal-item figcaption { padding: 8px 10px; font-size: .82rem; }

/* Diagramme */
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Große, gut tippbare Primär-Buttons */
button.big, .btn.big { padding: 15px 18px; font-size: 1.05rem; border-radius: 12px; }

/* Anklickbare Kennzahlen-Karten */
.stat-grid.two { grid-template-columns: 1fr 1fr; }
button.stat.tappable { text-align: left; cursor: pointer; border: 1px solid var(--line); background: var(--card); }
button.stat.tappable:hover { background: #f0fdfa; }
.stat .l { margin-top: 2px; }
.alert.warn[onclick] { cursor: pointer; }

/* Sticky Speichern-Leiste (mobil) */
.save-bar { position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); margin-top: 14px; z-index: 15; }
.save-bar button { box-shadow: 0 4px 14px rgba(15,118,110,.35); }

/* Größere Touch-Ziele für Formulareingaben auf dem Smartphone */
@media (max-width: 780px) {
  input, select, textarea { padding: 13px 12px; font-size: 16px; } /* 16px verhindert iOS-Zoom */
  .seg button { padding: 11px 8px; }
  .card { padding: 14px; }
  table th, table td { padding: 10px 6px; }
}

