/* Base Modal Structure */
.api-post-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--modal-z-index, 99999999);
    display: none;
    overflow: hidden !important;
    background: var(--modal-bg, #fff);
    will-change: opacity, visibility;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    pointer-events: none; /* Prevent unwanted clicks when hidden */
}

.api-post-modal.active {
    display: block;
    pointer-events: auto; /* Enable interactions when visible */
    animation: modalFadeIn 0.2s ease-out forwards;
}

/* Add smooth transition */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        visibility: hidden;
    }
    to {
        opacity: 1;
        visibility: visible;
    }
}

/* Modal States */
.api-post-modal.fullscreen-mode {
    display: block;
}

/* Modal Content */
.api-post-modal-content {
    position: fixed;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Essential Modal Header Structure - Both Modes */
.api-post-modal-header,
.api-post-modal.fullscreen-mode .api-post-modal-header {
    position: static;
    /* Changed from fixed to static */
    top: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    height: 44px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #eee;
    padding: 0;
    width: 100%;
    transition: all 0.3s ease;
}

/* Fullscreen Mode Header Specific */
.api-post-modal.fullscreen-mode .api-post-modal-header {
    position: fixed;
    z-index: 999999;
}

/* Jika ingin memastikan jarak minimum di tengah header */
.api-post-modal-header::before {
    content: '';
    grid-column: 2;
    min-width: 100px;
    /* Jarak minimum */
}

/* Middle Space for Both Modes */
.api-post-modal-header::after,
.api-post-modal.fullscreen-mode .api-post-modal-header::after {
    content: '';
    flex: 1;
    min-width: 300px;
    height: 1px;
}

/* Preview Buttons Group for Both Modes */
.api-post-modal-preview-buttons,
.api-post-modal.fullscreen-mode .api-post-modal-preview-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 20px;
    flex: 0 0 auto;
    margin-right: auto;
    grid-column: 1;
    justify-self: start;
}

.api-post-modal-preview-buttons .preview-button,
.api-post-modal.fullscreen-mode .api-post-modal-preview-buttons .preview-button {
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.api-post-modal-preview-buttons .preview-button:hover {
    background-color: transparent !important;
}

.api-post-modal-preview-buttons .preview-button.active {
    background-color: transparent !important;
}

/* Close Button for Both Modes */
.api-post-modal-close,
.api-post-modal.fullscreen-mode .api-post-modal-close {
    padding: 8px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    margin-left: auto;
    margin-right: 20px;
    flex: 0 0 auto;
    grid-column: 3;
    justify-self: end;
    z-index: 10000001;
}

.api-post-modal-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Content Area for Both Modes */
.api-post-modal-body,
.api-post-modal.fullscreen-mode .api-post-modal-body {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    background: #fff;
    overflow: auto;
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Wrapper untuk scaling (pembungkus luar) */
.iframe-scaler {
    position: absolute;
    top: 50% !important;
    left: 50% !important;
    /* transform akan diatur oleh JS */
    transform-origin: center center !important;
    transition: transform 0.3s ease-out, width 0.3s ease-out, height 0.3s ease-out;
    will-change: transform;
}

/* Wrapper untuk ukuran (pembungkus dalam) */
.iframe-container {
    /* Ukuran akan diatur oleh JS, pastikan tidak ada style yang mengganggu */
    overflow: hidden;
    background: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.api-post-modal-iframe {
    /* Ukuran akan diatur oleh JavaScript, hapus aturan width/height dari sini. */
    border: none;
    max-width: none; /* Mencegah iframe menjadi responsif terhadap container-nya */
    transform-origin: top left; /* Pastikan scaling dimulai dari pojok kiri atas */
}



/* Normal mode body position */
.api-post-modal .api-post-modal-body {
    top: 44px;
    /* Match normal header height */
}

/* Fullscreen mode body position - follows header height from Elementor controls */
.api-post-modal.fullscreen-mode .api-post-modal-body {
    top: 70px;
    /* Match fullscreen header height - should be sync with the value in Elementor controls */
}
/* Only structural CSS, styling moved to widget controls */

/* Modal Header Layout for Elementor Container */
.elementor-section.elementor-section-boxed .api-post-modal-header {
    max-width: var(--container-max-width, 1140px);
    margin: 0 auto;
    width: 100%;
    padding: 0;
}

/* Preview Buttons Group (Left Side) */
.elementor-section.elementor-section-boxed .api-post-modal-preview-buttons {
    margin-left: var(--container-padding, 20px);
    flex: 0 0 auto;
}

/* Close Button (Right Side) */
.elementor-section.elementor-section-boxed .api-post-modal-close {
    margin-right: var(--container-padding, 20px);
    flex: 0 0 auto;
}

/* Middle Spacing for Container */
.elementor-section.elementor-section-boxed .api-post-modal-header::after {
    content: '';
    flex: 1;
    min-width: 200px;
}

/* Responsive Container Adjustments */
@media (max-width: 1024px) {
    .elementor-section.elementor-section-boxed .api-post-modal-header {
        max-width: var(--container-max-width-tablet, 1024px);
        padding: 0 var(--container-padding-tablet, 15px);
    }
}

@media (max-width: 767px) {
    .elementor-section.elementor-section-boxed .api-post-modal-header {
        max-width: var(--container-max-width-mobile, 767px);
        padding: 0 var(--container-padding-mobile, 10px);
    }
}

/* Mobile Adjustments for Both Modes */
@media (max-width: 767px) {

    /* Common header styles for both modes */
    .api-post-modal-header,
    .api-post-modal.fullscreen-mode .api-post-modal-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        padding: 0 10px !important;
        overflow: visible !important;
        height: 50px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Hide pseudo elements for both modes */
    .api-post-modal-header::before,
    .api-post-modal-header::after,
    .api-post-modal.fullscreen-mode .api-post-modal-header::before,
    .api-post-modal.fullscreen-mode .api-post-modal-header::after {
        display: none !important;
    }

    /* Preview buttons styles for both modes */
    .api-post-modal-preview-buttons,
    .api-post-modal.fullscreen-mode .api-post-modal-preview-buttons {
        flex: 0 1 auto !important;
        margin-left: 5px !important;
        margin-right: 0 !important;
        max-width: 65% !important;
        overflow-x: auto !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }

    /* Close button styles for both modes */
    .api-post-modal-close,
    .api-post-modal.fullscreen-mode .api-post-modal-close {
        position: static !important;
        visibility: visible !important;
        opacity: 1 !important;
        min-width: 40px !important;
        min-height: 40px !important;
        margin-left: auto !important;
        margin-right: 5px !important;
    }
}

/* Khusus untuk perangkat sangat kecil */
@media (max-width: 375px) {
    .api-post-modal-preview-buttons {
        max-width: 55% !important;
        /* Batasi lebih banyak pada layar sangat kecil */
    }

    .api-post-modal-close {
        padding: 8px 5px !important;
        /* Padding lebih kecil */
    }
}

/* Responsive Adjustments */
@media (max-width: 767px) {
    .api-post-modal-header {
        height: 50px !important;
        padding: 0 10px !important;
    }
    
    .api-post-modal-preview-buttons {
        max-width: 65% !important;
    }
}

/* Prevent unwanted scrolling */
body.modal-open {
    overflow: hidden !important;
    padding-right: var(--scrollbar-width, 0px);
}

/* Remove all existing SVG styling rules and replace with this optimized version */

/* Base Icon System */
.api-post-modal {
    --device-icon-color: currentColor;
    --device-icon-hover-color: currentColor;
    --device-icon-active-color: currentColor;
    --close-icon-color: currentColor;
    --close-icon-hover-color: currentColor;
    --icon-size: 24px;
    --transition-speed: 0.3s;
    --spinner-size: 50px;
    --spinner-border-width: 2px;
    --spinner-border-color: rgba(0, 0, 0, 0.1); /* Ubah ini */
    --spinner-border-top-color: #3498db;
}

/* Icon Container Base Styles */
.api-post-modal .icon-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

/* Device Preview Icons - Normal State */
body .api-post-modal .preview-button .icon-container i,
body #modal-api-post-grid .preview-button .icon-container i {
    color: inherit !important;
}

body .api-post-modal .preview-button .icon-container svg,
body .api-post-modal .preview-button .icon-container svg path,
body #modal-api-post-grid .preview-button .icon-container svg,
body #modal-api-post-grid .preview-button .icon-container svg path {
    fill: currentColor !important;
}

/* Close Button Icon */
body .api-post-modal .api-post-modal-close .icon-container i,
body #modal-api-post-grid .api-post-modal-close .icon-container i {
    color: inherit !important;
}

body .api-post-modal .api-post-modal-close .icon-container svg,
body .api-post-modal .api-post-modal-close .icon-container svg path,
body #modal-api-post-grid .api-post-modal-close .icon-container svg,
body #modal-api-post-grid .api-post-modal-close .icon-container svg path {
    fill: currentColor !important;
}

/* Ensure SVG inherits colors properly */
.api-post-modal .icon-container svg[style],
.api-post-modal .icon-container svg *[style] {
    fill: inherit !important;
    color: inherit !important;
}

/* Force color inheritance in Elementor editor */
.elementor-editor-active .api-post-modal .icon-container svg.svg-processed,
.elementor-editor-active .api-post-modal .icon-container svg.svg-processed * {
    fill: inherit !important;
    stroke: inherit !important;
    color: inherit !important;
}

/* Remove any inline styles that might interfere */
.api-post-modal .icon-container svg[style],
.api-post-modal .icon-container svg *[style] {
    fill: inherit !important;
    stroke: inherit !important;
    color: inherit !important;
}

/* 1. Base styling untuk semua icon */
.api-post-modal .icon-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Loading indicator untuk modal */
.modal-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--loading-bg, rgba(255, 255, 255, 0.98));
    z-index: var(--loading-z-index, 99999);
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(5px);
}

/* State loading hidden */
.modal-loading.hidden {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

/* Layout 1: Spinner */
.modal-loading-spinner {
    width: var(--spinner-size, 50px);
    height: var(--spinner-size, 50px);
    border: var(--spinner-border-width, 3px) solid rgba(0, 0, 0, 0.1); /* Ubah ini */
    border-top-color: var(--spinner-color, #3498db) !important;
    border-radius: 50%;
    animation: spin 1.5s linear infinite, pulse 1.5s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

/* Layout 2: Progress Bar */
.modal-loading-progress {
    width: var(--progress-width, 200px);
    height: var(--progress-height, 4px);
    background: #f3f3f3;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
    margin-bottom: 20px;
}

.modal-loading-progress::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 40%;
    background: var(--progress-color, #3498db);
    animation: progress 1s ease-in-out infinite;
}

@keyframes progress {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

/* Layout 3: Custom Image */
.modal-loading-custom-image {
    width: var(--custom-image-width, 200px);
    height: auto;
    margin-bottom: 15px;
    animation: imagePulse 1.5s ease-in-out infinite;
}

@keyframes imagePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.95); opacity: 0.8; }
}

/* Loading Text & Animation */
.modal-loading-text {
    color: var(--loading-text-color, inherit);
    font-size: var(--loading-text-size, inherit);
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    position: relative; /* Tambahkan ini */
    opacity: 0.6;
}

.modal-loading-text::after {
    content: '';
    position: absolute;
    left: 100%; /* Ubah dari right ke left */
    margin-left: 5px; /* Beri jarak dari teks */
    top: 50%; /* Tengahkan vertikal */
    transform: translateY(-50%); /* Tengahkan vertikal */
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

/* Progress Bar Styles - Layout 2 */
.modal-loading-progress {
    width: var(--progress-width, 200px);
    height: var(--progress-height, 4px);
    background: #f3f3f3;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
    margin-bottom: 20px;
}

.modal-loading-progress .progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    background: var(--progress-color, #3498db);
    transition: width 0.3s linear;
}

/* Custom Image/Lottie Styles - Layout 3 */
.modal-loading-custom-image {
    width: var(--custom-image-width, 200px);
    height: auto;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-loading-custom-image img {
    max-width: 100%;
    height: auto;
    animation: imagePulse 1.5s ease-in-out infinite;
}

.modal-loading-custom-image lottie-player {
    width: var(--custom-image-width, 200px);
    height: var(--custom-image-width, 200px);
    animation: none;
}

/* Loading Layout Specific Styles */
.api-post-modal[data-active-layout="layout1"] .modal-loading {
    --loading-layout: spinner;
}

.api-post-modal[data-active-layout="layout2"] .modal-loading {
    --loading-layout: progress;
}

.api-post-modal[data-active-layout="layout3"] .modal-loading {
    --loading-layout: custom;
}

.api-post-modal[data-active-layout="layout3"] .modal-loading-text,
.api-post-modal[data-active-layout="layout3"] .modal-loading-text::after {
    display: none !important;
    animation: none !important;
}

/* Hide loading text for layout3 */
.api-post-modal[data-active-layout="layout3"] .modal-loading-text {
    display: none !important;
}