/* styles.css */
:root {
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --accent-color: #FFD700;
    --background-color: #f8fafc;
    --card-color: #ffffff;
    --text-color: #333333;
    --border-color: #e2e8f0;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: var(--transition);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0.5rem;
}

/* Header Improvements */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    border-radius: 12px;
    background-color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

header h1 {
    color: var(--secondary-color);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* Fix dark mode header styling */
body.dark-mode header {
    background-color: #1e1e1e;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

body.dark-mode header h1 {
    color: #fff;
    /* Make title clearly visible in dark mode */
}

@media (max-width: 768px) {
    header {
        padding: 0.75rem 1rem;
        border-radius: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    /* Change header text to be more compact */
    header h1 {
        font-size: 1.2rem;
        margin: 0;
    }

    /* Make header text shorter */
    header h1::after {
        content: "Images";
        display: block;
    }

    header h1 {
        font-size: 0;
        /* Hide the original text */
    }

    /* Make controls fit in one row */
    .header-controls {
        display: flex;
        align-items: center;
        flex-wrap: nowrap;
        gap: 4px;
    }

    /* Adjust filter toggle and dark mode buttons */
    #filter-toggle,
    #dark-mode-toggle {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
        min-width: 0;
        height: 32px;
        white-space: nowrap;
        border-radius: 4px;
    }

    /* Make filter button more compact */
    #filter-toggle {
        width: auto;
    }

    /* Make dark mode button match filter button height */
    #dark-mode-toggle {
        box-sizing: border-box;
        line-height: 1;
    }

    /* Make sort selector smaller */
    .sort-wrapper {
        flex-shrink: 1;
    }

    #sort-by {
        padding: 0.4rem 1.2rem 0.4rem 0.4rem;
        font-size: 0.8rem;
        min-width: 0;
        height: 32px;
        background-position: right 0.4rem center;
        background-size: 8px 5px;
    }
}

/* Header Controls */
.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#filter-toggle {
    padding: 0.5rem 1rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#filter-toggle:hover {
    background-color: #2980b9;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Dark Mode Toggle */
#dark-mode-toggle {
    padding: 0.5rem 1rem;
    background-color: #555;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 100px;
    text-align: center;
}

#dark-mode-toggle:hover {
    background-color: #444;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#dark-mode-toggle.active {
    background-color: #FFD700;
    color: #333;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode #dark-mode-toggle {
    background-color: #FFD700;
    color: #333;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode #dark-mode-toggle:hover {
    background-color: #ffde45;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Filter Panel */
.filter-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    z-index: 100;
    padding: 1rem;
    display: none;
    flex-direction: column;
    overflow-y: auto;
}

.filter-panel.open {
    display: flex;
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

#close-filter {
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
}

.category-filters {
    margin-bottom: 1rem;
}

#category-select {
    width: 100%;
    min-height: 300px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
}

.filter-actions button {
    width: 100%;
    padding: 0.75rem;
    background-color: #95a5a6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.filter-actions button:hover {
    background-color: #7f8c8d;
}

/* Add this to your CSS file */
.category-search {
    margin-bottom: 0.5rem;
}

.category-search input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.select-buttons {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.select-btn {
    flex: 1;
    padding: 0.4rem;
    background-color: #f0f0f0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.select-btn:hover {
    background-color: #e0e0e0;
}

/* Status Bar with Modern Image Count */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

#image-count {
    background-color: #f0f4f8;
    color: #2d3748;
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    font-weight: 500;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

#image-count::before {
    content: "📷";
    margin-right: 6px;
    font-size: 1rem;
}

body.dark-mode #image-count {
    background-color: #2d3748;
    color: #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode .status-bar {
    background-color: #121212;
}

@media (max-width: 768px) {
    header {
        padding: 0.75rem 1rem;
        border-radius: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    /* Fix for mobile status bar scrolling issue */
    .status-bar {
        padding: 0.5rem 1rem;
        background-color: white;
        border-bottom: 1px solid #eee;
        position: static;
        /* Change from sticky to static */
        /* Remove the top property */
        /* Keep z-index just in case it's needed elsewhere */
        z-index: 5;
        transition: all 0.3s ease;
    }

    body.dark-mode .status-bar {
        background-color: #1e1e1e;
        border-bottom: 1px solid #333;
    }

    #image-count {
        font-size: 0.8rem;
        padding: 0.3rem 0.6rem;
    }
}

/* Custom dropdown styling */
#sort-by {
    appearance: none;
    /* Remove default dropdown styling */
    -webkit-appearance: none;
    /* For Safari */
    -moz-appearance: none;
    /* For Firefox */
    background-color: var(--card-color);
    /* Light mode background */
    color: var(--text-color);
    /* Light mode text color */
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.4rem 1.5rem 0.4rem 0.8rem;
    /* Add padding for custom arrow */
    font-size: 0.9rem;
    cursor: pointer;
    position: relative;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path fill="%23333" d="M0 0l5 6 5-6z"/></svg>');
    /* Custom arrow */
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 10px 6px;
    transition: all 0.3s ease;
}

#sort-by:hover {
    background-color: #f0f0f0;
    /* Slightly lighter background on hover */
}

#sort-by:focus {
    outline: none;
    border-color: var(--primary-color);
    /* Highlight border on focus */
}

/* Dark mode styles for the dropdown */
body.dark-mode #sort-by {
    background-color: #333;
    /* Dark mode background */
    color: #ddd;
    /* Dark mode text color */
    border-color: #444;
    /* Dark mode border */
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path fill="%23ddd" d="M0 0l5 6 5-6z"/></svg>');
    /* Custom arrow for dark mode */
}

body.dark-mode #sort-by:hover {
    background-color: #444;
    /* Slightly lighter background on hover in dark mode */
}

body.dark-mode #sort-by:focus {
    border-color: #FFD700;
    /* Highlight border on focus in dark mode */
}

/* Gallery Styles - Desktop Default */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.gallery-item {
    position: relative;
    background-color: var(--card-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border: none;
}

.gallery-item:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.gallery-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.gallery-item-tags {
    padding: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tag {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    background-color: rgba(240, 240, 240, 0.9);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    border-radius: 20px;
    color: #555;
    transition: var(--transition);
    border: none;
}

.tag:hover {
    background-color: #e0e0e0;
}

.hidden {
    display: none;
}

.loading {
    text-align: center;
    padding: 2rem;
    grid-column: 1 / -1;
}

#loading-indicator {
    color: var(--primary-color);
    font-weight: bold;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    margin: 1.5rem 0;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.page-button {
    padding: 0.5rem 0.75rem;
    background-color: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.page-button:hover {
    background-color: #f0f4f8;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.page-button.active {
    background-color: var(--primary-color);
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-sm);
}

.page-ellipsis {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.5rem;
}

/* Modal Styles - Only for Desktop */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    overflow: auto;
}

.modal-content {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    text-shadow: 0 0 3px black;
    z-index: 1;
}

#modal-image {
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain;
    margin: auto;
}

#modal-info {
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

/* Mobile Styles */
@media (max-width: 768px) {
    body {
        background-color: white;
    }

    .container {
        padding: 0;
    }

    header {
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: white;
        padding: 0.5rem;
        margin-bottom: 0;
        border-bottom: 1px solid #eee;
    }

    header h1 {
        font-size: 1.2rem;
    }

    /* Fix for mobile status bar - force it to be non-sticky */
    .status-bar {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
        position: static !important;
        /* Force override any other definitions */
        background-color: white;
        border-bottom: 1px solid #eee;
    }

    /* Instagram/TikTok style feed */
    .gallery-grid {
        display: flex;
        flex-direction: column;
        gap: 1px;
        background-color: #fafafa;
    }

    .gallery-item {
        width: 100%;
        border-radius: 0;
        box-shadow: none;
        margin-bottom: 8px;
    }

    .gallery-item img {
        width: 100%;
        aspect-ratio: 4/5;
        /* More portrait oriented for feed */
        object-fit: cover;
    }

    .gallery-item-tags {
        padding: 0.25rem 0.5rem;
        background-color: white;
    }

    .tag {
        font-size: 0.7rem;
        padding: 0.1rem 0.3rem;
        background-color: transparent;
        color: #777;
    }

    /* Hide modal functionality on mobile */
    .modal {
        display: none !important;
    }

    .pagination {
        padding: 0.5rem;
        background-color: white;
        border-top: 1px solid #eee;
    }

    .page-button {
        padding: 0.4rem 0.6rem;
        font-size: 0.9rem;
    }
}

/* Active Filters */
.active-filters {
    display: flex;
    align-items: center;
    padding: 10px 0;
    flex-wrap: wrap;
    gap: 8px;
}

.active-filters-label {
    font-weight: bold;
    margin-right: 8px;
}

.active-filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-tag {
    background-color: #f0f4f8;
    border-radius: var(--radius-lg);
    padding: 0.3rem 0.8rem;
    font-size: 0.9em;
    display: inline-flex;
    align-items: center;
    transition: var(--transition);
    border: 1px solid transparent;
}

.filter-tag:hover {
    background-color: #e6ebf0;
    border-color: #d0d7de;
}

.filter-tag .remove-filter {
    margin-left: 6px;
    cursor: pointer;
    font-size: 1.1em;
    opacity: 0.7;
    transition: var(--transition);
}

.filter-tag .remove-filter:hover {
    opacity: 1;
}

/* Dark mode toggle */
.dark-mode-wrapper {
    margin: 0;
}

#dark-mode-toggle {
    padding: 0.5rem 1rem;
    background-color: #555;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 100px;
    text-align: center;
}

#dark-mode-toggle:hover {
    background-color: #444;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#dark-mode-toggle.active {
    background-color: #FFD700;
    color: #333;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode #dark-mode-toggle {
    background-color: #FFD700;
    color: #333;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode #dark-mode-toggle:hover {
    background-color: #ffde45;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Dark mode styles */
body.dark-mode {
    --background-color: #0f172a;
    --card-color: #1e293b;
    --text-color: #e2e8f0;
    --border-color: #334155;
}

body.dark-mode header {
    background-color: #1e1e1e;
}

body.dark-mode .filter-panel {
    background-color: #1e1e1e;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

body.dark-mode .gallery-item {
    background-color: #2d2d2d;
    border: 1px solid #333;
}

body.dark-mode .modal-content {
    background-color: #2d2d2d;
}

body.dark-mode .tag {
    background-color: rgba(51, 65, 85, 0.9);
    color: #e2e8f0;
}

body.dark-mode .tag:hover {
    background-color: rgba(71, 85, 105, 0.9);
}

body.dark-mode .filter-tag {
    background-color: #2d3748;
    color: #e2e8f0;
}

body.dark-mode .filter-tag:hover {
    background-color: #3a4458;
}

body.dark-mode .page-button {
    background-color: #333 !important;
    /* Force override any inline styles */
    color: #ddd;
    border-color: #444;
}

body.dark-mode .page-button.active {
    background-color: #666 !important;
}

body.dark-mode select,
body.dark-mode button:not(#dark-mode-toggle),
body.dark-mode input {
    background-color: #333;
    color: #ddd;
    border-color: #444;
}

/* Mobile optimizations for dark mode toggle */
@media (max-width: 768px) {
    #dark-mode-toggle {
        padding: 0.4rem 0.7rem;
        font-size: 0.8rem;
        min-width: 80px;
    }

    .filter-toggle-wrapper,
    .dark-mode-wrapper {
        flex: 1;
    }

    .header-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .sort-wrapper {
        width: 100%;
        order: 3;
    }
}

/* Improved dark mode styles with better mobile support */
body.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

body.dark-mode header,
body.dark-mode .status-bar,
body.dark-mode .filter-panel,
body.dark-mode .gallery-grid,
body.dark-mode .pagination {
    background-color: #1e1e1e;
}

body.dark-mode .gallery-item {
    background-color: #2d2d2d;
    border: 1px solid #333;
}

body.dark-mode .gallery-item-tags {
    background-color: #2d2d2d;
}

body.dark-mode .tag {
    background-color: #444;
    color: #ddd;
}

body.dark-mode .filter-tag {
    background-color: #444;
    color: #ddd;
}

body.dark-mode .modal-content {
    background-color: #2d2d2d;
}

body.dark-mode .page-button {
    background-color: #333 !important;
    /* Force override any inline styles */
    color: #ddd;
    border-color: #444;
}

body.dark-mode .page-button.active {
    background-color: #666 !important;
}

body.dark-mode .page-ellipsis {
    color: #ddd;
}

/* Fix for select elements and buttons in dark mode */
body.dark-mode select,
body.dark-mode button:not(#dark-mode-toggle),
body.dark-mode input {
    background-color: #333;
    color: #ddd;
    border-color: #444;
}

body.dark-mode #image-count,
body.dark-mode .loading-indicator,
body.dark-mode .active-filters {
    background-color: #1e1e1e;
    color: #ddd;
}

/* Fix for spaces between images */
body.dark-mode .gallery-grid {
    background-color: #121212;
    gap: 10px;
    /* Make sure gap is not showing white */
}

/* Fix for mobile-specific issues */
@media (max-width: 768px) {
    body.dark-mode .gallery-item {
        border-color: #333;
    }

    body.dark-mode .gallery-grid {
        background-color: #121212;
    }

    body.dark-mode .gallery-item-tags {
        background-color: rgba(45, 45, 45, 0.95);
    }
}

/* Apply dark mode to any elements that might have been missed */
body.dark-mode * {
    border-color: #444;
}

/* Sort By Dropdown */
#sort-by {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0.5rem 1.5rem 0.5rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
    position: relative;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path fill="%23333" d="M0 0l5 6 5-6z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    background-size: 10px 6px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#sort-by:hover {
    background-color: #eaeaea;
    border-color: #ccc;
}

#sort-by:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 4px rgba(52, 152, 219, 0.5);
}

/* Dark Mode Styles */
body.dark-mode #sort-by {
    background-color: #333;
    color: #ddd;
    border-color: #444;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path fill="%23ddd" d="M0 0l5 6 5-6z"/></svg>');
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

body.dark-mode #sort-by:hover {
    background-color: #444;
    border-color: #555;
}

body.dark-mode #sort-by:focus {
    border-color: #FFD700;
    box-shadow: 0 0 4px rgba(255, 215, 0, 0.5);
}

body.dark-mode #filter-toggle {
    background-color: #444;
    color: #ddd;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

body.dark-mode #filter-toggle:hover {
    background-color: #555;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.7);
}

body.dark-mode #dark-mode-toggle {
    background-color: rgba(255, 215, 0, 0.2);
    color: #FFD700;
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.3);
}

body.dark-mode #dark-mode-toggle:hover {
    background-color: rgba(255, 215, 0, 0.3);
    box-shadow: 0 4px 8px rgba(255, 215, 0, 0.5);
}

/* Mobile optimizations */
@media (max-width: 768px) {

    /* Header styles */
    header {
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: white;
        padding: 0.5rem;
        margin-bottom: 0;
    }

    header h1 {
        font-size: 1.1rem;
        margin: 0;
    }

    /* Fix controls layout on mobile */
    .header-controls {
        display: flex;
        align-items: center;
        flex-wrap: nowrap;
        gap: 4px;
        /* Reduced gap between elements */
        justify-content: flex-start;
    }

    /* Button containers should not take extra space */
    .filter-toggle-wrapper,
    .dark-mode-wrapper {
        display: inline-flex;
        margin: 0;
    }

    /* Make buttons more compact but still tappable */
    #filter-toggle,
    #dark-mode-toggle {
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
        height: 32px;
        white-space: nowrap;
        border-radius: 4px;
        min-width: 0;
    }

    /* Sort dropdown needs to be smaller but still usable */
    .sort-wrapper {
        margin-left: auto;
        /* Push to right side */
    }

    #sort-by {
        padding: 0.4rem 1.2rem 0.4rem 0.4rem;
        font-size: 0.75rem;
        height: 32px;
        background-position: right 0.4rem center;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {

    /* Header styles */
    header {
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: white;
        padding: 0.5rem;
        margin-bottom: 0;
    }

    /* Fix duplicate Images issue - remove the CSS that adds another "Images" */
    header h1 {
        font-size: 1.1rem;
        margin: 0;
    }

    /* Remove these problematic rules that create the duplicate "Images" */
    header h1::after {
        content: none;
    }

    /* Fix controls layout on mobile - ensure everything fits on one line */
    .header-controls {
        display: flex;
        align-items: center;
        flex-wrap: nowrap;
        gap: 3px;
        /* Even smaller gap between elements */
        justify-content: space-between;
    }

    /* Button containers shouldn't take extra space */
    .filter-toggle-wrapper,
    .dark-mode-wrapper {
        display: inline-flex;
        margin: 0;
        flex-shrink: 1;
    }

    /* Make buttons more compact */
    #filter-toggle,
    #dark-mode-toggle {
        padding: 0.3rem 0.4rem;
        font-size: 0.75rem;
        height: 32px;
        border-radius: 4px;
        min-width: 0;
        white-space: nowrap;
    }

    /* Make sort dropdown smaller */
    .sort-wrapper {
        flex-shrink: 1;
        max-width: 85px;
    }

    #sort-by {
        padding: 0.4rem 1rem 0.4rem 0.3rem;
        font-size: 0.75rem;
        height: 32px;
        background-position: right 0.3rem center;
        background-size: 7px 4px;
        width: 100%;
    }

    /* Override any other conflicting styles */
    .dark-mode-wrapper {
        flex: initial !important;
    }

    .filter-toggle-wrapper {
        flex: initial !important;
    }

    /* Override the other conflicting styles */
    .header-controls {
        flex-wrap: nowrap !important;
    }
}

/* Mobile optimizations - consolidated version */
@media (max-width: 768px) {

    /* Header styles */
    header {
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: white;
        padding: 0.5rem;
        margin-bottom: 0;
        border-bottom: 1px solid #eee;
    }

    header h1 {
        font-size: 1.1rem;
        margin: 0;
    }

    /* Fix header controls layout */
    .header-controls {
        display: flex;
        align-items: center;
        flex-wrap: nowrap !important;
        /* Force single line */
        gap: 6px;
        /* Slightly more space between items */
        justify-content: space-between;
    }

    /* Button containers */
    .filter-toggle-wrapper,
    .dark-mode-wrapper {
        display: inline-flex;
        margin: 0;
        flex-shrink: 1;
        flex: initial !important;
        /* Prevent flex growing */
    }

    /* Make buttons compact but with enough room */
    #filter-toggle,
    #dark-mode-toggle {
        padding: 0.35rem 0.45rem;
        font-size: 0.75rem;
        height: 32px;
        border-radius: 4px;
        white-space: nowrap;
    }

    /* Allow dark mode button to shrink a bit */
    #dark-mode-toggle {
        min-width: 0;
        width: auto;
    }

    /* Optimize sort dropdown */
    .sort-wrapper {
        flex-shrink: 2;
        /* Allow more shrinking */
        width: auto;
    }

    #sort-by {
        font-size: 0.75rem;
        height: 32px;
        padding: 0.35rem 1.2rem 0.35rem 0.35rem;
        background-position: right 0.3rem center;
        background-size: 7px 4px;
        width: auto;
        min-width: 0;
    }

    /* Disable any conflicting rules */
    .sort-wrapper {
        width: auto !important;
        order: initial !important;
    }

    /* Fix for mobile status bar */
    .status-bar {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
        position: static !important;
        background-color: white;
        border-bottom: 1px solid #eee;
    }

    body.dark-mode .status-bar {
        background-color: #1e1e1e;
        border-bottom: 1px solid #333;
    }

    #image-count {
        font-size: 0.8rem;
        padding: 0.3rem 0.6rem;
    }
}

/* Desktop/Mobile visibility classes */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

/* Mobile Filters */
.mobile-filters {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #eee;
    background-color: white;
    transition: all 0.3s ease;
}

.mobile-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

#mobile-category-search {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.mobile-filter-action {
    background-color: #f0f0f0;
    border: none;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    font-size: 0.85rem;
}

.mobile-categories-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 120px;
    overflow-y: auto;
    padding-bottom: 0.5rem;
}

.category-tag {
    background-color: #f0f4f8;
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    -webkit-user-select: none;
    user-select: none;
}

.category-tag::before {
    content: "#";
    opacity: 0.7;
}

.category-tag.selected {
    background-color: #3498db;
    color: white;
    border-color: #2980b9;
}

/* Dark mode styles for mobile filters */
body.dark-mode .mobile-filters {
    background-color: #1e1e1e;
    border-bottom: 1px solid #333;
}

body.dark-mode #mobile-category-search {
    background-color: #333;
    border-color: #444;
    color: #ddd;
}

body.dark-mode .mobile-filter-action {
    background-color: #333;
    color: #ddd;
}

body.dark-mode .category-tag {
    background-color: #333;
    color: #ddd;
}

body.dark-mode .category-tag.selected {
    background-color: #2980b9;
    color: white;
}

/* Mobile media query */
@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }

    .mobile-only {
        display: block;
    }
}

/* Password Prompt Styles */
.password-prompt {
    display: none;
    /* Hidden by default, shown via JS */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 2000;
    padding: 20px;
    color: white;
}

.password-prompt h2 {
    margin-bottom: 1rem;
}

.password-prompt input[type="password"] {
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100%;
    max-width: 300px;
    font-size: 1rem;
}

.password-prompt button {
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s ease;
}

.password-prompt button:hover {
    background-color: #2980b9;
}

.error-message {
    color: #e74c3c;
    margin-top: 0.5rem;
    font-weight: bold;
}

/* Dark mode adjustments for password prompt */
body.dark-mode .password-prompt {
    background-color: rgba(20, 20, 20, 0.85);
    color: #e0e0e0;
}

body.dark-mode .password-prompt input[type="password"] {
    background-color: #333;
    color: #ddd;
    border-color: #555;
}

body.dark-mode .password-prompt button {
    background-color: #FFD700;
    /* Use accent color for button in dark mode */
    color: #333;
}

body.dark-mode .password-prompt button:hover {
    background-color: #ffde45;
}

body.dark-mode .error-message {
    color: #f1948a;
}

/* Ensure main content is hidden correctly */