/*
 * The website assistant, pinned to the bottom right.
 *
 * z-index sits below the portal rail (200) on purpose. On a narrow screen the
 * rail opens as an overlay with a full-viewport backdrop, and the assistant
 * should go under that backdrop with everything else rather than floating on
 * top of a dimmed page looking like it escaped.
 *
 * Fixed positioning puts it in the bottom right of the viewport rather than the
 * page, so it stays put while reading. The left edge is left free: the nav
 * toggle lives in the opposite corner.
 */

/*
 * hidden has to win, and by default it does not.
 *
 * The attribute only hides anything because a stylesheet somewhere says
 * [hidden] { display: none }. Both rules below set display, at the same
 * specificity, and load after normalize, so without this they quietly beat it.
 * The visible symptoms were the panel rendering open on page load and the close
 * button appearing to do nothing, because the script was setting .hidden
 * correctly and the CSS was overruling it.
 *
 * The attribute selector raises specificity above the plain class rules, so
 * these win wherever they are declared.
 */
.assistant[hidden],
.assistant__panel[hidden],
.assistant__badge[hidden],
.assistant__badge-text[hidden] {
    display: none;
}

.assistant {
    position: fixed;
    right: clamp(1.2rem, 2vw, 2.4rem);
    bottom: clamp(1.2rem, 2vw, 2.4rem);
    z-index: 150;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1.2rem;
    font-family: inherit;
}

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

/*
 * Unread dot, top right of the launcher.
 *
 * Only appears when an answer arrives while the panel is closed, which happens
 * if somebody asks and then shuts the panel before the reply lands.
 *
 * The white ring keeps it visible against the navy pill and against whatever
 * the page behind it happens to be, since the launcher overhangs the corner.
 */
.assistant__badge {
    position: absolute;
    top: -0.2rem;
    right: -0.2rem;
    width: 1.4rem;
    height: 1.4rem;
    border: 2px solid #ffffff;
    border-radius: 50%;
    /* #d7263d on white is 5.9:1, so it still reads as a distinct mark for
       anyone who sees red and grey similarly. The text span beside it is what
       actually carries the meaning. */
    background: #d7263d;
}

/* Visible to a screen reader only. Inside the button, so it becomes part of
   the button's accessible name without needing an aria-label. */
.assistant__badge-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.assistant__launcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    height: auto;
    padding: 1.2rem 1.8rem;
    border: none;
    border-radius: 999px;
    background: var(--color-brand-navy, #12466f);
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(6, 28, 44, 0.28);
}

.assistant__launcher:hover,
.assistant__launcher:focus {
    background: var(--color-brand-navy-mid, #1b5e96);
    color: #ffffff;
}

.assistant__launcher:focus-visible {
    outline: 3px solid #f2c230;
    outline-offset: 2px;
}

.assistant__launcher-icon {
    width: 2rem;
    height: 2rem;
    flex: none;
}

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

.assistant__panel {
    display: flex;
    flex-direction: column;
    /* min() so the panel never sets a width a phone cannot honour. The 2.4rem
       allows for the gap this sits in on each side. */
    width: min(38rem, calc(100vw - 2.4rem));
    max-height: min(52rem, calc(100vh - 12rem));
    border: 1px solid rgba(18, 70, 111, 0.16);
    border-radius: 1.2rem;
    background: #ffffff;
    box-shadow: 0 18px 48px rgba(6, 28, 44, 0.26);
    overflow: hidden;
}

.assistant__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.4rem 1.6rem;
    background: var(--color-brand-navy, #12466f);
    color: #ffffff;
}

.assistant__heading {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: #ffffff;
}

.assistant__close {
    width: 3.2rem;
    height: 3.2rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #ffffff;
    font-size: 2.4rem;
    line-height: 1;
    cursor: pointer;
}

.assistant__close:hover,
.assistant__close:focus {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

.assistant__close:focus-visible {
    outline: 2px solid #f2c230;
    outline-offset: 1px;
}

/* ---------- conversation ---------- */

.assistant__log {
    flex: 1 1 auto;
    min-height: 12rem;
    padding: 1.6rem;
    overflow-y: auto;
    background: #f7fafc;
}

.assistant__message {
    max-width: 85%;
    margin: 0 0 1.2rem;
    padding: 1rem 1.3rem;
    border-radius: 1rem;
    font-size: 1.45rem;
    line-height: 1.5;
    /* Long words and pasted URLs wrap instead of pushing the bubble past the
       edge of the panel. */
    overflow-wrap: anywhere;
    /* Keeps the paragraph breaks the model writes without needing to render
       any of its output as markup. */
    white-space: pre-wrap;
}

.assistant__message--bot {
    background: #ffffff;
    border: 1px solid rgba(18, 70, 111, 0.14);
    color: #15364c;
}

.assistant__message--you {
    margin-left: auto;
    background: var(--color-brand-navy, #12466f);
    color: #ffffff;
}

.assistant__links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin: -0.4rem 0 1.2rem;
}

.assistant__link {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: 1px solid var(--color-brand-navy, #12466f);
    border-radius: 999px;
    color: var(--color-brand-navy, #12466f);
    font-size: 1.3rem;
    font-weight: 600;
    text-decoration: none;
}

.assistant__link:hover,
.assistant__link:focus {
    background: var(--color-brand-navy, #12466f);
    color: #ffffff;
}

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

.assistant__composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.8rem;
    align-items: end;
    padding: 1.2rem 1.6rem 0;
    border-top: 1px solid rgba(18, 70, 111, 0.12);
    background: #ffffff;
}

/* Visible to a screen reader, not on screen. The placeholder is a hint, not a
   label, and vanishes the moment someone types. */
.assistant__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.assistant__input {
    width: 100%;
    margin: 0;
    padding: 0.9rem 1.1rem;
    border: 1px solid rgba(18, 70, 111, 0.25);
    border-radius: 0.8rem;
    font-family: inherit;
    font-size: 1.45rem;
    line-height: 1.4;
    resize: none;
    /* milligram sets a fixed height on inputs; a textarea needs to size from
       its rows attribute instead. */
    height: auto;
}

.assistant__input:focus {
    border-color: var(--color-brand-navy, #12466f);
    outline: none;
    box-shadow: 0 0 0 3px rgba(18, 70, 111, 0.15);
}

.assistant__send {
    height: auto;
    margin: 0;
    padding: 1rem 1.6rem;
    border: none;
    border-radius: 0.8rem;
    background: var(--color-brand-navy, #12466f);
    color: #ffffff;
    font-size: 1.4rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
    cursor: pointer;
}

.assistant__send:hover,
.assistant__send:focus {
    background: var(--color-brand-navy-mid, #1b5e96);
    color: #ffffff;
}

.assistant__send:disabled {
    opacity: 0.6;
    cursor: default;
}

.assistant__footnote {
    margin: 0;
    padding: 0.9rem 1.6rem 1.4rem;
    background: #ffffff;
    color: #5b6b7a;
    font-size: 1.2rem;
    line-height: 1.4;
}

/*
 * On a phone the launcher label takes room the page needs, so it collapses to
 * the icon alone. The accessible name survives because the text is still in the
 * DOM for a screen reader.
 */
@media (max-width: 30em) {
    .assistant__launcher-text {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .assistant__launcher {
        padding: 1.3rem;
    }
}

/*
 * Someone who has asked for less motion gets no transitions. There are none
 * declared above, but the panel appearing is still a change; this keeps any
 * future animation honest.
 */
@media (prefers-reduced-motion: reduce) {
    .assistant,
    .assistant * {
        transition: none !important;
        animation: none !important;
    }
}
