*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --filter-h: 50px;
    --strip-h:  128px;
    --blue:     #2563eb;
    --blue-lt:  #60a5fa;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: #1a1a1a;
}

/* ── Filter bar ─────────────────────────────────────────────────────────── */

#filter-bar {
    grid-area: filter;
    height: var(--filter-h);
    background: linear-gradient(to bottom, #f7f7f7 0%, #dcdcdc 100%);
    border-top:    1px solid #aaa;
    border-bottom: 1px solid #aaa;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.85), 0 -1px 4px rgba(0,0,0,0.10);
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: nowrap;
    overflow-x: auto;
    z-index: 5;
}

/* Mobile-only filter-menu toggle — hidden on desktop, shown via media query. */
#filter-toggle {
    display: none;
}

#filter-bar-link {
    margin-left: auto;
    font-size: 12px;
    color: #444;
    text-decoration: none;
    text-shadow: 0 1px 0 rgba(255,255,255,0.7);
    padding: 4px 8px;
    border-radius: 3px;
    flex-shrink: 0;
}

#filter-bar-link:hover {
    text-decoration: underline;
    color: #111;
}

#lang-toggle {
    flex-shrink: 0;
    min-width: 36px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #333;
    text-shadow: 0 1px 0 rgba(255,255,255,0.7);
    background: linear-gradient(to bottom, #ffffff 0%, #e6e6e6 100%);
    border: 1px solid #a0a0a0;
    border-top-color: #888;
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.8), 0 1px 0 rgba(255,255,255,0.5);
    cursor: pointer;
    min-height: 24px;
}

#lang-toggle:hover {
    background: linear-gradient(to bottom, #f4f4f4 0%, #d4d4d4 100%);
}

#lang-toggle:active {
    background: linear-gradient(to bottom, #d4d4d4 0%, #f4f4f4 100%);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

#filter-bar label {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 500;
    color: #3a3a3a;
    text-shadow: 0 1px 0 rgba(255,255,255,0.75);
}

#filter-bar select,
#filter-bar input[type="number"] {
    padding: 3px 7px;
    border: 1px solid #a0a0a0;
    border-top-color: #888;
    border-radius: 5px;
    font-size: 13px;
    color: #222;
    background: linear-gradient(to bottom, #ffffff 0%, #f0f0f0 100%);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.10), 0 1px 0 rgba(255,255,255,0.6);
    min-height: 28px;
    appearance: auto;
}

.year-range {
    display: flex;
    align-items: center;
    gap: 4px;
}

.year-range input[type="number"] {
    width: 72px;
}

/* ── Content grid ───────────────────────────────────────────────────────── */

#content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: 50% 50%;
    grid-template-rows: 1fr var(--filter-h);
    grid-template-areas:
        "photo  map"
        "filter filter";
}

#content.has-strip {
    grid-template-rows: 1fr var(--filter-h) var(--strip-h);
    grid-template-areas:
        "photo  map"
        "filter filter"
        "strip-wrap strip-wrap";
}

/* ── Photo pane ─────────────────────────────────────────────────────────── */

#photo-pane {
    grid-area: photo;
    background: #111;
    color: #f0f0f0;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Mobile-only photo-pane collapse tab — hidden on desktop. */
#photo-collapse {
    display: none;
}

#photo-pane-placeholder {
    text-align: center;
    color: #666;
    padding: 24px;
    line-height: 1.8;
    font-size: 13px;
    pointer-events: none;
}

#photo-pane.has-photo #photo-pane-placeholder {
    display: none;
}

#panel-img-wrap {
    display: none;
    position: absolute;
    inset: 0;
}

#photo-pane.has-photo #panel-img-wrap {
    display: block;
}

#panel-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #111;
}

#panel-caption {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 28px 14px 10px;
    background: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.72) 100%);
    z-index: 5;
    pointer-events: none;
}

#photo-pane.has-photo #panel-caption {
    display: block;
}

#panel-datierung {
    font-size: 13px;
    color: #fff;
    font-weight: 500;
}

#panel-filename {
    font-size: 10px;
    color: #aaa;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    margin-top: 2px;
}

#panel-taschentext {
    font-size: 11px;
    color: #bbb;
    font-style: italic;
    line-height: 1.4;
    margin-top: 6px;
    margin-right: 54px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.12);
}

#panel-taschentext:empty {
    display: none;
}

#panel-info-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    font-size: 13px;
    font-style: italic;
    font-family: Georgia, serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
#panel-info-btn:hover { background: rgba(255,255,255,0.3); }

#panel-popover {
    position: absolute;
    bottom: 44px;
    right: 8px;
    width: 260px;
    max-height: 260px;
    overflow-y: auto;
    background: rgba(10,10,10,0.92);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 12px;
    z-index: 10;
}

#panel-popover dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 10px;
}

#panel-popover dt { color: #aaa; white-space: nowrap; }
#panel-popover dd { color: #f0f0f0; word-break: break-word; }

/* ── Map ────────────────────────────────────────────────────────────────── */

#map {
    grid-area: map;
    background: #e8e0d8;
}

/* Push Leaflet zoom controls below the filter bar */
.leaflet-top.leaflet-left {
    top: 10px;
}

/* ── Status overlay (loading / error) ──────────────────────────────────── */

#status {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

#status.visible {
    opacity: 1;
}

/* ── Cluster circle labels ──────────────────────────────────────────────── */

.cluster-label {
    background: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #fff;
    font-size: 12px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    pointer-events: none;
}

/* ── Thumbnail strip ────────────────────────────────────────────────────── */

#strip-wrap {
    grid-area: strip-wrap;
    position: relative;
    background: #1a1a1a;
    border-top: 1px solid #333;
}

#strip {
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

#strip-inner {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    height: 100%;
    width: max-content;
}

.strip-thumb {
    flex: 0 0 auto;
    height: calc(var(--strip-h) - 18px);
    aspect-ratio: 3/2;
    object-fit: cover;
    cursor: pointer;
    border-radius: 3px;
    border: 2px solid transparent;
    opacity: 0.75;
    transition: opacity 0.15s, border-color 0.15s;
}

.strip-thumb:hover { opacity: 1; }
.strip-thumb.selected { border-color: var(--blue); opacity: 1; }

.strip-nav {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 44px;
    z-index: 10;
    border: none;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#strip-prev {
    left: 0;
    background: linear-gradient(to right, rgba(10,10,10,0.82) 0%, transparent 100%);
    padding-right: 6px;
}

#strip-next {
    right: 0;
    background: linear-gradient(to left, rgba(10,10,10,0.82) 0%, transparent 100%);
    padding-left: 6px;
}

.strip-nav.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ── Lightbox (fullscreen photo viewer) ─────────────────────────────────── */

#lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.93);
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    animation: lightbox-fade 0.18s ease;
}

#lightbox[hidden] {
    display: none;
}

@keyframes lightbox-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#lightbox-stage {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 0 24px;
    gap: 18px;
}

#lightbox-img {
    max-width: 100%;
    max-height: calc(100% - 80px);
    object-fit: contain;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    border-radius: 2px;
}

#lightbox-caption {
    text-align: center;
    color: #ddd;
    font-size: 14px;
    line-height: 1.5;
    max-width: 80%;
}

#lightbox-datierung {
    font-size: 16px;
    color: #fff;
    font-weight: 500;
    letter-spacing: 0.02em;
}

#lightbox-filename {
    font-size: 11px;
    color: #888;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    margin-top: 4px;
}

#lightbox-taschentext {
    font-size: 12px;
    color: #999;
    font-style: italic;
    line-height: 1.5;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.1);
    max-width: 480px;
}

#lightbox-taschentext:empty {
    display: none;
}

.lightbox-nav {
    flex: 0 0 auto;
    width: 72px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 44px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#lightbox-prev {
    background: linear-gradient(to right, rgba(255,255,255,0.05), transparent);
}

#lightbox-next {
    background: linear-gradient(to left, rgba(255,255,255,0.05), transparent);
}

.lightbox-nav:hover {
    opacity: 1;
    background-color: rgba(255,255,255,0.06);
}

.lightbox-nav:disabled {
    opacity: 0.15;
    cursor: default;
    background-color: transparent;
}

#lightbox-close {
    position: absolute;
    top: 14px;
    right: 18px;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: #fff;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s;
    z-index: 1;
}

#lightbox-close:hover { opacity: 1; }

/* Photo in pane is clickable to open lightbox */
#panel-img {
    cursor: zoom-in;
}

@media (max-width: 768px) {
    .lightbox-nav {
        width: 50px;
        font-size: 36px;
    }
    #lightbox-stage {
        padding: 24px 0 16px;
    }
    #lightbox-img {
        max-height: calc(100% - 70px);
    }
}


/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    /* The filter bar becomes an overlay menu, not a grid row. */
    #content {
        grid-template-columns: 1fr;
        grid-template-rows: 40% 1fr;
        grid-template-areas:
            "map"
            "photo";
    }

    #content.has-strip {
        grid-template-rows: 40% 1fr var(--strip-h);
        grid-template-areas:
            "map"
            "photo"
            "strip-wrap";
    }

    /* Button that unfolds the filter menu — fixed at the top-left. */
    #filter-toggle {
        display: flex;
        align-items: center;
        gap: 6px;
        position: fixed;
        top: 8px;
        left: 8px;
        z-index: 1600;   /* above Leaflet panes/controls (max ~1000) */
        min-height: 38px;
        padding: 0 13px;
        font-size: 13px;
        font-weight: 600;
        color: #333;
        background: linear-gradient(to bottom, #ffffff 0%, #e6e6e6 100%);
        border: 1px solid #9a9a9a;
        border-radius: 6px;
        box-shadow: 0 1px 5px rgba(0,0,0,0.30);
        cursor: pointer;
    }

    #filter-toggle::after {
        content: "\25BE";   /* ▾ — rotates when the menu is open */
        font-size: 10px;
        transition: transform 0.2s;
    }

    #filter-toggle[aria-expanded="true"]::after {
        transform: rotate(180deg);
    }

    /* The filter bar unfolds as a panel sliding down from the top edge. */
    #filter-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: auto;
        max-height: 85vh;
        overflow-x: hidden;
        overflow-y: auto;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: 14px;
        padding: 54px 16px 18px;
        box-shadow: 0 3px 10px rgba(0,0,0,0.30);
        z-index: 1500;   /* above Leaflet panes/controls (max ~1000) */
        transform: translateY(-100%);
        visibility: hidden;
        transition: transform 0.22s ease, visibility 0.22s;
    }

    #filter-bar.open {
        transform: translateY(0);
        visibility: visible;
    }

    #filter-bar label {
        justify-content: space-between;
        font-size: 15px;
    }

    #filter-bar select,
    #filter-bar input[type="number"] {
        min-height: 44px;   /* touch target */
        font-size: 16px;    /* prevent iOS zoom */
    }

    #filter-bar-link {
        margin-left: 0;
        align-self: flex-start;
        font-size: 14px;
        padding: 6px 0;
    }

    #lang-toggle {
        align-self: flex-start;
        min-height: 40px;
        padding: 7px 16px;
        font-size: 13px;
    }

    /* Collapse tab: a handle at the top edge of the photo pane. Collapsing
       shrinks the photo row to just the tab, giving the map the rest. */
    #content.photo-collapsed {
        grid-template-rows: 1fr 30px;
    }

    #content.has-strip.photo-collapsed {
        grid-template-rows: 1fr 30px var(--strip-h);
    }

    /* Collapse handle: a light tab so it stays visible on the dark pane
       and over photos alike. z-index keeps it above all pane content. */
    #photo-collapse {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 78px;
        height: 30px;
        z-index: 12;
        border: none;
        border-radius: 0 0 11px 11px;
        background: rgba(255,255,255,0.94);
        color: #1a1a1a;
        box-shadow: 0 2px 8px rgba(0,0,0,0.55);
        cursor: pointer;
    }

    #photo-collapse::after {
        content: "\25BC";   /* ▼ — pane expanded, tap to collapse */
        font-size: 12px;
        line-height: 1;
    }

    #content.photo-collapsed #photo-collapse::after {
        content: "\25B2";   /* ▲ — pane collapsed, tap to expand */
    }

    /* Collapsed: show only the handle, never the panel content behind it. */
    #content.photo-collapsed #photo-pane > :not(#photo-collapse) {
        display: none;
    }
}

/* ── Keyboard focus ──────────────────────────────────────────────────────── */

:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
