:root {
  --primary: #007667;
  --primary-dark: #005a4e;
  --primary-light: #85ccd3;
  --danger: #dc3545;
  --warning: #fd7e14;
  --success: #198754;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #333333;
  --text-light: #6c757d;
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,.1);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .2s ease;
}

* { box-sizing: border-box; }

body {
  font-family: "Open Sans", sans-serif;
  color: var(--text);
  background: var(--bg);
  margin: 0;
  padding: 0;
  padding-top: calc(var(--topbar-h) + var(--safe-top));
  padding-bottom: var(--safe-bottom);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  min-height: 100dvh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Raleway", sans-serif;
  color: var(--primary-dark);
}

/* Topbar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--primary);
  color: #fff;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.topbar-inner {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 8px;
}

.topbar-logo {
  height: 36px;
  width: auto;
  margin-right: 8px;
  flex-shrink: 0;
}

.topbar-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  margin: 0;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-version {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.3rem;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:active { background: rgba(255,255,255,.2); }

/* Dropdown in Topbar */
.topbar .dropdown-menu {
  border: none;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  border-radius: var(--radius-sm);
  min-width: 220px;
}
.topbar .dropdown-item {
  font-size: .9rem;
  padding: 10px 16px;
}
.topbar .dropdown-item:active {
  background: var(--primary);
  color: #fff;
}
.topbar .dropdown-item-text {
  padding: 6px 16px;
}

/* Offline Banner */
.offline-banner {
  display: none;
  background: var(--warning);
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: .85rem;
  font-weight: 600;
  position: fixed;
  top: calc(var(--topbar-h) + var(--safe-top));
  left: 0;
  right: 0;
  z-index: 999;
}

body.offline .offline-banner { display: block; }

/* Pages */
.page {
  display: none;
  animation: fadeIn .2s ease;
}

.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Logo */
.app-logo {
  display: inline-block;
}

.app-logo img {
  height: 120px;
  width: auto;
  filter: drop-shadow(0 2px 8px rgba(0,118,103,.15));
}

/* Stats */
.stats-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 12px;
  box-shadow: var(--shadow-md);
}

.stat-number {
  font-family: "Raleway", sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: .75rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-top: 4px;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover, .btn-primary:active {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover, .btn-outline-primary:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Form */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  border: 1.5px solid #dee2e6;
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,118,103,.15);
}

.form-label {
  font-size: .85rem;
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 600;
}

/* Checklist Card */
.checklist-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--primary);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}

.checklist-card:active {
  transform: scale(.98);
  box-shadow: var(--shadow-md);
}

.checklist-card.done { border-left-color: var(--success); }
.checklist-card.has-mangel { border-left-color: var(--warning); }
.checklist-card.has-kritisch { border-left-color: var(--danger); }

.checklist-card h5 {
  font-size: 1rem;
  margin: 0 0 4px 0;
  font-family: "Raleway", sans-serif;
  color: var(--primary-dark);
}

.checklist-card .meta {
  font-size: .8rem;
  color: var(--text-light);
}

/* Checklist checkbox */
.checklist-item {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.checklist-item:active { background: #e9ecef; transform: scale(.98); }

.checklist-item .status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #dee2e6;
}

.checklist-item[data-status="ok"] .status-dot { background: var(--success); }
.checklist-item[data-status="mangel"] .status-dot { background: var(--warning); }
.checklist-item[data-status="kritisch"] .status-dot { background: var(--danger); }

.checklist-item .item-text {
  flex: 1;
  font-size: .95rem;
}

.checklist-item .item-arrow {
  color: var(--text-light);
  font-size: .8rem;
}

/* Kategorie Header */
.kategorie-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.kategorie-header i { font-size: 1.3rem; }

.kategorie-header h5 {
  margin: 0;
  color: #fff;
  font-size: 1rem;
  flex: 1;
}

.kategorie-header .badge {
  font-size: .75rem;
}

/* Status Buttons */
#statusGroup .btn {
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  font-weight: 600;
  transition: all var(--transition);
}

#statusGroup .btn.active { color: #fff; }
#statusGroup .btn[data-status="ok"].active { background: var(--success); border-color: var(--success); }
#statusGroup .btn[data-status="mangel"].active { background: var(--warning); border-color: var(--warning); }
#statusGroup .btn[data-status="kritisch"].active { background: var(--danger); border-color: var(--danger); }

/* Foto Grid */
.foto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.foto-grid .foto-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.foto-grid .foto-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.foto-grid .foto-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(220,53,69,.9);
  color: #fff;
  border: none;
  font-size: .7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Begehungen Liste */
.begehung-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform var(--transition), box-shadow var(--transition);
}

.begehung-card:active { transform: scale(.98); box-shadow: var(--shadow-md); }

.begehung-card .card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.begehung-card .card-body {
  flex: 1;
  min-width: 0;
}

.begehung-card .card-body h6 {
  margin: 0;
  font-family: "Raleway", sans-serif;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--primary-dark);
}

.begehung-card .card-body .meta {
  font-size: .8rem;
  color: var(--text-light);
}

.begehung-card .card-status {
  font-size: .7rem;
  padding: 4px 8px;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}

.begehung-card .card-status.status-offen { background: #e2e3e5; color: #41464b; }
.begehung-card .card-status.status-fertig { background: #d1e7dd; color: #0f5132; }

/* Kebab-Menü in Begehungs-Liste */
.begehung-card { position: relative; }
.begehung-card .card-kebab { z-index: 10; }
.begehung-card.menu-open { z-index: 100; }
.begehung-card.menu-open .begehung-menu { z-index: 100; }
.card-kebab {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  cursor: pointer;
  transition: background var(--transition);
}
.card-kebab:hover { background: rgba(0,0,0,.06); color: #333; }
.begehung-menu {
  display: none;
  position: absolute;
  top: 38px;
  right: 0;
  min-width: 230px;
  max-width: 260px;
  max-height: 70vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  padding: 6px;
}
.begehung-menu.show { display: block; }
.begehung-menu .dropdown-header {
  padding: 8px 12px 4px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.begehung-menu .dropdown-item {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  cursor: pointer;
  color: #333;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
}
.begehung-menu .dropdown-item:hover { background: #f3f6f4; }
.begehung-menu .dropdown-item.text-danger { color: var(--danger); }
.begehung-menu .dropdown-item.text-danger:hover { background: #fdeceb; }
.begehung-menu .dropdown-divider {
  height: 1px;
  margin: 6px 8px;
  background: rgba(0,0,0,.08);
}
.begehung-menu .dropdown-header { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }

/* Progress Bar */
.progress {
  height: 6px;
  border-radius: 3px;
  background: #e9ecef;
  margin-top: 6px;
}

.progress-bar {
  border-radius: 3px;
  background: var(--primary);
}

/* Delete confirm */
.modal-backdrop { background: rgba(0,0,0,.4); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Print: hide topbar */
@media print {
  .topbar, .offline-banner, .btn { display: none !important; }
  body { padding: 0; }
}

/* Nicht angemeldet: Topbar & Offline-Banner ausblenden (nur Login-Seite sichtbar) */
body.logged-out .topbar,
body.logged-out .offline-banner { display: none !important; }
body.logged-out { padding-top: 0 !important; }

/* Login-Seite: vertikal zentrieren auf vollem Bildschirm */
body.logged-out #pageLogin {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* Signature Pad */
.signature-block { margin-bottom: 1.5rem; }
.signature-box {
  border: 2px dashed #ccc;
  border-radius: 12px;
  background: #fff;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.signature-box canvas {
  display: block;
  cursor: crosshair;
  border-radius: 10px;
}
.signature-label {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  color: #aaa;
  pointer-events: none;
}
.signature-box:has(canvas:focus) {
  border-color: var(--primary);
}
