* { box-sizing: border-box; font-family: system-ui, sans-serif; }
body { margin: 0; height: 100vh; display: flex; flex-direction: column; }

header {
  padding: 10px 16px; background: #1e2937; color: white;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
header h1 { font-size: 18px; margin: 0; margin-right: 8px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { flex: 0 0 auto; display: block; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.controls label { display: flex; align-items: center; gap: 4px; }
.controls input[type=number] { width: 52px; }
.sep { opacity: 0.4; }
select, input[type=datetime-local], input[type=number] {
  font-size: 12px; padding: 3px 5px; border-radius: 3px; border: 1px solid #4b5563;
}
button {
  background: #3b82f6; color: white; border: none; padding: 6px 12px;
  border-radius: 4px; cursor: pointer; font-size: 13px;
}
button:hover { background: #2563eb; }
#status { font-size: 12px; opacity: 0.85; }

#sidebar { max-height: 38vh; overflow-y: auto; border-top: 1px solid #ddd; background: #fafafa; padding: 8px 12px; }

.hint { font-size: 11px; color: #6b7280; margin: 2px 0 8px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 4px 8px; border-bottom: 1px solid #eee; }
th { background: #f3f4f6; font-weight: 600; }
tr.presence { background: #fffbeb; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
button.mini { padding: 2px 8px; font-size: 11px; }
button.mini.danger { background: #dc2626; color: #fff; }
button.mini.danger:hover { background: #b91c1c; }
small { color: #6b7280; }

/* ---- Sensor-Status-Karten ---- */
#healthCards { display: flex; flex-wrap: wrap; gap: 10px; }
.hcard {
  border: 1px solid #e5e7eb; border-radius: 6px; background: white;
  padding: 10px 12px; min-width: 280px; flex: 1 1 300px;
}
.hcard.stale { border-color: #fca5a5; background: #fef2f2; }
.hcard-head { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; font-size: 13px; }

.badge { font-size: 10px; padding: 2px 7px; border-radius: 10px; font-weight: 600; }
.badge.ok   { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad  { background: #fee2e2; color: #991b1b; }

.hgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 12px; }
.hgrid > div { display: flex; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid #f3f4f6; padding: 2px 0; }
.hlabel { color: #6b7280; }
.warn-text { color: #b45309; font-weight: 600; }
.bad-text  { color: #b91c1c; font-weight: 700; }
.hwarn { margin-top: 8px; font-size: 11px; color: #b91c1c;
  background: #fef2f2; padding: 5px 7px; border-radius: 4px; }


/* ---- Navigation ---- */
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.navlink {
  background: transparent; color: #cbd5e1; border: none;
  padding: 7px 14px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.navlink:hover { background: rgba(255, 255, 255, 0.1); }
.navlink.active { background: #3b82f6; color: white; }

.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; }

.demo-btn { background: #9333ea; }
.demo-btn:hover { background: #7e22ce; }
.demo-btn:disabled { background: #a78bfa; cursor: default; }

/* ---- Ansichten (Live-Karte / Historische Daten / Admin) ---- */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; overflow-y: auto; }
.view .controls { padding: 8px 16px; background: #f3f4f6; border-bottom: 1px solid #e5e7eb; }

#view-history, #view-sensors, #view-admin { padding: 12px 16px; }

#mapWrap { position: relative; flex: 1; min-height: 240px; }
#mapWrap #map { position: absolute; inset: 0; }

/* ---- Alarm-Rahmen bei neuer Drohnen-Identität ---- */
#alertFrame {
  position: absolute; inset: 0; pointer-events: none;
  box-sizing: border-box; z-index: 500;
}
#alertFrame.blink { animation: alertBlink 1s step-start infinite; }
@keyframes alertBlink {
  0%, 49%  { border: 8px solid #dc2626; box-shadow: inset 0 0 40px rgba(220, 38, 38, 0.5); }
  50%, 100% { border: 8px solid transparent; box-shadow: none; }
}

/* ---- Widgets oben rechts auf der Live-Karte (Drohnenzähler, Sensor-Ampel) ---- */
#topRightWidgets {
  position: absolute; top: 10px; right: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.corner-widget {
  background: rgba(255, 255, 255, 0.92); border-radius: 6px; padding: 6px 10px;
  font-size: 11px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

#droneCountWidget { text-align: center; min-width: 100px; }
#droneCountRange {
  width: 100%; font-size: 10px; padding: 2px 4px; margin-bottom: 4px;
  border-radius: 3px; border: 1px solid #d1d5db;
}
.drone-count-num { font-size: 22px; font-weight: 700; color: #1e2937; line-height: 1.1; }
.drone-count-label { font-size: 10px; color: #6b7280; }

.sl-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; white-space: nowrap; }
.sl-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.sl-on  { background: #16a34a; box-shadow: 0 0 4px #16a34a; }
.sl-off { background: #dc2626; box-shadow: 0 0 4px #dc2626; }

/* ---- Admin-Bereich ---- */
.admin-tabs { display: flex; gap: 4px; padding-bottom: 10px; }
.admintab { background: #e5e7eb; color: #374151; border-radius: 4px; padding: 6px 14px; font-size: 12px; }
.admintab.active { background: #1e2937; color: white; }
.admintabpane { display: none; }
.admintabpane.active { display: block; }

.stat-tiles { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-tile {
  background: white; border: 1px solid #e5e7eb; border-radius: 6px;
  padding: 12px 20px; min-width: 120px; text-align: center;
}
.stat-num { font-size: 24px; font-weight: 700; color: #1e2937; }
.stat-label { font-size: 11px; color: #6b7280; margin-top: 2px; }

.inline-form { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.inline-form input, .inline-form select {
  font-size: 12px; padding: 5px 8px; border-radius: 4px; border: 1px solid #d1d5db;
}

.admin-subheading { font-size: 15px; margin: 22px 0 4px; }
.sensor-access-picker { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.sensor-access-picker label { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.sensor-access-row { background: #f9fafb; border-radius: 4px; padding: 8px; margin: -4px 0 8px; }
.sensor-access-row .inline-form { margin-bottom: 6px; }
#sensorLocationTable input { font-size: 12px; padding: 4px 6px; width: 110px;
  border-radius: 4px; border: 1px solid #d1d5db; }
#sensorLocationTable .loc-id { width: 140px; }
.user-actions { display: flex; gap: 6px; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }

/* ---- Login-Seite ---- */
.login-body { justify-content: center; align-items: center; background: #f3f4f6; }
.login-box {
  background: white; padding: 28px 32px; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  display: flex; flex-direction: column; gap: 12px; min-width: 280px;
}
.login-box h1 { font-size: 18px; margin: 0 0 8px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-box input { font-size: 14px; padding: 8px 10px; border-radius: 4px; border: 1px solid #d1d5db; }
.login-box button { margin-top: 4px; }
