#chat-window {
    --radius-control: 8px;

    position: fixed;
    right: 24px;
    bottom: 104px;
    z-index: 999998;

    /* 590 y no 500: con la leyenda de IA bajo el campo, el contenido de la
       bienvenida mide ~570 px y a 500 se recortaban el avatar y la última
       sugerencia. El max-height evita que se salga en pantallas bajas. */
    width: 360px;
    height: 590px;
    max-height: calc(100vh - 140px);

    color: #1f2937;
    background-color: white;

    border: 1px solid #e5e7eb;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);

    overflow: hidden;

    transition:
        width 0.2s ease,
        height 0.2s ease;
}

#chat-window[data-state="conversation"] {
    width: 420px;
    height: 640px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 140px);
}

#chat-window-content {
    padding: 16px;
}

/* Header: en desktop solo aparece ya en la conversación, con el botón de
   nueva conversación (cerrar lo hace la burbuja); en móvil siempre, con
   los dos (ver media query de abajo). */
#chat-window-header {
    display: none;
}

#chat-window[data-state="conversation"] #chat-window-header {
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 8px 12px 8px 16px;

    border-bottom: 1px solid #e5e7eb;
}

#chat-window-heading {
    display: flex;
    flex-direction: column;
    gap: 1px;

    min-width: 0;
}

#chat-window-title {
    color: #1f2937;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}

#chat-window-subtitle {
    color: #6b7280;
    font-size: 12px;
    line-height: 1.3;
}

#chat-window-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#chat-new-button,
#chat-end-button,
#chat-close-button {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 32px;
    height: 32px;
    padding: 0;

    color: #1f2937;

    background: none;
    border: none;
    border-radius: 50%;

    cursor: pointer;
}

/* Solo con mouse: en táctil el hover se queda pegado tras tocar. */
@media (hover: hover) {
    #chat-new-button:hover,
    #chat-end-button:hover,
    #chat-close-button:hover {
        background-color: #f3f4f6;
    }
}

#chat-new-button:focus-visible,
#chat-end-button:focus-visible,
#chat-close-button:focus-visible {
    outline: 2px solid rgba(215, 25, 32, 0.45);
    outline-offset: 1px;
}

/* En desktop la burbuja ya hace de botón de cerrar. */
#chat-close-button {
    display: none;
}

/* En la bienvenida no hay nada que reiniciar. */
#chat-window:not([data-state="conversation"]) #chat-new-button,
#chat-window:not([data-state="conversation"]) #chat-end-button {
    display: none;
}

/* En móvil la ventana cubre toda la pantalla — ni el tamaño de "welcome"
   ni el de "conversation" caben cómodamente en un viewport chico, así que
   ambos estados colapsan al mismo layout fullscreen. */
@media (max-width: 600px) {
    #chat-window,
    #chat-window[data-state="conversation"] {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;

        display: flex;
        flex-direction: column;

        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        max-height: none;

        border: none;
        border-radius: 0;
    }

    /* La burbuja flotante (fixed, siempre visible) queda tapando el botón
       de enviar del input cuando la ventana ocupa toda la pantalla — en
       su lugar, cerrar se hace desde el header. */
    #chat-window-header,
    #chat-window[data-state="conversation"] #chat-window-header {
        flex-shrink: 0;

        display: flex;
        align-items: center;
        justify-content: space-between;

        padding: 14px 16px;

        border-bottom: 1px solid #e5e7eb;
    }

    #chat-close-button {
        display: flex;
    }

    #chat-window-content {
        flex: 1;
        min-height: 0;

        display: flex;
        flex-direction: column;
    }

    #chat-bubble[aria-expanded="true"] {
        display: none;
    }
}