/* Workspace controls use the existing X-Wrt tokens. Panels never reserve
   framebuffer space, so opening tools cannot resize or clip the desktop. */
.workspace { padding-bottom: env(safe-area-inset-bottom, 0px); }
.workspace-footer { padding: 3px 4px; line-height: 1.2; }
.desktop-toolbar,
.desktop-card.controls-collapsed .desktop-toolbar {
  min-height: 52px;
  padding: 4px 10px;
  gap: 8px;
  flex-wrap: nowrap;
}
.desktop-title { flex: 1; min-width: 0; }
.desktop-header-actions { width: auto; flex-wrap: nowrap; gap: 6px; }
.desktop-header-actions > button { min-height: 44px; min-width: 44px; }
.desktop-stage, .terminal-mode .desktop-stage { min-height: 0; flex: 1 1 0; }
.connection-status { white-space: nowrap; }
.connection-notice { position: absolute; z-index: 6; inset: 8px 8px auto; margin: 0; padding: 6px 6px 6px 12px; border: 1px solid var(--accent-line); border-radius: 8px; background: var(--accent-soft); color: var(--ink); font-size: 13px; line-height: 1.6; pointer-events: none; display: flex; align-items: flex-start; gap: 4px; }
.connection-notice > span { flex: 1; min-width: 0; align-self: center; overflow-wrap: anywhere; }
.connection-notice > button { pointer-events: auto; flex: 0 0 44px; min-width: 44px; min-height: 44px; padding: 0; }
.input-notice-list { padding-inline-start: 24px; font-size: 13px; overflow-wrap: anywhere; }
.input-notice-list li + li { margin-top: 12px; }
.input-notice-list p { margin: 4px 0 0; }
.connection-notice[hidden] { display: none; }
.terminal-session-bar { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.terminal-session-bar:not([hidden]) ~ .monitor-icon,
.terminal-session-bar:not([hidden]) ~ strong { display: none; }
.terminal-session-bar:not([hidden]) ~ .connection-status { flex: none; }
.terminal-tabs { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; overflow: hidden; }
.terminal-tab-item { display: flex; flex: 0 1 200px; min-width: 120px; }
.terminal-tabs .terminal-tab { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.terminal-tab-item[data-available=true] { flex: 0 0 auto; min-width: 112px; }
.terminal-tab-item[data-available=false] .terminal-tab { border-right: 0; border-radius: 6px 0 0 6px; }
.terminal-tab-actions { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; min-height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 0 6px 6px 0; background: var(--surface); color: var(--muted); font-size: 20px; }
.terminal-tab-actions:hover { background: var(--surface-hover); color: var(--ink); }
.terminal-session-actions { display: none; }
.terminal-tab[aria-selected=true] { color: var(--accent-ink); border-color: var(--accent-line); background: var(--accent-soft); }
.terminal-session-button { display: none; align-items: center; flex: 1; min-width: 0; width: 100%; text-align: left; overflow: hidden; font-size: 13px; }
.terminal-session-button > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.terminal-session-button > span:last-child { flex: none; }
.terminal-session-bar[data-overflow=true] .terminal-session-button { display: flex; flex: 0 0 136px; width: 136px; }
.terminal-session-button[data-active=true] { color: var(--accent-ink); border-color: var(--accent-line); background: var(--accent-soft); }
.terminal-switch-dialog { max-height: 85dvh; overflow: auto; }
.terminal-switch-list { display: grid; gap: 8px; margin: 14px 0; }
.terminal-choice-row { display: flex; gap: 6px; min-width: 0; }
.terminal-choice-row .terminal-choice { flex: 1; min-width: 0; }
.terminal-choice-row .terminal-tab-actions { width: 44px; border-radius: 9px; }
.terminal-choice { min-height: 64px; width: 100%; padding: 10px 12px; text-align: left; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.terminal-choice small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.terminal-choice[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent-line); }
#terminal-switch-status { min-height: 1.7em; font-size: 12px; }
.terminal-action-menu { position: fixed; margin: 0; width: min(280px, calc(100vw - 16px)); padding: 12px; }
.terminal-action-menu .dialog-heading { gap: 8px; margin-bottom: 8px; }
.terminal-action-menu h2 { min-width: 0; overflow-wrap: anywhere; font-size: 15px; }
.terminal-action-menu .dialog-heading button { flex: none; min-width: 44px; min-height: 44px; }
.terminal-action-options { display: grid; gap: 6px; }
.terminal-action-options button { min-height: 44px; text-align: left; }
.terminal-action-options .danger { color: var(--danger); }
.terminal-rename-dialog { max-height: calc(var(--workspace-visible-height, 100dvh) - 24px); overflow: auto; }
#terminal-rename-form { display: grid; gap: 10px; }
#terminal-rename-name { width: 100%; min-width: 0; min-height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 16px; }
#terminal-rename-status { min-height: 1.7em; margin: 0; overflow-wrap: anywhere; }
#terminal-rename-form .confirmation-actions { justify-content: flex-end; }
#terminal-rename-form button { min-width: 72px; min-height: 44px; }
#draft-status { color: var(--warning); }
.workspace-panel {
  position: fixed;
  z-index: 25;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 12px 48px #0003;
  overflow: auto;
  overscroll-behavior: contain;
  outline-offset: -3px;
}
.workspace-panel:focus-visible { outline: 3px solid var(--focus); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-heading h2 { margin: 0; font-size: 16px; }
.panel-heading button { min-width: 44px; min-height: 44px; }
.tools-panel { inset: 116px 16px 42px auto; width: min(380px, calc(100vw - 32px)); }
.tools-panel .desktop-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tools-panel .display-controls { display: flex; flex-direction: column; align-items: stretch; padding: 16px 0 0; margin-top: 16px; border: 0; border-top: 1px solid var(--line); background: none; gap: 18px; }
.tools-panel .zoom-controls { display: flex; flex-wrap: wrap; flex: none; justify-content: flex-start; gap: 8px; }
.tools-panel .view-actions { width: auto; display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 8px; }
.tools-panel .terminal-view-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.tools-panel .terminal-view-controls label { width: 100%; }
.tools-panel .terminal-view-controls select { flex: 1; max-width: 100%; }
.terminal-target-controls, .terminal-font-controls { display: flex; align-items: center; gap: 8px; min-width: 0; }
.terminal-target-controls label { flex: 1; }
.terminal-target-controls > button { flex: none; }
.terminal-font-controls > span { font-size: 12px; }
.terminal-font-controls output { min-width: 36px; text-align: center; }
.pointer-options { display: grid; gap: 12px; }
.pointer-options label { display: grid; gap: 6px; font-size: 12px; }
.pointer-options select { width: 100%; min-width: 0; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 16px; }
.pointer-options .muted { font-size: 12px; }
.input-dock.workspace-panel { inset: auto 16px calc(42px + var(--workspace-keyboard-inset, 0px)) auto; width: min(660px, calc(100vw - 32px)); max-height: calc(var(--workspace-visible-height, 100dvh) - 130px); display: flex; flex-direction: column; overflow: hidden; }
.input-dock .panel-heading { flex: none; }
.assistant-directions { display: flex; gap: 8px; margin-bottom: 12px; flex: none; }
.assistant-directions button { flex: 1; font-size: 12px; min-height: 44px; }
.assistant-body { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.input-dock .terminal-destination { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 6px 10px; margin: 0 0 10px; }
.input-dock .terminal-destination label { display: grid; gap: 5px; width: auto; font-size: 12px; }
.input-dock .terminal-destination select { width: 100%; min-width: 0; font-size: 14px; }
.input-dock #terminal-target-note { grid-column: 1 / -1; font-size: 12px; }
.input-dock .composer textarea { min-height: 80px; max-height: 30dvh; }
.input-dock .dock-bottom { flex: none; }
.input-dock .keys { display: flex; gap: 6px; flex-wrap: nowrap; }
.input-dock .keys button { min-width: 44px; flex: 1 1 auto; font-size: 12px; }
.input-dock .keys .shortcuts-entry { flex: 1 0 auto; min-width: 96px; }
.input-dock .keys .interrupt-key { margin-left: 4px; }
.input-dock .dock-note { font-size: 11px; }
.input-dock .input-status { flex: none; max-height: 4.5em; overflow: auto; }
.clipboard-dialog { position: fixed; inset: auto 16px calc(42px + var(--workspace-keyboard-inset, 0px)) auto; margin: 0; width: min(660px, calc(100vw - 32px)); max-width: none; max-height: calc(var(--workspace-visible-height, 100dvh) - 130px); border-radius: 14px; }
.clipboard-dialog .dialog-heading h2 { margin: 0; font-size: 16px; }
.clipboard-dialog .dialog-heading button { min-height: 44px; min-width: 44px; }
.desktop-card:fullscreen .workspace-panel { bottom: 8px; max-height: calc(100dvh - 72px); }
.desktop-card:fullscreen .tools-panel { top: 60px; }
.desktop-card:fullscreen .input-dock { bottom: calc(8px + var(--workspace-keyboard-inset, 0px)); max-height: calc(var(--workspace-visible-height, 100dvh) - 16px); }
.workspace-keyboard-open .input-dock .assistant-directions { display: none; }
.workspace-keyboard-open .input-dock #terminal-target-note, .workspace-keyboard-open .input-dock .dock-note { display: none; }
@media (max-width: 1000px) {
  .terminal-session-bar { gap: 0; }
  .terminal-tabs { display: none; }
  .terminal-session-button { display: flex; }
  .terminal-session-bar[data-closable=true] .terminal-session-button { border-radius: 6px 0 0 6px; border-right: 0; }
  .terminal-session-actions:not([hidden]) { display: inline-flex; width: 44px; }
}
@media (max-width: 700px) {
  /* Use the phone width while keeping the notch out of the viewing area. */
  .workspace { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  .desktop-card { border-left: 0; border-right: 0; border-radius: 0; }
  .topbar .brand { min-width: 0; flex-shrink: 1; }
  .topbar .node-entry { min-width: 44px; }
  .terminal-session-bar:not([hidden]) ~ .connection-status { width: 14px; height: 14px; padding: 0; margin-left: 4px; gap: 0; font-size: 0; justify-content: center; }
  .terminal-switch-dialog { position: fixed; inset: auto 8px max(8px, env(safe-area-inset-bottom)); width: auto; max-width: none; margin: 0; padding: 16px; border-radius: 16px; max-height: 75dvh; }
  .desktop-toolbar,
  .desktop-card.controls-collapsed .desktop-toolbar { min-height: 52px; padding: 4px; gap: 4px; }
  .desktop-title { gap: 0; }
  .desktop-title > strong, .desktop-title > .monitor-icon { display: none; }
  .connection-status { font-size: 10px; padding: 5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .mode-switch { margin-left: 0; gap: 2px; }
  .mode-switch button, .desktop-header-actions > button { font-size: 11px; padding-inline: 7px; }
  .desktop-header-actions { width: auto; gap: 4px; }
  .fullscreen-entry { display: none; }
  .workspace-panel { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: auto; border-radius: 16px; padding: 12px; max-height: min(70dvh, calc(100dvh - 118px)); }
  .tools-panel { top: auto; }
  .input-dock.workspace-panel, .clipboard-dialog { top: auto; left: 8px; right: 8px; bottom: calc(max(8px, env(safe-area-inset-bottom)) + var(--workspace-keyboard-inset, 0px)); width: auto; max-height: min(70dvh, calc(var(--workspace-visible-height, 100dvh) - 16px)); margin: 0; }
  .input-dock .terminal-destination { grid-template-columns: minmax(0, 1fr) 100px; }
  .input-dock .composer .primary { min-width: 76px; height: auto; min-height: 44px; align-self: stretch; }
  .input-dock .terminal-destination select { min-height: 44px; font-size: 16px; }
  .workspace-keyboard-open .input-dock .panel-heading { margin-bottom: 4px; }
  .workspace-keyboard-open .input-dock #terminal-target-note { display: none; }
  .workspace-keyboard-open .input-dock .composer textarea { min-height: 72px; }
  .workspace-keyboard-open .input-dock .dock-note { display: none; }
}
@media (max-width: 420px) {
  /* Show the alternative action; the selected terminal/desktop remains clear
     in the title and accessible group name. The existing confirmation stays. */
  .mode-switch button[aria-pressed=true] { display: none; }
  .mode-switch button::before { content: '⇄'; margin-inline-end: 2px; }
  .terminal-session-bar { min-width: 72px; }
  .terminal-session-bar[data-closable=true] { min-width: 116px; }
  .terminal-session-button { min-width: 72px; padding-inline: 6px; }
}
@media (max-width: 360px) {
  .input-dock .keys { gap: 4px; }
  .input-dock .keys button { font-size: 11px; padding-inline: 4px; }
  .input-dock .keys .shortcuts-entry { min-width: 80px; }
}
@media (max-height: 540px) and (orientation: landscape) {
  .desktop-toolbar, .desktop-card.controls-collapsed .desktop-toolbar { min-height: 44px; padding-block: 0; }
  .tools-panel { top: 106px; bottom: 8px; }
  .input-dock.workspace-panel { bottom: calc(8px + var(--workspace-keyboard-inset, 0px)); max-height: calc(var(--workspace-visible-height, 100dvh) - 16px); }
}

/* History tools cover the page header on every screen, leaving both the history
   buttons and every terminal row in place. The content scrolls, not the close. */
.history-tools-floating { position: fixed; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); z-index: 30; box-sizing: border-box; margin: 0; padding: 0; overflow: hidden; border: 1px solid #666; border-radius: 8px; background: #2b2b2b; color: #e7eee9; color-scheme: dark; font: 12px/1.5 system-ui, sans-serif; box-shadow: 0 6px 18px #0005; }
.history-tools-floating[hidden], .history-tools-floating [hidden] { display: none !important; }
.history-tools-floating .history-tools-content { box-sizing: border-box; max-height: calc(var(--history-panel-height) - 2px); padding: 2px; overflow: auto; overscroll-behavior: contain; }
.history-tools-floating .history-find-row, .history-tools-floating .history-copy-row { display: flex; align-items: center; gap: 2px; min-width: 0; flex-wrap: nowrap; }
.history-tools-floating .history-find-row { padding-right: 46px; }
.history-tools-floating .history-copy-row { margin-top: 2px; flex-wrap: wrap; }
.history-tools-floating button { box-sizing: border-box; flex: none; min-width: 44px; min-height: 44px; padding: 4px; border: 1px solid #666; border-radius: 6px; background: #333; color: #e7eee9; font: 12px/1.5 system-ui, sans-serif; white-space: nowrap; }
.history-tools-floating button:disabled { opacity: .5; cursor: default; }
.history-tools-floating button:focus-visible, .history-tools-floating input:focus-visible, .history-tools-floating textarea:focus-visible { outline: 2px solid #f7971d; outline-offset: -2px; }
.history-tools-floating .history-tools-close { position: absolute; top: 3px; right: 3px; z-index: 2; }
.history-tools-floating #history-query { box-sizing: border-box; flex: 1; width: 110px; min-width: 64px; min-height: 44px; padding: 6px; border: 1px solid #666; border-radius: 6px; background: #222; color: #e7eee9; font: 16px/1.5 system-ui, sans-serif; }
.history-tools-floating #history-find-state { flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c7c7c7; font-size: 11px; }
.history-tools-floating #history-copy-state { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.history-tools-floating #history-copy-state:empty { display: none; }
.history-tools-floating #history-copy-selection { min-width: 76px; }
.history-tools-floating #history-copy-all { min-width: 128px; padding-inline: 10px; font-size: 14px; }
.history-tools-floating #history-download { min-width: 100px; }
.history-tools-short .history-tools-content { padding-right: 49px; }
.history-tools-short .history-find-row { padding-right: 0; }
.history-tools-short .history-tools-close { top: 0; right: 1px; }
@media (min-width: 701px) {
  .history-tools-floating .history-tools-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(230px, 1fr); gap: 6px; padding-right: 50px; }
  .history-tools-floating .history-find-row { padding-right: 0; }
  .history-tools-floating .history-copy-row { margin-top: 0; }
  .history-tools-floating #history-copy-manual { grid-column: 1 / -1; }
}

#history-copy-manual[open] { position: fixed; inset: var(--history-copy-top, 8px) 0 auto; display: flex; flex-direction: column; gap: 12px; box-sizing: border-box; width: min(760px, calc(100vw - 16px)); max-width: none; height: var(--history-copy-height, min(520px, calc(100dvh - 16px))); max-height: calc(100dvh - 16px); margin: 0 auto; padding: 16px; overflow: hidden; border: 1px solid #666; border-radius: 10px; background: #2b2b2b; color: #e7eee9; color-scheme: dark; font: 14px/1.5 system-ui, sans-serif; }
#history-copy-manual::backdrop { background: #0008; }
#history-copy-manual .history-copy-heading, #history-copy-manual .history-copy-actions { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
#history-copy-manual h2 { margin: 0; font: 600 16px/1.5 system-ui, sans-serif; }
#history-copy-manual p { margin: 0; color: #c7c7c7; font-size: 12px; }
#history-copy-manual .history-copy-actions { flex-wrap: wrap; justify-content: flex-start; gap: 8px; }
#history-copy-manual .history-copy-actions p { flex: 1 0 100%; min-width: 0; }
#history-copy-manual #history-copy-text { display: block; box-sizing: border-box; flex: 1 1 0; width: 100%; min-height: 0; max-height: none; margin: 0; padding: 10px; resize: none; overflow: auto; white-space: pre; border: 1px solid #666; border-radius: 6px; background: #222; color: #e7eee9; font: 14px/1.5 ui-monospace, monospace; }
#history-copy-manual button { flex: none; min-width: 64px; min-height: 44px; padding: 8px 12px; border: 1px solid #666; border-radius: 6px; background: #333; color: #e7eee9; font: 14px/1.5 system-ui, sans-serif; }
#history-copy-manual button:focus-visible, #history-copy-manual textarea:focus-visible { outline: 2px solid #f7971d; outline-offset: -2px; }
#history-copy-manual #history-copy-retry { min-width: 112px; background: #f7971d; border-color: #f7971d; color: #231815; font-weight: 600; }
#history-copy-manual button:disabled { opacity: .5; cursor: default; }

/* The server selector replaces the brand label; it does not add a toolbar row. */
.node-entry{display:flex;align-items:center;min-width:0;min-height:44px;max-width:220px;padding:3px 6px;background:transparent;color:inherit;border:1px solid #ffffff40;border-radius:6px;font-size:13px}.node-entry span:first-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.servers-dialog{max-height:calc(100dvh - 24px);overflow:auto}.server-row{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px 0;border-bottom:1px solid var(--line)}.server-row>div{min-width:0;overflow-wrap:anywhere}.server-row>button{flex:none;min-height:44px}.server-row p{font-size:12px}.servers-dialog #servers-portal{margin-top:16px;overflow-wrap:anywhere}#servers-destination{overflow-wrap:anywhere}#portal-register-form input,#portal-register-form textarea{box-sizing:border-box;display:block;width:100%;min-height:44px;margin:8px 0 14px;padding:10px;border:1px solid var(--line);border-radius:6px;background:var(--surface-soft);color:var(--ink);font:16px/1.5 system-ui,sans-serif}#portal-register-form textarea{resize:vertical;max-height:180px}#portal-node-origin,#portal-target-origin{overflow-wrap:anywhere}#portal-config-status{margin:12px 0}
@media(max-width:700px){.brand.nodes-configured>img{display:none}.node-entry{max-width:74px;font-size:12px;padding-inline:4px}.server-row{align-items:flex-start}}
