:root {
    --aisa-rail-width: clamp(350px, 24vw, 410px);
}

.aisa-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1045;
    display: flex;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: #4935b8;
    border: none;
    border-radius: 50%;
    box-shadow: 0 10px 28px rgba(11, 21, 48, .28);
    cursor: pointer;
}

.aisa-launcher:hover { background: #38288e; }
.aisa-launcher:focus-visible { outline: 3px solid var(--accent, #adffcf); outline-offset: 3px; }
.aisa-launcher svg { width: 26px; height: 26px; }

.aisa-panel {
    position: fixed;
    right: 20px;
    bottom: 90px;
    z-index: 1055;
    display: flex;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 140px);
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(11, 21, 48, .12);
    border-radius: 22px;
    box-shadow: 0 20px 60px rgba(11, 21, 48, .24);
    font-family: inherit;
}

.aisa-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    color: #fff;
    background: var(--ink, #0b1530);
    font-size: 15px;
    font-weight: 700;
}

.aisa-header-title { display: grid; gap: 1px; }
.aisa-header-title small { color: var(--accent, #adffcf); font-size: 9px; letter-spacing: .15em; }
.aisa-sheet-grip { display: none; width: 38px; height: 4px; background: #d8dce5; border-radius: 999px; }

.aisa-header button {
    color: #fff;
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    opacity: .75;
    cursor: pointer;
}

.aisa-header button:hover { opacity: 1; }

.aisa-messages {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px;
    background: #f7f8fb;
    font-size: 13.5px;
}

.aisa-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 10px;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.aisa-msg.user { align-self: flex-end; color: #fff; background: var(--ink, #0b1530); }
.aisa-msg.assistant { align-self: flex-start; color: #182033; background: #fff; border: 1px solid #e3e7ef; }
.aisa-suggestions { display: flex; flex-wrap: wrap; gap: 7px; }
.aisa-suggestions button { padding: 7px 10px; color: #4939a5; background: #eeeaff; border: 1px solid #dcd4ff; border-radius: 999px; font: inherit; font-size: 12px; cursor: pointer; }
.aisa-suggestions button:hover { background: #e2dcff; }
.aisa-msg.assistant:empty::after { content: '…'; opacity: .5; }
.aisa-msg a { color: #4939a5; font-weight: 600; text-decoration: underline; }
.aisa-msg a:hover { color: #372b80; }

.aisa-input-row {
    display: flex;
    min-width: 0;
    flex: 0 0 auto;
    gap: 8px;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #eee;
}

.aisa-input-row input {
    width: 100%;
    min-width: 0;
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #d7dbe4;
    border-radius: 12px;
    outline: none;
    font-size: 13.5px;
}

.aisa-input-row input:focus { border-color: #7864e6; box-shadow: 0 0 0 3px rgba(88, 68, 201, .12); }

.aisa-input-row button {
    min-width: 72px;
    flex: 0 0 auto;
    padding: 0 14px;
    color: #fff;
    background: #4935b8;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

.aisa-input-row button:hover { background: #38288e; }
.aisa-input-row button:focus-visible { outline: 3px solid var(--accent, #adffcf); outline-offset: 2px; }
.aisa-input-row button:disabled { opacity: .5; cursor: default; }
.aisa-mobile-composer { display: none; }
.aisa-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Agentic storefront: the assistant is part of the layout on large screens. */
@media (min-width: 1280px) {
    html.aisa-agentic-layout body { padding-right: var(--aisa-rail-width); }
    .aisa-layout-agentic .aisa-launcher { display: none; }

    .aisa-layout-agentic .aisa-panel {
        top: 0;
        right: 0;
        bottom: 0;
        display: flex !important;
        width: var(--aisa-rail-width);
        max-width: none;
        height: auto;
        max-height: none;
        border-width: 0 0 0 1px;
        border-radius: 0;
        box-shadow: -14px 0 36px rgba(11, 21, 48, .08);
    }

    .aisa-layout-agentic .aisa-header { min-height: 72px; padding-inline: 22px; }
    .aisa-layout-agentic .aisa-header [data-aisa-close] { display: none; }
    .aisa-layout-agentic .aisa-messages { padding: 20px; }
    .aisa-layout-agentic:not(.aisa-has-conversation) .aisa-messages { justify-content: center; }
    .aisa-layout-agentic .aisa-input-row { padding: 14px; }
}

/* Tablet: a conventional right-side drawer leaves the catalogue intact. */
@media (min-width: 768px) and (max-width: 1279px) {
    .aisa-layout-agentic .aisa-panel {
        top: 0;
        right: 0;
        bottom: 0;
        width: min(410px, 100vw);
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: 20px 0 0 20px;
    }
}

@media (max-width: 991px) {
    .aisa-launcher { right: 14px; bottom: calc(82px + env(safe-area-inset-bottom)); }

    .aisa-root:not(.aisa-layout-agentic).aisa-is-open .aisa-launcher {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    .aisa-root:not(.aisa-layout-agentic) .aisa-panel {
        top: max(10px, env(safe-area-inset-top));
        right: 10px;
        bottom: calc(82px + env(safe-area-inset-bottom));
        left: 10px;
        width: auto;
        height: auto;
        min-width: 0;
        max-width: none;
        max-height: none;
        border-radius: 18px;
    }

    .aisa-root:not(.aisa-layout-agentic) .aisa-input-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }
}

/* Mobile: a visible composer expands into a sheet above bottom navigation. */
@media (max-width: 767px) {
    html.aisa-agentic-layout body { padding-bottom: calc(148px + env(safe-area-inset-bottom)); }
    .aisa-layout-agentic .aisa-launcher { display: none; }

    .aisa-layout-agentic .aisa-mobile-composer {
        position: fixed;
        right: 10px;
        bottom: calc(74px + env(safe-area-inset-bottom));
        left: 10px;
        z-index: 1040;
        display: grid;
        min-width: 0;
        grid-template-columns: 38px minmax(0, 1fr) 44px;
        align-items: center;
        gap: 6px;
        padding: 7px;
        background: rgba(255, 255, 255, .97);
        border: 1px solid rgba(11, 21, 48, .14);
        border-radius: 18px;
        box-shadow: 0 -8px 30px rgba(11, 21, 48, .14);
        backdrop-filter: blur(16px);
    }

    .aisa-layout-agentic.aisa-is-open .aisa-mobile-composer { display: none; }

    .aisa-mobile-composer > svg { width: 20px; height: 20px; margin-inline: auto; color: #4935b8; }

    .aisa-mobile-composer input {
        width: 100%;
        min-width: 0;
        padding: 9px 4px;
        background: transparent;
        border: 0;
        outline: 0;
        font-size: 16px;
    }

    .aisa-mobile-composer button {
        display: grid;
        width: 42px;
        height: 42px;
        place-items: center;
        color: #fff;
        background: #4935b8;
        border: 0;
        border-radius: 13px;
    }

    .aisa-mobile-composer button svg { width: 19px; height: 19px; }

    .aisa-layout-agentic .aisa-panel {
        top: auto;
        right: 0;
        bottom: calc(66px + env(safe-area-inset-bottom));
        left: 0;
        width: auto;
        min-width: 0;
        max-width: none;
        height: 72vh;
        height: min(72dvh, 640px);
        max-height: calc(100dvh - 86px - env(safe-area-inset-bottom));
        border-width: 1px 0 0;
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -18px 50px rgba(11, 21, 48, .2);
    }

    .aisa-layout-agentic .aisa-header { position: relative; min-height: 66px; padding: 20px 14px 10px; }
    .aisa-layout-agentic .aisa-sheet-grip { position: absolute; top: 8px; left: 50%; display: block; transform: translateX(-50%); }
    .aisa-layout-agentic .aisa-messages { padding: 12px; }
    .aisa-layout-agentic .aisa-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 8px; }
    .aisa-layout-agentic .aisa-input-row button { min-width: 60px; padding-inline: 12px; }

    html.aisa-panel-open .mobile-bottom-nav [data-open-shopping-assistant] { color: var(--accent-dark, #6047d6); }
}

@media (prefers-reduced-motion: reduce) {
    .aisa-launcher, .aisa-panel, .aisa-mobile-composer { transition: none !important; }
}
