/*
 * Map (snippet map, module map.js): static image without JavaScript, interactive Leaflet map with it.
 * Leaflet's own stylesheet sits in the layer vendor (assets/vendor/leaflet/leaflet-layered.css).
 */
@layer components {
  .map {
    margin-inline: 0;
  }

  .map__frame {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    inline-size: 100%;
    aspect-ratio: 2 / 1;
    min-block-size: 320px;
    background-color: var(--color-sand-300);
    /* thin outline as on the image placeholders: the map never blends into a sand section */
    border: var(--border-width-thin) solid var(--color-border-default);
  }

  [data-bg="muted"] .map__frame {
    border-color: var(--color-sand-400);
  }

  [data-bg="inverse"] .map__frame {
    border-color: var(--color-olive-700);
  }

  [data-bg="strong"] .map__frame,
  [data-bg="accent"] .map__frame {
    border-color: var(--color-sand-500);
  }

  .map__fallback,
  .map__canvas {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
  }

  .map__fallback {
    object-fit: cover;
  }

  .map__fallback[hidden],
  .map__canvas[hidden] {
    display: none;
  }

  /* "Anfahrt" on the event page: air between the heading and the map */
  .event-directions .map {
    margin-block-start: var(--space-24);
  }

  .map__caption {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    margin-block-start: var(--space-8);
  }

  /* with the interactive map the credit is part of the map; the line keeps its space so the caption does not jump */
  .map[data-ready] .map__attribution {
    visibility: hidden;
  }

  .map__attribution {
    color: var(--color-text-subtle);
    font-size: var(--type-text-small-size);
    line-height: var(--type-text-small-line-height);
  }

  .map__attribution a {
    color: inherit;
  }

  .map__address {
    font-weight: var(--font-weight-bold);
  }

  .map__links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8) var(--space-24);
  }

  .map__note {
    margin-block-start: var(--space-24);
    max-inline-size: var(--layout-container-text);
  }

  /* ---------- interactive map ---------- */
  .map__canvas {
    z-index: var(--z-base);
    background-color: var(--color-sand-300);
    font-family: var(--font-family-base), system-ui, sans-serif;
    font-size: var(--type-text-small-size);
    line-height: var(--type-text-small-line-height);
    color: var(--color-text-default);
  }

  /* Tiles warmed towards the beige/olive palette: one filter on the pane (no seams between tiles). */
  .map__canvas .leaflet-tile-pane {
    filter: saturate(0.7) sepia(0.28) hue-rotate(-8deg) brightness(1.04) contrast(0.92);
  }

  .map__canvas:focus-visible {
    outline: var(--border-width-focus) solid var(--color-focus);
    outline-offset: -3px;
  }

  /* fullscreen: the canvas sits in a modal dialog (top layer), see map.js */
  .map-dialog {
    position: fixed;
    inset: 0;
    inline-size: 100vw;
    block-size: 100dvh;
    max-inline-size: none;
    max-block-size: none;
    margin: 0;
    padding: 0;
    border: 0;
    background-color: var(--color-sand-300);
    overflow: hidden;
  }

  .map-dialog::backdrop {
    background: transparent;
  }

  .map__canvas--expanded {
    border-radius: 0;
  }

  body.map-expanded {
    overflow: hidden;
  }

  /* pin */
  .map-pin-icon {
    background: none;
    border: 0;
  }

  .map-pin {
    display: block;
    filter: drop-shadow(0 2px 2px rgb(42 41 1 / 0.3));
  }

  .map-pin__shape {
    fill: var(--color-olive-950);
  }

  .map-pin__dot {
    fill: var(--color-yellow-500);
  }

  .map-pin-icon:focus-visible {
    outline: none;
  }

  .map-pin-icon:focus-visible .map-pin__shape {
    stroke: var(--color-yellow-500);
    stroke-width: 3px;
  }

  .map-pin-icon:focus-visible .map-pin {
    outline: var(--border-width-focus) solid var(--color-focus);
    outline-offset: 4px;
    border-radius: var(--radius-s);
  }

  /* controls: 44 x 44, white surface, 16 px group radius */
  .map__canvas .map-control {
    display: flex;
    margin: var(--space-12);
    border: var(--border-width-thin) solid var(--color-border-default);
    border-radius: var(--radius-l);
    background-color: var(--color-neutral-0);
    box-shadow: 0 1px 3px rgb(42 41 1 / 0.18);
    overflow: hidden;
  }

  .map__canvas .map-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 44px;
    block-size: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background-color: var(--color-neutral-0);
    color: var(--color-text-default);
    cursor: pointer;
  }

  .map__canvas .map-btn + .map-btn {
    border-inline-start: var(--border-width-thin) solid var(--color-border-default);
  }

  .map__canvas .map-btn:hover:not([aria-disabled='true']) {
    background-color: var(--color-background-subtle);
  }

  .map__canvas .map-btn[aria-disabled='true'] {
    color: var(--color-sand-700);
    cursor: not-allowed;
  }

  .map__canvas .map-btn:focus-visible {
    outline: var(--border-width-focus) solid var(--color-focus);
    outline-offset: -3px;
  }

  /* attribution: bottom left, last in tab order */
  .map__canvas .leaflet-control-attribution {
    margin: 0 0 var(--space-8) var(--space-12);
    padding: 0 var(--space-8);
    border-radius: var(--radius-s);
    background-color: rgb(255 255 255 / 0.9);
    color: var(--color-text-default);
    font-size: var(--type-label-s-size);
    line-height: var(--type-label-s-line-height);
  }

  .map__canvas .leaflet-control-attribution a {
    color: var(--color-text-link);
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  /* popup */
  .map__canvas .map-popup .leaflet-popup-content-wrapper {
    border-radius: var(--radius-l);
    background-color: var(--color-neutral-0);
    color: var(--color-text-default);
    box-shadow: 0 4px 16px rgb(42 41 1 / 0.22);
  }

  .map__canvas .map-popup .leaflet-popup-tip {
    background-color: var(--color-neutral-0);
    box-shadow: none;
  }

  .map__canvas .map-popup .leaflet-popup-content {
    margin: var(--space-12) var(--space-40) var(--space-12) var(--space-16);
    font-size: var(--type-text-small-size);
    line-height: var(--type-text-small-line-height);
  }

  .map-popup__content {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .map-popup__title {
    font-weight: var(--font-weight-bold);
  }

  .map-popup__links {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-block-start: var(--space-4);
  }

  .map__canvas .map-popup .map-popup__link {
    color: var(--color-text-link);
    font-weight: var(--font-weight-semibold);
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  .map__canvas .map-popup a.leaflet-popup-close-button {
    inset-block-start: var(--space-4);
    inset-inline-end: var(--space-4);
    inline-size: 36px;
    block-size: 36px;
    padding: 0;
    border-radius: var(--radius-m);
    color: var(--color-text-default);
    font-size: 24px;
    line-height: 36px;
    text-align: center;
    text-decoration: none;
  }

  .map__canvas .map-popup a.leaflet-popup-close-button:hover {
    background-color: var(--color-background-subtle);
    color: var(--color-text-default);
  }

  .map__canvas .map-popup a.leaflet-popup-close-button:focus-visible {
    outline: var(--border-width-focus) solid var(--color-focus);
    outline-offset: -3px;
  }

  @media (prefers-reduced-motion: reduce) {
    .map__canvas .leaflet-zoom-animated,
    .map__canvas .leaflet-fade-anim .leaflet-popup {
      transition: none;
    }
  }
}
