/**
 * Aaima Page Templates Styles
 * 
 * @package Aaima
 * @since 1.1.0
 */

/* ==========================================================================
   Template Buttons in Header
   ========================================================================== */

.aaima-template-buttons {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

.aaima-save-template-btn,
.aaima-load-template-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.aaima-save-template-btn {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: #fff;
    border: none;
}

.aaima-save-template-btn:hover {
    background: linear-gradient(135deg, #047857 0%, #065f46 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

.aaima-load-template-btn {
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
}

.aaima-load-template-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.aaima-save-template-btn svg,
.aaima-load-template-btn svg {
    width: 16px;
    height: 16px;
}

/* ==========================================================================
   Modal Base Styles
   ========================================================================== */

.aaima-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.aaima-modal.active {
    opacity: 1;
    visibility: visible;
}

.aaima-modal-overlay {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.aaima-modal-content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(20px);
    transition: transform 0.3s ease;
}

.aaima-modal.active .aaima-modal-content {
    transform: scale(1) translateY(0);
}

/* Save Template Modal */
.aaima-save-template-modal {
    width: 480px;
    max-width: 95vw;
}

/* Load Template Modal */
.aaima-load-template-modal {
    width: 900px;
    max-width: 95vw;
    max-height: 85vh;
}

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

.aaima-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
}

.aaima-modal-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.aaima-modal-header h3 svg {
    color: #6366f1;
}

.aaima-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 24px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.aaima-modal-close:hover {
    background: #f3f4f6;
    color: #111827;
}

/* ==========================================================================
   Modal Body
   ========================================================================== */

.aaima-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    transition: all 0.2s;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.template-info-box {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    font-size: 13px;
    color: #0369a1;
}

.template-info-box svg {
    flex-shrink: 0;
    color: #0ea5e9;
}

/* ==========================================================================
   Modal Footer
   ========================================================================== */

.aaima-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.aaima-modal-footer .button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.aaima-modal-footer .button-secondary {
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
}

.aaima-modal-footer .button-secondary:hover {
    background: #f3f4f6;
}

.aaima-modal-footer .button-primary {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #fff;
    border: none;
}

.aaima-modal-footer .button-primary:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* ==========================================================================
   Template Toolbar
   ========================================================================== */

.template-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.template-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.template-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.restore-presets-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 500;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    color: #92400e;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.restore-presets-btn:hover {
    background: #fde68a;
    border-color: #fbbf24;
}

.restore-presets-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.template-filter-btn {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.template-filter-btn:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.template-filter-btn.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

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

.template-search-wrap svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
}

.template-search-wrap input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    font-size: 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.2s;
}

.template-search-wrap input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* ==========================================================================
   Templates Grid
   ========================================================================== */

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
}

.templates-loading {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #6b7280;
}

.templates-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #6b7280;
}

/* ==========================================================================
   Template Card
   ========================================================================== */

.template-item {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.template-item:hover {
    border-color: #c7d2fe;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.1);
}

.template-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 16px 16px 12px;
}

.template-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.template-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
}

.template-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 4px;
}

.template-badge.preset {
    background: #dbeafe;
    color: #1d4ed8;
}

.template-actions {
    display: flex;
    gap: 4px;
}

.template-action-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s;
}

.template-action-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.template-delete-btn:hover {
    background: #fef2f2;
    color: #dc2626;
}

.template-body {
    padding: 0 16px 16px;
}

.template-description {
    margin: 0 0 12px;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 39px;
}

.template-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.template-category {
    display: inline-block;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    background: #f3f4f6;
    color: #4b5563;
    border-radius: 4px;
}

.template-sections {
    font-size: 12px;
    color: #9ca3af;
}

.template-colors {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.template-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.template-copy-shortcode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 12px;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.template-copy-shortcode:hover {
    background: #fff;
    border-color: #d1d5db;
    color: #374151;
}

.template-load-btn {
    padding: 8px 16px !important;
    font-size: 13px !important;
}

/* ==========================================================================
   Loading & Notifications
   ========================================================================== */

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

.loading-spinner-sm {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast Notifications */
.aaima-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    background: #1f2937;
    color: #fff;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100001;
}

.aaima-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.aaima-toast-success {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.aaima-toast-error {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

/* Shortcode Notice */
.aaima-shortcode-notice {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: #1f2937;
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 100001;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.aaima-shortcode-notice .notice-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aaima-shortcode-notice code {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
}

.aaima-shortcode-notice .copy-shortcode-btn {
    padding: 6px 14px;
    background: #6366f1;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.aaima-shortcode-notice .copy-shortcode-btn:hover {
    background: #4f46e5;
}

.aaima-shortcode-notice .notice-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.aaima-shortcode-notice .notice-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ==========================================================================
   Responsive Styles
   ========================================================================== */

@media (max-width: 768px) {
    .aaima-template-buttons {
        width: 100%;
        justify-content: flex-start;
        margin-top: 10px;
    }
    
    .template-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .template-search-wrap {
        width: 100%;
    }
    
    .templates-grid {
        grid-template-columns: 1fr;
    }
    
    .aaima-shortcode-notice {
        left: 16px;
        right: 16px;
        transform: none;
        flex-direction: column;
    }
    
    .aaima-shortcode-notice .notice-content {
        flex-wrap: wrap;
    }
}

/* ==========================================================================
   Section Editor Header Updates
   ========================================================================== */

.section-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.section-editor-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-editor-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Template Error (for shortcode) */
.aaima-template-error {
    padding: 20px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    text-align: center;
}

/* Template Content Wrapper (for shortcode) */
.aaima-template-content {
    /* Wrapper for shortcode rendered content */
}
