/* ---------------------------------------------------------------------------
   Map attribution: compact label, full sources one tap away.

   Only hidden once the script has actually built the replacement, so a map
   whose JS failed still shows Leaflet's own credit line rather than none.
   --------------------------------------------------------------------------- */

.leaflet-container.er-map-attrib-ready .leaflet-control-attribution {
    display: none;
}

.er-map-attrib {
    position: relative;
    margin: 0 8px 8px 0 !important;
    font-family: var(--er-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
}

.er-map-attrib__button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid var(--er-rule, rgba(38, 34, 30, 0.16));
    border-radius: 999px;
    background: rgba(253, 251, 246, 0.92);
    color: var(--er-ink-2, #4a433c);
    /* Readable, not microscopic: attribution is a credit, not fine print.
       Quiet enough to sit in the corner of a 390px map without competing
       with the geography. The opened panel stays at reading size. */
    font: inherit;
    font-size: 10px;
    line-height: 1.2;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.er-map-attrib__button:hover {
    background: var(--er-paper, #fdfbf6);
    color: var(--er-ink, #26221e);
}

.er-map-attrib__button:focus-visible {
    outline: 2px solid var(--er-clay, #b36a45);
    outline-offset: 2px;
}

.er-map-attrib__mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 13px;
    height: 13px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 9px;
    font-style: italic;
    line-height: 1;
}

/* An author `display` beats the user-agent [hidden] rule, so the mobile
   display: flex below would leave this panel permanently open. */
.er-map-attrib__panel[hidden] {
    display: none;
}

.er-map-attrib__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 1000;
    width: max-content;
    max-width: min(320px, calc(100vw - 40px));
    padding: 13px 15px;
    border: 1px solid var(--er-rule, rgba(38, 34, 30, 0.16));
    border-radius: var(--er-r-sm, 4px);
    background: var(--er-paper, #fdfbf6);
    box-shadow: 0 8px 24px rgba(38, 34, 30, 0.16);
}

.er-map-attrib__sources {
    margin: 0 0 10px;
    color: var(--er-ink-2, #4a433c);
    font-family: inherit;
    font-size: 12px;
    line-height: 1.5;
}

.er-map-attrib__sources a {
    color: inherit;
}

.er-map-attrib__close {
    min-height: 32px;
    padding: 6px 12px;
    border: 1px solid var(--er-rule, rgba(38, 34, 30, 0.16));
    border-radius: var(--er-r-sm, 4px);
    background: transparent;
    color: var(--er-ink-2, #4a433c);
    font: inherit;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

.er-map-attrib__close:focus-visible {
    outline: 2px solid var(--er-clay, #b36a45);
    outline-offset: 2px;
}

/* Deliberately never viewport-fixed. Leaflet transforms its panes and the
   route atlas filters its tile layer, and a transformed or filtered ancestor
   makes a fixed child position against that ancestor instead of the viewport:
   the panel then lands in the middle of the map with its close button clipped.
   Absolute against the control is predictable everywhere.

   On a phone it tightens rather than grows, so a 300px-tall map keeps most of
   its geography visible behind a panel the reader can dismiss three ways. */
@media (max-width: 600px) {
    .er-map-attrib__panel {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        width: min(300px, calc(100vw - 44px));
        max-width: none;
        max-height: 38vh;
        overflow-y: auto;
        padding: 10px 11px;
        /* Map notes and legends live along the bottom edge and wrap wide on a
           phone; clear them rather than sit on them. */
        bottom: calc(100% + 26px);
    }

    .er-map-attrib__sources {
        margin: 0;
        font-size: 11px;
        line-height: 1.45;
    }

    .er-map-attrib__close {
        flex: none;
        min-height: 28px;
        padding: 4px 9px;
        font-size: 10px;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .er-map-attrib__button,
    .er-map-attrib__close {
        transition: background-color 120ms ease, color 120ms ease;
    }
}
