:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07111f;
  color: #edf6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 15%, rgba(33, 148, 188, 0.18), transparent 25rem),
    linear-gradient(145deg, #07111f 0%, #0a1a2d 60%, #09101c 100%);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto minmax(420px, 1fr);
  gap: 14px;
  padding: 20px;
}

.topbar,
.controls,
.metrics,
.map-wrap {
  border: 1px solid rgba(163, 205, 226, 0.13);
  background: rgba(10, 26, 45, 0.82);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 14px 20px;
  border-radius: 18px;
}

.eyebrow {
  margin: 0 0 3px;
  color: #76d5ef;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  letter-spacing: -0.035em;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 112px;
  justify-content: flex-end;
  color: #bed1df;
  font-size: 0.86rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #86a0b2;
  box-shadow: 0 0 0 4px rgba(134, 160, 178, 0.09);
}

.status[data-state="busy"] .status-dot {
  background: #f6c55c;
  animation: pulse 1s infinite;
}

.status[data-state="ok"] .status-dot {
  background: #58dda1;
  box-shadow: 0 0 12px rgba(88, 221, 161, 0.65);
}

.status[data-state="error"] .status-dot {
  background: #ff7e79;
  box-shadow: 0 0 12px rgba(255, 126, 121, 0.55);
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

.controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  border-radius: 14px;
  padding: 12px;
}

.controls label,
dialog label {
  display: grid;
  gap: 6px;
  color: #9fb5c7;
  font-size: 0.78rem;
  font-weight: 700;
}

select,
input,
button {
  min-height: 40px;
  border-radius: 9px;
  border: 1px solid rgba(169, 209, 229, 0.18);
  background: #0d2033;
  color: #edf6ff;
  padding: 0 11px;
  font: inherit;
}

select {
  min-width: 180px;
}

button {
  cursor: pointer;
  border-color: rgba(78, 206, 229, 0.5);
  background: linear-gradient(135deg, #168daa, #21b6aa);
  color: white;
  font-weight: 800;
}

button.secondary {
  border-color: rgba(169, 209, 229, 0.18);
  background: #12283d;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-radius: 14px;
  overflow: hidden;
}

.metrics article {
  display: grid;
  gap: 4px;
  padding: 12px 16px;
  border-right: 1px solid rgba(163, 205, 226, 0.13);
}

.metrics article:last-child {
  border-right: 0;
}

.metrics span {
  color: #91aabd;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metrics strong {
  font-size: 1.08rem;
}

.map-wrap {
  position: relative;
  min-height: 440px;
  border-radius: 18px;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: #091524;
}

.leaflet-control-zoom a,
.leaflet-control-attribution {
  background: rgba(8, 21, 35, 0.92) !important;
  color: #dceafa !important;
  border-color: rgba(169, 209, 229, 0.14) !important;
}

.leaflet-control-attribution a {
  color: #76d5ef !important;
}

.legend {
  position: absolute;
  z-index: 500;
  right: 16px;
  bottom: 24px;
  width: 180px;
  padding: 10px 12px;
  border: 1px solid rgba(169, 209, 229, 0.15);
  border-radius: 10px;
  background: rgba(7, 17, 31, 0.88);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.26);
}

.legend strong {
  display: block;
  margin-bottom: 7px;
  font-size: 0.76rem;
}

.legend-scale {
  height: 8px;
  border-radius: 99px;
  background: linear-gradient(90deg, #49a7ff, #3df0b2, #f6d34a, #ff8a4c, #ff3f63);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: #9fb5c7;
  font-size: 0.68rem;
}

dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid rgba(169, 209, 229, 0.18);
  border-radius: 16px;
  background: #0b1a2b;
  color: #edf6ff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

dialog::backdrop {
  background: rgba(2, 8, 15, 0.74);
  backdrop-filter: blur(5px);
}

dialog form {
  display: grid;
  gap: 14px;
}

dialog h2,
dialog p {
  margin: 0;
}

dialog form > p {
  color: #9fb5c7;
  font-size: 0.86rem;
}

dialog input {
  width: 100%;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.form-error {
  min-height: 18px;
  color: #ff9b97 !important;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .controls label {
    min-width: 0;
  }

  select {
    min-width: 0;
    width: 100%;
  }

  .controls button {
    width: 100%;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .metrics article {
    border-right: 0;
    border-bottom: 1px solid rgba(163, 205, 226, 0.13);
  }

  .metrics article:last-child {
    border-bottom: 0;
  }
}
