:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a1d24;
  --muted: #6b7280;
  --border: #e3e5e9;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --blue-bg: #dbeafe;
  --grau-bg: #e5e7eb;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --radius: 10px;
  --radius-btn: 8px;
  --touch: 46px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Sidebar-Navigation (links, wie eine "richtige" App) ===== */

.sidebar-brand {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 18px 18px 14px;
}

.sidebar-suche { padding: 0 14px 14px; }
.sidebar-suche input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  min-height: 38px;
}
.sidebar-suche input::placeholder { color: #9ca3af; }

.sidebar-links {
  display: flex;
  flex-direction: column;
  padding: 0 10px;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
}

.sidebar-links a {
  color: #d1d5db;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
}
.sidebar-links a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.sidebar-links a.aktiv { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-links a.nav-hervorgehoben {
  background: var(--green);
  color: #fff;
  font-weight: 600;
  margin: 4px 0;
}
.sidebar-links a.nav-hervorgehoben.aktiv { background: #128038; }
.sidebar-links a.nav-hervorgehoben:hover { background: #128038; color: #fff; }

.sidebar-trenner {
  color: #6b7280;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 14px 12px 4px;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-footer a { color: #9ca3af; font-size: 0.85rem; }
.sidebar-footer a:hover { color: #fff; }

.sidebar {
  background: #111827;
  width: 230px;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 50;
  transform: translateX(0);
  transition: transform 0.2s ease;
}

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.mobile-topbar .brand { font-weight: 700; }
#btn-menu-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  min-height: var(--touch);
  min-width: var(--touch);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 45;
}
.sidebar-overlay.sichtbar { display: block; }

body.mit-sidebar .wrap { margin-left: 230px; }

@media (max-width: 900px) {
  .mobile-topbar { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.offen { transform: translateX(0); }
  body.mit-sidebar .wrap { margin-left: 0; }
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 14px 90px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

h1 { font-size: 1.4rem; margin: 0 0 14px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat .val { font-size: 1.5rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
tr:hover td { background: #fafbfc; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-grau { background: var(--grau-bg); color: #374151; }
.badge-gruen { background: var(--green-bg); color: #15803d; }
.badge-blau { background: var(--blue-bg); color: #1d4ed8; }
.badge-rot { background: var(--red-bg); color: #991b1b; }
.badge-amber { background: var(--amber-bg); color: #92400e; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  padding: 10px 18px;
  border-radius: var(--radius-btn);
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-gross { padding: 14px 20px; font-size: 1.1rem; width: 100%; }
.btn-gruen { background: var(--green); }
.btn-gruen:hover { background: #128038; }
.btn-rot { background: var(--red); }
.btn-rot:hover { background: #b91c1c; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: #eef2ff; }
.btn-sekundaer { background: #6b7280; }
.btn-sekundaer:hover { background: #4b5563; }
.btn-klein { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=tel], select, textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 12px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
textarea { min-height: 90px; }

label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
.feld { margin-bottom: 14px; }

.msg { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.95rem; }
.msg-fehler { background: var(--red-bg); color: #991b1b; }
.msg-erfolg { background: var(--green-bg); color: #15803d; }
.msg-hinweis { background: var(--amber-bg); color: #92400e; }

.login-box { max-width: 380px; margin: 8vh auto; }

.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar a {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.88rem;
}
.filter-bar a.aktiv { background: var(--primary); color: #fff; border-color: var(--primary); }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 14px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }

/* Sticky Aktionsleiste unten fuer mobile Formulare (v.a. Vor-Ort-Erfassung) */
.aktionsleiste-unten {
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  margin: 0 -14px;
}
.aktionsleiste-unten .btn { flex: 1; }

.positionszeile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.positionszeile .zeile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 640px) {
  .positionszeile .zeile-grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
}

.kunde-suche-wrap { position: relative; }
#kunde-ergebnisse {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-btn) var(--radius-btn);
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 16px rgba(0,0,0,0.08);
}
.kunde-treffer { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.kunde-treffer:hover { background: var(--bg); }
.kunde-treffer:last-child { border-bottom: none; }

.vor-ort-wrap { max-width: 480px; margin: 0 auto; }

#unterschrift-canvas {
  width: 100%;
  height: 220px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  touch-action: none;
  background: #fff;
  display: block;
}

@media print {
  .no-print, .aktionsleiste-unten { display: none !important; }
  body { background: #fff; padding-bottom: 0; }
  .wrap { max-width: none; padding: 0; }
}
