/* Phone layout: 640px and narrower. Loaded last, so it only has to say what changes.
   The app's own CSS has no phone rules, so side-by-side panels are turned into one thing at a time:
   a panel either opens over the page or sits above it. Which panels start open is decided in the
   scripts with window.__feMobile() (assets/command.js). */

/* controls that only exist on a phone */
.fe-mobile,
.chat-switch,
.fe-run-close {
    display: none;
}

@media (max-width: 640px) {
    .fe-mobile {
        display: inline-flex;
    }

    /* ---- chat list: opens over the chat, with its own close button ---- */
    :has(> nav[aria-label="Chat history"]) {
        position: relative;
    }

    nav[aria-label="Chat history"] {
        position: absolute;
        inset: 0;
        z-index: 30;
        width: auto;
        border-right: 0;
        background: var(--color-page);
    }

    /* ---- chats ---- */
    /* the list toggle sits top left: keep the prompt bar clear of it */
    .chat-main {
        padding-top: 44px;
    }

    .chat-reply {
        padding-inline: 4px;
    }

    /* a chat with a preview: one at a time, switched from a bar at the top */
    .chat-split {
        flex-direction: column;
    }

    .chat-switch {
        display: flex;
        flex: none;
        align-items: center;
        gap: 8px;
        padding: 12px 12px 0;
    }

    .chat-desktop {
        display: none;
    }

    .chat-split .chat-side {
        width: auto;
        min-height: 0;
        flex: 1 1 auto;
    }

    .chat-split > section {
        margin: 12px;
    }

    .chat-split > section > [role=region] {
        padding: 16px;
    }

    .chat-split[data-view=chat] > section,
    .chat-split[data-view=preview] > main {
        display: none;
    }

    /* cards: headers may wrap, rows lose most of their indent */
    .fe-chips [class~="h-10"] {
        height: auto;
        min-height: 40px;
        flex-wrap: wrap;
        row-gap: 4px;
        padding-block: 8px;
    }

    .fe-chips [class~="h-10"] > :is(h2, a)[class~="flex-1"] {
        flex-basis: calc(100% - 28px);
        white-space: normal;
    }

    .fe-chips [class~="h-10"] > :is(h2, a)[class~="flex-1"] + * {
        margin-left: 24px;
    }

    .fe-chips [class~="pl-8"] {
        padding-left: 12px;
    }

    /* a row with controls on the right: the controls drop under the text */
    .chat-row {
        flex-wrap: wrap;
    }

    .chat-row-main {
        flex-basis: calc(100% - 28px);
    }

    .chat-row-main + * {
        margin-left: 28px;
    }

    .chat-facts {
        column-gap: 16px;
    }

    /* prep notes: three columns become two lines, label over text */
    .chat-check {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .chat-check > :nth-child(2) {
        padding-right: 12px;
    }

    .chat-check > :last-child {
        grid-column: 1 / -1;
        padding-top: 0;
    }

    .chat-pair {
        grid-template-columns: minmax(0, 1fr);
    }

    .chat-pair > dt {
        padding-bottom: 0;
    }

    .chat-pair > dd {
        padding-top: 2px;
    }

    /* the finding popup: no keyboard, so no shortcut strip */
    .pr-keys {
        display: none;
    }

    .pr-dialog {
        padding: 16px;
    }

    /* ---- run panel (Today and the agent page): opens over the page, with a Close button ---- */
    :has(> .fe-run) {
        position: relative;
    }

    .fe-run {
        display: none !important;
    }

    .fe-run[data-run-open] {
        position: absolute;
        inset: 0;
        z-index: 30;
        display: flex !important;
        width: auto !important;
        flex-direction: column;
        background: var(--color-page);
    }

    .fe-run > div {
        width: 100%;
        min-height: 0;
        flex: 1;
        opacity: 1 !important;
        transform: none !important;
    }

    .fe-run aside {
        width: 100%;
    }

    .fe-run-close {
        display: block;
        align-self: flex-end;
        height: 24px;
        margin: 10px 12px 0;
        padding: 0 8px;
        border: 1px solid var(--color-line);
        border-radius: var(--radius-control);
        background: var(--color-surface);
        color: var(--color-ink);
        font-size: var(--text-body);
        cursor: pointer;
    }

    /* ---- list pages ---- */
    /* tables scroll sideways instead of squeezing every column */
    .overflow-auto:has(> table.table-fixed) {
        --table-width: 720px;
    }

    .overflow-auto table.table-fixed {
        min-width: 720px;
    }

    .chat-doc .overflow-auto:has(> table.table-fixed) {
        --table-width: 100%;
    }

    .chat-doc .overflow-auto table.table-fixed {
        min-width: 0;
    }

    /* "Individual skills" + search: the search drops to its own line */
    section > div:has(> [class~="w-[230px]"]) {
        flex-wrap: wrap;
    }

    section > div > [class~="w-[230px]"] {
        width: auto;
        flex: 1 1 100%;
    }

    header [class~="w-[230px]"] {
        width: auto;
        min-width: 0;
        flex: 1 1 0;
    }

    /* the page title keeps its full width, the search takes what is left */
    header h1 {
        flex-shrink: 0;
    }

    header > div:first-child {
        flex: 0 1 auto;
    }

    header > div:last-child {
        min-width: 0;
        flex: 1 1 0;
        justify-content: flex-end;
    }

    /* Integrations: the category list becomes a strip that scrolls sideways */
    :has(> [aria-label="Filter integrations"]) {
        flex-direction: column;
    }

    [aria-label="Filter integrations"] {
        width: auto;
        flex: none;
        flex-direction: row;
        align-items: center;
        gap: 4px;
        overflow: auto hidden;
        border-right: 0;
        border-bottom: 1px solid var(--color-line-soft);
        padding: 8px 12px;
        scrollbar-width: none;
    }

    [aria-label="Filter integrations"] > * {
        flex: none;
        flex-direction: row;
        gap: 4px;
        border-top: 0;
        padding-top: 0;
    }

    [aria-label="Filter integrations"] > * > * {
        flex: none;
        white-space: nowrap;
    }

    [aria-label="Filter integrations"] [class~="text-ink-subtle"] {
        display: none;
    }

    /* Automations: the list sits above the one that is open */
    :has(> .auto-list) {
        flex-direction: column;
    }

    .auto-list {
        width: auto;
        max-height: 34vh;
        flex: none;
        border-right: 0;
        border-bottom: 1px solid var(--color-line-soft);
    }

    /* Settings: the choice drops under its label, and the page uses the full width */
    .notif-row {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .notif-row > span:first-child {
        flex-basis: 100%;
    }

    [class~="px-9"] {
        padding-inline: 4px;
    }

    /* ---- Today ---- */
    .today-top {
        height: auto;
        min-height: 24px;
        gap: 8px;
    }

    /* the next meeting: its title gets a full line, the countdown and button sit under it */
    .today-next {
        flex-wrap: wrap;
    }

    .today-next-main {
        flex-basis: 100%;
    }

    /* ---- Chat page: a suggestion may take two lines ---- */
    [aria-labelledby="chat-openers-heading"] button {
        height: auto;
        min-height: 28px;
        align-items: flex-start;
        padding-block: 5px;
        text-align: left;
    }

    [aria-labelledby="chat-openers-heading"] button > span {
        flex-wrap: wrap;
        row-gap: 2px;
    }
}
