/* Карта — design/work/maps.html */

.map-page .map-main {
  gap: 1rem;
  flex: none;
}

/* Служебная карта: не сжимать блок карты в колонке service-page (иначе холст 0px и точек нет) */
body.map-page.service-page > .container {
  display: block;
  flex: none;
}

.map-page .map-main > .pub-hero + .map-filters {
  margin-top: 0;
}

[hidden] {
  display: none !important;
}

html[data-map-mode="public"] [data-service-only],
html[data-map-mode="service"] [data-public-only] {
  display: none !important;
}

.map-status-help {
  margin: 0;
  border: 1px solid var(--pub-border);
  border-radius: 8px;
  background: var(--surface);
  padding: 0;
}

.map-status-help summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  color: var(--pub-heading);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  list-style: none;
}

.map-status-help summary::-webkit-details-marker {
  display: none;
}

.map-status-help summary svg {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.map-status-help[open] summary svg {
  transform: rotate(180deg);
}

.map-status-help ul {
  margin: 0;
  padding: 0 1rem 0.85rem 1.75rem;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.55;
}

.map-status-help li + li {
  margin-top: 0.35rem;
}

/* Статистика */
.map-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.map-stat-card {
  background: var(--surface);
  border: 1px solid var(--pub-border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.map-stat-card--action {
  cursor: pointer;
  text-align: left;
  font: inherit;
  width: 100%;
}

.map-stat-card--action:hover,
.map-stat-card--action:focus-visible {
  border-color: var(--pub-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--pub-accent) 35%, transparent);
  outline: none;
}

.map-stat-card--action.is-active {
  border-color: var(--pub-accent);
  background: var(--pub-accent-soft);
}

.map-stat-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg);
  color: #6b7280;
}

.map-stat-icon svg {
  width: 1.15rem;
  height: 1.15rem;
}

.map-stat-icon--green {
  background: #e8f5e9;
  color: #3a5a38;
}

.map-stat-icon--yellow {
  background: #fef3c7;
  color: #d97706;
}

.map-stat-icon--grey {
  background: var(--combo-hover);
  color: #6b7280;
}

.map-stat-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  display: block;
}

.map-stat-dot--green {
  background: #3a5a38;
}

.map-stat-dot--yellow {
  background: #d97706;
}

.map-stat-dot--grey {
  background: #9ca3af;
}

.map-stat-info h4 {
  margin: 0 0 0.15rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.map-stat-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.map-stat-note {
  font-size: 0.75rem;
  font-weight: 500;
  color: #d97706;
}

/* Фильтры: две строки, каждое поле отдельно — без общей «полоски» */
.map-filters {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  margin: 0;
  border: 1px solid var(--pub-border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.map-filters-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}

.map-filters-row--meta {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.map-filter-field,
.map-filter-years {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
}

.map-filter-caption {
  line-height: 1.2;
}

.map-filters .ui-combo,
.map-filters .ui-combo-input,
.map-filters select,
.map-filters input:not([type="checkbox"]) {
  width: 100%;
  min-width: 0;
}

.map-year-range {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.map-year-range .ui-input,
.map-filters .map-year-range input {
  min-width: 0;
  flex: 1 1 0;
  padding-right: 0.65rem;
  background-image: none;
  text-align: center;
}

.map-year-sep {
  flex: 0 0 auto;
  color: #9ca3af;
  font-weight: 600;
}

.map-filters-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.85rem;
  min-height: 40px;
  padding-bottom: 0;
}

.map-filters label.map-cluster-label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  height: 40px;
  margin: 0;
  white-space: nowrap;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #2c4c3b;
  cursor: pointer;
  user-select: none;
}

.map-filters label.map-cluster-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
  margin: 0;
  padding: 0;
  background-image: none;
  border: 1px solid var(--pub-border);
  border-radius: 4px;
  cursor: pointer;
}

.map-filters #map-reset {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 40px;
  padding: 0 1.1rem;
  border: 1px solid var(--pub-border);
  border-radius: 8px;
  background: var(--surface);
  color: #3a5a38;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}

.map-filters #map-reset:hover {
  background: var(--bg);
}

/* Карта + список — фиксированная высота, прокрутка только в сайдбаре */
.map-container {
  --map-block-height: 420px;
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  height: var(--map-block-height);
  min-height: 420px;
  max-height: var(--map-block-height);
  background: var(--surface);
  border: 1px solid var(--pub-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.map-view.map-stage {
  position: relative;
  flex: 1 1 0%;
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  border: none;
  border-radius: 0;
  background: #d8dcd6;
  margin: 0;
  overflow: hidden;
}

.map-view.map-stage.map-season-bloom {
  background: #d4d8d1;
}

#maplibre {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.map-download-bar {
  position: absolute;
  left: 0.65rem;
  bottom: 0.65rem;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  pointer-events: none;
}

.map-download-bar button {
  pointer-events: auto;
  height: 36px;
  padding: 0 0.85rem;
  border: 1px solid var(--pub-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #3a5a38;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(31, 41, 55, 0.12);
}

.map-download-bar button:hover {
  background: var(--surface);
}

.map-download-bar button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.map-basemap-toggle {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  z-index: 4;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(58, 90, 56, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  color: #3d5c42;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(24, 40, 28, 0.12);
  opacity: 0.78;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

.map-basemap-toggle:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.94);
}

.map-basemap-toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.map-basemap-toggle__icon {
  display: none;
  line-height: 0;
}

.map-basemap-toggle:not(.is-dark) .map-basemap-toggle__sun,
.map-basemap-toggle.is-dark .map-basemap-toggle__moon {
  display: block;
}

.map-basemap-toggle.is-dark {
  background: rgba(32, 48, 40, 0.72);
  border-color: rgba(220, 232, 224, 0.22);
  color: #e8f0ea;
}

.map-basemap-toggle.is-dark:hover {
  background: rgba(32, 48, 40, 0.9);
}

.map-basemap-status {
  position: absolute;
  top: 0.65rem;
  left: 2.45rem;
  z-index: 2;
  margin: 0;
  max-width: min(22rem, calc(100% - 5rem));
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: 0 2px 10px rgba(31, 41, 55, 0.12);
  pointer-events: none;
}

.map-basemap-status--loading,
.map-basemap-status--fallback {
  background: rgba(255, 255, 255, 0.94);
  color: #3a5a38;
  border: 1px solid rgba(58, 90, 56, 0.18);
}

.map-basemap-status--ok {
  background: rgba(232, 245, 233, 0.95);
  color: #2e4a3e;
  border: 1px solid rgba(58, 90, 56, 0.22);
}

.map-basemap-status--error {
  background: rgba(254, 242, 242, 0.96);
  color: #991b1b;
  border: 1px solid rgba(185, 28, 28, 0.25);
}

#maplibre .maplibregl-map,
#maplibre .maplibregl-canvas-container,
#maplibre canvas.maplibregl-canvas {
  width: 100% !important;
  height: 100% !important;
}

.map-cluster-labels {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.map-cluster-count {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #fff;
  font: 700 12px/1 "Segoe UI", Arial, sans-serif;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  white-space: nowrap;
}

.map-sidebar {
  width: min(350px, 38vw);
  flex: 0 0 min(350px, 38vw);
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  border-left: 1px solid var(--pub-border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.map-sidebar-header {
  flex: 0 0 auto;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--pub-border);
  font-size: 0.8125rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  line-height: 1.4;
}

.map-sidebar-search {
  flex: 0 0 auto;
  display: block;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--pub-border);
  background: var(--bg);
}

.map-sidebar-search .ui-input {
  width: 100%;
  box-sizing: border-box;
  font-size: 0.8125rem;
  padding: 0.45rem 0.65rem;
  border-color: var(--pub-border);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.map-sidebar-header svg {
  flex-shrink: 0;
  color: #3a5a38;
}

.map-sidebar-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0.85rem;
  background: var(--surface);
}

.map-sidebar-empty {
  margin: 0;
  padding: 0.75rem 0.35rem;
  color: #9ca3af;
  font-size: 0.875rem;
}

.map-list-item {
  border: 1px solid var(--pub-border);
  border-radius: 10px;
  padding: 0.8rem 0.85rem;
  margin-bottom: 0.65rem;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.map-list-item a,
.map-list-item button,
.map-list-item summary {
  cursor: pointer;
}

.map-list-item:hover {
  border-color: var(--pub-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.map-list-item:last-child {
  margin-bottom: 0;
}

.map-list-item.is-map-selected,
.map-list-item.is-sidebar-focused {
  border-color: var(--pub-accent);
  box-shadow: none;
  background: var(--pub-accent-soft);
}

.map-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.map-region-back {
  border: 1px solid var(--pub-border);
  background: var(--surface);
  color: #3a5a38;
  border-radius: 8px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  margin-right: 0.35rem;
}

.map-region-back:hover {
  background: var(--combo-hover);
}

.map-list-item[data-region-key] {
  cursor: pointer;
}

.map-item-name {
  font-weight: 600;
  color: #1f2937;
  font-size: 0.9rem;
  line-height: 1.35;
  margin: 0 0 0.2rem;
}

.map-item-region {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  color: #6b7280;
  line-height: 1.4;
}

.map-item-country {
  margin: 0 0 0.35rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #374151;
}

.map-item-country--empty {
  color: #9ca3af;
}

.map-item-kicker {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9ca3af;
  margin-right: 0.15rem;
}

.map-item-country-value {
  font-weight: 600;
  color: #2e4a3e;
}

.map-item-country-note {
  display: inline-block;
  margin-left: 0.15rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--combo-hover);
  color: #6b7280;
  font-size: 0.6875rem;
  font-weight: 500;
  vertical-align: middle;
}

.map-item-hint {
  margin: 0 0 0.45rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 0.6875rem;
  line-height: 1.4;
}

.map-item-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: var(--combo-hover);
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #6b7280;
  white-space: nowrap;
}

.map-item-tag-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.map-item-tag.status-valid {
  background: #e8f5e9;
  color: #2e7d32;
}

.map-item-tag.status-missing,
.map-item-tag.status-zero_zero {
  background: var(--combo-hover);
  color: #6b7280;
}

.map-item-tag.status-invalid_range {
  background: #fdecec;
  color: #9f1239;
}

.map-item-tag.status-suspected_swap {
  background: #fef3c7;
  color: #92400e;
}

.map-item-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

.map-btn-open {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.map-btn-open:hover {
  background: var(--combo-hover);
  color: var(--pub-heading);
  border-color: var(--pub-accent);
}

.map-btn-coord {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
}

.map-btn-coord:hover {
  background: var(--pub-accent-soft);
  border-color: var(--pub-accent);
}

.map-item-details {
  margin: 0;
  font-size: 0.75rem;
}

.map-item-details summary {
  color: var(--pub-accent);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.map-item-details summary::-webkit-details-marker {
  display: none;
}

.map-item-details .muted {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  line-height: 1.5;
}

@media (max-width: 1100px) {
  .map-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .map-filters-row {
    grid-template-columns: 1fr;
  }

  .map-filters-row--meta {
    grid-template-columns: 1fr;
  }

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

  .map-container {
    --map-block-height: auto;
    flex-direction: column;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .map-view.map-stage {
    min-height: 380px;
  }

  #maplibre {
    position: absolute;
    inset: 0;
  }

  .map-sidebar {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--pub-border);
  }

  .map-sidebar-list {
    max-height: 360px;
  }
}

@media (max-width: 640px) {
  .map-stats-grid {
    grid-template-columns: 1fr;
  }

  .map-filters-row,
  .map-filters-row--meta {
    grid-template-columns: 1fr;
  }

  .map-filters-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
