*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    overscroll-behavior-x: none;
    -webkit-text-size-adjust: 100%;
}

body[data-chat-scroll-locked="1"] {
    overflow: hidden !important;
    overscroll-behavior: none;
}

.bs-chat-widget {
    position: fixed;
    right: max(18px, calc(env(safe-area-inset-right, 0px) + 18px));
    bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 18px));
    z-index: 140;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 14px;
    pointer-events: none;
}

.bs-chat-widget > * {
    pointer-events: auto;
}

.bs-chat-toggle {
    width: 68px;
    height: 68px;
    border: none;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #091d35;
    background: linear-gradient(135deg, #a0833c 0%, #d7bb74 100%);
    box-shadow:
        0 22px 44px rgba(160, 131, 60, 0.28),
        0 10px 20px rgba(0, 0, 0, 0.24),
        inset 0 1px 0 rgba(255, 255, 255, 0.25);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease;
    position: relative;
}

.bs-chat-toggle::before {
    content: "";
    position: absolute;
    inset: -7px;
    border-radius: inherit;
    background: radial-gradient(circle, rgba(215, 187, 116, 0.20) 0%, rgba(215, 187, 116, 0) 72%);
    z-index: -1;
    pointer-events: none;
}

.bs-chat-toggle:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow:
        0 28px 50px rgba(160, 131, 60, 0.34),
        0 12px 24px rgba(0, 0, 0, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.bs-chat-toggle:active {
    transform: translateY(0) scale(0.98);
}

.bs-chat-toggle:focus-visible,
.bs-chat-close:focus-visible,
.bs-chat-send:focus-visible,
.bs-chat-input:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 4px rgba(160, 131, 60, 0.16),
        0 0 0 1px rgba(215, 187, 116, 0.34);
}

.bs-chat-toggle svg {
    width: 30px;
    height: 30px;
    display: block;
}

.bs-chat-panel {
    width: min(100vw - 32px, 390px);
    height: min(72vh, 600px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 26px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background:
        radial-gradient(circle at top right, rgba(160, 131, 60, 0.12), transparent 30%),
        linear-gradient(180deg, rgba(10, 21, 35, 0.98), rgba(6, 14, 24, 0.98));
    box-shadow:
        0 32px 80px rgba(0, 0, 0, 0.42),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    transform-origin: bottom right;
    animation: bsChatPanelIn 0.2s ease;
    overscroll-behavior: contain;
}

.bs-chat-panel[hidden] {
    display: none !important;
}

.bs-chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 16px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(255, 255, 255, 0.03);
}

.bs-chat-head-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.bs-chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03)),
        rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex: 0 0 auto;
    overflow: hidden;
}

.bs-chat-avatar img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 0 8px rgba(215, 187, 116, 0.16));
}

.bs-chat-head-info strong {
    display: block;
    color: #fff;
    font-size: 16px;
    line-height: 1.15;
    margin-bottom: 3px;
}

.bs-chat-head-info span {
    display: block;
    color: rgba(245, 247, 251, 0.64);
    font-size: 13px;
    line-height: 1.35;
}

.bs-chat-close {
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    color: #fff;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease;
    flex: 0 0 auto;
}

.bs-chat-close:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(160, 131, 60, 0.24);
    transform: translateY(-1px);
}

.bs-chat-body {
    flex: 1 1 auto;
    padding: 16px 14px 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.bs-chat-body::-webkit-scrollbar {
    width: 10px;
}

.bs-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.bs-chat-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.10);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.bs-chat-message {
    display: flex;
    width: 100%;
    max-width: 100%;
}

.bs-chat-message-user {
    justify-content: flex-end;
}

.bs-chat-message-bot {
    justify-content: flex-start;
}

.bs-chat-bubble {
    max-width: min(86%, 290px);
    padding: 12px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.14);
}

.bs-chat-message-user .bs-chat-bubble {
    border-top-right-radius: 6px;
    color: #091d35;
    background: linear-gradient(135deg, #a0833c 0%, #d7bb74 100%);
}

.bs-chat-message-bot .bs-chat-bubble {
    border-top-left-radius: 6px;
    color: #f5f7fb;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.bs-chat-meta {
    margin-top: 6px;
    font-size: 11px;
    line-height: 1.3;
    opacity: 0.65;
}

.bs-chat-message-user .bs-chat-meta {
    text-align: right;
    color: rgba(9, 29, 53, 0.76);
}

.bs-chat-message-bot .bs-chat-meta {
    color: rgba(245, 247, 251, 0.56);
}

.bs-chat-system {
    text-align: center;
    padding: 0 10px;
}

.bs-chat-system span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: rgba(245, 247, 251, 0.68);
    border: 1px solid rgba(255, 255, 255, 0.07);
    font-size: 12px;
    line-height: 1.35;
}

.bs-chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 18px;
}

.bs-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: rgba(245, 247, 251, 0.72);
    display: block;
    animation: bsChatDot 1.1s infinite ease-in-out;
}

.bs-chat-typing span:nth-child(2) {
    animation-delay: 0.16s;
}

.bs-chat-typing span:nth-child(3) {
    animation-delay: 0.32s;
}

.bs-chat-form {
    padding: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(255, 255, 255, 0.03);
}

.bs-chat-label {
    display: block;
    margin-bottom: 9px;
    color: rgba(245, 247, 251, 0.88);
    font-size: 13px;
    font-weight: 700;
}

.bs-chat-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    align-items: center;
}

.bs-chat-input {
    min-width: 0;
    width: 100%;
    height: 52px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding: 0 15px;
    font-size: 15px;
    outline: none;
    transition:
        border-color 0.18s ease,
        background 0.18s ease,
        box-shadow 0.18s ease;
}

.bs-chat-input::placeholder {
    color: rgba(245, 247, 251, 0.44);
}

.bs-chat-input:focus {
    border-color: rgba(160, 131, 60, 0.84);
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 0 0 4px rgba(160, 131, 60, 0.10);
}

.bs-chat-send {
    height: 52px;
    min-width: 108px;
    padding: 0 18px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 800;
    color: #091d35;
    background: linear-gradient(135deg, #a0833c 0%, #d7bb74 100%);
    box-shadow: 0 16px 30px rgba(160, 131, 60, 0.20);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease;
}

.bs-chat-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 20px 34px rgba(160, 131, 60, 0.24);
}

.bs-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.bs-chat-widget.is-open .bs-chat-toggle {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.9);
    pointer-events: none;
}

.bs-chat-widget.is-loading .bs-chat-send {
    opacity: 0.75;
}

@keyframes bsChatPanelIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes bsChatDot {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.45;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 820px) {
    .bs-chat-widget {
        right: max(14px, calc(env(safe-area-inset-right, 0px) + 14px));
        bottom: max(14px, calc(env(safe-area-inset-bottom, 0px) + 14px));
    }

    .bs-chat-toggle {
        width: 62px;
        height: 62px;
    }

    .bs-chat-toggle svg {
        width: 28px;
        height: 28px;
    }

    .bs-chat-panel {
        width: min(100vw - 24px, 380px);
        height: min(78vh, 620px);
        border-radius: 22px;
    }

    .bs-chat-head {
        padding: 14px;
    }

    .bs-chat-avatar {
        width: 44px;
        height: 44px;
    }

    .bs-chat-avatar img {
        width: 26px;
        height: 26px;
    }

    .bs-chat-body {
        padding: 14px 12px 12px;
    }

    .bs-chat-form {
        padding: 12px;
    }

    .bs-chat-bubble {
        max-width: 90%;
        font-size: 14px;
    }
}

@media (max-width: 640px) {
    .bs-chat-widget {
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        gap: 0;
        align-items: stretch;
    }

    .bs-chat-toggle {
        width: 60px;
        height: 60px;
        position: absolute;
        right: max(10px, calc(env(safe-area-inset-right, 0px) + 10px));
        bottom: max(10px, calc(env(safe-area-inset-bottom, 0px) + 10px));
    }

    .bs-chat-toggle svg {
        width: 28px;
        height: 28px;
    }

    .bs-chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100dvh;
        max-width: 100%;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        box-shadow: none;
        transform-origin: center center;
        overscroll-behavior: none;
    }

    .bs-chat-head {
        padding:
            calc(env(safe-area-inset-top, 0px) + 14px)
            14px
            14px;
    }

    .bs-chat-avatar {
        width: 48px;
        height: 48px;
    }

    .bs-chat-avatar img {
        width: 30px;
        height: 30px;
    }

    .bs-chat-head-info strong {
        font-size: 18px;
        margin-bottom: 4px;
    }

    .bs-chat-head-info span {
        font-size: 14px;
    }

    .bs-chat-close {
        width: 44px;
        height: 44px;
        font-size: 30px;
        border-radius: 14px;
    }

    .bs-chat-body {
        padding: 12px;
        gap: 12px;
        overscroll-behavior: contain;
    }

    .bs-chat-bubble {
        max-width: 88%;
        padding: 12px 14px;
        font-size: 14px;
        line-height: 1.6;
        border-radius: 18px;
    }

    .bs-chat-meta {
        font-size: 11px;
        margin-top: 6px;
    }

    .bs-chat-system span {
        min-height: 30px;
        padding: 7px 12px;
        font-size: 12px;
    }

    .bs-chat-typing span {
        width: 7px;
        height: 7px;
    }

    .bs-chat-form {
        width: 100%;
        max-width: 100%;
        padding:
            12px
            12px
            calc(env(safe-area-inset-bottom, 0px) + 12px);
    }

    .bs-chat-label {
        margin-bottom: 8px;
        font-size: 13px;
    }

    .bs-chat-input-row {
        grid-template-columns: minmax(0, 1fr) 56px;
        gap: 8px;
        width: 100%;
        max-width: 100%;
    }

    .bs-chat-input {
        width: 100%;
        min-width: 0;
        height: 52px;
        padding: 0 15px;
        font-size: 16px;
        border-radius: 16px;
    }

    .bs-chat-send {
        min-width: 56px;
        width: 56px;
        height: 52px;
        padding: 0;
        border-radius: 16px;
        font-size: 0;
        line-height: 0;
        position: relative;
        overflow: hidden;
        justify-self: stretch;
    }

    .bs-chat-send::before {
        content: "➜";
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        font-size: 20px;
        line-height: 1;
        color: #091d35;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bs-chat-widget *,
    .bs-chat-widget *::before,
    .bs-chat-widget *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}