/* Сброс стилей */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body, #map {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

/* === ОСНОВНЫЕ ЭЛЕМЕНТЫ === */

#top-panel {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7.5rem; /* ~120px при базовом font-size = 16px */
  z-index: 999;
  width: auto;
  pointer-events: none;
}

.time-block,
.time-display,
#flight-height-input {
  pointer-events: auto;
}

.time-block,
.time-display {
  background: white;
  padding: 0.5rem 1.25rem;
  border: 1px solid #ccc;
  border-radius: 0.375rem;
  box-shadow: 0 0.125rem 0.375rem rgba(0,0,0,0.3);
  font-family: Arial, sans-serif;
  font-size: 0.875rem;
  font-weight: bold;
  color: #333;
  text-align: center;
  min-width: 8.125rem; /* 130px */
  white-space: nowrap;
}

#flight-height-input {
  background: white;
  border: 1px solid #ccc;
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 0.125rem 0.375rem rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 11.25rem; /* 180px */
}

#flight-height-input label {
  font-family: Arial, sans-serif;
  font-size: 0.875rem;
  color: #333;
  font-weight: bold;
}

#flight-height-input input {
  width: 4.375rem; /* 70px */
  padding: 0.375rem;
  border: 1px solid #999;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  font-family: Arial, sans-serif;
  text-align: center;
}

/* === ПРИЦЕЛ === */

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.25rem;
  height: 1.25rem;
  margin-left: -0.625rem;
  margin-top: -0.625rem;
  pointer-events: none;
  z-index: 1000;
}

#crosshair::before,
#crosshair::after {
  content: '';
  position: absolute;
  background: red;
}

#crosshair::before {
  width: 0.125rem;
  height: 1.25rem;
  left: 0.5625rem;
  top: 0;
}

#crosshair::after {
  width: 1.25rem;
  height: 0.125rem;
  left: 0;
  top: 0.5625rem;
}

/* === КООРДИНАТЫ (НИЖНИЙ ЦЕНТР) === */

.coordinates-display {
  position: fixed;
  bottom: 0.3125rem; /* 5px */
  left: 50%;
  transform: translateX(-50%);
  z-index: 1005;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #333;
  border-radius: 0.5rem;
  padding: 0.625rem 0.9375rem;
  font-family: 'Arial', sans-serif;
  font-size: 0.875rem;
  line-height: 1.3;
  color: #333;
  box-shadow: 0 0.1875rem 0.625rem rgba(0, 0, 0, 0.3);
  text-align: center;
  backdrop-filter: blur(0.25rem);
  pointer-events: none;
  max-width: 90vw;
}

.coordinates-content {
  text-align: center;
  white-space: nowrap;
}

.coordinates-content strong {
  color: #000;
  font-size: 0.875rem;
}

/* === ПРАВЫЙ НИЖНИЙ УГОЛ === */

#right-controls {
  position: absolute;
  bottom: 0.625rem;
  right: 0.625rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.625rem;
  z-index: 1003;
}

.zone-toggle-btn,
.dropdown-btn {
  width: 2.5rem;
  height: 2.5rem;
  background: white;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 0.125rem 0.375rem rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

#extra-controls {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  bottom: 2.8125rem;
  right: 0;
  background-color: white;
  min-width: 7.5rem;
  box-shadow: 0 0.25rem 0.75rem rgba(0,0,0,0.25);
  border-radius: 0.375rem;
  z-index: 1;
  padding: 0.5rem 0;
}

.dropdown-content button {
  width: 100%;
  padding: 0.5rem 1rem;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: #333;
}

.dropdown-content button:hover {
  background-color: #f0f0f0;
}

.dropdown:hover .dropdown-content {
  display: block;
}

/* === ЛЕВЫЙ НИЖНИЙ УГОЛ === */

#left-controls {
  position: absolute;
  bottom: 0.625rem;
  left: 0.625rem;
  z-index: 1003;
}

#logout-panel {
  position: absolute;
  bottom: 0.625rem;
  left: 0.625rem;
  z-index: 1001;
  background: rgba(0, 0, 0, 0.7);
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  width: 8.75rem; /* 140px */
}

/* === ЦЕНТРАЛЬНАЯ ПАНЕЛЬ УПРАВЛЕНИЯ === */

#control-panel {
  position: absolute;
  bottom: 3.125rem; /* 50px */
  left: 50%;
  transform: translateX(-50%);
  z-index: 1004;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 95%;
}

#control-panel button {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: none;
  border-radius: 0.5rem;
  background: #fff;
  box-shadow: 0 0.1875rem 0.75rem rgba(0,0,0,0.3);
  cursor: pointer;
  font-weight: bold;
  min-width: 5rem;
  touch-action: manipulation;
}

#control-panel button:hover {
  background: #f0f0f0;
}

/* === СТИЛИ КНОПОК === */

#btn-refresh-kmz,
#btn-fly,
#btn-bla-act,
#btn-logout {
  background: #2196F3;
  color: white;
  border: none;
  padding: 0.625rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.875rem;
  text-align: center;
  transition: background 0.2s;
}

#btn-fly {
  background: #64B5F6;
}

#btn-bla-act {
  background: #4CAF50;
  position: relative;
}

#btn-refresh-kmz:hover {
  background: #1976D2;
}

#btn-fly:hover {
  background: #42A5F5;
}

#btn-logout {
  background: #d32f2f;
}

#btn-logout:hover {
  background: #b71c1c;
}

#kmz-status-small {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: #f44336;
  align-self: center;
  transition: background 0.3s;
}

#kmz-status-small.online {
  background: #4CAF50;
}

/* === МЕНЮ БЛА === */

#bla-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 100%;
  background: white;
  border: 1px solid #ccc;
  border-radius: 0.375rem;
  box-shadow: 0 -0.25rem 0.75rem rgba(0,0,0,0.25);
  z-index: 1002;
  max-height: 18.75rem; /* 300px */
  overflow-y: auto;
  display: none;
}

#bla-menu button {
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: #333;
}

#bla-menu button:hover {
  background: #f0f0f0;
}

/* === АДАПТАЦИЯ ПОД УСТРОЙСТВА === */

/* Смартфоны — вертикальная ориентация (до 767px) */
@media (max-width: 767px) {
  #top-panel {
    gap: 2.5rem; /* 40px */
    top: 0.5rem;
  }

  .time-block {
    min-width: 5.625rem; /* 90px */
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
  }

  #flight-height-input {
    min-width: 10rem; /* 160px */
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
  }

  #flight-height-input label {
    font-size: 0.8125rem;
  }

  #flight-height-input input {
    width: 3.4375rem; /* 55px */
    font-size: 0.8125rem;
  }

  #control-panel {
    bottom: 3.75rem; /* 60px */
    gap: 0.375rem;
  }

  #control-panel button {
    padding: 0.875rem 0.75rem;
    font-size: 0.875rem;
    min-width: 4.375rem;
    flex: 1;
  }

  .coordinates-display {
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
  }

  #logout-panel {
    padding: 0.5rem 0.625rem;
    width: 8.125rem; /* 130px */
  }
}

/* Смартфоны — горизонтальная ориентация (768–991px) */
@media (min-width: 768px) and (max-width: 991px) {
  #top-panel {
    gap: 5rem; /* 80px */
  }
}

/* Планшеты (992–1199px) */
@media (min-width: 992px) and (max-width: 1199px) {
  /* Можно оставить как есть или уточнить, если нужно */
}

/* Небольшие ноутбуки и десктопы (1200–1439px) */
@media (min-width: 1200px) and (max-width: 1439px) {
  /* По умолчанию уже оптимизировано под desktop */
}

/* Большие десктопы (≥1440px) */
@media (min-width: 1440px) {
  /* По умолчанию */
}

/* Очень маленькие экраны (≤480px) */
@media (max-width: 480px) {
  #top-panel {
    gap: 1.25rem; /* 20px */
    top: 0.3125rem;
  }

  .time-block {
    min-width: 5rem; /* 80px */
    padding: 0.3125rem 0.5rem;
    font-size: 0.75rem;
  }

  #flight-height-input {
    min-width: 8.75rem; /* 140px */
    padding: 0.3125rem 0.375rem;
    font-size: 0.75rem;
  }

  #flight-height-input label {
    font-size: 0.75rem;
  }

  #flight-height-input input {
    width: 3.125rem; /* 50px */
    font-size: 0.75rem;
  }

  .coordinates-display {
    bottom: 0.625rem;
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
  }

  #logout-panel {
    bottom: 3.4375rem; /* 55px */
    width: 7.5rem; /* 120px */
    padding: 0.5rem 0.625rem;
  }

  .zone-toggle-btn {
    bottom: 3.4375rem;
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.125rem;
  }

  #control-panel {
    bottom: 5.9375rem; /* 95px */
    gap: 0.375rem;
  }

  #control-panel button {
    padding: 0.75rem 0.5rem;
    font-size: 0.8125rem;
    min-width: 3.75rem;
  }

  .coordinates-content {
    white-space: normal;
  }

  .coordinates-content strong {
    font-size: 0.75rem;
  }
}

/* Очень маленькие экраны (≤375px) */
@media (max-width: 375px) {
  .coordinates-display {
    bottom: 0.9375rem;
    font-size: 0.6875rem;
    padding: 0.375rem 0.625rem;
  }

  .coordinates-content strong {
    font-size: 0.6875rem;
  }

  #logout-panel {
    bottom: 3.75rem;
    width: 6.875rem; /* 110px */
    padding: 0.4375rem 0.5625rem;
  }

  .zone-toggle-btn {
    bottom: 3.75rem;
    width: 2.125rem;
    height: 2.125rem;
    font-size: 1rem;
  }

  #control-panel {
    bottom: 6.25rem; /* 100px */
    gap: 0.3125rem;
  }

  #control-panel button {
    padding: 0.625rem 0.375rem;
    font-size: 0.75rem;
    min-width: 3.4375rem;
  }
}

/* Сенсорные устройства */
@media (hover: none) {
  #control-panel button,
  #btn-refresh-kmz,
  #btn-fly,
  #btn-logout {
    min-height: 2.75rem; /* 44px */
    padding: 0.875rem 1rem;
  }

  #logout-panel {
    width: 9.375rem; /* 150px */
  }
}

/* === ДОПОЛНИТЕЛЬНЫЕ СТИЛИ === */

.leaflet-control-attribution {
  display: none;
}

.distance-label div {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #ffff00;
  padding: 0.375rem 0.625rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: bold;
  color: #000;
  text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
  box-shadow: 0 0.125rem 0.375rem rgba(0,0,0,0.3);
}

#btn-calculate {
  display: none;
}

.leaflet-bottom .coordinates-display,
.leaflet-control-container .coordinates-display {
  display: block !important;
}

.operator-marker {
  text-align: center;
}

.operator-marker-inner {
  background: #ff0000;
  color: white;
  border: 2px solid white;
  border-radius: 50%;
  width: 1.875rem;
  height: 1.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1rem;
  box-shadow: 0 0.125rem 0.5rem rgba(0,0,0,0.4);
}

.zone-menu-container {
  position: absolute;
  bottom: 3.4375rem;
  right: 0.625rem;
  width: 13.75rem;
  background: white;
  border: 1px solid #ccc;
  border-radius: 0.375rem;
  box-shadow: 0 0.25rem 0.75rem rgba(0,0,0,0.25);
  z-index: 1000;
  padding: 0.75rem;
  display: none;
  max-height: 80vh;
  overflow-y: auto;
}

.zone-menu-container.active {
  display: block;
}

.zone-menu-container label {
  display: flex;
  align-items: center;
  margin: 0.375rem 0;
  font-family: Arial, sans-serif;
  font-size: 0.9375rem;
  color: #222;
  white-space: nowrap;
}

.zone-menu-container input[type="checkbox"] {
  margin-right: 0.625rem;
  transform: scale(1.2);
}

.editing-point {
  cursor: move;
  -webkit-tap-highlight-color: transparent;
}

.rbla-center-marker {
  text-align: center;
}

.rbla-center-marker-inner {
  background: #ff0000;
  color: white;
  border: 2px solid white;
  border-radius: 50%;
  width: 1.875rem;
  height: 1.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1rem;
  box-shadow: 0 0.125rem 0.5rem rgba(0,0,0,0.4);
  cursor: move;
  z-index: 1001;
}

.rbla-result-popup {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #333;
  border-radius: 0.5rem;
  padding: 0.9375rem;
  font-family: 'Arial', sans-serif;
  font-size: 0.875rem;
  color: #333;
  box-shadow: 0 0.1875rem 0.625rem rgba(0, 0, 0, 0.3);
  text-align: left;
  max-width: 21.875rem; /* 350px */
  margin: 0 auto;
  animation: fadeIn 0.3s ease-out;
}

.rbla-result-popup h3 {
  margin: 0 0 0.625rem 0;
  color: #000;
}

.rbla-result-popup p {
  margin: 0.3125rem 0;
}

.rbla-result-popup .popup-buttons {
  margin-top: 0.625rem;
  display: flex;
  gap: 0.5rem;
  justify-content: space-around;
}

.rbla-result-popup .popup-buttons button {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  border: none;
  border-radius: 0.25rem;
  background: #007bff;
  color: white;
  cursor: pointer;
  flex: 1;
}

.rbla-result-popup .popup-buttons button:hover {
  background: #0056b3;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(0.625rem); }
  to { opacity: 1; transform: translateY(0); }
}