/* samoVertrieb – globales Stylesheet */

/* ── iOS PWA / Safe-Area Global ──────────────────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  max-width: 100%;
  overflow-x: hidden;
}

/* Momentum-Scroll für alle scrollbaren Panels */
.scroll-panel {
  -webkit-overflow-scrolling: touch;
}

/* iOS Auto-Zoom verhindern: mind. 16px für alle Eingabefelder */
input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=datetime-local],
input[type=search],
textarea,
select {
  font-size: 16px !important;
}

/* Touch-Targets: mind. 44px Höhe für interaktive Elemente */
.btn,
.topbar-nav a,
.btn-status,
.slot-btn {
  min-height: 44px;
}
.btn-sm {
  min-height: 36px;
}

:root {
  --accent:      #2563eb;
  --accent-dark: #1d4ed8;
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --text:        #1e293b;
  --text-muted:  #64748b;
  --danger:      #dc2626;
  --success:     #16a34a;
  --warning:     #d97706;
  --info:        #0891b2;
  --nav-h:       52px;
  --panel-w:     360px;

  /* Status-Farben */
  --c-offen:    #6b7280;
  --c-positiv:  #16a34a;
  --c-negativ:  #dc2626;
  --c-termin:   #2563eb;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  /* Höhe = var(--nav-h) + safe-area-inset-top (Notch) */
  height: calc(var(--nav-h) + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: nowrap; /* nie umbrechen → Abmelden bleibt in der Leiste, nicht über der Karte */
  align-items: center; /* vertikal zentriert im nav-h-Band (unter der Safe-Area) – Logo nicht mehr zu tief */
  gap: 0;
  /* >1000, damit Leaflet-Controls (+/- Zoom, z-index 1000) NICHT über der Topbar/Tabs liegen */
  z-index: 1100;
  padding-top: env(safe-area-inset-top);
  padding-bottom: 0;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  box-sizing: border-box;
}

.topbar-logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  text-decoration: none;
  padding-right: 20px;
  white-space: nowrap;
  letter-spacing: -0.3px;
}
.topbar-logo span { color: var(--text-muted); font-weight: 400; }

/* CI-Punkt (abgerundetes Quadrat in Akzentfarbe, am Ende oben angesetzt) – em-basiert, skaliert mit der Wortmarke.
   WICHTIG: layout-neutral – bleibt in-flow an der Baseline (vergrößert die Zeilenbox NICHT),
   und wird NUR optisch via position:relative/top nach oben gesetzt → keine Verschiebung ggü. den Tabs. */
.brand-dot {
  display: inline-block;
  width: 0.34em;
  height: 0.34em;
  border-radius: 0.11em;
  background: var(--accent);
  vertical-align: baseline;
  position: relative;
  top: -0.55em;             /* nur optisch nach oben, ohne Layout-Einfluss */
  margin-left: 0.1em;
}

.topbar-nav {
  display: flex;
  gap: 2px;
  flex: 1 1 0%;
  min-width: 0; /* erlaubt dem Nav zu schrumpfen/scrollen statt Geschwister (Abmelden) rauszudrücken */
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  /* Scrollbar ausblenden */
  scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.topbar-nav a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.topbar-nav a:hover { background: var(--bg); color: var(--text); }
.topbar-nav a.active { background: #eff6ff; color: var(--accent); }
.topbar-nav a svg { flex-shrink: 0; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0; /* Abmelden/Name nie zusammenquetschen oder rausdrücken */
  padding-left: 8px;
}

.topbar-user {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Status-Badge-Buttons */
.btn-status { border: 1px solid transparent; font-size: 12px; padding: 4px 10px; border-radius: 20px; cursor: pointer; }
.btn-status.offen   { background: #f1f5f9; color: var(--c-offen);   border-color: var(--c-offen); }
.btn-status.positiv { background: #f0fdf4; color: var(--c-positiv); border-color: var(--c-positiv); }
.btn-status.negativ { background: #fef2f2; color: var(--c-negativ); border-color: var(--c-negativ); }
.btn-status.termin  { background: #eff6ff; color: var(--c-termin);  border-color: var(--c-termin); }
.btn-status.active  { font-weight: 700; }

/* Status-Dot */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.offen   { background: var(--c-offen); }
.dot.positiv { background: var(--c-positiv); }
.dot.negativ { background: var(--c-negativ); }
.dot.termin  { background: var(--c-termin); }

/* ── Formulare ─────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=datetime-local],
textarea, select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}
textarea { resize: vertical; min-height: 80px; }

/* ── Cards / Panels ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

/* ── Toast-Nachrichten ─────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #fff;
  background: #1e293b;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--info); }
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Layout-Hilfsklassen ───────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page-Wrapper (unterhalb Topbar) ───────────────────────────── */
.page-content {
  margin-top: calc(var(--nav-h) + env(safe-area-inset-top));
  height: calc(100vh - var(--nav-h) - env(safe-area-inset-top));
  overflow: hidden;
  display: flex;
  /* Seitenränder bei Notch/Abrundungen */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  /* Unterer Home-Indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Scrollbare Panels ─────────────────────────────────────────── */
.scroll-panel {
  overflow-y: auto;
  overflow-x: hidden;
}
.scroll-panel::-webkit-scrollbar { width: 6px; }
.scroll-panel::-webkit-scrollbar-track { background: transparent; }
.scroll-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: min(480px, 95vw);
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Tabelle ───────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { font-weight: 600; color: var(--text-muted); font-size: 12px; background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── Login-Seite ───────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: min(400px, 95vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 12px;
  margin: 20px 0;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-google {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  justify-content: center;
  font-size: 14px;
  padding: 10px;
}
.btn-google:hover { background: var(--bg); }
.btn-google:disabled { opacity: 0.4; cursor: not-allowed; }
.error-banner {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: var(--danger);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Toast: Safe-Area-Abstand unten (Home-Indicator) ────────────── */
#toast-container {
  bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
  right: max(20px, calc(20px + env(safe-area-inset-right)));
}

/* ── Tabellen: horizontaler Scroll auf kleinen Screens ─────────── */
.doc-table-wrap table,
.table-responsive {
  min-width: 480px;
}

/* ── Responsive: iPhone (≤ 760px) ──────────────────────────────── */
@media (max-width: 760px) {

  /* Topbar-Logo kompakter */
  .topbar-logo {
    font-size: 13px;
    padding-right: 10px;
  }

  /* Topbar-Nav: horizontal scrollbar statt umbrechen */
  .topbar-nav a {
    font-size: 12px;
    padding: 6px 9px;
    gap: 4px;
  }
  .topbar-nav a svg {
    display: none; /* Icons auf sehr schmalen Screens weglassen, Text reicht */
  }

  /* User-Name ausblenden, spart Platz */
  .topbar-user { display: none; }

  /* ── CRM / Planer: Sidebar + Karte stapeln ── */
  /* Gilt für #sidebar in crm.html und #planer-sidebar in planer.html */
  .page-content {
    flex-direction: column;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* CRM Sidebar */
  #sidebar {
    width: 100% !important;
    flex-shrink: 0;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* Planer Sidebar */
  #planer-sidebar {
    width: 100% !important;
    flex-shrink: 0;
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* Karte bekommt Rest-Höhe */
  #map-container {
    flex: 1;
    min-height: 0;
  }
  #map {
    width: 100%;
    height: 100%;
    min-height: 200px;
  }

  /* Detail-Panel in CRM: auf kleinen Screens volle Breite, unten positioniert */
  #detail-panel {
    position: fixed !important;
    top: auto !important;
    bottom: env(safe-area-inset-bottom) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-height: 55vh;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  }

  /* Kalender-Monatsraster horizontal scrollbar */
  #calendar-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 560px;
  }
  /* Wrapper für Grid, damit card-padding den Scroll nicht bricht */
  .card:has(#calendar-grid) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Dokumente-Tabelle: scrollbarer Wrapper greift durch overflow-x */
  #doc-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Login-Karte: volle Breite mit weniger Padding */
  .login-card {
    padding: 28px 20px;
  }

  /* Slot-Grid in buchen.html kompakter */
  .slot-grid {
    gap: 4px;
  }
  .slot-btn {
    font-size: 11px;
    padding: 5px 2px;
  }
}

/* ── Responsive: iPad Portrait (761–1024px) ─────────────────────── */
@media (min-width: 761px) and (max-width: 1024px) {
  /* Sidebar etwas schmaler auf iPad */
  #sidebar {
    width: 280px;
  }
  #planer-sidebar {
    width: 280px;
  }
}
