/*
 * Site Chat widget.
 * Colours come from the backoffice theme (Chatbot → Appearance) as CSS custom properties on
 * the widget's host element (#site-chat). The editor's colours are used exactly as chosen; the --chat-on-* / assistant text
 * colours (white or black) are picked server-side for readability. Links and focus outlines use
 * the accent colour; the backoffice preview reports whether it meets WCAG AA. The fallbacks below
 * are the "Midnight" theme.
 */
:host {
    /* Start from a clean slate: nothing from the host page is inherited except the font family below. */
    all: initial;

    --chat-primary: #1a1a2e;
    --chat-on-primary: #ffffff;
    --chat-accent: #d63355;
    --chat-on-accent: #ffffff;
    --chat-panel: #f7f7fb;
    --chat-assistant-bg: #ffffff;
    --chat-assistant-text: #1a1a1a;
    --chat-assistant-border: #d6d6d6;
    --chat-error: #b42318;

    position: fixed;
    /* 1% of the width from the edge, exactly like OneTrust's cookie button (left: 1%); the launcher/close button never moves between states. */
    right: 1%;
    /* --site-chat-lift is set by the widget script while a host button (data-avoid) sits in this corner. */
    bottom: calc(1.25rem + var(--site-chat-lift, 0px));
    transition: bottom .3s ease;
    z-index: 2147483000;
    font-size: .95rem;
    font-family: inherit;
    line-height: 1.4;
    color: #1a1a1a;
    text-align: left;

    /* The panel opens above the launcher, which stays in place as the close button. */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .75rem;
}
:host(.is-left) { right: auto; left: 1%; align-items: flex-start; }
/* While open (any width), sit above OneTrust's floating cookie button (2147483646) and banner so the chat and its close button are never covered. */
:host(.is-open) { z-index: 2147483647; }

*, *::before, *::after { box-sizing: border-box; }
button { cursor: pointer; }
/* Form controls don't inherit fonts by default; inside the shadow root nothing else sets them, so they'd fall back to 13.3px. */
button, input, textarea, select { font: inherit; letter-spacing: inherit; }

/* ── Launcher ─────────────────────────────────────────────── */

.site-chat-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    /* 50px, like OneTrust's floating cookie button, so the two sit in the corner as a matching pair. */
    min-width: 50px;
    height: 50px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--chat-accent);
    color: var(--chat-on-accent);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    transition: transform .15s ease;
}

.site-chat-toggle.has-label { padding: 0 1.2rem 0 1rem; font-weight: 600; }

.site-chat-toggle:hover { transform: scale(1.06); }

/* Two-tone focus ring (white inner, dark outer) stays visible on any page background. */
.site-chat-toggle:focus-visible {
    outline: 3px solid #1a1a1a;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #ffffff, 0 6px 20px rgba(0, 0, 0, .25);
}

/* Open: the launcher turns into a round ✕ that closes the chat. */
.site-chat-toggle-close { display: none; }
:host(.is-open) .site-chat-toggle { width: 50px; min-width: 50px; padding: 0; }
:host(.is-open) .site-chat-bot-icon,
:host(.is-open) .site-chat-toggle-label { display: none; }
:host(.is-open) .site-chat-toggle-close { display: block; animation: site-chat-spin-in .2s ease; }

@keyframes site-chat-spin-in {
    from { transform: rotate(-90deg); opacity: 0; }
    to { transform: rotate(0); opacity: 1; }
}

/* Launcher animation (Appearance → Launcher button → Animation): an anim-* class on the host. Each plays once
   per page and stops in under WCAG 2.2.2's 5s limit for motion that can't be paused: pulse 4 × 1.1s from
   0.5s, the other attention animations 2 × 2.4s from 1s, slide-ins as the page loads (0.8s, like OneTrust's
   cookie button). Not while open, and not again once the visitor has opened the chat (.was-opened). */
.site-chat-toggle { position: relative; }
.site-chat-toggle::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
}
/* Pulse = a heartbeat: the button swells while a ring spreads out from it. */
:host(.anim-pulse:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-pulse-beat 1.1s ease-in-out .5s 4; }
:host(.anim-pulse:not(.is-open):not(.was-opened)) .site-chat-toggle::after { animation: site-chat-pulse 1.1s ease-out .5s 4; }
:host(.anim-bounce:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-bounce 2.4s ease 1s 2; }
:host(.anim-wiggle:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-wiggle 2.4s ease 1s 2; }
:host(.anim-float:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-float 2.4s ease-in-out 1s 2; }
/* "both": hidden at the start position until the slide begins, so it never flashes in its final place first. */
:host(.anim-slide-right-to-left:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-slide-rtl .8s ease both; }
:host(.anim-slide-left-to-right:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-slide-ltr .8s ease both; }
:host(.anim-slide-bottom-to-top:not(.is-open):not(.was-opened)) .site-chat-toggle { animation: site-chat-slide-btt .8s ease both; }

@keyframes site-chat-pulse-beat {
    0%, 55%, 100% { transform: scale(1); }
    22% { transform: scale(1.14); }
}

/* A ring in the accent colour that grows out of the button and fades. */
@keyframes site-chat-pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--chat-accent) 90%, transparent); }
    75%, 100% { box-shadow: 0 0 0 26px color-mix(in srgb, var(--chat-accent) 0%, transparent); }
}

/* Slide-ins: the same distance (94px) and fade as OneTrust's cookie button. */
@keyframes site-chat-slide-rtl {
    from { opacity: 0; transform: translateX(94px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes site-chat-slide-ltr {
    from { opacity: 0; transform: translateX(-94px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes site-chat-slide-btt {
    from { opacity: 0; transform: translateY(94px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes site-chat-bounce {
    0%, 40%, 100% { transform: translateY(0); }
    15% { transform: translateY(-10px); }
    25% { transform: translateY(0); }
    32% { transform: translateY(-4px); }
}

@keyframes site-chat-wiggle {
    0%, 40%, 100% { transform: rotate(0); }
    8% { transform: rotate(-10deg); }
    16% { transform: rotate(8deg); }
    24% { transform: rotate(-6deg); }
    32% { transform: rotate(4deg); }
}

@keyframes site-chat-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* ── Panel ────────────────────────────────────────────────── */

.site-chat-panel {
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - 2.5rem));
    order: -1; /* above the launcher */
    margin-right: max(0px, calc(1.25rem - 1%)); /* the host sits 1% from the edge; the panel keeps its 20px */
    /* Room for the page margin, the launcher (3.5rem) and the gap above it. */
    height: min(560px, calc(100vh - 6.75rem - var(--site-chat-lift, 0px)));
    /* dvh: iPad/iPhone Safari's 100vh includes the area behind the toolbar, which pushes the panel off the top. */
    height: min(560px, calc(100dvh - 6.75rem - var(--site-chat-lift, 0px)));
    background: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    overflow: hidden;
}

:host(.is-left) .site-chat-panel { margin-right: 0; margin-left: max(0px, calc(1.25rem - 1%)); }

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

.site-chat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem .85rem;
    background: var(--chat-primary);
    color: var(--chat-on-primary);
}

/* The bot's avatar: its icon on the accent colour, as on the launcher (a contrast-checked pair). */
.site-chat-avatar {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    background: var(--chat-accent);
    color: var(--chat-on-accent);
}

.site-chat-title { flex: 1; min-width: 0; }
.site-chat-actions { display: flex; gap: .15rem; }

/* Full-strength colour (no opacity) so the subtitle keeps AA contrast. */
.site-chat-header small { display: block; font-size: .75rem; }

.site-chat-actions button,
.site-chat-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    min-height: 2rem;
    border: 0;
    background: transparent;
    color: var(--chat-on-primary);
    padding: .25rem .4rem;
    border-radius: .35rem;
}

.site-chat-actions button:hover,
.site-chat-menu-toggle:hover,
.site-chat-menu-toggle[aria-expanded="true"] { background: color-mix(in srgb, var(--chat-on-primary) 15%, transparent); }

.site-chat-actions button:focus-visible,
.site-chat-menu-toggle:focus-visible { outline: 2px solid var(--chat-on-primary); outline-offset: 1px; }

/* ☰ menu: white with near-black text (always legible); accent focus ring is contrast-checked vs white. */
.site-chat-menu {
    position: absolute;
    top: calc(100% - .35rem);
    left: .6rem;
    z-index: 2;
    min-width: 12.5rem;
    padding: .3rem;
    background: #ffffff;
    color: #1a1a1a;
    border: 1px solid #d6d6d6;
    border-radius: .6rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

.site-chat-menu[hidden] { display: none; }
.site-chat-menu ul { list-style: none; margin: 0; padding: 0; }

.site-chat-menu button {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    padding: .55rem .7rem;
    border: 0;
    border-radius: .4rem;
    background: transparent;
    color: #1a1a1a;
    text-align: left;
    font-weight: 500;
}

.site-chat-menu button:hover { background: #f0f0f3; }
.site-chat-menu button:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: -2px; }

/* ── Messages ─────────────────────────────────────────────── */

.site-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    background: var(--chat-panel);
}

.site-chat-msg {
    max-width: 85%;
    padding: .6rem .85rem;
    border-radius: .9rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

/* Keep the visitor's and the bot's line breaks; only the text keeps them, so markup around it can be indented. */
.site-chat-text { white-space: pre-wrap; }

/* Avatar and name above each bot message. */
.site-chat-msg-head {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .3rem;
    font-size: .8rem;
    font-weight: 600;
}

.site-chat-msg-head svg { width: .85rem; height: .85rem; }

.site-chat-msg-user {
    align-self: flex-end;
    background: var(--chat-primary);
    color: var(--chat-on-primary);
    border-bottom-right-radius: .25rem;
}

.site-chat-msg-assistant {
    align-self: flex-start;
    background: var(--chat-assistant-bg);
    color: var(--chat-assistant-text);
    border: 1px solid var(--chat-assistant-border);
    border-bottom-left-radius: .25rem;
}

/* Error: same readable text colour, flagged with a thick accent border (not colour of text alone). */
.site-chat-msg.is-error { border: 2px solid var(--chat-accent); }

.site-chat-msg.is-typing .site-chat-text::after {
    content: '●●●';
    letter-spacing: .15rem;
    color: var(--chat-assistant-text);
    opacity: .6;
    animation: site-chat-pulse 1s infinite;
}

@keyframes site-chat-pulse { 50% { opacity: .2; } }

.site-chat-sources-label {
    margin: .6rem 0 0;
    padding-top: .5rem;
    border-top: 1px solid var(--chat-assistant-border);
    font-size: .8rem;
    font-weight: 600;
    white-space: normal;
}

.site-chat-sources {
    margin: .25rem 0 0;
    padding: 0 0 0 1.2rem;
    font-size: .82rem;
    white-space: normal;
}

/* Underlined so links aren't distinguished by colour alone. */
.site-chat-sources a { color: var(--chat-accent); text-decoration: underline; }
.site-chat-sources a:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 2px; border-radius: 2px; }

/* ── Suggested questions & quick replies ──────────────────── */
/* Chips use the bot-bubble colours (contrast-checked) with an accent outline. */

.site-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-self: flex-start;
    max-width: 92%;
}

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

.site-chat-chip {
    padding: .4rem .75rem;
    border: 1.5px solid var(--chat-accent);
    border-radius: 999px;
    background: var(--chat-assistant-bg);
    color: var(--chat-assistant-text);
    font-size: .85rem;
    line-height: 1.3;
    text-align: left;
}

.site-chat-chip:hover { background: color-mix(in srgb, var(--chat-accent) 12%, var(--chat-assistant-bg)); }
.site-chat-chip:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 2px; }

.site-chat-handoff-offer {
    margin-top: .6rem;
    padding-top: .5rem;
    border-top: 1px solid var(--chat-assistant-border);
    white-space: normal;
}

.site-chat-handoff-offer p { margin: 0 0 .4rem; font-size: .85rem; }

/* ── Feedback ─────────────────────────────────────────────── */

.site-chat-feedback {
    display: flex;
    gap: .3rem;
    margin-top: .5rem;
}

.site-chat-feedback-btn {
    min-width: 2.25rem;
    min-height: 2rem;
    padding: .1rem .45rem;
    border: 1px solid var(--chat-assistant-border);
    border-radius: .5rem;
    background: transparent;
    color: var(--chat-assistant-text);
    font-size: 1rem;
    line-height: 1;
}

/* Selected state isn't colour alone: filled background and a thicker border. */
.site-chat-feedback-btn[aria-pressed="true"] {
    background: var(--chat-accent);
    border: 2px solid var(--chat-accent);
    color: var(--chat-on-accent);
}

.site-chat-feedback-btn:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 2px; }

/* ── Talk to a person (contact form) ──────────────────────── */

.site-chat-contact-bubble { max-width: 100%; width: 100%; white-space: normal; }

.site-chat-contact-title { margin: 0 0 .2rem; font-weight: 700; }
.site-chat-contact-intro { margin: 0 0 .6rem; font-size: .85rem; }

/* Required fields carry an asterisk (decorative: the inputs are also marked required for assistive tech);
   optional ones are marked "(optional)". The asterisk uses the theme's error red, which is picked to be readable on the bubble in any theme. */
.site-chat-optional { font-weight: 400; }
.site-chat-required { margin-left: .1rem; font-weight: 700; color: var(--chat-error); }

.site-chat-field { margin-bottom: .6rem; }

.site-chat-field label {
    display: block;
    margin-bottom: .2rem;
    font-size: .82rem;
    font-weight: 600;
}

/* Form controls stay white with dark text (always legible), like the question box. */
.site-chat-field input[type="text"],
.site-chat-field input[type="email"],
.site-chat-field input[type="tel"],
.site-chat-field input[type="number"],
.site-chat-field input[type="date"],
.site-chat-field select,
.site-chat-field textarea {
    width: 100%;
    padding: .45rem .6rem;
    border: 1px solid #767676;
    border-radius: .5rem;
    background: #ffffff;
    color: #1a1a1a;
    font: inherit;
    resize: vertical;
}

.site-chat-field input:focus-visible,
.site-chat-field textarea:focus-visible,
.site-chat-field select:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 1px;
    border-color: var(--chat-accent);
}

/* Invalid fields: thicker border plus a text message (not colour alone). */
.site-chat-field [aria-invalid="true"] { border: 2px solid var(--chat-accent); }

.site-chat-field-error,
.site-chat-form-error {
    margin: .25rem 0 0;
    color: var(--chat-error); /* a red readable on the bubble (light or dark), picked server-side */
    font-size: .8rem;
    font-weight: 600;
}

.site-chat-field-error::before,
.site-chat-form-error::before { content: '⚠ '; }

.site-chat-consent,
.site-chat-check {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .2rem .5rem;
    align-items: start;
}

.site-chat-consent input,
.site-chat-check input { width: 1.1rem; height: 1.1rem; margin-top: .15rem; accent-color: var(--chat-accent); }
.site-chat-consent label,
.site-chat-check label { margin: 0; font-weight: 400; }
.site-chat-consent .site-chat-field-error,
.site-chat-check .site-chat-field-error { grid-column: 1 / -1; }

/* Checkbox group: the title is the legend, styled like a field label; options stack below it. */
.site-chat-checks { margin: 0 0 .6rem; padding: 0; border: 0; min-width: 0; }
.site-chat-checks legend { padding: 0; margin-bottom: .3rem; font-size: .82rem; font-weight: 600; }
.site-chat-checks .site-chat-check { margin-bottom: .3rem; }
.site-chat-consent a { color: var(--chat-accent); text-decoration: underline; }

/* Honeypot: off-screen for sighted users, hidden from assistive tech via aria-hidden. */
.site-chat-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.site-chat-contact-actions { display: flex; gap: .5rem; margin-top: .3rem; }

.site-chat-button,
.site-chat-button-secondary {
    padding: .45rem .9rem;
    border-radius: .5rem;
    font-weight: 600;
}

.site-chat-button { border: 0; background: var(--chat-accent); color: var(--chat-on-accent); }
.site-chat-button:disabled { opacity: .6; cursor: progress; }

.site-chat-button-secondary {
    border: 1px solid var(--chat-assistant-border);
    background: transparent;
    color: var(--chat-assistant-text);
}

.site-chat-button:focus-visible,
.site-chat-button-secondary:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 2px; }

/* Header "Talk to a person" button shares the header action styles. */

/* ── Input ────────────────────────────────────────────────── */

.site-chat-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .5rem;
    padding: .75rem;
    border-top: 1px solid #d6d6d6;
    background: #ffffff;
}

/* Friendly "type your question first" hint (replaces the browser's validation bubble).
   Kept in the page with zero height when empty so screen readers announce it when it appears. */
.site-chat-input-hint {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    gap: .35rem;
    margin: 0;
    font-size: .8rem;
    color: #b42318; /* 6.6:1 on the always-white input area, in every theme */
}

.site-chat-form:not(.has-hint) .site-chat-input-hint { height: 0; overflow: hidden; }

/* Editor's notice under the input (e.g. "Answers are written by AI"). */
.site-chat-notice {
    flex-basis: 100%;
    margin: 0;
    font-size: .75rem;
    line-height: 1.35;
    color: #555555; /* 7.5:1 on the always-white input area */
}
.site-chat-form.has-hint .site-chat-input-hint::before { content: 'ⓘ'; font-size: .95rem; }
.site-chat-form.has-hint textarea { border: 2px solid var(--chat-accent); }
.site-chat-form.nudge textarea { animation: site-chat-nudge .28s ease; }

@keyframes site-chat-nudge {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.site-chat-form textarea {
    flex: 1;
    resize: none;
    border: 1px solid #767676; /* 4.5:1 on white: the field boundary is clearly visible */
    border-radius: .6rem;
    padding: .5rem .7rem;
    min-height: 2.5rem;
    max-height: 120px;
    line-height: 1.4;
    color: #1a1a1a;
    background: #ffffff;
}

.site-chat-form textarea::placeholder { color: #6b6b6b; opacity: 1; }

.site-chat-form textarea:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 1px;
    border-color: var(--chat-accent);
}

/* Square icon button, as tall as the one-line question box; stays at the bottom as the box grows. */
.site-chat-form button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: .6rem;
    padding: 0;
    background: var(--chat-accent);
    color: var(--chat-on-accent);
}

.site-chat-form button:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 2px; }
.site-chat-form button:disabled { opacity: .5; cursor: not-allowed; }

/* ── Clear chat confirmation ──────────────────────────────── */

.site-chat-confirm {
    padding: .75rem;
    border-top: 1px solid #d6d6d6;
    background: #ffffff;
    color: #1a1a1a;
}

.site-chat-confirm[hidden] { display: none; }
.site-chat-confirm-title { margin: 0 0 .2rem; font-weight: 700; }
.site-chat-confirm-text { margin: 0 0 .6rem; font-size: .85rem; }
.site-chat-confirm .site-chat-contact-actions { margin-top: 0; }
.site-chat-confirm .site-chat-button-secondary { color: #1a1a1a; border-color: #767676; }

/* ── Utilities & adaptations ──────────────────────────────── */

.site-chat-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Maximised ────────────────────────────────────────────── */

.site-chat-icon-restore { display: none; }
:host(.is-maximized) .site-chat-icon-maximize { display: none; }
:host(.is-maximized) .site-chat-icon-restore { display: block; }

/* A large window above the launcher (which stays in its corner), with a margin at the top and side
   so it still reads as an overlay, capped so it doesn't span huge monitors. */
:host(.is-maximized.is-open) .site-chat-panel {
    width: min(1100px, calc(100vw - 6rem));
    height: min(900px, calc(100vh - 9rem - var(--site-chat-lift, 0px)));
    height: min(900px, calc(100dvh - 9rem - var(--site-chat-lift, 0px)));
}

/* Keep lines at a comfortable reading length on wide screens. */
:host(.is-maximized) .site-chat-msg { max-width: min(85%, 46rem); }
:host(.is-maximized) .site-chat-contact-bubble { max-width: 40rem; }

@media (max-width: 575.98px) {
    :host { right: 1%; bottom: calc(1rem + var(--site-chat-lift, 0px)); }
    :host(.is-left) { right: auto; left: 1%; }
    :host(.is-open) { inset: 0; }
    :host(.is-open) .site-chat-panel,
    :host(.is-left.is-open) .site-chat-panel { margin: 0; }
    :host(.is-open) { align-items: stretch; }
    /* % not vw: 100vw can be wider than the visible area on phones, cropping the send button. */
    :host(.is-open) .site-chat-panel { width: 100%; height: var(--site-chat-vh, 100dvh); max-height: 100%; border-radius: 0; }
    .site-chat-form { padding-right: max(.75rem, env(safe-area-inset-right)); padding-left: max(.75rem, env(safe-area-inset-left)); }
    /* Full screen on phones: close with the ✕ in the header; the launcher would cover the input. */
    :host(.is-open) .site-chat-toggle { display: none; }
    /* Already full screen on phones: no maximise button, and maximised looks the same. */
    .site-chat-actions .site-chat-maximize { display: none; }
    :host(.is-maximized.is-open),
    :host(.is-maximized.is-left.is-open) { inset: 0; }
    :host(.is-maximized.is-open) .site-chat-panel { width: 100%; height: var(--site-chat-vh, 100dvh); }
}

@media (prefers-reduced-motion: reduce) {
    .site-chat-toggle { transition: none; }
    :host { transition: none; }
    :host(.is-open) .site-chat-toggle-close { animation: none; }
    .site-chat-toggle:hover { transform: none; }
    .site-chat-msg.is-typing .site-chat-text::after { animation: none; }
    .site-chat-form.nudge textarea { animation: none; }
    /* !important: the anim-* rules use :host(...) selectors, which are more specific. */
    .site-chat-toggle,
    .site-chat-toggle::after { animation: none !important; }
}

/* Windows High Contrast / forced colours: custom colours are replaced, so draw explicit edges. */
@media (forced-colors: active) {
    .site-chat-toggle,
    .site-chat-panel,
    .site-chat-msg,
    .site-chat-form button { border: 1px solid CanvasText; }
    .site-chat-toggle:focus-visible { outline-color: Highlight; }
    /* The avatar's accent circle disappears in forced colours; keep its outline. */
    .site-chat-avatar { border: 1px solid CanvasText; }
}

@media (forced-colors: active) {
    .site-chat-chip,
    .site-chat-feedback-btn,
    .site-chat-button,
    .site-chat-button-secondary { border: 1px solid ButtonText; }
    .site-chat-feedback-btn[aria-pressed="true"] { border-width: 3px; }
}

@media (forced-colors: active) {
    .site-chat-menu { border: 1px solid CanvasText; }
}
