/* ==========================================================================
   Dahin map page + grouped sources directory (Phase 3C)

   Phone first: the map fills the viewport and the legend is a drag-handle
   sheet (max 60vh). From 1024px the legend becomes the thesis-style fixed
   right column next to the map. Extends the Phase 3A tokens from dahin.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Full-bleed map page (overrides the app frame)
   -------------------------------------------------------------------------- */

.page--map {
    padding: 0;
    background: var(--orange);
}

.page--map .shell {
    display: block;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
}

.page--map .topbar,
.page--map .sidenav,
.page--map .aside,
.page--map .tabbar {
    display: none;
}

.page--map .main {
    height: 100%;
    overflow: hidden;
}

.page--map .content {
    max-width: none;
    height: 100%;
    padding: 0;
}

.map-page {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--orange);
}

.map-page__canvas {
    position: absolute;
    inset: 0;
}

.map-brand {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    left: 12px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 6px 10px;
    background: var(--orange);
    border: var(--border-width) solid var(--tinte);
    border-radius: var(--radius);
}

.map-brand img {
    width: auto;
    height: 20px;
    filter: brightness(0);
}

.map-locate {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: 12px;
    z-index: 5;
    min-height: 44px;
    padding: 10px 14px;
    border: var(--border-width) solid var(--tinte);
    border-radius: var(--radius);
    background: var(--hell);
    font-family: var(--font-display);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}

.map-locate:hover {
    background: var(--papier);
}

.map-status {
    position: absolute;
    top: calc(64px + env(safe-area-inset-top));
    left: 12px;
    z-index: 5;
    max-width: min(320px, 70vw);
    padding: 6px 10px;
    background: var(--tinte);
    color: var(--papier);
    border-radius: var(--radius);
    font-size: 0.8125rem;
}

.map-status:empty {
    display: none;
}

.map-noscript {
    position: absolute;
    inset: auto 16px 96px;
    z-index: 8;
    padding: 12px 14px;
    background: var(--hell);
    border: var(--border-width) solid var(--tinte);
}

/* --------------------------------------------------------------------------
   Legend sheet (phone)
   -------------------------------------------------------------------------- */

.map-legend {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    max-height: 60vh;
    /* Darker orange + light ink: `#111` on `#d0411f` is only 4.01:1. */
    background: var(--orange-dunkel);
    color: var(--hell);
    border-top: var(--border-width) solid var(--tinte);
    transform: translateY(calc(100% - 56px));
    transition: transform 200ms ease;
}

.map-legend.is-open {
    transform: translateY(0);
}

.map-legend__handle {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 56px;
    padding: 8px 12px;
    border: 0;
    background: transparent;
    color: var(--hell);
    font-family: var(--font-display);
    font-size: 0.8125rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: grab;
    touch-action: none;
}

.map-legend__grip {
    width: 36px;
    height: 4px;
    background: var(--hell);
    border-radius: 2px;
}

.map-legend__handle-hint {
    font-family: var(--font-body);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: none;
    opacity: 0.7;
}

.map-legend__body {
    min-height: 0;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
}

.map-legend__body::-webkit-scrollbar {
    display: none;
}

.map-legend__search {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 4px 0 8px;
    background: var(--orange-dunkel);
}

.map-legend__search input {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    border: var(--border-width) solid var(--tinte);
    border-radius: var(--radius);
    background: rgb(var(--rgb-hell) / var(--o8));
    font-size: 0.875rem;
    font-weight: 600;
}

.map-filters {
    display: flex;
    gap: 8px;
    padding: 4px 0 10px;
    overflow-x: auto;
    scrollbar-width: none;
}

.map-filters::-webkit-scrollbar {
    display: none;
}

.map-chip {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 8px 12px;
    border: var(--border-width) solid var(--tinte);
    border-radius: 999px;
    background: var(--hell);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.map-chip[aria-pressed="false"] {
    background: transparent;
    opacity: var(--o5);
    text-decoration: line-through;
}

.map-legend__group + .map-legend__group {
    border-top: var(--border-width) solid var(--tinte);
}

.map-legend__group[hidden] {
    display: none;
}

.map-legend__cat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.map-legend__shape svg {
    display: block;
    width: 18px;
    height: 18px;
}

.map-legend__count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

.map-legend__items {
    display: flex;
    flex-direction: column;
    padding-bottom: 6px;
}

.map-legend__item {
    display: flex;
    gap: 10px;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 6px 4px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.map-legend__item:hover,
.map-legend__item:focus-visible {
    background: rgb(var(--rgb-schwarz) / var(--o1));
}

.map-legend__item[hidden] {
    display: none;
}

.map-legend__item-shape svg {
    display: block;
    width: 16px;
    height: 16px;
}

.map-legend__item-name {
    display: block;
    font-weight: 700;
}

.map-legend__item-area {
    display: block;
    font-size: 0.75rem;
    opacity: 0.75;
}

/* --------------------------------------------------------------------------
   Venue detail panel
   -------------------------------------------------------------------------- */

.map-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 7;
    max-height: 75vh;
    padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
    overflow-y: auto;
    background: var(--hell);
    border-top: var(--border-width) solid var(--tinte);
    box-shadow: 0 -8px 24px rgb(var(--rgb-schwarz) / var(--o2));
}

.map-panel[hidden] {
    display: none;
}

.map-panel:focus {
    outline: none;
}

.map-page.is-panel-open .map-legend {
    display: none;
}

.map-panel__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    border: var(--border-width) solid var(--tinte);
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
}

.map-panel__close::before {
    content: "×";
    font-size: 28px;
    line-height: 1;
}

.map-panel__close:hover {
    background: rgb(var(--rgb-schwarz) / var(--o1));
}

.map-panel__title {
    padding-right: 56px;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 400;
    line-height: 1.05;
    text-transform: uppercase;
}

.map-panel__cat {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 8px;
    background: var(--orange-dunkel);
    color: var(--papier);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.map-panel__label {
    margin-top: 16px;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.7;
}

.map-panel__text {
    margin-top: 4px;
    font-size: 0.9375rem;
    line-height: 1.45;
}

.map-panel__text--muted {
    opacity: 0.6;
}

.map-panel__link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-top: 4px;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.map-panel__events {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.map-panel__event {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid rgb(var(--rgb-schwarz) / var(--o3));
    border-radius: var(--radius);
    background: var(--papier);
    text-align: left;
    cursor: pointer;
}

.map-panel__event:hover {
    border-color: var(--tinte);
}

.map-panel__event-name {
    font-weight: 600;
}

.map-panel__event-date {
    flex: 0 0 auto;
    font-size: 0.8125rem;
    opacity: 0.7;
}

.map-panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 18px;
}

.map-panel__action {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* --------------------------------------------------------------------------
   MapLibre controls in the Dahin look
   -------------------------------------------------------------------------- */

.maplibregl-ctrl-group {
    background: var(--orange);
    border-radius: var(--radius);
    box-shadow: 0 0 0 2px var(--tinte);
}

.maplibregl-ctrl-attrib {
    background: rgb(var(--rgb-hell) / var(--o8));
    font-family: var(--font-body);
    font-size: 0.6875rem;
}

.maplibregl-ctrl-attrib a {
    color: var(--tinte);
}

/* --------------------------------------------------------------------------
   Desktop: fixed right column legend (thesis geometry)
   -------------------------------------------------------------------------- */

@media (width >= 1024px) {
    .map-legend {
        inset: 18px 18px auto auto;
        width: min(340px, 44vw);
        max-height: calc(100% - 96px);
        border: var(--border-width) solid var(--tinte);
        border-radius: var(--radius);
        transform: none;
    }

    .map-legend__handle {
        display: none;
    }

    .map-legend__body {
        padding-top: 12px;
    }

    .map-filters {
        flex-wrap: wrap;
        overflow: visible;
    }

    .map-page.is-panel-open .map-legend {
        display: flex;
    }

    .map-locate {
        top: calc(64px + env(safe-area-inset-top));
        right: auto;
        left: 12px;
    }

    .map-status {
        top: calc(108px + env(safe-area-inset-top));
    }

    .map-panel {
        right: auto;
        bottom: 18px;
        left: 18px;
        width: 380px;
        max-height: calc(100% - 120px);
        border: var(--border-width) solid var(--tinte);
        border-radius: var(--radius);
        box-shadow: 0 8px 24px rgb(var(--rgb-schwarz) / var(--o3));
    }
}

/* --------------------------------------------------------------------------
   Grouped sources directory
   -------------------------------------------------------------------------- */

.sources__search {
    display: flex;
    gap: 8px;
    margin-top: 24px;
}

.sources__input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    border: var(--border-width) solid var(--tinte);
    border-radius: var(--radius);
    background: var(--hell);
    font-size: 0.9375rem;
}

.sources__submit {
    flex: 0 0 auto;
}

.sources__status {
    margin-top: 12px;
    font-size: 0.875rem;
    color: rgb(var(--rgb-schwarz) / var(--o6));
}

.sources__groups {
    display: flex;
    flex-direction: column;
    gap: 28px;
    margin-top: 28px;
}

.sources-group[hidden] {
    display: none;
}

.sources-group__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: var(--border-width) solid var(--tinte);
}

.sources-group__img {
    flex: 0 0 auto;
    width: 64px;
    height: 44px;
    object-fit: cover;
    border: var(--border-width) solid var(--tinte);
    border-radius: var(--radius);
}

.sources-group__title {
    flex: 1 1 auto;
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 400;
    line-height: 1.05;
    text-transform: uppercase;
}

.sources-group__count {
    flex: 0 0 auto;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.sources-group__body {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.sources-group__empty {
    font-size: 0.875rem;
    opacity: 0.6;
}

.sources-card {
    padding: 14px;
    background: var(--hell);
    border: var(--line);
    border-radius: var(--radius);
}

.sources-card[hidden] {
    display: none;
}

.sources-card__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.sources-card__title .sources-link__icon {
    flex: 0 0 auto;
    color: var(--orange-dunkel);
}

.sources-card__text {
    margin-top: 6px;
    font-size: 0.875rem;
    line-height: 1.45;
}

.sources-links {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 8px;
}

.sources-link {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    min-height: 44px;
    font-size: 0.8125rem;
    font-weight: 600;
}

.sources-link__icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
}

.sources-link__icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.sources-link__host {
    font-weight: 400;
    opacity: 0.6;
}

.sources-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 8px;
}

.sources-card__action {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.sources-card__paired {
    margin-top: 12px;
    padding-top: 12px;
    border-top: var(--line);
}

.sources-card__paired-label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.65;
}

.sources-card__paired-name {
    margin-top: 2px;
    font-weight: 700;
}

@media (width >= 600px) {
    .sources-group__body {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    .map-legend {
        transition: none;
    }
}
