/**
 * Smart Gallery - Media Gallery Styling
 * Janus Design System Integration
 * @version 2.0.0
 */

/* ===========================================
   CONTAINER
   =========================================== */

.smart-gallery {
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ===========================================
   GHOST LINK SECTION (Terminal Style)
   =========================================== */

.ghost-link-section {
    margin-bottom: 20px;
    padding: 20px;
    background: var(--bg-dark);
    border: solid 1px var(--border);
    border-radius: 26px;
    margin-top: 20px;
}

.ghost-link-header {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ghost-link-header i {
    color: var(--accent);
}

.ghost-link-description {
    font-size: 0.9rem;
    color: var(--color-muted);
    margin-bottom: 20px;
    line-height: 1.4;
}

.ghost-link-options {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.ghost-link-options label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--color-muted);
    font-weight: 500;
}

.ghost-link-options select,
.ghost-link-options input {
    padding: 8px 12px;
    border: solid 1px var(--border);
    border-radius: 26px;
    background: var(--bg-tertiary);
    color: var(--text-main);
    font-size: 16px;
    outline: none;
    transition: all 0.2s ease;
}

.ghost-link-options select:focus,
.ghost-link-options input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(var(--color-accent-rgb), 0.1);
}

.ghost-link-options input[type="number"] {
    width: 100px;
}

.btn-generate-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--accent);
    color: var(--text-secondary);
    border: none;
    border-radius: 60px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-generate-link:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 15px rgba(var(--color-accent-rgb), 0.4);
}

/* Active Ghost Link */
.ghost-link-active {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ghost-link-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ghost-link-url {
    display: flex;
    gap: 10px;
}

.ghost-url-input {
    flex: 1;
    padding: 10px 15px;
    border: solid 1px var(--border);
    border-radius: 8px;
    background: var(--bg-dark);
    color: var(--accent);
    font-size: 16px;
    letter-spacing: 0.5px;
}

.btn-copy {
    padding: 0 15px;
    background: var(--bg-tertiary);
    border: solid 1px var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-main);
    transition: all 0.2s;
}

.btn-copy:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.ghost-link-meta {
    display: flex;
    gap: 20px;
    font-size: 0.8rem;
    color: var(--color-muted);
}

.ghost-link-meta span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-revoke {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 50, 50, 0.1);
    color: #ff4444;
    border: 1px solid #ff4444;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    margin-top: 10px;
}

.btn-revoke:hover {
    background: #ff4444;
    color: white;
}

/* ===========================================
   GALLERY CATEGORY
   =========================================== */

.gallery-category {
    background: var(--bg-tertiary);
    border: solid 1px var(--border);
    border-radius: 26px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease, border 0.5s ease;
    margin-bottom: 20px;
    margin-top: 20px;
}

.gallery-category:hover {
    border-color: var(--accent-dim);
}

.category-header {
    padding: 20px;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: solid 1px var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    color: var(--text-main);
    font-size: 16px;
}

.category-title i {
    color: var(--accent);
}

.category-count {
    font-weight: 400;
    color: var(--color-muted);
    font-size: 0.85em;
    background: var(--bg-dark);
    padding: 2px 8px;
    border-radius: 12px;
}

.category-description {
    margin-top: 8px;
    font-size: 11px;
    color: var(--color-muted);
    margin-left: 28px;
}

/* ===========================================
   UPLOAD AREA
   =========================================== */

.gallery-upload-area {
    margin: 20px;
    padding: 30px;
    border: 2px dashed var(--color-border);
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.02);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.gallery-upload-area:hover {
    border-color: var(--color-accent);
    background: rgba(var(--color-accent-rgb), 0.05);
}

.upload-icon {
    font-size: 2rem;
    color: var(--color-muted);
    margin-bottom: 5px;
}

.gallery-upload-area:hover .upload-icon {
    color: var(--color-accent);
}

.upload-text {
    font-weight: 600;
    color: var(--color-text);
}

.upload-subtext {
    font-size: 0.85rem;
    color: var(--color-muted);
}

/* ===========================================
   IMAGE GRID
   =========================================== */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding: 20px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-dark);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--color-border);
    transition: all 0.2s ease;
    cursor: grab;
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-color: var(--color-accent);
}

.gallery-item:active {
    cursor: grabbing;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.gallery-item:hover img {
    transform: scale(1.05);
}

/* Item Overlay */
.item-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
}

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

.item-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}



.btn-icon.delete:hover {
    background: #ff4444;
    color: white;
    border-color: #ff4444;
}

.item-badge {
    align-self: flex-start;
    padding: 4px 8px;
    background: var(--color-accent);
    color: #000;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.item-meta {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===========================================
   GALLERY UPLOAD ZONE
   =========================================== */

.gallery-upload-zone {
    padding: 20px;
    border-top: 1px dashed var(--border);
}

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 30px 20px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.02);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.upload-area i {
    font-size: 2.5rem;
    color: var(--color-muted);
    transition: color 0.2s;
}

.upload-area:hover i {
    color: var(--accent);
}

.upload-area span {
    font-size: 0.95rem;
    color: var(--color-text);
}

.gallery-upload-actions {
    margin-top: 14px;
    display: flex;
    justify-content: center;
}

.btn-select-existing {
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-select-existing:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Browse Button - inline in text */
.btn-browse {
    display: inline;
    padding: 0;
    background: none;
    border: none;
    color: var(--accent);
    font-size: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}

.btn-browse:hover {
    color: var(--color-text);
    text-decoration: none;
}

/* Gallery Empty State */
.gallery-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--color-muted);
    font-size: 0.95rem;
}

.gallery-empty i {
    font-size: 2rem;
    opacity: 0.5;
}

/* Category Content */
.category-content {
    padding: 0;
}

/* Cover Badge on Images */
.cover-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-lighter);
    color: var(--accent);
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    z-index: 2;
}

/* Item Thumbnail */
.item-thumbnail {
    position: relative;
    width: 100%;
    height: 100%;
}

.item-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Item Info in Overlay */
.item-info {
    text-align: center;
}

.item-filename {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Read-only Gallery Section */
.gallery-category.read-only .gallery-upload-zone {
    display: none;
}

/* ===========================================
   ACTION BUTTONS (View, Delete, Set Cover)
   =========================================== */

.btn-view,
.btn-delete,
.btn-set-cover {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-dark);
    border: solid 1px var(--border);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.btn-view:hover {
    background: var(--accent);
    color: var(--text-secondary);
    border-color: var(--accent);
    transform: scale(1.1);
}

.btn-delete:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    transform: scale(1.1);
}

.btn-set-cover:hover {
    background: #f59e0b;
    color: #000;
    border-color: #f59e0b;
    transform: scale(1.1);
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 0.8rem;
    z-index: 3;
}

.gallery-item:hover .drag-handle {
    opacity: 1;
}

.drag-handle:active {
    cursor: grabbing;
}

/* ===========================================
   LIGHTBOX / IMAGE VIEWER
   =========================================== */

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    will-change: blur;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.gallery-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    z-index: 10;
}

.lightbox-title {
    color: white;
    font-size: 1rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
}

.lightbox-counter {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    font-family: var(--font-mono, monospace);
}

.lightbox-close {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 28px;
    color: var(--danger);
}

.lightbox-close:hover {
    color: var(--accent);
}

.lightbox-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 80px 60px;
}

.lightbox-image-container {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.2rem;
    z-index: 10;
}

.lightbox-nav:hover {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav.prev {
    left: 20px;
}

.lightbox-nav.next {
    right: 20px;
}

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

.lightbox-nav:disabled:hover {
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%);
}

/* Lightbox Thumbnails Strip */
.lightbox-thumbnails {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 10px 15px;
    background: rgb(120 120 120 / 50%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    will-change: blur;
    border-radius: 16px;
    max-width: 80%;
    overflow-x: auto;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.lightbox-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

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

.lightbox-thumb:hover {
    border-color: rgba(255, 255, 255, 0.5);
}

.lightbox-thumb.active {
    border-color: var(--color-accent);
    box-shadow: 0 0 10px rgba(var(--color-accent-rgb), 0.5);
}

/* Loading state for lightbox */
.lightbox-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.lightbox-loading i {
    font-size: 2rem;
    color: var(--color-accent);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Keyboard navigation hint */
.lightbox-hint {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.lightbox-hint span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.lightbox-hint kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-mono, monospace);
}


/* ===========================================
   GALLERY DETAIL VIEW (ui_type: gallery)
   =========================================== */

.gallery-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.gallery-detail-item {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    background: var(--bg-dark);
}

.gallery-detail-item:hover {
    border-color: var(--accent);
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.gallery-detail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-detail-more {
    aspect-ratio: 1;
    border-radius: 8px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gallery-detail-more:hover {
    border-color: var(--accent);
    background: var(--bg-panel);
}

.gallery-detail-more span {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
}

.gallery-detail-footer {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.gallery-detail-footer i {
    color: var(--accent);
}

/* ===========================================
   GALLERY LIGHTBOX OVERLAY
   =========================================== */

.gallery-lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    animation: lightboxFadeIn 0.2s ease;
}

@keyframes lightboxFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.gallery-lightbox-overlay .lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}

.gallery-lightbox-overlay .lightbox-counter {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.7);
    font-family: var(--font-mono, monospace);
}

.gallery-lightbox-overlay .lightbox-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.gallery-lightbox-overlay .lightbox-close:hover {
    background: white;
    color: black;
}

.gallery-lightbox-overlay .lightbox-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

.gallery-lightbox-overlay .lightbox-image-wrapper {
    max-width: 85%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-lightbox-overlay .lightbox-main-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.gallery-lightbox-overlay .lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.gallery-lightbox-overlay .lightbox-nav:hover {
    background: var(--accent);
    color: black;
    border-color: var(--accent);
}

.gallery-lightbox-overlay .lightbox-nav.prev {
    left: 20px;
}

.gallery-lightbox-overlay .lightbox-nav.next {
    right: 20px;
}

.gallery-lightbox-overlay .lightbox-thumbnails {
    display: flex;
    gap: 8px;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.6);
    overflow-x: auto;
    justify-content: center;
}

.gallery-lightbox-overlay .lightbox-thumb {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

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

.gallery-lightbox-overlay .lightbox-thumb:hover {
    border-color: rgba(255,255,255,0.5);
}

.gallery-lightbox-overlay .lightbox-thumb.active {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(0, 188, 212, 0.5);
}
