:root {
  --bg: #060C1A;
  --bg-2: #0B1426;
  --bg-3: #111E36;
  --fg: #E6ECF7;
  --fg-mut: #93A0BA;
  --accent: #4472FF;
  --accent-2: #5B86FF;
  --danger: #FF4D6D;
  --ok: #2EE0A1;
  --border: #1B2A4A;
  --radius: 10px;
  --shadow: 0 4px 28px rgba(0,0,0,.4);
  --font: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  overflow-x: hidden;
}
#bg-canvas {
  position: fixed; inset: 0;
  z-index: 0; pointer-events: none;
  opacity: .55;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { color: var(--accent); }

/* --- Buttons --- */
button {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s ease;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-3); }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }
button.small { padding: 6px 10px; font-size: 13px; }
button.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
button.danger:hover { background: var(--danger); color: white; }

/* --- Form-Elemente --- */
label {
  display: block;
  margin: 10px 0;
  color: var(--fg-mut);
  font-size: 13px;
}
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 10px 12px;
  margin-top: 4px;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
}
input[type="color"] {
  width: 60px; height: 38px; padding: 0;
  border: 1px solid var(--border);
  background: var(--bg-2);
  border-radius: var(--radius);
  cursor: pointer;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
.opt {
  display: flex; align-items: center; gap: 8px;
  color: var(--fg);
}
.opt input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
}

/* --- Login --- */
.login-container {
  position: relative; z-index: 1;
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: rgba(11,20,38,.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
  text-align: center;
}
.logo { margin-bottom: 16px; }
.login-card h1 {
  margin: 0;
  font-size: 28px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2) 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--fg-mut); margin: 6px 0 24px; }
.login-card form { text-align: left; }
.login-card button { width: 100%; margin-top: 10px; }
.error {
  margin-top: 14px; padding: 10px;
  background: rgba(255,77,109,.12);
  color: var(--danger);
  border: 1px solid rgba(255,77,109,.35);
  border-radius: var(--radius);
  text-align: center;
}

/* --- Topbar --- */
.topbar {
  position: relative; z-index: 5;
  background: rgba(6,12,26,.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo-mini { font-size: 22px; }
.topbar h2 { margin: 0; font-size: 18px; }
.tag {
  font-size: 11px;
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}
.topbar-nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar-nav a {
  color: var(--fg-mut);
  padding: 6px 0;
  border-bottom: 2px solid transparent;
}
.topbar-nav a.active { color: var(--fg); border-bottom-color: var(--accent); }
.topbar-nav a:hover { color: var(--fg); }
.topbar-nav .logout { color: var(--danger); }
.user-badge {
  color: var(--fg-mut);
  font-size: 12px;
  padding: 4px 10px;
  background: var(--bg-3);
  border-radius: 12px;
}
.burger-btn {
  display: none;
  background: transparent;
  color: var(--fg);
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
  border: 1px solid var(--border);
}
.burger-btn:hover { background: var(--bg-3); }

/* --- Dropdown --- */
.dropdown { position: relative; display: inline-block; }
.dropdown-toggle {
  background: transparent;
  color: var(--fg-mut);
  border: none;
  padding: 4px 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
}
.dropdown-toggle:hover { background: var(--bg-3); color: var(--fg); }
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  min-width: 180px;
  padding: 4px;
  z-index: 50;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
}
.dropdown-menu button:hover { background: var(--bg-2); }
.dropdown-menu button.danger { color: var(--danger); }
.dropdown-menu button.danger:hover { background: rgba(255,77,109,.12); }

/* --- Dashboard Layout --- */
.dashboard {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 56px);
}
.sidebar {
  background: rgba(11,20,38,.92);
  backdrop-filter: blur(8px);
  border-right: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
}
.sidebar-section { margin-bottom: 24px; }
.sidebar-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--fg-mut);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.sidebar-header h3 { margin: 0; }
.sidebar-section .btn-secondary { width: 100%; margin-top: 8px; }

.device-list { display: flex; flex-direction: column; gap: 8px; }
.device {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color .15s;
}
.device:hover { border-color: var(--accent); }
.device.active { border-color: var(--accent); background: rgba(68,114,255,.08); }
.device-head { display: flex; align-items: center; gap: 8px; }
.device-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.device-icon-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.device-icon-mini svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}
.device-name {
  flex: 1; font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.device-meta {
  font-size: 11px; color: var(--fg-mut); margin-top: 6px;
  display: flex; align-items: center;
}

/* --- Map-Marker mit Geräte-Icon --- */
.leaflet-div-icon.gps-marker-icon {
  background: transparent !important;
  border: none !important;
}
.gps-pin {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, filter .3s, opacity .3s;
}
.gps-pin:hover { transform: scale(1.1); }
.gps-pin svg {
  width: 20px;
  height: 20px;
  fill: #fff;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.4));
}
.gps-pin.status-online {
  /* Voller Glow, leichter Puls */
  animation: pin-pulse 2.5s ease-in-out infinite;
}
.gps-pin.status-recent {
  filter: saturate(.55) brightness(.85);
}
.gps-pin.status-offline {
  filter: grayscale(.85) brightness(.55);
  opacity: .7;
  border-color: rgba(255,255,255,.5);
  animation: none;
  box-shadow: none !important;
}
@keyframes pin-pulse {
  0%, 100% { box-shadow: 0 0 14px var(--pin-glow, #4472FF), 0 2px 6px rgba(0,0,0,.5); }
  50%      { box-shadow: 0 0 24px var(--pin-glow, #4472FF), 0 2px 6px rgba(0,0,0,.5); }
}

/* --- Status-Dot (Sidebar + Admin-Tabelle) --- */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.status-dot.status-online {
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
  animation: dot-pulse 2s ease-in-out infinite;
}
.status-dot.status-recent  { background: #F0A030; }
.status-dot.status-offline { background: #666; }
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}

.map-wrap { position: relative; }
#map {
  width: 100%; height: 100%;
  background: var(--bg-2);
}

/* Leaflet im Dark-Mode */
.leaflet-tile { filter: brightness(.78) contrast(1.15) hue-rotate(190deg) invert(.92); }
.leaflet-control-attribution {
  background: rgba(6,12,26,.85) !important;
  color: var(--fg-mut) !important;
}
.leaflet-control-attribution a { color: var(--accent-2) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
}
.popup-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 2px 0 4px;
  font-size: 12px;
  color: var(--fg-mut);
}

/* --- Track-Page --- */
.track-wrap {
  position: relative; z-index: 1;
  padding: 20px;
  display: flex; justify-content: center;
}
.track-card {
  background: rgba(11,20,38,.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow);
}
.track-card h2 { margin-top: 0; }
.hint { color: var(--fg-mut); font-size: 13px; }
.track-actions {
  display: flex; gap: 10px;
  margin-top: 16px;
}
.track-actions button { flex: 1; }
.track-status {
  margin-top: 20px;
  padding: 14px;
  background: var(--bg-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.track-status .row {
  display: flex; justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}
.track-status .row span:first-child { color: var(--fg-mut); }
.log-details { margin-top: 16px; }
.log-details summary { cursor: pointer; color: var(--fg-mut); }
#log {
  max-height: 200px; overflow-y: auto;
  background: var(--bg);
  padding: 10px;
  border-radius: var(--radius);
  font-size: 11px;
  color: var(--fg-mut);
  white-space: pre-wrap;
}

/* --- Admin --- */
.admin-wrap {
  position: relative; z-index: 1;
  padding: 20px;
  display: grid; gap: 20px;
  max-width: 1300px; margin: 0 auto;
}
.card {
  background: rgba(11,20,38,.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.card-head h3 { margin: 0; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--fg-mut);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
td button { padding: 5px 10px; font-size: 12px; margin-right: 4px; }
.role-admin { color: var(--accent); font-weight: 600; }
.role-user  { color: var(--fg-mut); }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.65);
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
  margin: auto 0;
}
.modal-card.wide { max-width: 680px; }
.modal-card h3 { margin-top: 0; }
.modal-card h4 { margin: 18px 0 6px; color: var(--accent-2); font-size: 13px; }
.modal-card code {
  display: block;
  background: var(--bg);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 12px;
  word-break: break-all;
  color: var(--ok);
  user-select: all;
}
.modal-card code.inline {
  display: inline;
  padding: 1px 6px;
  font-size: 12px;
  border-radius: 4px;
}
.setup-list {
  margin: 6px 0 12px;
  padding-left: 20px;
  color: var(--fg);
}
.setup-list li { margin: 4px 0; font-size: 13px; }
.hint-small {
  color: var(--fg-mut);
  font-size: 12px;
  margin: 8px 0;
  line-height: 1.5;
}
.setup-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.setup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.setup-table th {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--fg-mut);
  letter-spacing: .5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  background: var(--bg-2);
}
.setup-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.setup-table tr:last-child td { border-bottom: none; }
.setup-table td:nth-child(2) {
  color: var(--ok);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600;
  white-space: nowrap;
}
.setup-table td:nth-child(3) { color: var(--fg-mut); }
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 18px;
}

/* --- Responsive --- */
@media (max-width: 720px) {
  .burger-btn { display: inline-block; }
  .topbar h2 { font-size: 16px; }
  .topbar-nav {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: rgba(6,12,26,.97);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 14px 20px;
    gap: 4px;
    display: none;
    box-shadow: 0 10px 30px rgba(0,0,0,.6);
  }
  .topbar-nav.open { display: flex; }
  .topbar-nav a {
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }
  .topbar-nav a:last-of-type { border-bottom: none; }
  .topbar-nav a.active { border-left: 3px solid var(--accent); padding-left: 10px; border-bottom: 1px solid var(--border); }
  .topbar-nav .user-badge { margin: 4px 0; align-self: flex-start; }

  .dashboard { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
    padding: 14px;
  }
  .topbar { padding: 8px 14px; }
  .dropdown-menu { right: -4px; }
  .admin-wrap { padding: 12px; }
  table { font-size: 12px; }
  th, td { padding: 6px 4px; }
}
