/* The workbench: a navigation rail, a top bar, and the composer in the middle. */

.workbench {
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
  height: 100%;
  overflow: hidden;
}

/* The page itself never scrolls: the stage does, inside. The grid takes the full height, so
   anything that follows it in <body> (a browser extension's element) would otherwise open a
   scrollbar. */
.workbench-page {
  overflow: hidden;
  --bar-height: 64px;
  --reading: 850px;
}

.skip-link {
  position: absolute;
  left: var(--s2);
  top: var(--s2);
  z-index: 3;
  padding: var(--s2) var(--s3);
  background: var(--raised);
  border-radius: var(--r-control);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.noscript-note {
  position: fixed;
  inset: auto 0 0 0;
  padding: var(--s3);
  background: var(--danger);
  color: #1a0907;
  text-align: center;
}

/* ---- Navigation rail ------------------------------------------------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  padding: var(--s4);
  background: var(--rail);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s1);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: none;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--r-control);
  color: var(--secondary);
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  background: var(--raised);
  color: var(--text);
}

.icon-button:disabled {
  color: var(--muted);
  opacity: 0.55;
  cursor: not-allowed;
}

.rail-history {
  border-top: 1px solid var(--line);
  margin-top: var(--s3);
  padding: var(--s3);
  min-height: 0;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
}

.rail-history[hidden], .rail-collapsed .rail-history { display: none; }
.rail-history h2 { font-size: inherit; margin-bottom: var(--s2); }
.rail-history ul { list-style: none; margin: 0; padding: 0; }
.rail-history li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
.rail-history-actions { display: flex; }
.rail-history-actions button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.rail-history-actions button:hover { background: var(--raised); color: var(--text); }
.history-action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); }
.history-delete-copy { margin: 0; overflow-wrap: anywhere; }
#history-title-field[hidden] { display: none; }
.rail-history a {
  display: block;
  padding: var(--s2);
  color: var(--text);
  border-radius: var(--r-control);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-history a:is(:hover, [aria-current]) { background: var(--raised); }

.rail-group {
  display: grid;
  gap: var(--s1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.rail-group[hidden] {
  display: none;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  min-height: 44px;
  padding: 0 var(--s3);
  background: transparent;
  border: 0;
  border-radius: var(--r-control);
  color: var(--secondary);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.rail-item:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

.rail-item.is-current {
  background: var(--accent-dim);
  color: var(--accent);
}

.rail-item:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

/* The section the composer is working in. Sections are chosen, not navigated to, so the state
   is `aria-pressed` rather than `aria-current`. */
.rail-item[aria-pressed="true"] {
  background: var(--raised);
  color: var(--text);
}

/* Collapsed rail: 64px. Labels are clipped out of sight but stay in the accessibility tree, so
   every item keeps its name. Icons are not touched: the toggle's arrow must stay visible, it is
   the only way to open the rail again. */
.workbench.rail-collapsed {
  grid-template-columns: var(--rail-width-collapsed) 1fr;
}

.rail-collapsed .rail {
  align-items: center;
  padding-inline: var(--s2);
}

.rail-collapsed .rail-head {
  flex-direction: column-reverse;
  padding: 0;
}

.rail-collapsed .rail-item {
  justify-content: center;
  padding: 0;
  min-width: 44px;
}

.rail-collapsed .brand > span,
.rail-collapsed .rail-item > span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Shell: bar and stage ----------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-rows: var(--bar-height) 1fr;
  min-width: 0;
  overflow: hidden;
}

.bar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s4);
  padding-inline: var(--s6);
  border-bottom: 1px solid var(--line);
  background: var(--page);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  :root[data-theme="light"] :is(.rail, .bar) {
    background: rgb(246 252 243 / 64%);
    border-color: rgb(58 101 76 / 24%);
    -webkit-backdrop-filter: blur(16px) saturate(115%);
    backdrop-filter: blur(16px) saturate(115%);
  }
}

/* The rail's own close control, shown only where the rail is a menu (the narrow screen rule
   below). A menu needs a visible way out: once it has slid in, it covers the bar's menu button. */
.rail-menu {
  display: none;
}

.bar-menu {
  display: none;
}

.bar-title {
  flex: none;
  font-weight: 650;
}

.notice {
  flex: 1;
  min-width: 0;
  color: var(--secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.points-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.theme-picker {
  min-height: 44px;
  padding-inline: var(--s3) var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--page);
  color: var(--text);
  cursor: pointer;
}

.balance-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  min-height: 44px;
  padding: 0 var(--s3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.balance-chip-unit {
  color: var(--muted);
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: var(--accent-dim);
  border-radius: 50%;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.stage {
  display: grid;
  align-content: start;
  gap: var(--s8);
  padding: var(--s12) var(--s8);
  overflow-y: auto;
}

/* ---- Composer ---------------------------------------------------------------------------- */

.composer {
  width: min(var(--reading), 100%);
  margin: 0 auto;
}

.composer-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s6);
  min-height: 166px;
  margin-bottom: var(--s6);
}

.greeting {
  font-size: 42px;
  font-weight: 650;
  line-height: 1.2;
  text-wrap: balance;
}

.intro-copy > p {
  margin-top: var(--s3);
  color: var(--secondary);
  font-size: 16px;
}

.intro-art {
  width: 150px;
  height: auto;
  flex: none;
  max-width: 40%;
}

.intro-copy .workbench-signature {
  margin-top: var(--s4);
  color: var(--accent);
  font-size: 14px;
  font-weight: 650;
}

.draft-starts {
  margin: var(--s8) 0 0;
}

.draft-starts h2 {
  margin-bottom: var(--s2);
  font-size: 15px;
}

.draft-starts-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 var(--s4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.draft-starts button {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  min-height: 48px;
  padding: var(--s2) var(--s1);
  border: 0;
  border-block-start: 1px solid var(--line);
  background: transparent;
  color: var(--secondary);
  text-align: start;
  cursor: pointer;
}

.draft-starts button:hover {
  background: var(--surface);
  color: var(--text);
}

.draft-arrow {
  margin-inline-start: auto;
  color: var(--muted);
}

.composer:has(.reply:not([hidden])) .draft-starts {
  display: none;
}

.composer-card {
  display: grid;
  gap: var(--s2);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: 0 12px 36px rgb(0 0 0 / 16%);
}

.composer-card:focus-within {
  border-color: var(--accent);
}

.composer-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
}

.composer-hint {
  color: var(--muted);
  font-size: 13px;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
  margin: 0;
  padding: 0 var(--s1);
  list-style: none;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  max-width: 100%;
  padding: var(--s1) var(--s1) var(--s1) var(--s3);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
}

.attachment-name {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.attachment-remove {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.attachment-remove:hover {
  background: var(--surface);
  color: var(--text);
}

/* ---- The asset picker --------------------------------------------------------------------- */

.asset-picker {
  width: min(560px, calc(100vw - 2 * var(--s4)));
  max-height: calc(100vh - 2 * var(--s4));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: auto;
}

.asset-picker::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.asset-picker-panel {
  display: grid;
  gap: var(--s4);
  padding: var(--s6);
}

.asset-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.asset-picker-title {
  font-size: 18px;
  line-height: 1.3;
}

.asset-picker-list {
  display: grid;
  gap: var(--s1);
  max-height: 50vh;
  overflow-y: auto;
}

.asset-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 var(--s2);
  align-items: center;
  min-height: 48px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  cursor: pointer;
}

.asset-option:hover {
  border-color: var(--accent);
}

.asset-option input {
  grid-row: span 2;
}

.asset-option-name {
  overflow-wrap: anywhere;
}

.asset-option-meta {
  color: var(--muted);
  font-size: 12px;
}

.asset-picker-empty {
  color: var(--muted);
}

.asset-picker-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
}

/* The section chips above the card. On a phone they wrap instead of scrolling sideways. */
.section-picker {
  flex: 0 1 auto;
  max-width: 100%;
}

.chip {
  max-width: 100%;
  min-height: 44px;
  padding: 0 var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--secondary);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.chip[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.composer-input {
  width: 100%;
  min-height: 108px;
  max-height: 40vh;
  padding: var(--s2) var(--s1);
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  line-height: 1.6;
  resize: none;
}

.composer-input::placeholder {
  color: var(--muted);
}

.composer-input:focus {
  outline: none;
}

.composer-foot {
  padding-top: var(--s2);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.composer-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.composer-status {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.composer-link {
  font-size: 13px;
}

.composer-note {
  color: var(--secondary);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.composer-actions {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  margin-inline-start: auto;
  gap: var(--s2);
}

.composer-tools > .section-picker {
  width: auto;
}

/* The model and the skill: only what the chosen section offers. */
.composer-options {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.composer-skills {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.composer-skills > legend {
  margin-bottom: var(--s1);
}

.composer-rate {
  color: var(--secondary);
  font-size: 13px;
  text-align: end;
}

.composer-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s3);
}

.composer-inputs input {
  max-width: 9rem;
}

/* The assistant's per-send creative budget. Hidden until the assistant is the chosen section;
   the attribute rule wins over the grid display below. */
.composer-budget {
  display: grid;
  gap: var(--s1);
}

.composer-budget[hidden] {
  display: none;
}

.composer-budget input {
  max-width: 11rem;
}

.composer-budget .composer-hint {
  margin: 0;
}

.option-field {
  display: grid;
  gap: var(--s1);
  min-width: 0;
}

.option-label {
  color: var(--muted);
  font-size: 13px;
}

.option-select {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--s2);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
}

.skill-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
}

.skill-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  max-width: 100%;
  min-height: 44px;
  padding: 0 var(--s3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--secondary);
  font-size: 13px;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.skill-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.skill-chip:has(input:checked) {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.send {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--accent);
  border: 0;
  border-radius: var(--r-control);
  color: var(--on-accent);
  cursor: pointer;
}

.send:hover:not(:disabled) {
  filter: brightness(1.1);
}

.send:disabled {
  background: var(--raised);
  color: var(--muted);
  cursor: not-allowed;
}

/* Stop is a control in its own right, not a send that happens to be greyed out. */
.send-stop {
  background: var(--raised);
  color: var(--text);
}

.send-stop:disabled {
  background: var(--raised);
  color: var(--muted);
}

/* ---- The answer to this turn --------------------------------------------------------------- */

.reply {
  margin-top: var(--s6);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

.reply[hidden] {
  display: none;
}

.reply-label {
  margin-bottom: var(--s2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.reply-text {
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* A caret while text is still arriving, so an empty reply does not look like a failure. */
.chat-answer[aria-busy="true"]::after {
  content: "▍";
  color: var(--accent);
}

.composer > .reply {
  margin: 0 0 var(--s4);
  min-width: 0;
  max-height: 52dvh;
  overflow: auto;
  overscroll-behavior: contain;
}

.chat-turn + .chat-turn {
  margin-top: var(--s6);
  padding-top: var(--s4);
  border-top: 1px solid var(--line);
}

.chat-question {
  width: fit-content;
  max-width: 90%;
  margin: 0 0 var(--s4) auto;
  padding: var(--s2) var(--s3);
  background: var(--accent-dim);
  color: var(--text);
  border-radius: var(--r-card);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-question .reply-label {
  margin-bottom: var(--s1);
  color: var(--secondary);
}

.reply-markdown {
  white-space: normal;
  overflow-x: auto;
}

.reply-markdown > * + * { margin-top: var(--s3); }
.reply-markdown pre { overflow: auto; padding: var(--s3); background: var(--raised); }
.reply-markdown blockquote { margin-inline: 0; padding-inline-start: var(--s3); border-inline-start: 1px solid var(--line); }
.reply-markdown table { border-collapse: collapse; }
.reply-markdown :is(td, th) { padding: var(--s1) var(--s2); border: 1px solid var(--line); }

.stage:not(.is-generation-view) .composer:has(#reply:not([hidden])) .composer-intro {
  display: none;
}

/* ---- Generation jobs ----------------------------------------------------------------------- */
/* A job is a turn in the conversation stream, styled as a card. Its place in the stream and its
   spacing come from #reply-text, not from a section of its own. */

.job-head > :is(.job-prompt, .job-section) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.job-details {
  color: var(--muted);
  font-size: 13px;
}

.job-details[open] {
  flex-basis: 100%;
}

.job-details summary {
  width: fit-content;
  padding-block: var(--s2);
  cursor: pointer;
}

.job-full-prompt {
  margin-bottom: var(--s2);
  color: var(--secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.job-pending {
  display: grid;
  min-height: clamp(116px, 24dvh, 270px);
  align-content: center;
  justify-items: center;
  gap: var(--s2);
  padding: var(--s3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--muted);
  text-align: center;
}

.job-pending[hidden], .job-progress[hidden], .job-confirm[hidden] {
  display: none;
}

.job-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
}

.job-progress {
  width: min(220px, 100%);
  height: 10px;
  accent-color: var(--accent);
}

.job-command {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  background: var(--raised);
  border: 1px solid transparent;
  border-radius: var(--r-control);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.job-command[hidden] {
  display: none;
}

.job-command:hover {
  border-color: var(--accent);
}

.job-command .ui-icon {
  width: 16px;
  height: 16px;
}

.job-confirm {
  display: flex;
  flex: 0 0 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
}

.job-confirm .job-note {
  flex-basis: 100%;
}

.job-result img {
  justify-self: start;
  object-fit: contain;
  width: auto;
  max-height: min(420px, 50dvh);
}

.job {
  display: grid;
  gap: var(--s2);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

/* The stream interleaves chat turns and job cards; every turn gets the same breathing room. */
#reply-text > * + * {
  margin-top: var(--s6);
}

#reply-text > .job {
  width: 100%;
}

/* Older jobs are read a page at a time; the control sits above the conversation stream. */
#reply > .job-more {
  display: block;
  width: fit-content;
  margin: 0 auto var(--s4);
  padding: var(--s2) var(--s3);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

#reply > .job-more[hidden] {
  display: none;
}

#reply > .job-more:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
}

#reply > .job-more:disabled {
  color: var(--muted);
  cursor: progress;
}

.job-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-start;
  gap: var(--s3);
}

.job-section {
  color: var(--secondary);
  font-size: 13px;
}

.job-state {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.job-state[data-job-status="running"] {
  color: var(--accent);
}

.job-state[data-job-status="succeeded"] {
  color: var(--accent);
}

.job-state[data-job-status="failed"] {
  color: var(--danger);
}

.job-prompt {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.job-meta {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.job-result {
  display: grid;
  gap: var(--s2);
}

.job-result[hidden] {
  display: none;
}

.job-media {
  max-width: 100%;
  max-height: 360px;
  border-radius: var(--r-control);
  background: var(--rail);
}

audio.job-media,
video.job-media {
  width: 100%;
  max-height: none;
}

.job-note {
  color: var(--muted);
  font-size: 13px;
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

.job-cancel,
.job-download {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--s3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--secondary);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.job-cancel:hover:not(:disabled),
.job-download:hover {
  border-color: var(--accent);
  color: var(--text);
}

.job-cancel:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.job-download {
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* ---- Tooltip for unavailable controls ----------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 4;
  max-width: 260px;
  padding: var(--s2) var(--s3);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
}

/* ---- Narrower screens --------------------------------------------------------------------- */

/* Between 768 and 1199px the rail is always collapsed. workbench.js puts ``rail-collapsed`` on
   the page at that width, so the collapsed look is described once, above, and not again here. */
@media (min-width: 768px) and (max-width: 1199px) {
  .workbench {
    grid-template-columns: var(--rail-width-collapsed) 1fr;
  }
}

@media (max-width: 767px) {
  .workbench {
    grid-template-columns: 1fr;
  }

  .bar-menu {
    display: inline-grid;
  }

  /* The rail becomes a menu that slides in over the page. */
  .rail-menu {
    display: inline-grid;
  }
  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 2;
    width: min(var(--rail-width), 84vw);
    align-items: stretch;
    box-shadow: var(--shadow-panel);
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
  }

  .workbench.menu-open .rail {
    transform: none;
  }

  .rail-head {
    flex-direction: row;
    padding: 0 var(--s1);
  }

  .rail-item {
    justify-content: flex-start;
  }

  #rail-toggle {
    display: none;
  }

  .stage {
    padding: var(--s6) max(var(--s4), env(safe-area-inset-right))
      calc(var(--s12) + env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left));
  }

  .bar {
    gap: var(--s2);
    padding-inline: var(--s2) var(--s3);
  }

  .bar-actions {
    margin-inline-start: auto;
  }

  .composer-intro {
    gap: var(--s2);
    min-height: 0;
    margin: var(--s3) 0 var(--s6);
  }

  .intro-art {
    max-width: 31%;
  }

  .intro-copy > p {
    font-size: 14px;
  }

  .greeting {
    font-size: 26px;
  }

  .draft-starts-list {
    grid-template-columns: 1fr;
  }

  .composer-hint {
    flex-basis: 100%;
  }

  .composer-input {
    font-size: 16px;
  }

  .notice:not(:empty) {
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .bar {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    min-height: var(--bar-height);
    padding-block: var(--s2);
  }

  .bar > .avatar {
    grid-column: 4;
    grid-row: 1;
  }

  .bar-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    margin-inline-start: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

/* Assistant: messages scroll independently and the composer stays at the bottom. */
.assistant-empty { display: none; }

.stage.is-assistant-view {
  align-content: stretch;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  gap: var(--s4);
  padding: 0;
  overflow: hidden;
}

.stage.is-assistant-view:has(#saved-work:not([hidden])) {
  grid-template-rows: minmax(0, auto) minmax(0, 1fr);
}

.is-assistant-view #saved-work { overflow: auto; max-height: 35dvh; margin: 0; }
.is-assistant-view .composer {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  width: 100%;
  min-height: 0;
}
.is-assistant-view .composer > :is(.reply, .assistant-empty, .composer-card) {
  grid-area: 1 / 1;
  min-width: 0;
}

.is-assistant-view :is(.composer-intro, .draft-starts) { display: none; }
.is-assistant-view #reply[hidden] + .assistant-empty {
  display: grid;
  align-content: center;
  gap: var(--s2);
  text-align: center;
  color: var(--secondary);
}
.assistant-empty p:first-child { color: var(--text); font-size: clamp(22px, 4vw, 32px); font-weight: 650; }

.is-assistant-view .composer > .reply {
  margin: 0;
  max-height: none;
  padding: var(--s4) var(--s4) calc(var(--assistant-dock-height, 0px) + var(--s8) + env(safe-area-inset-bottom));
  border: 0;
  background: none;
  overflow-anchor: none;
}
.is-assistant-view .composer > .reply > * {
  width: min(100%, var(--reading));
  margin-inline: auto;
}
.is-assistant-view .chat-turn + .chat-turn { border: 0; padding: 0; margin-top: var(--s6); }
.is-assistant-view .chat-turn.chat-question { padding: var(--s2) var(--s3); }
.is-assistant-view .composer-card {
  z-index: 1;
  align-self: end;
  justify-self: center;
  width: min(var(--reading), calc(100% - 2 * var(--s4) - var(--reply-scrollbar, 0px)));
  margin-right: var(--reply-scrollbar, 0px);
  margin-bottom: max(var(--s4), env(safe-area-inset-bottom));
  max-height: 56dvh;
  overflow: auto;
}
.is-assistant-view .composer-input { min-height: 58px; height: 4em; }
.is-assistant-view .composer-foot:has(#composer-status:empty):not(:has(progress:not([hidden]), #composer-link:not([hidden]))) {
  display: none;
}

.composer-details summary {
  width: fit-content;
  padding: var(--s1) var(--s2);
  color: var(--secondary);
  font-size: 13px;
  line-height: 24px;
  border-radius: var(--r-control);
  cursor: pointer;
}
.composer-details summary:hover { background: var(--raised); color: var(--text); }
.composer-detail-fields { display: grid; gap: var(--s2); padding-block: var(--s2); }
.composer-details:not([open]) .composer-detail-fields { display: none; }
