/* ============================================================
   Asistente Consular Virtual — Ecuador
   Widget de chat autocontenido. Todo namespaced bajo #ecc.
   Marca: azul #003893, acentos bandera (amarillo/rojo).
   ============================================================ */

#ecc, #ecc * { box-sizing: border-box; }

#ecc {
    --ecc-blue: #003893;
    --ecc-blue-dark: #002370;
    --ecc-yellow: #ffdd00;
    --ecc-red: #ef3340;
    --ecc-ink: #14213a;
    --ecc-body: #3a4557;
    --ecc-muted: #7b879c;
    --ecc-surface: #ffffff;
    --ecc-tint: #f4f8ff;
    --ecc-border: #dce6f7;
    --ecc-shadow: 0 24px 60px -12px rgba(0, 34, 90, .38), 0 8px 24px -8px rgba(0, 34, 90, .25);
    --ecc-radius: 20px;
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2147483000;
    font-family: 'Roboto', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Reposiciona los botones flotantes existentes a la IZQUIERDA
   para dejar la esquina inferior-derecha al chat. */
body .fixed-btn--container { left: 20px; right: auto; }
body .up-arrow { left: 24px; right: auto; }

/* ---------- Lanzador (FAB) ---------- */
.ecc-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(24px) scale(.85);
    transition: opacity .45s cubic-bezier(.2,.9,.3,1), transform .45s cubic-bezier(.2,.9,.3,1);
}
#ecc.is-revealed .ecc-launcher { opacity: 1; transform: translateY(0) scale(1); }
#ecc.is-open .ecc-launcher { opacity: 0; transform: translateY(24px) scale(.85); pointer-events: none; }

.ecc-fab {
    position: relative;
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(145deg, #0046b8 0%, var(--ecc-blue) 55%, #002a72 100%);
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 12px 28px -6px rgba(0,56,147,.6), 0 4px 10px rgba(0,0,0,.18);
    transition: transform .18s ease, box-shadow .18s ease;
    flex-shrink: 0;
}
.ecc-fab:hover { transform: translateY(-3px); box-shadow: 0 18px 34px -6px rgba(0,56,147,.7); }
.ecc-fab:active { transform: translateY(-1px) scale(.97); }
.ecc-fab svg { width: 28px; height: 28px; }
.ecc-fab::after { /* anillo pulso */
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--ecc-blue);
    opacity: .55;
    animation: ecc-pulse 2.4s ease-out infinite;
}
@keyframes ecc-pulse {
    0%   { transform: scale(1);    opacity: .5; }
    70%  { transform: scale(1.55); opacity: 0; }
    100% { transform: scale(1.55); opacity: 0; }
}
.ecc-fab-badge {
    position: absolute;
    top: -2px; right: -2px;
    min-width: 20px; height: 20px;
    padding: 0 5px;
    background: var(--ecc-red);
    color: #fff;
    font-size: 11px; font-weight: 700;
    border-radius: 10px;
    display: grid; place-items: center;
    border: 2px solid #fff;
    font-family: 'Montserrat', sans-serif;
}

/* Burbuja de saludo proactivo */
.ecc-greeting {
    max-width: 232px;
    background: #fff;
    color: var(--ecc-ink);
    padding: 12px 14px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: var(--ecc-shadow);
    font-size: 13.5px;
    line-height: 1.45;
    position: relative;
    opacity: 0;
    transform: translateX(12px) scale(.9);
    transition: opacity .35s ease, transform .35s ease;
    pointer-events: none;
}
.ecc-greeting strong { font-family: 'Montserrat', sans-serif; font-weight: 700; }
#ecc.show-greeting .ecc-greeting { opacity: 1; transform: translateX(0) scale(1); pointer-events: auto; }
.ecc-greeting-close {
    position: absolute; top: -8px; left: -8px;
    width: 22px; height: 22px; border-radius: 50%;
    background: #eef2fa; border: 1px solid var(--ecc-border);
    color: var(--ecc-muted); font-size: 13px; line-height: 1;
    cursor: pointer; display: grid; place-items: center;
}

/* ---------- Panel ---------- */
.ecc-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 388px;
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 48px));
    background: var(--ecc-surface);
    border-radius: var(--ecc-radius);
    box-shadow: var(--ecc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(28px) scale(.96);
    transform-origin: bottom right;
    transition: opacity .3s ease, transform .3s cubic-bezier(.2,.9,.3,1);
}
#ecc.is-open .ecc-panel { opacity: 1; transform: translateY(0) scale(1); }
#ecc:not(.is-open) .ecc-panel { pointer-events: none; }

/* Header con hairline de la bandera */
.ecc-header {
    position: relative;
    background: linear-gradient(160deg, #0046b8 0%, var(--ecc-blue) 60%, #002a72 100%);
    color: #fff;
    padding: 16px 16px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.ecc-header::before { /* firma: bandera Ecuador en hairline */
    content: "";
    position: absolute; top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg,
        var(--ecc-yellow) 0 50%, var(--ecc-blue) 50% 75%, var(--ecc-red) 75% 100%);
}
.ecc-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: rgba(255,255,255,.14);
    border: 1.5px solid rgba(255,255,255,.32);
    display: grid; place-items: center;
    flex-shrink: 0;
}
.ecc-avatar svg { width: 24px; height: 24px; color: #fff; }
.ecc-id { flex: 1; min-width: 0; }
.ecc-id h3 {
    margin: 0; font-family: 'Montserrat', sans-serif;
    font-size: 15px; font-weight: 700; color: #fff; line-height: 1.2;
}
.ecc-status { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; color: rgba(255,255,255,.82); }
.ecc-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.28); }
.ecc-close {
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(255,255,255,.12); border: none; color: #fff;
    cursor: pointer; display: grid; place-items: center; flex-shrink: 0;
    transition: background .18s ease;
}
.ecc-close:hover { background: rgba(255,255,255,.24); }
.ecc-close svg { width: 18px; height: 18px; }

/* Zona de mensajes */
.ecc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 8px;
    background:
        radial-gradient(120% 60% at 100% 0%, #eef4ff 0%, transparent 60%),
        var(--ecc-tint);
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ecc-messages::-webkit-scrollbar { width: 6px; }
.ecc-messages::-webkit-scrollbar-thumb { background: #c8d6ef; border-radius: 3px; }

.ecc-row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; animation: ecc-in .32s ease both; }
@keyframes ecc-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.ecc-row.bot { justify-content: flex-start; }
.ecc-row.user { justify-content: flex-end; }
.ecc-row-avatar {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(145deg, #0046b8, var(--ecc-blue));
    display: grid; place-items: center; margin-bottom: 2px;
}
.ecc-row-avatar svg { width: 15px; height: 15px; color: #fff; }

.ecc-bubble {
    max-width: 82%;
    padding: 11px 14px;
    font-size: 14.2px;
    line-height: 1.5;
    border-radius: 16px;
    color: var(--ecc-body);
}
.ecc-row.bot .ecc-bubble {
    background: #fff;
    border: 1px solid var(--ecc-border);
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 6px rgba(0,34,90,.05);
}
.ecc-row.user .ecc-bubble {
    background: linear-gradient(145deg, #0046b8, var(--ecc-blue));
    color: #fff;
    border-bottom-right-radius: 5px;
}
.ecc-bubble strong { color: inherit; font-weight: 700; }
.ecc-bubble p { margin: 0 0 8px; font-size: inherit; color: inherit; line-height: inherit; }
.ecc-bubble p:last-child { margin-bottom: 0; }

/* Fuente verificada */
.ecc-source {
    display: flex; align-items: center; gap: 5px;
    margin-top: 9px; padding-top: 9px;
    border-top: 1px dashed var(--ecc-border);
    font-size: 11.5px; color: var(--ecc-muted);
}
.ecc-source svg { width: 13px; height: 13px; color: #34a853; flex-shrink: 0; }

/* CTA dentro de la burbuja */
.ecc-cta {
    display: inline-flex; align-items: center; gap: 7px;
    margin-top: 10px;
    background: var(--ecc-blue); color: #fff !important;
    padding: 9px 15px; border-radius: 10px;
    font-size: 13.2px; font-weight: 600; text-decoration: none;
    font-family: 'Montserrat', sans-serif;
    transition: background .18s ease, transform .15s ease;
}
.ecc-cta:hover { background: var(--ecc-blue-dark); transform: translateY(-1px); }
.ecc-cta svg { width: 14px; height: 14px; }
.ecc-cta.ghost { background: #eef3fd; color: var(--ecc-blue) !important; }
.ecc-cta.ghost:hover { background: #e0e9fa; }
.ecc-cta-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ecc-cta-group .ecc-cta { margin-top: 0; }

/* Módulo comercial (lead) */
.ecc-lead {
    margin-top: 11px; padding: 12px;
    background: linear-gradient(135deg, #fff9e6, #fff);
    border: 1px solid #ffe89c;
    border-radius: 12px;
}
.ecc-lead-label {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: #b7791f; margin-bottom: 6px; font-family: 'Montserrat', sans-serif;
}
.ecc-lead-label svg { width: 12px; height: 12px; }
.ecc-lead p { font-size: 13px; margin: 0 0 9px; color: var(--ecc-body); }
.ecc-lead .ecc-cta { background: #f0a500; color: #3a2a00 !important; }
.ecc-lead .ecc-cta:hover { background: #dd9500; }

/* Indicador de escritura */
.ecc-typing { display: inline-flex; gap: 4px; padding: 13px 15px; }
.ecc-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #9db4d8;
    animation: ecc-bounce 1.3s infinite ease-in-out both;
}
.ecc-typing span:nth-child(2) { animation-delay: .16s; }
.ecc-typing span:nth-child(3) { animation-delay: .32s; }
@keyframes ecc-bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

/* Chips de respuesta rápida */
.ecc-chips {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 10px 16px 4px;
    flex-shrink: 0;
    background: var(--ecc-tint);
}
.ecc-chip {
    background: #fff;
    border: 1.5px solid var(--ecc-border);
    color: var(--ecc-blue);
    padding: 8px 13px;
    border-radius: 20px;
    font-size: 12.8px; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all .16s ease;
    font-family: 'Roboto', sans-serif;
}
.ecc-chip:hover { background: var(--ecc-blue); color: #fff; border-color: var(--ecc-blue); transform: translateY(-1px); }

/* Barra de entrada */
.ecc-input-wrap { padding: 10px 14px 8px; background: var(--ecc-tint); flex-shrink: 0; }
.ecc-input {
    display: flex; align-items: center; gap: 8px;
    background: #fff;
    border: 1.5px solid var(--ecc-border);
    border-radius: 26px;
    padding: 5px 5px 5px 16px;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.ecc-input:focus-within { border-color: var(--ecc-blue); box-shadow: 0 0 0 3px rgba(0,56,147,.12); }
.ecc-input input {
    flex: 1; border: none; outline: none; background: transparent;
    font-size: 14px; color: var(--ecc-ink); font-family: 'Roboto', sans-serif;
    min-width: 0; padding: 8px 0;
}
.ecc-input input::placeholder { color: #a3aec0; }
.ecc-send {
    width: 40px; height: 40px; border-radius: 50%; border: none; flex-shrink: 0;
    background: var(--ecc-blue); color: #fff; cursor: pointer;
    display: grid; place-items: center;
    transition: background .18s ease, transform .15s ease;
}
.ecc-send:hover { background: var(--ecc-blue-dark); }
.ecc-send:active { transform: scale(.92); }
.ecc-send svg { width: 18px; height: 18px; }

.ecc-disclaimer {
    text-align: center;
    font-size: 10.5px; color: var(--ecc-muted);
    padding: 6px 12px 4px; line-height: 1.4;
}
.ecc-disclaimer a { color: var(--ecc-muted); text-decoration: underline; }

/* ---------- Móvil: hoja a pantalla completa ---------- */
/* Breakpoint alineado con la navbar (700px). En móvil hay una barra
   inferior "Pedir Cita" a todo el ancho: el lanzador sube por encima. */
@media (max-width: 700px) {
    .ecc-panel {
        bottom: 0; right: 0; left: 0;
        width: 100%; max-width: 100%;
        height: 100dvh;
        border-radius: 0;
        transform-origin: bottom center;
    }
    #ecc:not(.is-open) .ecc-panel { transform: translateY(100%); }
    #ecc.is-open .ecc-panel { transform: translateY(0); }
    .ecc-launcher { bottom: 84px; right: 16px; }   /* por encima de la barra de cita */
    .ecc-greeting { max-width: 200px; }
    body .up-arrow { display: none !important; }
}

/* ---------- Accesibilidad ---------- */
.ecc-launcher:focus-visible .ecc-fab,
.ecc-close:focus-visible,
.ecc-send:focus-visible,
.ecc-chip:focus-visible,
.ecc-cta:focus-visible {
    outline: 3px solid var(--ecc-yellow);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
    #ecc *, #ecc *::before, #ecc *::after {
        animation-duration: .001ms !important;
        transition-duration: .08s !important;
    }
    .ecc-fab::after { display: none; }
}

/* ============================================================
   Componentes estructurados que devuelve el backend
   (tarjeta de contacto, mapa, tasas, listas, aclaración, aviso).
   Mismo lenguaje visual que el resto del widget: fondo tenue,
   borde suave y tipografía menor que el cuerpo del mensaje.
   ============================================================ */
.ecc-card {
    margin-top: 10px; padding: 11px 12px;
    background: var(--ecc-tint);
    border: 1px solid var(--ecc-border);
    border-radius: 12px;
}
.ecc-card-title {
    font-size: 10.5px; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: var(--ecc-muted);
    margin-bottom: 7px;
}

/* Pares etiqueta / valor: dirección, teléfono, horario, tasas */
.ecc-kv { display: flex; gap: 8px; font-size: 13px; line-height: 1.45; margin: 3px 0; }
.ecc-kv-k { color: var(--ecc-muted); flex: 0 0 84px; }
.ecc-kv-v { color: var(--ecc-ink); font-weight: 600; word-break: break-word; }

/* Listas de pasos, documentos y recursos */
.ecc-list { margin: 2px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.55; }
.ecc-list li { margin: 3px 0; color: var(--ecc-body); }
.ecc-list a { color: var(--ecc-blue); font-weight: 600; text-decoration: none; }
.ecc-list a:hover { text-decoration: underline; }

/* Opciones de una pregunta de aclaración */
.ecc-options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }

/* Aviso: riesgo, urgencia o necesidad de acudir a la fuente oficial */
.ecc-warning {
    margin-top: 10px; padding: 11px 12px;
    background: #fff7ed; border: 1px solid #fed7aa; border-radius: 12px;
}
.ecc-warning-label {
    display: flex; align-items: center; gap: 5px;
    font-size: 10.5px; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: #b45309; margin-bottom: 5px;
}
.ecc-warning-label svg { width: 13px; height: 13px; flex-shrink: 0; }
.ecc-warning p { margin: 3px 0; font-size: 13px; line-height: 1.5; color: #7c2d12; }

/* Por qué se recomienda ese enlace (navegación explicable) */
.ecc-reason { margin-top: 5px; font-size: 11.5px; color: var(--ecc-muted); font-style: italic; }

/* Aviso de asistente informativo independiente */
.ecc-note {
    margin-top: 9px; padding-top: 9px;
    border-top: 1px dashed var(--ecc-border);
    font-size: 11px; line-height: 1.45; color: var(--ecc-muted);
}

/* Bloque de enlaces recomendados, con su título */
.ecc-links { margin-top: 11px; padding-top: 10px; border-top: 1px dashed var(--ecc-border); }
.ecc-links .ecc-card-title { margin-bottom: 8px; }
.ecc-links .ecc-cta-group { margin-top: 0; }

/* Más aire entre párrafos de la respuesta */
.ecc-bubble p { margin-bottom: 11px; }
.ecc-bubble p:last-child { margin-bottom: 0; }

/* Mensaje de invitación a seguir: más ligero que una respuesta normal */
.ecc-bubble--soft {
    background: var(--ecc-tint) !important;
    color: var(--ecc-muted) !important;
    font-size: 13px;
}

/* Mapa embebido dentro de la burbuja */
.ecc-map {
    display: block; width: 100%; height: 170px;
    border: 1px solid var(--ecc-border); border-radius: 10px;
    margin-bottom: 9px; background: #eef3fd;
}

/* Pasos pulsables: fila ancha, comoda en movil, con la flecha a la derecha */
.ecc-list--pasos { padding-left: 20px; }
.ecc-list--pasos li { margin: 6px 0; }
.ecc-step {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 12px; margin-left: -2px;
    background: var(--ecc-surface); border: 1px solid var(--ecc-border);
    border-radius: 10px;
    color: var(--ecc-ink) !important; font-weight: 600; font-size: 13.2px;
    text-decoration: none;
    transition: border-color .18s ease, background .18s ease, transform .15s ease;
}
.ecc-step:hover, .ecc-step:focus-visible {
    background: #eef3fd; border-color: var(--ecc-blue); transform: translateY(-1px);
}
.ecc-step svg { width: 14px; height: 14px; color: var(--ecc-blue); flex-shrink: 0; }

/* En móvil los botones ocupan la fila entera: objetivo de pulsación grande */
@media (max-width: 480px) {
    .ecc-cta-group { flex-direction: column; align-items: stretch; }
    .ecc-cta { justify-content: space-between; width: 100%; }
}

/* ---------- Fuentes: señal corta, detalle bajo demanda ---------- */
.ecc-source-toggle {
    background: none; border: 0; padding: 0 0 0 6px;
    color: var(--ecc-blue); font-size: 11.5px; font-weight: 600;
    cursor: pointer; font-family: inherit;
}
.ecc-source-toggle:hover { text-decoration: underline; }
.ecc-source-list {
    margin-top: 5px; padding-left: 18px;
    font-size: 11.5px; line-height: 1.5; color: var(--ecc-muted);
}

/* ---------- Ampliar (solo escritorio) ---------- */
.ecc-max {
    background: rgba(255,255,255,.14); border: 0; border-radius: 8px;
    width: 30px; height: 30px; padding: 6px; margin-left: auto;
    color: #fff; cursor: pointer; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .18s ease;
}
.ecc-max:hover { background: rgba(255,255,255,.26); }
.ecc-max svg { width: 100%; height: 100%; }
.ecc-max .ecc-max-out { display: none; }
#ecc.is-max .ecc-max .ecc-max-in { display: none; }
#ecc.is-max .ecc-max .ecc-max-out { display: block; }
/* La cabecera ya usa `gap`; el margen automático del botón empuja el de cerrar */
.ecc-header .ecc-close { margin-left: 0; }

#ecc.is-max .ecc-panel {
    width: min(900px, calc(100vw - 48px));
    height: min(860px, calc(100vh - 48px));
}
/* Con más ancho, las burbujas pueden respirar sin volverse ilegibles */
#ecc.is-max .ecc-bubble { max-width: 72%; }
#ecc.is-max .ecc-map { height: 240px; }

@media (max-width: 700px) {
    /* Abajo el panel ya es la pantalla entera: ampliar no significa nada */
    .ecc-max { display: none; }
    #ecc.is-max .ecc-panel { width: 100%; height: 100dvh; }
}
