/*
 * Site-agnostic widget. Colour tokens below; the admin settings override
 * --brscb-accent / --brscb-on-accent and the title font with an inline
 * style, and pick the light or dark palette (.brscb--dark). Text uses the
 * site's own font (inherited). Themes can override any token on .brscb.
 */
.brscb {
    --brscb-accent: #1f6feb;
    --brscb-on-accent: #fff;
    --brscb-bg: #fff;
    --brscb-surface: #f2f3f5;
    --brscb-chrome: #f8f9fa;
    --brscb-border: #dfe1e5;
    /* Outline of controls and of the panel: 3:1 on --brscb-bg and --brscb-chrome. */
    --brscb-edge: #7b818a;
    --brscb-text: #1d2127;
    --brscb-muted: #5f6672;
    --brscb-error-bg: #fdecee;
    --brscb-error-text: #a1313a;
    --brscb-shadow: rgba(0, 0, 0, 0.18);
    --brscb-radius: 10px;
    /* Distance from the edges; the admin settings override both. */
    --brscb-offset-x: 24px;
    --brscb-offset-y: 24px;
    position: fixed;
    right: var(--brscb-offset-x);
    bottom: calc(var(--brscb-offset-y) + env(safe-area-inset-bottom, 0px));
    z-index: 99999;
    font-size: 15px;
    line-height: 1.5;
    color: var(--brscb-text);
}

.brscb--dark {
    --brscb-bg: #16131b;
    --brscb-surface: #211f26;
    --brscb-chrome: #000;
    --brscb-border: #49454f;
    --brscb-edge: #75717d;
    --brscb-text: #fff;
    --brscb-muted: #938f99;
    --brscb-error-bg: #3a1614;
    --brscb-error-text: #ff5b4f;
    --brscb-shadow: rgba(0, 0, 0, 0.55);
}

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

/* Toggle: accent pill with an icon on a disc and a label. A ring in the
   panel colour keeps the pill readable on a background of the accent colour;
   on small screens the short label replaces the full one. */
.brscb__toggle {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    height: 60px;
    padding: 0 7px;
    border: 0;
    border-radius: 90px;
    background: var(--brscb-accent);
    color: var(--brscb-on-accent);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    font-size: 15px;
    white-space: nowrap;
    box-shadow: 0 0 0 3px var(--brscb-bg), 0 8px 24px var(--brscb-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.brscb--labelled .brscb__toggle {
    padding-right: 24px;
}

.brscb__toggle:hover {
    transform: translateY(-2px);
}

/* Two-tone ring: --brscb-bg and --brscb-text sit at opposite ends of the
   scale, so one of them reaches 3:1 on any page background. The transparent
   outline shows up in forced-colors mode, where box-shadow is dropped. */
.brscb__toggle:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px var(--brscb-bg), 0 0 0 6px var(--brscb-text), 0 8px 24px var(--brscb-shadow);
}

.brscb__disc {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border-radius: 50%;
    background: var(--brscb-bg);
    color: var(--brscb-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.brscb__logo {
    width: 26px;
    height: 26px;
    object-fit: contain;
    display: block;
}

.brscb__label,
.brscb__label-short {
    line-height: 1;
}

.brscb__label-short {
    display: none;
}

/* !important: themes often force `display` on svg/img inside buttons. */
.brscb .brscb__disc .brscb__icon--close,
.brscb.is-open .brscb__disc .brscb__icon--open {
    display: none !important;
}

.brscb.is-open .brscb__disc .brscb__icon--close {
    display: block !important;
}

.brscb.is-open .brscb__label,
.brscb.is-open .brscb__label-short {
    display: none;
}

.brscb.is-open .brscb__toggle {
    padding-right: 7px;
}

/* Panel */
.brscb__panel {
    position: absolute;
    right: 0;
    bottom: 80px;
    width: min(390px, calc(100vw - 32px));
    height: min(600px, calc(100vh - var(--brscb-offset-y) - env(safe-area-inset-bottom, 0px) - 96px));
    display: flex;
    flex-direction: column;
    background: var(--brscb-bg);
    border: 1px solid var(--brscb-edge);
    border-radius: calc(var(--brscb-radius) * 2);
    box-shadow: 0 16px 40px var(--brscb-shadow);
    overflow: hidden;
    animation: brscb-rise 0.22s ease-out;
}

.brscb--left {
    right: auto;
    left: var(--brscb-offset-x);
}

.brscb--left .brscb__panel {
    right: auto;
    left: 0;
}

.brscb__panel[hidden] {
    display: none;
}

@keyframes brscb-rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header. Position/width/z-index are reset because the theme styles the bare
   `header` tag (site header: position:absolute; width:100%; z-index:99), which
   would otherwise overlay the message list. */
.brscb__header {
    position: static;
    width: auto;
    z-index: auto;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--brscb-chrome);
    border-bottom: 1px solid var(--brscb-border);
}

.brscb__title {
    font-family: inherit;
    font-weight: 500;
    font-size: 15px;
    letter-spacing: 0.2px;
}

.brscb__title::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 10px;
    border-radius: 50%;
    background: var(--brscb-accent);
    vertical-align: middle;
}

.brscb__clear {
    width: 32px;
    height: 32px;
    border: 1px solid var(--brscb-edge);
    border-radius: 50%;
    background: transparent;
    color: var(--brscb-text);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.brscb__clear:hover,
.brscb__clear:focus-visible {
    border-color: var(--brscb-accent);
    color: var(--brscb-accent);
}

.brscb__clear:focus-visible {
    outline: 2px solid var(--brscb-text);
    outline-offset: 2px;
}

/* Messages */
.brscb__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.brscb__msg {
    max-width: 86%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    font-size: 14.5px;
}

.brscb__msg--user {
    align-self: flex-end;
    background: var(--brscb-accent);
    color: var(--brscb-on-accent);
    border-bottom-right-radius: 4px;
}

.brscb__msg--model {
    align-self: flex-start;
    background: var(--brscb-surface);
    border-bottom-left-radius: 4px;
}

.brscb__msg--error {
    align-self: center;
    background: var(--brscb-error-bg);
    color: var(--brscb-error-text);
    font-size: 0.9em;
    border-radius: var(--brscb-radius);
}

.brscb__msg--typing {
    color: var(--brscb-muted);
    font-style: italic;
    animation: brscb-pulse 1.2s ease-in-out infinite;
}

@keyframes brscb-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

.brscb__msg ul {
    margin: 6px 0 4px 18px;
    padding: 0;
}

.brscb__msg li {
    margin: 2px 0;
}

.brscb__msg strong {
    font-weight: 700;
}

.brscb__msg--model a,
.brscb__sources a {
    color: var(--brscb-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.brscb__msg--model a:hover,
.brscb__sources a:hover {
    text-decoration-thickness: 2px;
}

.brscb__msg--user a {
    color: inherit;
}

.brscb__sources {
    margin: 8px 0 0;
    padding-top: 6px;
    border-top: 1px solid var(--brscb-border);
    font-size: 0.8em;
    color: var(--brscb-muted);
}

/* Contact request summary. Text uses --brscb-text / --brscb-muted (AA on
   --brscb-surface in both schemes); the accent is only the button fill,
   because the default accent as text on the light surface is 4.2:1. */
.brscb__card {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--brscb-border);
}

.brscb__card-title {
    margin: 0 0 6px;
    font-weight: 600;
}

.brscb__card-fields {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
    margin: 0 0 8px;
}

.brscb__card-fields dt {
    color: var(--brscb-muted);
    font-size: 0.9em;
}

.brscb__card-fields dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.brscb__card-fields dd.brscb__card-message {
    grid-column: 1 / -1;
    white-space: pre-line;
}

.brscb__card-notice {
    margin: 0 0 8px;
    font-size: 0.85em;
    color: var(--brscb-muted);
}

.brscb__msg--model .brscb__card-notice a {
    color: var(--brscb-text);
}

.brscb__card-attach {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 10px;
    font-size: 0.9em;
    cursor: pointer;
}

.brscb__card-attach input {
    margin: 0;
    width: 16px;
    height: 16px;
}

.brscb__card-attach input:focus-visible {
    outline: 2px solid var(--brscb-text);
    outline-offset: 2px;
}

.brscb__card-send {
    min-height: 36px;
    padding: 0 18px;
    border: 0;
    border-radius: 18px;
    background: var(--brscb-accent);
    color: var(--brscb-on-accent);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.brscb__card-send:focus-visible {
    outline: 2px solid var(--brscb-text);
    outline-offset: 2px;
}

.brscb__card-send:disabled {
    opacity: 0.6;
    cursor: default;
}

.brscb__card-status {
    margin: 8px 0 0;
}

.brscb__card-status:empty {
    display: none;
}

.brscb__card-status--error {
    color: var(--brscb-error-text);
}

/* Composer */
.brscb__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--brscb-border);
    background: var(--brscb-chrome);
}

.brscb__input {
    flex: 1;
    resize: none;
    max-height: 120px;
    padding: 10px 16px;
    border: 1px solid var(--brscb-edge);
    border-radius: 22px;
    background: var(--brscb-bg);
    color: var(--brscb-text);
    font: inherit;
    font-size: 14.5px;
    transition: border-color 0.15s ease;
}

.brscb__input:focus {
    border-color: var(--brscb-accent);
}

.brscb__input:focus-visible {
    outline: 2px solid var(--brscb-text);
    outline-offset: 2px;
}

.brscb__input::placeholder {
    color: var(--brscb-muted);
}

.brscb__hp {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.brscb__send {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: 0;
    border-radius: 50%;
    background: var(--brscb-accent);
    color: var(--brscb-on-accent);
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
}

.brscb__send:hover {
    transform: translateY(-1px);
}

.brscb__send:focus-visible {
    outline: 2px solid var(--brscb-text);
    outline-offset: 2px;
}

.brscb__send:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

.brscb__privacy {
    margin: 0;
    padding: 0 16px 10px;
    background: var(--brscb-chrome);
    font-size: 11px;
    color: var(--brscb-muted);
}

.brscb__privacy a {
    color: inherit;
    text-decoration: underline;
}

.brscb .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

@media (max-width: 480px) {
    /* The side gap is capped so the full-width panel fits; the bottom gap
       is kept, since it is usually set to clear a bar of the theme. */
    .brscb {
        right: min(var(--brscb-offset-x), 12px);
    }

    .brscb--left {
        right: auto;
        left: min(var(--brscb-offset-x), 12px);
    }

    .brscb__toggle {
        height: 56px;
        gap: 10px;
    }

    .brscb__disc {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
    }

    .brscb__label {
        display: none;
    }

    .brscb__label-short {
        display: inline;
    }

    .brscb--labelled .brscb__toggle {
        padding-right: 7px;
    }

    .brscb--short .brscb__toggle {
        padding-right: 18px;
    }

    .brscb.is-open .brscb__toggle {
        padding-right: 7px;
    }

    .brscb__panel {
        width: calc(100vw - 24px);
        bottom: 74px;
        height: calc(100dvh - var(--brscb-offset-y) - env(safe-area-inset-bottom, 0px) - 88px);
        border-radius: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .brscb__panel,
    .brscb__toggle,
    .brscb__send,
    .brscb__msg--typing {
        animation: none;
        transition: none;
    }
}
