#studio {
  --workspace-control-height: 25px;
  --workspace-right-width: min(var(--llm-width), 32vw);
}

#studio .workspace {
  grid-template-columns: min(var(--files-width), 26vw) 6px minmax(0, 1fr) 6px var(--workspace-right-width);
}

#studio > .bar {
  position: relative;
  z-index: 3;
  container: workspace-header / inline-size;
  min-height: 34px;
  gap: 8px;
  padding: 4px 8px;
  background: var(--raised);
}

#studio > .bar .branch { display: block; }
#studio > .bar .branch:empty { display: none; }
#studio > .bar .brand { flex: 0 0 auto; }
#studio > .bar .project-actions { flex: 0 1 auto; }

#studio > .bar :is(button, select) {
  min-height: var(--workspace-control-height);
  border-radius: 5px;
}

#studio > .bar button { flex: 0 0 auto; gap: 4px; padding-inline: 5px; }
#studio > .bar .project-picker > span { color: var(--muted); font-size: 11px; }
#studio > .bar .project-picker select { width: 132px; min-width: 46px; }

.workspace-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
  align-items: center;
  margin-inline-start: auto;
}

.workspace-actions .account-actions {
  margin: 0;
  width: calc(var(--workspace-right-width) - 6px);
  justify-content: flex-end;
  container: workspace-account / inline-size;
}

#only-favorites[aria-pressed="true"] svg { fill: currentColor; }

.author-filter { position: relative; }
.author-filter summary {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--workspace-control-height);
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--button);
  color: var(--text);
  list-style: none;
  cursor: pointer;
  white-space: nowrap;
}
.author-filter summary::-webkit-details-marker { display: none; }
.author-filter:is([open], .is-filtered) summary { background: #31251e; border-color: #73462c; color: var(--focus-hover); }
#author-filter-count { font-size: 11px; font-variant-numeric: tabular-nums; }
.author-menu {
  position: absolute;
  inset: calc(100% + 5px) 0 auto auto;
  width: min(264px, calc(100vw - 12px));
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 8px 24px #0008;
}
.author-menu-header, .author-menu .author-option {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--workspace-control-height);
  padding-inline: 7px;
}
.author-menu-header { justify-content: space-between; padding-block: 4px; border-bottom: 1px solid var(--border); }
.author-menu-options { max-height: min(220px, 45dvh); overflow: auto; padding: 3px; }
.author-option { min-width: 0; cursor: pointer; }
.author-option:hover, .author-option:has(:focus-visible) { background: var(--button); }
.author-option :is(.author-option-name, small) { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.author-option small { margin-inline-start: auto; }

@container workspace-account (max-width: 166px) {
  .workspace-actions .account-actions :is(#billing-open, #users-open) > span { display: none; }
}

@media (min-width: 821px) {
  #studio > .bar .workspace-actions #only-favorites { white-space: nowrap; }
}

#studio :is(.files, .llm) { padding: 6px; }
#studio .files .section-head,
#studio .llm .section-head {
  min-height: var(--workspace-control-height);
  padding: 0 1px;
  margin-block-end: 3px;
}

#studio :is(.files, .llm) .section-head h2 { font-size: 13px; font-weight: 630; }
#studio .files .section-head :is(#folders-root, #assets-root) { margin: 0; padding-inline: 2px; }
#studio :is(.folders, .assets) .tree { flex: 1 1 0; padding: 0 2px; overscroll-behavior: contain; }
#studio .files .tree > .empty { padding: 4px 2px; font-size: 12px; }

.tree-branches { margin: 0; padding: 0; list-style: none; }
.tree-branches .tree-branches {
  margin-inline-start: 7px;
  padding-inline-start: 7px;
  border-inline-start: 1px solid var(--border);
}

.tree-branches .tree-branches > .tree-branch > .tree-row::before {
  content: "";
  position: absolute;
  inset-block-start: calc(var(--workspace-control-height) / 2);
  inset-inline-start: -8px;
  width: 7px;
  border-block-start: 1px solid var(--border);
  pointer-events: none;
}

#studio .files .tree-row {
  position: relative;
  align-items: start;
  gap: 2px;
  padding-inline-start: 0;
  border-radius: 5px;
}

#studio .files .tree-row button,
#studio .files .section-head button {
  min-height: var(--workspace-control-height);
  border-radius: 5px;
}

#studio .files .tree-row > button:first-child {
  width: 100%;
  padding-inline: 3px;
  gap: 4px;
  font-size: 12px;
}

#studio .files .tree-row > button:first-child[aria-pressed="true"] { border-color: #73462c; }
#studio .files .tree-row > button:first-child:not(:hover):not(:focus-visible)[aria-pressed="false"] { background: transparent; }
#studio .files .tree-row > :is(.tree-disclosure, .tree-menu-button) {
  flex: 0 0 auto;
  min-width: var(--workspace-control-height);
  padding: 2px;
  border-color: transparent;
  background: transparent;
}

#studio .files .tree-row > :is(.tree-disclosure, .tree-menu-button):is(:hover, :focus-visible) {
  border-color: var(--border);
  background: var(--button);
}

.tree-disclosure[aria-expanded="true"] svg { rotate: 90deg; }
.tree-row[draggable="true"] { cursor: grab; }
.tree-row[draggable="true"]:active { cursor: grabbing; }

#studio .files .new-folder-row input {
  min-height: var(--workspace-control-height);
  flex-basis: 48px;
  border-color: #835137;
}

#studio .files .new-folder-row button { flex: 0 0 auto; width: var(--workspace-control-height); min-width: 0; }
#studio .files .new-folder-row > button:first-child { width: auto; }
#asset-preview { border-radius: 5px; }
#asset-preview header { flex-wrap: wrap; gap: 3px 5px; }
#asset-preview header strong { flex: 1 1 62px; min-width: 0; font-size: 12px; }
#asset-preview header button {
  flex: 0 0 auto;
  min-height: var(--workspace-control-height);
  margin-inline-start: auto;
  padding-inline: 4px;
  color: var(--focus-hover);
  font-size: 11px;
}

#studio .grip:not(:hover):not(:focus-visible) { border: 0; }
#studio .grip.vertical:not(:hover):not(:focus-visible) {
  background: linear-gradient(var(--muted), var(--muted)) center / 2px 18px no-repeat,
              linear-gradient(var(--border), var(--border)) center / 1px 100% no-repeat;
}

#studio .grip.horizontal:not(:hover):not(:focus-visible) {
  background: linear-gradient(var(--muted), var(--muted)) center / 24px 2px no-repeat,
              linear-gradient(var(--border), var(--border)) center / 100% 1px no-repeat;
}

#llm { container: workspace-llm / inline-size; }
#llm .section-head { flex: 0 0 auto; }

#llm .chat-settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, auto);
  align-items: center;
  gap: 4px;
}

#llm .chat-settings select { min-width: 0; width: 100%; min-height: var(--workspace-control-height); }
.chat-reasoning { display: grid; grid-template-columns: auto minmax(50px, 1fr); gap: 4px; align-items: center; min-width: 0; }
#llm .chat-reasoning .check { min-height: var(--workspace-control-height); font-size: 11px; white-space: nowrap; }
#llm :is(.chat-settings select, .presets-strip summary, #presets-open) { border-radius: 5px; font-size: 12px; }

#llm .presets-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  position: relative;
  min-width: 0;
  gap: 4px;
}

#llm #presets-choice { min-width: 0; position: static; }
#llm #presets-choice > summary {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--workspace-control-height);
  padding: 2px 4px;
  list-style: none;
}

#llm #presets-choice > summary::after { content: none; }
#llm #presets-choice[open] > summary { border-color: var(--focus); }
#llm #presets-choice > summary i { display: flex; rotate: 90deg; }
#llm #presets-choice > summary svg, #llm #presets-open svg { width: 12px; height: 12px; }
#llm #selected-presets { margin-inline-start: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
#llm #presets-open { min-height: var(--workspace-control-height); gap: 3px; padding: 2px 5px; }
#llm #presets-list {
  inset: calc(100% + 3px) 0 auto;
  min-width: 0;
  max-width: none;
  padding: 3px;
  box-shadow: 0 4px 14px #0006;
}

#llm #presets-list label { min-height: var(--workspace-control-height); padding: 2px 5px; border-radius: 4px; cursor: pointer; overflow-wrap: anywhere; }
#llm #presets-list label:is(:hover, :focus-within) { background: var(--surface); }
#llm #presets-list .empty { padding: 4px 3px; font-size: 12px; }

#llm .chat { overscroll-behavior: contain; }
#llm .chat::before { content: none; }
#llm .chat-item:first-child { margin-block-start: auto; }
#llm .chat-item {
  flex: 0 0 auto;
  min-width: 0;
  padding: 4px;
  border-radius: 5px;
  font-size: 12px;
}

#llm .chat-item > header { margin-block-end: 2px; }
#llm .chat-item > header strong { color: var(--focus-hover); font-size: 11px; }
#llm .chat-item[data-role="user"] > header strong { color: var(--muted); }
#llm .chat-item > footer { gap: 3px; flex-wrap: wrap; }
#llm .chat-item > footer button { min-height: var(--workspace-control-height); padding-inline: 4px; font-size: 11px; }

#llm #chat-form { flex: 0 0 auto; display: flex; flex-direction: column; gap: 3px; }
#llm #message { flex: none; min-height: 45px; padding: 4px 5px; overflow: auto; border-radius: 5px; background: var(--raised); }
#llm .send-row { align-items: center; }
#llm .send-row button { min-height: var(--workspace-control-height); border-radius: 5px; }
#llm #send { padding-inline: 7px; font-size: 12px; }
#llm #chat-context { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
#llm #chat-estimate { align-self: end; }
#llm #chat-estimate:empty, #llm #chat-context:empty { display: none; }
#llm #attachments {
  display: grid;
  gap: 3px;
  max-height: 88px;
  overflow: auto;
  padding: 0;
  list-style: none;
}

#llm #attachments:empty { display: none; }
#llm .attachment {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding: 2px 3px;
  font-size: 11px;
}

#llm .attachment span { max-width: none; }
#llm .attachment img { width: 24px; height: 24px; object-fit: contain; border-radius: 3px; background: var(--background); }
#llm .attachment > svg { justify-self: center; }
#llm .attachment button { min-width: 24px; }

@container workspace-llm (max-width: 222px) {
  #llm .chat-settings { grid-template-columns: minmax(0, 1fr); }
}

#panel-dialog:has(.llm-workbench) {
  width: min(980px, calc(100% - 24px));
  height: min(720px, calc(100dvh - 20px));
  max-height: none;
  border-radius: 8px;
}

#panel-dialog:has(.llm-workbench) > header { padding: 8px 12px; }
#panel-dialog:has(.llm-workbench) #panel-content {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  padding: 0;
  overflow: hidden;
}

.llm-workbench {
  display: grid;
  grid-template-columns: clamp(155px, 21%, 208px) minmax(0, 1fr);
  min-height: 0;
}

.llm-preset-library {
  min-width: 0;
  min-height: 0;
  padding: 8px;
  overflow: auto;
  border-inline-end: 1px solid var(--border);
  background: var(--background);
}

.llm-preset-library h3 { margin: 0 3px 5px; font-size: 13px; }
.llm-preset-library .mobile-picker { display: none; }
.llm-preset-library .choice-list { max-height: none; padding: 2px; }
.llm-preset-library .choice-list button { overflow: hidden; min-width: 0; }
.llm-preset-library .choice-list button > span { overflow: hidden; text-overflow: ellipsis; }

.llm-preset-editor {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 9px 12px;
}

.llm-editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 5px; flex-wrap: wrap; }
.llm-editor-title { flex: 1 1 120px; min-width: 0; overflow-wrap: anywhere; }
.llm-editor-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.llm-preset-editor :is(label, .llm-preset-input > span) { color: var(--muted); font-size: 12px; }

.llm-preset-editor .llm-preset-input {
  flex: 1 0 182px;
  display: grid;
  align-content: stretch;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 4px;
}

.llm-preset-editor #preset-editor,
.llm-preset-editor .llm-preview-text {
  min-height: 0;
  min-width: 0;
  padding: 9px;
  margin: 0;
  overflow: auto;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font: 13px/1.5 ui-monospace, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  resize: none;
}

.llm-editor-footer { padding: 8px 12px; border-top: 1px solid var(--border); }
.llm-editor-footer .inline-error { margin-block-end: 5px; }
.llm-editor-footer .dialog-actions { min-width: 0; gap: 5px; }

@media (max-width: 820px) {
  #studio { --workspace-control-height: 32px; }
  #studio > .bar { column-gap: 4px; padding: 5px 6px; }
  #studio > .bar .branch { display: none; }
  #studio > .bar .project-picker select { width: 100%; }
  .workspace-actions { min-width: 0; flex-shrink: 1; }
  .workspace-actions .account-actions { width: auto; container-type: normal; }
  .author-filter { position: static; }
  .author-menu { inset: calc(100% + 4px) 6px auto auto; }
  #studio[data-file="folders"] .files { grid-template-rows: auto minmax(0, 1fr); }
  #studio .files .tree-row > button:first-child { font-size: 13px; }
  #studio .files .tree-row > :is(.tree-disclosure, .tree-menu-button) { min-width: 36px; }
  #llm .chat-reasoning .check, #llm #chat-context { font-size: 12px; }
  #llm .send-row #send { min-height: 36px; }
}

@media (max-width: 670px) {
  #panel-dialog:has(.llm-workbench) { width: min(428px, calc(100% - 12px)); height: min(720px, calc(100dvh - 12px)); }
  .llm-workbench { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .llm-preset-library { padding: 5px 8px; border-inline-end: none; border-bottom: 1px solid var(--border); }
  .llm-preset-library :is(.choice-list, h3) { display: none; }
  .llm-preset-library .mobile-picker { display: block; width: 100%; }
  .llm-preset-editor, .llm-editor-footer { padding: 7px 8px; }
  .llm-preset-editor #preset-editor { font-size: 16px; }
}

@media (max-width: 420px) {
  .author-filter-label { display: none; }
  #studio > .bar .workspace-actions .account-actions :is(#billing-open, #users-open) > span { display: none; }
  #studio > .bar .project-actions :is(#project-settings, #archive-open) > span { display: none; }
}
