.cr-chat {
    --chat-accent: var(--accent, #c76043);
    --chat-accent-hover: var(--accent-hover, #a94d34);
    --chat-accent-dark: var(--cr-green-dark, #6a3a2a);
    --chat-surface: var(--surface-2, #fff8ef);
    --chat-soft: var(--accent-soft, #f3ddd3);
    --chat-border: var(--border, #eadbd0);
    --chat-text: var(--text, #2f2a24);
    --chat-muted: var(--muted, #7a6f64);
    font-family: var(--cr-font-base, "Manrope", sans-serif);
}

.cr-chat__toggle {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1079;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    color: var(--chat-surface);
    background: var(--chat-accent);
    border: 0;
    border-radius: 28px;
    box-shadow: 0 4px 16px rgba(106, 58, 42, 0.3);
    font: inherit;
    font-size: 15px;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.cr-chat__toggle:hover,
.cr-chat__toggle:focus-visible {
    color: var(--chat-surface);
    background: var(--chat-accent-hover);
    box-shadow: 0 6px 20px rgba(106, 58, 42, 0.4);
    transform: translateY(-1px);
}

.cr-chat__toggle:focus-visible,
.cr-chat__close:focus-visible,
.cr-chat__send:focus-visible,
.cr-chat__input:focus-visible {
    outline: 3px solid rgba(199, 96, 67, 0.28);
    outline-offset: 2px;
}

.cr-chat__window {
    position: fixed;
    right: 24px;
    bottom: 84px;
    z-index: 1080;
    display: flex;
    width: min(380px, calc(100vw - 32px));
    height: 540px;
    max-height: calc(100dvh - 116px);
    overflow: hidden;
    flex-direction: column;
    color: var(--chat-text);
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(106, 58, 42, 0.2);
}

.cr-chat__window[hidden] {
    display: none;
}

.cr-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    color: var(--chat-surface);
    background: var(--chat-accent);
}

.cr-chat__header-info {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.cr-chat__header-info > span:last-child {
    display: grid;
    min-width: 0;
}

.cr-chat__avatar {
    display: inline-flex;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    align-items: center;
    justify-content: center;
    color: var(--chat-surface);
    border: 2px solid currentColor;
    border-radius: 50%;
}

.cr-chat__title {
    color: inherit;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.cr-chat__subtitle {
    margin-top: 2px;
    overflow: hidden;
    color: var(--chat-soft);
    font-size: 12px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cr-chat__close {
    display: inline-flex;
    padding: 6px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    color: var(--chat-surface);
    background: transparent;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

.cr-chat__close:hover {
    background: rgba(255, 248, 239, 0.16);
}

.cr-chat__messages {
    display: flex;
    min-height: 0;
    padding: 16px;
    overflow-y: auto;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    overscroll-behavior: contain;
}

.cr-chat__message {
    display: flex;
    max-width: 86%;
}

.cr-chat__message--user {
    align-self: flex-end;
}

.cr-chat__message--bot {
    align-self: flex-start;
}

.cr-chat__bubble {
    padding: 10px 14px;
    overflow-wrap: anywhere;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.cr-chat__message--user .cr-chat__bubble {
    color: var(--chat-surface);
    background: var(--chat-accent);
    border-bottom-right-radius: 4px;
}

.cr-chat__message--bot .cr-chat__bubble {
    color: var(--chat-text);
    background: var(--chat-soft);
    border-bottom-left-radius: 4px;
}

.cr-chat__message--bot .cr-chat__bubble a {
    color: var(--chat-accent-dark);
    font-weight: 700;
    text-decoration-color: rgba(106, 58, 42, 0.45);
    text-underline-offset: 2px;
}

.cr-chat__message--bot .cr-chat__bubble a:hover,
.cr-chat__message--bot .cr-chat__bubble a:focus-visible {
    color: var(--chat-accent-hover);
    text-decoration-color: currentColor;
}

.cr-chat__message--typing .cr-chat__bubble {
    color: var(--chat-accent-dark);
    font-style: italic;
    opacity: 0.76;
}

.cr-chat__form {
    padding: 10px 12px 12px;
    background: var(--chat-surface);
    border-top: 1px solid var(--chat-border);
}

.cr-chat__input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cr-chat__input {
    min-width: 0;
    padding: 10px 14px;
    flex: 1 1 auto;
    color: var(--chat-text);
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    font: inherit;
    font-size: 14px;
}

.cr-chat__input::placeholder {
    color: #a89383;
}

.cr-chat__input:focus {
    border-color: var(--chat-accent);
}

.cr-chat__send {
    display: inline-flex;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    align-items: center;
    justify-content: center;
    color: var(--chat-surface);
    background: var(--chat-accent);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.cr-chat__send:hover {
    background: var(--chat-accent-hover);
}

.cr-chat__send:disabled {
    color: var(--chat-muted);
    background: var(--chat-border);
    cursor: wait;
}

.cr-chat__notice {
    margin: 8px 0 0;
    color: var(--chat-muted);
    font-size: 10px;
    line-height: 1.35;
    text-align: center;
}

.cr-chat__messages::-webkit-scrollbar {
    width: 5px;
}

.cr-chat__messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

@media (max-width: 575.98px) {
    body.cr-chat-open {
        overflow: hidden;
    }

    .cr-chat__toggle {
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        padding: 14px;
    }

    .cr-chat__toggle span {
        display: none;
    }

    .cr-chat__window {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100dvh;
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    .cr-chat__header {
        padding-top: calc(14px + env(safe-area-inset-top));
    }

    .cr-chat__form {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .cr-chat__toggle {
        transition: none;
    }
}
