@layer legacy, theme, base, components, utilities;
@layer legacy {
/* Main conversation surface. Applied after legacy and component styles. */
body .workspace-screen>header{display:flex!important;flex-wrap:wrap;align-items:center;justify-content:space-between}
.chat-heading-identity{flex:1 1 180px;min-width:0;max-width:100%}
body .chat-heading-identity h1{margin:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
body .chat-heading-identity .workspace-context{margin:5px 0 0;font-size:11px;color:var(--muted)}
.chat-heading-controls{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex:0 1 auto;min-width:0;max-width:100%}
body .chat-heading-controls .agent-picker{width:150px;max-width:150px;flex:0 1 150px;min-width:0}
body .chat-heading-controls select{width:100%;max-width:150px}
body .chat-heading-controls>button{flex:0 0 32px;width:32px;padding:4px}
@media(max-width:760px){.chat-heading-controls{width:100%;justify-content:flex-start}.chat-heading-identity{flex-basis:100%}body .chat-heading-controls .agent-picker{flex:1 1 0;width:0;max-width:none}body .chat-heading-controls select{max-width:100%}}

body .workspace-screen{background:var(--panel);padding:0;gap:0}
body .workspace-screen>header{background:var(--bg);padding:16px 24px;border-bottom:1px solid var(--line);gap:10px;grid-template-columns:minmax(0,1fr) minmax(110px,170px) minmax(110px,170px) 36px;align-items:center}
body .workspace-screen>header .agent-picker{width:100%;max-width:170px;justify-self:end}
body .workspace-screen>header .agent-picker select{width:100%;max-width:170px;min-width:0;text-overflow:ellipsis;padding:5px 8px;font-size:12px}
body .workspace-screen>header>button{width:36px;max-width:36px;padding:4px;justify-self:end}
body .workspace-tree .workspace-stream-row{display:grid;grid-template-columns:minmax(0,1fr) 36px;align-items:start;margin-left:4px}
body .workspace-tree .workspace-stream-row>button:first-child{display:-webkit-box;width:100%;min-width:0;white-space:normal;overflow-wrap:anywhere;line-height:1.45;-webkit-line-clamp:3;-webkit-box-orient:vertical;padding:8px 10px;text-align:left}
body .workspace-tree .workspace-agent-heading{white-space:normal;overflow-wrap:anywhere;text-align:left;line-height:1.4}
body .workspace-tree summary>button:first-child{-webkit-line-clamp:3;white-space:normal}
body .workspace-tree .workspace-stream-row>button:last-child{align-self:start;margin-top:4px}
body .workspace-screen>header h1{font-size:20px}
body .workspace-screen>.workspace-error:not([hidden]){margin:12px 24px}
body .workspace-content{padding:32px max(24px,calc((100% - 800px)/2));background:var(--panel)}
body .workspace-content .body h2{padding-bottom:8px;border-bottom:1px solid var(--line)}
body .workspace-content .body a{text-underline-offset:3px}
body .workspace-content .body li p{margin:4px 0}
body .workspace-content .bui-code-block>div{border-radius:12px;background:var(--panel)}
body .ui-composer-host{background:var(--panel);width:100%;max-width:none;padding:12px max(24px,calc((100% - 800px)/2)) 24px}
body .workspace-screen .bui-composer{background:var(--bg);border:1px solid var(--line);border-radius:20px;padding:16px 18px;margin:0;box-shadow:0 6px 24px #00000008}
.bui-composer-caption{display:flex;justify-content:space-between;gap:12px;font-size:10px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);padding-bottom:10px}
.bui-composer-caption span:last-child{font-weight:400;letter-spacing:0;text-transform:none}
body .bui-composer textarea{min-height:76px;padding:4px 0;font-size:15px}
body .bui-composer .ui-composer-toolbar{border-top:1px solid var(--line);padding-top:12px;margin-top:8px}
body .bui-composer button[type=submit]{height:36px;min-width:44px;padding:0 12px;border-radius:10px;gap:8px}
body .bui-composer .ui-send-label{display:none}
body .bui-composer button[type=submit][data-uploading] .ui-send-label{display:inline;white-space:nowrap}
body .bui-composer .ui-composer-hint{font-size:10px}
/* The keyboard hint only fits (and only matters) with a wide window and a keyboard: never let it squeeze into a one-word column. */
@media(max-width:1100px),(pointer:coarse){body .bui-composer .ui-composer-hint{display:none}}
@media(min-width:1200px){}
@media(max-width:760px){body .workspace-screen>header{padding:12px 16px;grid-template-columns:minmax(0,1fr) 36px}body .workspace-screen>header .agent-picker{justify-self:start;max-width:100%;grid-column:1;grid-row:auto}body .workspace-screen>header .agent-picker:nth-of-type(2){grid-column:2;min-width:0}body .workspace-screen>header{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}body .workspace-screen>header>button{grid-column:2;grid-row:1}body .workspace-screen>header .agent-picker select{max-width:100%}body .workspace-screen>header h1{font-size:18px}body .workspace-content{padding:20px 12px}body .ui-composer-host{padding:8px 12px 12px}body .workspace-screen .bui-composer{padding:12px 14px;border-radius:16px}body .bui-composer textarea{min-height:58px}.bui-composer-caption{font-size:9px}}
/* Transcript in the style of PI's TUI: flowing assistant text, tinted user block, compact tool lines. */
body .workspace-content .ui-chat-message{border:0;background:none;box-shadow:none;border-radius:0;padding:0;margin:0 0 14px;max-width:none;line-height:1.65;font-size:14.5px}
body .workspace-content .ui-chat-message.user{background:var(--user);border-radius:6px;padding:8px 14px;margin:18px 0 14px}
body .workspace-content .ui-chat-message.user p{margin:0;white-space:pre-wrap}
body .workspace-content .ui-chat-message.assistant{padding:0 2px}
body .workspace-content .ui-chat-message.toolResult{margin:0 0 8px}
body .workspace-content .tui-tool{display:flex;align-items:baseline;gap:8px;margin:10px 0 2px;font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--text);min-width:0}
body .workspace-content .tui-mark{flex:none;width:1.2em;text-align:center;color:var(--accent)}
body .workspace-content .tui-tool.failed,body .workspace-content .tui-tool.failed .tui-mark{color:var(--danger)}
body .workspace-content .tui-tool.running .tui-mark{color:var(--muted)}
body .workspace-content .tui-tool-name{flex:none;font-weight:600}
body .workspace-content .tui-tool-args{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}
body .workspace-content .tui-tool-time{flex:none;color:var(--muted)}
body .workspace-content .tui-result{margin:0 0 8px 1.2em;padding-left:10px;border-left:2px solid var(--line)}
body .workspace-content .tui-result.failed{border-left-color:var(--danger)}
body .workspace-content .tui-output,body .workspace-content .tui-thinking pre{margin:0;padding:0;border:0;background:none;white-space:pre-wrap;overflow-wrap:anywhere;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--muted)}
body .workspace-content .tui-result.failed .tui-output{color:var(--danger)}
body .workspace-content .tui-thinking{margin:6px 0;padding-left:10px;border-left:2px solid var(--line);font-style:italic}
body .workspace-content .tui-thinking pre{font:inherit;font-size:13px}
body .workspace-content .tui-more{border:0;background:none;margin:0;overflow:visible;border-radius:0}
body .workspace-content .tui-more summary{display:block;padding:0;background:none;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--accent);cursor:pointer;list-style:none}
body .workspace-content .tui-more summary::-webkit-details-marker{display:none}
body .workspace-content .tui-more[open] summary{display:none}
body .workspace-content .ui-chat-message.assistant .body{margin:0}
@media(max-width:760px){body .workspace-content .ui-chat-message{font-size:14px}body .workspace-content .tui-tool{flex-wrap:wrap}body .workspace-content .tui-tool-args{flex-basis:100%;white-space:normal}}

/* One scroller per region, never a scrollbar inside a scrollable page. Absolutely positioned
   helpers (.sr-only) inside the transcript must be contained by their message, otherwise the
   document grows by the whole transcript height and gets its own scrollbar. */
html,body{overflow:hidden;overscroll-behavior:none}
body .workspace-content,body .ui-chat-message{position:relative}
.ui-app-footer{flex:none;padding:2px 16px 8px;text-align:center;font:11px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--muted)}
[data-webui-version]{user-select:all}
body .workspace-content{overscroll-behavior:contain}
body .workspace-tree{overscroll-behavior:contain;overflow-x:hidden}
/* Base UI positions the Positioner; the legacy `.workspace-menu{position:fixed}` must not pull the popup out of it (it broke end-aligned menus). */
body .ui-action-menu{position:relative}

/* PI-like tool box: call line and result form one tinted panel; success/failure tint the result, palette variables preserved. */
body .workspace-content .tui-tool{background:color-mix(in srgb,var(--text) 7%,transparent);border-radius:6px 6px 0 0;padding:6px 10px;margin:10px 0 0}
body .workspace-content .tui-result{margin:0 0 10px;padding:6px 10px 8px;border-left:0;border-radius:0 0 6px 6px;background:color-mix(in srgb,var(--accent) 14%,transparent)}
body .workspace-content .tui-result.failed{background:color-mix(in srgb,var(--danger) 16%,transparent)}
body .workspace-content .tui-took,body .workspace-content .tui-time{color:var(--muted);font:11.5px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace}
body .workspace-content .tui-took{margin-top:6px}
body .workspace-content .tui-time{display:block;margin:0 0 2px;text-align:right}
body .workspace-content .tui-images{display:flex;flex-wrap:wrap;gap:6px;margin:6px 0 0}
body .workspace-content .tui-image-open{all:unset;cursor:pointer;text-decoration:underline dotted;text-underline-offset:3px}
body .workspace-content .tui-image-open:focus-visible{outline:2px solid var(--accent,currentColor);outline-offset:2px;border-radius:4px}
body .workspace-content .tui-image-pic{display:block;max-width:min(100%,420px);max-height:320px;border-radius:6px;object-fit:contain}
body .workspace-content .tui-image:has(.tui-image-pic){border:0;padding:0}
body .workspace-content .tui-image{border:1px dashed var(--line);border-radius:6px;padding:2px 8px;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--muted)}

/* Spacing in the live tail of a chat: the receipt of a message sent while the agent works, and the status line, sit clear of the tool boxes above. */
body .workspace-content .tui-working{margin:16px 0 4px;font-size:13px;color:var(--muted)}
body .workspace-content .message.user.pending-receipt{margin:16px 0 12px;padding:8px 14px;border-radius:6px;white-space:normal}
body .workspace-content .message.user.pending-receipt p{margin:0;white-space:pre-wrap}
body .workspace-content .tui-receipt{display:block;margin:4px 0 0;font-size:12px;color:var(--muted)}
body .workspace-content .tui-receipt-images{display:flex;flex-wrap:wrap;gap:6px;margin:8px 0 0}
body .workspace-content .tui-receipt-images img{display:block;max-width:min(100%,240px);max-height:180px;border-radius:6px;object-fit:contain}
/* Image drafts in the composer: thumbnails in a row, a small round remove button over the corner, a progress bar while uploading. */
.bui-composer [aria-label="Attached images"]{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 8px}
.bui-composer [aria-label="Attached images"]:empty{display:none}
.ui-attachment{position:relative;width:84px;height:84px;border:1px solid var(--line);border-radius:8px;overflow:hidden;background:var(--panel)}
.ui-attachment img{display:block;width:100%;height:100%;object-fit:cover}
.ui-attachment>button{position:absolute;top:3px;right:3px;width:22px;height:22px;min-height:0;padding:0;border-radius:50%;line-height:1;display:flex;align-items:center;justify-content:center;background:var(--bg);color:var(--text);border:1px solid var(--line)}
.ui-attachment>button[hidden]{display:none!important}
.ui-attachment[data-uploading] img{opacity:.45}
.ui-attachment progress{position:absolute;left:6px;right:6px;bottom:6px;width:auto;height:6px;appearance:none;border:0;border-radius:3px;overflow:hidden;background:var(--line)}
.ui-attachment progress::-webkit-progress-bar{background:var(--line)}
.ui-attachment progress::-webkit-progress-value{background:var(--accent);transition:width .15s}
.ui-attachment progress::-moz-progress-bar{background:var(--accent)}
.ui-attachment .pct{position:absolute;top:50%;left:0;right:0;transform:translateY(-60%);text-align:center;font-size:12px;font-weight:600;color:var(--text)}
@media(prefers-reduced-motion:reduce){.ui-attachment progress::-webkit-progress-value{transition:none}}

}
