/* ========================================
   Modal System Styles
   System Modal & Notification Standardization
   ======================================== */

/**
 * Modal System CSS
 * 
 * Provides styling for the unified modal component system using design system
 * CSS variables for consistent theming and dark mode support.
 * 
 * Requirements: 4.1, 4.2, 4.3, 4.4, 4.5, 7.1-7.9, 11.1-11.7
 */

/* ========================================
   Container & Backdrop
   ======================================== */

#modal-root {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999; /* Very high z-index to cover everything */
}

#modal-root > * {
    pointer-events: auto;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    /* Animation */
    opacity: 0;
    transition: opacity 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-backdrop.modal--show {
    opacity: 1;
}

/* ========================================
   Modal Dialog
   ======================================== */

.modal-dialog {
    position: fixed; /* Changed from relative to fixed for proper positioning */
    top: 50%; /* Center vertically */
    left: 50%; /* Center horizontally */
    transform: translate(-50%, -50%) scale(0.95); /* Center and initial scale */
    background: var(--bg-modal);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    color: var(--text-primary);
    padding: var(--spacing-xl);
    text-align: center; /* Center content like SweetAlert2 */
    z-index: calc(var(--z-modal) + 10); /* Much higher above backdrop */
    pointer-events: auto; /* Ensure clicks work */
    /* Animation */
    opacity: 0;
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1),
                opacity 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-dialog.modal--show {
    transform: translate(-50%, -50%) scale(1); /* Keep centered when showing */
    opacity: 1;
}

/* ========================================
   Modal Title (Below Icon)
   ======================================== */

.modal-title {
    margin: var(--spacing-md) 0 var(--spacing-sm) 0;
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-heading);
    line-height: 1.4;
}

/* ========================================
   Modal Icons (Top Center like SweetAlert2)
   Requirement 4.1, 4.2, 4.3, 4.4, 4.5
   ======================================== */

.modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    margin: 0 auto;
    border-radius: 50%;
    border: 4px solid; /* Border around the circle */
    font-size: 2.5rem; /* Smaller icon that fits well in circle */
    font-weight: 400;
    line-height: 1;
}

.modal-icon-content {
    display: block;
}

/* Type-specific icon colors - matching screenshot */

.modal-icon--success {
    color: #a5dc86;
    border-color: #a5dc86;
    animation: modal-icon-success 0.5s ease-in-out;
}

.modal-icon--error {
    color: #f27474;
    border-color: #f27474;
    animation: modal-icon-error 0.5s ease-in-out;
}

.modal-icon--warning {
    color: #f8bb86;
    border-color: #f8bb86;
    animation: modal-icon-pulse 0.5s ease-in-out;
}

.modal-icon--info {
    color: #3fc3ee;
    border-color: #3fc3ee;
    animation: modal-icon-scale 0.5s ease-in-out;
}

.modal-icon--confirmation {
    color: #87adbd; /* Light blue like SweetAlert2 question */
    border-color: #87adbd;
    animation: modal-icon-question 0.8s ease-in-out;
}

.modal-icon--question {
    color: #87adbd;
    border-color: #87adbd;
    animation: modal-icon-question 0.8s ease-in-out;
}

.modal-icon--alert {
    color: #f8bb86;
    border-color: #f8bb86;
    animation: modal-icon-pulse 0.5s ease-in-out;
}

/* ========================================
   Close Button
   ======================================== */

.modal-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--spacing-xs);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.modal-close:focus {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

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

.modal-body {
    padding: var(--spacing-md) 0;
}

.modal-message {
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0;
    text-align: center;
}

.modal-message p {
    margin: 0 0 var(--spacing-md) 0;
}

.modal-message p:last-child {
    margin-bottom: 0;
}

.modal-message strong,
.modal-message b {
    font-weight: 600;
    color: var(--text-heading);
}

/* ========================================
   Input Validation
   ======================================== */

.modal-validation {
    margin-top: var(--spacing-lg);
}

.modal-input {
    width: 100%;
    padding: 11px 18px; /* Match search input padding */
    border: 2px solid var(--border-default); /* Match search input border */
    border-radius: 25px; /* Match search input rounded style */
    font-size: 14px; /* Match search input font size */
    color: var(--text-primary);
    background: var(--bg-card); /* Match search input background */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* Match search input transition */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); /* Match search input shadow */
    height: 44px; /* Match search input height */
    box-sizing: border-box;
}

.modal-input:hover {
    border-color: var(--accent-primary); /* Match search input hover */
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08); /* Match search input hover shadow */
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent-primary); /* Match search input focus */
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15); /* Match search input focus shadow */
}

.modal-input::placeholder {
    color: var(--text-tertiary); /* Match search input placeholder */
    font-size: 13px; /* Match search input placeholder size */
}

.modal-validation-hint {
    margin: var(--spacing-sm) 0 0 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}


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

.modal-footer {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    padding: var(--spacing-md) 0 0 0;
    margin-top: var(--spacing-lg);
    /* Normal order: Cancel first (left), Confirm second (right) in HTML */
    /* But visually in screenshot: Green button LEFT, Cancel button RIGHT */
}

/* ========================================
   Modal Buttons
   ======================================== */

.modal-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    font-size: 1rem;
    transition: background-color var(--transition-fast),
                transform var(--transition-fast),
                box-shadow var(--transition-fast);
    min-width: 80px;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

.modal-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.modal-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.modal-btn:focus {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.modal-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

.modal-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Button variants */

.modal-btn--confirm {
    background: var(--accent-primary);
    color: var(--text-on-accent);
}

.modal-btn--confirm:hover:not(:disabled) {
    background: var(--accent-primary-hover);
}

.modal-btn--confirm:active:not(:disabled) {
    background: var(--accent-primary-active);
}

.modal-btn--success {
    background: #5cb85c;
    color: white;
}

.modal-btn--success:hover:not(:disabled) {
    background: #4cae4c;
}

.modal-btn--success:active:not(:disabled) {
    background: #449d44;
}

.modal-btn--danger {
    background: var(--accent-danger);
    color: var(--text-on-accent);
}

.modal-btn--danger:hover:not(:disabled) {
    background: var(--accent-danger-hover);
}

.modal-btn--cancel {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}

.modal-btn--cancel:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

/* ========================================
   Modal Type Variants
   ======================================== */

/* No type-specific border colors - SweetAlert2 doesn't use them */

/* ========================================
   Animations
   Requirement 11.1-11.7
   ======================================== */

/* Icon animations - matching SweetAlert2 behavior */
@keyframes modal-icon-scale {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes modal-icon-success {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes modal-icon-error {
    0% {
        transform: scale(0) rotate(-45deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes modal-icon-pulse {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    25% {
        transform: scale(1.1);
        opacity: 1;
    }
    50% {
        transform: scale(0.95);
    }
    75% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes modal-icon-question {
    0% {
        transform: rotateY(-360deg);
        opacity: 0;
    }
    100% {
        transform: rotateY(0);
        opacity: 1;
    }
}

/* Fade in animation */
@keyframes modal-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Scale in animation */
@keyframes modal-scale-in {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Fade out animation */
@keyframes modal-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Scale out animation */
@keyframes modal-scale-out {
    from {
        transform: scale(1);
        opacity: 1;
    }
    to {
        transform: scale(0.95);
        opacity: 0;
    }
}

/* Animation classes */
.modal-backdrop.modal--animating {
    animation: modal-fade-in 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-dialog.modal--animating {
    animation: modal-scale-in 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-backdrop.modal--closing {
    animation: modal-fade-out 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-dialog.modal--closing {
    animation: modal-scale-out 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   Reduced Motion Support
   Requirement 11.7
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .modal-backdrop,
    .modal-dialog,
    .modal-icon {
        transition: none;
        animation: none;
    }
    
    .modal-btn {
        transition: none;
    }
    
    .modal-btn:hover {
        transform: none;
    }
}

/* ========================================
   Body Scroll Lock
   Applied to body when modal is open
   ======================================== */

/* No scroll locking - let page scroll naturally even with modal open */

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 600px) {
    .modal-dialog {
        width: 95%;
        max-width: none;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-md);
    }
    
    .modal-title {
        font-size: 1.1rem;
    }
    
    /* Keep icon size same on mobile - DO NOT SHRINK */
    .modal-icon {
        width: 80px;
        height: 80px;
        font-size: 2.5rem; /* Match desktop size */
    }
    
    .modal-footer {
        flex-direction: column-reverse;
    }
    
    .modal-btn {
        width: 100%;
    }
}

/* ========================================
   Dark Theme Support
   Requirement 7.9
   ======================================== */

/* Dark theme variables are automatically handled by CSS variables
   defined in global.css and dark-theme.css */

/* Additional dark theme specific adjustments if needed */
@media (prefers-color-scheme: dark) {
    /* Adjustments already handled by CSS variables */
    /* Add any additional dark theme specific overrides here if needed */
}
