/**
 * Sistema de modales admin — coherente con admin-design-system.
 * Cargar después de bootstrap.min.css.
 */

/* -------------------------------------------------------------------------- */
/* 1. Overlay / backdrop                                                      */
/* -------------------------------------------------------------------------- */
.modal-backdrop {
    background: rgba(15, 25, 50, 0.45) !important;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.modal-backdrop.fade {
    opacity: 0;
}

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

[class*="modal-overlay"],
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
    box-sizing: border-box;
    background: rgba(15, 25, 50, 0.45) !important;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Custom full-screen overlay (Transacciones, Pagos, Facturación, Usuarios) */
.modal-custom {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
    background: rgba(15, 25, 50, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: none;
    overflow: auto;
}

.modal-custom.show,
.modal-custom[style*="display: flex"],
.modal-custom[style*="display:flex"] {
    display: flex !important;
}

/* Transacciones: opacity toggle */
.modal-custom[style*="opacity: 1"] {
    pointer-events: auto;
}

.modal-custom:not(.show):not([style*="display: flex"]):not([style*="display:flex"]) {
    pointer-events: none;
}

/* CrearPagos */
.crearpagos-modal {
    background-color: rgba(15, 25, 50, 0.45) !important;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* -------------------------------------------------------------------------- */
/* Animaciones backdrop + contenedor                                          */
/* -------------------------------------------------------------------------- */
@keyframes adminModalBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes adminModalIn {
    from {
        opacity: 0;
        transform: translateY(-12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-backdrop.show {
    animation: adminModalBackdropIn 0.15s ease-out forwards;
}

/* -------------------------------------------------------------------------- */
/* 2. Contenedor (Bootstrap .modal-dialog + custom)                           */
/* -------------------------------------------------------------------------- */
.modal-container,
.modal-dialog-custom {
    position: relative;
    width: 100%;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
    background: #ffffff;
    border-radius: 14px;
    border: 0.5px solid #e2e8f0;
    box-shadow:
        0 8px 32px rgba(15, 30, 60, 0.12),
        0 2px 8px rgba(15, 30, 60, 0.06);
    animation: adminModalIn 0.18s ease-out;
}

.modal .modal-dialog {
    position: relative;
    width: 100%;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
    animation: adminModalIn 0.18s ease-out;
}

/* Pagos/Facturas: el “card” estaba en .modal-content-custom; el dialog solo ancho */
.modal-custom > .modal-dialog-custom {
    background: #ffffff;
    border: 0.5px solid #e2e8f0;
    border-radius: 14px;
    box-shadow:
        0 8px 32px rgba(15, 30, 60, 0.12),
        0 2px 8px rgba(15, 30, 60, 0.06);
    overflow: hidden;
    animation: adminModalIn 0.18s ease-out;
    padding: 1.25rem 1.5rem;
    width: 90%;
    max-width: 560px;
    margin: 0 auto;
    flex-shrink: 0;
}

.modal-dialog-custom--sm {
    max-width: 500px !important;
}

.modal-dialog-custom--lg {
    max-width: 700px !important;
}

.modal-dialog-custom--xl {
    max-width: 900px !important;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
}

.modal-dialog-custom--flex {
    display: flex !important;
    flex-direction: column;
    max-height: min(90vh, 720px);
    padding: 1.25rem 1.5rem !important;
}

.modal-dialog-custom--flex .modal-body-scroll,
.modal-dialog-custom--flex .crearpagos-modal-body-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding-right: 4px;
}

.modal-dialog-custom--flex .modal-footer-fixed,
.modal-dialog-custom--flex .crearpagos-modal-footer-fixed {
    flex-shrink: 0;
    border-top: 1px solid #e5e7eb;
    padding-top: 12px;
    margin-top: 8px;
    background: #fff;
}

.modal-dialog.modal-sm,
.modal-sm.modal-dialog {
    max-width: 380px;
}

.modal-dialog.modal-lg,
.modal-lg.modal-dialog {
    max-width: 720px;
}

/* Planillas / exportación: ancho mayor (paso 2 del wizard) */
.modal-dialog-custom.modal-dialog-custom-wide,
.modal-custom .modal-dialog-custom.modal-dialog-custom-wide,
.facturas-page .modal-custom > .modal-dialog-custom.modal-dialog-custom-wide {
    max-width: min(900px, 96vw);
}

/* Páginas que ya usaban diálogos anchos (formularios / tablas en modal) */
.facturas-page .modal-custom > .modal-dialog-custom {
    max-width: min(720px, 95vw);
}

.pagos-page .modal-custom > .modal-dialog-custom {
    max-width: min(640px, 95vw);
}

/* Bootstrap: evitar doble animación con fade; diálogo sin pointer-events (Bootstrap) */
.modal.fade .modal-dialog {
    transition: opacity 0.18s ease-out, transform 0.18s ease-out;
    transform: translateY(-8px) scale(0.99);
    pointer-events: none;
}

.modal.show .modal-dialog {
    transform: none;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .modal.fade .modal-dialog,
    .modal-dialog-custom,
    .modal-container,
    .modal-backdrop.show {
        animation: none !important;
        transition: none !important;
    }
}

/* Centrado vertical Bootstrap */
.modal-dialog-centered {
    display: flex;
    align-items: center;
    min-height: calc(100% - 1rem);
}

.modal-dialog-centered::before {
    display: none;
}

.modal .modal-dialog .modal-content {
    pointer-events: auto;
}

/* -------------------------------------------------------------------------- */
/* Contenido: caja blanca interior (custom stack)                             */
/* -------------------------------------------------------------------------- */
.modal-content-custom {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    background: #ffffff;
    border-radius: 14px;
    border: 0.5px solid #e2e8f0;
    box-shadow:
        0 8px 32px rgba(15, 30, 60, 0.12),
        0 2px 8px rgba(15, 30, 60, 0.06);
    overflow: hidden;
}

.modal-custom > .modal-dialog-custom > .modal-content-custom {
    box-shadow: none;
    border: none;
    border-radius: 14px;
    overflow: hidden;
}

/* Bootstrap .modal-content */
.modal .modal-content {
    border-radius: 14px;
    border: 0.5px solid #e2e8f0;
    box-shadow:
        0 8px 32px rgba(15, 30, 60, 0.12),
        0 2px 8px rgba(15, 30, 60, 0.06);
    overflow: hidden;
}

/* -------------------------------------------------------------------------- */
/* 3. Header                                                                  */
/* -------------------------------------------------------------------------- */
.modal-header,
.modal-header-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 14px;
    border-bottom: 0.5px solid #e8ecf2;
    background: #f8fafc;
    flex-shrink: 0;
}

.modal-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.modal-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-icon.blue { background: #dbeafe; color: #1e6dbf; }
.modal-icon.green { background: #d1fae5; color: #065f46; }
.modal-icon.red { background: #fee2e2; color: #c03030; }
.modal-icon.amber { background: #fef3c7; color: #92400e; }

.modal-title,
.modal-header-custom .modal-title-custom,
.modal-header h3,
.modal-header h5 {
    font-size: 15px;
    font-weight: 500;
    color: #1a2e4a;
    margin: 0;
    line-height: 1.3;
}

.modal-subtitle {
    font-size: 12px;
    color: #8fa8c0;
    margin-top: 1px;
    margin-bottom: 0;
}

.modal-close,
.close-button-custom {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid #d0dce8;
    background: white;
    color: #6a8aaa;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.modal-close:hover,
.close-button-custom:hover {
    background: #fff0f0;
    border-color: #f5c0c0;
    color: #c03030;
}

.modal-header .btn-close {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid #d0dce8;
    background: white;
    opacity: 1;
    padding: 0;
    margin: 0;
    background-image: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-header .btn-close::before {
    content: "\00d7";
    font-size: 18px;
    line-height: 1;
    color: #6a8aaa;
}

.modal-header .btn-close:hover {
    background: #fff0f0;
    border-color: #f5c0c0;
    opacity: 1;
}

.modal-header .btn-close:hover::before {
    color: #c03030;
}

/* -------------------------------------------------------------------------- */
/* 4. Body                                                                    */
/* -------------------------------------------------------------------------- */
.modal-body,
.modal-body-custom {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 65vh;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.modal-field label,
.modal-body .form-label {
    font-size: 11px;
    font-weight: 500;
    color: #7a8fa6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0;
}

.modal-field input,
.modal-field select,
.modal-field textarea,
.modal-body .modal-field .form-control,
.modal-body .form-control {
    background: #f5f7fa;
    border: 0.5px solid #d8e2ec;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    color: #2c4260;
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    width: 100%;
    box-sizing: border-box;
}

.modal-field input:focus,
.modal-field select:focus,
.modal-field textarea:focus,
.modal-body .form-control:focus {
    border-color: #5b9bd5;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.12);
}

.modal-field input.error,
.modal-field select.error,
.modal-field textarea.error {
    border-color: #f5c0c0;
    background: #fff8f8;
}

.modal-field .error-msg {
    font-size: 11px;
    color: #c03030;
    margin-top: 2px;
}

.modal-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.modal-divider {
    border: none;
    border-top: 0.5px solid #e8ecf2;
    margin: 4px 0;
}

.modal-section-title {
    font-size: 10px;
    font-weight: 500;
    color: #9aacbf;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 2px;
}

/* -------------------------------------------------------------------------- */
/* 5. Footer                                                                  */
/* -------------------------------------------------------------------------- */
.modal-footer,
.modal-footer-custom {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px 16px;
    border-top: 0.5px solid #e8ecf2;
    background: #f8fafc;
    flex-shrink: 0;
}

.modal-footer > * {
    margin: 0;
}

/* -------------------------------------------------------------------------- */
/* 6. Confirmación destructiva                                                */
/* -------------------------------------------------------------------------- */
.modal-warning-card {
    background: #fff8f0;
    border: 0.5px solid #f5d080;
    border-left: 3px solid #e8a800;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    color: #8a6010;
}

/* -------------------------------------------------------------------------- */
/* 7. Éxito / feedback                                                        */
/* -------------------------------------------------------------------------- */
.modal-success-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #d1fae5;
    color: #065f46;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin: 0 auto 12px;
}

.modal-body--centered {
    text-align: center;
    align-items: center;
}

/* -------------------------------------------------------------------------- */
/* Modal configuración emisor (Facturación)                                   */
/* -------------------------------------------------------------------------- */
.facturas-page .modal-content#contenido-editar-emisor,
#contenido-editar-emisor.modal-content {
    max-width: min(720px, 95vw);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
    padding: 0;
}

.emisor-modal-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 90vh;
}

.emisor-modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding: 18px 20px;
}

.emisor-modal-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px 16px;
    border-top: 0.5px solid #e8ecf2;
    background: #f8fafc;
}

.emisor-modal-shell .modal-header {
    flex-shrink: 0;
}

/* -------------------------------------------------------------------------- */
/* Vanilla modals (Cuotas / Facturación page / standalone)                    */
/* -------------------------------------------------------------------------- */
.cuotas-page .modal,
.facturas-page .modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background: rgba(15, 25, 50, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: none;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    box-sizing: border-box;
}

.cuotas-page .modal[style*="display: block"],
.cuotas-page .modal[style*="display:flex"],
.cuotas-page .modal[style*="display: flex"],
.facturas-page .modal[style*="display: block"],
.facturas-page .modal[style*="display:flex"],
.facturas-page .modal[style*="display: flex"] {
    display: flex !important;
}

.cuotas-page .modal-content,
.facturas-page .modal-content {
    background: #ffffff;
    padding: 0;
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    border: 0.5px solid #e2e8f0;
    box-shadow:
        0 8px 32px rgba(15, 30, 60, 0.12),
        0 2px 8px rgba(15, 30, 60, 0.06);
    animation: adminModalIn 0.18s ease-out;
}

.cuotas-page .modal-content .modal-header,
.facturas-page .modal-content .modal-header {
    margin-bottom: 0;
}

.cuotas-page .modal .modal-body,
.facturas-page .modal .modal-body {
    max-height: 65vh;
}

.cuotas-page .modal-content.cuotas-modal-wide {
    max-width: min(720px, 95vw);
}

.cuotas-page .modal-body > form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    min-height: 0;
}

.cuotas-page .modal-body form .modal-footer {
    margin-top: auto;
}

.cuotas-page .modal-footer.cuotas-modal-facturar-footer {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.cuotas-page .close-modal,
.facturas-page .close-modal {
    position: static;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid #d0dce8;
    background: white;
    color: #6a8aaa;
    font-size: 16px;
    padding: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.cuotas-page .close-modal:hover,
.facturas-page .close-modal:hover {
    background: #fff0f0;
    border-color: #f5c0c0;
    color: #c03030;
}

/* Usuarios / fragmentos legacy: span.close */
.facturas-page .modal-content .close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid #d0dce8;
    background: white;
    color: #6a8aaa;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    z-index: 2;
}

.facturas-page .modal-content .close:hover {
    background: #fff0f0;
    border-color: #f5c0c0;
    color: #c03030;
}

.facturas-page .modal-header .close {
    position: static;
}

.facturas-page .modal-content {
    position: relative;
}

.facturas-page .modal-edicion-entidad .modal-content,
.facturas-page #modal-agregar-alumno .modal-content,
.facturas-page #modal-agregar-padre .modal-content {
    padding-top: 44px;
}

.modal-edicion-entidad .modal-content {
    max-width: 720px;
}

.facturas-page .modal-edicion-entidad .modal-edicion-body {
    padding: 18px 20px;
    max-height: 65vh;
    overflow-y: auto;
}

.facturas-page #contenido-agregar-alumno,
.facturas-page #contenido-agregar-padre {
    padding: 18px 20px;
    max-height: 65vh;
    overflow-y: auto;
}

/* Clic fuera para cerrar (patrón legacy en facturas) */
.facturas-page .modal::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
}

/* -------------------------------------------------------------------------- */
/* CrearPagos: leftovers (info boxes; shell vive en .modal-custom)            */
/* -------------------------------------------------------------------------- */
.crearpagos-modal-info {
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    background-color: #f8f9fa;
    border-radius: 6px;
    font-size: 0.9rem;
}

.crearpagos-form-label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: #374151;
}

#modalCrearFactura.modal-custom .modal-content,
#modalCrearFactura .modal-dialog-custom--xl {
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

/* -------------------------------------------------------------------------- */
/* CrearTransacción: overlay + tarjeta                                        */
/* -------------------------------------------------------------------------- */
.modal-overlay .modal-content {
    background: #ffffff;
    border-radius: 14px;
    border: 0.5px solid #e2e8f0;
    box-shadow:
        0 8px 32px rgba(15, 30, 60, 0.12),
        0 2px 8px rgba(15, 30, 60, 0.06);
    padding: 18px 20px;
    max-width: 28rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: adminModalIn 0.18s ease-out;
}

.close-modal-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid #d0dce8;
    background: white;
    color: #6a8aaa;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.close-modal-btn:hover {
    background: #fff0f0;
    border-color: #f5c0c0;
    color: #c03030;
}

/* -------------------------------------------------------------------------- */
/* Bootstrap: restaurar display en modales nativos                            */
/* -------------------------------------------------------------------------- */
.modal.fade {
    display: none;
}

.modal.fade.show {
    display: block;
}

/* -------------------------------------------------------------------------- */
/* Confirmación global (mostrarConfirmacion)                                  */
/* -------------------------------------------------------------------------- */
.admin-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 4500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
    background: rgba(15, 25, 50, 0.5);
    backdrop-filter: blur(2px);
}

.admin-confirm-overlay .admin-confirm-dialog {
    max-width: min(440px, 95vw);
    width: 100%;
    margin: 0;
}

/* -------------------------------------------------------------------------- */
/* Drawer lateral (beneficiarios, etc.)                                       */
/* -------------------------------------------------------------------------- */
.admin-drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 3200;
    display: none;
    background: rgba(15, 25, 50, 0.45);
    backdrop-filter: blur(2px);
}

.admin-drawer-overlay.show,
.admin-drawer-overlay[style*="display: flex"],
.admin-drawer-overlay[style*="display:flex"] {
    display: flex !important;
    justify-content: flex-end;
}

.admin-drawer {
    background: #fff;
    height: 100%;
    max-height: 100vh;
    width: min(520px, 100vw);
    box-shadow: -8px 0 28px rgba(15, 23, 36, 0.18);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.admin-drawer--wide {
    width: min(920px, 100vw);
}

.admin-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--admin-border, #e4ebf3);
    flex-shrink: 0;
}

.admin-drawer__title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--admin-text-primary, #1a2e4a);
}

.admin-drawer__body {
    flex: 1 1 auto;
    overflow: auto;
    padding: 16px 20px;
    min-height: 0;
}

.admin-drawer__footer {
    flex-shrink: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--admin-border, #e4ebf3);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    background: #fff;
}

.admin-drawer .close-modal {
    position: static;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid #d0dce8;
    background: white;
    color: #6a8aaa;
    font-size: 16px;
    padding: 0;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.admin-drawer .close-modal:hover {
    background: #fff0f0;
    border-color: #f5c0c0;
    color: #c03030;
}

/* Cobrar cuota: scroll + footer fijo (alias; preferir --flex en markup) */
.modal-dialog-custom--flex .crearpagos-modal-body-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

