/**
 * Modals Module - Template gallery, shape selection, and other modal components
 * Features: Professional modal designs, smooth animations, responsive layouts
 */

/* Modal Base Styles */
.modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem;
}

.modal-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.btn-close {
    background: none;
    border: none;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.btn-close:hover {
    opacity: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
}

/* Template Gallery Modal - Beautiful.ai Style */
#templateGalleryModal {
    z-index: 1055 !important;
}

#templateGalleryModal .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
    height: 100vh !important;
}

#templateGalleryModal .modal-content {
    height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
}

/* Ensure modal backdrop appears properly */
.modal-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    z-index: 1050 !important;
}

/* Force modal to appear above backdrop */
#templateGalleryModal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1055 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.template-gallery-view,
.template-detail-view {
    height: 100vh;
    overflow-y: auto;
}

.template-detail-view {
    display: none;
}

.template-detail-view.active {
    display: block;
}

/* Template Gallery Header */
.template-gallery-header {
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    padding: 2rem 3rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.template-gallery-title {
    font-size: 2rem;
    font-weight: 700;
    color: #212529;
    margin: 0;
}

/* Template Categories */
.template-categories {
    padding: 2rem 3rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e9ecef;
    background: white;
    position: sticky;
    top: 88px;
    z-index: 9;
}

.category-tabs {
    display: flex;
    gap: 0;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 4px;
}

.category-tab {
    background: none;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.category-tab:hover {
    color: #495057;
    background: rgba(255, 255, 255, 0.5);
}

.category-tab.active {
    background: white;
    color: #7106ee;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.template-search {
    position: relative;
    width: 300px;
}

.template-search i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    font-size: 0.875rem;
}

.template-search input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.template-search input:focus {
    outline: none;
    border-color: #7106ee;
    box-shadow: 0 0 0 3px rgba(113, 6, 238, 0.1);
}

/* Templates Grid */
.template-gallery-body {
    padding: 2rem 3rem 3rem;
    background: white;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
    margin-top: 1rem;
}

.template-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid #e9ecef;
    position: relative;
}

.template-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    border-color: #7106ee;
}

.template-card-preview {
    position: relative;
    aspect-ratio: 16/10;
    overflow: hidden;
    background: #f8f9fa;
}

.template-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.template-card:hover .template-card-image {
    transform: scale(1.02);
}

.template-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.8) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: flex-end;
    padding: 1.5rem;
}

.template-card:hover .template-card-overlay {
    opacity: 1;
}

.template-card-actions {
    display: flex;
    gap: 0.75rem;
    margin-left: auto;
}

.template-action-btn {
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #212529;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.template-action-btn:hover {
    background: white;
    transform: translateY(-1px);
}

.template-action-btn.primary {
    background: #7106ee;
    color: white;
}

.template-action-btn.primary:hover {
    background: #5a04c7;
}

.template-card-info {
    padding: 1.5rem;
}

.template-card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #212529;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.template-card-description {
    color: #6c757d;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
}

/* Template Detail View */
.template-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2rem 3rem;
    border-bottom: 1px solid #e9ecef;
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.btn-back {
    background: none;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-right: 1rem;
}

.btn-back:hover {
    background: #f8f9fa;
    color: #495057;
}

.template-detail-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: #212529;
    margin: 0;
    flex: 1;
}

.template-detail-body {
    padding: 2rem 3rem;
    background: #f8f9fa;
}

.template-detail-content {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 3rem;
    max-width: 1400px;
    margin: 0 auto;
}

.template-detail-left {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    height: fit-content;
    position: sticky;
    top: 140px;
}

.template-badges {
    margin-bottom: 1.5rem;
}

.template-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #7106ee;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.template-format-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 4px;
}

.format-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.format-btn.active {
    background: white;
    color: #7106ee;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.template-description {
    margin-bottom: 2rem;
}

.template-description p {
    color: #495057;
    line-height: 1.6;
    margin: 0;
}

.template-actions {
    margin-bottom: 2rem;
}

.btn-use-template {
    width: 100%;
    background: #7106ee;
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.btn-use-template:hover {
    background: #5a04c7;
    transform: translateY(-1px);
}

.template-meta {
    margin-bottom: 1.5rem;
}

.slide-count {
    color: #6c757d;
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.count-number {
    color: #7106ee;
    font-weight: 700;
    font-size: 1.25rem;
}

.template-slides-preview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.slide-thumbnail {
    aspect-ratio: 16/10;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    overflow: hidden;
}

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

/* Template Detail Right */
.template-detail-right {
    position: relative;
}

.template-preview-area {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    position: relative;
    min-height: 600px;
}

.template-preview-navigation {
    display: flex;
    justify-content: space-between;
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    padding: 0 1rem;
    z-index: 5;
    pointer-events: none;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #e9ecef;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #495057;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.nav-btn:hover {
    background: white;
    border-color: #7106ee;
    color: #7106ee;
    transform: scale(1.05);
}

.template-preview-main {
    height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.preview-mockup {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 2rem;
}

.mockup-images {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    max-width: 600px;
    width: 100%;
}

.mockup-image {
    background: white;
    border-radius: 8px;
    aspect-ratio: 16/10;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: perspective(1000px) rotateY(-5deg) rotateX(2deg);
    transition: transform 0.3s ease;
}

.mockup-image:nth-child(even) {
    transform: perspective(1000px) rotateY(5deg) rotateX(-2deg);
}

.mockup-image:hover {
    transform: perspective(1000px) rotateY(0deg) rotateX(0deg) scale(1.02);
}

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

.preview-action {
    text-align: center;
    margin-top: 1rem;
}

.scroll-to-preview {
    background: none;
    border: 1px solid #e9ecef;
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.scroll-to-preview:hover {
    border-color: #7106ee;
    color: #7106ee;
}

/* Template Loading States */
.template-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: #6c757d;
}

/* Shape Selection Modal */
.shape-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

.shape-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--background-secondary);
}

.shape-option:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
    transform: translateY(-2px);
}

.shape-preview {
    width: 40px;
    height: 40px;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shape-rectangle {
    background: var(--primary-color);
    border-radius: 4px;
}

.shape-circle {
    background: var(--primary-color);
    border-radius: 50%;
}

.shape-triangle {
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-bottom: 35px solid var(--primary-color);
    background: none;
}

.shape-arrow {
    background: var(--primary-color);
    position: relative;
}

.shape-arrow::after {
    content: '';
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 15px solid var(--primary-color);
}

.shape-star {
    background: var(--primary-color);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.shape-hexagon {
    background: var(--primary-color);
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.shape-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Chart Selection Modal */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.chart-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--background-secondary);
    text-align: center;
}

.chart-option:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
    transform: translateY(-2px);
}

.chart-preview {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    background: var(--primary-light);
    border-radius: 12px;
    color: var(--primary-color);
    font-size: 1.5rem;
}

.chart-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.chart-description {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .template-detail-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .template-detail-left {
        position: static;
    }
    
    .template-categories {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .category-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    
    .template-search {
        width: 100%;
    }
    
    .templates-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 1.5rem;
    }
    
    .mockup-images {
        grid-template-columns: 1fr;
    }
    
    .shape-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    }
    
    .chart-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 576px) {
    .template-gallery-header,
    .template-categories,
    .template-gallery-body,
    .template-detail-header,
    .template-detail-body {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    .templates-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .category-tabs {
        padding: 2px;
    }
    
    .category-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }
}

.chart-label {
  font-size: var(--decka-font-size-base);
  font-weight: var(--decka-font-weight-semibold);
  color: var(--decka-text-primary);
  margin: 0 0 var(--decka-space-4) 0;
}

.chart-description {
  font-size: var(--decka-font-size-sm);
  color: var(--decka-text-muted);
  margin: 0;
  line-height: var(--decka-line-height-normal);
}

/* === RESPONSIVE MODALS === */
@media (max-width: 768px) {
  .modal {
    padding: var(--decka-space-8);
  }
  
  .modal-dialog {
    max-width: 100%;
    margin: 0;
  }
  
  .modal-xl .modal-dialog,
  .modal-lg .modal-dialog {
    max-width: 100%;
  }
  
  .modal-header {
    padding: var(--decka-space-16) var(--decka-space-20);
  }
  
  .modal-body {
    padding: var(--decka-space-20);
  }
  
  .modal-footer {
    padding: var(--decka-space-12) var(--decka-space-20);
  }
  
  .modal-title {
    font-size: var(--decka-font-size-base);
  }
  
  .template-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--decka-space-12);
  }
  
  .shape-grid {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: var(--decka-space-12);
  }
  
  .chart-grid {
    grid-template-columns: 1fr;
    gap: var(--decka-space-12);
  }
}

/* === ACCESSIBILITY === */
.modal:focus {
  outline: none;
}

.modal-content:focus {
  outline: 2px solid var(--decka-primary);
  outline-offset: 2px;
}

.template-item:focus,
.shape-option:focus,
.chart-option:focus {
  outline: 2px solid var(--decka-primary);
  outline-offset: 2px;
}

/* === HIGH CONTRAST MODE === */
@media (prefers-contrast: high) {
  .modal-content {
    border-color: #000000;
  }
  
  .modal-header,
  .modal-footer {
    border-color: #000000;
  }
  
  .template-item,
  .shape-option,
  .chart-option {
    border-color: #000000;
  }
  
  .search-input {
    border-color: #000000;
  }
  
  .view-toggle {
    border-color: #000000;
  }
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  .modal.fade,
  .modal-backdrop,
  .template-item,
  .shape-option,
  .chart-option,
  .shape-preview,
  .chart-preview {
    transition: none;
  }
  
  .template-item:hover,
  .shape-option:hover,
  .chart-option:hover {
    transform: none;
  }
  
  .shape-option:hover .shape-preview,
  .chart-option:hover .chart-preview {
    transform: none;
  }
}

/* === SCROLLBAR STYLING === */
.modal-body::-webkit-scrollbar,
.template-gallery-content::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track,
.template-gallery-content::-webkit-scrollbar-track {
  background: var(--decka-bg-secondary);
}

.modal-body::-webkit-scrollbar-thumb,
.template-gallery-content::-webkit-scrollbar-thumb {
  background: var(--decka-gray-400);
  border-radius: var(--decka-radius-sm);
}

.modal-body::-webkit-scrollbar-thumb:hover,
.template-gallery-content::-webkit-scrollbar-thumb:hover {
  background: var(--decka-gray-500);
}
