.kp-chat {
    position: fixed;
    z-index: 1000; /* encima del encabezado de Storefront (999), que tapaba «Cerrar» */
    bottom: 1rem;
    right: max(1rem, env(safe-area-inset-right));
    color: #252b3f;
    font-size: .9375rem;
    line-height: 1.5;
}

.kp-chat [hidden] {
    display: none !important;
}

.kp-chat button {
    padding: .55rem .75rem;
    border: 1px solid #1d2343;
    border-radius: 8px;
    background: #1d2343;
    color: #fff;
    font: inherit;
    font-weight: 700;
}

.kp-chat .kp-chat-lanzador {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
}

.kp-chat-lanzador::before {
    content: "";
    width: 26px;
    height: 26px;
    background: currentColor;
    clip-path: polygon(4% 6%, 96% 6%, 96% 74%, 43% 74%, 15% 98%, 15% 74%, 4% 74%);
}

body:has(.kp-chat) {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
}

body:has(.kp-dialogo[open], .main-navigation.toggled) .kp-chat {
    display: none;
}

.kp-chat button:disabled {
    opacity: .65;
}

.kp-chat-panel {
    position: absolute;
    bottom: calc(100% + .5rem);
    right: 0;
    width: min(24rem, calc(100vw - 2rem));
    overflow: hidden;
    border: 1px solid #c9cbcd;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 10px 35px rgb(29 35 67 / 18%);
}

.kp-chat-cabecera, .kp-chat-formulario, .kp-chat-mensajes {
    padding: .75rem;
}

.kp-chat-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    border-bottom: 1px solid #c9cbcd;
}

.kp-chat-cabecera h2 {
    margin: 0;
    font-size: 1rem;
}

.kp-chat .kp-chat-cerrar {
    background: #fff;
    color: #1d2343;
}

.kp-chat-mensajes {
    max-height: min(40vh, 19rem);
    overflow-y: auto;
    overflow-wrap: anywhere;
}

.kp-chat-mensajes p {
    margin: 0 0 .625rem;
    white-space: pre-wrap;
}

.kp-chat-mensajes a {
    text-decoration: underline;
}

.kp-chat-visitante {
    padding: .5rem;
    border-radius: 6px;
    background: #edf1f6;
}

.kp-chat-formulario {
    display: grid;
    justify-items: start;
    gap: .4rem;
    border-top: 1px solid #c9cbcd;
}

.kp-chat-formulario textarea {
    width: 100%;
    font-size: 16px; /* con menos, Safari de iPhone acerca la página */
    min-height: 3rem;
    margin: 0;
    padding: .4rem;
    border: 1px solid #c9cbcd;
    border-radius: 6px;
    background: #fff;
}

@media (max-width: 767px) {
    .kp-chat {
        z-index: 10000;
        bottom: calc(.5rem + env(safe-area-inset-bottom));
    }

    body:has(.kp-chat) .storefront-handheld-footer-bar {
        box-sizing: border-box;
        padding: .25rem 5rem calc(.25rem + env(safe-area-inset-bottom)) 0;
        min-height: calc(72px + env(safe-area-inset-bottom));
        background: white;
    }
}

@media (max-height: 500px) {
    .kp-chat-mensajes {
        max-height: 25vh;
    }
}
