/* Public support chat. Scoped to .public-chat to avoid changing the public site. */
.public-chat {
    --chat-primary: #0a7f91;
    --chat-primary-hover: #086b7a;
    --chat-primary-soft: #eaf7f9;
    --chat-brand: #19b7d1;
    --chat-brand-hover: #10a6bf;
    --chat-ink: #202426;
    --chat-canvas: #f4f7f8;
    --chat-surface: #ffffff;
    --chat-text: var(--text, #1a1a1a);
    --chat-muted: #657276;
    --chat-line: #dce6e8;
    --chat-success: #1f7a3a;
    --chat-waiting: #5c97a2;
    --chat-error: #b3261e;

    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
    font-family: var(--font-body, 'Open Sans', Arial, sans-serif);
    color: var(--chat-text);
}

.public-chat[hidden],
.public-chat__panel[hidden] {
    display: none !important;
}

.public-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;
}

.public-chat__launcher {
    position: fixed;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(22px, env(safe-area-inset-bottom));
    min-width: 164px;
    height: 52px;
    padding: 0 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 11px;
    border: 1px solid rgba(32, 36, 38, .16);
    border-radius: 14px;
    background: var(--chat-brand);
    color: var(--chat-ink);
    box-shadow: 0 9px 24px rgba(27, 47, 51, .18);
    pointer-events: auto;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    transition: bottom .18s ease, background-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.public-chat.has-cookie-banner .public-chat__launcher {
    bottom: max(22px, var(--public-chat-cookie-clearance, 96px));
}

.public-chat__launcher:hover {
    background: var(--chat-brand-hover);
    box-shadow: 0 12px 28px rgba(27, 47, 51, .22);
    transform: translateY(-1px);
}

.public-chat__launcher:active {
    transform: translateY(0);
}

.public-chat__launcher:focus-visible,
.public-chat__panel button:focus-visible,
.public-chat__panel a:focus-visible {
    outline: 3px solid var(--chat-primary);
    outline-offset: 2px;
}

.public-chat.is-open .public-chat__launcher {
    visibility: hidden;
    pointer-events: none;
}

.public-chat__launcher-glyph {
    position: relative;
    width: 21px;
    height: 17px;
    flex: 0 0 auto;
    border: 2px solid currentColor;
    border-radius: 7px;
}

.public-chat__launcher-glyph::after {
    content: '';
    position: absolute;
    left: 3px;
    bottom: -5px;
    width: 7px;
    height: 7px;
    border-left: 2px solid currentColor;
    transform: skew(-30deg);
    background: var(--chat-brand);
    transition: background-color .16s ease;
}

.public-chat__launcher:hover .public-chat__launcher-glyph::after {
    background: var(--chat-brand-hover);
}

.public-chat__unread {
    position: absolute;
    top: -6px;
    right: -5px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 999px;
    background: var(--chat-ink);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.public-chat__unread[hidden] {
    display: none;
}

.public-chat__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 22, 28, .1);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.public-chat__panel {
    position: fixed;
    right: max(22px, env(safe-area-inset-right));
    bottom: 86px;
    width: min(408px, calc(100vw - 32px));
    height: min(650px, calc(100vh - 110px));
    height: min(650px, calc(100dvh - 110px));
    min-height: min(430px, calc(100vh - 116px));
    min-height: min(430px, calc(100dvh - 116px));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    border: 1px solid var(--chat-line);
    border-radius: 16px;
    background: var(--chat-surface);
    box-shadow: 0 22px 58px rgba(27, 47, 51, .18);
    opacity: 0;
    transform: translateY(12px) scale(.985);
    transform-origin: right bottom;
    pointer-events: none;
    transition: opacity .18s ease, transform .2s ease;
}

.public-chat__panel::before {
    content: '';
    position: absolute;
    z-index: 2;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--chat-brand);
}

.public-chat.is-open .public-chat__backdrop {
    opacity: 1;
    pointer-events: auto;
}

.public-chat.is-open .public-chat__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.public-chat__header {
    position: relative;
    min-height: 76px;
    padding: 16px 14px 13px 16px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 12px;
    border-bottom: 1px solid var(--chat-line);
    background: rgba(255, 255, 255, .96);
}

.public-chat__heading {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.public-chat__heading-copy { min-width: 0; }

.public-chat__brand-mark {
    position: relative;
    width: 35px;
    height: 35px;
    flex: 0 0 auto;
    border: 1px solid #c9e5ea;
    border-radius: 10px;
    background: #eff9fa;
}

.public-chat__brand-mark::before {
    content: '';
    position: absolute;
    top: 9px;
    left: 9px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-brand);
}

.public-chat__brand-mark::after {
    content: '';
    position: absolute;
    top: 16px;
    left: 12px;
    width: 13px;
    height: 8px;
    border-right: 2px solid var(--chat-ink);
    border-bottom: 2px solid var(--chat-ink);
    border-radius: 0 0 8px 0;
    transform: skewX(-18deg);
}

.public-chat__title {
    margin: 0;
    color: var(--chat-text);
    font-family: var(--font-head, 'Montserrat', system-ui, sans-serif);
    font-size: 18px;
    font-weight: 750;
    line-height: 1.2;
}

.public-chat__presence {
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--chat-muted);
    font-size: 12px;
    line-height: 1.25;
}

.public-chat__presence-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--chat-waiting);
    box-shadow: 0 0 0 3px rgba(92, 151, 162, .12);
}

.public-chat__presence[data-state='success'] .public-chat__presence-dot {
    background: var(--chat-success);
    box-shadow: 0 0 0 3px rgba(31, 122, 58, .12);
}

.public-chat__presence[data-state='error'] .public-chat__presence-dot {
    background: var(--chat-error);
    box-shadow: 0 0 0 3px rgba(179, 38, 30, .12);
}

.public-chat__header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.public-chat__quiet-action,
.public-chat__close {
    min-height: 38px;
    border-radius: 10px;
    color: var(--chat-muted);
}

.public-chat__quiet-action {
    padding: 0 9px;
    font-size: 12px;
    font-weight: 650;
}

.public-chat__quiet-action:hover,
.public-chat__close:hover {
    background: var(--chat-primary-soft);
    color: var(--chat-primary);
}

.public-chat__close {
    width: 38px;
    font-size: 24px;
    font-weight: 400;
    line-height: 1;
}

.public-chat__body {
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--chat-canvas);
}

.public-chat__state {
    min-height: 100%;
    padding: 18px 20px 16px;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
}

.public-chat__eyebrow {
    margin: 0 0 5px;
    color: var(--chat-primary);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.public-chat__state-title {
    margin: 0;
    max-width: 290px;
    color: var(--chat-text);
    font-family: var(--font-head, 'Montserrat', system-ui, sans-serif);
    font-size: 22px;
    line-height: 1.16;
}

.public-chat__state-copy {
    margin: 7px 0 0;
    max-width: 315px;
    color: var(--chat-muted);
    font-size: 12.5px;
    line-height: 1.45;
}

.public-chat__form {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.public-chat__honeypot {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.public-chat__fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.public-chat__legend,
.public-chat__field-label {
    display: block;
    color: #485458;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
}

.public-chat__legend { margin: 0 0 8px; }
.public-chat__field-label { margin: 0; }

.public-chat__field-label > .public-chat__textarea,
.public-chat__field-label > .public-chat__phone {
    display: block;
    margin-top: 7px;
}

.public-chat__topics {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.public-chat__topic {
    position: relative;
}

.public-chat__topic input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.public-chat__topic span {
    min-height: 33px;
    padding: 7px 10px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--chat-line);
    border-radius: 9px;
    background: var(--chat-surface);
    color: #485458;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color .14s ease, background-color .14s ease, color .14s ease;
}

.public-chat__topic input:checked + span {
    border-color: var(--chat-primary);
    background: #f7fcfc;
    color: var(--chat-primary);
}

.public-chat__topic input:focus-visible + span {
    outline: 3px solid var(--chat-primary);
    outline-offset: 2px;
}

.public-chat__textarea,
.public-chat__phone {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid var(--chat-line);
    border-radius: 12px;
    background: var(--chat-surface);
    color: var(--chat-text);
    font-size: 14px;
    line-height: 1.45;
    transition: border-color .14s ease, box-shadow .14s ease;
}

.public-chat__textarea {
    min-height: 76px;
    max-height: 132px;
    resize: none;
}

.public-chat__phone { min-height: 42px; }

.public-chat__textarea::placeholder,
.public-chat__phone::placeholder {
    color: var(--chat-muted);
}

.public-chat__textarea:hover,
.public-chat__phone:hover {
    border-color: #b8cacc;
}

.public-chat__textarea:focus,
.public-chat__phone:focus {
    outline: 0;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(25, 183, 209, .16);
}

.public-chat__privacy {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: start;
    gap: 9px;
    color: #566266;
    font-size: 11px;
    line-height: 1.45;
}

.public-chat__privacy input {
    width: 17px;
    height: 17px;
    margin: 1px 0 0;
    accent-color: var(--chat-primary);
}

.public-chat__privacy input:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

.public-chat__privacy a {
    color: var(--chat-primary);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.public-chat__primary {
    min-height: 44px;
    padding: 0 18px;
    border-radius: 12px;
    background: var(--chat-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 750;
    line-height: 1;
    transition: background-color .14s ease, transform .1s ease;
}

.public-chat__primary:hover {
    background: var(--chat-primary-hover);
}

.public-chat__primary:active {
    transform: translateY(1px);
}

.public-chat__primary:disabled,
.public-chat__panel textarea:disabled,
.public-chat__panel input:disabled {
    opacity: .58;
    cursor: wait;
}

.public-chat__notice,
.public-chat__form-status {
    margin: 0;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.45;
}

.public-chat__notice {
    margin-bottom: 15px;
    padding: 10px 12px;
    border: 1px solid #ead7b8;
    background: #fff7e8;
    color: #775019;
}

.public-chat__form-status:not(:empty) {
    padding: 9px 11px;
    border: 1px solid #efc6c2;
    background: #fff0ee;
    color: var(--chat-error);
}

.public-chat__retry {
    align-self: flex-start;
    margin-top: 18px;
}

.public-chat__loading-mark {
    width: 34px;
    height: 34px;
    margin-bottom: 17px;
    border: 2px solid #decfc2;
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    animation: public-chat-spin .8s linear infinite;
}

.public-chat__conversation {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    flex: 1 1 auto;
}

.public-chat__messages {
    min-height: 0;
    margin: 0;
    padding: 18px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #bfced1 transparent;
}

.public-chat__empty-log {
    margin: auto;
    padding: 24px;
    color: var(--chat-muted);
    font-size: 13px;
    text-align: center;
}

.public-chat__message {
    max-width: 84%;
    align-self: flex-start;
}

.public-chat__message--client {
    align-self: flex-end;
}

.public-chat__message-meta {
    margin: 0 4px 4px;
    color: var(--chat-muted);
    font-size: 10px;
    line-height: 1.2;
}

.public-chat__message--client .public-chat__message-meta {
    text-align: right;
}

.public-chat__bubble {
    padding: 10px 12px;
    border: 1px solid var(--chat-line);
    border-radius: 5px 14px 14px 14px;
    background: var(--chat-surface);
    color: #2b3234;
    box-shadow: 0 2px 8px rgba(27, 47, 51, .04);
    font-size: 13px;
    line-height: 1.48;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.public-chat__message--client .public-chat__bubble {
    border-color: #b9e1e7;
    border-radius: 14px 5px 14px 14px;
    background: var(--chat-primary-soft);
    color: var(--chat-ink);
}

.public-chat__message--system {
    max-width: 100%;
    align-self: center;
}

.public-chat__message--system .public-chat__message-meta {
    display: none;
}

.public-chat__message--system .public-chat__bubble {
    border: 0;
    background: transparent;
    box-shadow: none;
    color: var(--chat-muted);
    font-size: 11px;
    text-align: center;
}

.public-chat__composer {
    padding: 12px 13px 13px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 9px;
    border-top: 1px solid var(--chat-line);
    background: var(--chat-surface);
}

.public-chat__composer-field {
    min-width: 0;
}

.public-chat__composer .public-chat__textarea {
    min-height: 44px;
    max-height: 112px;
    margin: 0;
    padding: 10px 12px;
}

.public-chat__send {
    min-width: 44px;
    width: 44px;
    height: 44px;
    align-self: start;
    padding: 0;
    font-size: 0;
}

.public-chat__send::after {
    content: '↑';
    font-size: 21px;
    font-weight: 500;
}

.public-chat__composer-status {
    grid-column: 1 / -1;
}

.public-chat__closed-footer {
    display: grid;
    gap: 9px;
    padding: 13px 16px 16px;
    border-top: 1px solid var(--chat-line);
    background: var(--chat-surface);
}

.public-chat__closed-footer p {
    margin: 0;
    color: var(--chat-muted);
    font-size: 11px;
    line-height: 1.4;
}

.public-chat__hint {
    margin: 5px 2px 0;
    color: var(--chat-muted);
    font-size: 10px;
    line-height: 1.2;
}

.chat-dialog-open {
    overflow: hidden;
}

@keyframes public-chat-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 720px) {
    .public-chat__launcher {
        right: 0;
        bottom: max(94px, calc(78px + env(safe-area-inset-bottom, 0px)));
        width: 44px;
        min-width: 44px;
        height: 50px;
        padding: 0;
        border-radius: 14px 0 0 14px;
        border-right: 0;
    }

    .public-chat__launcher-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .public-chat__backdrop {
        bottom: 0;
        background: rgba(20, 22, 28, .4);
    }

    .public-chat__panel {
        top: max(8px, env(safe-area-inset-top, 0px));
        right: max(8px, env(safe-area-inset-right, 0px));
        bottom: max(80px, calc(66px + env(safe-area-inset-bottom, 0px)));
        left: max(8px, env(safe-area-inset-left, 0px));
        width: auto;
        height: auto;
        min-height: 0;
        border-radius: 16px 16px 10px 10px;
        transform: translateY(24px);
        transform-origin: center bottom;
    }

    .public-chat__panel[data-view='start'],
    .public-chat__panel[data-view='loading'],
    .public-chat__panel[data-view='error'] {
        top: auto;
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        height: auto;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
    }

    .public-chat__panel[data-view='start'] .public-chat__state,
    .public-chat__panel[data-view='loading'] .public-chat__state,
    .public-chat__panel[data-view='error'] .public-chat__state {
        min-height: 0;
    }

    .public-chat__header {
        min-height: 70px;
        padding: 16px 12px 12px 16px;
    }

    .public-chat__quiet-action { min-height: 38px; padding: 0 7px; font-size: 11px; }

    .public-chat__state {
        justify-content: flex-start;
        padding: 18px 16px;
        overflow: auto;
    }

    .public-chat__form {
        margin-top: 14px;
    }

    .public-chat__messages {
        padding: 15px 12px 10px;
    }

    .public-chat__message {
        max-width: 88%;
    }

    .public-chat__composer {
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0));
        grid-template-columns: minmax(0, 1fr) 48px;
    }

    .public-chat__send { min-width: 48px; width: 48px; padding: 0 6px; }

    .public-chat__hint {
        display: none;
    }
}

@media (max-width: 360px) {
    .public-chat__panel {
        right: max(4px, env(safe-area-inset-right, 0px));
        left: max(4px, env(safe-area-inset-left, 0px));
    }

    .public-chat__state {
        padding-right: 13px;
        padding-left: 13px;
    }

    .public-chat__topics {
        gap: 6px;
    }

    .public-chat__topic span {
        min-height: 33px;
        padding: 7px 9px;
        font-size: 11px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .public-chat *,
    .public-chat *::before,
    .public-chat *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media (forced-colors: active) {
    .public-chat__launcher,
    .public-chat__panel,
    .public-chat__primary,
    .public-chat__bubble,
    .public-chat__topic span {
        border: 1px solid ButtonText;
    }

    .public-chat__textarea:focus,
    .public-chat__phone:focus,
    .public-chat__privacy input:focus-visible {
        outline: 2px solid Highlight;
    }
}
