:root {
  --bg: #f5f7f2;
  --panel: #ffffff;
  --ink: #20251f;
  --muted: #687066;
  --line: #d9dfd2;
  --green: #236b4b;
  --orange: #d37b2d;
  --blue: #3269a8;
  --red: #b54136;
  --shadow: 0 16px 40px rgba(33, 39, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid #b7c3b1;
  background: #fff;
  color: var(--ink);
  height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

button:hover {
  border-color: var(--green);
}

button.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand {
  min-width: 260px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p,
.hint,
small {
  color: var(--muted);
}

.brand p {
  margin-top: 3px;
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.action-separator {
  width: 1px;
  align-self: stretch;
  min-height: 34px;
  background: var(--line);
  margin: 3px 4px;
}

.action-group-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.metrics div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.metrics span {
  display: block;
  font-size: 24px;
  font-weight: 750;
  line-height: 1.1;
}

small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.status-line {
  min-height: 22px;
  margin: -5px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.workbench {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
}

.controls,
.map-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.controls {
  padding: 16px;
}

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

h2 {
  font-size: 15px;
}

.controls > label,
.field-row label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  font-size: 13px;
  color: #394138;
}

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

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

input[type="range"]::-webkit-slider-thumb {
  min-width: 22px;
  min-height: 22px;
}

input[type="number"] {
  height: 38px;
  border: 1px solid #c6d0bf;
  border-radius: 8px;
  padding: 0 10px;
  width: 100%;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  color: var(--ink);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.hint {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.45;
}

.map-panel {
  position: relative;
  min-height: 560px;
  height: min(72vh, 760px);
  overflow: hidden;
}

#map {
  width: 100%;
  min-height: 560px;
  height: 100%;
  background: #dfe7d7;
  z-index: 1;
}

#map.leaflet-container {
  overflow: hidden;
  position: relative;
  outline-style: none;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  border: 0;
  width: 256px;
  height: 256px;
  max-width: none;
  max-height: none;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-zoom-animated {
  transform-origin: 0 0;
  will-change: transform;
}

.leaflet-zoom-anim .leaflet-zoom-animated {
  transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1);
}

.leaflet-pan-anim .leaflet-tile,
.leaflet-zoom-anim .leaflet-tile {
  transition: none;
}

.map-panel.map-zooming .leaflet-overlay-pane {
  opacity: 0.88;
  transition: opacity 0.14s ease;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control {
  float: left;
  clear: both;
}

.leaflet-right .leaflet-control {
  float: right;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-right .leaflet-control {
  margin-right: 10px;
}

.leaflet-control-layers {
  background: #fff;
  border: 1px solid rgba(32, 37, 31, 0.22);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(32, 37, 31, 0.18);
  color: var(--ink);
  overflow: hidden;
}

.leaflet-control-layers-toggle {
  display: grid;
  place-items: center;
  width: auto;
  min-width: 74px;
  height: 34px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}

.leaflet-control-layers-toggle::before {
  content: "Layers";
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

.leaflet-control-layers-expanded {
  padding: 8px;
}

.leaflet-control-layers-list {
  display: grid;
  gap: 4px;
  margin: 0;
}

.leaflet-control-layers:not(.leaflet-control-layers-expanded) .leaflet-control-layers-list,
.leaflet-control-layers:not(.leaflet-control-layers-expanded) .leaflet-control-layers-separator {
  display: none;
}

.leaflet-control-layers label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 145px;
  margin: 0;
  padding: 6px 8px;
  background: #fff;
  border-radius: 6px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
  text-shadow: none;
  cursor: pointer;
}

.leaflet-control-layers label:hover {
  background: #f3f6f0;
}

.leaflet-control-layers input[type="radio"],
.leaflet-control-layers input[type="checkbox"] {
  flex: 0 0 auto;
  accent-color: var(--green);
}

.leaflet-control-layers-separator {
  height: 1px;
  margin: 5px 0;
  background: var(--line);
}

.leaflet-tooltip {
  position: absolute;
  padding: 6px 9px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(17, 24, 39, 0.28);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.34);
  color: #111827;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.25;
  text-shadow: 0 1px 0 #fff;
  white-space: nowrap;
  pointer-events: none;
}

.leaflet-tooltip-top::before,
.leaflet-tooltip-bottom::before,
.leaflet-tooltip-left::before,
.leaflet-tooltip-right::before {
  position: absolute;
  pointer-events: none;
  border: 6px solid transparent;
  background: transparent;
  content: "";
}

.leaflet-tooltip-top::before {
  bottom: -12px;
  left: 50%;
  margin-left: -6px;
  border-top-color: rgba(255, 255, 255, 0.96);
}

.leaflet-tooltip-bottom::before {
  top: -12px;
  left: 50%;
  margin-left: -6px;
  border-bottom-color: rgba(255, 255, 255, 0.96);
}

.leaflet-tooltip-left::before {
  top: 50%;
  right: -12px;
  margin-top: -6px;
  border-left-color: rgba(255, 255, 255, 0.96);
}

.leaflet-tooltip-right::before {
  top: 50%;
  left: -12px;
  margin-top: -6px;
  border-right-color: rgba(255, 255, 255, 0.96);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
  z-index: 2;
}

.empty-state strong {
  font-size: 22px;
}

.empty-state span {
  max-width: 460px;
  color: var(--muted);
}

.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  z-index: 3;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 18px;
  height: 4px;
  border-radius: 2px;
  display: inline-block;
}

.legend .track {
  background: var(--blue);
}

.legend .thermal {
  background: var(--orange);
}

.legend .airspace {
  height: 10px;
  border: 2px solid #7c3aed;
  background: rgba(124, 58, 237, 0.12);
}

.legend .drift {
  background: repeating-linear-gradient(90deg, #20251f 0 5px, transparent 5px 9px);
}

.legend .hotspot {
  height: 8px;
  width: 34px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #14b8a6, #f59e0b, #dc2626);
}

.map-panel.selecting {
  cursor: crosshair;
}

.selection-rect {
  stroke: #111827;
  stroke-width: 3;
  stroke-dasharray: 8 6;
  paint-order: stroke;
  filter: drop-shadow(0 0 2px #ffffff) drop-shadow(0 0 4px rgba(255, 255, 255, 0.75));
  fill: #f8fafc;
  fill-opacity: 0.28;
}

@media (max-width: 980px) {
  .topbar,
  .workbench {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .actions {
    justify-content: flex-start;
  }

  .action-separator {
    flex-basis: 100%;
    width: 100%;
    min-height: 1px;
    height: 1px;
    margin: 2px 0;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workbench {
    display: flex;
    flex-direction: column;
  }

  .map-panel {
    order: 1;
  }

  .controls {
    order: 2;
  }

  .map-panel {
    height: 620px;
  }
}

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

  .topbar {
    gap: 10px;
    padding: 10px;
  }

  .brand {
    min-width: 0;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  h1 {
    font-size: 17px;
  }

  .brand p {
    display: none;
  }

  .actions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .action-separator {
    flex: 0 0 1px;
    width: 1px;
    height: 34px;
    min-height: 34px;
    margin: 2px 2px;
  }

  .action-group-label {
    align-self: center;
    flex: 0 0 auto;
  }

  .metrics {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    margin: 10px 0;
    scrollbar-width: thin;
  }

  .metrics div {
    flex: 0 0 132px;
    padding: 9px 10px;
  }

  .metrics span {
    font-size: 20px;
  }

  .status-line {
    margin: -2px 0 8px;
    font-size: 12px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .controls {
    padding: 12px;
  }

  .controls > label,
  .field-row label {
    margin-top: 13px;
  }

  input[type="range"] {
    min-height: 32px;
  }

  .map-panel {
    min-height: 430px;
    height: min(68vh, 560px);
  }

  #map {
    min-height: 430px;
  }

  .leaflet-control-layers {
    border-radius: 999px;
  }

  .leaflet-control-layers-toggle {
    width: auto;
    min-width: 72px;
    height: 36px;
    padding: 0 12px;
    display: grid;
    place-items: center;
    border-radius: 999px;
  }

  .leaflet-control-layers-expanded {
    position: fixed;
    left: 10px;
    right: 10px;
    top: auto;
    bottom: calc(154px + env(safe-area-inset-bottom));
    max-width: none;
    height: 235px;
    max-height: 34vh;
    padding: 10px;
    border-radius: 8px;
    overflow: auto;
    box-shadow: 0 14px 36px rgba(17, 24, 39, 0.24);
  }

  .leaflet-control-layers-expanded::before {
    content: "Map layers";
    display: block;
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
  }

  .leaflet-control-layers-expanded .leaflet-control-layers-toggle {
    display: none;
  }

  .leaflet-control-layers-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .leaflet-control-layers label {
    min-width: 0;
    padding: 8px 9px;
    font-size: 12px;
  }

  .leaflet-control-layers-separator {
    grid-column: 1 / -1;
    margin: 2px 0;
  }

  .legend {
    left: 8px;
    right: 8px;
    bottom: 8px;
    justify-content: flex-start;
    max-width: calc(100% - 16px);
  }

  .map-panel:has(.leaflet-control-layers-expanded) .legend {
    opacity: 0;
    pointer-events: none;
  }

  button {
    height: 40px;
    padding-inline: 12px;
  }
}

@media (max-width: 390px) {
  .map-panel {
    height: 62vh;
  }

  .metrics div {
    flex-basis: 118px;
  }

  button {
    padding-inline: 10px;
  }
}
