
/* ============================================
   MODAL
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--blurBackground);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.modal-overlay-ventana {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    pointer-events: none;
    z-index: calc(1000 + var(--z-modal, 0));
}

.modal-overlay.modal-overlay-ventana .modal {
    pointer-events: auto;
}

.modal {
    color: var(--text);
    border-radius: 20px;
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    /* El difuminado y el velo vienen de .glass (css/style.css): el modal es
       una superficie congelada como cualquier otra. Antes los declaraba aquí
       a 5px, mientras su propio pie iba a 14px, y el escalón se notaba al
       pasar del cuerpo al pie de la misma ventana. */
    --blur-frosted: 10px;
    animation: slideUp 0.3s ease;
    /* El glow y el borde solo aparecen al hacer hover: el modal en reposo no
       necesita encenderse. El glow (inset) va en el ::after de abajo. */
    --glow: none;
    outline: 1px solid transparent;
    outline-offset: -1px;

    /* Posición dinámica del drag */
    transform: translate(var(--modal-x, 0), var(--modal-y, 0));
    transition: transform 0.05s linear, outline-color 0.3s ease, border-color 0.3s ease;
}

@media (hover: hover) {
    .modal:hover {
        --glow: inset 0 0 20px var(--shadow);
        outline-color: var(--lightBorder);
        border-color: var(--border);
    }
}

/* El glow va en un pseudo-elemento porque `backdrop-filter` recorta el
   box-shadow propio del modal (ver .glass en style.css). El `transform` de
   arriba ya hace de .modal un bloque contenedor para el ::after. */
.modal::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    box-shadow: var(--glow, none);
    pointer-events: none;
}

/* Variantes */
.modal-info      { max-width: 420px; }
.modal-confirm   { max-width: 460px; }
.modal-form      { max-width: 560px; }
.modal-wide      { max-width: 760px; }
.modal-narrow    { max-width: 400px; }

/* Ventana grande: para paneles densos (configuración). Ocupa casi todo el
   alto disponible y deja el cuerpo como único contenedor de scroll. */
.modal-xl {
    max-width: 1120px;
    height: 88vh;
    max-height: 88vh;
}

/* --------------------------------------------
   HEADER
   -------------------------------------------- */

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px 24px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}

/* El modal solo es arrastrable en modo persistente (ventanas); en modo
   estándar el modal queda fijo y centrado. */
.modal-overlay-ventana .modal-header {
    cursor: grab;
}

.modal-overlay-ventana .modal.dragging,
.modal-overlay-ventana .modal.dragging .modal-header {
    cursor: grabbing;
}

.modal-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    flex: 1;
    min-width: 0;
    pointer-events: none;
}

.modal-header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.modal-header-acciones {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* Botones de acción junto al botón de cerrar */
.modal-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.modal-header-btn:hover {
    background: var(--lightHover);
    box-shadow: inset 0 0 10px var(--shadow);
}

.modal-header-btn.danger:hover {
    background: var(--negative);
    border-color: var(--negative);
    color: #fff;
}

.modal-close:hover {
    background: var(--lightHover);
    transform: rotate(90deg);
    box-shadow: inset 0 0 10px var(--shadow);
}

/* --------------------------------------------
   BODY / FOOTER
   -------------------------------------------- */

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    color: var(--text);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* El pie es una barra limpia: sin superficie propia. La separación con el
   cuerpo la da el borde superior, no un fondo más tupido que "cortara" la
   ventana en dos tramos de distinto frost. */
.modal-footer {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px 24px 20px 24px;
    border-top: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    flex-shrink: 0;
}

/* Acciones secundarias del footer (archivar / eliminar).
   El footer centra sus botones, así que este bloque se separa con
   margin-right:auto para quedarse pegado al extremo izquierdo, lejos
   del botón de Guardar. */
.modal-footer-acciones {
    display: flex;
    gap: 8px;
    margin-right: auto;
}

@media (max-width: 520px) {
    .modal-footer-acciones {
        margin-right: 0;
        width: 100%;
        justify-content: flex-start;
    }
}

/* Botones del modal */
.modal-btn {
    padding: 10px 24px;
    border-radius: 50px;
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
}

.modal-btn-primary {
    background: var(--border);
    color: var(--textAlt);
}

.modal-btn-primary:hover {
    transform: scale(1.02);
    box-shadow: inset 0 0 20px var(--shadow);
    color: var(--textSecondary);
}

.modal-btn-secondary {
    background: var(--surface);
    color: var(--text);
}

.modal-btn-secondary:hover {
    background: var(--lightHover);
}

.modal-btn-danger {
    background: var(--surface);
    color: var(--negative);
    border: 1px solid var(--negative);
}

.modal-btn-danger:hover {
    background: var(--negative);
    color: var(--onyx);
    box-shadow: inset 0 0 14px var(--shadow);
}

/* ============================================
   FORMULARIO DENTRO DEL MODAL
   ============================================ */

.form-movimiento {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--textSecondary);
}

.form-group .form-input {
    /* Sin esto los inputs no llenan la celda de la rejilla: un input es
       inline-block y se ajusta a su atributo `size`, así que en un formulario
       de dos columnas cada campo quedaba con un ancho distinto según su
       contenido en vez de ocupar media pantalla. */
    width: 100%;
    box-sizing: border-box;
    padding: 10px 14px;
    border-radius: 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.form-group .form-input:hover {
    border-color: var(--text);
    background-color: var(--lightHover);
}

.form-group .form-input::placeholder {
    color: var(--textSecondary);
    opacity: 0.5;
}

/* Buscador que filtra las opciones de un <select> (datos de cuenta/tarjeta).
   Va encima del select y es más compacto, a modo de caja de filtro. */
.form-group .form-buscador {
    border-radius: 40px;
    font-size: 13px;
    padding: 6px 14px 6px 34px;
    margin-bottom: 2px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 14px;
}

/* Campo informativo no editable (p. ej. el nombre del activo, que se deriva
   del símbolo): se muestra atenuado y con cursor por defecto. */
.form-group .form-input-bloqueado {
    background: var(--backgroundAlt);
    color: var(--textSecondary);
    border-style: dashed;
    cursor: default;
}

.form-group .form-input-bloqueado:hover {
    border-color: var(--border);
    background-color: var(--backgroundAlt);
}

.form-group .form-textarea {
    border-radius: 16px;
    resize: vertical;
    min-height: 76px;
    line-height: 1.5;
}

.form-group .form-static {
    padding: 10px 14px;
    border-radius: 18px;
    background: var(--surface);
    color: var(--textSecondary);
    font-size: 14px;
}

.form-group .form-hint {
    font-size: 12px;
    color: var(--textSecondary);
    opacity: 0.7;
}

/* Símbolo de divisa junto al label Monto */
.simbolo-divisa {
    color: inherit;
}

#campo-cuenta {
    width: 100%;
}

.campo-fecha {
    position: relative;
}

.campo-fecha input[type="date"] {
    width: 100%;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    padding-right: 46px;
}

/* Oculta el icono nativo del navegador para que quede el botón personalizado */
.campo-fecha input[type="date"]::-webkit-calendar-picker-indicator,
.campo-fecha input[type="date"]::-webkit-inner-spin-button {
    display: none;
    -webkit-appearance: none;
}

.btn-calendario {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--textSecondary);
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.3s ease, background 0.3s ease;
    z-index: 1;
}

.btn-calendario:hover {
    color: var(--text);
    background: var(--lightHover);
}

/* Modal procesando confirmación: se difumina SOLO el cuerpo del modal y se
   muestra el escinco girando en su centro. El overlay no difumina ni tapa la
   pantalla (la interfaz sigue visible y navegable con scroll), pero SÍ captura
   los clics para que no se pueda interactuar con los botones de detrás mien-
   tras la acción se procesa. El propio modal queda sin interacción (botones
   desactivados + pointer-events none). */
.modal-overlay.modal-procesando {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    pointer-events: auto;
}

.modal-overlay.modal-procesando .modal {
    position: relative;
    pointer-events: none;
    filter: none;
    opacity: 1;
    z-index: calc(1000 + var(--z-modal, 0));
}

.modal-overlay.modal-procesando .modal-body {
    filter: blur(3px);
    opacity: 0.85;
    pointer-events: none;
}

.modal-procesando-logo {
    position: absolute;
    top: 48%;
    left: 50%;
    display: flex;
    width: 72px;
    height: 72px;
    align-items: center;
    justify-content: center;
    color: var(--textSecondary);
    pointer-events: none;
    z-index: 5;
    transform: translate(-50%, -50%);
}

.modal-procesando-logo svg {
    width: 48px;
    height: 48px;
    color: var(--textSecondary);
    animation: loading 5s infinite;
}

/* Select personalizado */
.form-group select.form-input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23F3F3F3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 42px;
    cursor: pointer;
}

[data-theme="light"] .form-group select.form-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23141414' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* ============================================
   ANIMACIONES
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(var(--modal-x, 0), calc(var(--modal-y, 0) + 20px)) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translate(var(--modal-x, 0), var(--modal-y, 0)) scale(1);
    }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translate(var(--modal-x, 0), var(--modal-y, 0)) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(var(--modal-x, 0), calc(var(--modal-y, 0) + 20px)) scale(0.98);
    }
}

.modal-overlay.cerrando {
    animation: fadeOut 0.2s ease forwards;
    pointer-events: none;
}

.modal-overlay.cerrando .modal {
    animation: slideDown 0.3s ease forwards;
}

/* ============================================
   MODAL - MENSAJES
   ============================================ */

.modal-message {
    text-align: center;
}

.modal-message-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.modal-message-title {
    color: var(--text);
    font-weight: 500;
    margin-bottom: 8px;
}

.modal-message-title-danger {
    color: var(--negative);
    font-weight: 600;
    font-size: 16px;
}

.modal-message-desc {
    color: var(--textSecondary);
    font-size: 13px;
}

.modal-message-error {
    color: var(--negative);
    font-weight: 500;
    margin-top: 12px;
}

.modal-message-warning {
    color: var(--negative);
    font-size: 12px;
    margin-top: 12px;
}

.modal-list {
    text-align: left;
    max-width: 280px;
    margin: 16px auto 0;
    color: var(--textSecondary);
    font-size: 13px;
    line-height: 1.8;
}

.text-danger {
    color: var(--negative);
}

/* ============================================
   MODAL - LOADING
   ============================================ */

.modal-loading {
    text-align: center;
    padding: 20px 0;
}

.modal-loading-text {
    color: var(--textSecondary);
    margin-top: 16px;
}

.loading-logo {
    display: inline-flex;
    margin: 0 auto;
    color: var(--text);
}

.loading-logo svg.spin {
    animation: loading 5s infinite;
}

/* ============================================
   MODAL - PREVISUALIZACIÓN
   ============================================ */

.modal-preview {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preview-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.preview-label {
    color: var(--textSecondary);
}

.preview-value {
    color: var(--text);
    font-weight: 500;
}

.preview-content {
    margin-top: 8px;
}

.preview-content-title {
    color: var(--textSecondary);
    font-size: 12px;
    margin-bottom: 8px;
}

.preview-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.preview-item span {
    color: var(--textSecondary);
}

.preview-number {
    font-family: var(--font-secondary);
}

.modal-warning {
    background: var(--lightHover);
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    color: var(--textSecondary);
    font-size: 12px;
}

.modal-resultado {
    text-align: left;
    max-width: 280px;
    margin: 0 auto;
}

/* ============================================
   MODAL - INPUT CONFIRMACIÓN
   ============================================ */

.modal-input-confirm {
    margin-top: 16px;
    text-align: center;
    text-transform: uppercase;
}

.form-group .form-input.input-error,
.form-group .form-input.input-error:focus {
    border-color: var(--negative);
}

/* ============================================
   PANEL SECTIONS
   ============================================ */

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.panel-section[data-hidden="true"] {
    display: none;
}

/* ============================================
   TEXTOS DE CONFIGURACIÓN
   ============================================ */

.config-descripcion {
    color: var(--textSecondary);
    font-size: 13px;
    margin-bottom: 4px;
}

.config-status {
    font-size: 12px;
    color: var(--textSecondary);
    margin-top: 4px;
}

.config-status.success {
    color: var(--positive);
}

.config-status.error {
    color: var(--negative);
}