/* :host (no :root) a propósito: este archivo se carga DENTRO de un Shadow
   DOM (ver widget.js), así que :host apunta al contenedor del widget y no
   al <html> de la página real donde esté embebido. Con :root, estas
   variables se filtrarían al documento anfitrión — justo lo que el
   aislamiento por Shadow DOM busca evitar. */
:host {
    --pta-navy-900: #0B2A43;
    --pta-navy-700: #123A5C;
    --pta-navy-600: #17486E;
    --pta-teal-500: #1C8C74;
    --pta-teal-600: #15705D;
    --pta-teal-100: #E1F3EE;
    --pta-bg: #F3F6F8;
    --pta-surface: #FFFFFF;
    --pta-border: #E1E6EB;
    --pta-text: #1C2733;
    --pta-text-soft: #63707C;
    --pta-text-faint: #94A0AB;
    --pta-online: #2FBE83;
    --pta-shadow: 0 12px 32px rgba(11, 42, 67, 0.16);
    --pta-shadow-launcher: 0 8px 20px rgba(11, 42, 67, 0.28);
    --pta-radius-lg: 18px;
    --pta-radius-md: 12px;
    --pta-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#pta-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    padding: 0;
    background: var(--pta-navy-900);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--pta-shadow-launcher);
    font-family: var(--pta-font);
    z-index: 2147483000;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#pta-chat-launcher:hover {
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 10px 24px rgba(11, 42, 67, 0.34);
}

#pta-chat-launcher:focus-visible {
    outline: 2px solid var(--pta-teal-500);
    outline-offset: 2px;
}

#pta-chat-launcher svg {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

#pta-chat-launcher .pta-launcher-icon-wrap {
    position: relative;
    display: flex;
}

/* Anillo de pulso: se dispara UNA sola vez al cargar (no en loop — un anillo
   que nunca para se ve como spam, no como invitación). */
.pta-launcher-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--pta-teal-500);
    opacity: 0.55;
    pointer-events: none;
    animation: pta-pulse-ring 1.4s ease-out 1;
}

.pta-launcher-pulse.pta-pulse-2 {
    background: var(--pta-teal-100);
    opacity: 0.75;
}

@keyframes pta-pulse-ring {
    0% { transform: scale(1); opacity: 0.55; }
    100% { transform: scale(2); opacity: 0; }
}

/* Entrada del botón al aparecer por primera vez: un pequeño "rebote" en vez
   de aparecer seco — sin texto, solo movimiento, elegante y discreto. */
#pta-chat-launcher.pta-launcher-enter {
    animation: pta-launcher-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes pta-launcher-pop {
    0% { transform: scale(0.4); opacity: 0; }
    60% { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Pequeño "respiro" del ícono cuando se dispara la llamada de atención,
   para que el movimiento no sea solo el anillo sino también el botón mismo. */
#pta-chat-launcher.pta-launcher-attn .pta-launcher-icon-wrap {
    animation: pta-icon-breathe 0.7s ease-in-out 2;
}

@keyframes pta-icon-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

#pta-chat-launcher .pta-launcher-label {
    display: none;
}

#pta-chat-window {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 368px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 132px);
    max-height: calc(100dvh - 132px);
    background: var(--pta-surface);
    border-radius: var(--pta-radius-lg);
    box-shadow: var(--pta-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 2147483000;
    font-family: var(--pta-font);
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    transition: opacity 0.16s ease, transform 0.16s ease;
}

#pta-chat-window.open {
    display: flex;
}

#pta-chat-window.open.pta-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

#pta-chat-header {
    background: var(--pta-navy-900);
    color: #fff;
    padding: 16px 16px 16px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

#pta-chat-header .pta-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--pta-teal-500);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    overflow: hidden;
}

#pta-chat-header .pta-avatar.pta-avatar-img {
    /* Logo: cuadrado con esquinas redondeadas, NO círculo perfecto. Forzar
       cualquier logo a un círculo asume que está perfectamente centrado en
       su propio archivo — casi nunca es así, y el recorte se ve chueco.
       (selector calificado a propósito: sin esto, #pta-chat-header .pta-avatar
       de arriba gana por especificidad y el border-radius:50% no se pisa) */
    border-radius: 9px;
    background: var(--pta-surface);
}
.pta-avatar-img img {
    width: 100%;
    height: 100%;
    /* "contain": el logo se ve COMPLETO, tal cual lo subieron, sin recortar
       nada ni adivinar cómo está compuesto el archivo. */
    object-fit: contain;
    padding: 2px;
    box-sizing: border-box;
}

#pta-chat-header .pta-header-text {
    flex: 1;
    min-width: 0;
}

#pta-chat-header .pta-header-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}

#pta-chat-header .pta-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.72);
    margin-top: 2px;
}

#pta-chat-header .pta-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--pta-online);
    flex-shrink: 0;
}

#pta-chat-minimize,
#pta-chat-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background 0.12s ease;
}

#pta-chat-minimize:hover,
#pta-chat-close:hover { background: rgba(255, 255, 255, 0.12); }
#pta-chat-minimize svg,
#pta-chat-close svg { width: 16px; height: 16px; }

#pta-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: var(--pta-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pta-row {
    display: flex;
    gap: 8px;
    max-width: 88%;
}

.pta-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.pta-row.bot { align-self: flex-start; }

.pta-row .pta-mini-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--pta-navy-700);
    color: #fff;
    font-size: 8.5px;
    letter-spacing: -0.2px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    overflow: hidden;
}

.pta-bubble-col { display: flex; flex-direction: column; min-width: 0; }

.pta-row.user .pta-bubble-col { align-items: flex-end; }

.pta-msg {
    padding: 9px 13px;
    border-radius: var(--pta-radius-md);
    font-size: 13.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.pta-row.user .pta-msg {
    background: var(--pta-navy-900);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.pta-row.bot .pta-msg {
    background: var(--pta-surface);
    color: var(--pta-text);
    border: 1px solid var(--pta-border);
    border-bottom-left-radius: 4px;
}

.pta-msg a {
    color: var(--pta-teal-600);
    text-decoration: underline;
    word-break: break-all;
}

.pta-msg a:hover { color: var(--pta-teal-500); }

.pta-timestamp {
    font-size: 10.5px;
    color: var(--pta-text-faint);
    margin-top: 3px;
    padding: 0 2px;
}

.pta-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 11px 13px;
}

.pta-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--pta-text-faint);
    animation: pta-bounce 1.1s infinite ease-in-out;
}

.pta-typing span:nth-child(2) { animation-delay: 0.15s; }
.pta-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pta-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

#pta-chat-messages::-webkit-scrollbar { width: 6px; }
#pta-chat-messages::-webkit-scrollbar-thumb { background: #C7D0D8; border-radius: 3px; }
#pta-chat-messages::-webkit-scrollbar-track { background: transparent; }

#pta-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px;
    border-top: 1px solid var(--pta-border);
    background: var(--pta-surface);
    flex-shrink: 0;
}

#pta-chat-input {
    flex: 1;
    border: 1px solid var(--pta-border);
    background: var(--pta-bg);
    border-radius: 999px;
    padding: 10px 15px;
    font-size: 13.5px;
    font-family: var(--pta-font);
    color: var(--pta-text);
    outline: none;
    transition: border-color 0.12s ease, background 0.12s ease;
}

#pta-chat-input::placeholder { color: var(--pta-text-faint); }

#pta-chat-input:focus {
    border-color: var(--pta-teal-500);
    background: var(--pta-surface);
}

#pta-chat-form button {
    border: none;
    background: var(--pta-navy-900);
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s ease, transform 0.1s ease;
}

#pta-chat-form button svg { width: 16px; height: 16px; }
#pta-chat-form button:hover { background: var(--pta-navy-700); }
#pta-chat-form button:active { transform: scale(0.94); }

#pta-chat-form button:disabled {
    background: var(--pta-text-faint);
    cursor: default;
    transform: none;
}

@media (max-width: 420px) {
    #pta-chat-window {
        right: 16px;
        bottom: 86px;
        width: calc(100vw - 32px);
    }
    #pta-chat-launcher { right: 16px; }
}
