
.sbf-gallery-overlay {
    position: absolute;
    inset: 0;
    z-index: 1980; /* über Dialog (1950) und Apps, unter Statusbar (2000) */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;     /* Sheet am unteren Rand andocken */
    padding: 0;
    overflow: hidden;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    pointer-events: none;
    transition: background 0.26s cubic-bezier(0.4, 0, 0.2, 1),
                backdrop-filter 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI',
                 Roboto, Helvetica, Arial, sans-serif;
}

/* Im visible-Zustand: Backdrop sichtbar machen + Blur anwenden */
.sbf-gallery-overlay.visible {
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(1px);
    pointer-events: all;
}

/* ── Root-Container (das eigentliche Bottom-Sheet) ───────────────────────── */
.sbf-gallery {
    width: 100%;
    max-width: 100%;
    max-height: 72%;                 /* max. 72% der Phone-Höhe */
    min-height: 240px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    /* Sheet: oben stark abgerundet (Drag-Handle-Stil), unten dezent
       abgerundet damit es harmonisch mit dem Phone-Frame (45px) wirkt. */
    border-radius: 25px 25px 16px 16px;
    pointer-events: all;
    box-shadow:
        0 -10px 40px 0 rgba(0, 0, 0, 0.40),
        0 -2px 10px 0 rgba(0, 0, 0, 0.25);
    transform: translateY(110%);
    transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1);
    --gallery-text:        #ffffff;
    --gallery-text-soft:  rgba(255, 255, 255, 0.72);
    --gallery-text-mute:  rgba(255, 255, 255, 0.48);
    --gallery-bg:         #1a1a1c;
    --gallery-header-bg:  rgba(26, 26, 28, 0.78);
    --gallery-grid-bg:    rgba(255, 255, 255, 0.04);
    --gallery-tile-bg:    rgba(255, 255, 255, 0.08);
    --gallery-tile-border:rgba(255, 255, 255, 0.10);
    --gallery-divider:    rgba(255, 255, 255, 0.10);
    --gallery-accent:     #0a84ff;
    --gallery-overlay-bg: rgba(0, 0, 0, 0.55);
    --gallery-placeholder-icon: rgba(255, 255, 255, 0.35);
    --gallery-shadow-col: #000000;
}

/* Sobald Overlay sichtbar → Sheet nach oben schieben */
.sbf-gallery-overlay.visible .sbf-gallery {
    transform: translateY(0);
}

/* ── Dark Theme (default) ───────────────────────────────────────────────── */
.sbf-gallery.theme-dark {
    /* App-Konvention: Darkmode = #1a1a1c */
    background: #1a1a1c;
}

/* ── Light Theme ────────────────────────────────────────────────────────── */
.sbf-gallery.theme-light {
    /* App-Konvention: Lightmode = #dfdfdf */
    background: #dfdfdf;
    --gallery-text:        #0d0d1e;
    --gallery-text-soft:  rgba(0, 0, 0, 0.72);
    --gallery-text-mute:  rgba(0, 0, 0, 0.48);
    --gallery-bg:         #dfdfdf;
    --gallery-header-bg:  rgba(223, 223, 223, 0.85);
    --gallery-grid-bg:    rgba(0, 0, 0, 0.04);
    --gallery-tile-bg:    rgba(0, 0, 0, 0.06);
    --gallery-tile-border:rgba(0, 0, 0, 0.08);
    --gallery-divider:    rgba(0, 0, 0, 0.10);
    --gallery-accent:     #007aff;
    --gallery-overlay-bg: rgba(0, 0, 0, 0.35);
    --gallery-placeholder-icon: rgba(0, 0, 0, 0.32);
    --gallery-shadow-col: #1a1a3a;
}

/* ── Header (iOS-Photos-Style: Cancel | Spacer | Done) ──────────────────── */
.sbf-gallery-header {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 11px 9px;
    gap: 8px;
    background: var(--gallery-header-bg);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    backdrop-filter: blur(28px) saturate(180%);
    border-bottom: 1px solid var(--gallery-divider);
    box-shadow: 0 1px 0 0 var(--gallery-divider);
    z-index: 2;
}

/* ── iOS-Style Grab-Handle (kleiner Strich oben am Sheet) ────────────────── */
.sbf-gallery-handle {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 51px;
    background: var(--gallery-divider);
    opacity: 0.7;
    pointer-events: none;
}

/* Unsichtbarer Spacer, damit Cancel + Confirm an den Rändern bleiben
   und die Mitte frei bleibt (kein Titel/Subtitel mehr). */
.sbf-gallery-header-spacer {
    flex: 1;
    pointer-events: none;
}

/* ── Header-Buttons (Cancel + Confirm) — Liquid-Glass-Pill 1:1 wie Dialog ──
   Style ist exakt von .sbf-dialog-btn aus dialog.css übernommen, damit
   alle Dialog-/Picker-Buttons im Phone die gleiche Optik haben. */
.sbf-gallery-btn {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    cursor: pointer;
    font: inherit;
    border: none;
    padding: 9px 6px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    border-radius: 99em;
    color: #007AFF;
    background: rgba(187, 187, 188, 0.18);
    backdrop-filter: blur(8px) saturate(150%);
    -webkit-backdrop-filter: blur(8px) saturate(150%);
    box-shadow:
        inset 0 0 0 1px        rgba(255, 255, 255, 0.20),
        inset 1px 1px 0 -1px   rgba(255, 255, 255, 0.70),
        inset -1px -1px 0 -1px rgba(255, 255, 255, 0.45),
        inset 0 -1px 4px 0     rgba(0, 0, 0, 0.10),
        0 2px 8px 0            rgba(0, 0, 0, 0.12);
    transition: background 0.14s ease, box-shadow 0.14s ease;
    min-width: 96px;
    max-width: 140px;
    flex: 0 0 auto;
}

.sbf-gallery-btn:hover {
    background: rgba(187, 187, 188, 0.28);
}

.sbf-gallery-btn:active {
    background: rgba(187, 187, 188, 0.36);
    box-shadow:
        inset 0 0 0 1px    rgba(255, 255, 255, 0.10),
        inset 0 2px 6px 0  rgba(0, 0, 0, 0.18),
        0 1px 4px 0        rgba(0, 0, 0, 0.08);
}

/* Confirm-Button = "bold" (iOS-Photos-Picker "Use") — blau gefüllt */
.sbf-gallery-btn--confirm {
    background: rgba(0, 122, 255, 0.88);
    color: #ffffff;
    font-weight: 600;
    min-width: 96px;
    text-align: center;
}

.sbf-gallery-btn--confirm:hover {
    background: rgba(0, 122, 255, 1);
}

.sbf-gallery-btn--confirm:active {
    background: rgba(0, 82, 210, 0.92);
}

/* Cancel-Button = "cancel" (iOS-Dialog) — blauer Text, Glas, normal weight */
.sbf-gallery-btn--cancel {
    text-align: center;
    color: #007AFF;
    font-weight: 400;
}

/* Disabled-Confirm (noch keine Auswahl) — ausgegraut, nicht klickbar */
.sbf-gallery-btn.disabled,
.sbf-gallery-btn[aria-disabled="true"] {
    color: var(--gallery-text-mute);
    pointer-events: none;
    cursor: default;
    opacity: 0.42;
    background: rgba(187, 187, 188, 0.10);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        0 1px 4px 0 rgba(0, 0, 0, 0.08);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Buttons — Light Theme Anpassungen
   ═══════════════════════════════════════════════════════════════════════════ */
.sbf-gallery.theme-light .sbf-gallery-btn {
    background: rgba(118, 118, 128, 0.14);
    box-shadow:
        inset 0 0 0 1px        rgba(0, 0, 0, 0.06),
        inset 1px 2px 0 -1px   rgba(255, 255, 255, 0.90),
        inset -1px -1px 0 -1px rgba(255, 255, 255, 0.55),
        inset 0 -1px 4px 0     rgba(0, 0, 0, 0.06),
        0 2px 8px 0            rgba(0, 0, 0, 0.08);
    color: #007AFF;
}

.sbf-gallery.theme-light .sbf-gallery-btn:hover {
    background: rgba(118, 118, 128, 0.22);
}

.sbf-gallery.theme-light .sbf-gallery-btn:active {
    background: rgba(118, 118, 128, 0.30);
}

/* Confirm: blau gefüllt (light) */
.sbf-gallery.theme-light .sbf-gallery-btn--confirm {
    background: rgba(0, 122, 255, 0.90);
    color: #ffffff;
}

.sbf-gallery.theme-light .sbf-gallery-btn--confirm:hover {
    background: rgba(0, 122, 255, 1);
}

.sbf-gallery.theme-light .sbf-gallery-btn--confirm:active {
    background: rgba(0, 82, 210, 0.92);
}

/* Cancel: blauer Text (light) */
.sbf-gallery.theme-light .sbf-gallery-btn--cancel {
    color: #007AFF;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Bottom Liquid Glass Category Selector (1:1 von .photos-nav*)
   Liegt absolut unten ÜBER dem Bilder-Grid (nicht als eigene Zeile).
   Styles sind 1:1 aus apps/photos/app.css kopiert.
   ═══════════════════════════════════════════════════════════════════════════ */
.sbf-gallery-nav-wrapper {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    padding: 0;
    z-index: 10;
    pointer-events: none;
}

.sbf-gallery-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 50px;
    pointer-events: auto;
    width: 200px;
}

/* ── Nav Tabs — Liquid Glass Switcher ── */
.sbf-gallery-nav-links {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    flex: 1;
    height: 100%;
    padding: 0;
    border-radius: 99em;
    background-color: rgba(187, 187, 188, 0.70);
    /* Kein margin-right: Picker hat KEINEN "+"-Button rechts */

    box-shadow:
        inset 0 0 0 1px           rgb(255 255 255 / 10%),
        inset 1.8px 3px 0 -2px    rgb(255 255 255 / 28%),
        inset -1px -1px 0 -1px    rgb(255 255 255 / 0%),
        inset -3px -6px 1px -6px  rgb(255 255 255 / 65%),
        inset -0.3px -1px 4px 0   rgb(0 0 0 / 12%),
        inset -1.5px 2.5px 0 -2px rgb(0 0 0 / 20%),
        inset 0 3px 4px -2px      rgb(0 0 0 / 20%),
        inset 2px -6.5px 1px -4px rgb(0 0 0 / 10%),
        0 1px 5px 0               rgb(0 0 0 / 10%),
        0 6px 16px 0              rgb(0 0 0 / 8%);
}

/* Sliding pill indicator (Gallery-Picker hat NUR 2 Tabs → 50% Breite) */
.sbf-gallery-nav-links::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 4px;
    width: calc(50% - 6px);
    height: calc(100% - 8px);
    border-radius: 99em;
    background-color: rgba(187, 187, 188, 0.36);
    z-index: 0;
    pointer-events: none;
    box-shadow:
        inset 0 0 0 1px           rgb(255 255 255 / 10%),
        inset 2px 1px 0 -1px      rgb(255 255 255 / 50%),
        inset -1.5px -1px 0 -1px  rgb(255 255 255 / 39%),
        inset -2px -6px 1px -5px  rgb(255 255 255 / 43%),
        inset -1px 2px 3px -1px   rgb(0 0 0 / 20%),
        inset 0 -4px 1px -2px     rgb(0 0 0 / 10%),
        0 3px 6px 0               rgb(0 0 0 / 8%);
    transition: left 400ms cubic-bezier(1, 0, 0.4, 1);
}

/* Album tab active → slide pill to right half */
.sbf-gallery-nav-links:has([data-filter="album"].sbf-gallery-nav-btn--active)::after {
    left: calc(50% + 2px);
}

.sbf-gallery-nav-btn {
    position: relative;
    z-index: 1;
    flex: 1;
    height: 100%;
    padding: 0;
    border: none;
    border-radius: 99em;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: none;
    color: var(--gallery-text-mute);
    transition: color 160ms;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Media-Button: gleiche Breite wie die anderen Tabs */
.sbf-gallery-nav-btn--media {
    flex: 1;
    color: var(--gallery-text-mute);
}

.sbf-gallery-nav-icon {
    width: 30px;       /* 1:1 wie Photos-App (war vorher 26px) */
    height: 30px;
    display: block;
}

.sbf-gallery-nav-btn:hover {
    color: var(--gallery-text);
}

.sbf-gallery-nav-btn--active {
    color: var(--gallery-text);
    cursor: default;
}

/* ── Body (füllt restlichen Platz, scrollt) ─────────────────────────────── */
.sbf-gallery-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0px 0px 64px;
    background: var(--gallery-bg);
}

/* ═══════════════════════════════════════════════════════════════════════════
   ALBUM LIST (Karten-Liste, kein Erstellen/Löschen)
   ═══════════════════════════════════════════════════════════════════════════ */
.sbf-gallery-albums-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 4px 8px 14px;
    box-sizing: border-box;
}

.sbf-gallery-album-card {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 10px;
    background: var(--gallery-tile-bg);
    box-shadow: inset 0 0 0 1px var(--gallery-tile-border);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: transform 0.16s ease, opacity 0.16s ease;
    -webkit-tap-highlight-color: transparent;
}

.sbf-gallery-album-card:hover { transform: scale(1.02); }
.sbf-gallery-album-card:active { transform: scale(0.97); opacity: 0.85; }

.sbf-gallery-album-thumb,
.sbf-gallery-album-thumb-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
    display: block;
    background: var(--gallery-tile-bg);
}

.sbf-gallery-album-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gallery-placeholder-icon);
    background: #000000;
}

.sbf-gallery-album-thumb svg {
    width: 40%;
    height: 40%;
    opacity: 0.85;
}

.sbf-gallery-album-thumb-play {
    color: #ffffff;
    opacity: 0.95;
    filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
}

.sbf-gallery-album-thumb--placeholder {
    background: var(--gallery-tile-bg);
}

.sbf-gallery-album-meta {
    position: relative;
    z-index: 2;
    margin-top: auto;
    padding: 8px 10px 9px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
    color: #ffffff;
}

.sbf-gallery-album-name {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.sbf-gallery-album-count {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 1px;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

/* Scrollbar im Webkit-Stil (so unauffällig wie möglich) */
.sbf-gallery-body::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   GRID (iOS-Photos-Recents-Look: 3 Spalten quadratisch)
   ═══════════════════════════════════════════════════════════════════════════ */
.sbf-gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    width: 100%;
    box-sizing: border-box;
    padding: 0;
}

/* ── Item (Thumbnail) ────────────────────────────────────────────────────── */
.sbf-gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: var(--gallery-tile-bg);
    cursor: pointer;
    transition: transform 0.16s ease, opacity 0.16s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    box-shadow: inset 0 0 0 1px var(--gallery-tile-border);
    filter: brightness(0.8);
}

.sbf-gallery-item:active {
    transform: scale(0.97);
    opacity: 0.85;
}

/* Berg-mit-Sonne-Placeholder (default sichtbar, wird vom Bild überlagert) */
.sbf-gallery-item-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gallery-placeholder-icon);
    background: var(--gallery-tile-bg);
    z-index: 1;
    pointer-events: none;
}

.sbf-gallery-item-placeholder svg {
    width: 50%;
    height: 50%;
    opacity: 0.9;
}

/* ── Video-Placeholder (schwarzer Hintergrund + Play-Icon) ─────────────────
   Wird gezeigt solange _extractVideoThumbnail() läuft oder fehlschlägt
   (z.B. CORS-Block → tainted canvas). Sobald das data:image/jpeg zur
   Verfügung steht, ersetzt das <img>-Tag diesen Placeholder visuell. */
.sbf-gallery-item-placeholder--video {
    background: #000000;
    color: #ffffff;
    opacity: 0.85;
}

.sbf-gallery-item-video-play {
    width: 42% !important;
    height: 42% !important;
    opacity: 0.95 !important;
    filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
}

/* Bild — über dem Placeholder, beim Laden unsichtbar */
.sbf-gallery-item-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    z-index: 2;
    display: block;
    opacity: 0;
    transition: opacity 0.22s ease;
    background: transparent;
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none;
}

/* Wenn Bild komplett geladen → einblenden (Klasse wird per JS gesetzt) */
.sbf-gallery-item-img.is-loaded {
    opacity: 1;
}

/* Bei Videos: <img> ohne `src` (initial) — komplett verstecken, damit
   der Browser kein "broken image" Icon zeigt. Sobald _extractVideoThumbnail
   die data:image/jpeg geliefert hat, wird der src gesetzt und das Bild
   fadet per .is-loaded ein. */
.sbf-gallery-item--video .sbf-gallery-item-img:not([src]) {
    display: none;
}

/* Video-Badge (Play-Icon + Länge) */
.sbf-gallery-item-video-badge {
    position: absolute;
    right: 4px;
    bottom: 4px;
    z-index: 3;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px 4px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    pointer-events: none;
}

.sbf-gallery-item-video-badge svg {
    display: block;
}

/* ── Check-Indicator (iOS-Style: blauer Kreis mit Häkchen) ──────────────── */
.sbf-gallery-item-check {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 4;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.85);
    color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease;
    pointer-events: none;
}

.sbf-gallery-item-check svg {
    width: 14px;
    height: 14px;
    display: block;
}

.sbf-gallery-item:hover .sbf-gallery-item-check {
    opacity: 1;
    transform: scale(1);
}

.sbf-gallery-item.selected .sbf-gallery-item-check {
    opacity: 1;
    transform: scale(1);
    background: var(--gallery-accent);
    color: #ffffff;
    box-shadow: inset 0 0 0 1.5px var(--gallery-accent);
}

.sbf-gallery-item.selected .sbf-gallery-item-img {
    transform: scale(1.02);
    box-shadow: 0 0 0 2px var(--gallery-accent) inset;
}

.sbf-gallery.theme-light .sbf-gallery-item.selected .sbf-gallery-item-img {
    /* Etwas dunkler beim Auswählen — iOS-Look */
    opacity: 0.88;
}

.sbf-gallery.theme-dark .sbf-gallery-item.selected .sbf-gallery-item-img {
    opacity: 0.82;
}

/* ═══════════════════════════════════════════════════════════════════════════
   States (Loading / Empty / Error)
   ═══════════════════════════════════════════════════════════════════════════ */
.sbf-gallery-state {
    width: 100%;
    height: 100%;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px 28px;
    text-align: center;
    color: var(--gallery-text);
    box-sizing: border-box;
    gap: 8px;
}

.sbf-gallery-state-icon {
    color: var(--gallery-text-mute);
    margin-bottom: 4px;
}

.sbf-gallery-state-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gallery-text);
    line-height: 1.2;
}

.sbf-gallery-state-text {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--gallery-text-soft);
    line-height: 1.4;
    max-width: 220px;
}

/* Spinner (iOS-Style) */
.sbf-gallery-spinner {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sbf-gallery-spinner-inner {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2.5px solid var(--gallery-divider);
    border-top-color: var(--gallery-accent);
    animation: sbf-gallery-spin 0.85s linear infinite;
}

@keyframes sbf-gallery-spin {
    to { transform: rotate(360deg); }
}
