:root {
  --red: #c8102e;
  --red-dark: #a10d25;
  --gray-bg: #f4f5f7;
  --border: #dcdfe4;
  --text: #23262b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* --- Login --- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
}
.login-box {
  background: white;
  padding: 2.5rem 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.login-box h1 { margin: 0; font-size: 1.3rem; text-align: center; }
.login-box .subtitle { margin: 0 0 0.5rem; text-align: center; color: #777; font-size: 0.9rem; }
.login-box input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.login-box button {
  background: var(--red);
  color: white;
  border: none;
  padding: 0.65rem;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 0.25rem;
}
.login-box button:hover { background: var(--red-dark); }
.error { color: var(--red); font-size: 0.85rem; min-height: 1.2em; text-align: center; }

/* --- App shell --- */
.topbar {
  background: var(--red);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.topbar-right button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}
.tab-btn {
  background: none;
  border: none;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  font-size: 0.95rem;
  color: #555;
  border-bottom: 3px solid transparent;
}
.tab-btn.active { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }

main { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }
main:has(#tab-map.active) { max-width: none; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Karte + Sidebar --- */
.map-layout {
  display: flex;
  gap: 1rem;
  height: calc(100vh - 170px);
  min-height: 420px;
}
#map { flex: 1; min-width: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }

.map-sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}
.sidebar-block {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-block-grow { flex: 1 1 0; } /* Standorte + Fahrzeuge teilen sich die Höhe, jeweils scrollbar */
.sidebar-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.sidebar-block-header h3 { margin: 0; font-size: 0.95rem; }
.sidebar-block-header button {
  background: var(--gray-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.legend-list { overflow-y: auto; display: flex; flex-direction: column; gap: 0.3rem; }
.legend-group summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.25rem 0;
  cursor: pointer;
  list-style: none;
}
.legend-group summary::-webkit-details-marker { display: none; }
.legend-group summary::before { content: "▸"; color: #999; width: 0.7rem; }
.legend-group[open] summary::before { content: "▾"; }
.legend-group summary input { width: auto; margin: 0; }
.legend-group summary .legend-label { flex: 1; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.15rem 0 0.15rem 1.9rem;
}
.legend-item input { width: auto; margin: 0; }
.legend-label { flex: 1; }
.legend-sub { color: #888; font-size: 0.75rem; font-weight: normal; }
.legend-dot { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; flex-shrink: 0; vertical-align: middle; }

.standort-marker { background: none; border: none; }
.standort-marker svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }

.vehicle-tiles { overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.vehicle-tile {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.vehicle-tile:hover { background: var(--gray-bg); }
.vehicle-tile.selected { border-color: var(--red); background: #fdecec; }
.vehicle-tile .vt-title { font-weight: 600; font-size: 0.9rem; display: flex; justify-content: space-between; gap: 0.4rem; }
.vehicle-tile .vt-meta { font-size: 0.78rem; color: #777; margin-top: 0.15rem; }
.vehicle-tile .vt-standort { font-size: 0.78rem; color: #555; margin-top: 0.2rem; }
.vehicle-tile .vt-standort.no-standort { color: #aaa; font-style: italic; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.panel-header button {
  background: var(--red);
  color: white;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
}

.badge {
  display: inline-block;
  background: #eef0f3;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  margin-right: 0.3rem;
  margin-top: 0.3rem;
}
.badge.status-werkstatt { background: #fde8d7; color: #b4520a; }
.badge.status-ausser_dienst { background: #f6d3d3; color: #a10d25; }
.badge.status-einsatzbereit { background: #dcf3df; color: #1c7a34; }

.data-table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.data-table th { background: var(--gray-bg); }
.data-table .meta { color: #777; font-size: 0.8rem; margin-top: 0.15rem; }
.data-table .badge { margin-top: 0.1rem; }
.data-table td.actions-cell { width: 1%; white-space: nowrap; text-align: right; }

.row-actions { display: inline-flex; gap: 0.15rem; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--gray-bg); color: var(--text); }
.icon-btn.danger:hover { background: #fdecec; color: var(--red); }

/* --- Modal --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
  z-index: 1000;
}
.modal {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
}
.modal h2 { margin-top: 0; }
.modal label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
}
.modal input, .modal select, .modal textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.25rem;
  font-size: 0.95rem;
}
.modal .checkbox-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.25rem; }
.modal .checkbox-list label { display: flex; align-items: center; gap: 0.3rem; font-weight: normal; margin-top: 0; background: var(--gray-bg); padding: 0.25rem 0.6rem; border-radius: 999px; }
.modal .checkbox-list input { width: auto; margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.25rem; }
.modal-actions button { padding: 0.5rem 1rem; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; background: var(--gray-bg); }
.modal-actions button.primary { background: var(--red); color: white; border-color: var(--red); }
.modal-actions button.danger { background: #fff; color: var(--red); border-color: var(--red); margin-right: auto; }
.modal .field-row { display: flex; gap: 0.6rem; }
.modal .field-row > div { flex: 1; min-width: 0; }
.modal .field-row > .field-plz { flex: 0 0 6.5rem; }
.data-table a { color: inherit; }
.modal .label-hint { font-weight: normal; color: #888; }
.modal .geocode-row { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.9rem; flex-wrap: wrap; }
.modal .geocode-row button, .modal .geocode-hit {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--gray-bg);
  cursor: pointer;
  font-size: 0.85rem;
}
.modal .geocode-row .label-hint { font-size: 0.8rem; }
.modal .geocode-hit { display: block; width: 100%; text-align: left; margin-top: 0.35rem; }
.modal .geocode-hit:hover { border-color: var(--red); }
