/* --- 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;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(145deg, var(--larina-btn-main, #8e44ad), var(--larina-btn-dark, #6c3483));
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 10px !important;
    font-weight: 600;
    font-size: 15px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    box-shadow: 0 4px 16px var(--larina-btn-glow, rgba(142, 68, 173, 0.4));
    position: relative;
    overflow: hidden;
}

#larina-open-modal-button::before {
    content: '✨';
    font-size: 16px;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

#larina-open-modal-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(145deg, var(--larina-btn-light, #a569bd), var(--larina-btn-main, #8e44ad));
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 12px;
    z-index: -1;
}

#larina-open-modal-button:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 24px var(--larina-btn-glow, rgba(142, 68, 173, 0.5));
}

#larina-open-modal-button:hover::after {
    opacity: 1;
}

#larina-open-modal-button:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 8px var(--larina-btn-glow, rgba(142, 68, 173, 0.3));
}


/* --- 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: 760px; /* Increased from 680px for bigger modal */
    max-height: 90vh; /* Constrain to viewport height */
    overflow-y: auto; /* Scroll if content exceeds */
    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%;
    max-height: 600px; /* Increased from 500px for bigger images */
    border-radius: 18px;
    overflow: hidden;
    margin-bottom: 24px;
    background: #f5f5f7;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
#larina-result-image {
    display: block;
    width: 100%;
    max-height: 600px; /* Increased from 500px for bigger images */
    height: auto;
    object-fit: contain;
}

.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 Full Height Bottom Sheet) --- */
@media (max-width: 600px) {
    .larina-modal-content {
        width: 100%;
        max-width: none;
        max-height: none; /* Override desktop max-height */
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        top: 0;
        bottom: 0;
        left: 0;
        transform: translate(0, 0);
        border-radius: 0;
        padding: 24px 16px; /* Reduced padding for more space */
        padding-bottom: env(safe-area-inset-bottom, 20px);
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        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);
    }

    /* Allow content to flex properly */
    .larina-state.active {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    /* Make result image take available space - bigger! */
    .larina-result-image-wrapper {
        flex: 1;
        max-height: 55vh; /* Increased from 50vh for bigger images */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #larina-result-image {
        max-height: 100%;
        object-fit: contain;
    }
}


/* --- 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 (With Dynamic Colors) --- */

/* 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, var(--larina-btn-main, #8e44ad), var(--larina-btn-dark, #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 */
#larina-open-modal-button::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50px;
    background: linear-gradient(145deg, var(--larina-btn-light, #a569bd), var(--larina-btn-main, #8e44ad));
    z-index: -1;
    filter: blur(15px);
    opacity: 0.7;
    animation: softPulse 2.5s infinite ease-in-out;
}

/* 3. Icon */
#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);
    box-shadow:
        0 8px 15px var(--larina-btn-glow, rgba(142, 68, 173, 0.4)),
        0 3px 6px rgba(0, 0, 0, 0.15),
        inset 0 1px 1px rgba(255, 255, 255, 0.4);
}

/* Active/Click State */
#larina-open-modal-button:active {
    transform: translateY(1px) scale(0.98);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 2px 4px rgba(0, 0, 0, 0.4);
    transition-duration: 0.05s;
}


/* 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;
    }
}

/* === Error Display Styling === */
.larina-error-area {
    background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
    border: 2px solid #ff4444;
    border-radius: 12px;
    padding: 16px 20px;
    margin: 20px 0;
    color: #d32f2f;
    font-size: 14px;
    line-height: 1.8;
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.15);
    animation: errorSlideIn 0.3s ease-out;
    max-height: 400px;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.larina-error-area strong {
    display: block;
    font-size: 16px;
    margin-bottom: 8px;
    color: #c62828;
}

@keyframes errorSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile-optimized error display */
@media (max-width: 768px) {
    .larina-error-area {
        font-size: 11px;
        padding: 12px 14px;
        max-height: 300px;
        line-height: 1.6;
    }

    .larina-error-area strong {
        font-size: 13px;
        margin-bottom: 6px;
    }
}

/* 🐛 Mobile Debug Console Styles */
.larina-mobile-debug-console {
    background: white;
    border-radius: 12px;
    padding: 16px;
    max-height: 70vh;
    overflow-y: auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 12px;
    line-height: 1.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.larina-mobile-debug-console .debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
}

.larina-mobile-debug-console .debug-header h3 {
    color: #1d1d1f;
    font-weight: 600;
}

.larina-mobile-debug-console .debug-section {
    background: #f8f8f8;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    border-left: 4px solid #007AFF;
}

.larina-mobile-debug-console .debug-section h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: #1d1d1f;
}

.larina-mobile-debug-console .debug-section p {
    margin: 4px 0;
    color: #4a4a4a;
    font-size: 11px;
    word-break: break-word;
}

.larina-mobile-debug-console .success {
    color: #34C759;
    font-weight: 600;
}

.larina-mobile-debug-console .error {
    color: #FF3B30;
    font-weight: 600;
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    .larina-mobile-debug-console {
        font-size: 11px;
        padding: 12px;
        max-height: 60vh;
    }

    .larina-mobile-debug-console .debug-section {
        padding: 10px;
        margin-bottom: 10px;
    }

    .larina-mobile-debug-console .debug-section h4 {
        font-size: 12px;
    }

    .larina-mobile-debug-console .debug-section p {
        font-size: 10px;
    }
}

/* --- Size Options --- */
.larina-size-options {
    margin: 20px 0;
    padding: 16px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
}

.larina-size-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--larina-text-color);
}

.larina-size-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--larina-accent-color);
}

.larina-size-inputs {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.larina-size-field {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.larina-size-field label {
    font-size: 13px;
    font-weight: 500;
    color: #6e6e73;
    min-width: 45px;
}

.larina-size-field input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 14px;
    max-width: 80px;
    text-align: center;
}

.larina-size-field input:focus {
    outline: none;
    border-color: var(--larina-accent-color);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
}

.larina-size-field span {
    font-size: 14px;
    color: #6e6e73;
}

@media (max-width: 600px) {
    .larina-size-inputs {
        flex-direction: column;
        gap: 12px;
    }
}

/* --- Refine Section --- */
.larina-refine-section {
    margin: 20px 0 0 0;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.larina-refine-label {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: var(--larina-text-color);
}

#larina-refine-feedback {
    width: 100%;
    padding: 14px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    margin-bottom: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#larina-refine-feedback:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#larina-refine-feedback::placeholder {
    color: #9ca3af;
}

.larina-refine-btn {
    all: unset;
    box-sizing: border-box;
    display: block;
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.larina-refine-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.larina-refine-btn:active:not(:disabled) {
    transform: translateY(0);
}

.larina-refine-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.larina-refine-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.larina-refine-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: larina-spin 0.8s linear infinite;
}

/* 🔴 Live Debug Widget - Real-time floating progress display */
#larina-live-debug {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.live-debug-toggle {
    background: linear-gradient(135deg, #FF3B30, #FF6B6B);
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(255, 59, 48, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: 600;
    font-size: 14px;
}

.live-debug-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 59, 48, 0.5);
}

.live-debug-toggle .debug-icon {
    font-size: 16px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

.live-debug-content {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: 320px;
    max-height: 400px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.live-debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #FF3B30, #FF6B6B);
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.live-debug-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.live-debug-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.live-debug-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.live-debug-steps {
    max-height: 340px;
    overflow-y: auto;
    padding: 12px;
}

.debug-step {
    background: #f8f8f8;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    border-left: 4px solid #ccc;
    transition: all 0.3s ease;
}

.debug-step.in-progress {
    border-left-color: #FF9500;
    background: #fff9f0;
}

.debug-step.success {
    border-left-color: #34C759;
    background: #f0fff4;
}

.debug-step.error {
    border-left-color: #FF3B30;
    background: #fff5f5;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.debug-step.waiting {
    border-left-color: #8E8E93;
    background: #f5f5f5;
    opacity: 0.7;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.step-icon {
    font-size: 16px;
    min-width: 20px;
}

.debug-step.in-progress .step-icon {
    animation: spin 1.5s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.step-title {
    font-weight: 600;
    font-size: 13px;
    color: #1d1d1f;
}

.step-details {
    margin-top: 6px;
    padding-left: 28px;
}

.step-details p {
    margin: 2px 0;
    font-size: 11px;
    color: #4a4a4a;
    line-height: 1.4;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    #larina-live-debug {
        bottom: 10px;
        right: 10px;
    }

    .live-debug-toggle {
        padding: 10px 16px;
        font-size: 12px;
    }

    .live-debug-content {
        width: calc(100vw - 20px);
        max-width: 320px;
        max-height: 50vh;
    }

    .live-debug-steps {
        max-height: calc(50vh - 60px);
    }

    .step-title {
        font-size: 12px;
    }

    .step-details p {
        font-size: 10px;
    }
}

/* ============================================================================
   GALLERY DRAWER STYLES
   ============================================================================ */

/* --- Gallery Toggle Button --- */
.larina-gallery-toggle {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    background: var(--larina-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.larina-gallery-toggle:hover {
    transform: translateY(-50%) scale(1.08);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.larina-gallery-toggle .gallery-icon {
    font-size: 20px;
    line-height: 1;
}

.larina-gallery-toggle .gallery-count {
    font-size: 11px;
    font-weight: 700;
    color: var(--larina-accent-color);
    background: rgba(0, 113, 227, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* --- Expandable Drawer --- */
.larina-drawer {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%) translateX(100%);
    width: 320px;
    max-height: 80vh;
    background: var(--larina-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px 0 0 24px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-right: none;
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.15);
    z-index: 10002;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.larina-drawer.open {
    transform: translateY(-50%) translateX(0);
}

.larina-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.larina-drawer-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--larina-text-color);
}

.larina-drawer-close {
    all: unset;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    font-size: 20px;
    color: #6e6e73;
    cursor: pointer;
    transition: all 0.2s ease;
}

.larina-drawer-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #1d1d1f;
}

.larina-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* --- Gallery Grid --- */
.larina-gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.larina-gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    background: #f5f5f7;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.larina-gallery-item:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.larina-gallery-item.active {
    border-color: var(--larina-accent-color);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.larina-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Processing state for gallery item */
.larina-gallery-item.processing {
    pointer-events: none;
}

.larina-gallery-item .gallery-item-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
}

.larina-gallery-item.processing .gallery-item-loader {
    display: flex;
}

.gallery-item-loader .circular-progress {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(0, 113, 227, 0.2);
    border-top-color: var(--larina-accent-color);
    border-radius: 50%;
    animation: larina-spin 0.8s linear infinite;
}

/* Delete button on gallery item */
.larina-gallery-item .gallery-item-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.larina-gallery-item:hover .gallery-item-delete {
    opacity: 1;
}

.larina-gallery-item .gallery-item-delete:hover {
    background: rgba(255, 59, 48, 0.9);
}

/* Mode badge on gallery item */
.larina-gallery-item .gallery-item-mode {
    position: absolute;
    bottom: 6px;
    left: 6px;
    padding: 3px 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

/* Product name label on gallery item */
.larina-gallery-item .gallery-item-product {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 32px; /* Make room for delete button */
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    color: #1d1d1f;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* --- Empty Gallery State --- */
.larina-gallery-empty {
    text-align: center;
    padding: 40px 20px;
    color: #6e6e73;
}

.larina-gallery-empty p {
    margin: 0;
    font-size: 14px;
}

/* --- Mobile Drawer (From Bottom) --- */
@media (max-width: 600px) {
    .larina-gallery-toggle {
        top: auto;
        bottom: 80px; /* Moved closer to action buttons for better access */
        right: 16px;
        transform: none;
        width: 50px;
        height: 50px;
    }

    .larina-gallery-toggle:hover {
        transform: scale(1.05);
    }

    .larina-drawer {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 24px 24px 0 0;
        transform: translateY(100%);
    }

    .larina-drawer.open {
        transform: translateY(0);
    }

    .larina-drawer-header {
        padding: 16px 20px;
    }

    .larina-drawer-content {
        padding: 16px;
    }

    .larina-gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
}