/* Eras Chat Asistente. Todas las clases con prefijo eca- para evitar conflictos. */

#eca-chat-root *,
#eca-chat-root *::before,
#eca-chat-root *::after {
    box-sizing: border-box;
}

#eca-chat-root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --------- BOTON FLOTANTE --------- */
.eca-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(8, 145, 178, 0.4), 0 2px 8px rgba(0, 0, 0, 0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 0;
    animation: eca-fab-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.eca-fab:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 14px 36px rgba(8, 145, 178, 0.5), 0 4px 12px rgba(0, 0, 0, 0.16);
}
.eca-fab:active {
    transform: translateY(0) scale(0.98);
}
.eca-fab svg {
    width: 30px;
    height: 30px;
    stroke-width: 2.2;
}
.eca-fab-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    display: block;
}

@keyframes eca-fab-pop {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Pulso de atencion: solo se activa cuando aparece el teaser proactivo */
.eca-fab-pulse::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(8, 145, 178, 0.5);
    animation: eca-pulse-ring 2s cubic-bezier(0.66, 0, 0, 1) infinite;
}
@keyframes eca-pulse-ring {
    0%   { box-shadow: 0 0 0 0 rgba(8, 145, 178, 0.5); }
    70%  { box-shadow: 0 0 0 18px rgba(8, 145, 178, 0); }
    100% { box-shadow: 0 0 0 0 rgba(8, 145, 178, 0); }
}

/* Indicador de mensaje nuevo: puntito limpio (no numero) sobre el boton */
.eca-fab-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border-radius: 50%;
    border: 2.5px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    animation: eca-badge-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.eca-fab-badge[hidden] { display: none; }
@keyframes eca-badge-in {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* --------- TEASER PROACTIVO --------- */
.eca-teaser {
    position: fixed;
    bottom: 104px;
    left: 24px;
    max-width: 280px;
    background: #fff;
    color: #1f2937;
    padding: 14px 34px 14px 16px;
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 99998;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.4;
    animation: eca-teaser-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.eca-teaser[hidden] { display: none; }
.eca-teaser:hover { box-shadow: 0 14px 36px rgba(0, 0, 0, 0.2); }
.eca-teaser-out { animation: eca-teaser-out 0.25s ease-in forwards; }
.eca-teaser-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px;
}
.eca-teaser-close:hover { color: #4b5563; }
@keyframes eca-teaser-in {
    0% { opacity: 0; transform: translateY(12px) scale(0.9); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes eca-teaser-out {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(12px); }
}

/* --------- PANEL DEL CHAT --------- */
.eca-panel {
    position: fixed;
    bottom: 100px;
    left: 24px;
    width: 410px;
    max-width: calc(100vw - 32px);
    height: 620px;
    max-height: calc(100vh - 130px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    font-size: 14px;
    color: #1f2937;
    animation: eca-panel-in 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) both;
    transition: width 0.28s ease, height 0.28s ease;
}
.eca-panel[hidden] {
    display: none !important;
}
/* Modo ampliado: casi el doble de ancho, alto maximo */
.eca-panel-expanded {
    width: 560px;
    height: calc(100vh - 130px);
}

@keyframes eca-panel-in {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* --------- HEADER --------- */
.eca-header {
    background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 2;
}
.eca-header-title {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}
.eca-header-avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.eca-header-avatar svg {
    width: 22px;
    height: 22px;
}
.eca-avatar-img {
    width: 34px;
    height: 34px;
    object-fit: contain;
    display: block;
}
.eca-header-texts {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.eca-header-name {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.eca-header-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
    font-weight: 400;
    margin-top: 1px;
}
.eca-header-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.25);
    animation: eca-pulse 2s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes eca-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}
.eca-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.eca-icon-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.eca-icon-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}
.eca-icon-btn svg {
    width: 15px;
    height: 15px;
}
/* El boton de expandir se oculta en movil (no tiene sentido alli) */
@media (max-width: 480px) {
    .eca-expand { display: none; }
}

/* --------- MENSAJES --------- */
.eca-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f9fafb;
    scroll-behavior: smooth;
    /* Evita que el scroll se propague a la pagina al llegar al tope de los mensajes */
    overscroll-behavior: contain;
}
.eca-messages::-webkit-scrollbar {
    width: 6px;
}
.eca-messages::-webkit-scrollbar-track {
    background: transparent;
}
.eca-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.eca-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.eca-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    animation: eca-msg-in 0.2s ease-out both;
}
@keyframes eca-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.eca-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(8, 145, 178, 0.15);
}
.eca-msg-assistant {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* --------- TYPING INDICATOR --------- */
.eca-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    height: 16px;
}
.eca-typing span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: eca-typing-bounce 1.2s ease-in-out infinite;
}
.eca-typing span:nth-child(2) { animation-delay: 0.15s; }
.eca-typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes eca-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* --------- QUICK REPLIES --------- */
.eca-quick {
    padding: 8px 12px 4px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}
.eca-quick-label {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
}
.eca-quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.eca-quick-chip {
    background: #fff;
    border: 1px solid #0891b2;
    color: #0891b2;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    font-family: inherit;
}
.eca-quick-chip:hover {
    background: #0891b2;
    color: #fff;
}

/* --------- SELECTOR DE FECHAS RAPIDO --------- */
.eca-datepick {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #d1d5db;
}
.eca-datepick-fields {
    display: flex;
    gap: 8px;
}
.eca-datepick-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.eca-datepick-field span {
    font-size: 11px;
    color: #6b7280;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.eca-datepick-field input[type="date"] {
    border: 1px solid #d1d5db;
    border-radius: 9px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    color: #1f2937;
    background: #fff;
    outline: none;
    width: 100%;
    min-width: 0;
    min-height: 38px;
    /* iOS renderiza los date con estilos nativos de ancho fijo; esto lo normaliza */
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.eca-datepick-field input[type="date"]:focus {
    border-color: #0891b2;
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.12);
}
.eca-datepick-cta {
    margin-top: 8px;
    width: 100%;
    background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 11px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.eca-datepick-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(8, 145, 178, 0.35);
}
.eca-datepick-cta:active {
    transform: translateY(0);
}

/* --------- MARKDOWN DENTRO DE MENSAJES --------- */
.eca-msg a {
    color: #0891b2;
    text-decoration: underline;
    word-break: break-all;
}
.eca-msg-user a {
    color: #fff;
}
.eca-msg strong {
    font-weight: 600;
}
.eca-msg ul,
.eca-msg ol {
    margin: 4px 0;
    padding-left: 20px;
}
.eca-msg li {
    margin: 0;
    line-height: 1.45;
    padding: 1px 0;
}
.eca-msg li + li {
    margin-top: 2px;
}
.eca-msg-assistant ul,
.eca-msg-assistant ol {
    color: #1f2937;
}

/* --------- FORMULARIO INPUT --------- */
.eca-form {
    display: flex;
    border-top: 1px solid #e5e7eb;
    padding: 12px;
    gap: 8px;
    background: #fff;
    align-items: center;
}
.eca-input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid #d1d5db;
    border-radius: 22px;
    font-size: 14px;
    outline: none;
    color: #1f2937;
    background: #f9fafb;
    transition: border-color 0.15s ease, background 0.15s ease;
    font-family: inherit;
}
.eca-input::placeholder {
    color: #9ca3af;
}
.eca-input:focus {
    border-color: #0891b2;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.12);
}
.eca-send {
    width: 42px;
    height: 42px;
    padding: 0;
    background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
}
.eca-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(8, 145, 178, 0.3);
}
.eca-send:active {
    transform: scale(0.95);
}
.eca-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
.eca-send svg {
    width: 18px;
    height: 18px;
}

/* --------- FOOTER OPCIONAL --------- */
.eca-footer {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    padding: 6px 0 10px;
    background: #fff;
}
.eca-footer a {
    color: #6b7280;
    text-decoration: none;
}

/* --------- MOVIL --------- */
@media (max-width: 480px) {
    .eca-fab {
        bottom: 18px;
        left: 18px;
        width: 60px;
        height: 60px;
    }
    .eca-teaser {
        bottom: 90px;
        left: 18px;
        max-width: calc(100vw - 90px);
    }
    .eca-panel,
    .eca-panel-expanded {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }
    /* iOS: reservar el area segura inferior (home indicator / barra de Safari)
       para que no se coma el boton de enviar ni se solape con nada del sistema. */
    .eca-form {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    /* Fechas en columna: en pantallas estrechas los date de iOS no encogen
       lo suficiente y acababan solapandose */
    .eca-datepick-fields {
        flex-direction: column;
        gap: 10px;
    }
    /* iOS hace zoom automatico al enfocar inputs con fuente menor de 16px,
       y ese zoom descuadra el panel. 16px lo evita. */
    .eca-input,
    .eca-datepick-field input[type="date"] {
        font-size: 16px;
    }
}
