/* ============================================================
   Studio
   ============================================================ */

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.active-profile-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 13px;
}
.active-profile-chip strong { font-weight: 600; color: var(--text); }

.dot {
  width: 8px; height: 8px; border-radius: 0;
  background: var(--text-faint);
  display: inline-block;
}
.dot[data-status="ok"]   { background: var(--success); }
.dot[data-status="err"]  { background: var(--danger); }
.dot[data-status="warn"] { background: var(--warning); }

.field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}
.field > span { font-weight: 500; }
.field-row { display: flex; justify-content: space-between; align-items: center; }
.hint-right { color: var(--text-faint); font-weight: 400; }

.field input,
.field select,
.field textarea,
.profile-form input,
.profile-form select,
.profile-form textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit; font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field textarea { resize: vertical; min-height: 100px; }
.field input:focus, .field select:focus, .field textarea:focus,
.profile-form input:focus, .profile-form select:focus, .profile-form textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: none;
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  padding: 0;
  margin: 0;
  display: inline-grid;
  place-content: center;
  vertical-align: middle;
  border: 1.5px solid var(--border-strong);
  border-radius: 0;
  background-color: var(--surface);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 13px 13px;
  box-shadow: none;
  cursor: pointer;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease,
    transform 120ms ease;
}
input[type="checkbox"]:hover {
  border-color: var(--brand);
  box-shadow: none;
}
input[type="checkbox"]:checked {
  border-color: var(--brand);
  background-color: var(--brand);
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 14 14' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 7.2L5.7 10L11 4' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  box-shadow: none;
}
input[type="checkbox"]:indeterminate {
  border-color: var(--brand);
  background-color: var(--brand);
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 14 14' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.2 7H10.8' stroke='white' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
  box-shadow: none;
}
input[type="checkbox"]:active:not(:disabled) {
  opacity: 0.8;
}
input[type="checkbox"]:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: none;
}
input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  box-shadow: none;
}

.prompt-field textarea {
  min-height: 140px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.prompt-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 0;
}
.prompt-workbench[data-optimized="true"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}
.prompt-workbench .field { margin-bottom: 0; }
.prompt-optimized-field[hidden] { display: none; }
.prompt-workbench[data-prompt-source="manual"] #prompt,
.prompt-workbench[data-prompt-source="optimized"] #optimizedPrompt {
  border-color: var(--brand);
  box-shadow: none;
}
.prompt-optimized-field textarea {
  min-height: 168px;
  background: var(--surface-2);
  border-color: var(--border-strong);
  line-height: 1.78;
  letter-spacing: 0.01em;
}
.prompt-optimized-field .field-row > span:first-child::before {
  content: '// ';
  color: var(--text-faint);
}

@media (max-width: 840px) {
  .prompt-workbench[data-optimized="true"] {
    grid-template-columns: minmax(0, 1fr);
  }
}

.hint { color: var(--text-faint); font-size: 12.5px; margin: -4px 0 12px; }
.secret-runtime-note {
  display: block;
  margin-top: 6px;
  color: var(--warning);
  font-size: 12px;
  line-height: 1.45;
}
#promptHint {
  margin: 10px 0 20px;
  line-height: 1.75;
}

.reference-panel {
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface-2);
}
.reference-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.reference-head h3 {
  margin: 0 0 4px;
  font-size: 14px;
}
.reference-head .hint {
  margin: 0;
  line-height: 1.55;
}
.reference-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.reference-upload-button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  transition: background 120ms ease, border-color 120ms ease;
}
.reference-upload-button:hover {
  background: var(--surface-2);
}
.reference-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}
.reference-list[data-empty="true"] {
  display: block;
}
.reference-empty {
  padding: 12px;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  background: var(--surface);
  font-size: 12.5px;
}
.reference-item {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface);
}
.reference-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface-3);
}
.reference-item-meta {
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--text-faint);
  font-size: 11px;
}
.reference-item-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reference-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 0;
  color: white;
  background: rgba(0, 0, 0, 0.62);
  padding: 3px 7px;
  font-size: 11px;
  cursor: pointer;
}

@media (max-width: 720px) {
  .prompt-field kbd,
  .kbd-inline { display: none; }
  .field input,
  .field select,
  .field textarea,
  .profile-form input,
  .profile-form select,
  .profile-form textarea {
    font-size: 16px;
  }
  .active-profile-chip {
    width: auto;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }
  .active-profile-chip > span:not(.dot) {
    min-width: 0;
    display: inline-flex;
    flex: 1 1 auto;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
  }
  .active-profile-chip strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .active-profile-chip .tab-link {
    flex: 0 0 auto;
    min-height: 44px;
    margin-left: auto;
  }
  .reference-head {
    flex-direction: column;
  }
  .reference-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }
  .reference-actions > * {
    width: 100%;
    min-height: 44px;
  }
  .reference-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .reference-remove {
    width: 44px;
    height: 44px;
    padding: 0;
  }
}

.advanced {
  margin: 4px 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface-2);
}
.advanced > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 500; color: var(--text-muted);
  list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before {
  content: '▸';
  transition: transform 120ms ease;
  color: var(--text-faint);
}
.advanced[open] > summary::before { transform: rotate(90deg); }
.advanced > div { padding: 4px 14px 14px; }

.options {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.action-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 8px 0 12px;
}

.prompt-source-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface-2);
}
.prompt-source-switch button {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.prompt-source-switch button:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}
.prompt-source-switch button.active {
  background: var(--brand);
  color: var(--bg);
}
.prompt-source-switch button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.estimate {
  color: var(--text-faint); font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

button {
  font: inherit;
  padding: 9px 16px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
button:hover { background: var(--surface-2); }
button:active { opacity: 0.85; }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--brand); color: var(--bg); border-color: var(--brand);
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 500;
}
button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
button.primary .kbd-inline {
  background: rgba(128,128,128,0.2);
  border-color: rgba(128,128,128,0.3);
  color: var(--bg);
  font-size: 10.5px;
}

button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 12.5px; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }

.error {
  margin: 8px 0;
  padding: 10px 14px;
  background: var(--danger-soft);
  border: 1px solid transparent;
  border-left: 3px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-btn);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.progress {
  margin: 8px 0;
  padding: 10px 14px;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: var(--radius-btn);
  font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.progress::before {
  content: '\2022';
  font-size: 18px;
  line-height: 1;
}
.progress-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0;
}
.progress-grid[hidden] { display: none; }
.progress-grid:has(.progress-task[hidden]:first-child):has(.progress-task[hidden]:last-child) {
  display: none;
}
.progress-task {
  margin: 0;
  min-height: 42px;
  align-items: flex-start;
}
.progress-task strong {
  flex: 0 0 auto;
  padding-right: 8px;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}
.progress-task [data-progress-message] {
  min-width: 0;
  color: inherit;
  word-break: break-word;
}
.progress-task[data-task="optimize"] {
  background: var(--surface-2);
  color: var(--brand);
}
.progress-task[data-task="generate"] {
  background: var(--surface-2);
  color: var(--success);
}
@media (max-width: 720px) {
  .progress-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  #studioPanel .action-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
  }
  #studioPanel .prompt-source-switch {
    grid-column: 1 / -1;
    width: 100%;
  }
  #studioPanel .prompt-source-switch button {
    min-width: 0;
    min-height: 44px;
    flex: 1 1 50%;
    padding-inline: 8px;
  }
  #studioPanel #optimizePrompt,
  #studioPanel #generate {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }
  #studioPanel .estimate {
    grid-column: 1 / -1;
  }
  .advanced > summary { min-height: 44px; }
}

@media (max-width: 980px) {
  .shell.app-layout {
    display: block;
    max-width: 1200px;
  }
  body.job-queue-visible .shell.app-layout,
  .shell.app-layout.job-queue-visible {
    max-width: 1200px;
  }
  .job-queue-dock {
    position: fixed;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(68px + env(safe-area-inset-bottom));
    top: auto;
    z-index: 55;
    max-height: min(72vh, 620px);
    max-height: min(72dvh, 620px);
    min-height: 0;
    overflow: auto;
    transform: translateY(calc(100% + 96px));
    opacity: 0;
    pointer-events: none;
    transition: transform 180ms ease, opacity 180ms ease;
  }
  body.job-queue-open .job-queue-dock {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .job-queue-mobile-button {
    display: inline-flex;
  }
}



.row { display: flex; gap: 8px; }
.wrap-row { flex-wrap: wrap; }
