/* Owner: d-native */

/* Message typography follows the rem scale driven by Appearance. */
#app .thread-inner .msg-user,
#app .thread-inner .md {
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

#app .composer textarea {
  font-size: var(--text-size, 15px);
}

/* Scoped rules must not flatten the heading hierarchy or override code size. */
#app .thread-inner .md h1 { font-size: var(--text-h1); line-height: var(--leading-h1); }
#app .thread-inner .md h2 { font-size: var(--text-h2); line-height: var(--leading-h2); }
#app .thread-inner .md h3,
#app .thread-inner .md h4 { font-size: var(--text-h3); line-height: var(--leading-h3); }
#app .thread-inner .md code,
#app .thread-inner .md pre { font-size: var(--text-code); line-height: var(--leading-code); }
#app .thread-inner .md table { font-size: calc(var(--text-size, 15px) * 13 / 15); }

/* Native title area */
:root {
  --ui-scale: 1;
}

body {
  font-size: var(--text-body);
  font-weight: 400;
  line-height: var(--leading-body);
}

.titlebar {
  gap: 8px;
  padding-inline: .75rem;
  -webkit-user-select: none;
  user-select: none;
}

.titlebar-title {
  overflow: hidden;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  -webkit-app-region: no-drag;
}

.titlebar :is(button, a, input, select, textarea, [role="button"], [contenteditable="true"]) {
  -webkit-app-region: no-drag;
}

.titlebar-actions {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  -webkit-app-region: no-drag;
}

.titlebar-actions > * {
  flex-shrink: 0;
}

.titlebar-actions > .rules-chip {
  flex-shrink: 1;
}

/* Native window chrome: Orax surfaces sit over macOS vibrancy and Windows Mica. */
body.os-mac,
body.os-win {
  --surface: var(--bg-panel);
}

html[data-platform="darwin"][data-desktop="1"],
html[data-platform="win32"][data-desktop="1"],
html[data-platform="linux"][data-desktop="1"],
body.os-win,
body.os-win #app.app {
  background: transparent;
}

html:has(body.os-mac:not(.is-fullscreen)) {
  background: transparent;
}

body.os-mac:not(.is-fullscreen),
body.os-mac:not(.is-fullscreen) .app,
body.os-mac:not(.is-fullscreen) #app {
  background: transparent;
}

body.os-mac:not(.is-fullscreen) .rail,
body.os-win .rail {
  background: color-mix(in srgb, var(--surface) 48%, transparent);
}

body.os-mac:not(.is-fullscreen) .sidebar,
body.os-win .sidebar {
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border-right-color: color-mix(in srgb, var(--border-subtle) 76%, transparent);
}

body.os-mac .main,
body.os-mac .titlebar,
body.os-win .main,
body.os-win .titlebar {
  background: var(--bg);
}

body.os-mac:not(.is-fullscreen) :is(.sb-header, .rail) :is(
  button,
  a,
  input,
  select,
  textarea,
  [role="button"],
  [contenteditable="true"]
) {
  -webkit-app-region: no-drag;
}

/* Light surfaces and readable secondary content */
:root[data-theme$="-light"] {
  --bg-code: color-mix(in srgb, var(--bg-element) 90%, var(--text-muted));
  --bg-input: color-mix(in srgb, var(--bg-element) 97%, var(--text-muted));
  --bg-hover: color-mix(in srgb, var(--text) 6%, var(--bg-element));
  --bg-elev: var(--bg-panel);
  --bg-chrome: color-mix(in srgb, var(--bg-panel) 84%, var(--bg));
  --text-faint: color-mix(in srgb, var(--text-muted) 82%, var(--text));
}

:root[style*="color-scheme: light"] :is(.home-orax, .reply-orax img, img[src^="/ui/img/orax-"]),
:root[data-theme$="-light"] :is(.home-orax, .reply-orax img, img[src^="/ui/img/orax-"]) {
  /* Outline the existing white 3D artwork without replacing the dark-theme brand. */
  filter: drop-shadow(1px 0 0 #52525b) drop-shadow(-1px 0 0 #52525b)
    drop-shadow(0 1px 0 #52525b) drop-shadow(0 -1px 0 #52525b);
}

:root[data-theme="orax-light"] {
  --text-muted: color-mix(in srgb, var(--text) 70%, var(--bg-panel));
  --text-faint: color-mix(in srgb, var(--text) 60%, var(--bg-panel));
  --border: color-mix(in srgb, var(--text-muted) 24%, var(--bg-panel));
  --border-subtle: color-mix(in srgb, var(--text-muted) 14%, var(--bg-panel));
}

:root[data-theme$="-light"] .md pre {
  background: var(--bg-code);
  border-color: var(--border);
  
}

.md pre code {
  color: var(--text);
  background: transparent;
}

:root[data-theme$="-light"] .md :not(pre) > code {
  color: var(--md-code);
  background: var(--bg-element);
  border: 1px solid var(--border-subtle);
}

.steps-summary,
.step-text {
  color: var(--text-2);
}

.steps-list {
  border-left-color: var(--border);
}

.step,
.step-icon {
  color: var(--text-muted);
}

.step:hover,
.step:hover .step-text {
  color: var(--text);
}

.pill {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}

:root[data-theme$="-light"] .pill {
  color: var(--text-muted);
  background: var(--bg-element);
  border: 1px solid var(--border-subtle);
}

:root[data-theme$="-light"] .pill-ok {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, var(--bg-panel));
  border-color: color-mix(in srgb, var(--success) 26%, var(--border-subtle));
}

:root[data-theme$="-light"] .pill-warn {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, var(--bg-panel));
  border-color: color-mix(in srgb, var(--warning) 26%, var(--border-subtle));
}

:root[data-theme$="-light"] .pill-bad {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 10%, var(--bg-panel));
  border-color: color-mix(in srgb, var(--error) 24%, var(--border-subtle));
}

:root[data-theme$="-light"] .pill-muted {
  color: var(--text-muted);
  background: var(--bg-element);
  border-color: var(--border-subtle);
}

:root[data-theme$="-light"] :is(
  .group-card,
  .add-key-form,
  .shortcut-message,
  .modal,
  .slash-menu,
  .palette,
  .panel,
  .appearance-theme-card
) {
  background-color: var(--bg-panel);
  border-color: var(--border);
}

:root[data-theme$="-light"] :is(
  .input,
  .select,
  .textarea,
  .composer,
  .share-bar,
  .attachment-chip,
  .kbd,
  .account-badge
) {
  border-color: var(--border);
}

:root[data-theme$="-light"] .kbd,
:root[data-theme$="-light"] .account-badge {
  background: var(--bg-element);
}

.settings-title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
}

.group-title {
  font-size: 15px;
  font-weight: 600;
}

@media (max-width: 900px) {
  .titlebar-title {
    font-size: 15px;
  }
}

/* ==========================================================================
   VU1 visual system: layered surfaces, one accent, calm type.
   This block is intentionally last so every theme resolves to the same
   contrast rules regardless of which theme stylesheet loaded earlier.
   ========================================================================== */

:root[data-theme="orax"],
:root[data-theme="custom"],
:root[data-theme="ember"],
:root[data-theme="sand-dark"],
:root[data-theme="mailanzu-dark"] {
  --ui-scale: 1;
  --bg: #232323;
  --bg-panel: #292929;
  --bg-sidebar: #292929;
  --bg-chrome: #292929;
  --bg-element: #303030;
  --bg-elev: #303030;
  --bg-input: #303030;
  --bg-hover: #383838;
  --bg-active: rgba(255, 255, 255, 0.07);
  --bg-bubble: #303030;
  --bg-code: #2A2A2A;
  --border: rgba(255, 255, 255, 0.07);
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-active: rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #E8E8E8;
  --text-2: #D2D2D2;
  --text-muted: #A0A0A0;
  --text-faint: #9A9A9A;
  --primary: #D4D4D7;
  --secondary: #D2D2D2;
  --accent: #D4D4D7;
  --accent-ink: #18181B;
  --focus-ring: #D4D4D7;
  --btn-primary-bg: #D4D4D7;
  --btn-primary-fg: #18181B;
  --md-heading: #E8E8E8;
  --md-link: var(--accent, #D4D4D7);
  --md-code: #E8E8E8;
  --md-quote: #A0A0A0;
  --diff-add: #7BD3A0;
  --diff-del: #F08A8A;
  --success: #7BD3A0;
  --warning: var(--text-muted);
  --error: #F08A8A;
  --info: var(--accent, #D4D4D7);
  --scroll-thumb: rgba(255, 255, 255, 0.16);
  --scroll-thumb-hover: rgba(255, 255, 255, 0.28);
  --shadow: none;
  --font: "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="orax-light"],
:root[data-theme="sand-light"],
:root[data-theme="mailanzu-light"] {
  --ui-scale: 1;
  --bg: #F9F9F9;
  --bg-panel: #F1F1F1;
  --bg-sidebar: #F1F1F1;
  --bg-chrome: #F1F1F1;
  --bg-element: #FCFCFC;
  --bg-elev: #FCFCFC;
  --bg-input: #FCFCFC;
  --bg-hover: #E8E8E8;
  --bg-active: rgba(27, 27, 27, 0.05);
  --bg-bubble: #ECECEC;
  --bg-code: #F0F0F0;
  --border: rgba(27, 27, 27, 0.09);
  --border-subtle: rgba(27, 27, 27, 0.07);
  --border-active: rgba(27, 27, 27, 0.18);
  --border-strong: rgba(27, 27, 27, 0.18);
  --text: #1A1A1A;
  --text-2: #3C3C3C;
  --text-muted: #5E5E5E;
  --text-faint: #666666;
  --primary: #1A1A1A;
  --secondary: #454545;
  --accent: #5A5A62;
  --accent-ink: #FFFFFF;
  --focus-ring: #5A5A62;
  --btn-primary-bg: #1A1A1A;
  --btn-primary-fg: #FFFFFF;
  --md-heading: #1A1A1A;
  --md-link: var(--accent, #D4D4D7);
  --md-code: #1A1A1A;
  --md-quote: #5E5E5E;
  --diff-add: #157A45;
  --diff-del: #B3261E;
  --success: #157A45;
  --warning: var(--text-muted);
  --error: #B3261E;
  --info: var(--accent, #D4D4D7);
  --scroll-thumb: rgba(27, 27, 27, 0.18);
  --scroll-thumb-hover: rgba(27, 27, 27, 0.32);
  --shadow: none;
  --font: "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

/* Typography and shared chrome ------------------------------------------ */
body {
  font-size: var(--text-body);
  line-height: var(--leading-body);
  background: var(--bg);
  color: var(--text);
}

.app,
.main,
.titlebar {
  background: var(--bg);
}

.rail,
.sidebar {
  background: var(--bg-panel);
  border-right-color: var(--border-subtle);
}

body.os-mac:not(.is-fullscreen) .rail,
body.os-win .rail,
body.os-mac:not(.is-fullscreen) .sidebar,
body.os-win .sidebar {
  background: var(--bg-panel);
}

.titlebar {
  border-bottom-color: var(--border-subtle);
}

.titlebar-title {
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  margin: 0 8px;
  background: var(--error);
}

.status-dot[hidden] {
  display: none;
}

.thread {
  padding: 28px 24px 0;
}

/* The main grid already starts below the titlebar. Reserve a single inset. */
html body #thread:not(:has(.home)) {
  padding-block-start: 16px;
  scroll-padding-block-start: 16px;
}
html body #thread:not(:has(.home)) > .thread-inner {
  padding-top: 0;
}

.settings-title {
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0;
}

.group-title {
  font-size: 15px;
  font-weight: 500;
}

.group-card {
  background: var(--bg-element);
  border-color: var(--border-subtle);
  border-radius: var(--radius);
  
}

.settings-sidebar {
  background: var(--bg-panel);
  border-right-color: var(--border-subtle);
}

.settings-nav-item[aria-current="page"] {
  color: var(--text);
  background: var(--bg-hover);
  border-color: transparent;
}

.btn {
  min-height: 30px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-s);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border);
}

.btn-primary {
  color: var(--btn-primary-fg);
  background: var(--btn-primary-bg);
  border-color: transparent;
}

.btn-primary:hover {
  color: var(--btn-primary-fg);
  background: color-mix(in srgb, var(--btn-primary-bg) 85%, var(--bg));
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.input,
.select,
.textarea {
  min-height: 32px;
  color: var(--text);
  background: var(--bg-input);
  border-color: var(--border-subtle);
  border-radius: var(--radius-s);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--focus-ring);
  
}

.icon-btn {
  border-radius: var(--radius-s);
  transition: color 120ms ease, background-color 120ms ease;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.6;
}

.pill,
.chip {
  background: transparent;
  border: 0;
}

/* Right panel: docked, quiet chrome, a thin drag handle. */
.panel {
  width: var(--panel-w);
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
}

.panel-chrome {
  min-height: var(--titlebar-h);
  padding: 0 8px 0 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
}

.panel-tab {
  height: calc(var(--titlebar-h) - 1px);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.panel-tab[aria-selected="true"] {
  color: var(--text);
}

.panel-tab[aria-selected="true"]::after {
  background: var(--accent);
}

.panel-card {
  padding: 16px;
}

.panel-head {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.panel-section + .panel-section {
  border-top-color: var(--border-subtle);
}

.panel-file {
  color: var(--text-2);
  font-size: 13px;
  background: transparent;
}

.panel-file:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.panel-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  z-index: 8;
  width: 6px;
  cursor: col-resize;
  touch-action: none;
  border-radius: 3px;
  transition: background-color 120ms ease;
}

.panel-resizer:hover,
.panel-resizer.is-dragging {
  background: color-mix(in srgb, var(--text) 12%, transparent);
}

.panel-resizer:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -1px;
}

.popup {
  background: var(--bg-element);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-l);
  
}

.popup-item {
  border-radius: var(--radius-s);
  transition: background-color 120ms ease, color 120ms ease;
}

.popup-item:hover,
.popup-item.selected {
  color: var(--text);
  background: var(--bg-hover);
}

.popup-sep {
  border-top-color: var(--border-subtle);
}

.divider,
.md hr {
  background: var(--border-subtle);
}

.icon-btn.active {
  color: var(--text);
  background: var(--bg-hover);
}

.appearance-theme-card[aria-pressed="true"] {
  border-color: var(--border-active);
  outline: none;
}

.appearance-theme-check {
  color: var(--bg);
  background: var(--text);
}

.appearance-scale-slider {
  accent-color: var(--text-muted);
}

.fork-breadcrumb {
  color: var(--text-muted);
  background: var(--bg-element);
  border-color: var(--border-subtle);
}

.fork-breadcrumb-glyph,
.fork-breadcrumb-link:hover {
  color: var(--text-muted);
}

:root[data-theme] :focus-visible {
  outline-color: var(--focus-ring);
}

::selection {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 18%, transparent);
}

.toggle:has(input:checked)::before {
  background: var(--text-muted);
}

.share-color-0 {
  background: var(--text-muted);
}

:root[data-theme] :is(.review-file.active, .model-row.selected, .effort-stop.on) {
  color: var(--text);
}

.modal {
  background: var(--bg-element);
  border-color: var(--border-subtle);
  border-radius: var(--radius-l);
}

/* Light-theme primary actions need a filled, high-contrast accent. */
:root[data-theme$="-light"] .btn-primary:not(.send-btn) {
  color: var(--btn-primary-fg);
  background: var(--btn-primary-bg);
  border-color: transparent;
}

:root[data-theme$="-light"] .btn-primary:not(.send-btn):hover {
  color: var(--btn-primary-fg);
  background: color-mix(in srgb, var(--btn-primary-bg) 85%, var(--bg));
  border-color: transparent;
}

:root[data-theme] .approval-actions .approval-approve {
  color: var(--btn-primary-fg);
  background: var(--btn-primary-bg);
  border-color: transparent;
}

:root[data-theme] .approval-actions .approval-approve:hover {
  color: var(--btn-primary-fg);
  background: color-mix(in srgb, var(--btn-primary-bg) 85%, var(--bg));
  border-color: transparent;
}

.sb-empty-action.primary,
.sb-empty-action.primary:hover {
  color: var(--text-muted);
  background: transparent;
  border-color: transparent;
}

.sb-approval-badge {
  color: var(--text-muted) !important;
  background: transparent !important;
  border: 1px solid var(--border-subtle);
  font-weight: 500 !important;
}

.thread-worktree-chip {
  color: var(--text-muted);
  background: transparent;
  border-color: var(--border-subtle);
}

.thread-worktree-chip:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-active);
}

.thread-worktree-icon,
.thread-worktree-chevron {
  color: var(--text-muted);
}

.contract-strip {
  background: var(--bg-element);
  border-color: var(--border-subtle);
  
}

.contract-sigil {
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-subtle);
}

.contract-evidence-link {
  color: var(--text-muted);
}

.contract-evidence-link:hover {
  color: var(--text);
  border-color: var(--border-active);
}

.fork-breadcrumb-link {
  text-decoration-color: var(--border-active);
}

.work-step.contract-evidence-hit,
.changes-hunk.is-selected {
  background: var(--bg-hover);
  border-color: var(--border-active);
}

.step-status-dot.is-running {
  background: var(--text-muted);
  
}

.changes-panel:focus-visible {
  border-color: var(--focus-ring);
  
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Keep Mac panel interactions outside native window dragging, including handles
   whose hit areas extend into neighbouring chrome. */
html[data-desktop="1"][data-platform="darwin"] :is(
  .panel-resizer, .panel-split, .diagrams-split-handle, .activity-splitter,
  .pane-head, .panel button, .panel [role="button"]
) {
  -webkit-app-region: no-drag;
}

/* The pinned approval host keeps its desktop budget in CSS, so responsive
   sizing can replace it without an inline !important escape. These are the same
   values the HEAD~2 inline style carried, so >=1100px is unchanged. */
.pending-approval-host {
  flex: 0 0 auto;
  max-height: 42vh;
  overflow-y: auto;
}

/* ==========================================================================
   Responsive shell below 1100px.
   Every rule here is inside a media query, so >=1100px desktop geometry,
   chrome, caps and saved preferences are unchanged.
   ========================================================================== */
@media (max-width: 1099px) {
  /* The drawer backdrop only exists for narrow windows; it reserves no space
     on desktop even after a resize leaves a detached node behind. */
  .sidebar-backdrop { display: none; }

  /* A floating pane overlays the chat. The grid track and main width rules live
     in app.css, and the thread lane override in d-shell.css, so this file only
     positions the pane itself. */
  html body .app.panel-overlay > .panel {
    position: absolute;
    top: var(--window-header-h);
    right: 0;
    bottom: 0;
    z-index: 30;
    width: min(var(--panel-w), calc(100vw - var(--rail-w) - 24px));
    min-width: min(260px, calc(100vw - var(--rail-w) - 24px));
    max-width: calc(100vw - var(--rail-w) - 24px);
    height: auto;
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.22);
  }
  html body .app.tasks-docked > .panel {
    position: absolute;
    width: min(var(--panel-w), calc(100vw - var(--rail-w) - 24px));
    max-width: calc(100vw - var(--rail-w) - 24px);
  }

  /* Home must keep its heading, suggestions and composer beside the dock.
     Use a real grid column even when a saved layout asks for an overlay. */
  html body .app:has(.home) {
    grid-template-columns: var(--rail-w) var(--sidebar-w) minmax(0, 1fr) auto;
  }
  html body .app.sidebar-collapsed:has(.home),
  html body .app.sidebar-responsive:has(.home) {
    grid-template-columns: var(--rail-w) 0 minmax(0, 1fr) auto;
  }
  html body .app:has(.home) > .panel {
    position: static;
    width: min(var(--panel-w), 42vw);
    min-width: 0;
    max-width: 42vw;
    box-shadow: none;
  }
  html body .app:has(.home) .thread-view { padding-right: 0; }
  html body .home-starter-ideas .btn {
    min-width: 0;
    max-width: 100%;
    white-space: normal;
  }

  /* Keep the chat composer in view as the transcript and pinned cards grow. */
  html body .main > .thread-view { min-height: 0; overflow: hidden; }
  /* The composer is in normal flow here, so the measured overlay pad would
     become unshrinkable padding and push the composer off screen. Clearance
     belongs inside the scroll content below, so it is counted once. */
  html body #thread:not(:has(.home)) { padding-bottom: 0; }
  /* Keep the clearance in scroll content, where it cannot prevent the
     transcript from shrinking when the approval host or status row grows. */
  html body #thread:not(:has(.home)) > .thread-inner {
    /* The sheet already consumes its measured height in the flex column. */
    padding-bottom: 16px;
  }
  html body .thread { flex: 1 1 auto; min-height: 0; }

  /* The pinned approval host shares the bottom lane with the composer. It
     shrinks before the composer does, and its card body scrolls while the
     action row stays in the host instead of leaving the viewport. */
  html body #pendingApprovalHost {
    flex: 0 1 auto;
    min-height: 0;
    max-height: min(52dvh, calc(100dvh - var(--window-header-h) - 140px));
    padding: 0 12px !important;
    overflow-y: auto;
  }
  /* Keep the definite card cap in d-thread.css. If the host shrinks below
     the actions' intrinsic height, it must scroll rather than clip them. */

  /* Notifications take a real row in the main column. They shrink the chat
     instead of floating over the composer, status row or a decision card. */
  .main > .notification-region { flex: 0 0 auto; width: 100%; }
  .main > .notification-region:empty { display: none; }
  .main > .notification-region .toast-layer,
  .toast-layer {
    position: static;
    right: auto;
    bottom: auto;
    left: auto;
    z-index: 70;
    width: 100%;
    max-width: 928px;
    margin: 0 auto;
    padding: 0 16px calc(8px + env(safe-area-inset-bottom));
    transform: none;
  }
  .toast-layer:empty { display: none; }
  .toast { max-width: 100%; }
  .toast-details { max-height: min(40dvh, 220px); }

  /* The title may shrink to leave room for the actions; every action stays
     visible, so nothing is only reachable through the More menu. */
  html body .titlebar-title { min-width: 0; }
  html body .titlebar-actions { overflow: visible; }
  .titlebar-actions > #deviceChip { max-width: 80px; }
}

/* Size the compact actions against the space inside the native window controls.
   The title gives up its space first; no action is ever hidden. */
@container window-titlebar (width >= 640px) {
  .titlebar-actions { flex-shrink: 0; }
}
/* Last resort below the desktop window minimum: the row scrolls sideways
   rather than dropping a control. The header grows to 44px touch targets and
   keeps every control at that one height. */
@media (max-width: 760px) {
  html body .titlebar {
    --titlebar-control-h: 44px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  html body .titlebar::-webkit-scrollbar { display: none; }
  html body .titlebar .titlebar-text-btn { height: 44px; min-height: 44px; }
  html body .titlebar :is(.orax-mode-switch, .view-switch) { height: 44px; }
  html body .titlebar :is(.orax-mode-option, .view-switch-option) { height: 38px; }
}

@media (max-width: 900px) {
  /* Drawer layout: the sidebar track is always zero; an open drawer floats
     above the chat with a backdrop. */
  .app,
  .app.sidebar-collapsed,
  .app.settings-mode,
  .app.settings-mode.sidebar-collapsed {
    grid-template-columns: var(--rail-w) 0 minmax(0, 1fr) 0;
  }
  .app { --titlebar-h: 2.75rem; }
  html body .titlebar { gap: 4px; padding-right: 6px; }
  html body .titlebar-title { min-width: 0; font-size: 15px; }

  html body .sidebar-backdrop { display: none; }
  html body .app.sidebar-responsive:not(.sidebar-collapsed) > .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: var(--window-header-h) 0 0 var(--rail-w);
    z-index: 39;
    background: rgba(0, 0, 0, 0.38);
  }
  html body .app.sidebar-responsive:not(.sidebar-collapsed) > .sidebar {
    top: var(--window-header-h);
    bottom: 0;
    left: var(--rail-w);
    width: min(var(--sidebar-w), calc(100vw - var(--rail-w)));
    max-width: calc(100vw - var(--rail-w));
    height: auto;
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.22);
  }

  /* Every interactive control inside the phone/tablet layout gets a real
     44px touch target. Rows keep their text but grow vertically instead of
     shrinking the box under the minimum. */
  html body .rail-item {
    flex-basis: 44px;
    width: 100%;
    height: 44px;
    min-height: 44px;
  }
  html body .sb-row {
    height: auto;
    min-height: 44px;
  }
  html body .sb-search .input {
    height: 44px;
    min-height: 44px;
  }
  html body .sb-row-end .icon-btn,
  html body .icon-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    flex-basis: 44px;
  }
  html body .btn,
  html body .chip,
  html body .popup-item {
    min-height: 44px;
  }
}

/* The header row is one line of equal 28px controls at every desktop window
   size, including the 900px minimum. The 44px touch sizing above still covers
   the rail, the sidebar, sheets and the phone-width layout. */
@media (min-width: 761px) and (max-width: 900px) {
  html body .titlebar .icon-btn {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    flex-basis: 28px;
  }
  html body .titlebar :is(.btn, .chip, .titlebar-text-btn) {
    height: 28px;
    min-height: 28px;
  }
}

/* Phones use the same drawer as tablets, but it takes the whole lane beside
   the rail and is closed on entry (main.js applies that default). */
@media (max-width: 599px) {
  html body .app.sidebar-responsive:not(.sidebar-collapsed) > .sidebar-backdrop {
    inset: var(--window-header-h) 0 0 var(--rail-w);
    background: rgba(0, 0, 0, 0.46);
  }
  html body .app.sidebar-responsive:not(.sidebar-collapsed) > .sidebar {
    width: min(var(--sidebar-w), calc(100vw - var(--rail-w)));
    max-width: calc(100vw - var(--rail-w));
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.32);
  }
}

/* Phone home panels use the existing pane header close control and overlay
   the welcome column instead of taking 42% of its width. */
@media (width < 700px) {
  html body .app:has(.home),
  html body .app.sidebar-collapsed:has(.home),
  html body .app.sidebar-responsive:has(.home) {
    grid-template-columns: var(--rail-w) 0 minmax(0, 1fr) 0;
  }
  html body .app:has(.home) > .panel {
    position: absolute;
    /* The fourth grid track is zero here. Resolve percentage widths against
       the app, rather than that track's containing block. */
    grid-column: 1 / -1;
    top: var(--window-header-h);
    right: 0;
    bottom: 0;
    z-index: 30;
    min-width: 0;
    width: calc(100% - var(--rail-w));
    max-width: calc(100% - var(--rail-w));
    height: auto;
  }
}

/* Give the editor and coding suggestions more room in short windows. */
@media (max-width: 1099px) and (max-height: 560px) {
  html body .home-orax { width: 64px; height: 64px; }
  html body .home-orax-picture { display: none; margin-bottom: 4px; }
  html body .home { padding-top: 0; }
  html body .home-title { margin: 0; font-size: var(--text-h1); line-height: var(--leading-h1); }
  html body .home-suggestions { margin-top: 12px; gap: 8px; }
}

/* At high zoom in a short viewport, let the composer scroll so the tab row
   and the transcript can both stay visible. */
@media (max-height: 240px) {
  .app:has(.session-tabs:not([hidden])) #threadView:not(:has(.home)) {
    grid-template-rows: minmax(36px, 1fr);
  }
  .app:has(.session-tabs:not([hidden])) #threadView:not(:has(.home)) > #composerWrap {
    max-height: max(0px, calc(100dvh - var(--window-header-h) - 36px));
    overflow-y: auto;
  }
}

/* Compact approvals occupy their own lane immediately above the composer. */
@media (width < 900px), (height < 560px) {
  html body .main > .thread-view { min-height: 0; overflow: hidden; }
  html body .thread { flex: 1 1 0; min-height: 0; }
  html body #pendingApprovalHost.approval-sheet {
    flex: 0 0 auto;
    max-height: 60dvh;
    overflow: auto;
    box-sizing: border-box;
    padding: 0 12px !important;
  }
  html body .thread-view:has(.approval-sheet:not([hidden])) #runFeedback { display: none; }
  /* Clearance belongs after the content; short transcripts stay at the top. */
  html body .thread-view:has(.approval-sheet:not([hidden])) #thread > .thread-inner {
    /* The sheet reserves its height in flow. Allow a pixel for scrollTop
       rounding so the remaining clearance is always at least 16 CSS px. */
    padding-bottom: calc(var(--approval-sheet-reservation, 17px) - var(--approval-sheet-height, 0px));
  }
  html body #pendingApprovalHost.approval-sheet > .approval {
    margin: 0;
    padding: 8px 12px;
    max-height: min(40dvh, calc(100dvh - var(--window-header-h) - 160px));
    overflow: hidden;
  }
  html body .approval-sheet-details { min-height: 0; overflow: auto; }
  html body .approval-sheet .approval-head { flex: 0 0 auto; }
  html body .approval-sheet .approval-title {
    font-size: 13px;
    line-height: 18px;
    max-height: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  html body .approval-sheet .approval-badges { display: none; }
  html body .approval-sheet .approval-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }
  html body .approval-sheet .approval-actions .btn {
    min-height: 44px;
    max-width: none;
    padding: 4px;
    font-size: 12px;
    white-space: normal;
  }
  html body .approval-sheet .approval-approve { grid-column: 1; grid-row: 1; }
  html body .approval-sheet .approval-deny { grid-column: 2; grid-row: 1; }
  html body #thread .approval[hidden], .approval-inline-summary[hidden] { display: none; }
}

/* A sheet card that is 800px or wider still fits every decision on one row.
   Short-height sheet mode above is about vertical space, not width, so its
   compact two-column grid must not follow a wide card onto a second line.
   This repeats the sheet selector so it outranks that grid at any height. */
@container approval (width >= 800px) {
  html body .approval-sheet .approval-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    grid-template-columns: none;
  }
  html body .approval-sheet .approval-actions .btn {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: min(100%, 16rem);
  }
  html body .approval-sheet .approval-approve,
  html body .approval-sheet .approval-deny {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 599px) {
  html body .app { --rail-w: 0px; }
  html body .app > .rail { display: none; }
}
@media (height < 560px) {
  html body .thread-view:has(.approval-sheet:not([hidden])) .composer-project-slot { display: none; }
  html body .thread-view:has(.approval-sheet:not([hidden])) .composer-input { min-height: var(--composer-min-height); }
}

@media (width < 900px) and (height < 500px) {
  html body .approval-sheet-details { min-height: 0; overflow: auto; }
  html body .approval-sheet-details > summary { line-height: 20px; cursor: pointer; }
  html body .approval-sheet-details[open] { max-height: 60px; }
  html body .thread-view:has(.approval-sheet:not([hidden])) .composer-input {
    height: 24px !important;
    min-height: 24px !important;
    max-height: 24px !important;
    padding-top: 0;
    padding-bottom: 0;
  }
}

@media (width < 900px) {
  html body #pendingApprovalHost.approval-sheet-minimized > .approval { display: none; }
  html body .approval-sheet-bar { width: 100%; min-height: 44px; }
}
