/* Zakładka Mapa: filtry | mapa | karta osady. Boczne panele mają stałą, równą szerokość,
   więc mapa jest wyśrodkowana i zabiera całą resztę szerokości okna. Prawy panel stoi
   zawsze (pusty z podpowiedzią), żeby otwarcie karty nie zmieniało rozmiaru mapy. */
.map-shell {
  --map-side-w: 340px;
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 0 auto;
  padding: 0.65rem 1rem 1rem;
  display: grid;
  grid-template-columns: minmax(300px, var(--map-side-w)) minmax(0, 1fr) minmax(300px, var(--map-side-w));
  gap: 1rem;
  height: calc(100dvh - var(--site-header-h));
  min-height: 420px;
}

.map-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  overflow: auto;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
}

/* .map-card: patrz components.css (card) */

.map-filters {
  display: grid;
  gap: 0.35rem;
}

.map-extra-filters {
  display: grid;
  gap: 0.65rem;
}

.map-filter-field {
  display: grid;
  gap: 0.3rem;
  color: var(--ink);
  font-size: var(--fs-base);
}

.map-filter-field > span {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.map-filter-field select {
  width: 100%;
}

.map-check {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--ink);
}

.map-count {
  color: var(--muted);
  font-size: var(--fs-md);
}

.map-kind {
  width: 12px;
  height: 12px;
  border: 1.5px solid #140e08;
  background: var(--accent-2);
}

.map-kind-town {
  border-radius: 50%;
}

.map-kind-castle {
  border-radius: 1px;
}

.map-kind-village {
  width: 8px;
  height: 8px;
  margin: 2px;
  border-radius: 50%;
}

.map-kind-hideout {
  background: #3a3129;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  border: 0;
}

.map-hint {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.35;
}

.map-legend {
  display: grid;
  gap: 0.2rem;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.4rem;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.map-legend-item:hover {
  background: var(--selected-bg);
}

.map-legend-item[aria-pressed="false"] {
  opacity: 0.4;
}

.map-swatch {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.map-view {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: #1e2a36;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#map-canvas:active {
  cursor: grabbing;
}

.map-tip {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  gap: 0.1rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--selected-border);
  border-radius: var(--radius-lg);
  background: rgba(24, 18, 12, 0.94);
  color: var(--ink);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.map-tip-sub {
  color: var(--muted);
  font-size: var(--fs-md);
}

.map-zoom {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: grid;
  gap: 0.3rem;
}

.map-zoom button {
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(24, 18, 12, 0.9);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
}

.map-zoom button:hover,
.map-zoom button:focus-visible {
  border-color: var(--accent-2);
  outline: none;
}

.map-status {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-lg);
  background: rgba(24, 18, 12, 0.9);
  color: var(--muted);
}

/* Błąd wczytania mapy — ten sam kolor co .status.bad na innych zakładkach. */
.map-status.bad {
  color: var(--danger-text);
}

.map-kind-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

.map-names-btn {
  min-width: 2rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
  opacity: 0.8;
}

.map-names-btn[aria-pressed="true"] {
  border-color: var(--selected-border);
  background: var(--selected-bg);
  color: var(--accent-2);
  opacity: 1;
}

.map-names-btn:hover,
.map-names-btn:focus-visible {
  border-color: var(--accent-2);
  outline: none;
  opacity: 1;
}

.map-legend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.15rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.map-legend-bulk {
  display: flex;
  gap: 0.35rem;
}

.map-link-btn {
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}

.map-link-btn:hover,
.map-link-btn:focus-visible {
  border-color: var(--accent-2);
  color: var(--ink);
  outline: none;
}

/* Wysokość karty jak w innych zakładkach: tyle, ile treść, najwyżej do dołu mapy. */
.map-detail {
  position: relative;
  align-self: start;
  max-height: 100%;
  min-height: 0;
  overflow: auto;
}

.map-detail-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 2;
  margin: -0.3rem -0.3rem 0 0.5rem;
}

.map-shell [hidden] {
  display: none !important;
}

/* Poniżej tej szerokości mapa między dwoma panelami byłaby za wąska — panele pod mapą. */
@media (max-width: 1100px) {
  .map-shell {
    grid-template-columns: 1fr;
    height: auto;
    padding: 0.5rem;
  }

  .map-side {
    max-height: none;
  }

  /* Na wąskim ekranie najpierw mapa, pod nią karta osady, na końcu filtry. */
  .map-view {
    order: -2;
    height: 70dvh;
  }

  .map-detail {
    order: -1;
    overflow: visible;
  }
}

/* Ekran dotykowy: sterowanie mapą co najmniej 36–44 px, bo palec nie trafia w mniejsze cele. */
@media (pointer: coarse) {
  .map-zoom button {
    width: 2.75rem;
    height: 2.75rem;
  }

  .map-names-btn {
    min-width: 2.25rem;
    min-height: 2.25rem;
  }

  .map-link-btn {
    min-height: 2.25rem;
    padding-inline: 0.7rem;
  }

  .map-legend-item,
  .map-check {
    min-height: 2.25rem;
  }

  .map-detail-close {
    width: 2.5rem;
    height: 2.5rem;
  }
}
