/* CHAT only: compact composer anchored to the viewport, not to page flow. */
#chatApp .composer-wrap {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 160;
    width: min(1240px, calc(100vw - 40px));
    padding: 6px clamp(14px, 4vw, 54px) max(7px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    background: linear-gradient(180deg, rgba(9,10,12,0), rgba(9,10,12,.97) 32%, rgba(9,10,12,.99));
    pointer-events: none;
}

#chatApp .composer-wrap > * {
    pointer-events: auto;
}

/* Keep participant chips visible without making the fixed bar taller. */
#chatApp .selected-participants {
    position: absolute;
    left: clamp(18px, 4vw, 58px);
    right: clamp(18px, 4vw, 58px);
    bottom: calc(100% - 3px);
    min-height: 0;
    max-height: 24px;
    margin: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

#chatApp .selected-participants::-webkit-scrollbar {
    display: none;
}

#chatApp .participant-chip {
    flex: 0 0 auto;
    min-height: 20px;
    padding: 0 7px;
    font-size: 9px;
}

/* Desktop composer becomes one compact row. It still grows when the user writes multiple lines. */
#chatApp .composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    min-height: 50px;
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(0,0,0,.34);
}

#chatApp .composer textarea {
    min-height: 42px;
    max-height: 120px;
    padding: 10px 10px 9px 14px;
    line-height: 1.35;
}

#chatApp .composer-footer {
    min-height: 42px;
    padding: 3px 5px 3px 0;
    gap: 8px;
    flex-wrap: nowrap;
}

#chatApp .composer-left {
    gap: 7px;
}

#chatApp .composer-hint {
    font-size: 9px;
    white-space: nowrap;
}

#chatApp .voice-button {
    width: 36px;
    height: 36px;
    min-height: 36px;
    flex: 0 0 36px;
}

#chatApp .send-button {
    min-width: 88px;
    height: 36px;
    min-height: 36px;
    border-radius: 10px;
}

#chatApp #stopButton {
    min-height: 36px;
    height: 36px;
    padding-inline: 9px;
}

/* The last messages and the thinking strip must never sit underneath the fixed composer. */
#chatApp .chat-feed {
    padding-bottom: 96px;
}

#chatApp .thinking-strip:not([hidden]) {
    margin-bottom: 70px;
}

@media (max-width: 980px) {
    /* On CHAT the mobile navigation sits above the composer instead of covering it. */
    body:has(#chatApp) .main-nav {
        bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    }

    body:has(#chatApp) .app-main {
        padding-bottom: calc(142px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 700px) {
    #chatApp .composer-wrap {
        width: 100vw;
        padding: 4px max(8px, env(safe-area-inset-left, 0px)) max(6px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-right, 0px));
    }

    #chatApp .selected-participants {
        left: max(10px, env(safe-area-inset-left, 0px));
        right: max(10px, env(safe-area-inset-right, 0px));
        max-height: 22px;
    }

    #chatApp .composer {
        grid-template-columns: minmax(0, 1fr) auto;
        min-height: 48px;
        border-radius: 13px;
    }

    #chatApp .composer textarea {
        min-height: 44px;
        max-height: 30dvh;
        padding: 9px 8px 8px 11px;
    }

    #chatApp .composer-footer {
        min-height: 40px;
        padding: 2px 4px 2px 0;
        gap: 5px;
        flex-wrap: nowrap;
    }

    #chatApp .composer-hint {
        display: none;
    }

    #chatApp .voice-button,
    #chatApp .send-button,
    #chatApp #stopButton {
        min-height: 38px;
        height: 38px;
    }

    #chatApp .voice-button {
        width: 38px;
        flex-basis: 38px;
    }

    #chatApp .send-button {
        min-width: 78px;
        padding-inline: 10px;
    }

    #chatApp .chat-feed {
        padding-bottom: 90px;
    }

    #chatApp .thinking-strip:not([hidden]) {
        margin-bottom: 64px;
    }
}

@media (max-width: 420px) {
    #chatApp #stopButton {
        padding-inline: 6px;
        font-size: 11px;
    }

    #chatApp .send-button {
        min-width: 72px;
    }

    #chatApp .voice-state {
        max-width: 112px;
    }
}
