/* Phones & touch (680px = phones, hover:none + coarse = touch): the open panel is an ordinary
   centred modal over #chat-backdrop, placement affordances hidden. Centred by inset:0 + margin:auto,
   since transform belongs to the open/close animation; !important beats float mode's inline rect. */
@media (max-width: 680px) {
    stencil-chat-panel.chat-open {
        inset: 0 !important;
        margin: auto !important;
        /* dvh first-class, vh as the fallback for browsers without dynamic units:
           a phone's collapsing URL bar must not push the composer off-screen. */
        width: min(420px, calc(100vw - 24px)) !important;
        height: min(560px, calc(100vh - 24px)) !important;
        height: min(560px, calc(100dvh - 24px)) !important;
        min-width: 0;
        border-radius: 14px;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
    }
    body:has(stencil-chat-panel.chat-open) #chat-backdrop { display: block; }
    /* Placement buttons and every resize handle are meaningless in the modal. */
    stencil-chat-panel .chat-dock-btns, stencil-chat-panel .chat-resizer, .chat-dock-float .chat-float-handle,
    stencil-chat-panel .chat-input-sizer { display: none; }
    stencil-chat-panel .chat-input-row { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
    /* One suggestion per line: the chips are full sentences, and a wrapped
       two-column grid at 366px turns them into ragged fragments. */
    .chat-empty { flex-direction: column; align-items: stretch; }
    .chat-suggest { text-align: left; }
}
/* Touch devices: ≥40px targets for the compact icon buttons; the fiddly resize handles
   hide — the sheet/dock sizes itself. */
@media (hover: none) and (pointer: coarse) {
    .chat-hbtn, .chat-abtn, .chat-result-btn { width: 40px; height: 40px; }
    .chat-resizer { display: none; }
    .chat-dock-float .chat-float-handle { display: none; }
}

/* In fullscreen the slide-in strips (#fs-controls-panel / #fs-points-panel, 10000+)
   ARE the toolbar, and a docked chat at 90000 sat over the strip's own fullscreen
   toggle. The chat goes beneath them there; modal overlays stay above both. */
body.fullscreen-mode stencil-chat-panel { z-index: 9990; }
/* A docked chat shares the page: the body gives up its --chat-size band as padding and reflows
   live with the resizer. Float and fullscreen overlay by design (:not(.fullscreen-mode), as :has()
   would out-specify its padding:0); the transition matches the panel's own slide. */
body { transition: background 0.3s, color 0.3s, padding 0.51s ease; }
/* …but a resize drag tracks the pointer: a padding eased per step trailed the edge by half a second. */
body:has(stencil-chat-panel.chat-gesturing) { transition: background 0.3s, color 0.3s; }
/* Phones excluded on purpose: the modal overlays the page, and a 340px band on a
   390px viewport overflows the document sideways — which makes a mobile browser
   widen the LAYOUT VIEWPORT, so the fixed panel then hangs off the screen. */
@media (min-width: 681px) {
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open:not(.chat-closing):not(.chat-pour-wait).chat-dock-left) { padding-left: calc(var(--chat-size, 340px) + 10px); }
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open:not(.chat-closing):not(.chat-pour-wait).chat-dock-right) { padding-right: calc(var(--chat-size, 340px) + 10px); }
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open:not(.chat-closing):not(.chat-pour-wait).chat-dock-top) { padding-top: calc(var(--chat-size, 300px) + 10px); }
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open:not(.chat-closing):not(.chat-pour-wait).chat-dock-bottom) { padding-bottom: calc(var(--chat-size, 300px) + 10px); }
    /* The drop overlay gives up the same band, so the docked panel's own drop target stays
       readable during one drag; float/fullscreen keep the full-bleed overlay. */
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open.chat-dock-left) #global-drop-overlay { left: var(--chat-size, 340px); }
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open.chat-dock-right) #global-drop-overlay { right: var(--chat-size, 340px); }
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open.chat-dock-top) #global-drop-overlay { top: var(--chat-size, 300px); }
    body:not(.fullscreen-mode):has(stencil-chat-panel.chat-open.chat-dock-bottom) #global-drop-overlay { bottom: var(--chat-size, 300px); }
}
/* Closing plays the reverse slide (.chat-closing keeps .chat-open), so the padding
   releases on the out-duration, in step with the panel and starting with it. */
body:has(stencil-chat-panel.chat-closing) { transition: background 0.3s, color 0.3s, padding 0.39s ease; }
/* Sliding: the space moves on the genie's own clock and curve (motion/genie/flight.js GENIE_OPEN_MS / GENIE_CLOSE_MS);
   closing, it waits out the first 40% for the picture's far edge (motion/control/tips.js SPACE_CLOSE_WAIT). */
body:has(stencil-chat-panel.chat-open.genie-driven) { transition: background 0.3s, color 0.3s, padding 560ms cubic-bezier(0.39, 0.575, 0.565, 1); }
body:has(stencil-chat-panel.chat-closing.genie-driven) { transition: background 0.3s, color 0.3s, padding 288ms cubic-bezier(0.37, 0, 0.63, 1) 192ms; }
/* Transition: the space opens and shuts on the panel's own reveal curve (animations/overlay/overlays.css chatReveal*);
   a resize drag still tracks the pointer. */
:root[data-motion="transition"] body:not(:has(stencil-chat-panel.chat-gesturing)) { transition: background 0.3s, color 0.3s, padding 0.51s cubic-bezier(0.33, 1, 0.68, 1); }
:root[data-motion="transition"] body:has(stencil-chat-panel.chat-closing) { transition: background 0.3s, color 0.3s, padding 0.39s cubic-bezier(0.45, 0, 0.55, 1); }

/* Gear provider-status tooltip: a themed table plus a pre-line footer, above the gear. */
.chat-status-tip {
    position: fixed;
    z-index: 100003;
    max-width: 340px;
    padding: 8px 10px;
    background: var(--bg-info);
    border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border-main));
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
    pointer-events: none;
    opacity: 0;
    transition: opacity 90ms ease;
}
.chat-status-tip.visible { opacity: 1; }
/* Once the motes have flown the plain fade steps aside, so it never fights surfaceForm/surfaceLeave. */
.chat-status-tip.dust-driven { transition: none; }
.chat-status-tip table { border-collapse: collapse; font-size: 12px; line-height: 1.45; }
.chat-status-tip th {
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    padding-right: 12px;
    vertical-align: top;
    white-space: nowrap;
}
.chat-status-tip td { color: var(--text-key); word-break: break-word; }
.chat-status-tip td.chat-status-ok { color: #28a745; }
.chat-status-tip td.chat-status-error { color: #dc3545; }
.chat-status-tip td.chat-status-connecting { color: #e0a800; }
.chat-status-tip-foot {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-main);
    font-size: 11px;
    color: var(--text-muted);
    white-space: pre-line;
}

/* Assistant settings modal extras. */
.chat-server-status { font-size: 12px; color: var(--text-muted); }
/* Dot then text, side by side — the reading is one thing ("● failed to fetch"), and the
   row's default space-between threw them to opposite edges with 400px of nothing between
   (user report, with a picture). Desktop twin: llmSettingsForm's llmStatusRow. */
#chat-server-status-row { justify-content: flex-start; gap: 8px; }
.chat-cors-note {
    margin-top: 10px;
    /* Tight to its text: it is a note, not a panel (user report — too much air above and
       below the line). Desktop twin: llmNoteBox's 10/6 margins. */
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--bg-drop-hint);
    border: 1px solid var(--border-hint);
    font-size: 12px;
    color: var(--text-muted);
}
.chat-cors-note code { font-size: 11px; }
/* The one merged note box (user decision): its lines stack with a small gap. */
.chat-cors-note > div + div { margin-top: 4px; }
