/* Floating AI chat: button + resizable panel.
   Desktop: the panel is at most 30% of the viewport width. Mobile (<= 768px): the panel fills the viewport minus the margins,
   so it never overflows even at the smallest resolution (320px); the native resize handle does not work with touch there. */
.iftm-ai-host {
    --iftm-ai-gap: 1rem;
    --iftm-ai-fab: 3rem;
}

.iftm-ai-fab {
    position: fixed;
    left: var(--iftm-ai-gap);
    bottom: var(--iftm-ai-gap);
    z-index: 1050;
    width: var(--iftm-ai-fab);
    height: var(--iftm-ai-fab);
    border: 0;
    border-radius: 50%;
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
    cursor: pointer;
}

.iftm-ai-panel {
    position: fixed;
    left: var(--iftm-ai-gap);
    bottom: calc(var(--iftm-ai-gap) + var(--iftm-ai-fab) + .5rem);
    z-index: 1050;
    box-sizing: border-box;
    width: min(28rem, 30vw);
    height: min(36rem, calc(100dvh - 6rem));
    min-width: min(16rem, 30vw);
    min-height: min(14rem, calc(100dvh - 6rem));
    max-width: 30vw;
    max-height: calc(100dvh - 6rem);
    overflow: hidden;
    resize: both;
    /* rtl moves the native resize handle (and its NE-SW cursor) to the bottom-left; the 180 degree rotation puts it at the top-right. */
    direction: rtl;
    transform: rotate(180deg);
    border: 1px solid var(--bs-border-color, #ccc);
    border-radius: .5rem;
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}

.iftm-ai-panel-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    direction: ltr;
    transform: rotate(180deg);
}

.iftm-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
    padding: .25rem .5rem;
    border-bottom: 1px solid var(--bs-border-color, #ccc);
    font-weight: 600;
}

.iftm-ai-close {
    border: 0;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
}

.iftm-ai-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.iftm-ai-body .xaf-ai-chat {
    height: 100%;
}

@media (max-width: 768px) {
    .iftm-ai-host {
        --iftm-ai-gap: .5rem;
    }

    .iftm-ai-panel {
        width: calc(100vw - 2 * var(--iftm-ai-gap));
        height: calc(100dvh - 2 * var(--iftm-ai-gap) - var(--iftm-ai-fab) - .5rem);
        min-width: 0;
        min-height: 0;
        max-width: calc(100vw - 2 * var(--iftm-ai-gap));
        max-height: calc(100dvh - 2 * var(--iftm-ai-gap) - var(--iftm-ai-fab) - .5rem);
        resize: none;
    }
}
