:root {
  --primary: #1a3a5c;
  --accent: #f97316;
  --accent-dark: #ea6c0a;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --nav-height: 68px;
  --header-height: 60px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

/* ── Header ──────────────────────────────────── */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

#app-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

#app-header .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

#app-header h1 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
}
#app-header h1 span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: .75;
}

#header-date {
  font-size: 12px;
  text-align: right;
  opacity: .85;
  line-height: 1.4;
}

/* ── Main Content ─────────────────────────────── */
#main {
  margin-top: var(--header-height);
  margin-bottom: var(--nav-height);
  min-height: calc(100vh - var(--header-height) - var(--nav-height));
  padding: 16px;
  overflow-y: auto;
}
#main:has(#page-chat.active) {
  overflow: hidden;
  padding: 16px;
}

/* ── Bottom Nav ───────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,.08);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  padding-bottom: 4px;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-item .nav-icon { font-size: 22px; }

.nav-item.active {
  color: var(--accent);
}

.nav-item.active .nav-icon {
  transform: scale(1.1);
}

/* ── Cards ────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); opacity: .85; }

.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--primary); color: white; }
.btn-ghost { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ────────────────────────────────────── */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: var(--text);
  transition: border-color .15s;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea { min-height: 90px; resize: vertical; }

/* ── Badges ───────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-orange { background: #fff3e0; color: #e65100; }
.badge-blue   { background: #e3f2fd; color: #0d47a1; }
.badge-green  { background: #e8f5e9; color: #2e7d32; }
.badge-red    { background: #ffebee; color: #c62828; }
.badge-gray   { background: #f5f5f5; color: #616161; }

/* ── Page Sections ────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* Chat: stabiles Flex-Layout, kein vh, kein Springen bei Tastatur */
#page-chat.active {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-height) - var(--nav-height) - 32px);
  overflow: hidden;
}
#chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: white;
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
#chat-input-row {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
}

/* ── Dashboard ────────────────────────────────── */
.greeting {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}
.greeting-sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card.accent { background: var(--accent); }
.stat-card.accent .stat-label,
.stat-card.accent .stat-value { color: white; }
.stat-card.primary { background: var(--primary); }
.stat-card.primary .stat-label,
.stat-card.primary .stat-value { color: white; }

.stat-value { font-size: 30px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-icon  { font-size: 22px; margin-bottom: 4px; }

/* ── List Items ───────────────────────────────── */
.list-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }

.list-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: #f0f4f8;
}

.list-content { flex: 1; min-width: 0; }
.list-title { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.list-sub   { font-size: 12px; color: var(--muted); }

.list-actions { display: flex; gap: 6px; align-items: center; }

/* ── Checklists ───────────────────────────────── */
.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.checklist-item:last-child { border-bottom: none; }

.checklist-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checklist-item label {
  font-size: 14px;
  cursor: pointer;
  flex: 1;
}
.checklist-item.checked label {
  text-decoration: line-through;
  color: var(--muted);
}

/* ── Photo upload ─────────────────────────────── */
.photo-upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s;
}
.photo-upload-area:active { border-color: var(--accent); }
.photo-upload-area p { font-size: 13px; color: var(--muted); margin-top: 8px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
}
.photo-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-thumb .remove-photo {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,.55);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Modal ────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px 32px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title { font-size: 18px; font-weight: 800; color: var(--primary); }
.modal-close {
  background: var(--border);
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Unterweisungen ───────────────────────────── */
.unterweisung-card {
  border-left: 4px solid var(--accent);
  padding-left: 12px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s;
}

/* ── Utility ──────────────────────────────────── */
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.gap-8 { gap: 8px; }
.flex  { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-muted { color: var(--muted); font-size: 13px; }
.text-center { text-align: center; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--border);
  color: var(--muted);
}
.chip.active { background: #fff3e0; color: var(--accent-dark); }

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

/* Signature pad */
#sig-canvas {
  border: 2px solid var(--border);
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
  width: 100%;
}

.fälligkeit-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* Toast */
#toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  z-index: 999;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Admin-Panel ─────────────────────────────────── */
.admin-filter.active {
  background: var(--primary);
  color: white;
}

/* ── Desktop Sidebar (hidden on mobile) ──────────── */
#app-sidebar {
  display: none;
}

/* ════════════════════════════════════════════════
   DESKTOP LAYOUT  (≥ 900px)
   ════════════════════════════════════════════════ */
@media (min-width: 900px) {
  :root {
    --sidebar-width: 230px;
  }

  body {
    display: grid;
    grid-template-areas:
      "header  header"
      "sidebar main";
    grid-template-rows: var(--header-height) 1fr;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    overflow: hidden;
  }

  /* Header spans full width */
  #app-header {
    grid-area: header;
    position: static;
  }

  /* Sidebar */
  #app-sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    background: var(--primary);
    overflow-y: auto;
    border-right: none;
  }

  .sidebar-user {
    padding: 16px 18px 12px;
    border-bottom: 1px solid rgba(255,255,255,.12);
    color: rgba(255,255,255,.9);
    font-size: 13px;
    line-height: 1.4;
  }
  .sidebar-user strong { display: block; font-size: 14px; font-weight: 700; }
  .sidebar-user span   { font-size: 11px; opacity: .65; }

  .sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,.1);
    margin: 6px 0;
  }

  .sidebar-label {
    padding: 10px 18px 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    color: rgba(255,255,255,.4);
    text-transform: uppercase;
  }

  .sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 18px;
    color: rgba(255,255,255,.72);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    width: 100%;
    border-radius: 0;
    transition: background .15s, color .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar-item:hover { background: rgba(255,255,255,.09); color: white; }
  .sidebar-item.active {
    background: var(--accent);
    color: white;
    font-weight: 700;
  }
  .sidebar-item .sidebar-icon { font-size: 17px; width: 22px; text-align: center; }

  /* Main content area */
  #main {
    grid-area: main;
    margin-top: 0;
    margin-bottom: 0;
    min-height: auto;
    overflow-y: auto;
    padding: 24px 32px;
  }

  /* Hide mobile bottom nav */
  #bottom-nav { display: none; }

  /* Modal: centered popup instead of bottom sheet */
  .modal-backdrop { align-items: center; }
  .modal {
    border-radius: 18px;
    max-width: 580px;
    margin: 0 auto;
    max-height: 88vh;
  }

  /* Toast: no bottom-nav offset */
  #toast { bottom: 24px; }

  /* Dashboard: 4-column stats on desktop */
  .stats-grid { grid-template-columns: repeat(4, 1fr); }

  /* Leaflet map: taller on desktop */
  #leaflet-map { height: 420px !important; }
}
