/* ============================================================
   Bot Bert — botón flotante arrastrable + hoja inferior (bottom-sheet)
   Usa las variables de tema de Resonum (tema-resonum.css).
   ============================================================ */

/* Botón flotante (FAB) */
.bert-fab {
    position: fixed;
    right: 16px; bottom: 14px;
    z-index: 9980;
    width: 78px; height: 78px;
    border: 3px solid var(--rs-coral-500, #D55F44); border-radius: 50%;
    background: radial-gradient(circle at 38% 30%, #FFFFFF, #EFE7D6);
    cursor: pointer; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 22px -2px rgba(31,58,67,.36), 0 0 0 4px color-mix(in srgb, var(--rs-coral-500, #D55F44) 18%, transparent);
    transition: transform .15s ease, box-shadow .15s ease;
}
.bert-fab:hover  { transform: translateY(-2px); box-shadow: 0 12px 28px -4px rgba(31,58,67,.42), 0 0 0 5px color-mix(in srgb, var(--rs-coral-500, #D55F44) 24%, transparent); }
.bert-fab img    { width: 92%; height: 92%; object-fit: contain; pointer-events: none; }

/* "Volver arriba" (mejoras-ui) se apila JUSTO ENCIMA de Bot Bert, centrado y
   pegadito (poco espacio entre ambos). FAB desktop: right 16, 78px → centro-x 55. */
.es-volver-arriba { right: 37px !important; bottom: 100px !important; }

/* En mobile: Bot Bert por encima de la barra inferior, y "volver arriba" encima de él. */
@media (max-width: 900px) {
    /* Bert más grande en mobile (antes 50px se veía chiquito). El volver-arriba
       se mueve EN BLOQUE, justo arriba del FAB y centrado con él.
       FAB: 64px, right 16 → centro-x a 48px del borde; borde superior en bottom 124. */
    .bert-fab { width: 64px; height: 64px; bottom: 60px; right: 16px; }
    .es-volver-arriba { right: 32px !important; bottom: 132px !important; }
}

/* Overlay que oscurece la pantalla (suspende el fondo) */
.bert-overlay {
    position: fixed; inset: 0;
    z-index: 9990;
    background: rgba(0,0,0,0);
    pointer-events: none;
    transition: background .25s ease;
    display: flex; align-items: flex-end; justify-content: center;
}
.bert-overlay.abierto { background: rgba(0,0,0,.45); pointer-events: auto; }

/* Hoja inferior que emerge de abajo hacia arriba */
.bert-sheet {
    width: 100%; max-width: 560px; height: 600px; max-height: 85vh;
    background: var(--rs-marfil-50, #FBF7EE);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 40px -10px rgba(0,0,0,.4);
    display: flex; flex-direction: column; overflow: hidden;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.bert-overlay.abierto .bert-sheet { transform: translateY(0); }

.bert-handle {
    width: 42px; height: 4px; flex: none;
    margin: 10px auto 4px;
    border-radius: 99px; background: var(--rs-tinta-300, #cdc6b8);
}

.bert-header {
    display: flex; align-items: center; gap: .6rem; flex: none;
    padding: .5rem 1rem .7rem;
    background: color-mix(in srgb, var(--rs-petrol-800, #1F3A43) 8%, var(--rs-marfil-50, #FBF7EE));
    border-bottom: 1px solid var(--rs-tinta-200, #e7e0d2);
}
.bert-avatar {
    width: 46px; height: 46px; flex: none; overflow: hidden;
    border-radius: 50%;
    background: radial-gradient(circle at 38% 30%, #FFFFFF, #EFE7D6);
    border: 2px solid var(--rs-coral-500, #D55F44);
    display: flex; align-items: center; justify-content: center;
}
.bert-avatar img { width: 94%; height: 94%; object-fit: contain; }
.bert-titulo {
    flex: 1;
    font-family: var(--rs-fuente-display, Georgia, serif);
    font-weight: 700; font-size: 1.05rem;
    color: var(--rs-petrol-900, #0b2330);
}
.bert-cerrar {
    background: none; border: none; cursor: pointer; line-height: 0;
    color: var(--rs-tinta-500, #777); padding: 6px; border-radius: 8px;
}
.bert-cerrar:hover { background: var(--rs-tinta-100, #f0eada); }
.bert-cerrar svg { width: 20px; height: 20px; }
/* Botón "Nuevo chat" — mismo estilo que cerrar, con tinte petrol */
.bert-nuevo {
    background: none; border: none; cursor: pointer; line-height: 0;
    color: var(--rs-petrol-700, #2b4d57); padding: 6px; border-radius: 8px;
}
.bert-nuevo:hover { background: var(--rs-tinta-100, #f0eada); }
.bert-nuevo svg { width: 20px; height: 20px; }

.bert-msgs {
    flex: 1; overflow-y: auto;
    padding: 1rem;
    background: color-mix(in srgb, #fff 45%, var(--rs-marfil-50, #FBF7EE));
    display: flex; flex-direction: column; gap: .6rem;
}
.bert-bubble {
    max-width: 85%;
    padding: .55rem .85rem;
    font-size: .95rem; line-height: 1.5;
    border-radius: 14px;
    white-space: pre-wrap; word-wrap: break-word;
}
.bert-bubble--user {
    align-self: flex-end;
    background: var(--rs-petrol-800, #1F3A43); color: var(--rs-marfil-50, #FBF7EE);
    border-bottom-right-radius: 4px;
}
.bert-bubble--bot {
    align-self: flex-start;
    background: color-mix(in srgb, var(--rs-coral-500, #D55F44) 10%, #fff);
    border: 1px solid color-mix(in srgb, var(--rs-coral-500, #D55F44) 22%, transparent);
    color: var(--rs-tinta-700, #3a3329);
    border-bottom-left-radius: 4px;
}
.bert-typing {
    align-self: flex-start;
    color: var(--rs-tinta-400, #999); font-size: .85rem; font-style: italic;
    padding: .3rem .2rem;
}
.bert-vacio {
    margin: auto; text-align: center; max-width: 300px;
    color: var(--rs-tinta-500, #777); font-size: .9rem; line-height: 1.55;
}
.bert-vacio strong {
    display: block; margin-bottom: .3rem;
    font-family: var(--rs-fuente-display, Georgia, serif); font-size: 1.1rem;
    color: var(--rs-petrol-800, #1F3A43);
}
.bert-aviso {
    margin: auto; text-align: center;
    color: var(--rs-tinta-600, #555); font-size: .9rem; line-height: 1.6;
}
.bert-aviso a { color: var(--rs-coral-700, #93372A); font-weight: 700; }
/* Confirmación in-theme antes de vaciar el chat */
.bert-confirm {
    margin: auto; text-align: center; max-width: 320px;
    color: var(--rs-tinta-700, #3a3329); font-size: .92rem; line-height: 1.55;
    background: color-mix(in srgb, var(--rs-coral-500, #D55F44) 8%, #fff);
    border: 1px solid color-mix(in srgb, var(--rs-coral-500, #D55F44) 25%, transparent);
    border-radius: 14px; padding: 1rem 1.1rem;
}
.bert-confirm strong {
    font-family: var(--rs-fuente-display, Georgia, serif);
    color: var(--rs-petrol-800, #1F3A43);
}
.bert-confirm-acciones { display: flex; gap: .5rem; justify-content: center; margin-top: .85rem; }
.bert-confirm-acciones button {
    font: inherit; font-size: .88rem; font-weight: 700; cursor: pointer;
    padding: .45rem .9rem; border-radius: 10px; border: none;
}
.bert-confirm-si { background: var(--rs-coral-500, #D55F44); color: var(--rs-marfil-50, #FBF7EE); }
.bert-confirm-si:hover { background: var(--rs-coral-600, #B94732); }
.bert-confirm-no { background: var(--rs-tinta-200, #e7e0d2); color: var(--rs-tinta-800, #2a2620); }
.bert-confirm-no:hover { background: var(--rs-tinta-300, #cdc6b8); }

.bert-form {
    display: flex; gap: .5rem; align-items: flex-end; flex: none;
    padding: .75rem 1rem;
    background: color-mix(in srgb, var(--rs-petrol-800, #1F3A43) 4%, var(--rs-marfil-50, #FBF7EE));
    border-top: 1px solid var(--rs-tinta-200, #e7e0d2);
}
.bert-input {
    flex: 1; resize: none; font: inherit; font-size: .95rem;
    min-height: 42px; max-height: 120px;
    padding: .55rem .75rem;
    border: 1.5px solid var(--rs-tinta-300, #cdc6b8); border-radius: 12px;
    background: #fff; color: var(--rs-tinta-800, #2a2620);
}
.bert-input:focus { outline: none; border-color: var(--rs-coral-500, #D55F44); }
.bert-enviar {
    flex: none; width: 42px; height: 42px;
    border: none; border-radius: 50%; cursor: pointer;
    background: var(--rs-coral-500, #D55F44); color: var(--rs-marfil-50, #FBF7EE);
    display: flex; align-items: center; justify-content: center;
}
.bert-enviar:hover    { background: var(--rs-coral-600, #B94732); }
.bert-enviar:disabled { opacity: .5; cursor: default; }
.bert-enviar svg      { width: 20px; height: 20px; }

/* ---- Markdown dentro de las burbujas del bot ---- */
.bert-bubble--bot { white-space: normal; }
.bert-bubble--bot p { margin: 0 0 .5rem; }
.bert-bubble--bot strong { color: var(--rs-petrol-900, #0b2330); }
.bert-bubble--bot ul,
.bert-bubble--bot ol { margin: .35rem 0; padding-left: 1.25rem; }
.bert-bubble--bot li { margin: .15rem 0; }
.bert-bubble--bot a { color: var(--rs-coral-700, #93372A); font-weight: 700; }
.bert-bubble--bot code {
    font-family: var(--rs-fuente-mono, ui-monospace, monospace); font-size: .85em;
    background: color-mix(in srgb, var(--rs-petrol-800, #1F3A43) 10%, transparent);
    padding: .05rem .3rem; border-radius: 5px;
}
.bert-bubble--bot pre {
    margin: .4rem 0; padding: .6rem .7rem; overflow-x: auto;
    background: color-mix(in srgb, var(--rs-petrol-800, #1F3A43) 8%, #fff);
    border: 1px solid color-mix(in srgb, var(--rs-petrol-800, #1F3A43) 18%, transparent);
    border-radius: 10px;
}
.bert-bubble--bot pre code { background: none; padding: 0; }

/* El indicador "pensando…/consultando…" ahora vive dentro de la burbuja del bot. */
.bert-bubble--bot .bert-typing { display: inline-block; padding: 0; }

/* ---- Prompts sugeridos (estado inicial) ---- */
.bert-sugerencias {
    display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center;
    margin: .25rem auto 0; max-width: 340px;
}
.bert-sug {
    font: inherit; font-size: .82rem; cursor: pointer;
    padding: .4rem .7rem; border-radius: 999px;
    background: color-mix(in srgb, var(--rs-coral-500, #D55F44) 8%, #fff);
    border: 1px solid color-mix(in srgb, var(--rs-coral-500, #D55F44) 30%, transparent);
    color: var(--rs-petrol-800, #1F3A43);
    transition: background .15s ease;
}
.bert-sug:hover { background: color-mix(in srgb, var(--rs-coral-500, #D55F44) 18%, #fff); }

@media (max-width: 560px) {
    .bert-sheet { height: 80vh; border-radius: 16px 16px 0 0; }
}
