/* ======================
   ОСНОВНЫЕ СТИЛИ КАРТЫ
   ====================== */

/* Контейнер карты */
#map {
    width: 100%;
    height: 800px;
    z-index: 1;
    position: relative;
    font-family: 'Open Sans', sans-serif;
    font-size: 15px;
    line-height: 1.2;
    font-weight: 400;
    overflow: hidden;
}

.leaflet-container {

    background: #ece4d9 !important;
}

/* Скрываем стандартные элементы Leaflet */
.leaflet-control-attribution,
.leaflet-control-logo {
    display: none !important;
}

/* ======================
   МОДАЛЬНОЕ ОКНО
   ====================== */

#markerModal {
    display: none;
    position: absolute;
    top: 8px;
    right: 10px;
    background: #ece4d9;
    padding: 20px;
    border: 1px solid #ccc;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    z-index: 2600;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#markerModal h3 {
    margin-top: 0;
    color: #333;
    pointer-events: auto;
}

/* Секция просмотра */
#viewType {
    font-style: italic;
    color: #555;
    margin-bottom: 15px;
}

#viewAdditionalInfo {
    margin-bottom: 10px;
    font-size: 14px;
    color: #555;
}

#viewSection .scrollable-content {
    max-height: calc(80vh - 180px);
    overflow-y: auto;
}

#viewDescription {
    padding: 4px;
    margin-bottom: 10px;
    white-space: pre-line;
}

#viewButtons {
    display: flex;
    justify-content: flex-end;
    margin-top: 15px;
    gap: 10px;
}

/* Секция редактирования */
#editSection {
    padding: 4px;
    display: none;
    max-height: calc(80vh - 40px);
    overflow-y: auto;
}

/* ======================
   ФОРМА
   ====================== */

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: inline-block;
    max-width: 100%;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-control {
    display: block;
    width: 100%;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

.form-control:focus {
    border-color: #66afe9;
    outline: 0;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
}

textarea.form-control {
    resize: vertical;
}

/* Поля для населенных пунктов */
#settlementFields {
    display: none;
}

#settlementFields .form-group:first-child label {
    display: block;
    margin-bottom: 5px;
}

#settlementFields .checkbox-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 5px;
}

#settlementFields .checkbox-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

#settlementFields .checkbox-item input[type="checkbox"] {
    margin: 0;
}

/* ======================
   КНОПКИ
   ====================== */

.btn {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: normal;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
    text-decoration: none;
    transition: all 0.15s ease-in-out;
}

.btn:hover {
    opacity: 0.8;
}

.btn:focus {
    outline: 0;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.btn-primary {
    background-color: #a6b477;
    color: white;
    border-color: #95a366;
}

.btn-primary:hover {
    background-color: #95a366;
    border-color: #849055;
}

.btn-danger {
    background-color: #d32f2f;
    color: white;
    border-color: #c12e2a;
}

.btn-danger:hover {
    background-color: #c12e2a;
    border-color: #b02626;
}

.btn-default {
    background-color: #ece4d9;
    color: #333;
    border-color: #ddd;
}

.btn-default:hover {
    background-color: #e0d7cc;
    border-color: #ccc;
}

/* Группы кнопок */
.btn-group {
    display: flex;
    justify-content: flex-end;
    margin-top: 15px;
    gap: 10px;
}

/* ======================
   КОНТЕКСТНОЕ МЕНЮ
   ====================== */

.context-menu-popup .leaflet-popup-content-wrapper {
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.context-menu-popup .leaflet-popup-content {
    margin: 0;
    min-width: 150px;
}

.context-menu-popup .leaflet-popup-tip {
    display: none;
}

.context-menu-popup ul {
    list-style: none;
    margin: 0;
    padding: 5px;
    border-radius: 8px;
    background-color: #ece4d9;
    min-width: 150px;
}

.context-menu-popup ul li a {
    display: block;
    padding: 5px 10px;
    text-decoration: none;
    color: #333;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.context-menu-popup ul li a:hover {
    background-color: #d6cfc5;
}

.context-menu-popup ul li a.danger {
    color: #d32f2f;
}

.context-menu-popup ul li a.danger:hover {
    background-color: #ffebee;
}

/* ======================
   ИНТЕРАКТИВНЫЕ ЭЛЕМЕНТЫ
   ====================== */

.leaflet-interactive {
    pointer-events: visiblePainted !important;
}

/* Подсказки при редактировании */
.edit-tooltip {
    background-color: #e4d8c8 !important;
    color: #333 !important;
    border: none !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    padding: 8px 12px !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
}

.edit-tooltip::before {
    border-top-color: #e4d8c8 !important;
}

/* ======================
   АДАПТИВНОСТЬ
   ====================== */


input[type="checkbox"] {
    accent-color: #6d8d26;
}


@media (max-width: 480px) {
    #markerModal {
        padding: 15px;
        font-size: 14px;
    }

    .form-control {
        font-size: 16px; /* Предотвращает зум на мобильных устройствах */
    }
}

/* Стили для подписей маркеров */
.marker-label {
    background: none;
    border: none;
    box-shadow: none;
    font-weight: bold;
    font-size: 12px;
    color: #333;
    text-shadow: 1px 1px 1px white, -1px -1px 1px white, 1px -1px 1px white, -1px 1px 1px white;
    white-space: nowrap;
}

/* Стили для маркеров без иконок */
.custom-marker div {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

/* Стили для подписей полигонов */
.polygon-label span {
    font-weight: bold;
    font-size: 12px;
    color: #333;
    text-shadow: 1px 1px 1px white, -1px -1px 1px white, 1px -1px 1px white, -1px 1px 1px white;
    white-space: nowrap;
    background: none;
    border: none;
}

.custom-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.custom-modal-content {
    background-color: #ece4d9;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.custom-confirm-buttons {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
    gap: 10px;
}

.custom-confirm-buttons button {
    min-width: 80px;
}
.pm-measure-line {
    color: rgb(255, 145, 20);
    background-color: rgba(255, 204, 0, 0.2);
    cursor: crosshair !important;
}

.measure-label {
    background: white;
    border: 1px solid #666;
    color: #333;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 11px;
    text-align: center;
    white-space: nowrap;
    position: absolute;
}

.leaflet-overlay-pane svg text,
.leaflet-overlay-pane svg textPath,
.leaflet-overlay-pane svg tspan {
    pointer-events: none !important;
    user-select: none !important;
}
/* Стили для подписей */
.map-label {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    pointer-events: none !important;
    white-space: nowrap;
    font-size: 12px;
    font-weight: bold;
    top: 10px;
}

/* Для полилиний делаем подписи вдоль линии */
.leaflet-polyline-label {
    position: absolute;
    transform-origin: 0 0;
}

.leaflet-control-search .search-tip,
.leaflet-control-search.search-exp,
.leaflet-control-search .search-button ,
.leaflet-bar a {
    background-color: #ece4d9 !important;
}

/* Основные стили для фильтра */
.map-filter {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ece4d9;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 10px;
    max-width: 280px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 2600;
    font-size: 12px;
    /* Блокируем взаимодействие с картой */
    pointer-events: auto;
}

/* Предотвращаем скролл карты при взаимодействии с фильтрами */
.map-filter {
    touch-action: pan-y; /* Разрешаем только вертикальную прокрутку */
}

/* Стили для скроллбара */
.map-filter::-webkit-scrollbar {
    width: 8px;
}

.map-filter::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.map-filter::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.map-filter::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Блоки фильтров */
.filter-block {
    margin-bottom: 3px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 3px;
}

.filter-block:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.filter-title {
    padding-bottom: 5px;
    font-weight: bold;
    color: #6d8d26;
    cursor: pointer;
    display: flex;
    align-items: center;
    /* Блокируем события для карты */
    pointer-events: auto;
}

.filter-title .toggle-icon {
    margin-right: 5px;
    font-size: 10px;
    transition: transform 0.2s;
}

.filter-content {
    display: block;
    /* Блокируем события для карты */
    pointer-events: auto;
}

.filter-content.collapsed {
    display: none;
}

.filter-title.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.filter-master {
    font-weight: bold;
    margin-bottom: 8px;
}

.filter-option {
    margin-left: 15px;
    margin-bottom: 3px;
}

.filter-option label {
    font-weight: normal;
    cursor: pointer;
    display: flex;
    align-items: center;
    /* Блокируем события для карты */
    pointer-events: auto;
}

.filter-option input[type="checkbox"] {
    margin-right: 6px;
    /* Блокируем события для карты */
    pointer-events: auto;
}

/* Стили для модального окна */
#markerModal {
  touch-action: pan-y; /* Разрешаем только вертикальную прокрутку */
  -webkit-overflow-scrolling: touch; /* Для плавного скролла на iOS */
  overscroll-behavior: contain; /* Предотвращаем эффект "отскока" */
      /* Блокируем взаимодействие с картой */
    pointer-events: auto;
    touch-action: pan-y; /* Разрешаем только вертикальную прокрутку */
}

/* Для панели фильтров */
#mapFilter {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Для контента с прокруткой */
.scrollable-content, #editSection {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Все элементы внутри модального окна */
#markerModal * {
    pointer-events: auto;
}

/* Секция просмотра с прокруткой */
#viewSection .scrollable-content {
    touch-action: pan-y;
    pointer-events: auto;
}

/* Секция редактирования с прокруткой */
#editSection {
    touch-action: pan-y;
    pointer-events: auto;
}

/* Кастомные модальные окна */
.custom-modal {
    pointer-events: auto;
    touch-action: pan-y;
}

.custom-modal-content {
    pointer-events: auto;
    touch-action: pan-y;
}

.custom-modal-content * {
    pointer-events: auto;
}

/* Мобильные стили */
@media (max-width: 768px) {


  /* Основной контейнер карты */
#map {
height: calc(100vh - 60px); /* Динамическая высота */
width: 100vw;
margin-left: -10px; /* Компенсируем padding родителя */
margin-right: -10px;
}

/* Контейнеры карточки */
.paper-1.card,
.card-wrapper,
.card-body.new-article,
.desc {
padding: 0;
margin: 0;
width: 100%;
max-width: 100%;
overflow: hidden;
}

/* Фиксируем размеры модальных окон */
#markerModal,
#mapFilter {
width: calc(100% - 70px);
right: 10px;
top: 10px;
max-height: 70vh;
}

/* Улучшаем скролл контента */
.scrollable-content,
#editSection {
max-height: 60vh;
-webkit-overflow-scrolling: touch;
}

/* Оптимизация кнопок */
.btn {
padding: 12px;
min-height: 48px;
font-size: 16px;
}

/* Улучшаем форму */
.form-control {
font-size: 16px;
padding: 12px;
}

textarea.form-control {
min-height: 150px;
}

/* Убираем горизонтальный скролл */
html, body {
overflow-x: hidden;
width: 100%;
}

#map-container {
  position: relative;
  width: 100%;
  overflow: hidden;
}

/* Для очень маленьких экранов */
@media (max-width: 480px) {
  #map {
    height: calc(100vh - 120px); /* Занимает всю высоту минус заголовок и другие элементы */
    width: 100%;
  }

#markerModal,
#mapFilter {
max-height: 65vh;
padding: 15px;
}

.btn-group {
flex-direction: column;
}

.btn {
width: 100%;
margin-bottom: 8px;
}
}

/* Фикс для iOS */
@supports (-webkit-touch-callout: none) {
#map {
height: calc(100vh - 60px - env(safe-area-inset-bottom));
}
}
    #settlementFields .checkbox-group {
        flex-direction: column;
        gap: 8px;
    }

    .btn-group {
        flex-direction: column;
    }

    .map-filter {
        /* Увеличиваем отступы для лучшего взаимодействия */
        padding: 15px;
        /* Делаем немного шире на мобильных */
        max-width: 300px;
        /* Оптимизируем высоту */
        max-height: 70vh;
    }

    .filter-option {
        /* Увеличиваем отступы для лучшего тапа */
        margin-bottom: 8px;
    }

    .filter-option label {
        /* Увеличиваем область клика */
        padding: 5px 0;
        min-height: 44px; /* Минимальная высота для комфортного тапа */
        align-items: center;
    }

    .filter-option input[type="checkbox"] {
      width: 20px;
      height: 20px;
      min-width: 20px;
      min-height: 20px;
    }

    /* Мобильные стили для модального окна */
    #markerModal {
        /* Улучшаем взаимодействие на мобильных */
        padding: 20px;
        font-size: 16px; /* Предотвращаем зум */
    }

    #markerModal .form-control {
        font-size: 16px; /* Предотвращаем зум на input */
        padding: 10px;
        min-height: 44px; /* Минимальная высота для комфортного тапа */
    }

    #markerModal .btn {
        min-height: 44px; /* Минимальная высота для кнопок */
        padding: 10px 15px;
    }

    /* Увеличиваем область клика для кнопок */
    .btn {
      padding: 12px 16px;
      min-height: 44px; /* Рекомендуемый минимальный размер для touch */
    }

    /* Увеличиваем отступы в модальном окне */
    #markerModal {
      padding: 15px;
    }
}

.close-btn {
  background: none;
  border: none;
  font-size: 17px;
  font-weight: bold; /* Добавляем жирный шрифт */
  cursor: pointer;
  color: #777;
  padding: 0;
  margin-left: auto; /* Выравниваем вправо */
  display: flex; /* Для лучшего контроля выравнивания */
  align-items: center; /* Вертикальное выравнивание */
}

.close-btn:hover {
  color: #333;
}

/* Для заголовка модального окна */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%; /* Занимает всю ширину */
}

/* Для заголовка фильтра */
.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}



/* Стили для линейки */


.vertex-circle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #ff7800;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    left: 50px;
    top: 20px;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.vertex-label {
    position: absolute;
    left: 60px;
    top: 0px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 2px solid red;
    border-radius: 4px;
    padding: 2px 6px;
    color: #333;
    font-weight: bold;
    font-size: 12px;
    white-space: nowrap;
    text-shadow: 0 0 2px white;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    z-index: 999;
}

/* Стили для серединных меток (оставляем как было) */

.ruler-segment-label {
    background-color: rgba(255, 255, 255, 0.9);
    border: 2px solid #3388ff;
    border-radius: 4px;
    padding: 2px 6px;
    color: #333;
    border-color: orange;
    font-weight: bold;
    font-size: 12px;
    white-space: nowrap;
    text-shadow: 0 0 2px white;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    display: inline-block;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}


.leaflet-draw-draw-polyline:before {
    content: "\f545"; /* Иконка линейки в FontAwesome */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 16px;
    color: #333;
}
