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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.top-bar {
    position: sticky;
    top: 0;
    background: white;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: var(--z-header);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-group label {
    font-size: 0.85rem;
    color: #666;
}

.search-box {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    min-width: 250px;
}

select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    background: white;
    min-width: 150px;
}

.quality-range {
    min-width: 200px;
}

.quality-range label {
    font-size: 0.85rem;
    color: #666;
}

.slider-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

input[type="range"] {
    flex: 1;
    min-width: 80px;
}

button {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #007bff;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
}

button:hover {
    background: #0056b3;
}

#clear-filters {
    background: #6c757d;
}

#clear-filters:hover {
    background: #545b62;
}

.stats {
    font-size: 0.9rem;
    color: #666;
    margin-top: 0.5rem;
}

.selection-bar {
    position: sticky;
    top: 0;
    background: #007bff;
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 99;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.selection-bar button {
    background: white;
    color: #007bff;
    border: none;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.selection-bar button:hover {
    background: #f0f0f0;
}

.selection-bar #clear-selection {
    background: #6c757d;
    color: white;
}

.selection-bar #clear-selection:hover {
    background: #545b62;
}

.main-content {
    display: flex;
    position: relative;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1rem;
    flex: 1;
    transition: margin-right 0.3s ease;
}

.grid-container.with-panel {
    margin-right: 400px;
}

.thumbnail {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.thumbnail:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.thumbnail.selected {
    border: 3px solid #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.thumbnail-checkbox {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 20px;
    height: 20px;
    z-index: 10;
    cursor: pointer;
    accent-color: #007bff;
}

.thumbnail img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.thumbnail-info {
    padding: 0.75rem;
}

.thumbnail-title {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thumbnail-meta {
    font-size: 0.75rem;
    color: #666;
}

.detail-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: -2px 0 8px rgba(0,0,0,0.1);
    transition: right 0.3s ease;
    overflow-y: auto;
    z-index: var(--z-panel);
}

.detail-panel.open {
    right: 0;
}

.close-panel {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-panel:hover {
    background: rgba(0,0,0,0.7);
}

.detail-content {
    padding: 2rem 1.5rem;
}

.detail-preview {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    background: #f5f5f5;
}

.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section h2 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #333;
    border-bottom: 2px solid #007bff;
    padding-bottom: 0.25rem;
}

.detail-section p,
.detail-section div {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.detail-label {
    font-weight: 600;
    color: #666;
    display: inline-block;
    min-width: 120px;
}

.detail-value {
    color: #333;
}

.detail-value a {
    color: #007bff;
    text-decoration: none;
}

.detail-value a:hover {
    text-decoration: underline;
}

.subjects-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.subject-tag {
    background: #e7f3ff;
    color: #0066cc;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
}

.copy-button {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem;
    font-size: 0.9rem;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #ddd;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 2rem;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.close-modal:hover {
    color: #000;
}

.modal-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.form-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.command-box {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 1rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    word-break: break-all;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
}

.modal-footer button {
    padding: 0.75rem 1.5rem;
}

/* Lightbox styles */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox.hidden {
    display: none;
}

.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
    z-index: var(--z-overlay);
}

.lightbox-container {
    position: fixed;
    inset: 0;
    z-index: var(--z-lightbox);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.55);
    backdrop-filter: blur(2px);
    border-radius: 12px;
    pointer-events: none;
}

.lightbox-container > * {
    pointer-events: auto;
}

.lightbox-header {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: var(--z-lightbox-ui);
    pointer-events: auto;
}

.lightbox-close {
    background: rgba(20, 20, 20, 0.75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 2rem;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s;
}

.lightbox-close:hover {
    background: rgba(30, 30, 30, 0.85);
}

.lightbox-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(20, 20, 20, 0.75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 8px 10px;
    border-radius: 10px;
}

.lightbox-nav {
    background: rgba(20, 20, 20, 0.75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.lightbox-nav:hover:not(:disabled) {
    background: rgba(30, 30, 30, 0.85);
}

.lightbox-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.lightbox-view-select {
    background: rgba(20, 20, 20, 0.75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
}

.lightbox-view-select option {
    background: #333;
    color: white;
}

.lightbox-metadata-btn {
    background: rgba(20, 20, 20, 0.75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.lightbox-metadata-btn:hover {
    background: rgba(30, 30, 30, 0.85);
}

.lightbox-image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5rem 1rem 4rem 1rem;
    width: 100%;
    overflow: auto;
}

#lightbox-image {
    max-width: 92vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    opacity: 1 !important;
    filter: none !important;
}

.lightbox-info {
    position: fixed;
    bottom: 12px;
    left: 12px;
    right: 12px;
    padding: 1rem;
    background: rgba(20, 20, 20, 0.75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    z-index: var(--z-lightbox-ui);
    pointer-events: auto;
}

.lightbox-info-content {
    text-align: center;
    color: white;
}

.lightbox-info-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.lightbox-info-meta {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
}

@media (max-width: 768px) {
    .filters {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .search-box,
    select {
        width: 100%;
    }
    
    .grid-container {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .detail-panel {
        width: 100%;
        right: -100%;
    }
    
    .grid-container.with-panel {
        margin-right: 0;
    }
    
    .modal-content {
        width: 95%;
    }
    
    .lightbox-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .lightbox-nav,
    .lightbox-metadata-btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    #lightbox-image {
        max-width: 95vw;
        max-height: 75vh;
    }
}

/* Z-index scale */
:root {
    --z-base: 1;
    --z-header: 100;
    --z-overlay: 10000;
    --z-lightbox: 10010;
    --z-lightbox-ui: 10020;
    --z-panel: 10030;
    --z-modal: 10040;
}

