/* Website chat (WK6): bubble and panel on the pages of the new website. Colours follow the
   website's tokens where they exist, with fallbacks for any other page. */
.kesa-chat {
    --kesa-accent: var(--yellow, #ffc107);
    --kesa-accent-hover: var(--yellow-hover, #ffd24d);
    --kesa-ink: var(--ink, #1b1733);
    --kesa-muted: var(--ink-faint, #6f6b85);
    --kesa-line: var(--line, #e8e6f0);
    --kesa-tint: var(--tint, #f6f5fa);
    --kesa-paper: var(--paper, #fff);
    --kesa-navy: var(--navy, #211350);
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    font-family: var(--font-body, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif);
    font-size: 15px;
    line-height: 1.5;
    color: var(--kesa-ink);
}

.kesa-chat *,
.kesa-chat *::before,
.kesa-chat *::after {
    box-sizing: border-box;
}

.kesa-chat-bubble {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-left: auto;
    border: 0;
    border-radius: 999px;
    background: var(--kesa-accent);
    color: var(--kesa-navy);
    box-shadow: 0 1px 2px rgb(22 19 37 / 10%), 0 8px 24px rgb(22 19 37 / 18%);
    cursor: pointer;
}

.kesa-chat-bubble:hover {
    background: var(--kesa-accent-hover);
}

.kesa-chat-bubble {
    position: relative;
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.kesa-chat-bubble:hover {
    transform: scale(1.05);
}

.kesa-chat-bubble:active {
    transform: scale(0.95);
}

/* Speech bubble while closed, chevron while open; the two turn into each other. */
.kesa-chat-bubble-chat,
.kesa-chat-bubble-close {
    display: grid;
    grid-area: 1 / 1;
    place-items: center;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease;
}

.kesa-chat-bubble-close,
.kesa-chat-bubble[aria-expanded='true'] .kesa-chat-bubble-chat {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.kesa-chat-bubble[aria-expanded='true'] .kesa-chat-bubble-close {
    opacity: 1;
    transform: none;
}

.kesa-chat-bubble:focus-visible,
.kesa-chat button:focus-visible,
.kesa-chat textarea:focus-visible,
.kesa-chat a:focus-visible {
    outline: 2px solid var(--kesa-navy);
    outline-offset: 2px;
}

.kesa-chat-panel {
    display: flex;
    flex-direction: column;
    /* Chatbase's size (WU2): more of a long answer fits without scrolling. */
    width: min(400px, calc(100vw - 32px));
    height: min(760px, 85vh, calc(100vh - 100px));
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid var(--kesa-line);
    border-radius: 20px;
    background: var(--kesa-paper);
    box-shadow:
        0 1px 2px rgb(22 19 37 / 6%),
        0 10px 23px rgb(22 19 37 / 8%),
        0 42px 42px rgb(22 19 37 / 6%);
}

.kesa-chat-panel[hidden] {
    display: none;
}

/* Opens out of the bubble and shrinks back into it. */
.kesa-chat-panel {
    transform-origin: bottom right;
    animation: kesa-chat-open 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.kesa-chat-panel.kesa-chat-closing {
    animation: kesa-chat-close 0.15s ease-in forwards;
}

@keyframes kesa-chat-open {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
}

@keyframes kesa-chat-close {
    to {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
}

.kesa-chat-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px 12px 16px;
    border-bottom: 1px solid var(--kesa-line);
}

.kesa-chat-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 999px;
    background: var(--kesa-tint);
    color: var(--kesa-navy);
}

.kesa-chat-heading {
    flex: 1;
    min-width: 0;
}

.kesa-chat-title,
.kesa-chat-subtitle {
    margin: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.kesa-chat-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}

.kesa-chat-subtitle {
    color: var(--kesa-muted);
    font-size: 12px;
    line-height: 1.3;
}

/* Greeting bubble above the button (WU4). */
.kesa-chat-nudge {
    position: absolute;
    right: 0;
    bottom: 68px;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    width: max-content;
    max-width: min(270px, calc(100vw - 32px));
    padding: 4px 4px 4px 0;
    border: 1px solid var(--kesa-line);
    border-radius: 14px 14px 4px;
    background: var(--kesa-paper);
    box-shadow: 0 8px 24px rgb(22 19 37 / 14%);
    transform-origin: bottom right;
    animation: kesa-chat-pop 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.kesa-chat-nudge-text {
    padding: 8px 4px 8px 14px;
    border: 0;
    background: transparent;
    color: var(--kesa-ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.kesa-chat-nudge-close {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: none;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--kesa-muted);
    cursor: pointer;
}

.kesa-chat-nudge-close:hover {
    background: var(--kesa-tint);
    color: var(--kesa-ink);
}

@keyframes kesa-chat-pop {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.92);
    }
}

.kesa-chat-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--kesa-muted);
    cursor: pointer;
}

.kesa-chat-icon:hover {
    background: var(--kesa-tint);
    color: var(--kesa-ink);
}

.kesa-chat-body {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
}

.kesa-chat-log {
    position: relative;
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.kesa-chat-spacer {
    margin: 0;
}

/* New messages, cards and suggestions slide in from below. */
.kesa-chat-msg,
.kesa-chat-guide,
.kesa-chat-meta,
.kesa-chat-suggestion {
    animation: kesa-chat-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.kesa-chat-msg-user {
    transform-origin: bottom right;
    animation-name: kesa-chat-in-user;
}

.kesa-chat-guide {
    animation-delay: 0.08s;
}

.kesa-chat-meta {
    animation-delay: 0.16s;
}

.kesa-chat-suggestion:nth-child(1) {
    animation-delay: 0.1s;
}

.kesa-chat-suggestion:nth-child(2) {
    animation-delay: 0.18s;
}

.kesa-chat-suggestion:nth-child(3) {
    animation-delay: 0.26s;
}

.kesa-chat-log-quiet * {
    animation: none !important;
}

@keyframes kesa-chat-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

@keyframes kesa-chat-in-user {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
}

/* While the answer is written, every new word fades in. */
.kesa-chat-word {
    animation: kesa-chat-word 0.3s ease-out both;
}

@keyframes kesa-chat-word {
    from {
        opacity: 0;
    }
}

.kesa-chat-jump {
    position: absolute;
    right: 16px;
    bottom: 12px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--kesa-line);
    border-radius: 999px;
    background: var(--kesa-paper);
    color: var(--kesa-navy);
    box-shadow: 0 4px 12px rgb(22 19 37 / 14%);
    cursor: pointer;
    animation: kesa-chat-in 0.2s ease-out both;
}

.kesa-chat-jump[hidden] {
    display: none;
}

.kesa-chat-jump:hover {
    background: var(--kesa-tint);
}

.kesa-chat-msg {
    max-width: 88%;
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 14px;
    overflow-wrap: anywhere;
}

.kesa-chat-msg p {
    margin: 0 0 8px;
}

.kesa-chat-msg p:last-child,
.kesa-chat-msg :is(ul, ol):last-child {
    margin-bottom: 0;
}

.kesa-chat-msg :is(ul, ol) {
    margin: 0 0 8px;
    padding-left: 20px;
}

/* Website themes reset list markers; the answers need them. */
.kesa-chat-msg ul {
    list-style: disc;
}

.kesa-chat-msg ol {
    list-style: decimal;
}

.kesa-chat-msg li {
    margin: 0 0 4px;
    padding: 0;
}

.kesa-chat-msg li::marker {
    color: var(--kesa-muted);
}

.kesa-chat-msg a {
    color: var(--kesa-navy);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.kesa-chat-msg a:hover {
    text-decoration-thickness: 2px;
}

.kesa-chat-msg-bot {
    background: var(--kesa-tint);
    border-bottom-left-radius: 4px;
}

.kesa-chat-msg-user {
    margin-left: auto;
    background: var(--kesa-navy);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.kesa-chat-msg-error {
    background: #fdecea;
    color: #8e1b1b;
}

.kesa-chat-typing {
    display: inline-flex;
    gap: 4px;
    padding: 6px 0;
}

.kesa-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--kesa-muted);
    animation: kesa-chat-dot 1s infinite ease-in-out;
}

.kesa-chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.kesa-chat-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes kesa-chat-dot {
    0%,
    80%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .kesa-chat *,
    .kesa-chat *::before,
    .kesa-chat *::after,
    .kesa-chat-panel {
        animation: none !important;
        transition: none !important;
    }
}

.kesa-chat-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: -6px 0 12px;
    color: var(--kesa-muted);
    font-size: 13px;
}

.kesa-chat-meta a {
    color: var(--kesa-navy);
}

.kesa-chat-rate {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--kesa-muted);
    cursor: pointer;
}

.kesa-chat-rate:hover {
    background: var(--kesa-tint);
}

.kesa-chat-rate[aria-pressed='true'] {
    color: var(--kesa-navy);
    background: var(--kesa-tint);
}

.kesa-chat-handover {
    margin-left: 4px;
}

.kesa-chat-transfer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 0 12px;
    padding: 12px;
    border-radius: 12px;
    background: var(--kesa-tint);
}

.kesa-chat-transfer-hint,
.kesa-chat-transfer-result {
    margin: 0;
    font-size: 14px;
}

.kesa-chat-transfer-result {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--kesa-tint);
}

.kesa-chat-transfer-note {
    margin: 0;
    font-size: 14px;
    color: #b32d2e;
}

.kesa-chat-transfer-note:empty {
    display: none;
}

.kesa-chat-transfer-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
}

.kesa-chat-transfer-field {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--kesa-line);
    border-radius: 12px;
    background: var(--kesa-paper);
    font: inherit;
    /* Below 16 px an iPhone zooms into the page when the field gets focus. */
    font-size: 16px;
    color: inherit;
}

.kesa-chat-transfer-send {
    align-self: flex-start;
    padding: 8px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--kesa-accent);
    color: var(--kesa-navy);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.kesa-chat-transfer-send:hover {
    background: var(--kesa-accent-hover);
}

.kesa-chat-transfer-send:disabled {
    opacity: 0.6;
    cursor: default;
}

.kesa-chat-suggestions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin: 4px 0 12px;
}

.kesa-chat-suggestion {
    padding: 6px 12px;
    border: 1px solid var(--kesa-line);
    border-radius: 999px;
    background: var(--kesa-paper);
    color: var(--kesa-ink);
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.kesa-chat-suggestion {
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.kesa-chat-suggestion:hover {
    border-color: var(--kesa-navy);
    background: var(--kesa-tint);
}

.kesa-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--kesa-line);
}

.kesa-chat-input {
    flex: 1;
    min-width: 0;
    max-height: 120px;
    padding: 8px 12px;
    border: 1px solid var(--kesa-line);
    border-radius: 12px;
    font: inherit;
    /* Below 16 px an iPhone zooms into the page when the field gets focus. */
    font-size: 16px;
    color: inherit;
    resize: none;
}

.kesa-chat-send {
    transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border: 0;
    border-radius: 12px;
    background: var(--kesa-accent);
    color: var(--kesa-navy);
    cursor: pointer;
}

.kesa-chat-send:hover {
    background: var(--kesa-accent-hover);
}

.kesa-chat-send:active:not(:disabled) {
    transform: scale(0.92);
}

.kesa-chat-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.kesa-chat-foot {
    margin: 0;
    padding: 0 12px 10px;
    color: var(--kesa-muted);
    font-size: 12px;
    line-height: 1.4;
}

.kesa-chat-foot a {
    color: inherit;
}

@media (max-width: 480px) {
    .kesa-chat {
        right: 16px;
        bottom: 16px;
    }

    /* On a phone the open chat fills the screen, like Chatbase (WU1); ✕ in the head closes it. */
    .kesa-chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        transform-origin: bottom center;
    }

    .kesa-chat-open .kesa-chat-bubble {
        display: none;
    }

    .kesa-chat-foot {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

.kesa-chat-guide {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 88%;
    margin: -4px 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--kesa-line);
    border-radius: 12px;
    background: var(--kesa-paper);
    color: var(--kesa-ink);
    text-decoration: none;
}

.kesa-chat-guide {
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.kesa-chat-guide > svg:last-child {
    transition: transform 0.15s ease;
}

.kesa-chat-guide:hover > svg:last-child {
    transform: translateX(3px);
}

.kesa-chat-guide:hover {
    border-color: var(--kesa-navy);
    background: var(--kesa-tint);
}

.kesa-chat-guide > svg {
    flex: none;
    color: var(--kesa-navy);
}

.kesa-chat-guide-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.kesa-chat-guide-label {
    color: var(--kesa-muted);
    font-size: 12px;
}

.kesa-chat-guide-title {
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The product page's buy bar sticks to the bottom up to 860 px with a full-width button. */
@media (max-width: 860px) {
    body:has(.product__buy) .kesa-chat:not(.kesa-chat-open) {
        bottom: 92px;
    }
}
