/* ============================================
   Argus Alarm - Clean Rewrite
   ============================================ */

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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --primary: #00D68F;
  --primary-dark: #00B377;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --offline: #6b7280;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --border: #475569;
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --primary: #00B377;
  --primary-dark: #0369a1;
  --success: #16a34a;
  --warning: #ca8a04;
  --danger: #dc2626;
  --offline: #9ca3af;
  --text: #0f172a;
  --text-dim: #475569;
  --border: #cbd5e1;
}

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(10px, 2vw, 24px);
  scrollbar-width: none;
}
.main::-webkit-scrollbar { display: none; }

.nav { flex-shrink: 0; }

/* 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: 12px 16px;
  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; }

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

.nav-btn {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.nav-btn.active { color: var(--primary); }
.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: rgba(34, 197, 94, 0.15);
  color: var(--success);
  border-bottom: 1px solid rgba(34, 197, 94, 0.3);
}

.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 8px var(--success); }
.status-dot.yellow { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.status-dot.red    { background: var(--danger);  box-shadow: 0 0 8px var(--danger); animation: pulse 1.5s infinite; }
.status-dot.offline { background: var(--offline); }

/* === CARDS === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

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

.stat-value {
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 700;
  line-height: 1;
}

.stat-label { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.stat-sub   { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.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: 2px solid var(--border);
  transition: border-color 0.3s;
}

.alarm-card.armed {
  border-color: var(--success);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(34, 197, 94, 0.05) 100%);
}

.alarm-card.alarm-triggered {
  border-color: var(--danger);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(239, 68, 68, 0.1) 100%);
  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: 12px; }
.alarm-status-icon { font-size: 36px; line-height: 1; }
.alarm-status-label { font-size: 20px; font-weight: 700; }
.alarm-armed-since { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.alarm-controls { display: flex; gap: 8px; }

.alarm-btn {
  font-size: 14px;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.alarm-btn-arm { background: var(--success); color: #fff; }
.alarm-btn-arm:hover { background: #16a34a; }
.alarm-btn-disarm { background: var(--warning); color: #000; }
.alarm-btn-disarm:hover { background: #ca8a04; }
.alarm-last-event { margin-top: 10px; 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); }

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

.sensor-dot.green  { background: var(--success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.4); }
.sensor-dot.red    { background: var(--danger);  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5); animation: pulse 1.5s infinite; }
.sensor-dot.yellow { background: var(--warning); box-shadow: 0 0 6px rgba(234, 179, 8, 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: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.sensor-row:last-child { border-bottom: none; }
.sensor-row-name { min-width: 90px; font-weight: 600; flex-shrink: 0; }
.sensor-row-status { flex: 1; }
.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 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.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 rgba(71, 85, 105, 0.3);
  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: invert(1) hue-rotate(180deg) brightness(1.3) contrast(1.1); transition: filter 0.3s; }
[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(15,23,42,0.85) 30%, rgba(15,23,42,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 rgba(71, 85, 105, 0.5);
  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 rgba(71, 85, 105, 0.5);
  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(15, 23, 42, 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: 8px;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.range-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.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: 8px; background: var(--surface-2); border-radius: 4px; 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 rgba(71, 85, 105, 0.3);
  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: 12px 8px; background: var(--surface-2); border-radius: 8px; }
.power-stat-value { font-size: 22px; font-weight: 700; color: var(--primary); }
.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: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--primary); color: white; }
.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: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  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: 12px 24px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  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 4px 16px rgba(0, 0, 0, 0.3);
}

.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); }
}
