/**
 * Gallery Modal Styles
 *
 * Contains: Gallery modal, tabs, grid, cards, detail panel, sidebar selector
 * Used by: gallery.js
 */

/* ===== Gallery Modal Size ===== */
.modal-gallery {
    width: 90%;
    max-width: 960px;
    height: 80vh;
}

/* ===== Gallery Tabs ===== */
.gallery-tabs {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.gallery-tabs::-webkit-scrollbar {
    display: none;
}

.gallery-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease-out;
    white-space: nowrap;
    flex-shrink: 0;
}

.gallery-tab svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.gallery-tab:hover:not(.disabled) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.gallery-tab.active {
    color: var(--accent-blue-light);
    border-bottom-color: var(--accent-blue);
}

.gallery-tab.active svg {
    stroke: var(--accent-blue-light);
    filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.4));
}

.gallery-tab.disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ===== Gallery Body (split layout) ===== */
.gallery-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== Gallery Grid Container ===== */
.gallery-grid-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    transition: flex 0.25s ease-out;
}

.gallery-grid-container::-webkit-scrollbar {
    width: 6px;
}

.gallery-grid-container::-webkit-scrollbar-track {
    background: transparent;
}

.gallery-grid-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.gallery-grid-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.gallery-grid-container.gallery-grid-shrunk {
    flex: 0 0 calc(100% - 360px);
}

/* ===== Gallery Grid ===== */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

.gallery-grid-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    gap: 0.75rem;
    font-size: 0.85rem;
}

.gallery-grid-empty svg {
    opacity: 0.3;
}

/* ===== Gallery Card ===== */
.gallery-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease-out;
    overflow: hidden;
    position: relative;
}

.gallery-card:hover {
    border-color: var(--accent-blue);
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.gallery-card.selected {
    border-color: var(--accent-blue);
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.2);
}

/* Card Preview Area */
.gallery-card-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 110px;
    overflow: hidden;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
}

.gallery-card-preview svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.gallery-card-thumbnail {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
}

.gallery-card-thumbnail svg {
    max-width: 100%;
    max-height: 100%;
}

.gallery-card-no-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    opacity: 0.4;
}

/* Card Info Area */
.gallery-card-info {
    padding: 0.625rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    position: relative;
}

.gallery-card-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 2.5rem;
}

.gallery-card-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Card Badge */
.gallery-card-badge {
    position: absolute;
    top: 0.625rem;
    right: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.gallery-card-badge.public {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue-light);
}

.gallery-card-badge.own {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-purple);
}

.gallery-card-badge.system {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
}

/* Card Delete Button */
.gallery-card-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s ease-out;
    padding: 0;
    z-index: 2;
    backdrop-filter: blur(4px);
}

.gallery-card:hover .gallery-card-delete {
    opacity: 1;
}

.gallery-card-delete:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--accent-red);
}

/* ===== Gallery Detail Panel ===== */
.gallery-detail {
    width: 360px;
    flex-shrink: 0;
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    animation: galleryDetailSlideIn 0.2s ease-out;
}

@keyframes galleryDetailSlideIn {
    from {
        opacity: 0;
        transform: translateX(16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Detail Header */
.gallery-detail-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.gallery-detail-back {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s ease-out;
    flex-shrink: 0;
}

.gallery-detail-back:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.gallery-detail-header h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Detail Body */
.gallery-detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.gallery-detail-body::-webkit-scrollbar {
    width: 6px;
}

.gallery-detail-body::-webkit-scrollbar-track {
    background: transparent;
}

.gallery-detail-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Preview Area */
.gallery-preview {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    max-height: 300px;
    overflow: hidden;
}

.gallery-preview svg {
    max-width: 100%;
    max-height: 100%;
    height: auto;
}

.gallery-preview-placeholder {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 2rem;
}

/* Options Form */
.gallery-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.gallery-options:empty {
    display: none;
}

.gallery-options .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.gallery-options .form-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.gallery-options .form-group select,
.gallery-options .form-group input[type="text"],
.gallery-options .form-group input[type="number"] {
    width: 100%;
    padding: 0.5rem 0.625rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: var(--font-sans);
    transition: border-color 0.15s;
}

.gallery-options .form-group select:focus,
.gallery-options .form-group input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.gallery-options .form-group input[type="color"] {
    width: 36px;
    height: 36px;
    padding: 2px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    cursor: pointer;
}

.gallery-options .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.gallery-options .checkbox-group {
    flex-direction: row;
}

.gallery-options .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.gallery-options .checkbox-label input[type="checkbox"] {
    accent-color: var(--accent-blue);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* Range slider in gallery options */
.gallery-options .gallery-range-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.gallery-options .gallery-range {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
    outline: none;
}

.gallery-options .gallery-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent-purple);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s;
}

.gallery-options .gallery-range::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.gallery-options .gallery-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent-purple);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.gallery-options .gallery-range-value {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--accent-purple);
    min-width: 32px;
    text-align: right;
}

/* Options Section Title */
.gallery-options-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--border-subtle);
}

/* Detail Footer */
.gallery-detail-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.625rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.gallery-detail-footer .btn {
    padding: 0.625rem 1rem;
    font-size: 0.85rem;
}

.gallery-detail-footer .btn-secondary {
    flex: 0;
}

.gallery-confirm-btn {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-light));
    color: white;
    width: auto;
}

.gallery-confirm-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--glow-blue);
}

/* ===== Sidebar Gallery Selector Card ===== */
.gallery-selector-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease-out;
    text-align: left;
    font-family: var(--font-sans);
}

.gallery-selector-card:hover {
    border-color: var(--accent-blue);
    background: var(--bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.gallery-selector-card.has-selection {
    border-color: var(--accent-purple);
    background: rgba(139, 92, 246, 0.08);
}

.gallery-selector-card.has-selection:hover {
    background: rgba(139, 92, 246, 0.12);
    border-color: var(--accent-purple);
}

.gallery-selector-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    flex-shrink: 0;
}

.gallery-selector-card-icon svg {
    width: 22px;
    height: 22px;
    color: var(--accent-blue);
}

.gallery-selector-card.has-selection .gallery-selector-card-icon {
    background: rgba(139, 92, 246, 0.15);
}

.gallery-selector-card.has-selection .gallery-selector-card-icon svg {
    color: var(--accent-purple);
}

.gallery-selector-card-content {
    flex: 1;
    min-width: 0;
}

.gallery-selector-card-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-selector-card-info {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.gallery-selector-card-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.2s;
}

.gallery-selector-card:hover .gallery-selector-card-arrow {
    color: var(--accent-blue);
    transform: translateX(2px);
}

/* ===== Sidebar Options (below gallery selector card) ===== */
.gallery-sidebar-options {
    margin-top: 0.75rem;
}

.gallery-sidebar-options:empty {
    display: none;
    margin-top: 0;
}

/* ===== Responsive: Gallery Modal ===== */
@media (max-width: 900px) {
    .modal-gallery {
        width: 95%;
        height: 85vh;
    }

    .gallery-grid-container.gallery-grid-shrunk {
        flex: 0 0 100%;
    }

    .gallery-detail {
        position: absolute;
        inset: 0;
        width: 100%;
        z-index: 10;
        border-left: none;
        animation: galleryDetailSlideUp 0.2s ease-out;
    }

    @keyframes galleryDetailSlideUp {
        from {
            opacity: 0;
            transform: translateY(24px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .gallery-body {
        position: relative;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

@media (max-width: 600px) {
    .modal-gallery {
        width: 100%;
        height: 100%;
        max-width: none;
        border-radius: 0;
    }

    .gallery-tabs {
        padding: 0 1rem;
    }

    .gallery-tab {
        padding: 0.625rem 0.75rem;
        font-size: 0.75rem;
    }

    .gallery-tab svg {
        width: 16px;
        height: 16px;
    }

    .gallery-grid-container {
        padding: 1rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .gallery-card-preview {
        height: 90px;
    }

    .gallery-detail {
        width: 100%;
    }
}

/* ===== Reduced Motion Support ===== */
@media (prefers-reduced-motion: reduce) {
    .gallery-card,
    .gallery-tab,
    .gallery-selector-card,
    .gallery-detail-back {
        transition: none;
    }

    .gallery-detail {
        animation: none;
    }

    .gallery-card:hover {
        transform: none;
    }

    .gallery-selector-card:hover {
        transform: none;
    }
}
