/* Visitor chat widget */

.cw-root {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    font-family: Inter, ui-sans-serif, system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
}

@media (max-width: 480px) {
    .cw-root {
        bottom: 0;
        right: 0;
        left: 0;
        align-items: stretch;
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }

    .cw-root.is-open {
        padding: 0;
        inset: 0;
        top: 0;
        z-index: 99999;
    }

    .cw-teaser {
        max-width: none;
    }

    .cw-launcher {
        width: 100%;
        justify-content: center;
        height: 3.25rem;
    }

    .cw-root.is-open .cw-launcher {
        display: none;
    }
}

.cw-root.hidden {
    display: none !important;
}

body.cw-scroll-lock {
    overflow: hidden !important;
    touch-action: none;
}

@media (max-width: 640px) {
    .cw-panel {
        position: fixed;
        inset: 0;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        z-index: 99999;
        animation: cw-panel-mobile-in 0.28s ease-out;
    }

    .cw-header {
        padding-top: calc(0.875rem + env(safe-area-inset-top, 0px));
    }

    .cw-header__close {
        width: 2.75rem;
        height: 2.75rem;
        background: rgba(255, 255, 255, 0.18);
    }

    .cw-composer {
        padding-bottom: calc(0.875rem + env(safe-area-inset-bottom, 0px));
    }

    .cw-messages {
        padding: 0.875rem;
    }
}

@keyframes cw-panel-mobile-in {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
}

/* Panel - desktop */

@media (min-width: 641px) {
    .cw-panel {
        position: absolute;
        bottom: 4.25rem;
        right: 0;
        z-index: 1;
        width: min(calc(100vw - 2rem), 360px);
        height: min(75vh, 580px);
        display: flex;
        flex-direction: column;
        border-radius: 1.25rem;
        background: #fff;
        overflow: hidden;
        box-shadow: 0 28px 60px rgba(15, 23, 42, 0.22);
        transform-origin: bottom right;
        animation: cw-panel-in 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
    }
}

.cw-panel {
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.cw-panel.hidden {
    display: none !important;
}

@keyframes cw-panel-in {
    from { opacity: 0; transform: translateY(16px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Teaser bubble */
.cw-teaser {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    max-width: 320px;
    padding: 0.75rem 1rem;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(15, 23, 42, 0.06);
    cursor: pointer;
    animation: cw-teaser-in 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.cw-teaser.hidden {
    display: none !important;
}

@keyframes cw-teaser-in {
    from { opacity: 0; transform: translateY(8px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.cw-teaser__dot {
    flex-shrink: 0;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
}

.cw-teaser__text {
    flex: 1;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.35;
}

.cw-teaser__dismiss {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: 9999px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.cw-teaser__dismiss:hover {
    background: #e2e8f0;
}

/* Launcher pill */
.cw-launcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0 1.25rem 0 1rem;
    height: 3.5rem;
    border: none;
    border-radius: 9999px;
    background: linear-gradient(135deg, #022429 0%, #03363d 50%, #0a7a87 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 28px rgba(3, 54, 61, 0.45);
    transition: transform 0.2s, box-shadow 0.2s;
}

.cw-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 36px rgba(3, 54, 61, 0.5);
}

.cw-launcher__label {
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.cw-launcher__icon {
    width: 1.375rem;
    height: 1.375rem;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.cw-launcher__icon--close {
    position: absolute;
    right: 1.125rem;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.cw-root.is-open .cw-launcher__label,
.cw-root.is-open .cw-launcher__icon--chat {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.cw-root.is-open .cw-launcher {
    width: 3.5rem;
    padding: 0;
    justify-content: center;
}

.cw-root.is-open .cw-launcher__icon--close {
    position: static;
    opacity: 1;
    transform: none;
}

.cw-launcher__pulse {
    position: absolute;
    inset: -5px;
    border-radius: 9999px;
    border: 2px solid #30aabc;
    opacity: 0;
    pointer-events: none;
}

.cw-root.has-unread .cw-launcher__pulse {
    animation: cw-pulse 2s ease-out infinite;
}

@keyframes cw-pulse {
    0% { transform: scale(1); opacity: 0.75; }
    100% { transform: scale(1.2); opacity: 0; }
}

.cw-launcher__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 1.375rem;
    height: 1.375rem;
    padding: 0 0.35rem;
    border-radius: 9999px;
    background: #f43f5e;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(244, 63, 94, 0.5);
}

.cw-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1.125rem 1rem;
    background: linear-gradient(135deg, #022429 0%, #03363d 45%, #0a7a87 100%);
    color: #fff;
}

.cw-header__avatar {
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.cw-header__logo {
    max-width: 1.75rem;
    height: auto;
}

.cw-header__title {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.cw-header__status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.15rem;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.85);
}

.cw-status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
    background: #34d399;
    box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.35);
    animation: cw-blink 2.4s ease-in-out infinite;
}

@keyframes cw-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.cw-header__close {
    margin-left: auto;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    border-radius: 0.625rem;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cw-header__close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: linear-gradient(180deg, #f4f7f8 0%, #eef2f4 100%);
}

.cw-msg {
    display: flex;
    margin-bottom: 0.75rem;
    animation: cw-msg-in 0.22s ease-out;
}

@keyframes cw-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.cw-msg.is-visitor { justify-content: flex-end; }
.cw-msg.is-inbound { justify-content: flex-start; }

.cw-bubble {
    max-width: 88%;
    border-radius: 1.125rem;
    padding: 0.7rem 0.95rem;
    font-size: 0.875rem;
    line-height: 1.5;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.cw-bubble.is-visitor {
    background: linear-gradient(145deg, #03363d, #065a63);
    color: #fff;
    border-bottom-right-radius: 0.3rem;
}

.cw-bubble.is-bot,
.cw-bubble.is-agent {
    background: #fff;
    color: #1e293b;
    border: 1px solid #dbe4e8;
    border-bottom-left-radius: 0.3rem;
}

.cw-bubble.is-agent {
    border-color: #a5e9f0;
}

.cw-bubble__sender {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.6875rem;
    font-weight: 800;
    margin-bottom: 0.3rem;
    color: #0d9488;
}

.cw-bubble__avatar {
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 9999px;
    background: linear-gradient(135deg, #30aabc, #0d9488);
    color: #fff;
    font-size: 0.5625rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cw-bubble__meta {
    font-size: 0.5625rem;
    color: #94a3b8;
    margin-top: 0.3rem;
}

.cw-bubble.is-visitor .cw-bubble__meta {
    text-align: right;
    color: rgba(255, 255, 255, 0.65);
}

.cw-welcome {
    text-align: center;
    padding: 1.25rem 0.5rem 0.5rem;
}

.cw-welcome__icon {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 0.75rem;
    border-radius: 9999px;
    background: linear-gradient(145deg, rgba(48, 170, 188, 0.2), rgba(3, 54, 61, 0.08));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0a7a87;
}

.cw-welcome__title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #334155;
}

.cw-welcome__text {
    font-size: 0.8125rem;
    color: #64748b;
    margin-top: 0.35rem;
    line-height: 1.45;
}

.cw-typing {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem 0.5rem;
    font-size: 0.75rem;
    color: #64748b;
    background: #eef2f4;
}

.cw-typing.hidden {
    display: none !important;
}

.cw-typing__bubble {
    display: inline-flex;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    border-bottom-left-radius: 0.3rem;
}

.cw-typing__dots span {
    display: inline-block;
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 9999px;
    background: #94a3b8;
    animation: cw-dot 1.2s ease-in-out infinite;
}

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

@keyframes cw-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.cw-composer {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
    background: #fff;
    border-top: 1px solid #e8ecee;
}

.cw-composer textarea {
    flex: 1;
    resize: none;
    border: 1px solid #d1dbe0;
    border-radius: 0.875rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.4;
    min-height: 2.625rem;
    max-height: 6.5rem;
    background: #f8fafb;
}

.cw-composer textarea:focus {
    outline: none;
    border-color: #30aabc;
    box-shadow: 0 0 0 3px rgba(48, 170, 188, 0.2);
    background: #fff;
}

.cw-composer__send {
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    border: none;
    border-radius: 0.875rem;
    background: linear-gradient(145deg, #03363d, #065a63);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(3, 54, 61, 0.3);
}

.cw-composer__send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.cw-error {
    flex-shrink: 0;
    margin: 0 1rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 0.75rem;
    font-weight: 600;
}

.cw-error.hidden {
    display: none !important;
}

.cw-composer.is-disabled textarea,
.cw-composer.is-disabled button {
    opacity: 0.55;
    pointer-events: none;
}

.cw-composer.is-connecting textarea::placeholder {
    color: #94a3b8;
}

.cw-footer {
    flex-shrink: 0;
    text-align: center;
    padding: 0.375rem 1rem 0.625rem;
    font-size: 0.625rem;
    font-weight: 600;
    color: #94a3b8;
    background: #fff;
}
