/* 🌍 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
   Die Breite ist bewusst fest gelegt: ein Flex-Element darf ohne min-width auf
   die Länge seines Inhalts zusammenschrumpfen – das Feld wurde dadurch beim
   Tippen immer schmaler (in den Browsern ab ca. 1100 px Fenstern Breite). */
.search-container { position: relative; flex: 1 1 320px; width: 320px; min-width: 240px; max-width: 340px; margin: 0 0.8rem; }
#searchInput { width: 100%; min-width: 0; box-sizing: border-box; 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: background 0.2s, box-shadow 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); }
/* Eingabefeld und Vorschlagsliste behalten ihre Breite. */
.search-container > #searchInput, .search-container > #searchResults { width: 100%; }
.search-results { position: absolute; top: 105%; left: 0; width: 100%; min-width: 260px; max-height: 240px; overflow-y: auto; background: #fff; border-radius: 12px; 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; }
/* Kopf der Vorschlagsliste ("12 Treffer") und die Fundstelle selbst */
.search-result-count { padding: 0.5rem 1rem; font-size: 0.78rem; color: #64748b; background: #f1f5f9; border-bottom: 1px solid #e2e8f0; }
.search-result-item mark { background: #fef3c7; border-radius: 3px; padding: 0 1px; color: inherit; }
/* Der Hinweis "keine Treffer" darf nicht wie ein Klickergebnis aussehen */
.search-result-noresult { cursor: default; color: #475569; }
.search-result-noresult:hover { background: #fff; color: #475569; }
.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: 18%; }  /* PSA */
#machinesTable th:nth-child(3),
#machinesTable td:nth-child(3) { width: 26%; }  /* Straße */
#machinesTable th:nth-child(4),
#machinesTable td:nth-child(4) { width: auto; } /* Beschreibung */
#machinesTable th:nth-child(5),
#machinesTable td:nth-child(5) { width: 46px; text-align: center; } /* Zur Karte */

#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; }

/* Zwischenbreite: die Suchbox bekommt eine eigene volle Zeile im Header,
   damit sie nie auf wenige Zeichen zusammenschrumpft. */
@media (max-width: 1100px) {
  header { flex-wrap: wrap; }
  .search-container { flex: 1 1 100%; width: 100%; min-width: 0; max-width: 100%; }
  .search-results { min-width: 0; }
}

/* 📱 Mobile Optimierung */
@media (max-width: 768px) {
  header { flex-direction: column; gap: 0.8rem; padding: 0.9rem 1rem; }
  .search-container { width: 100%; min-width: 0; max-width: 100%; margin: 0; order: 2; }
  .search-results { min-width: 0; }
  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; }

/* Toolbar-Gruppen und Koordinaten-Zeile (vorher als inline-Styles im HTML) */
.toolbar-group {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-right: 1rem;
  border-right: 1px solid rgba(255,255,255,0.1);
  padding-right: 1rem;
}
.toolbar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
}
#descFilter { margin: 0; min-width: 140px; }
.coords-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.coords-row input { flex: 1; }
.btn-coords {
  padding: 0.8rem;
  border: none;
  border-radius: 10px;
  background: #3b82f6;
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background 0.2s;
}
.btn-coords:hover { background: #2563eb; }

@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.
   main.js setzt die Klasse show-labels am Kartencontainer (ein einziger
   Klassenwechsel pro Zoom, statt jedes Tooltip einzeln umzustellen). */
#map:not(.show-labels) .feature-label,
#map:not(.show-labels) .leaflet-tooltip {
  opacity: 0 !important;
  pointer-events: none !important;
}
#map.show-labels .feature-label,
#map.show-labels .leaflet-tooltip {
  opacity: 1;
  transition: opacity 0.2s ease;
}
/* Alte Klasse weiter nutzbar (falls an anderer Stelle verwendet) */
.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 */
.popup-edit-btn:hover { background: #2563eb !important; }
.popup-route-btn:hover { background: #15803d !important; }

#routeInfo {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 9999;
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  max-width: min(94vw, 400px);
  white-space: normal;
  line-height: 1.3;
}

/* Der Text im Banner: kompakt, bricht sauber um, gut lesbar auf dem Handy */
#routeInfo span {
  white-space: normal;
  max-width: min(66vw, 330px);
  overflow-wrap: anywhere;
  font-weight: 500;
  flex: 1 1 auto;
}
#routeInfo span div { margin: 1px 0; }
#routeInfo span b { color: #a7f3d0; }
#routeInfo span a { color: #93c5fd; text-decoration: underline; overflow-wrap: anywhere; }
#routeInfo .route-del-link { color: #a7f3d0 !important; }
#routeInfo #routeClear {
  background: #1e293b;
  border: 1px solid #475569;
  color: #fff;
  padding: 2px 9px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1.25;
  cursor: pointer;
  flex: 0 0 auto;
}
#routeInfo #routeClear:hover { background: #334155; }

@media (max-width: 640px) {
  #routeInfo {
    padding: 6px 10px;
    gap: 6px;
    border-radius: 10px;
    max-width: 94vw;
  }
  #routeInfo span { font-size: 0.74rem; max-width: 70vw; }
  #routeInfo #routeClear { padding: 2px 11px; }
}

/* 🔔 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 { bottom: 80px; max-width: 94vw; }   /* über dem GPS-Knopf */
}

/* 📍 Highlight Animation */
.marker-point.selected {
  stroke: var(--marker-stroke, #f6c73b) !important;
  stroke-width: 7 !important;
  animation: marker-pulse 2s infinite;
}

@keyframes marker-pulse {
  0% {
    stroke-width: 7;
    stroke-opacity: 1;
  }
  50% {
    stroke-width: 15;
    stroke-opacity: 0.5;
  }
  100% {
    stroke-width: 7;
    stroke-opacity: 1;
  }
}

/* 🖨️ Print Styles */
@media print {
  body * {
    visibility: hidden;
  }
  #listView, #listView * {
    visibility: visible;
    position: static;
  }
  .table-wrapper {
    margin: 0;
    padding: 0;
    border: none;
    max-height: none !important;
    overflow: visible !important;
  }
  #machinesTable {
    border: 1px solid #eee;
    width: 100%;
  }
  #machinesTable th, #machinesTable td {
    border-bottom: 1px solid #eee !important;
    color: #000 !important;
  }
  #machinesTable th {
    background: #f8fafc !important;
    color: #000 !important;
    border-bottom: 1px solid #ddd !important;
  }
  header, .toolbar, .search-container, .map-controls, .status-bar, #editModal, .btn-import, #btnExportJSON, #descFilter, #btnPrint, .modal-actions, .modal-content h3 {
    display: none !important;
  }
}

/* 🎯 "Zur Karte"-Knopf in der Liste (letzte Spalte) */
#machinesTable .loc-th { text-align: center; }
#machinesTable .loc-td { text-align: center; }
.loc-btn {
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #0f172a;
  border-radius: 8px;
  padding: 3px 9px;
  font-size: 1rem;
  line-height: 1.2;
  cursor: pointer;
}
.loc-btn:hover { background: #dbeafe; border-color: #3b82f6; }
.loc-btn:active { background: #bfdbfe; }

@media (max-width: 768px) {
  #machinesTable th:nth-child(5),
  #machinesTable td:nth-child(5) { width: 40px; }
  .loc-btn { padding: 6px 12px; font-size: 1.05rem; }  /* Finger-tauglich */
}

/* Im Ausdruck hat der Knopf nichts zu suchen */
@media print {
  #machinesTable .loc-th, #machinesTable .loc-td { display: none; }
}
