:root {
    --brand-primary: #3b82f6;
    --brand-primary-hover: #2563eb;
    --brand-gradient: linear-gradient(135deg, #3b82f6, #2563eb);
    --surface-light: rgba(255, 255, 255, 0.85);
    --surface-border: rgba(0, 0, 0, 0.08);
    --text-primary: #1f2937;
    --shadow-soft: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.03);
}

html, body {
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(145deg, #f3f4f6, #ffffff) fixed;
    color: var(--text-primary);
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

h1:focus {
    outline: none;
}

a, .btn-link {
    color: var(--brand-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover, .btn-link:hover {
    color: var(--brand-primary-hover);
}

/* Global button styling */
.btn {
    border-radius: 0.5rem;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-weight: 500;
}

.btn-primary {
    color: #fff;
    background: var(--brand-gradient);
    border: none;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
    color: #fff;
    transform: translateY(-1px);
}

.btn-outline-primary {
    border: 1px solid var(--brand-primary);
    color: var(--brand-primary);
}

.btn-outline-primary:hover {
    background: #eff6ff;
    border-color: var(--brand-primary-hover);
    color: var(--brand-primary-hover);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem rgba(59, 130, 246, 0.4);
  outline: none;
}

/* Global inputs and cards */
.form-control, .form-select {
    border-radius: 0.5rem;
    border: 1px solid var(--surface-border);
    transition: all 0.2s ease;
    background-color: var(--surface-light);
    backdrop-filter: blur(8px);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.15);
    background-color: #fff;
}

.card {
    background: var(--surface-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 1rem;
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

/* Modals */
.modal-content {
    border-radius: 1rem;
    border: 1px solid var(--surface-border);
    background: rgba(255,255,255, 0.95);
    backdrop-filter: blur(16px);
    box-shadow: 0 25px 50px -12px rgba(0,0,0, 0.15);
}

/* Alerts */
.alert {
    border-radius: 0.75rem;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.content {
    padding-top: 1.1rem;
}

.home-stats .home-stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.2;
    color: #1b6ec2;
}

.home-stats .home-stat-loading {
    min-height: calc(1.75rem * 1.2);
}

.home-stats .home-stat-label {
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.home-stats .home-stat-card {
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.home-stats .home-stat-refresh {
    padding: 0.25rem 0.35rem;
    line-height: 1;
    margin-top: 0.1rem;
}

/* Home — Vanta.js birds hero (behind title) */
.home-page-vanta {
    position: relative;
    min-height: 11rem;
    margin-bottom: 1.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.06);
}

.home-vanta-host {
    position: absolute;
    inset: 0;
    z-index: 0;
}

/* Let mouse/touch reach the WebGL canvas for Vanta “predator” interaction */
.home-vanta-foreground {
    position: relative;
    z-index: 1;
    padding: 1.75rem 1.25rem 1.25rem;
    min-height: 11rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.08) 0%,
        rgba(255, 255, 255, 0.72) 45%,
        rgba(255, 255, 255, 0.94) 100%
    );
}

.home-vanta-foreground h1 {
    margin-bottom: 0.35rem;
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.95), 0 1px 2px rgba(255, 255, 255, 0.8);
}

.home-vanta-foreground p {
    margin-bottom: 0.25rem;
}

.home-vanta-foreground p:last-child {
    margin-bottom: 0;
}

/* Home page refresh completion toast */
.home-snackbar {
    position: fixed;
    z-index: 1080;
    left: 50%;
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    max-width: min(28rem, calc(100vw - 2rem));
    padding: 0.75rem 1.25rem;
    border-radius: 0.375rem;
    background: rgba(33, 37, 41, 0.92);
    color: #fff;
    font-size: 0.9375rem;
    line-height: 1.4;
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.2);
    pointer-events: none;
    animation: home-snackbar-in 0.25s ease-out;
}

@keyframes home-snackbar-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(0.75rem);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.setup-page {
    max-width: 40rem;
}

.tag-management-page {
    max-width: 100%;
    box-sizing: border-box;
}

/* Panel fills viewport below title/help; only the tag pills scroll — rename stays visible. */
.tag-management-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: min(85dvh, calc(100dvh - 11rem));
    min-height: 0;
    overflow: hidden;
}

.tag-management-page .tag-selector {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.tag-management-selector-top,
.tag-management-selector-foot {
    flex-shrink: 0;
}

.tag-management-page .tag-pills-scroll--tag-management {
    flex: 1 1 auto;
    min-height: 6rem;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tag-management-search {
    max-width: min(28rem, 100%);
}

.tag-management-actions {
    flex: 0 0 auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--surface-border, rgba(0, 0, 0, 0.08));
}

@media (max-width: 640.98px) {
    .tag-management-content {
        max-height: min(82dvh, calc(100dvh - 10rem));
    }
}

.download-page {
    max-width: 40rem;
}

.download-page .download-install-btn {
    width: 100%;
}

@media (min-width: 576px) {
    .download-page .download-install-btn {
        width: auto;
        min-width: 12rem;
    }
}

/* Access code login gate (shown before Router when Auth:AccessCode is set) */
.login-gate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
        max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: linear-gradient(160deg, #03173d 0%, #0a2a5c 50%, #e8eef5 50%, #f5f7fa 100%);
}

.login-gate-card {
    width: 100%;
    max-width: 22rem;
}

.login-gate-input {
    font-size: 16px;
    min-height: 44px;
}

.login-gate-submit {
    min-height: 44px;
}

.login-gate-loading {
    min-height: 40vh;
}

.nav-sign-out {
    color: #d7d7d7;
    font-size: 0.95rem;
}

.nav-sign-out:hover {
    color: #fff;
}

.setup-page code {
    font-size: 0.9em;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

    .loading-progress circle {
        fill: none;
        stroke: #e0e0e0;
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: #1b6ec2;
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }

code {
    color: #c02d76;
}

/* Upload page */
.upload-page {
    max-width: 42rem;
}

.drop-zone {
    border: 2px dashed rgba(0,0,0,0.15);
    border-radius: 1rem;
    padding: 4rem 2rem;
    text-align: center;
    background: var(--surface-light);
    backdrop-filter: blur(8px);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.02);
}

.drop-zone.drag-over {
    border-color: var(--brand-primary);
    background: rgba(59, 130, 246, 0.05);
    transform: scale(1.02);
}

.drop-zone-text {
    color: #666;
}

/* Gallery */
.gallery-page {
    max-width: 100%;
}

/* Override the layout's article padding for the gallery so the photo grid
   fills the full available content area (sidebar excluded). */
@media (min-width: 641px) {
    article.content:has(.gallery-page) {
        padding-left: 1rem !important;
        padding-right: 0.75rem !important;
    }
}

.gallery-page .nav-tabs {
    border-bottom: none;
    gap: 0.5rem;
    background: var(--surface-light);
    backdrop-filter: blur(8px);
    padding: 0.35rem;
    border-radius: 0.75rem;
    display: inline-flex;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
    border: 1px solid var(--surface-border);
}
.gallery-page .nav-tabs .nav-link {
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 1.25rem;
    background: transparent;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-weight: 500;
}
.gallery-page .nav-tabs .nav-link:hover {
    color: var(--brand-primary);
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
}
.gallery-page .nav-tabs .nav-link.active {
    color: #fff;
    background: var(--brand-gradient);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
    transform: translateY(-1px);
}

.date-filter label {
    font-size: 0.9rem;
    color: #555;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

/* Videos page: exactly five tiles per row when the layout is wide (maximized / full-screen) */
@media (min-width: 1200px) {
    .gallery-page-videos .photo-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* Video tiles use 16:9 thumbnails (server-generated JPEGs) */
.gallery-page-videos .photo-link {
    aspect-ratio: 16 / 9;
}

.photo-card {
    position: relative;
    background: var(--surface-light);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--surface-border);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.photo-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    z-index: 10;
}

.photo-card.selected {
    box-shadow: 0 0 0 3px var(--brand-primary);
    transform: scale(0.98);
}

.photo-card-checkbox {
    position: absolute;
    top: 0.35rem;
    left: 0.35rem;
    z-index: 2;
    margin: 0;
}

.photo-card-checkbox input {
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}

.selection-bar {
    display: flex;
    align-items: center;
}

.photo-link {
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    aspect-ratio: 1;
    overflow: hidden;
    text-align: left;
}

.photo-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-info {
    padding: 0.5rem;
    font-size: 0.85rem;
}

.photo-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.photo-date {
    color: #666;
}

.by-tag-search-input {
    max-width: 20rem;
}

.tag-pills-scroll {
    max-height: 9.5rem;
    overflow-y: auto;
    align-content: flex-start;
    padding: 0.25rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background: #fff;
}

/* Gallery lightbox: full image when thumbnail is clicked */
.lightbox-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.lightbox-content {
    position: relative;
    max-width: min(96vw, 1200px);
    max-height: min(92vh, 900px);
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-close {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    z-index: 10;
    width: 2.35rem;
    height: 2.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    opacity: 0.95;
}

.lightbox-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.75);
}

.lightbox-image {
    max-width: 100%;
    max-height: min(78vh, calc(100dvh - 10rem));
    object-fit: contain;
    display: block;
}

.lightbox-caption {
    color: #ccc;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: center;
}

/* Lightbox tabbed view */
.lightbox-content-tabs {
    display: flex;
    flex-direction: column;
    max-height: min(90vh, 880px);
}

.lightbox-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    flex-shrink: 0;
}

.lightbox-tab {
    padding: 0.4rem 1rem;
    border: 1px solid #555;
    background: rgba(0, 0, 0, 0.5);
    color: #ccc;
    cursor: pointer;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.lightbox-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.lightbox-tab.active {
    background: var(--brand-gradient);
    border-color: transparent;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

.lightbox-tab-danger {
    border-color: #dc3545;
    color: #f8d7da;
}

.lightbox-tab-danger:hover {
    background: rgba(220, 53, 69, 0.9);
    color: #fff;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.35);
}

.lightbox-tab-pane {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-metadata-pane {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 0.5rem;
    padding: 1rem 1.5rem;
    align-self: stretch;
    overflow: auto;
    min-width: 320px;
}

.lightbox-metadata-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lightbox-meta-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 1rem;
    align-items: baseline;
    font-size: 0.9rem;
}

.lightbox-meta-label {
    color: #999;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}

.lightbox-meta-value {
    color: #eee;
    word-break: break-all;
}

/* Gallery — phones / narrow viewports */
@media (max-width: 576px) {
    .gallery-page {
        max-width: 100%;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .gallery-page h1 {
        font-size: 1.35rem;
    }

    .gallery-page .nav-tabs {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .gallery-page .nav-tabs .nav-link {
        padding: 0.35rem 0.55rem;
        font-size: 0.8rem;
    }

    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }

    .photo-card {
        border-radius: 6px;
    }

    .photo-info {
        padding: 0.35rem 0.4rem;
        font-size: 0.72rem;
    }

    .photo-tags {
        font-size: 0.7rem;
    }

    /* Match Gallery tab .photo-grid thumbnail cell size on phones */
    .folder-thumbnails-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }

    .tag-pills .btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .by-tag-search-input {
        max-width: 100%;
        width: 100%;
    }

    .tag-pills-scroll {
        max-height: 11rem;
    }

    .lightbox-backdrop {
        padding: 0.5rem;
        align-items: center;
    }

    .lightbox-content {
        max-width: 100%;
        max-height: min(88dvh, 820px);
    }

    .lightbox-close {
        top: 0.25rem;
        right: 0.25rem;
        width: 2.1rem;
        height: 2.1rem;
        font-size: 1.35rem;
    }

    .lightbox-image {
        max-height: min(72dvh, calc(100dvh - 11rem));
    }

    .lightbox-content-tabs {
        max-height: min(86dvh, 800px);
    }

    .lightbox-tab {
        padding: 0.35rem 0.65rem;
        font-size: 0.8rem;
    }

    .lightbox-metadata-pane {
        min-width: 0;
        padding: 0.65rem 0.85rem;
    }

    .lightbox-meta-row {
        grid-template-columns: 1fr;
        gap: 0.2rem;
    }

    .lightbox-meta-label {
        font-size: 0.65rem;
    }

    .lightbox-meta-value {
        font-size: 0.82rem;
    }
}

/* Folder structure — phones & small tablets: full-width stack, tree scrolls above thumbnails */
@media (max-width: 767.98px) {
    .tree-and-thumbnails {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: 0.75rem;
        flex: 1 1 auto;
        min-height: 0;
    }

    .folder-tree-panel {
        flex: 0 0 auto;
        width: 100%;
        max-width: none;
        min-width: 0;
        max-height: min(42dvh, 300px);
        padding: 0.4rem 0.5rem;
    }

    .folder-tree-panel .folder-tree {
        font-size: 0.875rem;
    }

    .folder-thumbnails-panel {
        flex: 1 1 auto;
        min-height: 0;
        min-width: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .folder-thumbnails-panel h6 {
        font-size: 0.9rem;
        word-break: break-word;
        line-height: 1.35;
        margin-bottom: 0.5rem;
    }

    .folder-thumbnails-panel .selection-bar {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .tree-node-header {
        min-height: 44px;
        padding: 0.3rem 0.2rem;
        -webkit-tap-highlight-color: rgba(13, 110, 253, 0.12);
        touch-action: manipulation;
    }

    .tree-toggle {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.72rem;
        touch-action: manipulation;
    }

    .tree-toggle-empty {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .tree-folder-name {
        font-size: 0.9rem;
        line-height: 1.25;
        word-break: break-word;
    }

    .tree-count {
        flex-shrink: 0;
    }
}

/* Folder structure: no document scroll — fill shell, scroll inside .tree-tab */
@media (min-width: 641px) {
    .page:has(article.content .gallery-page > .tree-tab) {
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    .page:has(article.content .gallery-page > .tree-tab) main {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .page:has(article.content .gallery-page > .tree-tab) article.content {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .page:has(article.content .gallery-page > .tree-tab) article.content > *:not(.gallery-page) {
        flex-shrink: 0;
    }

    .page:has(article.content .gallery-page > .tree-tab) article.content .gallery-page:has(> .tree-tab) {
        flex: 1 1 auto;
        min-height: 0;
    }
}

@media (max-width: 640.98px) {
    .gallery-page:has(> .tree-tab) {
        height: calc(100dvh - var(--gallery-folder-mobile-top));
        max-height: calc(100dvh - var(--gallery-folder-mobile-top));
        --gallery-folder-mobile-top: 11rem;
    }
}

.gallery-page:has(> .tree-tab) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.gallery-page:has(> .tree-tab) > :not(.tree-tab) {
    flex-shrink: 0;
}

.tree-tab {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.tree-tab > p {
    flex-shrink: 0;
}

/* Tree left (scroll inside .folder-tree), thumbnails right (separate scroll) */
.tree-and-thumbnails {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 1.5rem;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    overflow: hidden;
    position: relative;
}

/* Gallery folder structure: dropdown tree above thumbnails */
.tree-and-thumbnails.tree-layout-dropdown {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
}

.tree-and-thumbnails.tree-layout-dropdown .folder-thumbnails-panel {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    z-index: 1;
}

.folder-tree-dropdown-wrap {
    width: 100%;
    max-width: 100%;
    position: relative;
}

.folder-tree-dropdown-wrap.is-open {
    z-index: 1040;
}

.folder-dropdown-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(0, 0, 0, 0.12);
}

.folder-dropdown-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: min(60vh, 480px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    padding: 0.5rem;
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.18);
}

.folder-tree-dropdown-inner {
    font-family: ui-monospace, monospace;
    font-size: 0.9rem;
}

.folder-dropdown-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    text-align: left;
}

.folder-dropdown-label-text {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-dropdown-caret {
    flex-shrink: 0;
    font-size: 0.65rem;
    line-height: 1;
    opacity: 0.75;
}

.folder-tree-panel {
    flex: 0 0 auto;
    width: min(360px, 34vw);
    min-width: 280px;
    max-width: 360px;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    padding: 0.5rem;
    background: var(--bs-body-bg, #fff);
}

.folder-thumbnails-panel {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.folder-thumbnails-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.folder-photo-card .photo-name {
    font-size: 0.75rem;
}

.folder-thumb-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-top: 0.3rem;
    line-height: 1.2;
    justify-content: center;
}

.folder-thumb-tags .badge {
    font-size: 0.62rem;
    font-weight: 500;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-tree-panel .folder-tree {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-family: ui-monospace, monospace;
    font-size: 0.9rem;
}

.tree-node {
    margin-left: 0;
}

.tree-node-header {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0;
    cursor: pointer;
    border-radius: 0.25rem;
}

.tree-node-header:hover {
    background: rgba(0, 0, 0, 0.05);
}

.tree-node-header.selected {
    background: rgba(13, 110, 253, 0.12);
}

.tree-toggle {
    width: 1.25rem;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.65rem;
    color: #666;
    flex-shrink: 0;
}

.tree-toggle-empty {
    cursor: default;
}

.tree-svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 0;
    vertical-align: middle;
}

.tree-svg svg {
    display: block;
}

.tree-svg-folder {
    color: #c9a227;
}

.tree-svg-folder-open {
    color: #d4a524;
}

.tree-node-header.selected .tree-svg-folder,
.tree-node-header.selected .tree-svg-folder-open {
    color: #0b5ed7;
}

.tree-svg-file {
    color: #6c757d;
}

.tree-folder-name {
    font-weight: 500;
}

.tree-count {
    color: #666;
    font-weight: normal;
    font-size: 0.85em;
}

.tree-children {
    margin-left: 1.25rem;
    border-left: 1px solid #dee2e6;
    padding-left: 0.5rem;
}

.tree-file {
    padding: 0.1rem 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.tree-file-name {
    color: #333;
    font-weight: normal;
}

/* Photo tags on cards */
.photo-tags {
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.2rem;
}

/* Right-click tag context menu */
.tag-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
}

.tag-menu {
    position: fixed;
    min-width: 220px;
    max-width: 320px;
    max-height: 70vh;
    overflow: auto;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    padding: 0.5rem 0;
    z-index: 9999;
}

.tag-menu-title {
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    font-size: 0.9rem;
}

.tag-menu-add {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #eee;
}

.tag-menu-add input {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 0.25rem;
    font-size: 0.9rem;
}

.tag-menu-list {
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.tag-menu-item {
    padding: 0.35rem 0.5rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    border-radius: 0.25rem;
    font-size: 0.9rem;
}

.tag-menu-item:hover {
    background: #f0f0f0;
}

.tag-menu-item.on {
    background: #e3f2fd;
    color: #1565c0;
}

/* Tag menu on phones: cursor coords are wrong/off-screen — center as a modal */
@media (max-width: 576px) {
    .tag-menu-backdrop {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
            max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
        background: rgba(0, 0, 0, 0.45);
    }

    .tag-menu {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        width: min(100%, 22rem);
        max-width: none;
        min-width: 0;
        max-height: min(85vh, 32rem);
        overflow: auto;
        margin: 0;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevents iOS zoom on input focus; larger tap targets */
    .tag-menu-add {
        flex-wrap: wrap;
    }

    .tag-menu-add input {
        flex: 1 1 100%;
        min-width: 0;
        font-size: 16px;
        padding: 0.5rem;
    }

    .tag-menu-add .btn {
        flex: 1;
        min-height: 44px;
        padding: 0.5rem 0.75rem;
    }

    .tag-menu-item {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
    }
}

/* Tag rename modal (above tag context menu z-index) */
.tag-rename-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: rgba(0, 0, 0, 0.45);
}

.tag-rename-modal-dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 10051;
    width: min(100%, 26rem);
    max-height: min(90vh, 32rem);
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.tag-rename-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.tag-rename-modal-title {
    font-size: 1rem;
    font-weight: 600;
}

.tag-rename-modal-body {
    padding: 1rem;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tag-rename-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: #fff;
}

/* Gallery: date range filter (opens as dialog) */
.date-range-open-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.45rem 0.85rem;
    text-align: left;
}

.date-range-open-icon {
    display: inline-flex;
    flex-shrink: 0;
}

.date-range-open-label {
    white-space: normal;
    word-break: break-word;
}

.date-range-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
        max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: rgba(0, 0, 0, 0.45);
    -webkit-overflow-scrolling: touch;
    outline: none;
}

.date-range-dialog {
    width: min(100%, 26rem);
    max-height: min(90vh, 32rem);
    overflow: auto;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.2);
    padding: 1rem 1.1rem 1.1rem;
}

.date-range-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.date-range-dialog-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
    padding-right: 0.25rem;
}

.date-range-dialog-close {
    font-size: 1.75rem;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    text-decoration: none;
    margin: -0.35rem -0.25rem 0 0;
}

.date-range-dialog-close:hover {
    color: #212529;
}

.date-range-dialog-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.date-range-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: 0;
}

.date-range-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #495057;
}

.date-range-field .form-control {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
}

.date-range-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.date-range-dialog-actions .btn {
    min-height: 44px;
}

@media (max-width: 576px) {
    .date-range-dialog {
        width: 100%;
        max-height: min(92vh, 100%);
        align-self: flex-end;
        border-radius: 0.75rem 0.75rem 0 0;
        margin-top: auto;
        padding-bottom: max(1.1rem, env(safe-area-inset-bottom));
    }

    .date-range-dialog-backdrop {
        align-items: flex-end;
        padding-bottom: 0;
    }

    .date-range-dialog-actions {
        flex-direction: column;
    }

    .date-range-dialog-actions .btn {
        width: 100%;
    }
}

.face-ref-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
    padding: 0.25rem;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 0.375rem;
    background: rgba(0, 0, 0, 0.02);
}

.face-ref-thumb {
    width: 88px;
    height: 88px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 0.25rem;
    overflow: hidden;
    background: #21262d;
    cursor: pointer;
}

.face-ref-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.face-ref-thumb-selected {
    border-color: #1b6ec2;
    box-shadow: 0 0 0 2px rgba(27, 110, 194, 0.35);
}

.face-history-table .face-history-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    flex-shrink: 0;
}

.face-ref-selected-preview {
    width: 56px;
    height: 56px;
    object-fit: cover;
}

.face-ref-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(0, 0, 0, 0.5);
}

.face-ref-modal-dialog {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
        max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
    pointer-events: none;
}

.face-ref-modal-content {
    pointer-events: auto;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    border-radius: 0.5rem;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
    max-width: min(960px, 100%);
    width: 100%;
    max-height: min(90dvh, calc(100dvh - 1.5rem), 900px);
    height: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.face-ref-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.face-ref-modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.face-ref-modal-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.face-ref-modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.face-ref-modal-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 0.375rem;
    overflow: hidden;
    background: #21262d;
    cursor: pointer;
    text-align: left;
}

.face-ref-modal-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.face-ref-modal-name {
    font-size: 0.7rem;
    padding: 0.35rem 0.4rem;
    color: #e5e7eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.face-ref-modal-item-selected {
    border-color: #1b6ec2;
    box-shadow: 0 0 0 2px rgba(27, 110, 194, 0.35);
}

/* Mobile override (must be at end of file):
   Desktop rules for the folder tree appear later in this stylesheet and can override
   earlier mobile media queries, so we force the stacked layout again here. */
@media (max-width: 767.98px) {
    .tree-and-thumbnails {
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .folder-tree-panel {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        max-height: min(42dvh, 300px) !important;
        padding: 0.4rem 0.5rem !important;
    }

    .folder-tree-panel .folder-tree {
        max-height: min(38dvh, 268px) !important;
        font-size: 0.875rem !important;
    }

    .folder-dropdown-panel {
        max-height: min(50dvh, 360px) !important;
    }

    .tree-node-header {
        min-height: 44px !important;
        padding: 0.3rem 0.2rem !important;
        touch-action: manipulation !important;
    }

    .tree-toggle {
        min-width: 44px !important;
        min-height: 44px !important;
        width: auto !important;
        touch-action: manipulation !important;
        padding: 0 !important;
    }

    .tree-toggle-empty {
        min-width: 44px !important;
        min-height: 44px !important;
    }
}
