/* --- Global Variables for Theming --- */
:root {
    --larina-bg-color: rgba(255, 255, 255, 0.65);
    --larina-border-radius: 24px;
    --larina-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
    --larina-accent-color: #0071e3;
    --larina-text-color: #1d1d1f;
}

/* --- Small Loader for Image Processing --- */
.larina-loader-small {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--larina-accent-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: larina-spin 0.8s linear infinite;
    margin: 20px auto 15px;
}

@keyframes larina-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Preview Loading State --- */
.larina-preview-loading {
    text-align: center;
    padding: 30px 20px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 12px;
    animation: pulseLoading 1.5s ease-in-out infinite;
}

@keyframes pulseLoading {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* --- Preview Container with Badge --- */
.larina-preview-container {
    animation: previewFadeIn 0.3s ease-out;
}

@keyframes previewFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* --- Conversion Progress UI --- */
.larina-conversion-progress {
    text-align: center;
    padding: 20px;
    animation: fadeIn 0.3s ease-in;
}

.conversion-status {
    font-size: 14px;
    font-weight: 500;
    color: #1d1d1f;
    margin: 10px 0;
    min-height: 40px;
}

.conversion-status small {
    font-size: 12px;
    color: #666;
    display: block;
    margin-top: 5px;
}

.conversion-progress-bar {
    width: 100%;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
    margin: 15px 0 10px;
}

.conversion-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--larina-accent-color), #00d4ff);
    border-radius: 3px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}

.conversion-percent {
    font-size: 13px;
    font-weight: 600;
    color: var(--larina-accent-color);
    font-family: 'Courier New', monospace;
    margin: 5px 0 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@supports (backdrop-filter: blur(20px)) {
    :root {
        --larina-bg-color: rgba(255, 255, 255, 0.65);
    }
}

/* --- Preview Button Style --- */
#larina-open-modal-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: #f5f5f7;
    color: var(--larina-text-color);
    border: none;
    padding: 10px 18px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    margin-left: 10px !important; /* To add space from add-to-cart */
}
#larina-open-modal-button:hover {
    transform: scale(1.05);
    background-color: #e8e8ea;
}
/* Add an icon (You can use a real SVG here) */
#larina-open-modal-button::before {
    content: '✨'; /* Example: Sparkle Icon */
    font-size: 16px;
}


/* --- Modal General Style --- */
.larina-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    -webkit-animation: fadeIn 0.3s;
    animation: fadeIn 0.3s;
    overflow: hidden;
}

.larina-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 520px;
    background: var(--larina-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--larina-border-radius);
    box-shadow: var(--larina-shadow);
    padding: 32px;
    box-sizing: border-box;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.larina-close-button {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 30px;
    height: 30px;
    background: rgba(0,0,0,0.1);
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    line-height: 30px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.larina-close-button:hover {
    background: rgba(0,0,0,0.2);
}

/* --- Upload State --- */
.larina-state { display: none; }
.larina-state.active { display: block; }

#larina-upload-state h2 {
    font-size: 24px;
    color: var(--larina-text-color);
    margin: 0 0 24px 0;
}

.larina-upload-area {
    background: rgba(0,0,0,0.05);
    border: 2px dashed rgba(0,0,0,0.1);
    border-radius: 18px;
    padding: 40px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}
.larina-upload-area.dragover {
    transform: scale(1.03);
    border-color: var(--larina-accent-color);
    background: rgba(0, 113, 227, 0.1);
}
.larina-upload-area p {
    margin: 10px 0 0 0;
    color: #6e6e73;
}
.larina-upload-area .upload-icon {
    font-size: 48px;
    color: var(--larina-accent-color);
}
#larina-image-upload { display: none; }

/* --- Loading State --- */
.larina-loader-container {
    padding: 40px 0;
}
.larina-loader {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(0,0,0,0.1);
    border-top-color: var(--larina-accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}
.larina-status-text {
    font-size: 18px;
    color: var(--larina-text-color);
}

/* --- Progress Bar Styles --- */
.larina-progress-bar-container {
    width: 100%;
    height: 10px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    margin: 15px 0;
    overflow: hidden;
}
.larina-progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--larina-accent-color);
    border-radius: 5px;
    transition: width 0.3s ease;
}


/* --- Result State --- */
.larina-result-image-wrapper {
    width: 100%;
    border-radius: 18px;
    overflow: hidden;
    margin-bottom: 24px;
    background: #f5f5f7;
    position: relative; /* For before/after slider */
}
#larina-result-image {
    display: block;
    width: 100%;
    height: auto;
}

.larina-action-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
}
.larina-action-bar button {
    background: rgba(0,0,0,0.08);
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}
.larina-action-bar button:hover {
    background: rgba(0,0,0,0.12);
}
.larina-action-bar button.primary {
    background-color: var(--larina-accent-color);
    color: #fff;
}
.larina-action-bar button.primary:hover {
    background-color: #0077ed;
}

/* --- Mobile (iOS Style Bottom Sheet) --- */
@media (max-width: 600px) {
    .larina-modal-content {
        width: 100%;
        max-width: none;
        top: auto;
        bottom: 0;
        left: 0;
        transform: translate(0, 0);
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    }
    .larina-modal.closing .larina-modal-content {
        animation: slideDown 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    }
}


/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes slideUp { 
    from { transform: translateY(100%); } 
    to { transform: translateY(0); } 
}
@keyframes slideDown { 
    from { transform: translateY(0); } 
    to { transform: translateY(100%); } 
}

/* --- The "Magic" Preview Button Design V2 (Refined & Optimized) --- */

/* 1. Base Structure and 3D Effect */
#larina-open-modal-button {
    all: unset;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    margin-left: 12px !important;
    border-radius: 50px;
    cursor: pointer;
    position: relative;
    font-family: 'Vazirmatn', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    background: linear-gradient(145deg, #8e44ad, #6c3483);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-top-color: rgba(255, 255, 255, 0.3);
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.2),
        0 1px 3px rgba(0, 0, 0, 0.1),
        inset 0 1px 1px rgba(255, 255, 255, 0.4);
    
    /* Optimized transition for smoother performance */
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Prevents flickering/jittering on some browsers */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* 2. The Pulsing Glow Effect (Unchanged) */
#larina-open-modal-button::after {
    content: '';
    position: absolute;
    top: -4px; 
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50px;
    background: linear-gradient(145deg, #a569bd, #8e44ad);
    z-index: -1;
    filter: blur(15px);
    opacity: 0.7;
    animation: softPulse 2.5s infinite ease-in-out;
}

/* 3. Icon (Animation Removed) */
#larina-open-modal-button::before {
    content: '✨';
    font-size: 20px;
    display: inline-block;
}

/* 4. Refined Interaction States */

/* Hover State */
#larina-open-modal-button:hover {
    transform: translateY(-3px) scale(1.02); /* A bit more lift and scale for a premium feel */
    box-shadow: 
        0 8px 15px rgba(0, 0, 0, 0.25), /* Stronger shadow when lifted */
        0 3px 6px rgba(0, 0, 0, 0.15),
        inset 0 1px 1px rgba(255, 255, 255, 0.4);
}

/* Active/Click State - The core of the improvement */
#larina-open-modal-button:active {
    transform: translateY(1px) scale(0.98); /* Pushes down and slightly shrinks */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2), /* Reduced outer shadow */
        inset 0 2px 4px rgba(0, 0, 0, 0.4); /* Stronger inner shadow for pressed effect */
    transition-duration: 0.05s; /* Make the press action feel instant */
}


/* 5. Mobile Optimization (Unchanged) */
@media (max-width: 768px) {
    #larina-open-modal-button {
        width: 100%;
        padding: 16px 24px;
        margin-top: 15px;
        margin-left: 0 !important;
        font-size: 18px;
    }
}

/* 6. Keyframes (iconSpin removed) */
@keyframes softPulse {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0.7;
    }
}

/* --- Mode Switcher Styles --- */
.larina-mode-switcher {
    display: flex;
    justify-content: center;
    background-color: rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 24px;
}
.larina-mode-switcher .mode-btn {
    border: none;
    background-color: transparent;
    padding: 8px 16px;
    border-radius: 9px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
.larina-mode-switcher .mode-btn.active {
    background-color: #fff;
    color: #000;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* --- Mockup List Styles --- */
#larina-mockup-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 5px;
}
.larina-mockup-item {
    border: 2px solid transparent;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.larina-mockup-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.larina-mockup-item.selected {
    border-color: var(--larina-accent-color);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.3);
}

/* Local Mockup Badge */
.mockup-local-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: linear-gradient(135deg, #34C759, #30D158);
    color: white;
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.3);
    letter-spacing: 0.3px;
    z-index: 1;
}

.larina-mockup-item {
    position: relative;
}
.larina-loader-small {
    width: 30px;
    height: 30px;
    margin: 20px auto;
    border-width: 3px;
    border-top-color: var(--larina-accent-color);
}

/* --- Generate Button --- */
.larina-generate-btn {
    all: unset;
    box-sizing: border-box;
    display: block;
    width: 100%;
    margin-top: 24px;
    padding: 14px;
    border-radius: 12px;
    background-color: var(--larina-accent-color);
    color: white;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.larina-generate-btn:hover {
    background-color: #0077ed;
}
.larina-generate-btn:disabled {
    background-color: #a0a0a0;
    cursor: not-allowed;
}

/* --- Download Converted File Button - Premium macOS Style --- */
.larina-download-converted {
    margin-top: 16px;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.larina-download-converted.visible {
    opacity: 1;
    transform: translateY(0);
}

.larina-download-btn {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 18px;
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.08) 0%, rgba(52, 199, 89, 0.02) 100%);
    border: 1.5px solid rgba(52, 199, 89, 0.25);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.larina-download-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(52, 199, 89, 0.1), transparent);
    transition: left 0.5s;
}

.larina-download-btn:hover::before {
    left: 100%;
}

.larina-download-btn:hover {
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.15) 0%, rgba(52, 199, 89, 0.05) 100%);
    border-color: rgba(52, 199, 89, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(52, 199, 89, 0.2);
}

.larina-download-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.15);
}

.larina-download-btn.success {
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.2) 0%, rgba(52, 199, 89, 0.1) 100%);
    border-color: rgba(52, 199, 89, 0.5);
    animation: successPulse 0.5s ease-out;
}

@keyframes successPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.03);
    }
    100% {
        transform: scale(1);
    }
}

.larina-download-btn .download-icon {
    font-size: 24px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.larina-download-btn:hover .download-icon {
    transform: translateY(-2px);
}

.larina-download-btn.success .download-icon {
    animation: bounceIcon 0.6s ease-out;
}

@keyframes bounceIcon {
    0%, 100% {
        transform: translateY(0);
    }
    25% {
        transform: translateY(-8px);
    }
    50% {
        transform: translateY(-4px);
    }
    75% {
        transform: translateY(-6px);
    }
}

.larina-download-btn .download-text {
    flex: 1;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.larina-download-btn .download-text strong {
    font-size: 15px;
    font-weight: 600;
    color: #1d1d1f;
    letter-spacing: -0.2px;
}

.larina-download-btn .download-text small {
    font-size: 12px;
    font-weight: 500;
    color: #34C759;
    letter-spacing: -0.1px;
}

/* Mobile Optimization */
@media (max-width: 600px) {
    .larina-download-btn {
        padding: 16px;
    }

    .larina-download-btn .download-icon {
        font-size: 22px;
    }

    .larina-download-btn .download-text strong {
        font-size: 14px;
    }

    .larina-download-btn .download-text small {
        font-size: 11px;
    }
}

/* ========== DEBUG PANEL STYLES ========== */
.larina-debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 500px;
    max-width: calc(100vw - 40px);
    max-height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 999999;
    overflow: hidden;
    animation: debugSlideIn 0.3s ease-out;
    border: 2px solid #0071e3;
}

@keyframes debugSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.larina-debug-header {
    background: linear-gradient(135deg, #0071e3 0%, #0056b3 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.larina-debug-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.larina-debug-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.larina-debug-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.larina-debug-content {
    padding: 20px;
    max-height: 520px;
    overflow-y: auto;
    background: #f8f9fa;
}

.larina-debug-section {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid #e0e0e0;
}

.larina-debug-section:last-child {
    margin-bottom: 0;
}

.larina-debug-section h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #0071e3;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.larina-debug-item {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    align-items: start;
}

.larina-debug-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.larina-debug-label {
    font-weight: 600;
    color: #333;
    font-size: 13px;
}

.larina-debug-value {
    color: #555;
    font-size: 13px;
    word-break: break-all;
    font-family: 'Courier New', monospace;
}

.larina-debug-json {
    background: #282c34;
    color: #61dafb;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
}

.larina-debug-value#debug-status-code {
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 4px;
    display: inline-block;
}

.larina-debug-value#debug-status-code.success {
    background: #d4edda;
    color: #155724;
}

.larina-debug-value#debug-status-code.error {
    background: #f8d7da;
    color: #721c24;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .larina-debug-panel {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 10px;
        max-height: 500px;
    }

    .larina-debug-item {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .larina-debug-label {
        font-size: 12px;
    }

    .larina-debug-value {
        font-size: 12px;
    }
}