/* Widget chat asistente – Bienvenidos (botón flotante + panel) */

.cj-chat-asistente {
    --cj-chat-bg: #ffffff;
    --cj-chat-header: #0d1f3c;
    --cj-chat-accent: #0c54a0;
    --cj-chat-bubble-user: #e3f2fd;
    --cj-chat-bubble-bot: #f4f6f8;
    --cj-chat-radius: 16px;
    --cj-chat-shadow: 0 16px 48px rgba(13, 31, 60, 0.2);
    /* Encuadre del vídeo/ GIF en el FAB: sube el 2.º % si aún se ve franja negra; baja si se recorta (p. ej. 32%…46%). */
    --fab-media-object-y: 40%;
    --fab-media-scale: 1.14;
    --fab-media-origin-y: 42%;
    font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.cj-chat-asistente__fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #e3e6ea;
    color: #fff;
    box-shadow: var(--cj-chat-shadow);
    z-index: 1100;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 0;
    overflow: hidden;
}

.cj-chat-asistente__fab:hover {
    transform: scale(1.06);
}

.cj-chat-asistente__fab:focus-visible {
    outline: 3px solid rgba(12, 84, 160, 0.45);
    outline-offset: 2px;
}

.cj-chat-asistente__fab-img,
.cj-chat-asistente__fab-media {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    object-fit: cover;
    /* 50% horizontal; Y más bajo = “miramos” más hacia abajo en el plano, recortando banda superior (negra/letterbox). */
    object-position: 50% var(--fab-media-object-y, 40%);
    /* Zoom con origen ligeramente bajo al centro: centra a María y tapa bordes vacíos. */
    transform: scale(var(--fab-media-scale, 1.14));
    transform-origin: 50% var(--fab-media-origin-y, 42%);
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
    vertical-align: top;
    border: 0;
    outline: none;
    /* Fondo bajo el vídeo por si el alpha/borde hace un flash: tono gris de la toma, no negro. */
    background: #b8bcc4;
    backface-visibility: hidden;
}

/* FAB v2: solo la imagen, sin máscara circular ni marco (el vídeo sigue usando .fab redondo) */
.cj-chat-asistente__fab--v2 {
    width: auto;
    height: auto;
    max-width: min(200px, 46vw);
    max-height: min(240px, 38vh);
    border-radius: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    padding: 0;
    align-items: center;
    justify-content: center;
}

.cj-chat-asistente__fab--v2:hover {
    transform: scale(1.05);
}

.cj-chat-asistente__fab--v2:focus-visible {
    outline-offset: 4px;
}

/* Imagen a tamaño natural (tope max), sin recorte circular */
.cj-chat-asistente__fab--v2 .cj-chat-asistente__fab-media--v2 {
    width: auto;
    height: auto;
    max-width: min(200px, 46vw);
    max-height: min(240px, 38vh);
    min-width: 0;
    min-height: 0;
    object-fit: contain;
    object-position: 50% 100%;
    transform: none;
    padding: 0;
    background: transparent;
    box-sizing: border-box;
    /* Sombra suave alrededor del personaje (no marco blanco) */
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.28));
}

/* Anula reglas compartidas .fab-img/.fab-media para v2 (evita cover + zoom) */
.cj-chat-asistente__fab--v2 .cj-chat-asistente__fab-img,
.cj-chat-asistente__fab--v2 .cj-chat-asistente__fab-media {
    width: auto;
    height: auto;
    max-width: min(200px, 46vw);
    max-height: min(240px, 38vh);
    object-fit: contain;
    object-position: 50% 100%;
    transform: none;
    background: transparent;
}

.cj-chat-asistente__panel {
    position: fixed;
    right: 20px;
    bottom: 108px;
    width: min(100vw - 28px, 440px);
    max-height: min(82vh, 640px);
    min-height: 360px;
    background: var(--cj-chat-bg);
    border-radius: var(--cj-chat-radius);
    box-shadow: var(--cj-chat-shadow);
    border: 1px solid rgba(13, 31, 60, 0.06);
    z-index: 1100;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

/* Chat abierto: el FAB de MarIA se oculta; al cerrar (X) vuelve a mostrarse */
.cj-chat-asistente--open .cj-chat-asistente__fab {
    display: none;
}

.cj-chat-asistente--open .cj-chat-asistente__panel {
    display: flex;
    bottom: 24px; /* con el FAB oculto el panel apoya en la esquina (antes dejábamos sitio al botón) */
    right: 20px;
}

.cj-chat-asistente__header {
    background: linear-gradient(160deg, #0d1f3c 0%, #0c2d56 50%, #0a3a6e 100%);
    color: #fff;
    padding: 16px 16px 16px 18px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.cj-chat-asistente__head-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

.cj-chat-asistente__head-titles {
    min-width: 0;
}

.cj-chat-asistente__title {
    margin: 0 0 2px 0;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

/* Marca MarIA: M + ar + IA, gradiente tipo logotipo (rojo → ámbar) */
.cj-chat-asistente__title--mar-ia {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    line-height: 1.2;
    color: #f9a825;
    background: linear-gradient(180deg, #c62828 0%, #ef6c00 48%, #ffb300 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    -webkit-text-stroke: 0.35px rgba(255, 255, 255, 0.85);
    text-shadow: 0 0 0 rgba(255, 255, 255, 0.15);
}

.cj-chat-asistente__name-mar-ia {
    font-weight: 700;
    color: #c62828;
    background: linear-gradient(180deg, #c62828 0%, #e65100 50%, #f9a825 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.cj-chat-asistente__subtitle {
    font-size: 0.8rem;
    margin: 0;
    line-height: 1.35;
    opacity: 0.9;
    font-weight: 400;
}

.cj-chat-asistente__avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cj-chat-asistente__avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cj-chat-asistente__avatar-fallback {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.95);
    background: linear-gradient(135deg, #0c54a0, #1a6ec4);
}

.cj-chat-asistente__avatar-fallback.is-visible {
    display: flex;
}

.cj-chat-asistente__close {
    background: transparent;
    border: none;
    color: #fff;
    padding: 6px;
    cursor: pointer;
    border-radius: 8px;
    line-height: 1;
    flex-shrink: 0;
    margin: -2px -4px 0 0;
}

.cj-chat-asistente__close:hover {
    background: rgba(255, 255, 255, 0.12);
}

.cj-chat-asistente__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px;
    background: linear-gradient(180deg, #f6f8fa 0%, #fafbfc 12%);
    min-height: 260px;
    -webkit-overflow-scrolling: touch;
}

.cj-chat-asistente__empty {
    font-size: 0.9rem;
    color: #5c636a;
    text-align: center;
    padding: 32px 12px 28px;
    line-height: 1.5;
    max-width: 280px;
    margin: 0 auto;
}

.cj-chat-asistente__empty strong {
    color: #0c54a0;
    font-weight: 600;
}

.cj-chat-asistente__row {
    display: flex;
    margin-bottom: 10px;
}

.cj-chat-asistente__row--user {
    justify-content: flex-end;
}

.cj-chat-asistente__row--bot {
    justify-content: flex-start;
}

.cj-chat-asistente__bubble {
    max-width: 88%;
    padding: 11px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.cj-chat-asistente__bubble--user {
    background: var(--cj-chat-bubble-user);
    color: #0d1f3c;
    border-bottom-right-radius: 4px;
}

.cj-chat-asistente__bubble--bot {
    background: var(--cj-chat-bubble-bot);
    color: #212529;
    border-bottom-left-radius: 4px;
}

.cj-chat-asistente__bubble--bot-rich {
    white-space: normal;
    padding: 12px 14px 14px;
    max-width: 92%;
}

.cj-chat-asistente__texto-rico {
    font-size: 0.92rem;
    line-height: 1.55;
    color: #212529;
    word-wrap: break-word;
    /* Emojis/íconos: stack explícita para evitar “doble trazo” al mezclar con Public Sans vía <strong> */
    font-family: "Public Sans", system-ui, "Segoe UI", "Segoe UI Emoji", "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Symbol", sans-serif;
    text-rendering: optimizeLegibility;
}

/* Enlaces http(s) autodetectados: nueva pestaña (rel en el HTML) */
.cj-chat-asistente__texto-rico a.cj-cwa-a {
    color: var(--cj-chat-accent, #0c54a0);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    font-weight: 500;
}

.cj-chat-asistente__texto-rico a.cj-cwa-a:hover {
    color: #06336b;
    text-decoration-thickness: 2px;
}

.cj-chat-asistente__texto-rico a.cj-cwa-a:focus-visible {
    outline: 2px solid var(--cj-chat-accent, #0c54a0);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Keycap/emoji iniciales fuera del <strong> (ver chat-asistente.js): nunca color/weight forzado del negrita */
.cj-wa-emo,
.cj-chat-asistente__wa-emoji,
.cj-chat-asistente__texto-rico .cj-wa-emo *,
.cj-chat-asistente__texto-rico .cj-chat-asistente__wa-emoji * {
    display: inline;
    font-weight: 400;
    font-style: normal;
    line-height: inherit;
    text-shadow: none;
    -webkit-text-fill-color: currentColor;
    color: #212529;
    font-size: 1.08em;
    line-height: 1.2;
    vertical-align: -0.12em;
    margin-right: 0.1em;
    /* Evita contorno/ghosting con fuentes con peso o color forzado heredado */
    filter: none;
    letter-spacing: 0;
}

.cj-chat-asistente__texto-rico .cj-cwa-b,
.cj-chat-asistente__texto-rico .cj-cwa-b * {
    /* Negrita tipo chat (sin color de marca: evita halos al mezclar con Segoe/emoji) */
    font-weight: 700;
    color: #1b2838;
    text-shadow: none;
    letter-spacing: 0.01em;
}

.cj-chat-asistente__texto-rico .cj-cwa-i,
.cj-chat-asistente__texto-rico .cj-cwa-i * {
    font-style: italic;
    color: #1a1f26;
}

.cj-chat-asistente__texto-rico .cj-cwa-s,
.cj-chat-asistente__texto-rico .cj-cwa-s * {
    text-decoration: line-through;
    color: #6c757d;
    opacity: 0.9;
}

.cj-cwa-code--inline {
    font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
    font-size: 0.86em;
    background: #e9ecef;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    color: #0d1f3c;
}

.cj-cwa-pre {
    margin: 8px 0 0;
    padding: 10px 12px;
    background: #0d1f3c;
    color: #e8eef4;
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.5;
    overflow-x: auto;
    max-width: 100%;
}

.cj-cwa-code--block {
    display: block;
    font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

.cj-cwa-quote {
    margin: 4px 0;
    padding: 6px 0 6px 10px;
    border-left: 3px solid var(--cj-chat-accent);
    color: #495057;
    background: rgba(12, 84, 160, 0.06);
    border-radius: 0 6px 6px 0;
}

.cj-chat-asistente__imagen {
    display: block;
    max-width: 100%;
    width: auto;
    height: auto;
    max-height: 220px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid rgba(13, 31, 60, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.cj-chat-asistente__audio-wrap {
    margin-top: 10px;
    width: 100%;
    max-width: 100%;
}

.cj-chat-asistente__audio {
    display: block;
    width: 100%;
    max-width: 280px;
    min-height: 40px;
    vertical-align: middle;
    border-radius: 8px;
}

.cj-chat-asistente__imagen + .cj-chat-asistente__texto-rico {
    margin-top: 2px;
}

.cj-chat-asistente__meta {
    font-size: 0.65rem;
    color: #adb5bd;
    margin-top: 4px;
    padding: 0 4px;
}

.cj-chat-asistente__footer {
    padding: 12px 14px 14px;
    background: #fff;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.cj-chat-asistente__input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 0.95rem;
    resize: none;
    min-height: 48px;
    max-height: 140px;
}

.cj-chat-asistente__input:focus {
    outline: none;
    border-color: var(--cj-chat-accent);
    box-shadow: 0 0 0 2px rgba(12, 84, 160, 0.15);
}

.cj-chat-asistente__send {
    border: none;
    background: var(--cj-chat-accent);
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cj-chat-asistente__send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.cj-chat-asistente__send:hover:not(:disabled) {
    background: #094a8c;
}

.cj-chat-asistente__hint {
    font-size: 0.7rem;
    color: #868e96;
    padding: 0 12px 8px;
    background: #fff;
}

.cj-chat-asistente__typing {
    font-size: 0.75rem;
    color: #6c757d;
    padding: 0 14px 8px;
    display: none;
}

.cj-chat-asistente__typing.is-visible {
    display: block;
}

/* —— Tema “conversación” estilo WhatsApp (oscuro, referencia app) —— */
.cj-chat-asistente--wa {
    --wa-fondo: #0b141a;
    --wa-burbuja-entrada: #202c33;
    --wa-burbuja-salida: #005c4b;
    --wa-texto: #e9edef;
    --wa-texto-suave: #aebac1;
    --wa-input-fondo: #2a3942;
    --wa-borde: rgba(255, 255, 255, 0.08);
    --wa-sombra: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.cj-chat-asistente--wa .cj-chat-asistente__panel {
    background: #111b21;
    border-color: var(--wa-borde);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.cj-chat-asistente--wa .cj-chat-asistente__header {
    background: linear-gradient(180deg, #1f2c32 0%, #18232a 100%);
    border-bottom: 1px solid var(--wa-borde);
}

.cj-chat-asistente--wa .cj-chat-asistente__subtitle {
    color: #aebac1;
    opacity: 1;
}

.cj-chat-asistente--wa .cj-chat-asistente__messages {
    background-color: var(--wa-fondo);
    background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h32v32H0V0zm32 32h32v32H32V32z' fill='%23ffffff' fill-opacity='.02'/%3E%3C/svg%3E");
    color: var(--wa-texto);
    color-scheme: dark;
}

.cj-chat-asistente--wa .cj-chat-asistente__empty {
    color: var(--wa-texto-suave);
}

.cj-chat-asistente--wa .cj-chat-asistente__empty strong,
.cj-chat-asistente--wa .cj-chat-asistente__name-mar-ia {
    color: #6ec6ff;
    -webkit-text-fill-color: #6ec6ff;
}

.cj-chat-asistente--wa .cj-chat-asistente__bubble--user {
    background: var(--wa-burbuja-salida);
    color: #e6ffed;
    border-bottom-right-radius: 0.25rem;
    box-shadow: var(--wa-sombra);
}

.cj-chat-asistente--wa .cj-chat-asistente__bubble--bot,
.cj-chat-asistente--wa .cj-chat-asistente__bubble--bot-rich {
    background: var(--wa-burbuja-entrada);
    color: var(--wa-texto);
    border-bottom-left-radius: 0.25rem;
    box-shadow: var(--wa-sombra);
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico {
    color: var(--wa-texto);
}

.cj-chat-asistente--wa .cj-wa-emo,
.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-wa-emo * {
    color: var(--wa-texto);
    -webkit-text-fill-color: var(--wa-texto);
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-cwa-b,
.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-cwa-b * {
    color: #fff;
    font-weight: 600;
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-cwa-i,
.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-cwa-i * {
    color: #d1d7db;
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-cwa-s,
.cj-chat-asistente--wa .cj-chat-asistente__texto-rico .cj-cwa-s * {
    color: #8696a0;
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico a.cj-cwa-a {
    color: #53bdeb;
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico a.cj-cwa-a:hover {
    color: #7dcdf5;
}

.cj-chat-asistente--wa .cj-chat-asistente__texto-rico a.cj-cwa-a:focus-visible {
    outline-color: #53bdeb;
}

.cj-chat-asistente--wa .cj-cwa-code--inline {
    background: #2a3942;
    color: #e9edef;
}

.cj-chat-asistente--wa .cj-cwa-quote {
    border-left-color: #00a884;
    color: #d1d7db;
    background: rgba(0, 0, 0, 0.2);
}

.cj-chat-asistente--wa .cj-chat-asistente__imagen {
    background: #2a3942;
    border-color: var(--wa-borde);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.cj-chat-asistente--wa .cj-chat-asistente__audio {
    color-scheme: dark;
    filter: brightness(0.95);
}

.cj-chat-asistente--wa .cj-chat-asistente__footer {
    background: #1f2c32;
    border-top-color: var(--wa-borde);
}

.cj-chat-asistente--wa .cj-chat-asistente__input {
    background: var(--wa-input-fondo);
    border-color: #3b4a54;
    color: var(--wa-texto);
}

.cj-chat-asistente--wa .cj-chat-asistente__input::placeholder {
    color: #8696a0;
}

.cj-chat-asistente--wa .cj-chat-asistente__input:focus {
    border-color: #00a884;
    box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.2);
}

.cj-chat-asistente--wa .cj-chat-asistente__send {
    background: #00a884;
    color: #fff;
}

.cj-chat-asistente--wa .cj-chat-asistente__send:hover:not(:disabled) {
    background: #008f72;
}

.cj-chat-asistente--wa .cj-chat-asistente__hint,
.cj-chat-asistente--wa .cj-chat-asistente__typing {
    background: transparent;
    color: #8696a0;
}

@media (max-width: 576px) {
    .cj-chat-asistente__fab {
        right: 16px;
        bottom: max(16px, env(safe-area-inset-bottom));
    }

    .cj-chat-asistente__fab--v2,
    .cj-chat-asistente__fab--v2 .cj-chat-asistente__fab-img,
    .cj-chat-asistente__fab--v2 .cj-chat-asistente__fab-media--v2 {
        max-width: min(160px, 48vw);
        max-height: min(200px, 32vh);
    }

    .cj-chat-asistente__panel {
        right: 12px;
        left: 12px;
        width: auto;
        max-height: min(88vh, 100%);
        min-height: 300px;
        bottom: max(108px, calc(12px + env(safe-area-inset-bottom)));
    }

    .cj-chat-asistente--open .cj-chat-asistente__panel {
        bottom: max(16px, env(safe-area-inset-bottom));
        left: 12px;
        right: 12px;
    }
}
