/* David Bot — widget de chat flotante.
 *
 * Todo se escribe contra #david-bot en vez de .david-bot a propósito: el widget
 * se inyecta en temas ajenos (Divi, Astra, Elementor…) que estilan `button` e
 * `input` de forma agresiva. Con el ID subimos la especificidad a 1,x,x y
 * ganamos sin tener que llenar el archivo de !important. Los pocos !important
 * que quedan son geometría que NO puede negociarse (el lanzador tiene que ser
 * un círculo) frente a temas que sí usan !important.
 */

/* El color lo sobrescribe el plugin en línea, también sobre :root, para que lo
   vean tanto el widget como el panel de colocación (que es hermano, no hijo). */
:root { --db-color: #2563eb; }

#david-bot {
    position: fixed;
    bottom: 20px;
    z-index: 99999;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    letter-spacing: normal;
    text-align: left;
    color: #16161d;
    -webkit-font-smoothing: antialiased;
}

#david-bot.david-bot--derecha   { right: 20px; }
#david-bot.david-bot--izquierda { left: 20px; }

#david-bot *,
#david-bot *::before,
#david-bot *::after { box-sizing: border-box; }

/* ─── Reset defensivo ──────────────────────────────────────────────────────
   Neutraliza lo que el tema le hace a botones y campos antes de que apliquen
   nuestras reglas de componente (que llevan más especificidad y van después). */

#david-bot button,
#david-bot input {
    display: block;
    width: auto;
    min-width: 0;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    font: inherit;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    text-shadow: none;
    color: inherit;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}

#david-bot button::before,
#david-bot button::after { content: none; }

#david-bot button { cursor: pointer; }

/* Sin esto el tema puede dejar un hueco bajo cada icono por la línea base. */
#david-bot svg {
    display: block;
    flex: 0 0 auto;
}

/* ─── Lanzador ─────────────────────────────────────────────────────────── */

#david-bot .david-bot__lanzador {
    position: relative;
    display: grid !important;
    place-items: center;
    width: 58px !important;
    height: 58px !important;
    padding: 0 !important;
    color: #fff;
    background: var(--db-color) !important;
    border-radius: 50% !important;
    box-shadow: 0 4px 14px rgba(16, 16, 40, .22);
    transition: transform .18s ease, box-shadow .18s ease;
}

#david-bot .david-bot__lanzador:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(16, 16, 40, .28);
}

#david-bot .david-bot__lanzador:focus-visible {
    outline: 3px solid var(--db-color);
    outline-offset: 3px;
}

#david-bot .david-bot__icono {
    grid-area: 1 / 1;
    transition: opacity .16s ease, transform .16s ease;
}

#david-bot .david-bot__icono--cerrar { opacity: 0; transform: rotate(-45deg); }

#david-bot.is-abierto .david-bot__icono--chat   { opacity: 0; transform: rotate(45deg); }
#david-bot.is-abierto .david-bot__icono--cerrar { opacity: 1; transform: none; }

/* ─── Panel ────────────────────────────────────────────────────────────── */

#david-bot .david-bot__panel {
    display: flex;
    flex-direction: column;
    width: 370px;
    height: 520px;
    max-height: calc(100dvh - 120px);
    margin: 0 0 14px;
    overflow: hidden;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 6px rgba(16, 16, 40, .08), 0 16px 44px rgba(16, 16, 40, .18);
    animation: david-bot-entra .2s ease both;
}

#david-bot .david-bot__panel[hidden] { display: none; }

@keyframes david-bot-entra {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

/* ─── Cabecera ─────────────────────────────────────────────────────────── */

#david-bot .david-bot__cabecera {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    padding: 13px 13px 13px 16px;
    color: #fff;
    background: var(--db-color);
}

#david-bot .david-bot__avatar {
    display: grid;
    place-items: center;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
    background: rgba(255, 255, 255, .22);
    border-radius: 50%;
}

#david-bot .david-bot__identidad {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
}

#david-bot .david-bot__nombre {
    font-size: 15px;
    font-weight: 650;
    line-height: 1.25;
    color: #fff;
}

#david-bot .david-bot__estado {
    font-size: 12.5px;
    line-height: 1.3;
    color: rgba(255, 255, 255, .82);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#david-bot .david-bot__cerrar {
    display: grid !important;
    place-items: center;
    flex: 0 0 32px;
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    color: #fff;
    border-radius: 50% !important;
    opacity: .8;
    transition: opacity .14s ease, background .14s ease;
}

#david-bot .david-bot__cerrar:hover {
    opacity: 1;
    background: rgba(255, 255, 255, .18);
}

#david-bot .david-bot__cerrar:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

/* ─── Mensajes ─────────────────────────────────────────────────────────── */

#david-bot .david-bot__mensajes {
    flex: 1 1 auto;
    padding: 18px 16px;
    overflow-y: auto;
    background: #f6f7fb;
    overscroll-behavior: contain;
}

#david-bot .david-bot__mensaje {
    display: block;
    width: fit-content;
    max-width: 80%;
    margin: 0 0 10px;
    padding: 10px 13px;
    font-size: 14.5px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    border-radius: 15px;
    animation: david-bot-mensaje .18s ease both;
}

#david-bot .david-bot__mensaje:last-child { margin-bottom: 0; }

@keyframes david-bot-mensaje {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: none; }
}

#david-bot .david-bot__mensaje--bot {
    color: #16161d;
    background: #fff;
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(16, 16, 40, .07);
}

#david-bot .david-bot__mensaje--yo {
    margin-left: auto;
    color: #fff;
    background: var(--db-color);
    border-bottom-right-radius: 5px;
}

/* Indicador de "escribiendo" */

#david-bot .david-bot__escribiendo {
    display: flex;
    gap: 4px;
    align-items: center;
    width: max-content;
    padding: 14px 13px;
}

#david-bot .david-bot__punto {
    display: block;
    width: 7px;
    height: 7px;
    background: #9a9aae;
    border-radius: 50%;
    animation: david-bot-punto 1.1s infinite ease-in-out;
}

#david-bot .david-bot__punto:nth-child(2) { animation-delay: .16s; }
#david-bot .david-bot__punto:nth-child(3) { animation-delay: .32s; }

@keyframes david-bot-punto {
    0%, 60%, 100% { opacity: .35; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ─── Formulario ───────────────────────────────────────────────────────── */

#david-bot .david-bot__form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    margin: 0;
    padding: 11px 12px;
    background: #fff;
    border-top: 1px solid #e8e8f0;
}

#david-bot .david-bot__texto {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 40px !important;
    padding: 0 15px !important;
    font-size: 14.5px;
    line-height: 40px;
    color: #16161d;
    background: #f2f2f7;
    border: 1.5px solid transparent !important;
    border-radius: 20px !important;
}

#david-bot .david-bot__texto::placeholder { color: #8a8a9c; opacity: 1; }

#david-bot .david-bot__texto:focus {
    outline: none;
    background: #fff;
    border-color: var(--db-color) !important;
}

#david-bot .david-bot__enviar {
    display: grid !important;
    place-items: center;
    flex: 0 0 40px;
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    color: #fff;
    background: var(--db-color) !important;
    border-radius: 50% !important;
    transition: filter .14s ease, opacity .14s ease;
}

#david-bot .david-bot__enviar:hover:not(:disabled) { filter: brightness(1.08); }
#david-bot .david-bot__enviar:focus-visible { outline: 2px solid var(--db-color); outline-offset: 2px; }
#david-bot .david-bot__enviar:disabled { opacity: .45; cursor: default; }

/* El icono de avión va ópticamente centrado, no geométricamente. */
#david-bot .david-bot__enviar svg { margin-left: -1px; }

/* Etiqueta solo para lectores de pantalla (por si el tema no la define). */
#david-bot .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ─── Móvil: el panel ocupa la pantalla ────────────────────────────────── */
/* La posición del lanzador la fija el plugin en línea, acotada con min() para
   que no se salga en pantallas pequeñas. */

@media (max-width: 480px) {
    #david-bot .david-bot__panel {
        position: fixed;
        inset: 0;
        width: auto;
        height: auto;
        max-height: none;
        margin: 0;
        border-radius: 0;
    }

    #david-bot.is-abierto .david-bot__lanzador { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    #david-bot .david-bot__panel,
    #david-bot .david-bot__mensaje { animation: none; }

    #david-bot .david-bot__lanzador,
    #david-bot .david-bot__icono { transition: none; }

    #david-bot .david-bot__punto { animation-duration: 0s; opacity: .6; }
}
