/**
 * CRM Modal System - Reusable modals with guaranteed scroll, modern styling
 * BEM-style classes to avoid conflicts with legacy CSS
 */

/* Wrapper - full viewport overlay */
.crm-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1055;
    display: none;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
    -webkit-overflow-scrolling: touch;
}

.crm-modal.show {
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

/* Backdrop: Bootstrap 5 handles .modal-backdrop */

/* Dialog - constrained, scrollable container */
.crm-modal__dialog {
    position: relative;
    width: 100%;
    max-width: min(90vw, 800px);
    max-height: 90vh;
    margin: auto;
    pointer-events: auto;
}

/* Content box */
.crm-modal__content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}

/* Header - sticky, dark style for forms */
.crm-modal__header.model-headline {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: #374151;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px 12px 0 0;
}

.crm-modal__header.crm-modal__header--minimal {
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.crm-modal__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    text-transform: capitalize;
}

.crm-modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    margin-left: auto;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.crm-modal__header.model-headline .crm-modal__close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.crm-modal__close svg {
    width: 1.25rem;
    height: 1.25rem;
}

.crm-modal__close-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: #6b7280;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.crm-modal__close-link:hover {
    color: #111827;
    background: #f3f4f6;
}

/* Body - THE SCROLLABLE REGION (critical for Add Company form) */
.crm-modal__body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(90vh - 60px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 1.5rem 2.5rem 2rem;
}

/* Content slot - where .load() injects HTML */
.crm-modal__body > div {
    width: 100%;
}

/* Mobile responsive */
@media (max-width: 640px) {
    .crm-modal.show {
        padding: 0.5rem;
        align-items: flex-start;
    }

    .crm-modal__dialog {
        max-width: 95vw;
        max-height: 95vh;
    }

    .crm-modal__content {
        max-height: 95vh;
    }

    .crm-modal__body {
        max-height: calc(95vh - 56px);
        padding: 1rem 1.25rem 1.5rem;
    }
}
