.workbench-button, .workbench-controls input, .workbench-controls select {
  min-height: 36px; border: 1px solid var(--border); border-radius: var(--r-2);
  color: var(--ink); background: var(--surface); font: inherit; font-size: var(--fs-3);
  padding: 7px 12px;
}
.workbench-button { cursor: pointer; }
.workbench-button:hover:not(:disabled), .workbench-file-open:hover { background: var(--surface-2); }
.workbench-button:focus-visible, .workbench-file-open:focus-visible, .workbench-controls select:focus-visible,
.workbench-controls input:focus-visible, .workbench-source:focus-visible, .workbench-steps summary:focus-visible {
  outline: 2px solid var(--teal-ink); outline-offset: 3px;
}
.workbench-button:disabled { opacity: .6; cursor: default; }
.workbench-primary { color: var(--accent-ink); background: var(--teal); border-color: var(--teal); }
.workbench-primary:hover:not(:disabled) { color: var(--accent-ink); background: var(--teal); }
.workbench-message:empty { display: none; }
.workbench-files { display: grid; gap: 0; margin-top: 8px; max-width: 680px; overflow: hidden; border: 1px solid color-mix(in srgb, var(--text-3) 16%, transparent); border-radius: var(--r-2); background: var(--surface); }
.workbench-file { display: flex; gap: 8px; align-items: center; min-width: 0; padding: 8px 12px; border: 0; border-radius: 0; background: var(--surface); font-size: var(--fs-2); }
.workbench-file > svg { flex: none; color: var(--muted); }
.workbench-file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.workbench-file-size { color: var(--muted); white-space: nowrap; }
.workbench-file > .workbench-button { margin-left: auto; flex: none; }
.workbench-delivery { min-width: 0; }
.workbench-inline { margin-top: 0; }
.workbench-files:has(.workbench-inline) { max-width: none; }
.workbench-inline-body { min-width: 0; overflow: hidden; border-radius: 0; background: var(--surface); }
.workbench-inline-body iframe { display: block; width: 100%; border: 0; color-scheme: light; background: var(--document-canvas); }
.workbench-flow-actions { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 8px; margin: 0; padding: 8px 12px; border: 0; color: var(--muted); background: var(--surface); font-size: var(--fs-2); }
.workbench-file-label { display: flex; gap: 8px; align-items: center; min-width: 0; color: var(--muted); }
.workbench-file-label > svg { flex: none; }
.workbench-file-label > span { min-width: 0; overflow-wrap: anywhere; }
:is(.workbench-flow-actions,.workbench-file) .workbench-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 32px; padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--r-1); background: var(--surface); color: var(--ink); font-size: var(--fs-2); white-space: nowrap; transition: background var(--theme-color-time) var(--ease-out); }
:is(.workbench-flow-actions,.workbench-file) .workbench-button:hover:not(:disabled) { background: var(--hover); color: var(--ink); text-decoration: none; }
.workbench-button[aria-busy="true"] { cursor: wait; opacity: .6; }
.workbench-file .workbench-download-icon { width: 32px; padding: 4px; }
.workbench-inline-status { margin: 0; padding: 16px; color: var(--muted); font-size: var(--fs-3); overflow-wrap: anywhere; }
.workbench-inline-body > .workbench-button { margin: 0 16px 16px; }
.workbench-steps { color: var(--muted); font-size: 11.5px; max-width: 680px; margin-top: 8px; }
.workbench-steps summary { cursor: pointer; padding: 4px 0; font-size: inherit; font-weight: 400; }
.workbench-steps summary span { margin-left: 8px; font-variant-numeric: tabular-nums; }
.workbench-steps ol { padding-left: 24px; margin: 4px 0; }
.workbench-steps li { padding: 4px 0; }
.workbench-steps small { font-size: inherit; margin-left: 8px; }
.workbench-steps p { margin: 4px 0; overflow-wrap: anywhere; }
.message-actions .message-copy-button { min-width: 28px; min-height: 28px; padding: 4px; border: 0; color: var(--muted); background: transparent; }
.message .bubble:empty { display: none; }
.workbench-dialog { width: min(1120px, 94vw); height: min(860px, 90dvh); max-width: 100vw; max-height: 100dvh; padding: 0; border: 1px solid var(--border); border-radius: var(--r-3); color: var(--ink); background: var(--surface); }
.workbench-dialog::backdrop { background: var(--studio-scrim); }
.workbench-dialog-shell { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.workbench-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.workbench-dialog h2 { margin: 0; font-size: var(--fs-6); font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.workbench-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 14px 22px 0; }
.workbench-controls:empty { padding: 0; }
.workbench-controls label { display: flex; align-items: center; gap: 8px; font-size: var(--fs-3); min-width: 0; white-space: nowrap; }
.workbench-controls select { max-width: min(300px, 70vw); }
.workbench-controls input { min-width: 0; width: min(270px, 58vw); }
.workbench-status { margin: 0; padding: 12px 22px; font-size: var(--fs-2); color: var(--muted); overflow-wrap: anywhere; }
.workbench-body { flex: 1; min-height: 0; overflow: auto; padding: 0 22px 22px; }
.workbench-file-list { display: grid; gap: 10px; }
.workbench-empty { color: var(--muted); line-height: 1.8; max-width: 65ch; }
.workbench-preview { height: 100%; min-height: 200px; }
.workbench-preview iframe { display: block; width: 100%; height: 100%; min-height: 200px; border: 1px solid var(--line); border-radius: var(--r-1); color-scheme: light; background: var(--document-canvas); }
.workbench-preview pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-3); line-height: 1.7; margin: 0; }
.workbench-document { max-width: 75ch; margin: 0 auto; line-height: 1.8; font-size: var(--fs-4); overflow-wrap: anywhere; }
.workbench-document table { display: block; overflow-x: auto; max-width: 100%; border-collapse: collapse; }
.workbench-document td, .workbench-document th { border: 1px solid var(--border); padding: 8px; }
.workbench-document pre { overflow-x: auto; white-space: pre; }
.workbench-source { display: block; width: 100%; height: 100%; min-height: 240px; box-sizing: border-box; resize: none; border: 1px solid var(--border); border-radius: var(--r-2); padding: 16px; font: inherit; font-size: var(--fs-3); line-height: 1.7; color: var(--ink); background: var(--surface); tab-size: 2; }
.workbench-source[hidden], .workbench-preview[hidden], .workbench-button[hidden], [hidden] { display: none; }

/* Legacy & Exported Code-Video Cards */
.code-video-delivery {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface);
}
.code-video-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.code-video-status strong { flex: 1; min-width: 120px; font-size: var(--fs-3); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-video-status > span, .code-video-note { color: var(--muted); font-size: var(--fs-2); }
.code-video-note { margin: 6px 0 0; }
.code-video-player { display: block; width: 100%; max-height: min(48vh, 420px); aspect-ratio: 16/9; margin-top: 10px; border-radius: var(--r-2); background: #0f0f11; object-fit: contain; }
.code-video-player > video-skin { display: block; width: 100%; aspect-ratio: 16/9; --media-controls-before-start: visible; overflow: hidden; border-radius: var(--r-2); }
.code-video-downloads, .code-video-files > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.code-video-downloads .workbench-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 5px 11px; font-size: var(--fs-2); border-radius: var(--r-1); }
.code-video-files { margin-top: 10px; color: var(--muted); font-size: var(--fs-2); }
.code-video-files summary { cursor: pointer; padding: 4px 0; }
.code-video-files pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto; }
.code-video-error { color: var(--red, #b13f36); white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-3); }
.code-video-refresh { margin-top: 8px; }
.code-video-process { margin: 10px 0; color: var(--muted); font-size: var(--fs-2); }
.code-video-process > summary { cursor: pointer; padding: 6px 0; }
.code-video-check { padding: 10px 0; border-top: 1px solid var(--border); }
.code-video-check > span { display: block; }

/* ── V2 1080P Browser Sandbox Code-Video Studio Card (Zero Inner Scroll) ── */
@media (min-width: 981px) {
  .chat-shell:has(.code-video-web-card) {
    --chat-side-pad: clamp(16px, 2.2vw, 32px);
  }
  .message.assistant:has(.code-video-web-card) .message-copy-scope {
    max-width: min(920px, 100%);
  }
}

.cv-card-slot {
  margin-top: 10px;
  min-width: 0;
}

.code-video-web-card {
  margin-top: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.cv-ui-ico {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  display: block;
}

.cv-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-width: 0;
}

.cv-card-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.cv-stage-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  font-size: var(--fs-1);
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-fg);
  border: 1px solid var(--accent-line);
  white-space: nowrap;
}

.cv-stage-pill.is-final {
  background: var(--accent-base);
  color: var(--on-accent);
  border-color: var(--accent-base);
}

.cv-card-title {
  min-width: 0;
  font-size: var(--fs-3);
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cv-card-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.cv-gpu-badge {
  font-size: var(--fs-1);
  color: var(--text-3);
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--hover);
  white-space: nowrap;
}

.cv-theater-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  height: 28px;
  padding: 0 9px;
  font-size: var(--fs-1);
  font-weight: 500;
  border-radius: var(--r-1);
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.cv-theater-btn:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
}

.cv-card-note {
  margin: 0;
  padding: 6px 12px;
  font-size: var(--fs-1);
  line-height: 1.5;
  color: var(--text-3);
  background: color-mix(in srgb, var(--bg-side) 60%, var(--surface));
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.cv-card-note.is-expanded {
  white-space: normal;
  overflow: visible;
}

.code-video-web-stage {
  margin: 0;
  width: 100%;
  container-type: inline-size;
  overflow: hidden;
  background: #111114;
}

.cv-stage-loading {
  margin: 0;
  padding: 48px 16px;
  text-align: center;
  color: #a1a1aa;
}

/* Exact 1:1 height lock: 36px studio topbar + 16:9 stage + 50px transport = 100cqw * 9/16 + 86px.
   Capped by viewport height so even compact laptops fit the entire workspace without scrolling. */
.code-video-web-iframe {
  display: block;
  width: 100%;
  height: calc(100cqw * 9 / 16 + 86px);
  max-height: calc(100dvh - 236px);
  min-height: 236px;
  border: 0;
  overflow: hidden;
  background: #111114;
}

.code-video-web-actions {
  margin: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cv-action-primary-wrap,
.cv-tool-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.code-video-web-actions .workbench-button {
  min-height: 34px;
  height: 34px;
  padding: 0 11px;
  font-size: var(--fs-2);
  border-radius: var(--r-1);
}

.code-video-web-actions .primary-export-btn {
  background: var(--accent-base);
  color: var(--on-accent);
  border-color: var(--accent-base);
  font-weight: 600;
  padding: 0 13px;
}

.code-video-web-actions .primary-export-btn svg {
  color: var(--on-accent);
}

.code-video-web-actions .primary-export-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-base) 90%, var(--text) 10%);
  color: var(--on-accent);
  border-color: transparent;
}

.cv-export-status {
  margin: 0 0 0 auto;
  font-size: var(--fs-1);
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Wide Theater Engineering Mode (In-Place Fixed Expansion, Zero Iframe Reload) ── */
.cv-theater-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: var(--studio-scrim);
  backdrop-filter: blur(4px);
}

#messages .message:has(.code-video-web-card.is-theater) {
  content-visibility: visible;
  contain: none;
}

.code-video-web-card.is-theater {
  position: fixed;
  inset: clamp(10px, 2.5vh, 24px) clamp(10px, 2.5vw, 32px);
  max-width: 1460px;
  max-height: 920px;
  margin: auto;
  z-index: 1210;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.42);
  border-color: var(--border-strong);
}

@media (max-height: 780px) {
  .code-video-web-card:not(.is-theater) .code-video-web-iframe {
    max-height: calc(100dvh - 340px);
  }
}

.code-video-web-card.is-theater .cv-card-note {
  white-space: normal;
}

.code-video-web-card.is-theater .code-video-web-stage {
  flex: 1 1 auto;
  min-height: 0;
}

.code-video-web-card.is-theater .code-video-web-iframe {
  height: 100%;
  max-height: none;
  min-height: 0;
}

@media (max-width: 640px) {
  .workbench-flow-actions { padding: 8px; }
  :is(.workbench-flow-actions,.workbench-file) .workbench-button { min-height: 40px; }
  .workbench-file .workbench-download-icon { width: 40px; }
  .workbench-dialog { margin: 0; width: 100%; height: 100dvh; border-radius: 0; border: 0; }
  .workbench-dialog header { padding: 14px 16px; }
  .workbench-controls { padding: 12px 16px 0; gap: 8px; }
  .workbench-status { padding: 12px 16px; }
  .workbench-body { padding: 0 16px 16px; }
  .workbench-file { gap: 8px; padding: 8px; }
  .workbench-controls label { flex-wrap: wrap; }
  .workbench-button { min-height: 40px; }

  .cv-gpu-badge { display: none; }
  .cv-theater-btn span { display: none; }
  .cv-theater-btn { width: 32px; min-height: 32px; height: 32px; padding: 0; justify-content: center; }
  .code-video-web-iframe {
    max-height: calc(100dvh - 180px);
    min-height: 220px;
  }
  .code-video-web-actions {
    padding: 8px 10px;
    gap: 6px;
  }
  .code-video-web-actions .workbench-button {
    min-height: 36px;
    height: 36px;
    padding: 0 10px;
  }
  .cv-export-status {
    margin-left: 0;
    width: 100%;
  }
  .code-video-web-card.is-theater {
    inset: 0;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: 0;
  }
}

.code-video-downloads .workbench-button[hidden],
.code-video-web-actions [hidden],
.cv-theater-backdrop[hidden] {
  display: none;
}
