/**
 * InstaSave Custom Downloader Styles
 * Clean CSS from scratch
 */

/* ========================================
   RESULTS CONTAINER
   ======================================== */
#instasave-results {
    margin: 40px auto;
    max-width: 900px;
    padding: 0 20px;
}

.instasave-results-container {
    width: 100%;
}

/* ========================================
   RESULTS HEADER - Premium Style
   ======================================== */
.results-title {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 20px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 20px 30px;
    border-radius: 16px 16px 0 0;
    margin: 0;
}

.results-title .material-icons {
    font-size: 28px;
    color: #00e676;
    filter: drop-shadow(0 0 8px rgba(0, 230, 118, 0.5));
}

.media-count {
    font-size: 13px;
    font-weight: 500;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 100%);
    color: #fff;
    padding: 6px 16px;
    border-radius: 20px;
    margin-left: 8px;
}

/* ========================================
   LOADING ANIMATION
   ======================================== */
.instasave-loading {
    background: #fff;
    border-radius: 20px;
    padding: 50px 40px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    margin: 0 auto;
}

.loading-spinner {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 25px;
}

.loading-spinner .dot {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    border-radius: 50%;
    animation: dotBounce 1.4s infinite ease-in-out both;
}

.loading-spinner .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-spinner .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.loading-spinner .dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes dotBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.instasave-loading p {
    color: #333;
    font-size: 18px;
    font-weight: 500;
    margin: 0;
}

/* ========================================
   SINGLE MEDIA VIEWER
   ======================================== */
.single-media-viewer {
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.15);
    max-width: 600px;
    margin: 0 auto;
}

.single-media-viewer .main-media {
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.single-media-viewer .main-video,
.single-media-viewer .main-image {
    width: 100%;
    max-height: 70vh;
    object-fit: contain;
}

.single-media-viewer .main-download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    color: #fff !important;
    text-decoration: none !important;
    padding: 18px 30px;
    font-size: 16px;
    font-weight: 600;
    transition: filter 0.2s;
}

.single-media-viewer .main-download-btn:hover {
    filter: brightness(1.1);
}

/* ========================================
   GALLERY VIEWER (Multiple Media)
   ======================================== */
.gallery-viewer {
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

/* Main media area */
.main-media-area {
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
    padding: 20px;
    position: relative;
}

/* Gallery Navigation Arrows */
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.25s ease;
    z-index: 10;
}

.gallery-nav:hover:not(:disabled) {
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    border-color: transparent;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 8px 25px rgba(131, 58, 180, 0.4);
}

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

.gallery-nav .material-icons {
    font-size: 28px;
}

.gallery-prev {
    left: 30px;
}

.gallery-next {
    right: 30px;
}

.main-media {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

.main-video,
.main-image {
    width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 12px;
}

/* Custom Video Player Styling */
.main-video {
    background: #000;
}

.main-video::-webkit-media-controls-panel {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
}

.main-video::-webkit-media-controls-play-button,
.main-video::-webkit-media-controls-volume-slider,
.main-video::-webkit-media-controls-mute-button {
    filter: brightness(1.2);
}

.main-media-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    margin: 15px;
    border-radius: 12px;
    position: relative;
    z-index: 1;
}

.current-index {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 100%);
    padding: 8px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(131, 58, 180, 0.3);
}

.main-download-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    color: #fff !important;
    text-decoration: none !important;
    padding: 12px 25px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(131, 58, 180, 0.4);
}

.main-download-btn:hover {
    transform: scale(1.05);
}

/* Thumbnails grid */
.gallery-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    padding: 15px;
    background: #f8f9fa;
}

.gallery-thumb {
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    border: 3px solid transparent;
    transition: all 0.2s ease;
}

.gallery-thumb.active {
    border-color: #833ab4;
    box-shadow: 0 0 0 2px rgba(131, 58, 180, 0.3);
}

.gallery-thumb:hover:not(.active) {
    border-color: rgba(131, 58, 180, 0.5);
    transform: scale(1.05);
}

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

.thumb-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 28px;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* Media count badge */
.media-count {
    font-size: 12px;
    font-weight: 500;
    background: rgba(131, 58, 180, 0.15);
    color: #833ab4;
    padding: 4px 12px;
    border-radius: 15px;
    margin-left: 10px;
}

/* ========================================
   RESPONSIVE GALLERY
   ======================================== */
@media (max-width: 768px) {
    .gallery-thumbs {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
        padding: 10px;
    }

    .gallery-thumb {
        border-width: 2px;
    }

    .main-media-actions {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
        margin-top: -80px;
    }

    .main-download-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ========================================
   SINGLE CARD
   ======================================== */
.instasave-card {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.instasave-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.18);
}

/* Card Media */
.card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #111;
    cursor: pointer;
    overflow: hidden;
}

.card-media img,
.card-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.card-media:hover img,
.card-media:hover video {
    transform: scale(1.05);
}

/* Play overlay for videos */
.card-media .play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.card-media:hover .play-overlay {
    opacity: 1;
}

.card-media .play-overlay .material-icons {
    font-size: 72px;
    color: #fff;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Download Button */
.card-download {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    color: #fff !important;
    text-decoration: none !important;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 600;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.card-download:hover {
    filter: brightness(1.1);
    transform: scale(1.02);
}

.card-download .material-icons {
    font-size: 22px;
}

/* ========================================
   ERROR MESSAGE
   ======================================== */
.instasave-error {
    background: #fff;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    margin: 0 auto;
}

.instasave-error .material-icons {
    font-size: 56px;
    color: #fd1d1d;
    margin-bottom: 15px;
}

.instasave-error p {
    color: #333;
    font-size: 16px;
    margin: 0 0 25px;
}

.instasave-error button {
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    border: none;
    border-radius: 30px;
    padding: 14px 35px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.instasave-error button:hover {
    transform: scale(1.05);
}

/* ========================================
   MODERN MINIMAL LIGHTBOX VIEWER
   ======================================== */
#instasave-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.96);
    cursor: pointer;
    backdrop-filter: blur(15px);
}

.lightbox-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    max-height: 100vh;
    z-index: 1;
}

/* Header */
.lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.5);
}

.lightbox-back-btn,
.lightbox-share-btn,
.lightbox-close-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.lightbox-back-btn:hover,
.lightbox-share-btn:hover,
.lightbox-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.lightbox-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    padding: 0 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lightbox-header-actions {
    display: flex;
    gap: 8px;
}

/* Story Progress Bar */
.story-progress {
    display: flex;
    gap: 4px;
    padding: 8px 16px 0;
}

.progress-segment {
    flex: 1;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.progress-segment .progress-fill {
    height: 100%;
    background: #fff;
    width: 0%;
    transition: width 0.1s linear;
}

.progress-segment.completed .progress-fill {
    width: 100%;
}

.progress-segment.active .progress-fill {
    animation: storyFill 5s linear forwards;
}

@keyframes storyFill {
    to {
        width: 100%;
    }
}

/* Main content area */
.lightbox-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 20px;
    min-height: 0;
}

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

.lightbox-media {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 12px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
    object-fit: contain;
}

/* Tap zones for stories */
.tap-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 35%;
    cursor: pointer;
    z-index: 5;
}

.tap-zone-prev {
    left: 0;
}

.tap-zone-next {
    right: 0;
}

.tap-zone:active {
    background: rgba(255, 255, 255, 0.05);
}

/* Bottom bar - unified controls */
.lightbox-bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 15px 20px 25px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}

.nav-spacer,
.indicator-spacer {
    width: 44px;
    flex-shrink: 0;
}

.lightbox-nav-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.lightbox-nav-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    border-color: transparent;
    transform: scale(1.1);
}

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

/* Indicators */
.lightbox-indicators {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    max-width: 200px;
}

.lightbox-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    border: none;
    cursor: pointer;
    transition: all 0.25s ease;
}

.lightbox-dot.active {
    background: #fff;
    width: 24px;
    border-radius: 4px;
}

.lightbox-dot:hover:not(.active) {
    background: rgba(255, 255, 255, 0.6);
    transform: scale(1.2);
}

/* Download button */
.lightbox-download-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    color: #fff !important;
    text-decoration: none !important;
    padding: 12px 28px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 6px 25px rgba(131, 58, 180, 0.4);
    flex-shrink: 0;
}

.lightbox-download-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 35px rgba(131, 58, 180, 0.5);
}

.lightbox-download-btn .material-icons {
    font-size: 20px;
}

/* Story mode specific */
#instasave-lightbox.story-mode .lightbox-container {
    max-width: 450px;
}

#instasave-lightbox.story-mode .lightbox-media {
    max-height: 75vh;
    border-radius: 16px;
}

#instasave-lightbox.story-mode .lightbox-bottom {
    padding: 10px 16px 20px;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    #instasave-results {
        padding: 0 15px;
        margin: 30px auto;
    }

    .instasave-cards-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .instasave-loading,
    .instasave-error {
        padding: 35px 25px;
    }

    .lightbox-close {
        top: -40px;
        right: -5px;
    }
}