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

:root {
  --primary: #1565C0;
  --primary-dark: #0D47A1;
  --primary-light: #42A5F5;
  --accent: #FF6F00;
  --accent-light: #FFA726;
  --bg: #F5F5F5;
  --card: #FFFFFF;
  --text: #212121;
  --text-secondary: #757575;
  --border: #E0E0E0;
  --success: #2E7D32;
  --success-light: #E8F5E9;
  --warning: #F57F17;
  --warning-light: #FFF8E1;
  --danger: #C62828;
  --danger-light: #FFEBEE;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.16);
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* Header */
.header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
  min-height: 56px;
}

.header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-subtitle {
  font-size: 0.75rem;
  opacity: 0.85;
  font-weight: 400;
}

.btn-back {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  line-height: 1;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:active {
  background: rgba(255,255,255,0.2);
}

.header-actions {
  display: flex;
  gap: 4px;
}

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

.header-btn:active {
  background: rgba(255,255,255,0.2);
}

/* Main content */
#app {
  padding: 16px;
  padding-bottom: 100px;
  max-width: 600px;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  border: 2px solid transparent;
}

.card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-lg);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card .badge {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-open {
  background: #E3F2FD;
  color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.96);
  opacity: 0.9;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-accent {
  background: var(--accent);
  color: white;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-lg {
  padding: 18px 32px;
  font-size: 1.15rem;
}

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.4rem;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 2rem;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: transform 0.15s;
}

.fab:active {
  transform: scale(0.9);
}

/* Choice buttons (Trasse / Hausanschlüsse) */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.choice-btn {
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
}

.choice-btn:active {
  transform: scale(0.96);
}

.choice-btn .icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
}

.choice-btn .label {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.choice-btn .sublabel {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

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

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

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--text);
}

.form-label.required::after {
  content: ' *';
  color: var(--danger);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s;
}

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

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23757575' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

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

/* Section headers */
.section-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header .icon {
  font-size: 1.2rem;
}

/* Photo grid */
.photo-section {
  margin-bottom: 20px;
}

.photo-section-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text);
}

.photo-section-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-slot {
  position: relative;
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FAFAFA;
  transition: border-color 0.2s;
}

.photo-slot:active {
  border-color: var(--primary);
}

.photo-slot.has-photo {
  border-style: solid;
  border-color: var(--success);
}

.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-slot .add-icon {
  font-size: 2rem;
  color: var(--text-secondary);
}

.photo-slot .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.photo-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.65);
  color: white;
  font-size: 0.6rem;
  padding: 3px 5px;
  line-height: 1.3;
}

/* Camera button */
.camera-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.camera-btn:active {
  opacity: 0.9;
  transform: scale(0.98);
}

.camera-btn.gallery-btn {
  background: var(--accent);
}

.camera-btn .icon {
  font-size: 1.5rem;
}

/* Button group for camera/gallery */
.btn-group-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.btn-group-row .camera-btn {
  flex: 1;
  margin-bottom: 0;
  padding: 16px 12px;
  font-size: 0.95rem;
}

/* Photo slot with camera/gallery buttons */
.photo-slot.photo-slot-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  border-style: dashed;
  aspect-ratio: auto;
  min-height: 80px;
}

.photo-slot.photo-slot-actions .photo-add-btn {
  width: 100%;
}

.photo-add-btn {
  flex: 1;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 0;
}

.photo-add-btn.gallery {
  background: var(--accent);
}

.photo-add-btn:active {
  opacity: 0.8;
}

/* Signature pad */
.signature-section {
  margin-bottom: 20px;
}

.signature-label {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.signature-description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.signature-pad-wrapper {
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: white;
  position: relative;
}

.signature-pad-wrapper.signed {
  border-color: var(--success);
}

.signature-canvas {
  width: 100%;
  height: 150px;
  display: block;
  touch-action: none;
}

.signature-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.signature-actions .btn {
  padding: 8px 16px;
  font-size: 0.85rem;
}

.signature-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-secondary);
  font-size: 0.85rem;
  pointer-events: none;
  opacity: 0.5;
}

/* Trasse photo list */
.trasse-photo-item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
}

.trasse-photo-item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.trasse-photo-info {
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trasse-photo-info .coords {
  font-family: monospace;
  font-size: 0.75rem;
}

.trasse-photo-actions {
  display: flex;
  gap: 8px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 1rem;
  margin-bottom: 8px;
}

.empty-state .hint {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* Modal / Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}

.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Toast / Notification */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 300;
  animation: toastIn 0.3s, toastOut 0.3s 2.7s;
  box-shadow: var(--shadow-lg);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Status bar */
.status-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--card);
  padding: 6px 12px;
  border-radius: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.gps { background: var(--primary-light); }

/* Progress indicator */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 8px 0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Action row */
.action-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.action-row .btn {
  flex: 1;
}

/* Delete button in card */
.card-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.2rem;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-delete:active {
  background: var(--danger-light);
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Utility classes */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-small { font-size: 0.85rem; }
.text-muted { color: var(--text-secondary); }
.hidden { display: none !important; }

/* Fix for iOS input zoom */
@media screen and (max-width: 768px) {
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* Map */
.trasse-map {
  width: 100%;
  height: calc(100vh - 72px);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 1;
}

.trasse-map .leaflet-popup-content {
  margin: 8px;
}

/* Dashboard */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px;
  text-align: center;
}

.stat-item {
  padding: 8px 4px;
  border-radius: 8px;
  background: var(--bg);
}

.stat-item.stat-open { background: #E3F2FD; }
.stat-item.stat-progress { background: var(--warning-light); }
.stat-item.stat-done { background: var(--success-light); }

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.progress-bar-stacked {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  display: flex;
  overflow: hidden;
}

.progress-segment {
  height: 100%;
  transition: width 0.3s;
}

.progress-done { background: var(--success); }
.progress-wip { background: var(--warning); }

.card-warning {
  border-left: 4px solid var(--warning);
}

.missing-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.missing-tag {
  font-size: 0.7rem;
  background: var(--warning-light);
  color: var(--warning);
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.activity-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

.activity-text {
  font-size: 0.85rem;
}

.activity-text .badge {
  font-size: 0.65rem;
  padding: 1px 6px;
  vertical-align: middle;
}

.activity-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Sync indicator dot */
.sync-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.3s;
}

.sync-dot.offline { background: #9E9E9E; }
.sync-dot.syncing { background: var(--warning); animation: pulse 1s infinite; }
.sync-dot.synced { background: var(--success); }
.sync-dot.error { background: var(--danger); }
.sync-dot.checking { background: var(--primary-light); animation: pulse 1s infinite; }
.sync-dot.idle { background: var(--primary-light); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Header user menu */
.header-user {
  position: relative;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.header-user:active {
  background: rgba(255,255,255,0.2);
}

.header-username {
  color: white;
  font-size: 0.8rem;
  font-weight: 500;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.user-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: 150;
  overflow: hidden;
  margin-top: 4px;
}

.user-menu.show {
  display: block;
}

.user-menu a {
  display: block;
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.user-menu a:last-child {
  border-bottom: none;
}

.user-menu a:active {
  background: var(--bg);
}

/* Login screen */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-logo {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.login-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.login-offline-hint {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 16px;
  padding: 8px;
  background: var(--warning-light);
  border-radius: 8px;
}

/* Audit log styles */
.audit-card {
  border-left: 3px solid var(--primary-light);
}

.audit-json {
  font-family: monospace;
  font-size: 0.7rem;
  background: var(--bg);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
  color: var(--text-secondary);
}

/* Badge variants */
.badge-admin {
  background: #E8EAF6;
  color: #283593;
}

.badge-disabled {
  background: #ECEFF1;
  color: #78909C;
}

/* Conflict compare */
.conflict-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.conflict-side {
  min-width: 0;
}

.conflict-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
  text-transform: uppercase;
}

/* Print styles */
@media print {
  .header, .fab, .btn, .camera-btn {
    display: none;
  }
}
