/**
 * Custom Modal System CSS
 * 
 * Modern SaaS-style modals to replace native alert(), confirm(), and prompt()
 */

/* Modal Container */
.custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    padding: var(--spacing-lg);
}

.custom-modal .modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.custom-modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
    max-width: 420px;
    width: 100%;
    z-index: 2001;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.custom-modal-content.modal-content-large {
    max-width: 640px;
}

/* Community create & edit post modals: same width, full content on screen, footer fixed */
.custom-modal:has(#communityCreatePostForm) .custom-modal-content,
.custom-modal:has(#communityEditPostForm) .custom-modal-content {
    max-width: min(90vw, 800px);
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.custom-modal:has(#communityCreatePostForm) .modal-body-custom,
.custom-modal:has(#communityEditPostForm) .modal-body-custom {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.custom-modal:has(#communityCreatePostForm) .modal-body-custom::-webkit-scrollbar,
.custom-modal:has(#communityEditPostForm) .modal-body-custom::-webkit-scrollbar {
    width: 6px;
}

.custom-modal:has(#communityCreatePostForm) .modal-body-custom::-webkit-scrollbar-thumb,
.custom-modal:has(#communityEditPostForm) .modal-body-custom::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Modal Header */
.custom-modal .modal-header {
    padding: 24px 24px 16px;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 12px;
}

.custom-modal .modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.3;
    flex: 1;
}

.custom-modal .modal-close-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
}
.custom-modal .modal-close-btn:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}
.custom-modal .modal-close-btn::before,
.custom-modal .modal-close-btn::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
}
.custom-modal .modal-close-btn::before { transform: rotate(45deg); }
.custom-modal .modal-close-btn::after { transform: rotate(-45deg); }
.custom-modal .modal-header { position: relative; }
.custom-modal .modal-close-btn { position: relative; }

/* Modal footer for form actions (keeps Save/Cancel visible without scrolling) */
.custom-modal .modal-footer-actions {
    flex-shrink: 0;
    padding: 16px 24px 24px;
    justify-content: flex-end;
    gap: 12px;
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: var(--bg-primary);
}
.custom-modal .modal-footer-actions .form-actions {
    margin-top: 0;
}

/* Modal Icon */
.modal-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-icon svg {
    width: 24px;
    height: 24px;
}

.modal-icon-info {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
}

.modal-icon-success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.modal-icon-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.modal-icon-error,
.modal-icon-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Error alert: red title and message (e.g. Payment Cancelled) */
.custom-modal-content.alert-type-error .modal-header h2,
.custom-modal-content.alert-type-error .modal-body p {
    color: #dc2626;
}

/* Modal Body */
.custom-modal .modal-body {
    padding: 0 24px 24px;
}

.custom-modal .modal-body p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
    font-weight: 400;
}

/* Form Input in Prompt */
.custom-modal .form-group {
    margin-top: 1rem;
}

.custom-modal .form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.15s ease;
    box-sizing: border-box;
}

.custom-modal .form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.custom-modal .form-input.error {
    border-color: #ef4444;
}

.custom-modal .error-message {
    color: #ef4444;
    font-size: 13px;
    margin-top: 0.5rem;
}

/* Modal Actions */
.custom-modal .modal-actions {
    display: flex;
    gap: 12px;
    padding: 20px 24px 24px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
    justify-content: flex-end;
}

.custom-modal .btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-size: 14px;
    min-width: 100px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.custom-modal .btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.custom-modal .btn-primary:hover {
    background: var(--primary-dark);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.custom-modal .btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.custom-modal .btn-secondary {
    background: white;
    color: var(--text-primary);
    border: 1.5px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.custom-modal .btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.custom-modal .btn-secondary:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.custom-modal .btn-destructive {
    background: #dc2626;
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.custom-modal .btn-destructive:hover {
    background: #b91c1c;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.custom-modal .btn-destructive:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* Responsive */
@media (max-width: 480px) {
    .custom-modal {
        padding: var(--spacing-md);
    }

    .custom-modal-content {
        max-width: 100%;
    }

    .custom-modal .modal-header {
        padding: 20px 20px 12px;
    }

    .custom-modal .modal-body {
        padding: 0 20px 20px;
    }

    .custom-modal .modal-actions {
        padding: 16px 20px 20px;
        flex-direction: column-reverse;
    }

    .custom-modal .btn {
        width: 100%;
        min-width: auto;
    }
}

/* Photo crop modal (profile-setup, mentor-profile-setup) */
.photo-resize-modal .photo-resize-content {
    max-width: min(90vw, 440px);
}
.photo-resize-modal .photo-resize-body {
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}
.photo-crop-hint {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.photo-crop-viewport {
    width: 380px;
    height: 380px;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: var(--bg-secondary, #f1f5f9);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.photo-crop-viewport:active {
    cursor: grabbing;
}
.photo-crop-image-wrap {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    will-change: transform;
}
.photo-crop-image-wrap .photo-crop-img {
    display: block;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    vertical-align: top;
    pointer-events: none;
}
.photo-crop-overlay {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}
/* Free crop: overlay strips (top, left, right, bottom) – updated by JS; allow drag image when clicking dimmed area */
.photo-crop-free-overlay-top,
.photo-crop-free-overlay-left,
.photo-crop-free-overlay-right,
.photo-crop-free-overlay-bottom {
    position: absolute;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}
.photo-crop-free-overlay-top { top: 0; width: 100%; }
.photo-crop-free-overlay-left { width: 0; }
.photo-crop-free-overlay-right { width: 0; }
.photo-crop-free-overlay-bottom { width: 100%; }
/* Draggable crop box */
.photo-crop-free-box {
    position: absolute;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-sizing: border-box;
    cursor: move;
    pointer-events: auto;
    z-index: 3;
}
.photo-crop-resize-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    right: -2px;
    bottom: -2px;
    background: #fff;
    border: 2px solid var(--primary-color);
    border-radius: 2px;
    cursor: nwse-resize;
}
.photo-crop-resize-se { cursor: nwse-resize; }
.photo-resize-modal .photo-resize-controls {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}
.photo-resize-modal .photo-resize-label {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}
.photo-resize-modal .photo-resize-slider {
    width: 100%;
    height: 8px;
    accent-color: var(--primary-color);
}
@media (max-width: 480px) {
    .photo-crop-viewport {
        width: 100%;
        max-width: 380px;
        height: auto;
        aspect-ratio: 1;
    }
}
