:root {
    --chat-blue-1: #3f97f4;
    --chat-blue-2: #2d79d8;
    --chat-blue-3: #1f5fae;
    --chat-blue-soft: #eef6ff;
    --chat-blue-border: #cfe4ff;
    --chat-ink: #17324d;
}

.chat-widget-btn {
    position: fixed;
    right: 24px;
    bottom: calc(24px + var(--mobile-bottom-nav-space, 0px));
    width: 62px;
    height: 62px;
    padding: 8px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--chat-blue-1) 0%, var(--chat-blue-2) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 14px 32px rgba(45, 121, 216, 0.34);
    transition: width 0.24s ease, padding 0.24s ease, transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 10000;
    overflow: hidden;
    box-sizing: border-box;
}

.chat-widget-btn:not(.open):hover,
.chat-widget-btn:not(.open):focus-visible {
    width: 164px;
    padding: 8px 8px 8px 16px;
    justify-content: space-between;
    transform: translateY(-2px);
    box-shadow: 0 18px 36px rgba(45, 121, 216, 0.42);
}

.chat-btn-label {
    display: inline-flex;
    align-items: center;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 700;
    opacity: 0;
    transition: max-width 0.24s ease, opacity 0.2s ease, margin-right 0.24s ease;
}

.chat-widget-btn:not(.open):hover .chat-btn-label,
.chat-widget-btn:not(.open):focus-visible .chat-btn-label {
    max-width: 90px;
    margin-right: 12px;
    opacity: 1;
}

.chat-btn-icon,
.chat-btn-close {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 22px;
}

.chat-btn-icon i,
.chat-btn-close {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.chat-btn-close {
    display: none;
    font-size: 30px;
    line-height: 1;
}

.chat-widget-btn.open {
    width: 62px;
    padding: 8px;
    justify-content: center;
}

.chat-widget-btn.open .chat-btn-label,
.chat-widget-btn.open:hover .chat-btn-label {
    max-width: 0;
    margin-right: 0;
    opacity: 0;
}

.chat-widget-btn.open .chat-btn-icon {
    display: none;
}

.chat-widget-btn.open .chat-btn-close {
    display: flex;
}

.chat-widget-notif {
    position: absolute;
    top: 5px;
    right: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    display: none;
}

.chat-widget-notif.show {
    display: block;
}

.chat-widget-window {
    position: fixed;
    right: 24px;
    bottom: calc(98px + var(--mobile-bottom-nav-space, 0px));
    width: min(410px, calc(100vw - 40px));
    max-width: calc(100vw - 40px);
    max-height: min(760px, calc(100vh - 132px));
    border-radius: 28px;
    background: linear-gradient(180deg, #f7fbff 0%, #ffffff 100%);
    box-shadow: 0 28px 74px rgba(27, 73, 128, 0.24);
    overflow: hidden;
    display: none;
    flex-direction: column;
    z-index: 9999;
    border: 1px solid rgba(63, 151, 244, 0.16);
}

.chat-widget-window.show {
    display: flex;
    animation: chat-widget-in 0.24s ease;
}

@keyframes chat-widget-in {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-widget-header {
    padding: 18px 20px 16px;
    color: #fff;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.18), transparent 36%),
        linear-gradient(135deg, var(--chat-blue-1) 0%, var(--chat-blue-3) 100%);
    position: relative;
}

.chat-widget-header h4 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.chat-widget-header p {
    margin: 4px 0 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.88);
}

.chat-widget-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    cursor: pointer;
}

.chat-widget-intro {
    padding: 18px;
    background: #f7fbff;
}

.chat-widget-intro-card {
    border: 1px solid var(--chat-blue-border);
    border-radius: 22px;
    background: #fff;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-widget-intro label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 700;
    color: var(--chat-ink);
}

.chat-widget-intro input,
.chat-widget-input textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--chat-blue-border);
    border-radius: 16px;
    font-size: 14px;
    color: var(--chat-ink);
    box-sizing: border-box;
    background: #fff;
}

.chat-widget-intro input:focus,
.chat-widget-input textarea:focus {
    outline: none;
    border-color: var(--chat-blue-2);
    box-shadow: 0 0 0 4px rgba(63, 151, 244, 0.14);
}

.chat-widget-intro-submit,
.chat-widget-input button {
    border: 0;
    background: linear-gradient(135deg, var(--chat-blue-1) 0%, var(--chat-blue-2) 100%);
    color: #fff;
    cursor: pointer;
}

.chat-widget-intro-submit {
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 800;
}

.chat-widget-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.chat-widget-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-widget-profile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--chat-blue-border);
    border-radius: 20px;
    background: #fff;
}

.chat-widget-profile-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--chat-ink);
}

.chat-widget-profile-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b8aa8;
}

.chat-widget-profile-copy strong {
    font-size: 14px;
}

.chat-widget-profile-copy span:last-child {
    font-size: 12px;
    color: #5f7894;
}

.chat-widget-profile-edit {
    border: 0;
    background: transparent;
    color: var(--chat-blue-2);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.chat-widget-assistant {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.chat-widget-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #dbeeff 0%, #b8d9fb 100%);
    color: var(--chat-blue-3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    flex-shrink: 0;
}

.chat-widget-assistant-bubble {
    background: var(--chat-blue-soft);
    color: var(--chat-ink);
    border-radius: 18px;
    border-top-left-radius: 8px;
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.55;
    border: 1px solid #d9eafc;
}

.chat-widget-assistant-name {
    font-size: 14px;
    font-weight: 800;
    margin-bottom: 4px;
}

.chat-widget-assistant-bubble p {
    margin: 0;
}

.chat-widget-assistant-bubble p + p {
    margin-top: 4px;
}

.chat-widget-faq-title {
    margin-bottom: 10px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b8aa8;
}

.chat-widget-faq-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chat-widget-faq-item {
    border: 1px solid var(--chat-blue-border);
    border-radius: 16px;
    background: #fff;
    color: #406483;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.35;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-widget-faq-item:hover {
    border-color: var(--chat-blue-2);
    color: var(--chat-blue-2);
    background: var(--chat-blue-soft);
}

.chat-widget-stream {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 4px;
}

.cw-welcome-msg {
    padding: 11px 14px;
    border-radius: 16px;
    background: #fff;
    border: 1px solid var(--chat-blue-border);
    color: #51708f;
    font-size: 13px;
    line-height: 1.45;
}

.chat-widget-msg {
    display: flex;
    max-width: 82%;
}

.chat-widget-msg.cw-customer {
    align-self: flex-end;
}

.chat-widget-msg.cw-bot,
.chat-widget-msg.cw-admin {
    align-self: flex-start;
}

.cw-bubble {
    padding: 11px 14px;
    border-radius: 18px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.cw-customer .cw-bubble {
    background: linear-gradient(135deg, var(--chat-blue-1) 0%, var(--chat-blue-2) 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.cw-bot .cw-bubble,
.cw-admin .cw-bubble {
    background: #fff;
    color: var(--chat-ink);
    border: 1px solid var(--chat-blue-border);
    border-bottom-left-radius: 6px;
}

.cw-bot-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--chat-blue-soft);
    color: var(--chat-blue-3);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cw-time {
    display: block;
    margin-top: 6px;
    font-size: 10px;
    opacity: 0.7;
    text-align: right;
}

.cw-customer .cw-time {
    color: rgba(255, 255, 255, 0.82);
}

.cw-typing {
    display: none;
    align-items: center;
    gap: 5px;
    padding: 0 18px 10px;
}

.cw-typing.show {
    display: flex;
}

.cw-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #7fb7f7;
    animation: cw-typing 1s infinite ease-in-out;
}

.cw-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.cw-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes cw-typing {
    0%, 80%, 100% {
        transform: scale(0.7);
        opacity: 0.55;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chat-widget-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px 16px;
    border-top: 1px solid var(--chat-blue-border);
    background: rgba(255, 255, 255, 0.96);
}

.chat-widget-input textarea {
    flex: 1;
    min-height: 22px;
    max-height: 96px;
    resize: none;
}

.chat-widget-input button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 15px;
    box-shadow: 0 10px 22px rgba(45, 121, 216, 0.25);
}

@media (max-width: 768px) {
    body.public-page-product .chat-widget-btn,
    body.public-page-product .chat-widget-window {
        display: none !important;
    }
}

@media (max-width: 640px) {
    .chat-widget-btn {
        right: 16px;
        bottom: calc(16px + var(--mobile-bottom-nav-space, 0px));
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
    }

    .chat-widget-btn:hover,
    .chat-widget-btn:focus-visible {
        width: 40px;
    }

    .chat-widget-btn.open {
        width: 40px;
        height: 40px;
        padding: 0;
    }

    .chat-btn-label {
        display: none;
    }

    .chat-btn-icon,
    .chat-btn-close {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .chat-widget-window {
        right: 12px;
        bottom: calc(88px + var(--mobile-bottom-nav-space, 0px));
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        max-height: calc(100vh - 112px);
        border-radius: 24px;
    }

    .chat-widget-profile {
        flex-direction: column;
        align-items: flex-start;
    }

    .chat-widget-profile-edit {
        padding: 0;
    }

    .chat-widget-msg {
        max-width: 88%;
    }
}

@media (max-width: 420px) {
    .chat-widget-window {
        right: 8px;
        bottom: calc(82px + var(--mobile-bottom-nav-space, 0px));
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        max-height: calc(100vh - 96px);
        border-radius: 20px;
    }

    .chat-widget-scroll {
        padding: 12px 12px 8px;
    }

    .chat-widget-input {
        padding: 10px 12px 12px;
    }
}
