.sacw-root,
.sacw-root * {
    box-sizing: border-box;
}

.sacw-root {
    --sacw-bg: #ffffff;
    --sacw-text: #0f172a;
    --sacw-muted: #64748b;
    --sacw-soft: #f8fafc;
    --sacw-border: rgba(148, 163, 184, .24);
    --sacw-shadow: 0 24px 70px rgba(15, 23, 42, .24);
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sacw-toggle {
    width: 64px;
    height: 64px;
    border-radius: 999px;
    border: 0;
    background: linear-gradient(135deg, var(--sacw-brand), var(--sacw-accent));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 18px 40px rgba(37, 99, 235, .34);
    position: relative;
    transition: transform .2s ease, box-shadow .2s ease;
}

.sacw-toggle:hover,
.sacw-toggle:focus {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 24px 50px rgba(37, 99, 235, .42);
    outline: none;
}

.sacw-icon-close {
    display: none;
}

.sacw-root.is-open .sacw-icon-chat {
    display: none;
}

.sacw-root.is-open .sacw-icon-close {
    display: block;
}

.sacw-pulse {
    position: absolute;
    inset: -6px;
    border-radius: inherit;
    border: 2px solid color-mix(in srgb, var(--sacw-brand) 45%, transparent);
    animation: sacwPulse 2s infinite;
    pointer-events: none;
}

.sacw-root.is-open .sacw-pulse {
    display: none;
}

@keyframes sacwPulse {
    0% { transform: scale(.86); opacity: .8; }
    100% { transform: scale(1.25); opacity: 0; }
}

.sacw-window {
    width: min(390px, calc(100vw - 28px));
    height: min(650px, calc(100vh - 108px));
    background: var(--sacw-bg);
    color: var(--sacw-text);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--sacw-shadow);
    border: 1px solid rgba(255,255,255,.72);
    position: absolute;
    right: 0;
    bottom: 82px;
    display: flex;
    flex-direction: column;
    transform-origin: right bottom;
    animation: sacwIn .22s ease both;
}

.sacw-window[hidden] {
    display: none;
}

@keyframes sacwIn {
    from { opacity: 0; transform: translateY(18px) scale(.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.sacw-header {
    padding: 18px 18px 20px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    background:
        radial-gradient(circle at top right, rgba(255,255,255,.24), transparent 34%),
        linear-gradient(135deg, var(--sacw-brand), var(--sacw-accent));
}

.sacw-avatar {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    background: rgba(255,255,255,.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}

.sacw-heading {
    min-width: 0;
    flex: 1;
}

.sacw-heading strong,
.sacw-heading span {
    display: block;
}

.sacw-heading strong {
    font-size: 17px;
    line-height: 1.25;
    letter-spacing: -.01em;
}

.sacw-heading span {
    margin-top: 3px;
    font-size: 12.5px;
    line-height: 1.4;
    opacity: .88;
}

.sacw-close {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 0;
    background: rgba(255,255,255,.16);
    color: #fff;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.sacw-body {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 42%);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sacw-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px 8px;
    scrollbar-width: thin;
}

.sacw-message-row {
    display: flex;
    margin: 0 0 10px;
}

.sacw-message-row.is-user {
    justify-content: flex-end;
}

.sacw-message {
    max-width: 82%;
    padding: 11px 13px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.sacw-message-assistant {
    background: #fff;
    border: 1px solid var(--sacw-border);
    color: var(--sacw-text);
    border-bottom-left-radius: 6px;
    box-shadow: 0 8px 26px rgba(15, 23, 42, .06);
}

.sacw-message-user {
    background: linear-gradient(135deg, var(--sacw-brand), var(--sacw-accent));
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 10px 26px rgba(37, 99, 235, .22);
}

.sacw-faqs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 16px 16px;
    border-top: 1px solid rgba(226, 232, 240, .7);
}

.sacw-faq {
    border: 1px solid rgba(37, 99, 235, .18);
    background: rgba(37, 99, 235, .08);
    color: var(--sacw-brand);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 12.5px;
    white-space: nowrap;
    cursor: pointer;
    transition: background .16s ease, transform .16s ease;
}

.sacw-faq:hover,
.sacw-faq:focus {
    background: rgba(37, 99, 235, .13);
    transform: translateY(-1px);
    outline: none;
}

.sacw-form {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: #fff;
    border-top: 1px solid var(--sacw-border);
}

.sacw-form input {
    flex: 1;
    width: 100%;
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, .36);
    background: var(--sacw-soft);
    color: var(--sacw-text);
    padding: 0 15px;
    font-size: 14px;
    outline: none;
}

.sacw-form input:focus {
    border-color: color-mix(in srgb, var(--sacw-brand) 55%, #fff);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--sacw-brand) 13%, transparent);
}

.sacw-form button {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 0;
    background: linear-gradient(135deg, var(--sacw-brand), var(--sacw-accent));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.sacw-form.is-loading button {
    opacity: .72;
    cursor: wait;
}

.sacw-powered {
    padding: 0 0 10px;
    text-align: center;
    color: var(--sacw-muted);
    background: #fff;
    font-size: 11px;
}

.sacw-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    min-width: 54px;
}

.sacw-typing span {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #94a3b8;
    animation: sacwTyping 1s infinite ease-in-out;
}

.sacw-typing span:nth-child(2) { animation-delay: .16s; }
.sacw-typing span:nth-child(3) { animation-delay: .32s; }

@keyframes sacwTyping {
    0%, 80%, 100% { transform: translateY(0); opacity: .45; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 480px) {
    .sacw-root {
        right: 14px;
        bottom: 14px;
    }

    .sacw-window {
        width: calc(100vw - 28px);
        height: min(620px, calc(100vh - 100px));
        border-radius: 24px;
        bottom: 78px;
    }

    .sacw-toggle {
        width: 58px;
        height: 58px;
    }
}

.sacw-human-row {
    padding: 0 16px 14px;
    background: #fff;
}

.sacw-human-button {
    width: 100%;
    border: 1px solid rgba(37, 99, 235, .18);
    background: linear-gradient(135deg, rgba(37, 99, 235, .08), rgba(124, 58, 237, .08));
    color: var(--sacw-brand);
    border-radius: 16px;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.sacw-human-button:hover,
.sacw-human-button:focus {
    background: linear-gradient(135deg, rgba(37, 99, 235, .13), rgba(124, 58, 237, .13));
    outline: none;
}

.sacw-handoff-panel {
    margin: 0 16px 14px;
    padding: 14px;
    border: 1px solid rgba(37, 99, 235, .14);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 10px 26px rgba(15, 23, 42, .07);
}

.sacw-handoff-panel[hidden] {
    display: none;
}

.sacw-handoff-panel p {
    margin: 0 0 10px;
    color: var(--sacw-text);
    font-size: 13px;
    line-height: 1.45;
}

.sacw-handoff-form {
    display: grid;
    gap: 8px;
}

.sacw-handoff-form input,
.sacw-handoff-form textarea {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, .36);
    background: var(--sacw-soft);
    color: var(--sacw-text);
    padding: 10px 12px;
    font-size: 13px;
    outline: none;
}

.sacw-handoff-form textarea {
    resize: vertical;
    min-height: 76px;
}

.sacw-handoff-form input:focus,
.sacw-handoff-form textarea:focus {
    border-color: color-mix(in srgb, var(--sacw-brand) 55%, #fff);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--sacw-brand) 12%, transparent);
}

.sacw-handoff-submit,
.sacw-whatsapp-link,
.sacw-handoff-prompt button {
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--sacw-brand), var(--sacw-accent));
    color: #fff;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.sacw-whatsapp-link {
    display: block;
    margin-top: 10px;
}

.sacw-handoff-form.is-loading .sacw-handoff-submit {
    opacity: .72;
    cursor: wait;
}

.sacw-handoff-prompt {
    max-width: 86%;
    padding: 12px;
    border: 1px solid rgba(37, 99, 235, .16);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    background: #fff;
    box-shadow: 0 8px 26px rgba(15, 23, 42, .06);
    display: grid;
    gap: 9px;
}

.sacw-handoff-prompt span {
    font-size: 13px;
    color: var(--sacw-text);
    line-height: 1.4;
}

.sacw-handoff-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.sacw-handoff-top strong {
    font-size: 14px;
    color: var(--sacw-text);
}

.sacw-handoff-close {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 999px;
    background: rgba(148, 163, 184, .16);
    color: var(--sacw-muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.sacw-handoff-close:hover,
.sacw-handoff-close:focus {
    background: rgba(148, 163, 184, .28);
    color: var(--sacw-text);
    outline: none;
}
