:root {
  --bg: #0f1720;
  --panel: #16212c;
  --panel-2: #1c2b38;
  --border: #2a3d4d;
  --text: #e7eef4;
  --muted: #8ea3b5;
  --accent: #2fb5a3;
  --accent-2: #3d8bfd;
  --danger: #e5484d;
  --warn: #f5a524;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent-2); }

.center-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 380px;
}

.card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.card p.sub {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 14px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 14px 0 6px;
}

input[type=text], input[type=password], input[type=tel] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
input:focus { outline: 2px solid var(--accent); }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
}

.btn-primary {
  background: var(--accent);
  color: #04211d;
  width: 100%;
  margin-top: 18px;
}
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
  margin-top: 10px;
}
.btn-danger { background: var(--danger); color: white; }
.btn-warn { background: var(--warn); color: #241900; }
.btn-block { width: 100%; }

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

.tabs {
  display: flex;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 4px;
}
.tabs button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  padding: 8px;
}
.tabs button.active {
  background: var(--accent);
  color: #04211d;
}

/* ---- App shell (map/track) ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.app-header .brand {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-header .brand .dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
}
.app-header nav a, .app-header nav span {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-left: 16px;
}
.app-header nav a.active { color: var(--text); font-weight: 600; }

#map { position: absolute; top: 52px; bottom: 0; left: 0; right: 0; }

.sidebar {
  position: absolute;
  top: 62px;
  left: 10px;
  width: 280px;
  max-height: calc(100% - 80px);
  overflow-y: auto;
  background: rgba(22, 33, 44, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 500;
}
.sidebar h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 14px 4px; margin: 0; }

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.user-row:hover { background: var(--panel-2); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(229,72,77,.6); }
  70% { box-shadow: 0 0 0 10px rgba(229,72,77,0); }
  100% { box-shadow: 0 0 0 0 rgba(229,72,77,0); }
}

.user-row .meta { flex: 1; min-width: 0; }
.user-row .name { font-weight: 600; font-size: 14px; }
.user-row .sub { font-size: 12px; color: var(--muted); }

.popup-actions { margin-top: 8px; display: flex; gap: 6px; }
.popup-actions button { font-size: 13px; padding: 8px 10px; }

/* ---- Track page ---- */
.track-wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.status-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.status-card .big-dot {
  width: 64px; height: 64px; border-radius: 50%;
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.status-card .big-dot.idle { background: #23343f; }
.status-card .big-dot.active { background: rgba(47,181,163,.15); border: 2px solid var(--accent); }
.status-card .big-dot.alarm { background: rgba(229,72,77,.15); border: 2px solid var(--danger); animation: pulse 1.4s infinite; }

.status-label { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.status-detail { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; margin: 16px 0; }
.grid-2 .box { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.grid-2 .box .label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.grid-2 .box .val { font-size: 15px; font-weight: 600; margin-top: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 14px 20px;
  border-radius: 10px;
  font-weight: 600;
  z-index: 2000;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  display: none;
  max-width: 90vw;
}

/* ---- Section titles ---- */
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 26px 0 10px;
}

/* ---- Funkstatus grid (track page) ---- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.status-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.status-btn .code {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}
.status-btn .label {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}
.status-btn.active {
  border-color: var(--accent);
  background: rgba(47,181,163,.12);
}
.status-btn.active .code { color: var(--accent); }
.status-btn.sos {
  grid-column: 1 / -1;
  background: rgba(229,72,77,.1);
  border-color: var(--danger);
  flex-direction: row;
  justify-content: center;
  padding: 16px;
}
.status-btn.sos .code, .status-btn.sos .label { color: var(--danger); font-size: 16px; font-weight: 800; }
.status-btn.sos.active {
  background: var(--danger);
  animation: pulse 1.4s infinite;
}
.status-btn.sos.active .code, .status-btn.sos.active .label { color: white; }

/* ---- Mission card (track page) ---- */
.mission-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.mission-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.mission-address { color: var(--accent); font-size: 13px; margin-bottom: 6px; }
.mission-desc { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.nav-link { display: block; text-align: center; text-decoration: none; }
.mission-quick-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.mission-quick-actions button {
  flex: 1;
  min-width: 100px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 13px;
  padding: 10px 6px;
}
#missionMap {
  height: 220px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 12px;
  border: 1px solid var(--border);
}
.pin-mission { font-size: 22px; }
.pin-me {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid #0f1720;
}

/* ---- Chat ---- */
.chat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  height: 320px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
}
.chat-bubble.mine {
  align-self: flex-end;
  background: var(--accent);
  color: #04211d;
  border-bottom-right-radius: 3px;
}
.chat-bubble.theirs {
  align-self: flex-start;
  background: var(--panel-2);
  border-bottom-left-radius: 3px;
}
.chat-sender { font-size: 11px; opacity: .7; margin-bottom: 2px; font-weight: 600; }
.chat-time { font-size: 10px; opacity: .6; margin-top: 3px; text-align: right; }
.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  padding: 16px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  min-height: 50px;
}
.chat-input-row button { white-space: nowrap; padding: 12px 18px; font-size: 15px; }

/* ---- Map page: sidebar tabs & panels ---- */
.tab-panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 14px 4px; margin: 0; }

.chip {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  font-size: 12px;
}
.chip a { color: var(--danger); text-decoration: none; margin-left: 4px; }

.mission-form-panel {
  position: absolute;
  top: 62px;
  right: 10px;
  width: 300px;
  background: rgba(22, 33, 44, 0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  z-index: 600;
}
.mission-form-panel h3 { margin: 0 0 4px; font-size: 16px; }
.mission-form-panel label { margin: 10px 0 4px; }
.mission-form-panel input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}

#newMissionBtn.active { background: var(--danger); color: white; }

.notruf-banner {
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  z-index: 900;
  background: var(--danger);
  color: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  animation: pulse 1.4s infinite;
}
.notruf-banner button { padding: 6px 12px; font-size: 13px; margin-left: 8px; background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.4); }

.chat-panel {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 320px;
  height: 420px;
  background: rgba(22, 33, 44, 0.98);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 700;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.chat-panel-header button { padding: 6px 10px; font-size: 12px; }
.chat-panel .chat-messages { flex: 1; }
.chat-panel .chat-input-row input { font-size: 16px; }

@media (max-width: 640px) {
  .sidebar { width: calc(100% - 20px); }
  .mission-form-panel { width: calc(100% - 40px); right: 10px; left: 10px; }
  .chat-panel { width: calc(100% - 20px); left: 10px; right: 10px; }
}

/* ---- Unit markers (status-colored, symbol + callsign, like a real Leitstelle board) ---- */
.unit-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.unit-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid #0f1720;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.unit-icon-img { width: 100%; height: 100%; object-fit: cover; }
.unit-badge-number { font-size: 20px; font-weight: 800; line-height: 1; }
.unit-badge {
  position: absolute;
  margin-top: -14px;
  margin-left: 22px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #0f1720;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
}
.unit-label {
  margin-top: 3px;
  background: rgba(15, 23, 32, .85);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

.status-bg-1 { background: #8bc34a; }
.status-bg-2 { background: #1b5e20; }
.status-bg-3 { background: #fdd835; }
.status-bg-4 { background: #e53935; }
.status-bg-5 { background: #1e88e5; }
.status-bg-6 { background: #000000; }
.status-bg-7 { background: #673ab7; }
.status-bg-8 { background: #e1bee7; }
.status-bg-0 { animation: blink-red 1s steps(1) infinite; }
@keyframes blink-red {
  0%, 49% { background: #e53935; }
  50%, 100% { background: #7a1a17; }
}
.status-bg-9 {
  background-image: repeating-linear-gradient(45deg, #757575, #757575 5px, #9e9e9e 5px, #9e9e9e 10px);
}

.eta-box {
  margin-top: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}

.unit-popup { min-width: 220px; max-width: 260px; }
.popup-edit {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.popup-edit label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 2px;
}
.popup-edit input[type=text],
.popup-edit select,
.popup-edit input[type=file] {
  width: 100%;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
}

/* ---- Tactical symbols (events) ---- */
.tac-symbol {
  font-size: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.tac-symbol .unit-label { margin-top: 2px; }

/* ---- Event detail / form panels ---- */
#eventDetailPanel { bottom: 10px; top: auto; right: 10px; height: 480px; }
#eventDetailBody { overflow-y: auto; }
#eventDetailBody .section-title { margin: 14px 0 6px; }
#eventDetailBody .section-title:first-child { margin-top: 0; }

/* ---- Admin / Benutzerverwaltung modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 14, .7);
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}
.admin-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table input[type=text],
.admin-table select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
}

@media (max-width: 640px) {
  #eventDetailPanel { width: calc(100% - 20px); left: 10px; right: 10px; }
}

/* ---- Escalating alert overlay (track page) ---- */
.escalation-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(120, 10, 10, .95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: blink-red 1s steps(1) infinite;
}
.escalation-box {
  background: rgba(15, 23, 32, .9);
  border: 2px solid var(--danger);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.escalation-icon { font-size: 56px; margin-bottom: 10px; }
.escalation-title {
  font-size: 22px;
  font-weight: 800;
  color: white;
  letter-spacing: .03em;
  margin-bottom: 10px;
}
.escalation-from { font-size: 15px; color: #ffd3d3; margin-bottom: 6px; }
.escalation-message { font-size: 14px; color: white; margin-bottom: 24px; min-height: 20px; }
.escalation-ack-btn {
  width: 100%;
  padding: 20px;
  font-size: 19px;
  border-radius: 14px;
  letter-spacing: .03em;
}
