/* 🌍 Basis & Layout */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }
body { background: #f8fafc; color: #1e293b; line-height: 1.5; }

/* 🔐 Login */
.login-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); }
.login-box { background: #fff; padding: 2rem; border-radius: 16px; box-shadow: 0 12px 32px rgba(0,0,0,0.2); width: 90%; max-width: 380px; }
.login-box input { width: 100%; padding: 0.85rem 1rem; margin: 0.6rem 0; border: 1.5px solid #e2e8f0; border-radius: 10px; font-size: 0.95rem; background: #f8fafc; transition: all 0.2s; }
.login-box input:focus { outline: none; border-color: #3b82f6; background: #fff; box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.login-box button { width: 100%; padding: 0.9rem; background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff; border: none; border-radius: 10px; font-weight: 600; cursor: pointer; margin-top: 0.5rem; transition: all 0.2s; }
.login-box button:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37,99,235,0.3); }
.error { color: #ef4444; font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }

/* 📱 Header & Navigation */
header { background: #0f172a; color: #fff; padding: 1rem 1.2rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.8rem; box-shadow: 0 4px 12px rgba(0,0,0,0.15); position: relative; z-index: 500; }
header h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }
nav button { padding: 0.6rem 1rem; border: none; border-radius: 8px; background: rgba(255,255,255,0.12); color: #e2e8f0; font-weight: 500; cursor: pointer; transition: all 0.2s; font-size: 0.9rem; }
nav button:hover { background: rgba(255,255,255,0.2); }
nav button.active { background: #3b82f6; color: #fff; box-shadow: 0 2px 8px rgba(59,130,246,0.4); }
#btnLogout { background: #ef4444 !important; color: #fff !important; }
#btnLogout:hover { background: #dc2626 !important; }

/* 🔍 Suche & Status */
.search-container { position: relative; flex: 1; max-width: 340px; margin: 0 0.8rem; }
#searchInput { width: 100%; padding: 0.7rem 2.8rem 0.7rem 1rem; border: none; border-radius: 10px; font-size: 0.95rem; background: rgba(255,255,255,0.15); color: #fff; outline: none; transition: all 0.2s; }
#searchInput::placeholder { color: rgba(255,255,255,0.6); }
#searchInput:focus { background: rgba(255,255,255,0.25); box-shadow: 0 0 0 2px rgba(255,255,255,0.2); }
.clear-x { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: pointer; color: #cbd5e1; font-size: 1.1rem; padding: 4px; border-radius: 50%; transition: all 0.2s; }
.clear-x:hover { color: #ef4444; background: rgba(255,255,255,0.1); }
.search-results { position: absolute; top: 105%; left: 0; right: 0; background: #fff; border-radius: 12px; max-height: 240px; overflow-y: auto; box-shadow: 0 10px 24px rgba(0,0,0,0.15); z-index: 9999; display: none; }
.search-results.active { display: block; }
.search-result-item { padding: 0.85rem 1rem; cursor: pointer; border-bottom: 1px solid #f1f5f9; font-size: 0.92rem; color: #334155; transition: all 0.15s; }
.search-result-item:hover { background: #f8fafc; color: #2563eb; }
.search-result-item strong { color: #2563eb; }
.status-bar { display: flex; gap: 12px; margin-top: 0.5rem; font-size: 0.82rem; color: #94a3b8; align-items: center; flex-wrap: wrap; }
.status-pill { background: rgba(255,255,255,0.1); padding: 4px 10px; border-radius: 20px; font-size: 0.78rem; color: #cbd5e1; border: 1px solid rgba(255,255,255,0.15); }

/* 🗺 Karte & Views */
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
#mapView { height: 65vh; min-height: 420px; width: 100%; position: relative; border-radius: 16px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,0.12); isolation: isolate; }
#map { width: 100%; height: 100%; min-height: 420px; z-index: 1; }
.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 180px); /* Höhe anpassen je nach Navbar */
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  margin-top: 1rem;
}

#machinesTable {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

#machinesTable th, #machinesTable td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
  font-size: 0.83rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#machinesTable th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1; /* wichtig: sonst scrollt der Inhalt über die Header */
  box-shadow: 0 1px 0 #f1f5f9; /* ersetzt border-bottom beim sticky-Header */
}
/* Spaltenbreiten – automatisch */
#machinesTable th:nth-child(1),
#machinesTable td:nth-child(1) { width: 28px; text-align: center; } /* Status */
#machinesTable th:nth-child(2),
#machinesTable td:nth-child(2) { width: 20%; }  /* PSA */
#machinesTable th:nth-child(3),
#machinesTable td:nth-child(3) { width: 30%; }  /* Straße */
#machinesTable th:nth-child(4),
#machinesTable td:nth-child(4) { width: auto; } /* Beschreibung */

#machinesTable tr:hover td { background: #f8fafc; }
#machinesTable tr:last-child td { border-bottom: none; }

/* 🛠 Edit Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(10px); z-index: 2000; display: none; justify-content: center; align-items: center; padding: 1rem; animation: fadeIn 0.2s ease; }
.modal-overlay.active { display: flex; }
.modal-content { background: #fff; border-radius: 18px; width: 100%; max-width: 440px; box-shadow: 0 24px 48px rgba(0,0,0,0.3); padding: 1.8rem; position: relative; animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-content h3 { margin: 0 0 1.2rem; font-size: 1.35rem; color: #0f172a; display: flex; align-items: center; gap: 0.5rem; }
.modal-content label { display: block; margin: 0.8rem 0 0.3rem; font-weight: 500; color: #334155; font-size: 0.9rem; }
.modal-content input, .modal-content select { width: 100%; padding: 0.8rem 1rem; border: 1.5px solid #e2e8f0; border-radius: 10px; font-size: 0.95rem; background: #f8fafc; transition: all 0.2s; }
.modal-content input:focus, .modal-content select:focus { outline: none; border-color: #3b82f6; background: #fff; box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.modal-actions { display: flex; gap: 0.8rem; margin-top: 1.4rem; }
.modal-actions button { flex: 1; padding: 0.85rem; border: none; border-radius: 10px; font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: all 0.2s; }
#btnCloseModal { background: #f1f5f9; color: #475569; }
#btnCloseModal:hover { background: #e2e8f0; }
.modal-content button[type="submit"] { background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.modal-content button[type="submit"]:hover { background: linear-gradient(135deg, #2563eb, #1d4ed8); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37,99,235,0.4); }

/* 📥📤 Toolbar */
.toolbar { display: flex; gap: 0.8rem; margin: 1rem 0; flex-wrap: wrap; }
.toolbar button, .btn-import { padding: 0.7rem 1.1rem; border-radius: 10px; border: none; cursor: pointer; background: #f1f5f9; color: #334155; font-weight: 500; font-size: 0.88rem; transition: all 0.2s; display: inline-flex; align-items: center; gap: 0.4rem; }
.toolbar button:hover, .btn-import:hover { background: #e2e8f0; transform: translateY(-1px); }
.btn-import { background: #dcfce7; color: #166534; }
.btn-import:hover { background: #bbf7d0; }

/* 📱 Mobile Optimierung */
@media (max-width: 768px) {
  header { flex-direction: column; gap: 0.8rem; padding: 0.9rem 1rem; }
  .search-container { max-width: 100%; margin: 0; order: 2; }
  nav { width: 100%; justify-content: center; order: 3; }
  header h1 { order: 1; width: 100%; text-align: center; margin: 0; }
  .status-bar { justify-content: center; font-size: 0.8rem; }
  #mapView { height: 55vh; min-height: 320px; }
  .modal-content { padding: 1.4rem; }
  .modal-content h3 { font-size: 1.2rem; }
  .toolbar { justify-content: center; }
}
.popup-edit-btn:hover { background: #2563eb; }
.popup-edit-btn:active { transform: scale(0.98); }
/* 🗺 Map Control Dropdown */
.map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 400;
}
.dropdown-control {
  padding: 7px 12px;
  border: none;
  border-radius: 8px;
  background: #ffffff;
  color: #1e293b;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
  cursor: pointer;
  outline: none;
  min-width: 190px;
  transition: all 0.2s;
}
.dropdown-control:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.2); }
.dropdown-control:focus { border: 2px solid #3b82f6; }
.dropdown-control option { padding: 6px; }

@media (max-width: 768px) {
  .map-controls { top: 6px; right: 6px; }
  .dropdown-control { min-width: 150px; font-size: 0.85rem; padding: 6px 10px; }
}
/* 🏷️ Leaflet Tooltip Styling (keine !important, Leaflet-kompatibel) */
.feature-label {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: bold;
  color: #0f172a;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
  white-space: nowrap;
}
.feature-label::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
}
/* Klicks durchlassen */
.leaflet-tooltip-wrapper .feature-label {
  pointer-events: none;
}
/* Versteckt Labels bei zu kleinem Zoom */
.label-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}
@media (max-width: 768px) {
  .feature-label { font-size: 0.75rem; font-weight: bold; padding: 3px 8px; }

  /* Tabelle auf Mobile: Text umbrechend statt abschneiden */
  #machinesTable th, #machinesTable td {
    white-space: normal;
    word-break: break-word;
    font-size: 0.78rem;
    padding: 0.35rem 0.4rem;
  }
  #machinesTable th:nth-child(1),
  #machinesTable td:nth-child(1) { width: 24px; }
}

/* 📍 GPS Button */
.gps-control-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.gps-control-btn:hover { background: #f0f9ff; }
.gps-control-btn.gps-active { background: #3b82f6; }

/* 📍 Blinkender GPS-Marker */
.gps-pulse-outer {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: gpsPulse 1.5s ease-out infinite;
}
.gps-pulse-inner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(59,130,246,0.8);
}
@keyframes gpsPulse {
  0%   { transform: scale(1);   opacity: 1; }
  70%  { transform: scale(2.2); opacity: 0.3; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ⏳ Lade-Spinner */
#loadingSpinner {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
}
.spinner-inner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 🧭 Route Info Banner */
#routeInfo {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 9999;
  display: none;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

/* 🔔 Toast */
.psa-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 9999;
  animation: fadeInUp 0.3s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (max-width: 768px) {
  #routeInfo { font-size: 0.85rem; padding: 10px 14px; bottom: 80px; }
}
