/* =========================================================
   JURISCHILE IA v27.1
   Hotfix móvil + archivos
   ========================================================= */

/* La grilla del usuario debe tener texto primero y avatar después. */
.j27-message.user{
    display:grid !important;
    grid-template-columns:minmax(0,1fr) 36px !important;
    width:min(760px,92%) !important;
    max-width:100% !important;
    margin-left:auto !important;
}

.j27-message.user .j27-message-body{
    grid-column:1 !important;
    grid-row:1 !important;
    min-width:0 !important;
    width:100% !important;
    max-width:100% !important;
    overflow:hidden !important;
}

.j27-message.user .j27-message-avatar{
    grid-column:2 !important;
    grid-row:1 !important;
    order:initial !important;
}

/* Nunca permitir una palabra por línea. */
.j27-message-text{
    word-break:normal !important;
    overflow-wrap:anywhere !important;
    white-space:normal !important;
    min-width:0 !important;
}

/* Archivos dentro del mensaje. */
.j27-message-files{
    min-width:0 !important;
    max-width:100% !important;
}

.j27-message-files span{
    display:block !important;
    width:100% !important;
    max-width:100% !important;
    min-width:0 !important;
    white-space:nowrap !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
}

/* Archivos elegidos en el compositor. */
.j27-file-preview{
    width:100% !important;
    max-width:100% !important;
    overflow-x:auto !important;
    overflow-y:hidden !important;
}

.j27-file-pill{
    min-width:190px !important;
    max-width:245px !important;
}

.j27-file-pill strong{
    display:block !important;
    min-width:0 !important;
    max-width:100% !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
    white-space:nowrap !important;
}

/* El compositor no puede sobresalir del viewport. */
.j27-composer-wrap,
.j27-composer,
.j27-composer textarea{
    box-sizing:border-box !important;
    max-width:100% !important;
}

.j27-composer textarea{
    font-family:Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Arial,sans-serif !important;
}

/* Mejor lectura de errores. */
.j27-error-message .j27-message-body{
    min-width:0 !important;
    max-width:100% !important;
}

.j27-error-message .j27-message-text{
    word-break:break-word !important;
}

/* Fuentes */
.j27-source-card{
    min-width:0 !important;
    overflow:hidden !important;
}

.j27-source-head strong,
.j27-source-card small,
.j27-source-card em,
.j27-source-card p{
    overflow-wrap:anywhere !important;
}

/* Mobile */
@media(max-width:600px){
    .j27-chat-inner{
        width:calc(100% - 18px) !important;
    }

    .j27-message{
        grid-template-columns:30px minmax(0,1fr) !important;
        gap:8px !important;
        max-width:100% !important;
    }

    .j27-message.user{
        grid-template-columns:minmax(0,1fr) 30px !important;
        width:96% !important;
        gap:8px !important;
    }

    .j27-message.user .j27-message-body{
        grid-column:1 !important;
        width:100% !important;
        padding:11px 12px !important;
    }

    .j27-message.user .j27-message-avatar{
        grid-column:2 !important;
        width:30px !important;
        height:30px !important;
    }

    .j27-message-text{
        font-size:.94rem !important;
        line-height:1.58 !important;
    }

    .j27-composer-wrap{
        padding:7px 8px 8px !important;
    }

    .j27-composer{
        width:100% !important;
        border-radius:15px !important;
    }

    .j27-file-preview{
        gap:5px !important;
    }

    .j27-file-pill{
        min-width:170px !important;
        max-width:220px !important;
    }
}

/* Pantallas muy angostas */
@media(max-width:380px){
    .j27-message.user{
        width:98% !important;
    }

    .j27-file-pill{
        min-width:155px !important;
        max-width:195px !important;
    }
}