/**
 * Media Block - Frontend Styles
 * 
 * @package AIWorkflowBlocks
 * @author Mika Wenell
 * @copyright 2025 uniwaves Oy
 */

/* Block wrapper */
.ai-workflow-block.media {
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

/* Media block wrapper - Natural image size */
.media-block-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    display: inline-block;
    min-height: 60px; /* Ensure space for edit button even when empty */
}

/* Media alignment classes */
.media-block-wrapper.media-align-left {
    text-align: left;
}

.media-block-wrapper.media-align-center {
    text-align: center;
}

.media-block-wrapper.media-align-right {
    text-align: right;
}

/* Ensure carousel frame respects alignment */
.media-block-wrapper.media-align-left .media-carousel-frame {
    margin-left: 0;
    margin-right: auto;
}

.media-block-wrapper.media-align-center .media-carousel-frame {
    margin-left: auto;
    margin-right: auto;
}

.media-block-wrapper.media-align-right .media-carousel-frame {
    margin-left: auto;
    margin-right: 0;
}

/* Placeholder image (default SVG when empty) */
.media-block-placeholder-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    object-position: center;
    opacity: 0.3;
    padding: 40px;
}

/* Empty state overlay (waiting for queue) */
.media-block-waiting {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(245, 245, 245, 0.85);
    border-radius: 8px;
    pointer-events: none;
}

.media-block-queue-message {
    margin: 0;
    font-size: 16px;
    color: #666;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 16px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Empty state overlay (has control, can edit) */
.media-block-empty {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(249, 249, 249, 0.95);
    border-radius: 8px;
}

.ai-workflow-block.media.is-active .media-block-empty {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(76, 175, 80, 0.2);
    }
    50% {
        box-shadow: 0 4px 16px rgba(76, 175, 80, 0.4);
    }
}

.media-block-upload-area {
    max-width: 500px;
    margin: 0 auto;
}

.media-block-message {
    font-size: 18px;
    color: #333;
    margin-bottom: 20px;
}

/* Uploader container */
.media-block-uploader {
    position: relative;
    width: 100%;
    background-color: white;
    padding: 1rem;
}

/* Uploader Frame - new architecture */
.media-uploader-frame {
    position: relative;
    width: 100%;
    background-color: white;
    padding: 20px;
    border-radius: 8px;
}

/* Old Done button styles - removed */
.media-done-btn {
    display: none;
}

/* ===== CAROUSEL STRUCTURE ===== */

.media-block-carousel {
    position: relative;
    width: 100%;
    max-width: 100%;
    display: inline-block;
}

/* New architecture - Carousel Frame */
/* Always visible, even when empty - contains controls */
.media-carousel-frame {
    position: relative;
    width: 100%;
    max-width: 100%;
    display: inline-block;
    min-height: 60px; /* Ensure space for edit button even when images are hidden */
}

/* New architecture - Controls Frame (edit button and arrows) */
/* Always overlays the carousel images */
.media-controls-frame {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none; /* Allow clicks to pass through to images */
    z-index: 100;
}

.media-controls-frame > * {
    pointer-events: auto; /* But buttons themselves should be clickable */
}

/* New architecture - Images container */
.media-carousel-images {
    position: relative;
    width: 100%;
    display: inline-block;
}

.media-carousel-track {
    position: relative;
    width: 100%;
    display: inline-block;
}

.media-carousel-slide {
    display: none;
    width: 100%;
}

.media-carousel-slide.active,
.media-carousel-slide[style*="display: block"] {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

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

/* Loading animation overlay */
.media-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none; /* Hidden by default, shown with fadeIn */
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 200; /* Above controls but below uploader */
    border-radius: 8px;
}

.media-loading-icon {
    width: 60px;
    height: 60px;
}

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

/* Block with content */
.media-block-content {
    position: relative;
    width: auto;
    max-width: 100%;
    display: inline-block;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

/* Empty state - minimal container, no visible frame */
.media-block-empty-content {
    border: none !important;
    background: transparent !important;
    width: auto !important;
    min-height: 60px; /* Just enough for edit button */
    display: block;
    position: relative;
}

/* When block is empty and waiting for queue */
.ai-workflow-block.media.is-empty .media-block-waiting {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #f9f9f9;
    border: 2px solid #ddd;
    border-radius: 8px;
}

/* When block is empty and active (has control), show FilePond frame */
.ai-workflow-block.media.is-empty.is-active .media-block-uploader {
    width: 100%;
    min-height: 400px;
    background: #f9f9f9;
    border: 2px solid black;
    border-radius: 8px;
    padding: 20px;
}

/* Add new image content (Hidden - not used) */
.media-add-new-slide,
.media-add-new-content,
.media-add-new-overlay,
.media-add-new-btn,
.media-add-indicator {
    display: none !important;
}

.media-block-figure {
    margin: 0;
    position: relative;
    width: auto;
    max-width: 100%;
    display: inline-block;
}

.media-block-image {
    width: auto;
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===== NAVIGATION BUTTONS ===== */

.media-block-carousel .media-nav-btn,
.media-carousel-frame .media-nav-btn {
    position: absolute;
    top: 5px; /* Default: 5px from top for small images */
    transform: none; /* No transform for small images */
    width: 50px;
    height: 50px;
    border-radius: 50% !important;
    background: rgba(0, 0, 0, 0.5) !important;
    border: 2px solid rgba(255, 255, 255, 0.8) !important;
    color: white !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100;
    padding: 0 !important;
}

/* For tall images (>= 200px), center the arrows vertically */
.media-block-carousel.tall-image .media-nav-btn,
.media-carousel-frame.tall-image .media-nav-btn {
    top: 50%;
    transform: translateY(-50%);
}

.media-block-carousel .media-nav-btn:hover,
.media-carousel-frame .media-nav-btn:hover {
    background: rgba(0, 0, 0, 0.7) !important;
    transform: scale(1.1); /* Scale only for small images */
}

.media-block-carousel .media-nav-btn:active,
.media-carousel-frame .media-nav-btn:active {
    transform: scale(0.95); /* Scale only for small images */
}

/* For tall images, maintain centering during hover/active */
.media-block-carousel.tall-image .media-nav-btn:hover,
.media-carousel-frame.tall-image .media-nav-btn:hover {
    transform: translateY(-50%) scale(1.1);
}

.media-block-carousel.tall-image .media-nav-btn:active,
.media-carousel-frame.tall-image .media-nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.media-block-carousel .media-nav-prev,
.media-carousel-frame .media-nav-prev {
    left: 5px;
}

.media-block-carousel .media-nav-next,
.media-carousel-frame .media-nav-next {
    right: 5px;
}

.media-block-carousel .media-nav-btn svg,
.media-carousel-frame .media-nav-btn svg {
    width: 24px;
    height: 24px;
    stroke: white !important;
    stroke-width: 3;
    fill: none;
}

/* Hide arrows at boundaries */
.media-block-carousel .media-nav-btn.hidden,
.media-carousel-frame .media-nav-btn.hidden {
    display: none !important;
}

/* ===== DELETE BUTTON (Hidden - not used in carousel view) ===== */

.media-delete-btn {
    display: none;
}

/* ===== EDIT BUTTON ===== */

.media-edit-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 1)!important;
    border: 1px solid lightgray;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    overflow: hidden;
    z-index: 100;
    pointer-events: auto;
    position: absolute;
}

.media-edit-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.95)!important;
    border-color: black;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.media-edit-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.media-edit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.media-edit-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Edit button in empty state - bottom right (same as carousel) */
.media-edit-btn-empty {
    position: absolute;
    bottom: 0;
    right: 0;
}

.media-edit-btn-empty:hover:not(:disabled) {
    transform: scale(1.1);
}

.media-edit-btn-empty:active:not(:disabled) {
    transform: scale(0.95);
}

/* Edit button in carousel - bottom right */
.media-edit-btn-carousel {
    position: absolute;
    bottom: 20px;
    right: 20px;
}

/* Edit button in new controls frame - bottom right */
.media-controls-frame .media-edit-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
}

/* YouTube video container */
.media-block-video {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 16 / 9;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

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

/* ===== ADD NEW IMAGE OVERLAY ===== */

.media-add-new-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(240, 240, 240, 0.9);
    z-index: 5;
}

.media-add-new-btn {
    padding: 16px 32px;
    font-size: 18px;
    font-weight: 600;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.media-add-new-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.4);
}

.media-add-new-btn:active {
    transform: translateY(0);
}

/* ===== CLOSE BUTTONS ===== */

.media-close-btn {
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent!important;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.media-close-btn:hover {
    transform: scale(1.1);
}

.media-close-btn:active {
    transform: scale(0.95);
}

.media-close-icon {
    width: 100%;
    height: 100%;
    display: block;
}

/* Close button - top right */
.media-close-btn-top {
    top: 10px;
    right: 10px;
}

/* ===== CAROUSEL INDICATORS (Removed - not needed) ===== */

.media-carousel-indicators {
    display: none !important;
}

/* Completed state */
.ai-workflow-block.media.is-completed .media-block-waiting {
    background: #e8f5e9;
    border-color: #4CAF50;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .ai-workflow-block.media {
        margin: 15px 0;
    }

    .media-block-waiting,
    .media-block-empty {
        padding: 30px 15px;
    }

    .media-block-message {
        font-size: 16px;
    }

    .media-close-btn {
        width: 36px;
        height: 36px;
    }
    
    .media-close-btn-top {
        top: 5px;
        right: 5px;
    }

    .media-edit-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .media-block-carousel .media-nav-btn {
        width: 45px;
        height: 45px;
    }

    .media-block-carousel .media-nav-btn svg {
        width: 20px;
        height: 20px;
    }

    .media-block-carousel .media-nav-prev {
        left: 3px;
    }

    .media-block-carousel .media-nav-next {
        right: 3px;
    }
}


/* ============================================
   Empty State Instructions
   ============================================ */
.block-empty-instructions {
    background: transparent;
    border: none;
    padding: 20px 30px 30px 30px;
    margin-top: 20px;
    text-align: center;
    max-width: 100%;
}

.media-instructions-content h3 {
    margin: 0 0 15px 0;
    font-size: 24px;
    font-weight: 600;
    color: #2c3e50;
}

.media-instructions-content > p {
    margin: 0 0 20px 0;
    font-size: 16px;
    color: #495057;
    line-height: 1.5;
}

.media-instructions-list {
    list-style: none;
    padding: 0;
    margin: 0 0 20px 0;
    text-align: left;
    display: inline-block;
}

.media-instructions-list li {
    margin: 10px 0;
    padding: 8px 15px;
    background: white;
    border-radius: 4px;
    font-size: 14px;
    color: #495057;
}

.media-instructions-list li strong {
    color: #2c3e50;
    font-weight: 600;
}

.media-instructions-tip {
    margin: 20px 0 0 0;
    padding: 15px;
    background: #e3f2fd;
    border-left: 4px solid #2196F3;
    border-radius: 4px;
    font-size: 14px;
    color: #1976d2;
    font-style: italic;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .block-empty-instructions {
        padding: 15px 20px 20px 20px;
        margin-top: 15px;
    }

    .media-instructions-content h3 {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .media-instructions-content > p {
        font-size: 14px;
        margin-bottom: 15px;
    }

    .media-instructions-list li {
        font-size: 13px;
        padding: 6px 12px;
    }

    .media-instructions-tip {
        font-size: 13px;
        padding: 12px;
    }
}

/* ============================================
   FilePond Image Visibility Controls
   ============================================ */

/* Visibility control button on FilePond items - matches edit button style */
.filepond-visibility-control {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 10;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    width: 30px;
    height: 30px;
    padding: 5px!important;
    
    background: white!important;
    border: 1px solid black!important;
    border-radius: 10px;
    
    cursor: pointer;
    transition: all 0.2s ease;
    
    overflow: hidden;
}

.filepond-visibility-control:hover {
    transform: scale(1.1);
}

.filepond-visibility-control:active {
    transform: scale(0.95);
}

.filepond-visibility-control .control-icon {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

/* Hidden image state - dim the entire FilePond item */
.filepond--item[style*="opacity: 0.5"] {
    filter: grayscale(50%);
}

/* Mobile responsiveness for FilePond controls */
@media (max-width: 768px) {
    .filepond-visibility-control {
        width: 36px;
        height: 36px;
        bottom: 8px;
        left: 8px;
    }
}

