/**
 * Instagram Insights Admin Page Styles
 *
 * @package wpzoom/instagram-widget-by-wpzoom
 * @since 2.0.0
 */

// Variables
$color-positive: #28a745;
$color-negative: #dc3545;
$color-primary: #2271b1;
$color-primary-hover: #135e96;
$color-border: #ddd;
$color-text: #1d2327;
$color-text-light: #666;
$color-background: #fff;
$color-background-alt: #f8f9fa;
$color-skeleton: #e0e0e0;
$border-radius: 8px;
$box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);

// Animations
@keyframes skeleton-pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
    100% {
        opacity: 1;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.wpzoom-instagram-insights {
    padding: 20px;

    // Loading state
    &.is-loading {
        pointer-events: none;
    }

    .insights-container {
        margin-top: 20px;

        &.is-loading {
            .metric-card,
            .chart-container,
            .recent-posts-section {
                position: relative;
            }
        }
    }

    // Error notice
    .insights-error {
        margin: 15px 0;
        padding: 12px 15px;
        position: relative;

        &.fade-out {
            animation: fade-out 0.3s ease-out forwards;
        }

        p {
            margin: 0;
            padding-right: 30px;
        }

        .notice-dismiss {
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%);
            padding: 0;
            background: none;
            border: none;
            cursor: pointer;

            &:before {
                content: '\f153';
                font: normal 16px/1 dashicons;
                color: #787c82;
            }

            &:hover:before {
                color: #d63638;
            }
        }
    }

    // Header with selectors
    .insights-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
        flex-wrap: wrap;
        gap: 15px;
    }

    .account-selector,
    .period-selector {
        select {
            min-width: 200px;
            padding: 8px 12px;
            border-radius: 4px;
            border: 1px solid $color-border;
            font-size: 14px;
            background-color: $color-background;

            &:focus {
                border-color: $color-primary;
                box-shadow: 0 0 0 1px $color-primary;
                outline: none;
            }
        }
    }

    // Date range display
    .date-range-display {
        background: #f0f0f1;
        padding: 10px 15px;
        border-radius: 4px;
        margin-bottom: 20px;
        text-align: center;
        font-size: 14px;
        color: #50575e;
    }

    // Metric cards grid
    .insights-metrics {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 20px;
        margin-bottom: 30px;
    }

    // Individual metric card
    .metric-card {
        background: $color-background;
        border-radius: $border-radius;
        padding: 20px;
        box-shadow: $box-shadow;

        h3 {
            margin: 0 0 10px 0;
            font-size: 14px;
            color: $color-text-light;
            font-weight: 500;
        }

        .metric-value {
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 8px;
            color: $color-text;
            min-height: 34px;

            &.skeleton {
                background: $color-skeleton;
                border-radius: 4px;
                animation: skeleton-pulse 1.5s ease-in-out infinite;
                width: 80%;
                height: 34px;
            }
        }

        .metric-change {
            font-size: 14px;
            color: $color-text-light;
            min-height: 21px;

            &.skeleton {
                background: $color-skeleton;
                border-radius: 4px;
                animation: skeleton-pulse 1.5s ease-in-out infinite;
                width: 60%;
                height: 21px;
            }

            &.positive {
                color: $color-positive;

                &:before {
                    content: "\2191 "; // Up arrow
                }
            }

            &.negative {
                color: $color-negative;

                &:before {
                    content: "\2193 "; // Down arrow
                }
            }
        }

        // Followers card specific styles
        &.followers {
            .followers-breakdown {
                display: flex;
                gap: 16px;
                margin-top: 12px;
                padding-top: 12px;
                border-top: 1px solid $color-border;

                .breakdown-item {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    flex: 1;

                    .breakdown-label {
                        font-size: 11px;
                        color: $color-text-light;
                        text-transform: uppercase;
                        letter-spacing: 0.5px;
                        margin-bottom: 4px;
                    }

                    .breakdown-value {
                        font-size: 16px;
                        font-weight: 600;
                        color: $color-text;

                        &.positive {
                            color: $color-positive;
                        }

                        &.negative {
                            color: $color-negative;
                        }
                    }

                    &.new .breakdown-value {
                        color: $color-positive;
                    }

                    &.lost .breakdown-value {
                        color: $color-negative;
                    }
                }
            }
        }
    }

    // Charts section
    .insights-charts {
        display: grid;
        grid-template-columns: 1fr;
        gap: 30px;
        margin-top: 30px;

        @media (min-width: 1200px) {
            grid-template-columns: 1fr 1fr;
        }
    }

    .chart-container {
        background: $color-background;
        border-radius: $border-radius;
        padding: 20px;
        box-shadow: $box-shadow;
        height: 400px;
        position: relative;

        .chart-title {
            margin: 0 0 5px 0;
            font-size: 14px;
            font-weight: 600;
            color: $color-text;
        }

        .chart-note {
            margin: 0 0 10px 0;
            font-size: 12px;
            color: $color-text-light;
            font-style: italic;
        }

        canvas {
            max-height: calc(100% - 40px);
        }
    }

    // Chart loading overlay
    .chart-loading-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: $border-radius;
        z-index: 10;
    }

    // Loading spinner
    .loading-spinner {
        width: 40px;
        height: 40px;
        border: 3px solid #f3f3f3;
        border-top: 3px solid $color-primary;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }

    // Recent posts section
    .recent-posts-section {
        margin-top: 40px;
        background: $color-background;
        padding: 20px;
        border-radius: $border-radius;
        box-shadow: $box-shadow;

        h2 {
            margin: 0 0 20px 0;
            font-size: 18px;
            color: $color-text;
        }
    }

    .recent-posts-grid {
        display: flex;
        flex-direction: column;
        gap: 20px;

        &.is-loading {
            .recent-post {
                display: none;
            }
        }

        .no-posts {
            color: $color-text-light;
            font-style: italic;
            padding: 20px;
            text-align: center;
        }
    }

    // Posts loading placeholder
    .posts-loading-placeholder {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .post-skeleton {
        background: $color-skeleton;
        border-radius: $border-radius;
        height: 200px;
        animation: skeleton-pulse 1.5s ease-in-out infinite;
    }

    // Individual post card
    .recent-post {
        background: $color-background-alt;
        border-radius: $border-radius;
        overflow: hidden;
        transition: transform 0.2s, box-shadow 0.2s;
        display: flex;
        align-items: flex-start;

        &:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .post-thumbnail {
            flex: 0 0 200px;
            height: 200px;
            background: #eee;
            position: relative;
            overflow: hidden;

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

            .media-type-badge {
                position: absolute;
                top: 10px;
                left: 10px;
                background: rgba(0, 0, 0, 0.7);
                color: #fff;
                padding: 4px 8px;
                border-radius: 4px;
                font-size: 10px;
                font-weight: 600;
                text-transform: uppercase;
            }
        }

        .post-content {
            flex: 1;
            padding: 15px;
        }

        .post-caption {
            margin-bottom: 15px;
            font-size: 14px;
            color: $color-text;
            line-height: 1.5;
        }

        .post-stats {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
            gap: 12px;

            .stat {
                background: $color-background;
                padding: 10px;
                border-radius: 4px;
                box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);

                .label {
                    display: block;
                    font-size: 11px;
                    color: $color-text-light;
                    margin-bottom: 4px;
                    text-transform: uppercase;
                    letter-spacing: 0.5px;
                }

                .value {
                    font-size: 16px;
                    font-weight: 600;
                    color: $color-text;
                }
            }
        }

        .post-meta {
            margin-top: 15px;
            padding-top: 15px;
            border-top: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .view-post {
                text-decoration: none;
                color: $color-primary;
                font-size: 13px;
                font-weight: 500;

                &:hover {
                    color: $color-primary-hover;
                    text-decoration: underline;
                }
            }

            .post-date {
                font-size: 12px;
                color: $color-text-light;
            }
        }

        // Responsive
        @media (max-width: 768px) {
            flex-direction: column;

            .post-thumbnail {
                flex: 0 0 auto;
                width: 100%;
                height: 250px;
            }

            .post-stats {
                grid-template-columns: repeat(2, 1fr);
            }
        }
    }

    // Load More button wrapper
    .load-more-wrapper {
        margin-top: 20px;
        text-align: center;

        .load-more-button {
            min-width: 200px;
            padding: 10px 24px;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s ease;

            &:disabled {
                opacity: 0.7;
                cursor: not-allowed;
            }

            &:hover:not(:disabled) {
                transform: translateY(-1px);
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
            }
        }
    }

    // Demo/Upsell Mode Styles
    &.is-demo {
        position: relative;
        min-height: 80vh;

        .insights-demo-content {
            filter: blur(3px);
            pointer-events: none;
            user-select: none;
            opacity: 0.7;
        }

        .demo-chart-placeholder {
            width: 100%;
            height: calc(100% - 40px);
            display: flex;
            align-items: center;
            justify-content: center;

            svg {
                width: 100%;
                height: 100%;
            }
        }

        .demo-thumbnail-placeholder {
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
        }

        .demo-post {
            .post-thumbnail {
                background: #f0f0f0;
            }
        }
    }

    // Upsell Overlay
    .insights-upsell-overlay {
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding-top: 80px;
        z-index: 100;
        background: rgba(255, 255, 255, 0.1);
    }

    // Upsell Modal
    .insights-upsell-modal {
        background: $color-background;
        border-radius: 12px;
        box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
        padding: 40px 50px;
        max-width: 520px;
        text-align: center;
        animation: modal-appear 0.3s ease-out;

        @keyframes modal-appear {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .upsell-icon {
            margin-bottom: 20px;

            svg {
                width: 64px;
                height: 64px;
            }
        }

        h2 {
            margin: 0 0 15px 0;
            font-size: 24px;
            font-weight: 600;
            color: $color-text;
        }

        .upsell-description {
            margin: 0 0 25px 0;
            font-size: 15px;
            line-height: 1.6;
            color: $color-text-light;
        }

        .upsell-features {
            text-align: left;
            margin: 0 0 30px 0;
            padding: 0;
            list-style: none;

            li {
                position: relative;
                padding-left: 28px;
                margin-bottom: 12px;
                font-size: 14px;
                color: $color-text;
                line-height: 1.5;

                &:before {
                    content: '';
                    position: absolute;
                    left: 0;
                    top: 2px;
                    width: 18px;
                    height: 18px;
                    background: linear-gradient(135deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
                    border-radius: 50%;
                }

                &:after {
                    content: '✓';
                    position: absolute;
                    left: 4px;
                    top: 3px;
                    font-size: 11px;
                    color: #fff;
                    font-weight: bold;
                }

                &:last-child {
                    margin-bottom: 0;
                }
            }
        }

        .button-upsell-primary {
            display: inline-block;
            background: linear-gradient(135deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
            color: #fff !important;
            font-size: 16px;
            font-weight: 600;
            padding: 14px 40px;
            border-radius: 6px;
            text-decoration: none;
            transition: all 0.2s ease;
            border: none;
            cursor: pointer;

            &:hover {
                box-shadow: 0 4px 15px rgba(220, 39, 67, 0.4);
                color: #fff !important;
            }

            &:active {
                transform: translateY(0);
            }
        }

        .upsell-note {
            margin: 20px 0 0 0;
            font-size: 13px;
            color: $color-text-light;
        }
    }
}
