/* ==========================================================================
   TalPress AI Support – Chat Widget
   Figma Community (node 12:165): white header, light canvas, indigo user
   bubbles, neutral composer + send, thread avatars. Full RTL mirror support.
   ========================================================================== */

/* ── Font: inherited from website ── */

/* ── Custom Properties ── */
:root {
    /* Primary purple palette (from Figma) */
    --tp-purple-500: #6366F1;
    --tp-purple-600: #4F46E5;
    --tp-purple-400: #818CF8;
    --tp-purple-300: #A5B4FC;
    --tp-purple-50: #EEF2FF;

    /* Neutrals */
    --tp-gray-50: #F9FAFB;
    --tp-gray-100: #F3F4F6;
    --tp-gray-200: #E5E7EB;
    --tp-gray-300: #D1D5DB;
    --tp-gray-400: #9CA3AF;
    --tp-gray-500: #6B7280;
    --tp-gray-600: #4B5563;
    --tp-gray-700: #374151;
    --tp-gray-800: #1F2937;
    --tp-gray-900: #111827;

    /* Functional */
    --tp-white: #FFFFFF;
    --tp-bg-widget: var(--tp-white);
    --tp-bg-messages: #f7faff;
    --tp-bg-user-bubble: #575ff6;
    --tp-bg-bot-bubble: #e7edf3;
    --tp-text-user: var(--tp-white);
    --tp-text-bot: #333;
    --tp-text-muted: #99a1b7;
    --tp-border: var(--tp-gray-200);
    --tp-border-figma: rgba(120, 132, 151, .5);
    --tp-header-title: #070709;
    --tp-link-on-bot: #575ff6;
    --tp-header-icon: #788497;
    --tp-send-icon: #575ff6;
    --tp-send-icon-hover: #4a51d9;

    /* Sizing (Figma: 325 x 552) */
    --tp-widget-w: 325px;
    --tp-widget-h: 552px;

    /* Radii */
    --tp-radius-window: 20px;
    --tp-radius-bubble: 24px;
    --tp-radius-input: 24px;

    /* Shadows */
    --tp-shadow-window: 0 16px 48px -12px rgba(15, 23, 42, .12),
        0 4px 16px -4px rgba(15, 23, 42, .06);
    --tp-shadow-toggle: 0 8px 28px -4px rgba(99, 102, 241, .45);

    /* Transitions */
    --tp-ease: cubic-bezier(.4, 0, .2, 1);
    --tp-dur: .3s;

    /* Font – inherits from the website's theme */
    --tp-font: inherit;
    --tp-toggle-size: 36px;
    --tp-toggle-radius: 50px;
    --tp-toggle-bg: linear-gradient(135deg, var(--tp-purple-500) 0%, var(--tp-purple-600) 100%);
    --tp-toggle-icon: #ffffff;
    --tp-toggle-border: none;
    --tp-toggle-window-gap: 16px;
    --tp-toggle-offset-x: 24px;
    --tp-toggle-offset-y: 24px;
    /* Extra vertical reserve on narrow viewports (browser chrome + other floating buttons). */
    --tp-mobile-external-reserve: 72px;
}

/* ── Reset scoping ── */
.talpress-ai-chat-wrapper,
.talpress-ai-chat-wrapper *,
.talpress-ai-chat-wrapper *::before,
.talpress-ai-chat-wrapper *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.talpress-ai-chat-wrapper {
    font-family: var(--tp-font);
    font-size: 14px;
    line-height: 1.5;
    position: fixed;
    z-index: 999999;
    direction: ltr;
    text-align: left;
}

/* ==========================================================================
   RTL – Mirrored layout (header, rows, composer) + RTL text in bubbles
   ========================================================================== */

.talpress-rtl .talpress-ai-header {
    direction: rtl;
}

.talpress-rtl .talpress-ai-msg-row,
.talpress-rtl .talpress-ai-typing-row {
    direction: rtl;
}

.talpress-rtl .talpress-ai-msg {
    direction: rtl;
    text-align: right;
}

.talpress-rtl .talpress-ai-date-separator {
    direction: rtl;
}

.talpress-rtl .talpress-ai-input-shell {
    flex-direction: row-reverse;
    direction: ltr;
    padding-inline: 5px 12px;
}

.talpress-rtl .talpress-ai-send-btn svg {
    transform: scaleX(-1);
}

.talpress-rtl .talpress-ai-input {
    direction: rtl;
    text-align: right;
}

.talpress-rtl .talpress-ai-footer {
    direction: rtl;
}

.talpress-rtl .talpress-ai-escalation-card {
    direction: rtl;
    text-align: right;
}

.talpress-rtl .talpress-ai-esc-form input {
    direction: rtl;
    text-align: right;
}

/* ==========================================================================
   Toggle Button (size/colors from admin via CSS variables on wrapper)
   ========================================================================== */
.talpress-ai-toggle {
    width: var(--tp-toggle-size, 36px) !important;
    height: var(--tp-toggle-size, 36px) !important;
    box-sizing: border-box !important;
    border: var(--tp-toggle-border, none) !important;
    border-radius: var(--tp-toggle-radius, 50px) !important;
    background: var(--tp-toggle-bg, linear-gradient(135deg, var(--tp-purple-500) 0%, var(--tp-purple-600) 100%)) !important;
    color: var(--tp-toggle-icon, #ffffff) !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: var(--tp-shadow-toggle) !important;
    transition: transform var(--tp-dur) var(--tp-ease),
        box-shadow var(--tp-dur) var(--tp-ease) !important;
    position: relative !important;
    outline: none !important;
}

.talpress-ai-toggle svg {
    width: calc(var(--tp-toggle-size, 36px) * 0.45) !important;
    height: calc(var(--tp-toggle-size, 36px) * 0.45) !important;
    flex-shrink: 0 !important;
    display: block !important;
}

.talpress-ai-toggle:hover {
    transform: scale(1.08) !important;
    box-shadow: 0 12px 36px -4px rgba(99, 102, 241, .55) !important;
}

.talpress-ai-toggle:focus-visible {
    outline: 3px solid var(--tp-purple-300) !important;
    outline-offset: 3px !important;
}

/* Icon swap */
.talpress-ai-toggle .talpress-ai-icon-close {
    display: none !important;
}

.talpress-ai-toggle[aria-expanded="true"] .talpress-ai-icon-chat {
    display: none !important;
}

.talpress-ai-toggle[aria-expanded="true"] .talpress-ai-icon-close {
    display: block !important;
}

/* Pulse */
@keyframes tp-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, .5);
    }

    70% {
        box-shadow: 0 0 0 16px rgba(99, 102, 241, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

.talpress-ai-toggle:not([aria-expanded="true"]) {
    animation: tp-pulse 2.5s ease-out 3 !important;
}

/* ── Toggle Tooltip (appears beside the bubble) ── */
.talpress-ai-toggle-tooltip {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    background: var(--tp-gray-800);
    color: var(--tp-white);
    font-size: 12px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s var(--tp-ease);
    z-index: -1;
    /* Default: appears to the LEFT (toggle is bottom-right) */
    right: calc(100% + 12px);
    left: auto;
}

/* Arrow pointing right (toward the bubble) */
.talpress-ai-toggle-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    /* Default: arrow points RIGHT */
    left: 100%;
    border-left-color: var(--tp-gray-800);
}

/* Show on hover, hide when chat is open */
.talpress-ai-toggle:not([aria-expanded="true"]):hover .talpress-ai-toggle-tooltip {
    opacity: 1;
}

/* Bottom-left placement: tooltip goes to the RIGHT */
.talpress-ai-launcher-bl .talpress-ai-toggle-tooltip {
    right: auto;
    left: calc(100% + 12px);
}

.talpress-ai-launcher-bl .talpress-ai-toggle-tooltip::after {
    left: auto;
    right: 100%;
    border-left-color: transparent;
    border-right-color: var(--tp-gray-800);
}

/* ==========================================================================
   Chat Window
   ========================================================================== */
.talpress-ai-window {
    position: absolute;
    bottom: calc(var(--tp-toggle-size, 36px) + var(--tp-toggle-window-gap, 16px));
    right: 0;
    width: min(var(--tp-widget-w), calc(100vw - var(--tp-toggle-offset-x, 24px) - 16px));
    height: min(var(--tp-widget-h), calc(100vh - var(--tp-toggle-size, 36px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - 40px));
    max-width: min(var(--tp-widget-w), calc(100vw - var(--tp-toggle-offset-x, 24px) - 16px));
    max-height: min(var(--tp-widget-h), calc(100vh - var(--tp-toggle-size, 36px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - 40px));
    background: var(--tp-bg-widget);
    border-radius: var(--tp-radius-window);
    box-shadow: var(--tp-shadow-window);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: tp-slide-in .35s var(--tp-ease) forwards;
}

.talpress-ai-launcher-bl .talpress-ai-window {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.talpress-ai-window[hidden] {
    display: none !important;
}

@keyframes tp-slide-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(.94);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.talpress-rtl .talpress-ai-window {
    left: auto;
    right: 0;
    transform-origin: bottom left;
}

.talpress-ai-chat-wrapper.talpress-rtl.talpress-ai-launcher-bl .talpress-ai-window {
    left: 0;
    right: auto;
    transform-origin: bottom left;
}

/* ── Header (Figma: white bar, title, close) ── */
.talpress-ai-header {
    background: var(--tp-bg-widget);
    color: var(--tp-header-title);
    min-height: 52px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    gap: 12px;
    border-bottom: 1px solid var(--tp-border-figma);
}

.talpress-ai-header-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.talpress-rtl .talpress-ai-header-text {
    align-items: flex;
    text-align: right;
}

.talpress-ai-header-title {
    display: block;
    font-weight: 600;
    font-size: 16px;
    line-height: 1.25;
    letter-spacing: -.01em;
    color: var(--tp-header-title);
}

.talpress-ai-header-subtitle {
    display: block;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--tp-text-muted);
}

/* Header actions container */
.talpress-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* Shared header button base (reset + close) */
.talpress-ai-header-btn {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    padding: 0;
    border: 0 !important;
    border-style: none !important;
    border-width: 0 !important;
    border-radius: 50%;
    box-shadow: none !important;
    background: transparent !important;
    background-image: none !important;
    font-family: inherit;
    line-height: 1;
    color: var(--tp-header-icon);
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: color var(--tp-dur) var(--tp-ease),
        background var(--tp-dur) var(--tp-ease);
}

.talpress-ai-header-btn:hover {
    color: var(--tp-header-title);
    background: rgba(120, 132, 151, .12) !important;
}

.talpress-ai-header-btn:focus-visible {
    outline: 3px solid var(--tp-purple-400);
    outline-offset: 2px;
}

/* ── Custom Tooltip (CSS-only, no title attr) ── */
.talpress-ai-tooltip {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    background: var(--tp-gray-800);
    color: var(--tp-white);
    font-size: 11px;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s var(--tp-ease);
    z-index: 10;
}

/* Arrow */
.talpress-ai-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: var(--tp-gray-800);
}

.talpress-ai-header-btn:hover .talpress-ai-tooltip {
    opacity: 1;
}

/* ==========================================================================
   Messages Area
   ========================================================================== */
.talpress-ai-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 16px;
    background: var(--tp-bg-messages);
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

/* Scrollbar */
.talpress-ai-messages::-webkit-scrollbar {
    width: 4px;
}

.talpress-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.talpress-ai-messages::-webkit-scrollbar-thumb {
    background: var(--tp-gray-300);
    border-radius: 4px;
}

/* ── Date separator (Figma: centered muted date) ── */
.talpress-ai-date-separator {
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--tp-text-muted);
    padding: 12px 0 6px;
    user-select: none;
}

/* ── Message row (bot gets avatar) ── */
.talpress-ai-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: tp-msg-in .25s ease-out;
}

.talpress-ai-msg-row--user {
    justify-content: flex-end;
}

@keyframes tp-msg-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Bot avatar (no ring — soft fill like Figma photo well) */
.talpress-ai-msg-avatar {
    width: 29px;
    height: 29px;
    border-radius: 50%;
    border: none;
    background: var(--tp-bg-bot-bubble);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--tp-link-on-bot);
}

.talpress-ai-msg-avatar--img {
    background: transparent;
}

.talpress-ai-msg-avatar svg {
    width: 15px;
    height: 15px;
}

.talpress-ai-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* ── Bubbles ── */
.talpress-ai-msg {
    max-width: 78%;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* User bubble (Figma: indigo, tail bottom-right in LTR) */
.talpress-ai-msg-user {
    background: var(--tp-bg-user-bubble);
    color: var(--tp-text-user);
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) 4px var(--tp-radius-bubble);
    align-self: flex-end;
}

/* Bot bubble (Figma: gray fill, tail bottom-left in LTR) */
.talpress-ai-msg-bot {
    background: var(--tp-bg-bot-bubble);
    color: var(--tp-text-bot);
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) var(--tp-radius-bubble) 4px;
}

.talpress-rtl .talpress-ai-msg-user {
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) var(--tp-radius-bubble) 4px;
}

.talpress-rtl .talpress-ai-msg-bot {
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) 4px var(--tp-radius-bubble);
}

/* Links inside bot messages */
.talpress-ai-msg-bot a {
    color: var(--tp-link-on-bot);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color var(--tp-dur) var(--tp-ease);
}

.talpress-ai-msg-bot a:hover {
    color: var(--tp-purple-600);
}

/* ── Typing indicator ── */
.talpress-ai-typing-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: tp-msg-in .25s ease-out;
}

.talpress-ai-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: var(--tp-bg-bot-bubble);
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) var(--tp-radius-bubble) 4px;
}

.talpress-rtl .talpress-ai-typing {
    border-radius: var(--tp-radius-bubble) 4px var(--tp-radius-bubble) var(--tp-radius-bubble);
}

.talpress-ai-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tp-gray-400);
    animation: tp-bounce .6s ease-in-out infinite;
}

.talpress-ai-typing-dot:nth-child(2) {
    animation-delay: .15s;
}

.talpress-ai-typing-dot:nth-child(3) {
    animation-delay: .3s;
}

@keyframes tp-bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-5px);
    }
}

/* ==========================================================================
   Input Area — Figma: one rounded field; send sits inside (not beside)
   ========================================================================== */
.talpress-ai-input-area {
    padding: 12px 14px;
    border-top: 1px solid var(--tp-border-figma);
    display: block;
    background: var(--tp-bg-widget);
    flex-shrink: 0;
}

.talpress-ai-input-shell {
    display: flex;
    align-items: flex-end;
    width: 100%;
    gap: 6px;
    padding-block: 4px;
    padding-inline: 12px 5px;
    border: 1px solid var(--tp-border-figma);
    border-radius: var(--tp-radius-input);
    background: var(--tp-white);
    transition: border-color var(--tp-dur) var(--tp-ease),
        box-shadow var(--tp-dur) var(--tp-ease);
}

.talpress-ai-input-shell:focus-within {
    border-color: var(--tp-purple-400);
    box-shadow: 0 0 0 2px rgba(129, 140, 248, .22);
}

.talpress-ai-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding-block: 8px;
    padding-inline: 0 4px;
    font-family: var(--tp-font);
    font-size: 13px;
    line-height: 1.45;
    resize: none;
    outline: none;
    max-height: 100px;
    background: transparent;
    color: var(--tp-gray-900);
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}

.talpress-ai-input::placeholder {
    color: var(--tp-text-bot);
    opacity: .85;
}

.talpress-ai-input:focus {
    outline: none;
}

/* Send: icon on transparent pad — theme-safe, no border */
#talpress-ai-send.talpress-ai-send-btn {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    padding: 0;
    border: 0 !important;
    border-style: none !important;
    border-width: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    background-image: none !important;
    font-family: inherit;
    line-height: 1;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 50%;
    color: var(--tp-send-icon);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: center;
    transition: color var(--tp-dur) var(--tp-ease),
        background var(--tp-dur) var(--tp-ease),
        opacity var(--tp-dur) var(--tp-ease);
}

#talpress-ai-send.talpress-ai-send-btn:hover {
    color: var(--tp-send-icon-hover);
    background: rgba(87, 95, 246, .1) !important;
}

#talpress-ai-send.talpress-ai-send-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    color: var(--tp-text-muted);
    background: transparent !important;
}

#talpress-ai-send.talpress-ai-send-btn:focus-visible {
    outline: 3px solid var(--tp-purple-400);
    outline-offset: 1px;
}

#talpress-ai-send.talpress-ai-send-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

.talpress-ai-reset-btn {
    padding-right: 0 !important;
    padding-left: 0 !important;
}

/* ==========================================================================
   Inline Escalation Card (rendered inside messages area)
   ========================================================================== */
.talpress-ai-escalation-card {
    background: var(--tp-purple-50);
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) var(--tp-radius-bubble) 4px;
    padding: 16px;
    max-width: 85%;
    animation: tp-msg-in .3s ease-out;
}

.talpress-rtl .talpress-ai-escalation-card {
    border-radius: var(--tp-radius-bubble) var(--tp-radius-bubble) 4px var(--tp-radius-bubble);
}

.talpress-ai-esc-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--tp-purple-600);
    margin-bottom: 10px;
}

.talpress-ai-esc-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.talpress-ai-esc-form input {
    border: 1px solid var(--tp-border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    font-family: var(--tp-font);
    outline: none;
    background: var(--tp-white);
    color: var(--tp-gray-900);
    transition: border-color var(--tp-dur) var(--tp-ease);
    width: 100%;
}

.talpress-ai-esc-form input:focus {
    border-color: var(--tp-purple-400);
}

.talpress-ai-esc-btn {
    background: linear-gradient(135deg, var(--tp-purple-500), var(--tp-purple-600));
    color: var(--tp-white) !important;
    border: none;
    border-radius: 10px;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--tp-font);
    cursor: pointer;
    transition: opacity var(--tp-dur) var(--tp-ease);
    width: 100%;
}

.talpress-ai-esc-btn:hover {
    opacity: .9;
}

.talpress-ai-esc-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.talpress-ai-esc-btn:focus-visible {
    outline: 3px solid var(--tp-purple-300);
    outline-offset: 2px;
}

.talpress-ai-esc-success {
    font-size: 14px;
    font-weight: 500;
    color: var(--tp-gray-700);
    line-height: 1.5;
}

/* ── Powered-by footer ── */
.talpress-ai-footer {
    text-align: center;
    padding: 6px 0 8px;
    font-size: 11px;
    color: var(--tp-text-muted);
    background: var(--tp-bg-widget);
    border-top: 1px solid var(--tp-border-figma);
    flex-shrink: 0;
    user-select: none;
}

.talpress-ai-footer a {
    color: var(--tp-link-on-bot);
    text-decoration: none;
    font-weight: 600;
}

.talpress-ai-footer a:hover {
    text-decoration: underline;
}

.talpress-ai-footer a:focus-visible {
    outline: 2px solid var(--tp-link-on-bot);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ── Screen reader utility ── */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Responsive (narrow viewports — phones, small tablets, short desktop windows)
   ========================================================================== */
@media (max-width: 900px) {
    .talpress-ai-window {
        width: min(var(--tp-widget-w), calc(100vw - var(--tp-toggle-offset-x, 24px) - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 16px));
        max-width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 12px);
        height: min(var(--tp-widget-h), calc(100vh - min(var(--tp-toggle-size, 36px), 56px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--tp-mobile-external-reserve, 72px)));
        max-height: min(var(--tp-widget-h), calc(100vh - min(var(--tp-toggle-size, 36px), 56px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--tp-mobile-external-reserve, 72px)));
        border-radius: 16px;
        bottom: calc(min(var(--tp-toggle-size, 36px), 56px) + var(--tp-toggle-window-gap, 16px));
    }

    .talpress-ai-toggle {
        width: min(var(--tp-toggle-size, 36px), 56px) !important;
        height: min(var(--tp-toggle-size, 36px), 56px) !important;
    }

    @supports (height: 100dvh) {
        .talpress-ai-window {
            height: min(var(--tp-widget-h), calc(100dvh - min(var(--tp-toggle-size, 36px), 56px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--tp-mobile-external-reserve, 72px)));
            max-height: min(var(--tp-widget-h), calc(100dvh - min(var(--tp-toggle-size, 36px), 56px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--tp-mobile-external-reserve, 72px)));
        }
    }

    /* svh last: stricter cap when dynamic and small units disagree (other FABs / URL bar). */
    @supports (height: 100svh) {
        .talpress-ai-window {
            height: min(var(--tp-widget-h), 84svh, calc(100svh - min(var(--tp-toggle-size, 36px), 56px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--tp-mobile-external-reserve, 72px)));
            max-height: min(var(--tp-widget-h), 84svh, calc(100svh - min(var(--tp-toggle-size, 36px), 56px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--tp-mobile-external-reserve, 72px)));
        }
    }
}

@supports (height: 100dvh) {
    @media (min-width: 769px) {
        .talpress-ai-window {
            height: min(var(--tp-widget-h), calc(100dvh - var(--tp-toggle-size, 36px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - 40px));
            max-height: min(var(--tp-widget-h), calc(100dvh - var(--tp-toggle-size, 36px) - var(--tp-toggle-window-gap, 16px) - var(--tp-toggle-offset-y, 24px) - 40px));
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .talpress-ai-toggle {
        animation: none !important;
    }

    .talpress-ai-window {
        animation: none;
    }

    .talpress-ai-msg-row,
    .talpress-ai-typing-row {
        animation: none;
    }

    .talpress-ai-typing-dot {
        animation: none;
    }

    .talpress-ai-escalation-card {
        animation: none;
    }
}