/**
 * Modal Component Styles
 *
 * Comprehensive styling for the reusable modal component including:
 * - Dialog and fullscreen modal types
 * - Multiple size variants (small, medium, large)
 * - Smooth animations and transitions
 * - Backdrop overlay with blur effect
 * - Mobile-responsive design
 * - Accessibility features
 * - Dark mode support
 *
 * NOTE: This component uses the centralized color management system from src/color-system/colors.css
 * All colors are referenced using CSS custom properties (variables) for consistency.
 *
 * @author Austin Steil
 * @version 1.0.0
 * @license MIT <https://raw.githubusercontent.com/AustinSteil/generate-files-model/refs/heads/main/LICENSE>
 * @copyright 2025 Austin Steil
 * @created October 18, 2025
 * @updated October 18, 2025
 */

/* ============================================
   BASE MODAL STYLES
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-cubic);
}

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

.modal.modal-hide {
    opacity: 0;
}

/* ============================================
   BACKDROP
   ============================================ */
.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, var(--opacity-50));
    backdrop-filter: blur(2px);
    cursor: pointer;
}

/* ============================================
   MODAL CONTENT CONTAINER
   ============================================ */
.modal-content {
    position: relative;
    background: var(--color-bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1;
    transform: scale(0.9) translateY(-20px);
    transition: transform var(--transition-cubic);
}

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

.modal.modal-hide .modal-content {
    transform: scale(0.9) translateY(-20px);
}

/* ============================================
   SIZE VARIANTS
   ============================================ */
.modal-content.modal-small {
    width: 90%;
    max-width: 400px;
}

.modal-content.modal-medium {
    width: 90%;
    max-width: 500px;
}

.modal-content.modal-large {
    width: 90%;
    max-width: 700px;
}

/* ============================================
   MODAL HEADER
   ============================================ */
.modal-header {
    padding: var(--spacing-xl) var(--spacing-xl) var(--spacing-lg);
    border-bottom: 1px solid var(--color-border-light);
    flex-shrink: 0;
}

.modal-header h3 {
    margin: 0;
    color: var(--color-text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.3;
}

/* ============================================
   MODAL BODY
   ============================================ */
.modal-body {
    padding: var(--spacing-xl);
    flex: 1;
    overflow-y: auto;
    color: var(--color-text-secondary);
    line-height: 1.6;
}

.modal-body p {
    margin-bottom: var(--spacing-lg);
}

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

/* ============================================
   MODAL FOOTER
   ============================================ */
.modal-footer {
    padding: var(--spacing-lg) var(--spacing-xl) var(--spacing-xl);
    border-top: 1px solid var(--color-border-light);
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ============================================
   CLOSE BUTTON
   ============================================ */
.modal-close {
    position: absolute;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    transition: all var(--transition-base);
    z-index: 2;
}

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

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

.close-icon {
    line-height: 1;
}

/* ============================================
   FULLSCREEN MODAL TYPE
   ============================================ */
.modal-fullscreen .modal-content {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
}

.modal-fullscreen .modal-close {
    position: fixed;
    top: var(--spacing-xl);
    right: var(--spacing-xl);
    background: var(--color-bg-primary);
    border: 2px solid var(--color-border-medium);
    box-shadow: var(--shadow-lg);
    z-index: 10001;
}

.modal-fullscreen .modal-close:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-dark);
}

/* ============================================
   FORM ELEMENTS IN MODAL
   ============================================ */
.modal-body .form-group {
    margin-bottom: var(--spacing-lg);
}

.modal-body label {
    display: block;
    margin-bottom: var(--spacing-sm);
    color: var(--color-text-primary);
    font-weight: 500;
}

.modal-body input,
.modal-body textarea,
.modal-body select {
    width: 100%;
    padding: var(--spacing-md);
    border: 1px solid var(--color-border-medium);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: border-color var(--transition-base);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.modal-body input:focus,
.modal-body textarea:focus,
.modal-body select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), var(--opacity-20));
}

.modal-body small {
    display: block;
    margin-top: var(--spacing-sm);
    color: var(--color-text-tertiary);
    font-size: 12px;
}

/* ============================================
   ERROR STATES
   ============================================ */
.modal-body .error {
    background: var(--gradient-error-subtle);
    color: var(--color-error-darker);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-error-border);
    margin-top: var(--spacing-sm);
    font-size: 14px;
}

.modal-body input.invalid,
.modal-body textarea.invalid {
    border-color: var(--color-error);
    box-shadow: 0 0 0 2px rgba(var(--color-error-rgb), var(--opacity-10));
}

/* ============================================
   DARK MODE FORM ELEMENTS
   ============================================ */
.dark-mode .modal-body input,
.dark-mode .modal-body textarea,
.dark-mode .modal-body select {
    background: var(--color-bg-tertiary);
    border-color: var(--color-border-medium);
    color: var(--color-text-primary);
}

.dark-mode .modal-body input:focus,
.dark-mode .modal-body textarea:focus,
.dark-mode .modal-body select:focus {
    border-color: var(--color-primary);
    background: var(--color-bg-primary);
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), var(--opacity-30));
}

.dark-mode .modal-body input:hover,
.dark-mode .modal-body textarea:hover,
.dark-mode .modal-body select:hover {
    border-color: var(--color-border-dark);
    background: var(--color-bg-primary);
}

.dark-mode .modal-body label {
    color: var(--color-text-secondary);
    font-weight: 600;
}

.dark-mode .modal-body small {
    color: var(--color-text-tertiary);
}

.dark-mode .modal-body .error {
    background: var(--gradient-error);
    color: var(--color-text-light);
    border-color: var(--color-error);
}

.dark-mode .modal-body input.invalid,
.dark-mode .modal-body textarea.invalid {
    border-color: var(--color-error);
    background: var(--color-bg-primary);
    box-shadow: 0 0 0 2px rgba(var(--color-error-rgb), var(--opacity-20));
}

/* System preference fallback for form elements */
@media (prefers-color-scheme: dark) {
    html:not(.dark-mode) .modal-body input,
    html:not(.dark-mode) .modal-body textarea,
    html:not(.dark-mode) .modal-body select {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }

    html:not(.dark-mode) .modal-body input:focus,
    html:not(.dark-mode) .modal-body textarea:focus,
    html:not(.dark-mode) .modal-body select:focus {
        border-color: #3b82f6;
        background: #1f2937;
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
    }

    html:not(.dark-mode) .modal-body input:hover,
    html:not(.dark-mode) .modal-body textarea:hover,
    html:not(.dark-mode) .modal-body select:hover {
        border-color: #6b7280;
        background: #1f2937;
    }

    html:not(.dark-mode) .modal-body label {
        color: #d1d5db;
        font-weight: 600;
    }

    html:not(.dark-mode) .modal-body small {
        color: #9ca3af;
    }

    html:not(.dark-mode) .modal-body .error {
        background: linear-gradient(135deg, #7f1d1d 0%, #1f2937 100%);
        color: #f3f4f6;
        border-color: #ef4444;
    }

    html:not(.dark-mode) .modal-body input.invalid,
    html:not(.dark-mode) .modal-body textarea.invalid {
        border-color: #ef4444;
        background: #1f2937;
        box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
    }
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .modal-content {
        margin: var(--spacing-lg);
        max-height: calc(100vh - 2 * var(--spacing-lg));
    }

    .modal-content.modal-small,
    .modal-content.modal-medium,
    .modal-content.modal-large {
        width: calc(100vw - 2 * var(--spacing-lg));
        max-width: none;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: var(--spacing-lg);
        padding-right: var(--spacing-lg);
    }

    .modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-footer .btn {
        width: 100%;
        margin-bottom: var(--spacing-sm);
    }

    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }

    .modal-close {
        top: var(--spacing-md);
        right: var(--spacing-md);
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* ============================================
   ACCESSIBILITY & REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .modal,
    .modal-content {
        transition: opacity var(--transition-base);
    }

    .modal.modal-show .modal-content,
    .modal.modal-hide .modal-content {
        transform: none;
    }
}

/* ============================================
   DARK MODE SUPPORT
   Manual dark mode via .dark-mode class (matches color system pattern)
   Also supports system preference as fallback
   ============================================ */

/* Dark mode when .dark-mode class is applied */
.dark-mode .modal-backdrop {
    background: rgba(0, 0, 0, var(--opacity-70));
}

.dark-mode .modal-content {
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--color-border-light);
}

.dark-mode .modal-header {
    border-bottom-color: var(--color-border-light);
}

.dark-mode .modal-header h3 {
    color: var(--color-text-primary);
}

.dark-mode .modal-body {
    color: var(--color-text-secondary);
}

.dark-mode .modal-footer {
    border-top-color: var(--color-border-light);
}

.dark-mode .modal-close {
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border-medium);
}

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

.dark-mode .modal-close:focus {
    box-shadow: 0 0 0 2px var(--color-primary);
}

/* System preference fallback (when .dark-mode class is not present) */
@media (prefers-color-scheme: dark) {
    html:not(.dark-mode) .modal-backdrop {
        background: rgba(0, 0, 0, var(--opacity-70));
    }

    html:not(.dark-mode) .modal-content {
        background: var(--color-bg-dark);
        box-shadow: var(--shadow-xl);
        border: 1px solid #4b5563;
    }

    html:not(.dark-mode) .modal-header {
        border-bottom-color: #4b5563;
    }

    html:not(.dark-mode) .modal-header h3 {
        color: #f9fafb;
    }

    html:not(.dark-mode) .modal-body {
        color: #d1d5db;
    }

    html:not(.dark-mode) .modal-footer {
        border-top-color: #4b5563;
    }

    html:not(.dark-mode) .modal-close {
        background: #374151;
        color: #d1d5db;
        border: 1px solid #4b5563;
    }

    html:not(.dark-mode) .modal-close:hover {
        background: #111827;
        color: #f9fafb;
        border-color: #6b7280;
    }

    html:not(.dark-mode) .modal-close:focus {
        box-shadow: 0 0 0 2px #3b82f6;
    }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (prefers-contrast: high) {
    .modal-content {
        border: 2px solid var(--color-border-dark);
    }

    .modal-close {
        border: 1px solid var(--color-text-secondary);
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .modal {
        display: none;
    }
}
