:root {
    --bg-color: #222;
    --text-color: #fff;
    --dim-color: #444;
    --sidebar-width: 350px;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

/* --- Mobile Header --- */
.mobile-header {
    display: none;
    height: 60px;
    background: #111;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid #333;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
    box-sizing: border-box;
}

.menu-icon {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.mobile-title {
    margin-left: 20px;
    font-weight: bold;
    letter-spacing: 2px;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    border-right: 1px solid #111;
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    transition: transform 0.3s ease;
    overflow: hidden;
}

/* --- Sidebar Header --- */
.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid #111;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* --- Mode toggle button (filter / browse) --- */
.mode-btn {
    background: none;
    border: none;
    color: #666;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    letter-spacing: 0.5px;
    transition: color 0.2s;
}
.mode-btn:hover { color: #ccc; }
.mode-btn.active { color: #fff; }

/* --- Sort --- */
.sort-container {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.sort-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-color);
    user-select: none;
}

.sort-controls { display: flex; gap: 10px; }

.sort-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.75rem;
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: color 0.2s ease;
}
.sort-btn.active { color: var(--text-color); }
.sort-btn .arrow { transition: transform 0.3s ease; }
.sort-btn[data-dir="desc"] .arrow { transform: scaleY(-1); }

/* --- Set list (browse mode) --- */
#set-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}
#set-list::-webkit-scrollbar { width: 6px; }
#set-list::-webkit-scrollbar-thumb { background-color: #333; border-radius: 10px; }
#set-list.hidden { display: none; }

.set-item {
    padding: 15px 20px;
    border-bottom: 1px solid #111;
    cursor: pointer;
    font-size: 0.85rem;
    color: #888;
}
.set-item.active { color: #fff; background: #111; font-weight: bold; }
.set-item:hover { color: #ccc; }

/* --- Filter Panel (filter mode) --- */
.filter-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.filter-panel.hidden { display: none; }

/* Global search box */
.filter-search-wrap {
    padding: 12px 14px 10px;
    border-bottom: 1px solid #111;
    flex-shrink: 0;
    position: relative;
}

#filter-search {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #fff;
    padding: 8px 10px;
    font-size: 0.8rem;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
}
#filter-search:focus { border-color: #555; }

/* Autocomplete dropdown */
.autocomplete-list {
    position: fixed;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    list-style: none;
    margin: 0;
    padding: 4px 0;
    z-index: 500;
    max-height: 280px;
    overflow-y: auto;
    box-shadow: 0 6px 16px rgba(0,0,0,0.6);
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}
.autocomplete-list.hidden { display: none; }
.autocomplete-group {
    padding: 5px 12px 3px;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #555;
    pointer-events: none;
}
.autocomplete-item {
    padding: 7px 14px;
    font-size: 0.78rem;
    color: #bbb;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.autocomplete-item:hover { background: #333; color: #fff; }

/* Active filter chips */
.active-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 8px 14px;
    border-bottom: 1px solid #111;
    flex-shrink: 0;
}
.active-filter-chips.hidden { display: none; }

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px 3px 10px;
    background: #333;
    border-radius: 12px;
    font-size: 0.7rem;
    color: #ccc;
    max-width: 180px;
    overflow: hidden;
}
.filter-chip-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chip-remove {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 0;
    font-size: 0.65rem;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s;
}
.chip-remove:hover { color: #fff; }

/* Result count row */
.filter-count-row {
    padding: 5px 14px;
    font-size: 0.6rem;
    letter-spacing: 1.5px;
    color: #555;
    text-transform: uppercase;
    border-bottom: 1px solid #111;
    flex-shrink: 0;
}

/* Scrollable filter sections */
.filter-sections {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}
.filter-sections::-webkit-scrollbar { width: 4px; }
.filter-sections::-webkit-scrollbar-thumb { background-color: #333; border-radius: 4px; }

.filter-section {
    padding: 12px 14px;
    border-bottom: 1px solid #111;
}

.filter-section-title {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #555;
    margin-bottom: 10px;
    user-select: none;
}

/* Tag sub-search */
.filter-sub-search {
    width: 100%;
    background: #242424;
    border: 1px solid #2e2e2e;
    border-radius: 4px;
    color: #aaa;
    padding: 6px 8px;
    font-size: 0.75rem;
    box-sizing: border-box;
    outline: none;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}
.filter-sub-search:focus { border-color: #444; color: #fff; }

/* Tag pills */
.filter-tag-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.tag-pill {
    padding: 4px 10px;
    border: 1px solid #2e2e2e;
    border-radius: 12px;
    font-size: 0.7rem;
    color: #777;
    background: none;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}
.tag-pill:hover { border-color: #555; color: #ccc; }
.tag-pill.active { background: #e8e8e8; border-color: #e8e8e8; color: #111; font-weight: 500; }
.tag-pill.hidden { display: none; }

/* Filter selects */
.filter-select {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #ccc;
    padding: 7px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    margin-bottom: 6px;
    box-sizing: border-box;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}
.filter-select:focus { border-color: #555; }
.filter-select option { background: #222; color: #ccc; }
.filter-select:last-child { margin-bottom: 0; }

/* Exposure 2×2 grid */
.filter-select-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.filter-select-grid .filter-select { margin-bottom: 0; }

/* Date range */
.filter-date-row {
    display: flex;
    gap: 8px;
}
.filter-date {
    flex: 1;
    min-width: 0;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #ccc;
    padding: 7px 6px;
    font-size: 0.72rem;
    outline: none;
    box-sizing: border-box;
    cursor: pointer;
}
.filter-date:focus { border-color: #555; }
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.5);
    cursor: pointer;
}

/* --- Main Content --- */
.content {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    scrollbar-width: none;
}
.content::-webkit-scrollbar { display: none; }

.image-stack { width: 100%; max-width: 1290px; }

.image-stack img {
    display: block;
    width: 100%;
    height: auto;
    margin-bottom: 5px;
    transition: opacity 0.5s ease, filter 0.5s ease;
    opacity: 0.3;
    filter: saturate(50%);
    cursor: pointer;
}
.image-stack img.in-focus { opacity: 1; filter: saturate(100%); }

#placeholder {
    color: #444;
    font-size: 0.85rem;
    margin: auto;
    letter-spacing: 1px;
}

/* --- Fullscreen Lightbox --- */
#fullscreen-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
#fullscreen-overlay.active { opacity: 1; visibility: visible; }
#fullscreen-image { max-width: 100%; max-height: 100%; transition: transform 0.1s ease-out; }
#fullscreen-overlay.hidden { display: none; }

/* --- Exposure range slider --- */
.range-wrap { padding: 2px 0 6px; width: 100%; box-sizing: border-box; }

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: #666;
    margin-bottom: 10px;
    min-height: 1em;
}

.range-track {
    position: relative;
    height: 4px;
    background: #2e2e2e;
    border-radius: 2px;
    margin: 0 10px;   /* inset to keep thumb circles inside the column */
}

.range-fill {
    position: absolute;
    height: 100%;
    background: #555;
    border-radius: 2px;
    pointer-events: none;
}

.rng-min, .rng-max {
    position: absolute;
    width: 100%;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 20px;   /* taller hit area for easier touch */
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    outline: none;
}

.rng-min::-webkit-slider-thumb,
.rng-max::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #888;
    border: 2px solid #1a1a1a;
    cursor: grab;
    pointer-events: all;
    box-sizing: border-box;
    transition: background 0.15s;
}
.rng-min::-webkit-slider-thumb:hover,
.rng-max::-webkit-slider-thumb:hover,
.rng-min:active::-webkit-slider-thumb,
.rng-max:active::-webkit-slider-thumb { background: #bbb; cursor: grabbing; }

.rng-min::-moz-range-thumb,
.rng-max::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #888;
    border: 2px solid #1a1a1a;
    cursor: grab;
    pointer-events: all;
    box-sizing: border-box;
}

.range-only-val {
    font-size: 0.7rem;
    color: #555;
}

/* --- Exposure pill subsections --- */
.filter-subsection {
    margin-bottom: 8px;
}
.filter-subsection:last-child { margin-bottom: 0; }

.filter-sub-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #444;
    margin-bottom: 5px;
    user-select: none;
}

/* Exposure range container */
.filter-exposure-pills {
    display: block;
    width: 100%;
}

/* Exposure pill buttons */
.exposure-pill {
    padding: 3px 8px;
    border: 1px solid #2e2e2e;
    border-radius: 10px;
    font-size: 0.68rem;
    color: #666;
    background: none;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}
.exposure-pill:hover { border-color: #555; color: #ccc; }
.exposure-pill.active { background: #e8e8e8; border-color: #e8e8e8; color: #111; font-weight: 500; }
.exposure-pill.unavailable { display: none; }

/* Tag unavailability (cross-filter) — hide inactive unavailable pills */
.tag-pill.unavailable:not(.active) { display: none; }

/* Lazy load sentinel — invisible trigger element */
.lazy-sentinel {
    height: 1px;
    width: 100%;
}

/* Hide sort controls in filter mode */
.sidebar.filter-mode .sort-container { display: none; }

/* --- Mobile sidebar backdrop --- */
#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 89; /* just behind sidebar z-index: 90 */
    background: rgba(0, 0, 0, 0.45);
}
#sidebar-backdrop.visible { display: block; }

/* --- Per-image info card --- */
#image-info {
    position: fixed;
    left: 0;   /* JS overrides left/right via updateInfoBarPosition */
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, rgba(17,17,17,0.92) 55%, transparent);
    padding: 18px 24px 22px;
    font-size: 0.7rem;
    color: #fff;
    letter-spacing: 0.3px;
    line-height: 1.8;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.35s ease;
    z-index: 10;
}
#image-info.visible { opacity: 1; }
.info-dot  { color: rgba(255,255,255,0.3); }
.info-tags { color: rgba(255,255,255,0.55); font-size: 0.65rem; letter-spacing: 0.2px; }
.info-item {
    pointer-events: auto;
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.15s;
}
.info-item:hover { opacity: 0.65; }
.info-tags .info-item { color: rgba(255,255,255,0.55); }
.info-tags .info-item:hover { color: #fff; opacity: 1; }
.info-location-line {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.75);
    letter-spacing: 0.4px;
}
.info-map-link {
    pointer-events: auto;
    color: rgba(255,255,255,0.35);
    text-decoration: none;
    font-size: 0.6rem;
    cursor: pointer;
    transition: color 0.15s;
    margin-left: 3px;
}
.info-map-link:hover { color: rgba(255,255,255,0.8); }

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .mobile-header { display: flex; }
    .container { padding-top: 60px; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        width: 85%;
        background: #1a1a1a;
        border-right: 1px solid #333;
    }
    .sidebar.open { transform: translateX(0); }

    #image-info { left: 0; right: 0; padding: 12px 16px 16px; }

    /* Larger touch targets on mobile */
    .tag-pill { padding: 6px 12px; font-size: 0.75rem; }
    .filter-select { padding: 10px 8px; font-size: 0.8rem; }
    .filter-date { padding: 10px 6px; font-size: 0.8rem; }
    .filter-select-grid { grid-template-columns: 1fr; }
    .autocomplete-item { padding: 10px 14px; font-size: 0.82rem; }
}
