/**
 * AI Wedding Invitation Designer - Modal Styles
 * Responsive modal popup for the editor
 */

/* ============================================================================
   Modal Overlay
   ============================================================================ */

.aiwid-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.75) !important;
    z-index: 99999999 !important;
    display: none !important;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.aiwid-modal-overlay.aiwid-active {
    display: flex !important;
}

/* ============================================================================
   Modal Container
   ============================================================================ */

.aiwid-modal {
    background: #fff !important;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiwid-modal-appear 0.3s ease-out;
    position: relative !important;
    z-index: 100000000 !important;
}

@keyframes aiwid-modal-appear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ============================================================================
   Modal Header
   ============================================================================ */

.aiwid-modal-header {
    padding: 20px 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #5568d3;
    flex-shrink: 0;
}

.aiwid-modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #fff;
}

.aiwid-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 28px;
    line-height: 1;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.aiwid-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.aiwid-modal-close:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ============================================================================
   Modal Content
   ============================================================================ */

.aiwid-modal-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for modal content */
.aiwid-modal-content::-webkit-scrollbar {
    width: 10px;
}

.aiwid-modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.aiwid-modal-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

.aiwid-modal-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ============================================================================
   Edit Button (Product Page)
   ============================================================================ */

.aiwid-open-editor {
    display: inline-block;
    width: 100%;
    padding: 14px 24px;
    margin-bottom: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.aiwid-open-editor:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.aiwid-open-editor:active {
    transform: translateY(0);
}

.aiwid-open-editor:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* ============================================================================
   Modal-Specific Editor Adjustments
   ============================================================================ */

/* When editor is in modal, adjust app-header */
.aiwid-modal-content .app-header {
    display: none !important;
    /* Hide duplicate header since modal has its own */
}

/* Adjust editor padding in modal */
.aiwid-modal-content .app {
    width: 100% !important;
    min-height: 500px;
    display: flex !important;
    flex-direction: column !important;
}

/* ============================================================================
   RESPONSIVE: Desktop (Default)
   ============================================================================ */

@media (min-width: 769px) {
    .aiwid-modal {
        width: 90%;
        max-width: 1200px;
        max-height: 90vh;
    }

    /* Editor layout - row on desktop */
    .aiwid-modal-content .app-content {
        display: flex;
        flex-direction: row;
        min-height: 600px;
    }

    .aiwid-modal-content .sidebar-left {
        width: 220px;
        min-width: 220px;
    }

    .aiwid-modal-content .sidebar-right {
        width: 220px;
        min-width: 220px;
    }

    .aiwid-modal-content .main-area {
        flex: 1;
    }
}

/* ============================================================================
   RESPONSIVE: Mobile (≤768px)
   ============================================================================ */

@media (max-width: 768px) {

    /* Full screen modal on mobile */
    .aiwid-modal {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .aiwid-modal-overlay {
        padding: 0;
    }

    /* Smaller header on mobile */
    .aiwid-modal-header {
        padding: 15px 20px;
    }

    .aiwid-modal-header h2 {
        font-size: 18px;
    }

    .aiwid-modal-close {
        width: 32px;
        height: 32px;
        font-size: 24px;
    }

    /* Stacked layout on mobile */
    .aiwid-modal-content .app-content {
        display: flex;
        flex-direction: column;
        min-height: auto;
    }

    /* Full width sidebars on mobile */
    .aiwid-modal-content .sidebar-left,
    .aiwid-modal-content .sidebar-right {
        width: 100%;
        border: none;
        border-bottom: 1px solid #e0e0e0;
        padding: 12px;
    }

    .aiwid-modal-content .sidebar-right {
        border-top: 1px solid #e0e0e0;
        border-bottom: none;
    }

    /* Adjust main area padding */
    .aiwid-modal-content .main-area {
        padding: 15px;
    }

    /* Smaller canvas on mobile */
    .aiwid-modal-content .canvas-container {
        max-width: 100%;
    }

    /* Smaller buttons on mobile */
    .aiwid-modal-content .toolbar-buttons button {
        padding: 10px 14px;
        font-size: 13px;
    }

    /* Edit button on mobile */
    .aiwid-open-editor {
        padding: 12px 20px;
        font-size: 15px;
    }
}

/* ============================================================================
   RESPONSIVE: Small Mobile (≤480px)
   ============================================================================ */

@media (max-width: 480px) {
    .aiwid-modal-header {
        padding: 12px 15px;
    }

    .aiwid-modal-header h2 {
        font-size: 16px;
    }

    .aiwid-modal-content .sidebar h3 {
        font-size: 14px;
        margin-bottom: 10px;
    }

    .aiwid-modal-content .main-area {
        padding: 10px;
    }

    .aiwid-modal-content .canvas-container {
        padding: 5px;
    }
}

/* ============================================================================
   Accessibility
   ============================================================================ */

/* Focus visible for keyboard navigation */
.aiwid-modal-close:focus-visible,
.aiwid-open-editor:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .aiwid-modal {
        animation: none;
    }

    .aiwid-modal-close:hover {
        transform: none;
    }

    .aiwid-open-editor:hover {
        transform: none;
    }
}

/* ============================================================================
   Body Scroll Lock (applied via JS)
   ============================================================================ */

body.aiwid-modal-open {
    overflow: hidden !important;
    padding-right: var(--scrollbar-width, 0);
    height: 100vh !important;
}