/* Подключить после leaflet.css и общих стилей сайта.
   Попапы определяются по .marker-collected или .marker-form внутри.
   Также поддерживается явный className: 'marker-popup' в bindPopup(). */

.marker-form,
.leaflet-popup.marker-popup,
.leaflet-popup:has(.marker-collected, .marker-form) {
  --marker-bg: #0b0b0b;
  --marker-panel: #061d25;
  --marker-accent: #067f72;
  --marker-accent-hover: #2ba997;
  --marker-muted: #717574;
  --marker-text: #9da6a4;
  --marker-highlight: #ffce00;
  --marker-danger: #661010;
  --marker-border: rgb(157 166 164 / 24%);
  --marker-radius: 10px;
  color: var(--marker-text);
  color-scheme: dark;
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.marker-form,
.marker-form *,
.marker-form *::before,
.marker-form *::after,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) * {
  box-sizing: border-box;
}

/* Служебные состояния ограничены компонентами. */
.marker-form :is([hidden], .hide, .hide-i),
.marker-form:is([hidden], .hide, .hide-i),
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) :is([hidden], .hide, .hide-i) {
  display: none !important;
}

.marker-form .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Форма */
.marker-form {
  display: grid;
  gap: 16px;
  width: 400px;
  max-width: 460px;
  min-width: 0;
  margin: 0;
  padding: 18px;
  background: var(--marker-bg);
  border: 1px solid var(--marker-border);
  border-radius: 14px;
  overflow-wrap: anywhere;
  container: marker-form / inline-size;
}

.marker-form :is(.form-section, .form-subsection) {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--marker-border);
  border-radius: var(--marker-radius);
  background: var(--marker-panel);
}

.marker-form :is(.form-section, .form-subsection) > legend {
  max-width: 100%;
  padding: 0 6px;
  color: var(--marker-accent-hover);
  font-size: 13px;
  font-weight: 650;
}

.marker-form :is(.form-section, .form-subsection) > :not(legend) + :not(legend) {
  margin-top: 12px;
}

.marker-form .form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.marker-form .form-field--inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  align-items: center;
  gap: 10px;
}

.marker-form .form-field__label {
  font-size: 12px;
  font-weight: 600;
}

.marker-form :is(input, textarea, select, button) {
  font: inherit;
}

.marker-form :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), textarea, select) {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  margin: 0;
  padding: 9px 10px;
  color: var(--marker-text);
  background: var(--marker-bg);
  border: 1px solid var(--marker-muted);
  border-radius: 6px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.marker-form textarea {
  min-height: 110px;
  resize: vertical;
}

.marker-form select {
  padding-right: 6px;
  cursor: none;
}

.marker-form :is(input, textarea)::placeholder {
  color: var(--marker-muted);
  opacity: 1;
}

.marker-form :is(input, textarea, select):focus {
  border-color: var(--marker-accent-hover);
}

.marker-form :is(input, textarea, select, button, summary, [tabindex]):focus-visible,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) :is(input, summary, a):focus-visible {
  outline: 2px solid var(--marker-highlight);
  outline-offset: 3px;
}

.marker-form :is(input, textarea, select)[aria-invalid="true"],
.marker-form :is(input, textarea, select):user-invalid {
  border-color: var(--marker-highlight);
  box-shadow: inset 3px 0 var(--marker-danger);
}

.marker-form :is(input, textarea, select, button):disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.marker-form :is(.checkbox-field, .radio-field) {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  margin: 0;
  cursor: none;
}

.marker-form :is(input[type="checkbox"], input[type="radio"]),
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .marker-collected {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--marker-accent-hover);
  cursor: none;
}

.marker-form :is(.checkbox-field, .radio-field):has(input:disabled) {
  color: var(--marker-muted);
  cursor: not-allowed;
}

.marker-form .coordinate-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.marker-form .radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.marker-form .color-picker {
  width: 100%;
  cursor: none;
}

.marker-form .number-field--percent {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.marker-form .number-field--percent > span {
  flex: 0 0 auto;
  color: var(--marker-accent-hover);
}

/* Details: display не переопределяется, нативное сворачивание сохраняется. */
.marker-form details.form-section {
  padding: 0;
}

.marker-form .form-collapsible__summary,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  color: var(--marker-accent-hover);
  font-weight: 600;
  list-style: none;
  cursor: none;
  border-radius: var(--marker-radius);
}

.marker-form .form-collapsible__summary::-webkit-details-marker,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__summary::-webkit-details-marker {
  display: none;
}

.marker-form .form-collapsible__summary::before,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__summary::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 150ms ease;
}

.marker-form details[open] > .form-collapsible__summary::before,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) details[open] > .collapsible__summary::before {
  transform: rotate(45deg);
}

.marker-form .form-collapsible__icon,
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-left: auto;
  object-fit: contain;
  opacity: 0.65;
}

.marker-form .form-collapsible > :is(.form-collapsible__content, .content-fields) {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 0;
  border-top: 1px solid var(--marker-border);
}

.marker-form .content-fields {
  display: grid;
  gap: 14px;
}

.marker-form .form-subsection {
  background: var(--marker-bg);
}

.marker-form .wealth-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--marker-panel);
  font-variant-numeric: tabular-nums;
}

.marker-form .wealth-preview output {
  color: var(--marker-highlight);
  font-weight: 650;
}

/* Теги и выпадающие подсказки.
   Элементы подсказок: role="option".
   Каждый непосредственный потомок .tag-list — отдельный тег. */
.marker-form .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.marker-form .tag-list:empty {
  display: none;
}

.marker-form .tag-list > * {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
  padding: 5px 8px;
  color: var(--marker-text);
  background: var(--marker-panel);
  border: 1px solid var(--marker-accent);
  border-radius: 6px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.marker-form .tag-list > * > span {
  min-width: 0;
}

.marker-form .tag-list button {
  flex-shrink: 0;
  min-width: 28px;
  min-height: 28px;
  padding: 2px 5px;
  color: var(--marker-text);
  background: transparent;
  border: 1px solid var(--marker-border);
  border-radius: 4px;
  cursor: none;
}

.marker-form :is(.tag-input__control, .autocomplete) {
  position: relative;
  min-width: 0;
}

.marker-form :is(.tag-input__suggestions, .autocomplete__suggestions) {
  position: absolute;
  z-index: 20;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  max-height: 200px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px;
  background: var(--marker-panel);
  border: 1px solid var(--marker-accent);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgb(0 0 0 / 45%);
}

.marker-form :is(.tag-input__suggestions, .autocomplete__suggestions) [role="option"] {
  display: block;
  width: 100%;
  padding: 9px 10px;
  color: var(--marker-text);
  background: transparent;
  border: 0;
  border-radius: 4px;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: none;
}

.marker-form :is(.tag-input__suggestions, .autocomplete__suggestions) [role="option"]:is(:hover, [aria-selected="true"]) {
  color: var(--marker-highlight);
  background: var(--marker-bg);
}

.marker-form .form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--marker-border);
}

.marker-form .form-actions button {
  flex: 1 1 90px;
  min-height: 42px;
  padding: 9px 14px;
  color: var(--marker-text);
  background: var(--marker-panel);
  border: 1px solid var(--marker-muted);
  border-radius: 7px;
  font-weight: 650;
  cursor: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.marker-form .form-actions .btn-submit {
  color: var(--marker-bg);
  background: var(--marker-accent-hover);
  border-color: var(--marker-accent-hover);
}

.marker-form .form-actions .btn-delete {
  color: var(--marker-text);
  background: var(--marker-danger);
  border-color: var(--marker-danger);
}

/* Leaflet: внешний корпус, наконечник и кнопка закрытия. */
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) .leaflet-popup-content-wrapper {
  padding: 1px;
  color: var(--marker-text);
  background: var(--marker-bg);
  border: 1px solid var(--marker-accent);
  border-radius: 12px;
  box-shadow: 0 10px 32px rgb(0 0 0 / 55%);
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) .leaflet-popup-tip {
  background: var(--marker-bg);
  box-shadow: 3px 3px 8px rgb(0 0 0 / 25%);
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) .leaflet-popup-content {
  min-width: 0;
  max-width: calc(100vw - 72px);
  margin: 18px 20px 16px;
  font: inherit;
  overflow-wrap: anywhere;
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) a.leaflet-popup-close-button {
  top: 3px;
  right: 3px;
  width: 28px;
  height: 28px;
  color: var(--marker-text);
  background: transparent;
  border-radius: 5px;
  font: 22px/28px sans-serif;
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .leaflet-popup-content > b:first-child {
  display: inline-block;
  padding-right: 12px;
  margin-bottom: 5px;
  color: var(--marker-accent-hover);
  font-size: 17px;
  line-height: 1.3;
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) label:has(> .marker-collected) {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--marker-panel);
  border: 1px solid var(--marker-border);
  border-radius: 7px;
  cursor: none;
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) label:has(> .marker-collected:checked) {
  color: var(--marker-accent-hover);
  border-color: var(--marker-accent);
}

/* Названия popap-section и __content сохранены из исходной разметки. */
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) :is(.popap-section, .__content) {
  margin-top: 10px;
  background: var(--marker-panel);
  border: 1px solid var(--marker-border);
  border-radius: var(--marker-radius);
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__content {
  padding: 10px 12px;
  border-top: 1px solid var(--marker-border);
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .__content {
  padding: 10px 12px;
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .field {
  display: grid;
  gap: 5px;
  margin: 0;
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .field + .field {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--marker-border);
}

:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .field__label {
  display: block;
  min-width: 0;
  font-size: 13px;
}

/* Если редактор тоже открывается внутри Leaflet. */
:is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-form)) .marker-form {
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 0;
}

@media (hover: hover) {
  .marker-form .form-actions button:not(:disabled):hover {
    border-color: var(--marker-highlight);
  }

  .marker-form .form-actions .btn-submit:not(:disabled):hover {
    background: var(--marker-highlight);
  }

  .marker-form .form-collapsible__summary:hover,
  :is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__summary:hover,
  :is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected, .marker-form)) a.leaflet-popup-close-button:hover {
    color: var(--marker-highlight);
  }
}

/* Реагирует на ширину формы, в том числе внутри узкого попапа. */
@container marker-form (max-width: 320px) {
  .marker-form .form-field--inline {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .marker-form {
    padding: 12px;
    gap: 12px;
  }

  .marker-form :is(input:not([type="checkbox"]):not([type="radio"]), textarea, select) {
    font-size: 16px;
  }

  .marker-form .form-field--inline {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .marker-form *,
  .marker-form *::before,
  :is(.leaflet-popup.marker-popup, .leaflet-popup:has(.marker-collected)) .collapsible__summary::before {
    transition: none;
  }
}


.fit-content {
  width: fit-content !important;
}

.edit-popup-class{
  width: 445px;
}

