/**
 * Content Gallery & Composer Styles
 * Adaptive image layouts, lightbox, and composer UI
 */

/* =====================================================
   CONTENT COMPOSER
   ===================================================== */

.content-composer {
    background: var(--card-background, #ffffff);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.composer-header {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.privacy-selector {
    padding: 8px 12px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 6px;
    background: var(--input-background, #fff);
    color: var(--text-color, #333);
    font-size: 14px;
    min-width: 150px;
}

.schedule-input {
    padding: 8px 12px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 6px;
    background: var(--input-background, #fff);
    color: var(--text-color, #333);
    font-size: 14px;
}

.composer-editor {
    position: relative;
    border: 2px dashed transparent;
    border-radius: 8px;
    transition: border-color 0.2s, background-color 0.2s;
}

.composer-editor.drag-active,
.composer-editor[data-drop-active="true"] {
    border-color: var(--primary-color, #4AAEDC);
    background-color: rgba(74, 174, 220, 0.05);
}

.drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(74, 174, 220, 0.1);
    border-radius: 6px;
    z-index: 10;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--primary-color, #4AAEDC);
    pointer-events: none;
}

.composer-editor.drag-active .drop-overlay {
    display: flex;
}

/* Media Preview Area */
.composer-media-preview,
.composer-video-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    min-height: 0;
}

.composer-media-preview:empty,
.composer-video-preview:empty {
    display: none;
}

/* Image Preview Items */
.image-preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--card-background-secondary, #f5f5f5);
}

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

.image-preview-item.uploading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
}

.upload-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(0, 0, 0, 0.3);
}

.upload-progress-bar {
    height: 100%;
    background: var(--primary-color, #4AAEDC);
    transition: width 0.2s;
}

.image-remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.2s;
}

.image-remove-btn:hover {
    background: rgba(220, 53, 69, 0.9);
}

/* Video Preview Items */
.video-preview-item {
    position: relative;
    width: 200px;
    background: var(--card-background-secondary, #f5f5f5);
    border-radius: 8px;
    overflow: hidden;
}

.video-preview-item.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    gap: 10px;
}

.video-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color, #ddd);
    border-top-color: var(--primary-color, #4AAEDC);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.video-thumbnail {
    position: relative;
    aspect-ratio: 16/9;
}

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

.video-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 24px;
}

.video-platform-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.video-info {
    padding: 8px;
}

.video-title {
    font-size: 12px;
    color: var(--text-color, #333);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.video-remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.video-remove-btn:hover {
    background: rgba(220, 53, 69, 0.9);
}

/* Composer Actions */
.composer-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color, #eee);
}

.composer-options {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-right: auto;
}

.composer-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-color-secondary, #666);
    cursor: pointer;
}

/* =====================================================
   ADAPTIVE GALLERY - Content Display
   ===================================================== */

.content-gallery {
    display: grid;
    gap: 4px;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 10px;
}

/* 1 Image - Full width */
.content-gallery.images-1 {
    grid-template-columns: 1fr;
}

.content-gallery.images-1 .gallery-item {
    max-height: 500px;
}

.content-gallery.images-1 .gallery-image {
    width: 100%;
    max-height: 500px;
    object-fit: contain;
    background: var(--card-background-secondary, #f0f0f0);
}

/* 2 Images - Stacked full width */
.content-gallery.images-2 {
    grid-template-columns: 1fr;
    gap: 4px;
}

.content-gallery.images-2 .gallery-item {
    max-height: 300px;
}

.content-gallery.images-2 .gallery-image {
    width: 100%;
    height: 100%;
    max-height: 300px;
    object-fit: cover;
}

/* 3 Images - First large, two small */
.content-gallery.images-3 {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.content-gallery.images-3 .gallery-item:first-child {
    grid-row: span 2;
}

.content-gallery.images-3 .gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 4 Images - 2x2 grid */
.content-gallery.images-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.content-gallery.images-4 .gallery-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

/* 5+ Images - 2x2 with overlay */
.content-gallery.images-5plus {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.content-gallery.images-5plus .gallery-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.gallery-image {
    transition: transform 0.2s;
}

.gallery-item:hover .gallery-image {
    transform: scale(1.02);
}

.gallery-more-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 600;
    cursor: pointer;
}

.gallery-more-overlay:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* =====================================================
   VIDEO EMBEDS IN CONTENT
   ===================================================== */

.content-video-embeds {
    margin-top: 10px;
}

.content-video-embed {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 10px;
}

.video-embed-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
}

.video-embed-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.video-embed-preview {
    position: relative;
    cursor: pointer;
}

.video-embed-preview img {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
}

.video-embed-preview .video-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    transition: background 0.2s;
}

.video-embed-preview:hover .video-play-overlay {
    background: rgba(0, 0, 0, 0.5);
}

.video-embed-preview .video-play-overlay i {
    font-size: 48px;
    color: white;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* =====================================================
   LIGHTBOX
   ===================================================== */

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    cursor: pointer;
}

.lightbox-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.lightbox-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 60px 80px;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    cursor: grab;
    transition: transform 0.1s;
}

.lightbox-image:active {
    cursor: grabbing;
}

.lightbox-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: background 0.2s;
    z-index: 10;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-prev,
.lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: background 0.2s;
    z-index: 10;
}

.lightbox-prev {
    left: 15px;
}

.lightbox-next {
    right: 15px;
}

.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-footer {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 20px;
    color: white;
    z-index: 10;
}

.lightbox-counter {
    font-size: 14px;
    opacity: 0.8;
}

.lightbox-controls {
    display: flex;
    gap: 5px;
}

.lightbox-controls button {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.lightbox-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* =====================================================
   DARK MODE ADJUSTMENTS
   ===================================================== */

[data-theme="dark"] .content-composer,
.dark-mode .content-composer {
    background: var(--card-background-dark, #2a2a2a);
}

[data-theme="dark"] .image-preview-item,
[data-theme="dark"] .video-preview-item,
.dark-mode .image-preview-item,
.dark-mode .video-preview-item {
    background: var(--card-background-secondary-dark, #333);
}

[data-theme="dark"] .content-gallery.images-1 .gallery-image,
.dark-mode .content-gallery.images-1 .gallery-image {
    background: var(--card-background-dark, #2a2a2a);
}

/* =====================================================
   RESPONSIVE ADJUSTMENTS
   ===================================================== */

@media (max-width: 768px) {
    .content-gallery.images-3 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    .content-gallery.images-3 .gallery-item:first-child {
        grid-column: span 2;
        grid-row: span 1;
    }

    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .lightbox-prev { left: 5px; }
    .lightbox-next { right: 5px; }

    .lightbox-content {
        padding: 50px 50px;
    }

    .video-preview-item {
        width: 150px;
    }
}

@media (max-width: 480px) {
    .composer-header {
        flex-direction: column;
        align-items: stretch;
    }

    .privacy-selector,
    .schedule-input {
        width: 100%;
    }

    .image-preview-item {
        width: 80px;
        height: 80px;
    }
}
