/*
    The website assistant.

    Uses the site's own tokens from site.css rather than defining a palette of its own, so the widget
    reads as part of the product and not as a third-party chat bubble bolted on.

    Everything is scoped under .chat- and the panel is inert until opened, so nothing here can affect
    a page that never opens it.
*/

/* ---------------------------------------------------------------- launcher */

.chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 60;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--brand-gradient);
    color: #fff;
    box-shadow: 0 14px 30px -10px rgba(109, 40, 217, .65);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}

.chat-launcher:hover {
    transform: translateY(-3px);
    box-shadow: 0 20px 38px -12px rgba(109, 40, 217, .7);
}

.chat-launcher .icon--close { display: none; }
.chat-launcher[aria-expanded="true"] .icon--open { display: none; }
.chat-launcher[aria-expanded="true"] .icon--close { display: block; }

/* ---------------------------------------------------------------- panel */

.chat-panel {
    position: fixed;
    right: 24px;
    bottom: 92px;
    z-index: 61;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 132px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 30px 70px -24px rgba(36, 16, 51, .45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.chat-head {
    background: var(--brand-gradient);
    color: #fff;
    padding: 18px 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex: none;
}

.chat-head-title {
    font-family: var(--display);
    font-weight: 800;
    font-size: 16px;
    letter-spacing: -.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-head-sub {
    font-size: 12px;
    color: rgba(255, 255, 255, .8);
    margin-top: 3px;
}

.chat-close {
    border: 0;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: none;
    transition: background .3s ease;
}

.chat-close:hover { background: rgba(255, 255, 255, .28); }

.chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    background: var(--page);
}

/* ---------------------------------------------------------------- the details form */

.chat-intro {
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--ink-72);
    margin-bottom: 16px;
}

.chat-field { margin-bottom: 12px; }

.chat-field label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 5px;
}

.chat-field input[type="text"],
.chat-field input[type="tel"],
.chat-field input[type="email"] {
    width: 100%;
    font-family: var(--body);
    font-size: 14px;
    padding: 10px 12px;
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
}

.chat-field input:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
    border-color: transparent;
}

.chat-consent {
    display: flex;
    gap: 9px;
    align-items: flex-start;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--ink-70);
    margin: 14px 0 6px;
}

.chat-consent input { margin-top: 2px; flex: none; }

.chat-privacy {
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--ink-62);
    margin-bottom: 14px;
}

.chat-error {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: var(--bad-bg);
    color: var(--bad-fg);
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 12.5px;
    line-height: 1.45;
    margin-bottom: 12px;
}

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

.chat-submit {
    width: 100%;
    justify-content: center;
    border: 0;
    cursor: pointer;
}

.chat-submit[disabled] { opacity: .6; cursor: progress; }

/* ---------------------------------------------------------------- messages */

.chat-thread { display: flex; flex-direction: column; gap: 14px; }

.chat-msg { display: flex; max-width: 100%; }
.chat-msg.is-user { justify-content: flex-end; }

.chat-bubble {
    max-width: 84%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-msg.is-agent .chat-bubble {
    background: var(--surface);
    border: 1px solid var(--line-soft);
    color: var(--ink);
    border-bottom-left-radius: 5px;
}

.chat-msg.is-user .chat-bubble {
    background: var(--brand);
    color: #fff;
    border-bottom-right-radius: 5px;
}

/* Three dots while the first token is awaited. On CPU inference that wait can be twenty seconds,
   which is precisely why something has to be moving. */
.chat-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 13px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--c-faint);
    animation: chat-bounce 1.3s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .18s; }
.chat-typing span:nth-child(3) { animation-delay: .36s; }

@keyframes chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 4px;
}

.chat-chip {
    font-family: var(--body);
    font-size: 12px;
    font-weight: 600;
    padding: 7px 11px;
    border-radius: 999px;
    border: 1px solid var(--tint-line);
    background: var(--tint);
    color: var(--brand);
    cursor: pointer;
    transition: background .25s ease;
}

.chat-chip:hover { background: #EBDDFD; }

/* ---------------------------------------------------------------- composer */

.chat-foot {
    flex: none;
    border-top: 1px solid var(--line-soft);
    background: var(--surface);
    padding: 12px 14px;
}

.chat-composer { display: flex; gap: 8px; align-items: flex-end; }

.chat-composer textarea {
    flex: 1;
    font-family: var(--body);
    font-size: 13.5px;
    line-height: 1.5;
    padding: 9px 12px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    resize: none;
    max-height: 110px;
    color: var(--ink);
}

.chat-composer textarea:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
    border-color: transparent;
}

.chat-send {
    border: 0;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 11px;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .3s ease;
}

.chat-send:hover { background: var(--brand-dark); }
.chat-send[disabled] { background: var(--c-faint); cursor: not-allowed; }

.chat-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 9px;
}

.chat-human {
    font-family: var(--body);
    font-size: 12px;
    font-weight: 600;
    color: var(--brand);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chat-human:hover { text-decoration: underline; }

/* Says plainly that answers come from a model. A visitor is entitled to know, and it sets the
   expectation that this is not a person typing. */
.chat-disclaimer {
    font-size: 10.5px;
    color: var(--ink-58);
    text-align: right;
    line-height: 1.4;
}

/* ---------------------------------------------------------------- narrow screens */

@media (max-width: 720px) {
    /* Pinned to all four edges rather than sized with 100vw. 100vw includes the scrollbar's width,
       so on a narrow desktop window the panel ended up about fifteen pixels wider than the visible
       area and sat partly underneath it. left/right resolve against the viewport without it. */
    .chat-panel {
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: 0;
        border: 0;
    }

    .chat-launcher { right: 16px; bottom: 16px; }
    .chat-launcher[aria-expanded="true"] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-typing span { animation: none; opacity: .6; }
}
