/* Polar Wohnwagen Monitor - v0.5.0 - Winterlager */
* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--surface);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header h1 { font-size: 18px; font-weight: 700; }
.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); }
.last-update { font-size: 11px; color: var(--text-dim); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Navigation */
.nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.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; }

/* Main Content */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.view { display: none; }
.view.active { display: block; }

/* 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;
}

/* Stat Items */
.stat {
  text-align: center;
}
.stat-value {
  font-size: 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); }

/* Security Items (Tür, Bewegung) */
.security-grid {
  display: flex;
  gap: 8px;
}
.security-item {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 12px;
}
.security-item.closed { border: 1px solid var(--success); }
.security-item.open { border: 1px solid var(--danger); background: rgba(239,68,68,0.1); }
.security-item.clear { border: 1px solid var(--success); }
.security-item.detected { border: 1px solid var(--warning); background: rgba(234,179,8,0.1); }
.security-icon { font-size: 16px; margin-bottom: 4px; }

/* Alarm Badge */
.alarm-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.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); }

/* Map */
#map {
  width: 100%;
  height: 300px;
  border-radius: var(--radius);
  z-index: 1;
}

/* History */
.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; }

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

/* 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;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 600px) {
  .main { max-width: 500px; margin: 0 auto; }
}

/* Auth & Admin Styles */
.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; }
.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); }

/* 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; }

/* 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;
}

/* App Shell fix */
.chat-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Stats View */
.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;
}
