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

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

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

h1 {
    color: #333;
    margin-bottom: 30px;
    text-align: center;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-button {
    padding: 12px 24px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-button:hover {
    color: #333;
}

.tab-button.active {
    color: #007bff;
    border-bottom-color: #007bff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Dropzone */
.dropzone {
    border: 3px dashed #ccc;
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: #fafafa;
    margin-bottom: 20px;
}

.dropzone:hover {
    border-color: #007bff;
    background: #f0f8ff;
}

.dropzone.dragover {
    border-color: #007bff;
    background: #e3f2fd;
}

.dropzone p {
    color: #666;
    font-size: 16px;
}

/* Preview */
.preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.preview-item {
    position: relative;
    border: 2px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.preview-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.preview-item .remove-btn:hover {
    background: rgba(255, 0, 0, 1);
}

/* Form */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
}

/* Previous Tags */
.previous-tags {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
}

.previous-tags strong {
    display: block;
    margin-bottom: 10px;
    color: #555;
}

#tagsList {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-item {
    display: inline-block;
    padding: 6px 12px;
    background: #007bff;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.tag-item:hover {
    background: #0056b3;
    transform: translateY(-2px);
}

/* Buttons */
.btn-primary {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Upload Status */
#uploadStatus {
    margin-top: 15px;
    padding: 10px;
    border-radius: 4px;
    display: none;
}

#uploadStatus.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    display: block;
}

#uploadStatus.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    display: block;
}

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

.gallery-item {
    position: relative;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s;
    background: white;
}

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

.gallery-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    cursor: pointer;
}

/* Gallery Actions */
.gallery-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
}

.gallery-item:hover .gallery-actions {
    opacity: 1;
}

.action-btn {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.action-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.ocr-btn:hover {
    background: #28a745;
}

.edit-btn:hover {
    background: #007bff;
}

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

.gallery-info {
    padding: 15px;
}

.gallery-info .date {
    color: #999;
    font-size: 12px;
    margin-bottom: 5px;
}

.gallery-info .size {
    color: #999;
    font-size: 12px;
    margin-bottom: 10px;
}

.gallery-info .note {
    color: #333;
    font-size: 14px;
    margin-bottom: 10px;
    line-height: 1.4;
}

/* Markdown styles in notes */
.gallery-info .note h1,
.gallery-info .note h2,
.gallery-info .note h3,
.gallery-info .note h4,
.gallery-info .note h5,
.gallery-info .note h6 {
    margin-top: 8px;
    margin-bottom: 4px;
    font-weight: 600;
}

.gallery-info .note h1 { font-size: 16px; }
.gallery-info .note h2 { font-size: 15px; }
.gallery-info .note h3 { font-size: 14px; }
.gallery-info .note h4 { font-size: 13px; }
.gallery-info .note h5 { font-size: 12px; }
.gallery-info .note h6 { font-size: 11px; }

.gallery-info .note p {
    margin-bottom: 8px;
}

.gallery-info .note ul,
.gallery-info .note ol {
    margin-left: 20px;
    margin-bottom: 8px;
}

.gallery-info .note li {
    margin-bottom: 4px;
}

.gallery-info .note code {
    background: #f4f4f4;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.gallery-info .note pre {
    background: #f4f4f4;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 8px;
}

.gallery-info .note pre code {
    background: none;
    padding: 0;
}

.gallery-info .note blockquote {
    border-left: 3px solid #ddd;
    padding-left: 10px;
    margin-left: 0;
    margin-bottom: 8px;
    color: #666;
}

.gallery-info .note a {
    color: #007bff;
    text-decoration: none;
}

.gallery-info .note a:hover {
    text-decoration: underline;
}

.gallery-info .note strong {
    font-weight: 600;
}

.gallery-info .note em {
    font-style: italic;
}

.gallery-info .note hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 8px 0;
}

.gallery-info .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.gallery-info .tag {
    display: inline-block;
    padding: 4px 8px;
    background: #e9ecef;
    color: #495057;
    border-radius: 12px;
    font-size: 11px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.pagination button {
    padding: 8px 16px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination button.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

/* Search Form */
.search-form {
    margin-bottom: 30px;
}

.search-form label {
    margin-right: 20px;
    cursor: pointer;
}

.search-form input[type="text"] {
    width: calc(100% - 120px);
    display: inline-block;
    margin-right: 10px;
}

.search-form .btn-primary {
    display: inline-block;
}

/* Search Tag Cloud */
.search-tag-cloud {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.search-tag-cloud strong {
    display: block;
    margin-bottom: 10px;
    color: #555;
}

#searchTagsList {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#searchTagsList .tag-item {
    display: inline-block;
    padding: 6px 12px;
    background: #007bff;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

#searchTagsList .tag-item:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Search Date Range */
.search-date-range {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.date-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-input-group label {
    font-weight: 500;
    color: #555;
    font-size: 14px;
}

.date-input-group input[type="date"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

.date-input-group input[type="date"]:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

#searchDateButton {
    margin-left: auto;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

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

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    overflow: auto;
}

.lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: zoom 0.3s;
}

@keyframes zoom {
    from { transform: translate(-50%, -50%) scale(0.5); }
    to { transform: translate(-50%, -50%) scale(1); }
}

.lightbox-close {
    position: absolute;
    top: 30px;
    right: 50px;
    color: #f1f1f1;
    font-size: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 10000;
}

.lightbox-close:hover,
.lightbox-close:focus {
    color: #bbb;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    position: relative;
    animation: slideDown 0.3s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #333;
    font-size: 24px;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: #999;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    line-height: 1;
}

.modal-close:hover,
.modal-close:focus {
    color: #333;
}

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

/* Secondary Button */
.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* OCR Modal Specific Styles */
.ocr-text-container {
    margin-top: 20px;
}

.ocr-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.btn-copy {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-copy:hover {
    background: #218838;
}

#ocrText {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    resize: vertical;
    line-height: 1.6;
}

.ocr-status {
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.ocr-status .loading {
    background: #e3f2fd;
    color: #1976d2;
    padding: 20px;
    border-radius: 4px;
    text-align: center;
    font-size: 16px;
}

.ocr-status .loading::before {
    content: "⏳ ";
    font-size: 20px;
}

.ocr-status .error {
    background: #f8d7da;
    color: #721c24;
    padding: 15px;
    border-radius: 4px;
    border: 1px solid #f5c6cb;
}

/* ============================================================
   IMAGE SET STYLES
   ============================================================ */

/* Set badge on gallery items */
.set-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 123, 255, 0.9);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Gallery item styling for sets */
.gallery-item.is-set {
    border: 2px solid #007bff;
}

/* Selection checkboxes */
.set-selection-checkbox {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    z-index: 10;
}

/* Browse toolbar */
.browse-toolbar {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Lightbox counter */
.lightbox-counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    z-index: 10001;
}

/* Lightbox navigation buttons */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    font-size: 48px;
    padding: 20px 15px;
    cursor: pointer;
    z-index: 10001;
    transition: background 0.3s;
    line-height: 1;
}

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

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

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

/* Lightbox thumbnail strip */
.lightbox-thumbnails {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    gap: 10px;
    max-width: 90%;
    overflow-x: auto;
    z-index: 10001;
}

.lightbox-thumbnails::-webkit-scrollbar {
    height: 8px;
}

.lightbox-thumbnails::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.lightbox-thumbnails::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.lightbox-thumbnails::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Thumbnail items in lightbox */
.lightbox-thumb {
    flex-shrink: 0;
    width: 80px;
    height: 60px;
    cursor: pointer;
    border: 3px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    transition: all 0.2s;
    position: relative;
}

.lightbox-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.lightbox-thumb.active {
    border-color: #007bff;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
}

.lightbox-thumb:hover:not(.active) {
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

/* Drag and drop states for thumbnails */
.lightbox-thumb.dragging {
    opacity: 0.5;
}

.lightbox-thumb.drag-over {
    border-color: #28a745;
    background: rgba(40, 167, 69, 0.2);
}

/* Create Set Modal */
#createSetModal .modal-content {
    max-width: 500px;
}

/* Upload as set checkbox area */
#createSetCheckbox {
    margin-right: 8px;
}

#setTitleGroup {
    margin-top: 15px;
}

/* Responsive adjustments for set features */
@media (max-width: 768px) {
    .browse-toolbar {
        flex-direction: column;
    }

    .browse-toolbar button {
        width: 100%;
    }

    .lightbox-nav {
        font-size: 32px;
        padding: 15px 10px;
    }

    .lightbox-prev {
        left: 10px;
    }

    .lightbox-next {
        right: 10px;
    }

    .lightbox-thumbnails {
        bottom: 10px;
        padding: 10px;
        max-width: 95%;
    }

    .lightbox-thumb {
        width: 60px;
        height: 45px;
    }

    .lightbox-counter {
        top: 10px;
        font-size: 12px;
        padding: 6px 12px;
    }

    .set-badge {
        font-size: 10px;
        padding: 3px 8px;
    }
}

/* Ensure lightbox content doesn't interfere with new controls */
.lightbox-content {
    max-height: calc(90vh - 150px);
    margin-top: 50px;
}

/* Animation for set creation success */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.gallery-item.is-set {
    animation: pulse 0.5s ease-in-out;
}

/* Toolbar button spacing */
.btn-secondary + .btn-primary {
    margin-left: 0;
}
