/* ============================================
   MFM Guard - Clean Rewrite
   ============================================ */

/* === RESET & VARIABLES === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #080c12;
  --surface: #111820;
  --surface-2: #1a2230;
  --primary: #00D68F;
  --primary-dark: #00B377;
  --primary-glow: rgba(0, 214, 143, 0.12);
  --success: #00D68F;
  --warning: #f59e0b;
  --danger: #ef4444;
  --offline: #4b5563;
  --text: #f1f5f9;
  --text-dim: #7c8ca3;
  --border: rgba(255, 255, 255, 0.06);
  --radius: 16px;
  --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #e8ecf1;
  --primary: #00B377;
  --primary-dark: #009966;
  --primary-glow: rgba(0, 179, 119, 0.08);
  --success: #00B377;
  --warning: #d97706;
  --danger: #dc2626;
  --offline: #9ca3af;
  --text: #0f172a;
  --text-dim: #64748b;
  --border: rgba(0, 0, 0, 0.08);
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* === APP SHELL (CRITICAL LAYOUT) === */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.header { flex-shrink: 0; }
#alarm-banner { flex-shrink: 0; }

.main {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: clamp(12px, 3vw, 28px);
  scrollbar-width: none;
}
.main::-webkit-scrollbar { display: none; }

.nav { flex-shrink: 0; }

/* === LAST-UPDATE-BAR (Online-Status / Letzter Kontakt) === */
.last-update-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  letter-spacing: 0.2px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.last-update-bar .lub-label {
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.6px;
}
.last-update-bar #last-update {
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
}
.last-update-bar #last-update.stale { color: var(--danger); }
.last-update-bar .lub-abs {
  color: var(--text-dim);
  font-size: 11px;
  opacity: 0.85;
}
.last-update-bar .lub-abs:not(:empty)::before { content: "("; }
.last-update-bar .lub-abs:not(:empty)::after { content: ")"; }


/* Content max-width on views, NOT on .main */
.main > .view {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* === VIEWS === */
.view { display: none; }
.view.active { display: block; }
#view-map.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* === HEADER === */
.header {
  background: var(--surface);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; }

/* === NAVIGATION === */
.nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 4px 8px;
  gap: 4px;
}

.nav-btn {
  flex: 1;
  padding: 8px 0 6px;
  background: none;
  border: none;
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.2s, background 0.2s;
}

.nav-btn.active {
  color: var(--primary);
  background: var(--primary-glow);
}
.nav-btn svg { width: 22px; height: 22px; }

/* === ALARM BANNER === */
.alarm-banner {
  text-align: center;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  animation: bannerSlide 0.3s ease-out;
}

.alarm-banner-alarm {
  background: var(--danger);
  color: #fff;
  animation: bannerPulse 2s ease-in-out infinite;
}

.alarm-banner-armed {
  background: linear-gradient(135deg, rgba(0, 214, 143, 0.18) 0%, rgba(0, 179, 119, 0.08) 100%);
  color: var(--success);
  border-bottom: 1px solid rgba(0, 214, 143, 0.2);
}

.alarm-banner-disarmed {
  background: rgba(107, 114, 128, 0.1);
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  padding: 6px 16px;
}

/* === COMMAND BANNER === */
.command-banner {
  text-align: center;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  display: none;
  animation: bannerSlide 0.3s ease-out;
}

.command-banner-pending { background: var(--primary); color: #fff; }
.command-banner-success { background: var(--success); color: #fff; }
.command-banner-expired,
.command-banner-error { background: var(--warning); color: #000; }

/* === STATUS DOT === */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--offline);
  flex-shrink: 0;
}

.status-dot.green  { background: var(--success); box-shadow: 0 0 10px rgba(0, 214, 143, 0.5); }
.status-dot.yellow { background: var(--warning); box-shadow: 0 0 10px rgba(245, 158, 11, 0.5); }
.status-dot.red    { background: var(--danger);  box-shadow: 0 0 10px rgba(239, 68, 68, 0.5); animation: pulse 1.5s infinite; }
.status-dot.offline { background: var(--offline); }

/* === CARDS === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  transition: border-color 0.2s;
}

.card-title {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  margin-bottom: 14px;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* === DASHBOARD GRID === */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  align-items: stretch;
}

.dashboard-grid > .card { margin-bottom: 0; display: flex; flex-direction: column; border: 1px solid var(--border); }
.dashboard-grid > .card:first-child { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .dashboard-grid { grid-template-columns: 1fr; align-items: start; }
  .dashboard-grid > .card:first-child { grid-column: auto; }
}

/* === STAT ITEMS === */
.stat {
  text-align: center;
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.stat-value {
  font-size: clamp(28px, 6vw, 38px);
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.stat-label { font-size: 11px; color: var(--text-dim); margin-top: 6px; font-weight: 500; }
.stat-sub   { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger  { color: var(--danger); }
.stat-value.stale   { opacity: 0.5; }

/* === ALARM CARD === */
.alarm-card {
  border: 1px solid var(--border);
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
  position: relative;
  overflow: hidden;
}

.alarm-card.armed {
  border-color: rgba(0, 214, 143, 0.25);
  background: linear-gradient(135deg, rgba(0, 214, 143, 0.12) 0%, var(--surface) 60%);
  box-shadow: 0 4px 24px rgba(0, 214, 143, 0.08), inset 0 1px 0 rgba(0, 214, 143, 0.1);
}

.alarm-card.alarm-triggered {
  border-color: rgba(239, 68, 68, 0.4);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.12) 0%, var(--surface) 60%);
  box-shadow: 0 4px 24px rgba(239, 68, 68, 0.12);
  animation: alarmCardPulse 2s ease-in-out infinite;
}

.alarm-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.alarm-status-big { display: flex; align-items: center; gap: 14px; }
.alarm-status-icon { font-size: 40px; line-height: 1; }
.alarm-status-label { font-size: 22px; font-weight: 700; letter-spacing: 0.3px; }
.alarm-armed-since { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.alarm-controls { display: flex; gap: 8px; }

.alarm-btn {
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.alarm-btn:active { transform: scale(0.97); }

.alarm-btn-arm { background: var(--success); color: #fff; box-shadow: 0 2px 12px rgba(0, 214, 143, 0.25); }
.alarm-btn-arm:hover { background: #00B377; }
.alarm-btn-disarm { background: var(--warning); color: #000; box-shadow: 0 2px 12px rgba(245, 158, 11, 0.2); }
.alarm-btn-disarm:hover { background: #d97706; }
.alarm-last-event { margin-top: 12px; font-size: 12px; color: var(--text-dim); }

/* === SENSOR OVERVIEW DOTS === */
.sensor-overview {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sensor-dot-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); font-weight: 500; }

.sensor-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sensor-dot.green  { background: var(--success); box-shadow: 0 0 8px rgba(0, 214, 143, 0.4); }
.sensor-dot.red    { background: var(--danger);  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); animation: pulse 1.5s infinite; }
.sensor-dot.yellow { background: var(--warning); box-shadow: 0 0 8px rgba(245, 158, 11, 0.4); }
.sensor-dot.gray   { background: var(--offline); }

/* === SENSOR DETAIL LIST === */
.sensor-list { display: flex; flex-direction: column; }

.sensor-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  border-radius: 10px;
  margin-bottom: 4px;
  transition: background 0.15s;
}

.sensor-row:last-child { border-bottom: none; margin-bottom: 0; }
.sensor-row-name { min-width: 90px; font-weight: 600; flex-shrink: 0; }
.sensor-row-status { flex: 1; font-weight: 500; }
.sensor-row-meta { font-size: 11px; color: var(--text-dim); text-align: right; white-space: nowrap; }

/* === SECURITY GRID (legacy sensor classes) === */
.security-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.security-item {
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface-2);
}

.security-item.closed, .security-item.clear { border-left: 3px solid var(--success); }
.security-item.open, .security-item.detected { border-left: 3px solid var(--danger); }

/* === ALARM BADGE === */
.alarm-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
}

.alarm-badge.armed { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.alarm-badge.disarmed { background: rgba(107, 114, 128, 0.15); color: var(--offline); }

/* === ALARM HISTORY === */
.alarm-history-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 214, 143, 0.2);
}

.alarm-history-table { max-height: 400px; overflow-y: auto; }
.alarm-history-loading { color: var(--text-dim); font-size: 13px; padding: 16px 0; text-align: center; }

.ah-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.ah-row:last-child { border-bottom: none; }
.ah-row-alarm   { background: rgba(239, 68, 68, 0.08); border-radius: 6px; padding: 8px 6px; margin: 2px -6px; }
.ah-row-system  { background: rgba(34, 197, 94, 0.05); border-radius: 6px; padding: 8px 6px; margin: 2px -6px; }
.ah-row-warning { background: rgba(234, 179, 8, 0.06); border-radius: 6px; padding: 8px 6px; margin: 2px -6px; }
.ah-icon { font-size: 16px; flex-shrink: 0; width: 24px; text-align: center; }
.ah-detail { flex: 1; min-width: 0; }
.ah-sensor { font-weight: 600; color: var(--text); }
.ah-text { color: var(--text-dim); font-size: 11px; }
.ah-time { font-size: 11px; color: var(--text-dim); white-space: nowrap; flex-shrink: 0; }

/* === WEATHER CARD === */
#weather-card { padding: 0 !important; overflow: hidden; position: relative; }

.weather-bg {
  padding: 20px;
  background-size: cover;
  background-position: center;
  min-height: 120px;
  position: relative;
  flex: 1;
}

.weather-bg-clear   { background: linear-gradient(135deg, #00B377 0%, #00D68F 50%, #7dfcc8 100%); }
.weather-bg-cloudy  { background: linear-gradient(135deg, #334155 0%, #64748b 50%, #94a3b8 100%); }
.weather-bg-rain    { background: linear-gradient(135deg, #1e293b 0%, #334155 40%, #475569 100%); }
.weather-bg-snow    { background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 50%, #94a3b8 100%); color: #1e293b; }
.weather-bg-fog     { background: linear-gradient(135deg, #475569 0%, #94a3b8 50%, #cbd5e1 100%); }
.weather-bg-thunder { background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%); }
.weather-bg-night   { background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 40%, #312e81 100%); }

.weather-bg .weather-main { display: flex; align-items: center; gap: 16px; }
.weather-bg .weather-icon { font-size: 48px; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }
.weather-bg .weather-temp { font-size: 36px; font-weight: 700; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); }
.weather-bg .weather-desc { font-size: 14px; opacity: 0.9; }
.weather-bg .weather-detail { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.weather-bg .weather-station { font-size: 10px; opacity: 0.5; margin-top: 2px; }

.weather-forecast-bar {
  display: flex;
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.weather-forecast-bar::-webkit-scrollbar { display: none; }

.weather-forecast-item {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 8px 4px;
  border-right: 1px solid var(--border);
  font-size: 11px;
}

.weather-forecast-item:last-child { border-right: none; }
.weather-forecast-day { color: var(--text-dim); font-size: 10px; }
.weather-forecast-icon { font-size: 16px; margin: 2px 0; }
.weather-forecast-temps { font-weight: 600; font-size: 12px; }
.weather-forecast-sun { font-size: 9px; color: var(--warning); }

.weather-solar-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface);
  font-size: 11px;
  color: var(--warning);
}

/* === MAP === */
.map-container {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
}

#map {
  width: 100%;
  flex: 1;
  min-height: 300px;
  z-index: 1;
}

#map .leaflet-tile-pane { filter: none; }   /* dark_all/voyager sind schon themengerecht — invert machte dunkle Kacheln WEISS */
[data-theme="light"] #map .leaflet-tile-pane { filter: none; }
[data-theme="light"] .leaflet-tile { filter: none !important; }
.leaflet-container { background: var(--bg); }

/* === GPS MINI-MAP (Dashboard) === */
#gps-card { min-height: 0; display: flex; flex-direction: column; }
#gps-card > div:last-child { flex: 1; min-height: 150px; }
#mini-map { height: 100% !important; min-height: 150px; display: block !important; }

/* === MAP TIMELINE CONTROLS === */
.map-overlay-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(transparent 0%, rgba(8,12,18,0.85) 30%, rgba(8,12,18,0.95) 100%);
  padding: 32px 16px 12px;
  pointer-events: none;
}
.map-overlay-controls > * { pointer-events: all; }

/* Timeline: Zeitfenster Start/Ende */
.map-timeline { margin-bottom: 8px; }
.map-timeline-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.map-timeline-date {
  font-size: 11px;
  color: rgba(241,245,249,0.7);
  white-space: pre-line;
  line-height: 1.3;
  min-width: 70px;
}
.map-timeline-date:last-child { text-align: right; }
.map-timeline-sliders {
  position: relative;
  height: 24px;
}
.map-timeline-sliders input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 24px;
  accent-color: var(--primary);
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.map-timeline-sliders input[type="range"]::-webkit-slider-thumb {
  pointer-events: all;
  -webkit-appearance: none;
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  cursor: grab;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.map-timeline-sliders input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

/* Playback: Play + Position + Speed */
.map-playback {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.map-pos-slider {
  flex: 1;
  accent-color: var(--primary);
  height: 20px;
}
.map-playback-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: rgba(241,245,249,0.8);
}
.map-overlay-info { font-size: 11px; color: rgba(241,245,249,0.6); }
.map-overlay-coords { font-size: 11px; color: rgba(241,245,249,0.5); }

.map-speed-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

.map-no-data {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  background: var(--bg);
  padding: 16px 24px;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 13px;
}

.map-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

.map-play-btn:hover,
.map-play-btn.playing { background: var(--primary); border-color: var(--primary); }

/* === CHASE MODE === */
.chase-start-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.chase-start-btn:active { transform: scale(0.95); }
.chase-start-alarm { background: var(--danger); color: #fff; animation: chaseAlarmPulse 1.5s ease-in-out infinite; }
.chase-start-manual { background: var(--surface-2); color: var(--text-dim); font-size: 12px; padding: 8px 12px; font-weight: 600; opacity: 0.8; }
.chase-start-manual:hover { opacity: 1; color: var(--text); }

.chase-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(transparent, rgba(8, 12, 18, 0.95) 30%);
  padding: 40px 16px 12px;
  pointer-events: none;
}

.chase-overlay > * { pointer-events: all; }
.chase-info { display: flex; gap: 16px; justify-content: center; align-items: flex-end; margin-bottom: 12px; }
.chase-stat { text-align: center; flex: 1; max-width: 120px; }
.chase-distance { font-size: 28px; font-weight: 700; color: var(--danger); line-height: 1.1; }
.chase-speed { font-size: 20px; font-weight: 600; color: var(--warning); }
.chase-time { font-size: 18px; font-weight: 600; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.chase-label { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.chase-arrow-wrap { margin-bottom: 4px; }
.chase-arrow { display: inline-block; font-size: 22px; color: var(--danger); transition: transform 0.3s ease; line-height: 1; }

.chase-actions { display: flex; gap: 8px; justify-content: center; }

.chase-action-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chase-action-btn:hover { background: var(--surface-2); color: var(--text); }
.chase-action-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chase-action-stop { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.4); color: var(--danger); }
.chase-action-stop:hover { background: var(--danger); color: #fff; }
.chase-action-gmaps { background: rgba(34, 197, 94, 0.15); border-color: rgba(34, 197, 94, 0.3); color: var(--success); }
.chase-action-gmaps:hover { background: var(--success); color: #fff; }

/* Chase map markers */
.chase-dot { position: relative; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 8px rgba(0, 0, 0, 0.4); }
.chase-dot-me { width: 16px; height: 16px; background: #3b82f6; }
.chase-dot-target { width: 22px; height: 22px; background: #ef4444; }

.chase-dot-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  animation: chasePulse 2s ease-out infinite;
}

.chase-dot-pulse-blue { width: 40px; height: 40px; border: 2px solid rgba(59, 130, 246, 0.5); background: rgba(59, 130, 246, 0.15); }
.chase-dot-pulse-red { width: 50px; height: 50px; border: 2px solid rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.15); }

/* === STATS === */
.stats-range { display: flex; gap: 6px; margin-bottom: 12px; }

.range-btn {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.range-btn.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 2px 8px rgba(0, 214, 143, 0.2); }

.stats-toggles { display: flex; flex-wrap: wrap; gap: 8px; }

.stats-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface-2);
}

.stats-toggle input { width: 14px; height: 14px; accent-color: var(--primary); }
.stats-toggle .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* === SYSTEM TAB === */
.sys-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sys-label { font-size: 11px; color: var(--text-dim); margin-bottom: 2px; }
.sys-value { font-size: 16px; font-weight: 600; }
.sys-value.success { color: var(--success); }
.sys-value.warning { color: var(--warning); }
.sys-value.danger { color: var(--danger); }

.sys-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.sys-bar-sm { height: 6px; width: 60px; display: inline-block; vertical-align: middle; }
.sys-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.sys-bar-label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }

.bar-green  { background: var(--success); }
.bar-yellow { background: var(--warning); }
.bar-red    { background: var(--danger); }

/* Services */
.svc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.svc-row:last-child { border-bottom: none; }
.svc-name { font-weight: 500; }
.svc-status { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 12px; }

/* ZigBee table */
.zb-table { overflow-x: auto; }

.zb-header {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.zb-row {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  align-items: center;
}

.zb-row:last-child { border-bottom: none; }
.zb-row-alt { background: rgba(30, 41, 59, 0.5); }
.zb-row-warning { border-left: 3px solid var(--warning); padding-left: 5px; }
.zb-row-offline { border-left: 3px solid var(--danger); padding-left: 5px; opacity: 0.6; }

.zb-col-name  { flex: 2; min-width: 80px; font-weight: 500; }
.zb-col-model { flex: 2; min-width: 70px; color: var(--text-dim); }
.zb-col-bat   { flex: 2; min-width: 90px; display: flex; align-items: center; gap: 4px; }
.zb-col-sig   { flex: 2; min-width: 80px; display: flex; align-items: center; gap: 4px; }
.zb-col-seen  { flex: 1.5; min-width: 60px; color: var(--text-dim); font-size: 11px; }
.zb-val { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

/* USB */
.usb-item { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.usb-item:last-child { border-bottom: none; }

/* === POWER ESTIMATION === */
.power-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }

.power-stat { text-align: center; padding: 14px 8px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); }
.power-stat-value { font-size: 22px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.power-stat-label { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.power-bar-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12px; }
.power-bar-name { min-width: 120px; color: var(--text-dim); }
.power-bar-wrap { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.power-bar-fill { height: 100%; border-radius: 4px; background: var(--primary); transition: width 0.3s; }
.power-bar-val { min-width: 50px; text-align: right; font-size: 11px; color: var(--text-dim); }

.power-estimates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.power-est-item { text-align: center; padding: 8px; background: var(--surface-2); border-radius: 6px; font-size: 12px; color: var(--text-dim); }
.power-toggles .setting-row { padding: 8px 0; }

/* === DUAL RANGE SLIDER === */
.dual-slider { position: relative; height: 30px; }

.dual-slider input[type="range"] {
  position: absolute;
  width: 100%;
  top: 0;
  height: 30px;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  margin: 0;
  padding: 0;
}

.dual-slider input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--surface-2); border-radius: 2px; }
.dual-slider input[type="range"]:last-child::-webkit-slider-runnable-track { background: transparent; }

.dual-slider input[type="range"]::-webkit-slider-thumb {
  pointer-events: all;
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  margin-top: -7px;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(14, 165, 233, 0.5);
}

.dual-slider input[type="range"]::-moz-range-track { height: 4px; background: var(--surface-2); border-radius: 2px; border: none; }
.dual-slider input[type="range"]:last-child::-moz-range-track { background: transparent; }

.dual-slider input[type="range"]::-moz-range-thumb {
  pointer-events: all;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(14, 165, 233, 0.5);
}

.dual-slider-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.dual-slider-labels span { line-height: 1.3; white-space: pre-line; }

/* === SETTINGS === */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border-radius: 24px;
  transition: 0.3s;
}

.toggle-slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); background: #fff; }

/* === BUTTONS === */
.btn { padding: 10px 20px; border: none; border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s, transform 0.1s; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 10px rgba(0, 214, 143, 0.2); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
}

.btn-logout:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); border-color: var(--danger); }

/* === AUTH & LOGIN === */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 20px;
}

.auth-box {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  padding: 32px;
  width: 380px;
  max-width: 95vw;
}

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text-dim); }

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
}

.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }

.error-msg {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* === ACCOUNT INFO === */
.account-info { display: flex; flex-direction: column; }

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.account-row:last-child { border-bottom: none; }
.account-label { color: var(--text-dim); font-size: 12px; min-width: 90px; flex-shrink: 0; }
.account-value { font-weight: 500; text-align: right; }

/* === ROLE & PERMISSION BADGES === */
.role-badge { display: inline-block; font-size: 11px; font-weight: 600; color: #fff; padding: 2px 10px; border-radius: 10px; background: var(--offline); }
.role-description { font-size: 11px; color: var(--text-dim); margin-top: 4px; font-style: italic; }

.perm-badge { display: inline-block; font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 8px; margin-right: 4px; }
.perm-yes { background: rgba(34, 197, 94, 0.15); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.3); }
.perm-no { background: rgba(107, 114, 128, 0.15); color: var(--offline); border: 1px solid rgba(107, 114, 128, 0.3); text-decoration: line-through; }

/* === USER CARDS (ADMIN) === */
.user-card { padding: 14px; }
.user-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.user-card-info { flex: 1; min-width: 0; }
.user-card-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-card-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.user-card-perms { margin-top: 6px; }
.user-card-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }

/* === EVENT LIST === */
.event-list { list-style: none; }

.event-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.event-item:last-child { border-bottom: none; }
.event-time { color: var(--text-dim); font-size: 11px; }

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  z-index: 9999;
  color: #fff;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
}

.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* === LOADING === */
.loading { text-align: center; padding: 40px; color: var(--text-dim); }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

/* === STALE INDICATOR === */
.stale-indicator { display: inline-block; font-size: 9px; color: var(--warning); vertical-align: super; margin-left: 2px; }

/* === ANIMATIONS === */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

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

@keyframes bannerSlide {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes bannerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; background: #dc2626; }
}

@keyframes alarmCardPulse {
  0%, 100% { border-color: var(--danger); }
  50% { border-color: rgba(239, 68, 68, 0.4); }
}

@keyframes chasePulse {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

@keyframes chaseAlarmPulse {
  0%, 100% { box-shadow: 0 2px 12px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 2px 24px rgba(239, 68, 68, 0.8); }
}

/* === Admin Panel === */
.admin-tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 0; -webkit-overflow-scrolling: touch; }
.admin-tab { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; color: var(--text-dim); font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap; font-family: inherit; }
.admin-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.admin-content { min-height: 200px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.admin-stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; text-align: center; }
.admin-stat-icon { font-size: 20px; margin-bottom: 4px; }
.admin-stat-value { font-size: 22px; font-weight: 700; color: var(--text); }
.admin-stat-label { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th { text-align: left; padding: 8px 10px; color: var(--text-dim); font-weight: 500; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:hover { background: rgba(255,255,255,.02); }
.admin-table code { font-size: 11px; background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; color: #fff; text-transform: uppercase; letter-spacing: .03em; }
.badge-green { background: var(--primary); }
.badge-dim { background: var(--text-dim); }
.btn-sm-admin { background: var(--card-bg); border: 1px solid var(--border); color: var(--text-dim); padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; font-family: inherit; }
.btn-sm-admin:hover { border-color: var(--primary); color: var(--primary); }

/* ========== DESKTOP LAYOUT (>= 900px): Bottom-Nav bleibt, Content breiter ========== */
/* User-Praeferenz: klassische Bottom-Navigation auch auf grossen Screens (wie in der App).
   Kein Side-Nav mehr. Dashboard-Grid darf aber mehrere Spalten nutzen. */
@media (min-width: 900px) {
  .main > .view { max-width: 1400px; }
  .view-dashboard .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
  }
  .view-dashboard .card.full-width { grid-column: 1 / -1; }
  .view-dashboard .weather-card { grid-column: 1 / -1; }
  /* Bottom-Nav auf Desktop zentrieren + etwas breiter */
  .nav { padding: 6px 12px; }
  .nav-btn { padding: 10px 0 8px; font-size: 11px; }
  .nav-btn svg { width: 22px; height: 22px; }
}

/* === DASHBOARD 2.0 (2026-08-21) === */
.dashboard-grid > .span-2 { grid-column: span 2; }
@media (max-width: 560px) { .dashboard-grid > .span-2 { grid-column: auto; } }

.chip { font-size: 11px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.chip.on  { background: rgba(0, 214, 143, 0.14); color: var(--success); }
.chip.off { background: rgba(239, 68, 68, 0.12); color: var(--danger); }

.basic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; }
.basic-tile { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); min-width: 0; }
.basic-tile[data-trend] { cursor: pointer; }
.basic-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); font-weight: 600; }
.basic-val { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.basic-val.klein { font-size: 15px; line-height: 1.25; white-space: normal; }
.basic-sub { font-size: 11px; color: var(--text-dim); }

.sensor-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 9px; }
/* Kennzahlen ueber den Diagrammen — gleiche Sprache wie die Geraetekacheln. */
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 14px; }
.kpi { background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
       padding: 9px 11px; display: flex; flex-direction: column; gap: 2px; }
.kpi-l { font-size: 10px; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-dim); }
.kpi-v { font-size: 16px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }

.sensor-group { grid-column: 1 / -1; font-size: 12px; font-weight: 700; letter-spacing: 0.2px; color: var(--text); padding: 12px 2px 4px; display: flex; align-items: center; gap: 6px; }
.sensor-group:first-child { padding-top: 0; }
.sensor-tile { position: relative; display: flex; flex-direction: column; gap: 3px; padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid transparent; min-height: 98px; min-width: 0; transition: border-color 0.15s, transform 0.1s, background 0.2s; }
.sensor-tile.clickable { cursor: pointer; }
.sensor-tile.clickable:hover { border-color: var(--border); }
.sensor-tile.clickable:active { transform: scale(0.98); }
.sensor-tile.alert { border-color: rgba(239, 68, 68, 0.55); background: rgba(239, 68, 68, 0.09); }
.sensor-tile.warn  { border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.08); }
.sensor-tile.stale { opacity: 0.55; }
.sensor-tile-head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text); min-width: 0; }
.sensor-tile-head .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sensor-tile-val { font-size: 24px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.sensor-tile-val.txt { font-size: 17px; }
.sensor-tile-sub { font-size: 11px; color: var(--text-dim); }
.sensor-tile-meta { margin-top: auto; display: flex; gap: 8px; font-size: 10px; color: var(--text-dim); flex-wrap: wrap; padding-top: 4px; }
.sensor-badge { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--danger); color: #fff; }
.sensor-empty { grid-column: 1 / -1; color: var(--text-dim); font-size: 12px; padding: 8px 0; }

.dash-events { display: flex; flex-direction: column; }
.dash-event { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.dash-event:last-child { border-bottom: none; }
.dash-event .ico { width: 18px; text-align: center; flex-shrink: 0; }
.dash-event .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dash-event .when { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.dash-event.crit .txt { color: var(--danger); font-weight: 600; }
.dash-event.warn .txt { color: var(--warning); }
