:root {
  --bg: #05070d;
  --panel: #0b1220;
  --panel-2: #101a2d;
  --text: #d5e2ff;
  --muted: #8aa0c9;
  --accent: #22d3ee;
  --ok: #22c55e;
  --danger: #ef4444;
  --border: #1e2e4f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 20% 20%, #102241, var(--bg) 50%);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
}

.view {
  min-height: 100vh;
}

.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, #0d1930, #0a1324);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.login-card h1 {
  margin: 0 0 8px;
}

.muted {
  margin: 0;
  color: var(--muted);
}

.login-form {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.login-form input {
  width: 100%;
  background: #061024;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.login-form button,
#logoutButton {
  border: none;
  background: linear-gradient(90deg, #1ec5de, #0ea5e9);
  color: #00121d;
  font-weight: 700;
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
}

.error {
  margin: 10px 0 0;
  color: #fb7185;
  min-height: 20px;
}

.dashboard-view {
  padding: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: rgba(10, 17, 30, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  animation: slideDown 360ms ease;
}

.topbar h2 {
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.state {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.state-online {
  color: #86efac;
  border-color: #14532d;
  background: rgba(34, 197, 94, 0.15);
}

.state-offline {
  color: #fda4af;
  border-color: #7f1d1d;
  background: rgba(239, 68, 68, 0.15);
}

.layout {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 12px;
}

.panel {
  background: rgba(9, 14, 27, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.panel h3 {
  margin: 0 0 10px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.chip {
  font-size: 12px;
  color: #86efac;
  border: 1px solid #14532d;
  border-radius: 999px;
  padding: 5px 10px;
}

/* Внешняя рамка: подложка под «letterbox», контейнер для cqw/cqh. */
.world-map {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 180px);
  min-height: 520px;
  border-radius: 12px;
  background: linear-gradient(180deg, #08172f, #061126);
  border: 1px solid #203256;
  overflow: hidden;
  container-type: size;
  container-name: livemap-map;
}

/*
  Эквирректангулярная карта имеет соотношение 2:1. Если тянуть её на произвольный
  прямоугольник (100% × 100%), широта/долгота в % съезжают. Стадия всегда 2:1
  и вписывается в доступную область: min(ширина контейнера, 2 × высота).
*/
.world-map__stage {
  position: relative;
  flex-shrink: 0;
  width: min(100cqw, calc(100cqh * 2));
  aspect-ratio: 2 / 1;
  max-height: 100cqh;
  border-radius: 10px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 32%, rgba(58, 119, 197, 0.16), transparent 30%),
    radial-gradient(circle at 70% 40%, rgba(60, 160, 220, 0.12), transparent 35%),
    radial-gradient(circle at 52% 72%, rgba(19, 72, 140, 0.1), transparent 35%),
    url("https://upload.wikimedia.org/wikipedia/commons/c/c0/Equirectangular_projection_world_map_without_borders.svg"),
    linear-gradient(180deg, #08172f, #061126);
  background-size: auto, auto, auto, 100% 100%, auto;
  background-position: center center, center center, center center, center center, center center;
  background-repeat: no-repeat;
}

.grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(120, 160, 220, 0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(120, 160, 220, 0.12) 1px, transparent 1px);
  background-size: calc(100% / 12) calc(100% / 6);
}

.markers-layer {
  position: absolute;
  inset: 0;
}

.marker {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--ok);
  --marker-ring: rgba(34, 197, 94, 0.55);
  --marker-ring-outline: rgba(34, 197, 94, 0.75);
  box-shadow: 0 0 0 0 var(--marker-ring);
  transform: translate(-50%, -50%);
  animation: pulse 2.1s infinite;
}

.marker--authorized {
  background: var(--ok);
  --marker-ring: rgba(34, 197, 94, 0.55);
  --marker-ring-outline: rgba(34, 197, 94, 0.75);
}

.marker--guest {
  background: #9ca3af;
  --marker-ring: rgba(156, 163, 175, 0.5);
  --marker-ring-outline: rgba(209, 213, 219, 0.7);
}

.marker--suspicious {
  background: var(--danger);
  --marker-ring: rgba(239, 68, 68, 0.55);
  --marker-ring-outline: rgba(252, 165, 165, 0.85);
}

.marker.marker-appear {
  animation: markerPopOnce 260ms ease, pulse 2.1s infinite;
}

.marker.marker-leave {
  animation: markerFadeOut 240ms ease forwards;
}

.marker::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 1px solid var(--marker-ring-outline);
  border-radius: 999px;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 var(--marker-ring);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(0, 0, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
}

.right-column {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
}

.stat-card.stat-updated {
  animation: statValueFlash 380ms ease;
}

.stat-card .label {
  font-size: 12px;
  color: var(--muted);
}

.stat-card .value {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 700;
}

.actions-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.actions-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  max-height: calc(100vh - 350px);
  display: grid;
  gap: 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.actions-list::-webkit-scrollbar {
  display: none;
}

.action-item {
  border: 1px solid var(--border);
  background: #0c172a;
  border-radius: 10px;
  padding: 9px 10px;
  transform-origin: top center;
}

.action-item.is-new {
  animation: newEventIn 420ms cubic-bezier(0.22, 1, 0.36, 1);
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.25) inset;
}

.action-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.action-type {
  color: #a5f3fc;
}

.action-time {
  color: var(--muted);
  font-size: 12px;
}

.action-meta {
  margin-top: 6px;
  font-size: 13px;
  color: #c3d6f7;
}

.action-details-wrap {
  margin-top: 4px;
}

.action-details-wrap[hidden] {
  display: none !important;
}

@keyframes markerPopOnce {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.45);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes markerFadeOut {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.32);
  }
}

@keyframes statValueFlash {
  0% {
    border-color: var(--border);
    box-shadow: none;
  }
  35% {
    border-color: rgba(34, 211, 238, 0.45);
    box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.2) inset;
  }
  100% {
    border-color: var(--border);
    box-shadow: none;
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes newEventIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    filter: saturate(1.4);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: saturate(1);
  }
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .world-map {
    height: 60vh;
    min-height: 420px;
  }
}
