.custom-catalog {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.catalog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
    padding-bottom: 20px;
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.upload-form {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.category-management {
    display: flex;
    gap: 10px;
    align-items: center;
}

.category-management select {
    flex: 1;
}

.new-category-input {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
}

.new-category-input input {
    flex: 1;
    margin: 0;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    color: white; /* Ensure button text is white */
}

.btn-primary {
    background: #007cba;
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-link {
    background: none;
    color: #007cba;
    text-decoration: underline;
    padding: 8px 12px;
}

.catalog-search {
    margin-bottom: 30px;
}

.search-container {
    position: relative;
    max-width: 500px;
}

#global-search {
    width: 100%;
    padding: 12px 40px 12px 15px;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

#global-search:focus {
    outline: none;
    border-color: #007cba;
}

.search-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
}

.search-results-count {
    margin-top: 10px;
    color: #666;
    font-style: italic;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.gallery-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    background: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s ease;
}

.gallery-item:hover {
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    transform: translateY(-2px);
}

.item-image {
    text-align: center;
    margin-bottom: 10px;
}

.item-image img {
    max-width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 4px;
}

.item-info div {
    margin-bottom: 5px;
}

.item-name {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.item-box,
.item-category {
    color: #666;
    font-size: 0.9em;
}

/* Edit and Delete buttons in gallery */
.item-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.btn-edit, .btn-delete {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 3px;
    border: none;
    cursor: pointer;
    color: white; /* Ensure button text is visible */
}

.btn-edit {
    background: #007cba;
    color: white;
}

.btn-delete {
    background: #dc3545;
    color: white;
}

.btn-edit:hover {
    background: #006ba1;
}

.btn-delete:hover {
    background: #c82333;
}

/* Pagination - FIXED TEXT COLOR */
.catalog-pagination {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.pagination-btn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    min-width: 60px;
    color: #333; /* Fixed: Dark text for readability */
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: #f8f9fa;
    border-color: #007cba;
    color: #007cba;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: #999; /* Grey text for disabled state */
}

.page-numbers {
    display: flex;
    gap: 5px;
}

.page-number {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    min-width: 36px;
    color: #333; /* Fixed: Dark text for readability */
    transition: all 0.2s ease;
}

.page-number:hover {
    background: #f8f9fa;
    border-color: #007cba;
    color: #007cba;
}

.page-number.active {
    background: #007cba;
    color: white; /* White text on blue background */
    border-color: #007cba;
}

.page-ellipsis {
    padding: 6px;
    color: #666;
    display: flex;
    align-items: center;
}

.pagination-info {
    text-align: center;
    color: #666;
    font-size: 14px;
    margin-top: 10px;
}

/* Loading state */
.loading-state {
    text-align: center;
    padding: 40px;
    font-size: 18px;
    color: #666;
    grid-column: 1 / -1;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.empty-state h3 {
    margin-bottom: 10px;
    color: #333;
}

/* Stats display */
.catalog-stats {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 14px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #007cba;
}

.stat-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Results per page selector */
.results-per-page {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    color: #666;
}

.results-per-page select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    color: #333;
}

/* Lightbox Styles - Mobile Fix */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px; /* Add padding for mobile */
    box-sizing: border-box; /* Include padding in height calculation */
}

.lightbox-content {
    background: white;
    border-radius: 8px;
    max-width: 90%;
    max-height: 90vh; /* Changed from 90% to 90vh for better control */
    width: 800px;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent content from spilling out */
}

.lightbox-close {
    position: absolute;
    top: 10px; /* Reduced from 15px for mobile */
    right: 15px; /* Reduced from 20px for mobile */
    font-size: 24px; /* Reduced from 30px for mobile */
    color: #333;
    cursor: pointer;
    z-index: 10001;
    background: white;
    width: 36px; /* Reduced from 40px */
    height: 36px; /* Reduced from 40px */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2); /* Add shadow for better visibility */
}

.lightbox-close:hover {
    background: #f0f0f0;
}

.lightbox-body {
    display: flex;
    max-height: calc(90vh - 60px); /* Account for close button and padding */
    overflow: hidden; /* Prevent overflow */
}

.lightbox-image {
    flex: 1;
    padding: 15px; /* Reduced from 20px */
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9f9f9;
    min-height: 150px; /* Minimum height for image area */
    max-height: 50vh; /* Limit image height */
    overflow: hidden; /* Prevent image overflow */
}

.lightbox-image img {
    max-width: 100%;
    max-height: 100%; /* Changed from 70vh to 100% of parent */
    width: auto;
    height: auto;
    object-fit: contain;
}

.lightbox-info {
    flex: 1;
    padding: 20px; /* Reduced from 30px */
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Changed from center */
    overflow-y: auto; /* Allow scrolling if content is too long */
    max-height: 100%; /* Take full height of parent */
}

.lightbox-info h3 {
    margin-bottom: 15px; /* Reduced from 20px */
    color: #333;
    font-size: 1.3em; /* Reduced from 1.5em */
    line-height: 1.3;
    word-wrap: break-word; /* Prevent long words from breaking layout */
}

.info-item {
    margin-bottom: 12px; /* Reduced from 15px */
    line-height: 1.4;
}

.info-item strong {
    display: block;
    color: #666;
    font-size: 0.85em; /* Reduced from 0.9em */
    margin-bottom: 3px; /* Reduced from 5px */
}

/* Lightbox actions */
.lightbox-actions {
    margin-top: 15px; /* Reduced from 20px */
    display: flex;
    gap: 8px; /* Reduced from 10px */
    flex-wrap: wrap; /* Allow buttons to wrap on very small screens */
}

.lightbox-actions .btn {
    padding: 10px 15px; /* Adjusted padding */
    font-size: 14px; /* Ensure consistent font size */
    flex: 1; /* Make buttons flexible */
    min-width: 120px; /* Minimum width for buttons */
    text-align: center;
    color: white; /* Ensure button text is white */
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: none;
}

.btn-danger:hover {
    background: #c82333;
}

/* Edit Modal */
.edit-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.edit-modal-content {
    background: white;
    border-radius: 8px;
    max-width: 90%;
    max-height: 90%;
    width: 600px;
    padding: 30px;
    position: relative;
    overflow-y: auto;
}

.edit-modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 30px;
    color: #333;
    cursor: pointer;
    line-height: 1;
}

.edit-modal-close:hover {
    color: #666;
}

.current-image-preview {
    margin-bottom: 15px;
    text-align: center;
}

.current-image-preview img {
    max-width: 200px;
    max-height: 150px;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
}

.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Delete Modal */
.delete-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-modal-content {
    background: white;
    border-radius: 8px;
    max-width: 90%;
    width: 400px;
    padding: 30px;
    text-align: center;
}

.delete-preview {
    margin: 20px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
}

.delete-preview-content img {
    max-width: 150px;
    max-height: 100px;
    object-fit: contain;
    margin-bottom: 10px;
}

.delete-form {
    margin: 20px 0;
    text-align: left;
}

.delete-form .form-group {
    margin-bottom: 15px;
}

.delete-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.delete-form input[type="password"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
    color: #333; /* Ensure password text is visible */
}

.delete-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Modal open state */
body.lightbox-open,
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

.catalog-message {
    padding: 12px 20px;
    margin: 10px 0;
    border-radius: 4px;
    font-weight: bold;
}

.message-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.catalog-login {
    max-width: 400px;
    margin: 50px auto;
    padding: 30px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.catalog-login h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

/* Optimize images */
.gallery-item img {
    max-width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 4px;
    background: #f5f5f5; /* Placeholder color */
}

/* Will-change hint for smooth animations */
.gallery-item {
    will-change: transform, box-shadow;
}

/* Performance optimizations */
.gallery-grid {
    contain: layout style paint; /* CSS Containment for performance */
}

/* Improved mobile responsiveness */
@media (max-width: 768px) {
    .catalog-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .header-controls {
        flex-direction: column;
        width: 100%;
    }
    
    .category-management {
        flex-direction: column;
        align-items: stretch;
    }
    
    .new-category-input {
        flex-direction: column;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
    
    #global-search {
        font-size: 14px;
    }
    
    .lightbox {
        padding: 5px; /* Reduce padding on very small screens */
    }
    
    .lightbox-content {
        max-width: 95%;
        max-height: 95vh; /* Use more screen real estate on mobile */
        width: auto; /* Remove fixed width */
    }
    
    .lightbox-body {
        flex-direction: column;
        max-height: calc(95vh - 50px); /* Adjust for mobile */
        overflow-y: auto; /* Allow scrolling on mobile */
    }
    
    .lightbox-image {
        padding: 10px;
        max-height: 40vh; /* Reduce image height on mobile */
        min-height: 120px; /* Smaller minimum height */
        flex-shrink: 0; /* Prevent image area from shrinking too much */
    }
    
    .lightbox-image img {
        max-height: 35vh; /* Further limit image height */
    }
    
    .lightbox-info {
        padding: 15px;
        overflow-y: visible; /* Don't scroll info separately on mobile */
        flex-shrink: 1; /* Allow info area to shrink if needed */
    }
    
    .lightbox-info h3 {
        font-size: 1.2em;
        margin-bottom: 10px;
    }
    
    .info-item {
        margin-bottom: 8px;
        font-size: 0.95em; /* Slightly smaller text on mobile */
    }
    
    .lightbox-actions {
        margin-top: 10px;
        gap: 5px;
        flex-direction: column; /* Stack buttons vertically on mobile */
    }
    
    .lightbox-actions .btn {
        width: 100%; /* Full width buttons on mobile */
        margin-bottom: 5px;
        min-width: 0; /* Remove minimum width on mobile */
    }
    
    .lightbox-close {
        top: 8px;
        right: 10px;
        width: 32px;
        height: 32px;
        font-size: 22px;
    }
    
    .item-actions {
        flex-direction: column;
    }
    
    .btn-edit, .btn-delete {
        width: 100%;
    }
    
    .edit-modal-content {
        padding: 20px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions button {
        width: 100%;
    }
    
    .delete-actions {
        flex-direction: column;
    }
    
    .delete-actions button {
        width: 100%;
    }
    
    .pagination-controls {
        gap: 3px;
    }
    
    .pagination-btn {
        padding: 4px 8px;
        font-size: 12px;
        min-width: 50px;
        color: #333; /* Ensure text is dark on mobile too */
    }
    
    .page-number {
        padding: 4px 8px;
        font-size: 12px;
        min-width: 30px;
        color: #333; /* Ensure text is dark on mobile too */
    }
    
    .page-number.active {
        color: white; /* White text on active state */
    }
    
    .pagination-btn:disabled {
        color: #999; /* Grey text for disabled state on mobile */
    }
}

/* Extra small devices (phones, less than 480px) */
@media (max-width: 480px) {
    .lightbox-content {
        max-width: 98%;
        max-height: 98vh;
    }
    
    .lightbox-image {
        max-height: 35vh;
        padding: 8px;
    }
    
    .lightbox-image img {
        max-height: 30vh;
    }
    
    .lightbox-info {
        padding: 12px;
    }
    
    .lightbox-info h3 {
        font-size: 1.1em;
    }
    
    .info-item {
        font-size: 0.9em;
    }
    
    .lightbox-actions .btn {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .lightbox-close {
        top: 5px;
        right: 8px;
        width: 30px;
        height: 30px;
        font-size: 20px;
    }
    
    .pagination-controls {
        gap: 2px;
    }
    
    .pagination-btn {
        padding: 3px 6px;
        font-size: 11px;
        min-width: 40px;
    }
    
    .page-number {
        padding: 3px 6px;
        font-size: 11px;
        min-width: 25px;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .lightbox-body {
        flex-direction: row; /* Keep side-by-side in landscape */
        max-height: 80vh; /* Less height in landscape */
    }
    
    .lightbox-image {
        max-height: 70vh; /* More height for image in landscape */
        min-height: auto;
    }
    
    .lightbox-image img {
        max-height: 65vh;
    }
    
    .lightbox-info {
        max-height: 70vh;
        overflow-y: auto; /* Allow scrolling in info area for landscape */
    }
    
    .lightbox-actions {
        flex-direction: row; /* Keep buttons side-by-side in landscape */
        flex-wrap: nowrap; /* Don't wrap in landscape */
    }
    
    .lightbox-actions .btn {
        flex: 1;
        min-width: 0;
    }
}

/* === Category Delete Buttons === */
.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
}

.category-name {
    flex: 1;
}

.delete-category-btn {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 16px;
    padding: 0 5px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.delete-category-btn:hover {
    opacity: 1;
}

/* Category management area */
#category-management-area {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    margin-top: 10px;
}

#edit-category-management-area {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    margin-top: 10px;
}

#category-management-area h4,
#edit-category-management-area h4 {
    margin-top: 0;
    color: #333;
}

#category-management-area ul,
#edit-category-management-area ul {
    list-style: none;
    padding: 0;
    margin: 15px 0;
}

#category-management-area li,
#edit-category-management-area li {
    padding: 8px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#category-management-area li:last-child,
#edit-category-management-area li:last-child {
    border-bottom: none;
}