/**
 * Responsive Modal Windows
 * Mobile-optimized modal dialogs with proper sizing and scrolling
 */

/* ============================================
   Modal Backdrop
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.active,
.modal.show {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   Modal Container
   ============================================ */

/* Mobile: 95% width */
.modal-container {
    background: var(--white, #ffffff);
    border-radius: 12px;
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal.active .modal-container,
.modal.show .modal-container {
    transform: scale(1);
}

/* Tablet (768px+): Larger modal */
@media (min-width: 768px) {
    .modal-container {
        max-width: 600px;
    }
}

/* Desktop (1024px+): Even larger modal */
@media (min-width: 1024px) {
    .modal-container {
        max-width: 700px;
    }
}

/* ============================================
   Modal Header
   ============================================ */

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900, #111827);
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--gray-500, #6b7280);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--gray-100, #f3f4f6);
    color: var(--gray-700, #374151);
}

.modal-close i {
    font-size: 1.25rem;
}

/* Tablet and up: Larger header */
@media (min-width: 768px) {
    .modal-header {
        padding: 1.5rem;
    }
    
    .modal-title {
        font-size: 1.25rem;
    }
}

/* ============================================
   Modal Body
   ============================================ */

.modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* Tablet and up: More padding */
@media (min-width: 768px) {
    .modal-body {
        padding: 1.5rem;
    }
}

/* ============================================
   Modal Footer
   ============================================ */

/* Mobile: Vertical button stack */
.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    display: flex;
    gap: 0.5rem;
    flex-direction: column;
    flex-shrink: 0;
}

.modal-footer button {
    width: 100%;
    min-height: 44px;
    padding: 0.75rem 1.5rem;
    justify-content: center;
}

/* Tablet and up: Horizontal button layout */
@media (min-width: 768px) {
    .modal-footer {
        padding: 1.5rem;
        flex-direction: row;
        justify-content: flex-end;
    }
    
    .modal-footer button {
        width: auto;
    }
}

/* ============================================
   Modal Forms
   ============================================ */

/* Mobile: Stack form fields vertically */
.modal-body form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-body .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.modal-body .form-group label {
    font-weight: 600;
    color: var(--gray-700, #374151);
    font-size: 0.875rem;
}

.modal-body .form-group input,
.modal-body .form-group select,
.modal-body .form-group textarea {
    width: 100%;
    
    padding: 0.75rem;
    border: 1px solid var(--gray-300, #d1d5db);
    border-radius: 6px;
    font-size: 1rem;
}

.modal-body .form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Tablet and up: Side-by-side for some fields */
@media (min-width: 768px) {
    .modal-body .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    .modal-body .form-group.full-width {
        grid-column: 1 / -1;
    }
}

/* ============================================
   Prevent Background Scroll
   ============================================ */

body.modal-open {
    overflow: hidden;
}

/* ============================================
   Modal Sizes
   ============================================ */

/* Small modal */
.modal-container.modal-sm {
    max-width: 400px;
}

/* Large modal */
.modal-container.modal-lg {
    max-width: 800px;
}

@media (min-width: 1280px) {
    .modal-container.modal-lg {
        max-width: 900px;
    }
}

/* Full-screen modal on mobile */
.modal-container.modal-fullscreen-mobile {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
}

@media (min-width: 768px) {
    .modal-container.modal-fullscreen-mobile {
        width: 95%;
        height: auto;
        max-width: 600px;
        max-height: 90vh;
        border-radius: 12px;
    }
}

/* ============================================
   Modal Animations
   ============================================ */

@keyframes modalSlideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal.active .modal-container.slide-up,
.modal.show .modal-container.slide-up {
    animation: modalSlideUp 0.3s ease;
}

/* ============================================
   Confirmation Modals
   ============================================ */

.modal-container.modal-confirm {
    max-width: 400px;
}

.modal-confirm .modal-body {
    text-align: center;
    padding: 2rem 1rem;
}

.modal-confirm .modal-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.modal-confirm.modal-danger .modal-icon {
    background: var(--red-100, #fee2e2);
    color: var(--red-600, #dc2626);
}

.modal-confirm.modal-warning .modal-icon {
    background: var(--yellow-100, #fef3c7);
    color: var(--yellow-600, #d97706);
}

.modal-confirm.modal-success .modal-icon {
    background: var(--green-100, #dcfce7);
    color: var(--green-600, #16a34a);
}

/* ============================================
   Accessibility
   ============================================ */

/* Focus trap within modal */
.modal[aria-hidden="true"] {
    display: none;
}

.modal[aria-hidden="false"] {
    display: flex;
}

/* Ensure first focusable element gets focus */
.modal.active .modal-container *:focus-visible,
.modal.show .modal-container *:focus-visible {
    outline: 2px solid var(--primary-color, #6366f1);
    outline-offset: 2px;
}

/* ============================================
   Loading State
   ============================================ */

.modal-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    z-index: 10;
}

.modal-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200, #e5e7eb);
    border-top-color: var(--primary-color, #6366f1);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
