:root {
  --bg: #08131b;
  --bg-2: #0c2230;
  --panel: rgba(10, 25, 36, 0.86);
  --accent: #4dd0e1;
  --accent-strong: #00bcd4;
  --text: #e6f7ff;
  --muted: #9cbfca;
  --danger: #ff6b6b;
  --ok: #47dca0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Barlow", "Segoe UI", sans-serif;
  background:
    radial-gradient(1000px 500px at 8% -10%, rgba(0, 188, 212, 0.18), transparent 58%),
    radial-gradient(700px 400px at 95% 0%, rgba(77, 208, 225, 0.15), transparent 60%),
    linear-gradient(140deg, var(--bg) 0%, var(--bg-2) 48%, #071016 100%);
  color: var(--text);
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
}

.topbar {
  background: linear-gradient(130deg, rgba(6, 25, 35, 0.92), rgba(10, 40, 56, 0.8));
  border: 1px solid rgba(77, 208, 225, 0.35);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 14px 28px rgba(1, 8, 13, 0.4);
  position: relative;
  overflow: hidden;
}

.topbar::after {
  content: "";
  position: absolute;
  right: -80px;
  top: -80px;
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(77, 208, 225, 0.22), transparent 70%);
  pointer-events: none;
}

.brand-block {
  position: relative;
  z-index: 1;
}

.brand-kicker {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 2px 0 4px;
  font-family: "Sora", "Barlow", sans-serif;
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0.08em;
  color: #ecfdff;
  text-shadow: 0 0 26px rgba(77, 208, 225, 0.35);
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  flex: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(77, 208, 225, 0.23);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(1, 9, 15, 0.35);
}

.map-panel {
  min-height: 65vh;
  height: clamp(420px, 68vh, 760px);
  max-height: 760px;
}

#map {
  height: 100%;
  width: 100%;
}

.side-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-panel h2 {
  margin: 8px 0 2px;
  font-family: "Sora", "Barlow", sans-serif;
  font-size: 0.96rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c6f3ff;
}

#devices,
#alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#alerts {
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.live-img {
  width: 100%;
  border-radius: 8px;
  margin-top: 8px;
  border: 1px solid rgba(34, 211, 238, 0.22);
  background: #06101a;
}

.device-preview {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 8px;
  margin: 8px 0;
  border: 1px solid rgba(34, 211, 238, 0.22);
  background: #06101a;
}

.live-empty {
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(6, 16, 26, 0.9);
  border: 1px dashed rgba(34, 211, 238, 0.25);
  opacity: 0.85;
}

.card {
  background: linear-gradient(160deg, rgba(8, 18, 26, 0.95), rgba(11, 28, 39, 0.9));
  border: 1px solid rgba(77, 208, 225, 0.2);
  border-radius: 10px;
  padding: 11px;
}

.card strong {
  color: #b5f4ff;
}

.btn-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  font-family: "Barlow", "Segoe UI", sans-serif;
  transition: transform 120ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button.start {
  background: var(--ok);
  color: #03121d;
}

button.stop {
  background: var(--danger);
  color: #2a0f16;
}

button.secondary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #02212b;
  box-shadow: 0 8px 16px rgba(0, 188, 212, 0.2);
  border-color: rgba(178, 247, 255, 0.35);
}

.alert-item {
  border-left: 4px solid var(--danger);
}

.alert-item.pending-review {
  border: 1px solid rgba(255, 107, 107, 0.75);
  border-left: 6px solid var(--danger);
  box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.18), 0 10px 20px rgba(90, 16, 16, 0.28);
}

.alert-item.pending-review strong {
  text-decoration: underline;
  text-decoration-color: var(--danger);
  text-decoration-thickness: 2px;
}

.motion-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.motion-indicator .motion-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.65);
  box-shadow: none;
}

.motion-indicator.active {
  color: #ffd6d6;
}

.motion-indicator.active .motion-dot {
  background: #ff3b30;
  box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.15);
}

.alert-motion {
  margin-top: 4px;
}

.motion-unavailable {
  font-size: 0.8rem;
  font-style: italic;
  color: #a9bec8;
}

.alert-popup {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 360px;
  width: calc(100% - 32px);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 107, 107, 0.75);
  background: linear-gradient(155deg, rgba(50, 10, 14, 0.96), rgba(28, 8, 10, 0.94));
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.45);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 160ms ease, opacity 160ms ease;
  z-index: 1200;
}

.alert-popup.visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.alert-popup-title {
  font-family: "Sora", "Barlow", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #ffd2d2;
}

.alert-popup-body {
  margin-top: 6px;
  color: #ffe7e7;
  font-size: 0.94rem;
  line-height: 1.35;
}

.alert-popup button {
  margin-top: 10px;
  background: rgba(255, 107, 107, 0.22);
  border-color: rgba(255, 145, 145, 0.55);
  color: #ffdede;
}

.device-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.device-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.badge.type-esp32 {
  color: #b8f7ff;
  background: rgba(0, 188, 212, 0.16);
  border-color: rgba(77, 208, 225, 0.35);
}

.badge.type-phone {
  color: #d9d0ff;
  background: rgba(129, 99, 255, 0.16);
  border-color: rgba(167, 139, 250, 0.35);
}

.badge.online {
  color: #b8ffd9;
  background: rgba(71, 220, 160, 0.14);
  border-color: rgba(71, 220, 160, 0.35);
}

.badge.offline {
  color: #ffc9c9;
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 145, 145, 0.35);
}

.pir-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.pir-indicator.active {
  color: #ffd59a;
}

.pir-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(156, 191, 202, 0.55);
}

.pir-indicator.active .pir-dot {
  background: #ffb347;
  box-shadow: 0 0 8px rgba(255, 179, 71, 0.75);
}

@media (max-width: 920px) {
  .shell {
    padding: 10px;
    gap: 10px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .map-panel {
    min-height: 45vh;
  }
}
