.ta-chat {
    position: fixed;
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    z-index: 80;
    width: max-content;
    max-width: calc(100% - 24px);
    box-sizing: border-box;
    font-family: inherit;
}

.ta-chat[hidden] { display: none !important; }

.ta-chat-launcher {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 12px 12px;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 12px 32px rgba(8, 23, 44, .18);
    font: inherit;
    font-weight: 700;
    font-size: 14px;
}

.ta-chat-launcher-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
}

.ta-chat-launcher-icon svg {
    width: 22px;
    height: 22px;
}

.ta-chat-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #e64848;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 18px;
}

.ta-chat-panel {
    /* Stay on the viewport, not inside the FAB. Viewport-width units overflow on iOS. */
    position: fixed;
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    left: auto;
    width: min(380px, calc(100% - 24px));
    max-width: calc(100% - 24px);
    height: min(520px, calc(100dvh - 110px));
    max-height: calc(100dvh - 110px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 18px;
    box-shadow: 0 18px 52px rgba(8, 23, 44, .18);
}

.ta-chat-panel[hidden] { display: none; }

.ta-chat-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
}

.ta-chat-head strong {
    display: block;
    font-size: 15px;
}

.ta-chat-head span {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    opacity: .75;
}

.ta-chat-close {
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    opacity: .7;
}

.ta-chat-log {
    flex: 1;
    overflow: auto;
    padding: 12px 14px;
    display: grid;
    align-content: start;
    gap: 8px;
}

.ta-chat-bubble {
    max-width: 86%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.ta-chat-bubble small {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    opacity: .7;
}

.ta-chat-bubble.is-client { justify-self: end; }
.ta-chat-bubble.is-admin { justify-self: start; }
.ta-chat-empty {
    font-size: 13px;
    line-height: 1.45;
    opacity: .8;
}

.ta-chat-form {
    padding: 10px 12px 12px;
    display: grid;
    gap: 8px;
    min-width: 0;
}

.ta-chat-identity {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.ta-chat-identity[hidden] { display: none; }

.ta-chat-identity input,
.ta-chat-compose textarea {
    width: 100%;
    box-sizing: border-box;
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
    font-size: 13px;
}

.ta-chat-consent {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-size: 11px;
    line-height: 1.35;
}

.ta-chat-consent span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.ta-chat-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
    min-width: 0;
}

.ta-chat-compose textarea {
    resize: none;
    min-height: 44px;
    min-width: 0;
}

.ta-chat-send {
    border: 0;
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.ta-chat-error {
    margin: 0;
    font-size: 12px;
    color: #b91c1c;
}

.ta-chat-landing .ta-chat-launcher {
    background: #07111f;
    color: #fff;
}

.ta-chat-landing .ta-chat-panel {
    background: #fff;
    color: #172235;
    border: 1px solid rgba(20, 36, 61, .10);
}

.ta-chat-landing .ta-chat-head {
    background: #07111f;
    color: #fff;
}

.ta-chat-landing .ta-chat-close { color: #fff; }

.ta-chat-landing .ta-chat-log { background: #f4f7fb; }

.ta-chat-landing .ta-chat-bubble.is-client {
    background: #2864f0;
    color: #fff;
}

.ta-chat-landing .ta-chat-bubble.is-admin {
    background: #fff;
    border: 1px solid rgba(20, 36, 61, .10);
}

.ta-chat-landing .ta-chat-identity input,
.ta-chat-landing .ta-chat-compose textarea {
    border: 1px solid #dce4f0;
    background: #fff;
    color: #172235;
}

.ta-chat-landing .ta-chat-send {
    background: #2864f0;
    color: #fff;
}

.ta-chat-app .ta-chat-launcher {
    background: var(--btn-primary-bg, #0F172A);
    color: var(--btn-primary-text, #fff);
}

.ta-chat-app .ta-chat-panel {
    background: var(--card, #fff);
    color: var(--text, #0F172A);
    border: 1px solid var(--border, #E2E8F0);
}

.ta-chat-app .ta-chat-head {
    background: var(--bg, #F8FAFC);
    border-bottom: 1px solid var(--border, #E2E8F0);
}

.ta-chat-app .ta-chat-log { background: var(--bg, #F8FAFC); }

.ta-chat-app .ta-chat-bubble.is-client {
    background: var(--btn-primary-bg, #0F172A);
    color: var(--btn-primary-text, #fff);
}

.ta-chat-app .ta-chat-bubble.is-admin {
    background: var(--card, #fff);
    border: 1px solid var(--border, #E2E8F0);
}

.ta-chat-app .ta-chat-identity input,
.ta-chat-app .ta-chat-compose textarea {
    border: 1px solid var(--border, #E2E8F0);
    background: var(--card, #fff);
    color: var(--text, #0F172A);
}

.ta-chat-app .ta-chat-send {
    background: var(--btn-primary-bg, #0F172A);
    color: var(--btn-primary-text, #fff);
}

@media (max-width: 640px) {
    .ta-chat {
        right: max(10px, env(safe-area-inset-right, 0px));
        bottom: max(10px, env(safe-area-inset-bottom, 0px));
    }
    .ta-chat-launcher-label { display: none; }
    .ta-chat-launcher { padding: 12px; }
    .ta-chat-panel {
        left: max(8px, env(safe-area-inset-left, 0px));
        right: max(8px, env(safe-area-inset-right, 0px));
        bottom: calc(66px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        height: min(70dvh, 520px);
        max-height: calc(100dvh - 90px);
    }
}

@supports not (height: 100dvh) {
    .ta-chat-panel {
        height: min(520px, calc(100vh - 110px));
        max-height: calc(100vh - 110px);
    }
    @media (max-width: 640px) {
        .ta-chat-panel {
            height: min(70vh, 520px);
            max-height: calc(100vh - 90px);
        }
    }
}
