:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #71717a;
  --line: #e8e8ec;
  --soft: #f6f6f7;
  --panel: #ffffff;
  --brand: #ffe575;
  --brand-strong: #ffd84d;
  --green: #0f9f6e;
  --red: #d92d20;
  --blue: #246bfe;
  --shadow: 0 14px 40px rgba(25, 25, 25, 0.08);
  --page-gap: clamp(0.5rem, 1.1vw, 0.875rem);
  --panel-pad: clamp(0.75rem, 1.4vw, 1.125rem);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  background: #f2f2f4;
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  min-width: 0;
}


.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 2.5rem);
  background:
    linear-gradient(135deg, rgba(255, 229, 117, 0.42), rgba(36, 107, 254, 0.12)),
    #f4f4f5;
}

.login-shell {
  width: min(58rem, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 24rem);
  gap: clamp(1rem, 4vw, 3rem);
  align-items: center;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.login-mark {
  width: clamp(4.75rem, 11vw, 7rem);
  height: clamp(4.75rem, 11vw, 7rem);
  display: grid;
  place-items: center;
  border-radius: 1.125rem;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-mark img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

.login-brand strong {
  display: block;
  font-size: clamp(2.4rem, 7vw, 4.75rem);
  line-height: 0.95;
  font-weight: 950;
}

.login-brand span {
  display: block;
  margin-top: 0.7rem;
  color: #52525b;
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 800;
}

.login-panel {
  display: grid;
  gap: 1rem;
  padding: clamp(1.25rem, 3vw, 1.75rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  font-size: 1.65rem;
}

.login-panel .primary-btn {
  width: 100%;
  height: 2.9rem;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  width: 100%;
  padding-right: 3rem;
}

.password-toggle {
  position: absolute;
  right: 0.45rem;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #71717a;
}

.password-toggle:hover,
.password-toggle.active {
  background: #f2f2f4;
  color: #111;
}

.password-toggle svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-hint {
  min-height: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-shell {
  min-height: 100dvh;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logout-btn {
  height: 36px;
  min-width: 4.5rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 900;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 3.75rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  padding: 0.625rem clamp(0.75rem, 2vw, 1.375rem);
  background: #1b1b1d;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  overflow: hidden;
}

.brand-mark img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-size: clamp(1.35rem, 2.3vw, 1.8rem);
  line-height: 1;
  font-weight: 900;
}

.config-btn {
  height: 36px;
  min-width: 4.5rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 0 16px;
  background: #fff;
  color: #111;
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(255, 255, 255, 0.08);
}

.config-btn:hover,
.config-btn:active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

nav {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
}

.nav-btn,
.ghost-btn,
.icon-btn {
  border: 0;
  background: transparent;
}

.nav-btn {
  height: 34px;
  padding: 0 12px;
  color: #f4f4f5;
  border-radius: 6px;
}

.nav-btn.active,
.nav-btn:hover {
  color: #111;
  background: var(--brand);
}

.api-badge {
  justify-self: end;
  max-width: min(28vw, 22.5rem);
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #e8e8ec;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(20rem, 1.2fr) minmax(18rem, 0.9fr) minmax(18rem, 1fr);
  gap: var(--page-gap);
  padding: var(--page-gap);
  height: calc(100dvh - 3.75rem);
  min-height: 0;
}

.panel {
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls,
.task-panel {
  height: 100%;
  max-height: 100%;
  overflow: auto;
}

.preview-panel {
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-panel .panel-head {
  flex: 0 0 auto;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: var(--panel-pad) var(--panel-pad) 0.5rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.task-heading-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.panel-head p,
.muted {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 8px;
  padding: 0.625rem var(--panel-pad);
}

.field span {
  color: #3f3f46;
  font-size: 13px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.55;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: #1d1d1f;
  box-shadow: 0 0 0 3px rgba(255, 229, 117, 0.55);
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0.5rem var(--panel-pad) 0.625rem;
}

.upload-card {
  position: relative;
  min-height: clamp(10rem, 18vw, 13rem);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  overflow: hidden;
  border: 1px dashed #cacad1;
  border-radius: 8px;
  background: #fbfbfc;
}

.upload-card.required {
  border-color: #d2b436;
  background: #fffbed;
}

.garment-box,
.scene-box {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.garment-uploader {
  min-height: clamp(6.5rem, 11vw, 8.5rem);
}

.garment-uploader small {
  color: var(--muted);
  font-size: 12px;
}

.garment-list {
  display: flex;
  gap: 8px;
  max-height: clamp(7.5rem, 14vw, 9.5rem);
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.garment-empty {
  width: 100%;
  min-height: 5.5rem;
  display: grid;
  place-items: center;
  border: 1px dashed #dedee4;
  border-radius: 8px;
  color: #8b8b94;
  font-size: 12px;
  font-weight: 800;
  background: #fbfbfc;
}

.garment-item {
  position: relative;
  flex: 0 0 clamp(6.25rem, 26%, 7.75rem);
  min-width: 6.25rem;
  max-width: 7.75rem;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.garment-item img {
  width: 100%;
  height: clamp(4.25rem, 8vw, 5.75rem);
  object-fit: contain;
  background: #f7f7f8;
  border-radius: 6px;
}

.garment-order {
  position: absolute;
  top: 8px;
  left: 8px;
  max-width: calc(100% - 16px);
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(17, 17, 17, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.garment-name {
  min-width: 0;
  color: #52525b;
  font-size: 11px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.garment-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.garment-actions button {
  min-width: 0;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: #f1f1f3;
  color: #27272a;
  font-weight: 900;
}

.garment-actions button:disabled {
  cursor: not-allowed;
  color: #a1a1aa;
}

.upload-card input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-card span {
  color: #52525b;
  font-size: 13px;
  font-weight: 700;
}

.upload-card strong {
  padding: 7px 12px;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font-size: 13px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.08);
}

.upload-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  object-fit: contain;
  background: #fff;
}

.remove-image {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  display: none;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(17, 17, 17, 0.82);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.upload-card.has-image img {
  display: block;
}

.upload-card.has-image .remove-image {
  display: block;
}

.upload-card.has-image span,
.upload-card.has-image strong {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.86);
}

.model-box {
  display: grid;
  align-content: start;
  gap: 10px;
}

.scene-box {
  padding: 0.5rem var(--panel-pad) 0.625rem;
}

.scene-toggle {
  max-width: 100%;
}

.scene-upload {
  min-height: clamp(8rem, 14vw, 10rem);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #ededf0;
}

.segmented button {
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #52525b;
  font-weight: 700;
}

.segmented button.active {
  background: #fff;
  color: #111;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.08);
}

.field.compact {
  padding: 0;
}

.template-action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.description-template-row {
  padding: 0 var(--panel-pad) 0.625rem;
}

.inline-template-row {
  padding: 0;
}

.template-action-row .ghost-btn {
  min-width: 0;
  padding-inline: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-action-row select {
  min-width: 0;
}

.danger-text {
  color: var(--red);
}

.ghost-btn.danger-text {
  border: 1px solid rgba(217, 45, 32, 0.28);
  background: #fff1f0;
  color: var(--red);
}

.ghost-btn.danger-text:hover:not(:disabled) {
  border-color: rgba(217, 45, 32, 0.45);
  background: #ffe1de;
}

.ghost-btn.danger-text:disabled {
  border-color: #f2c7c3;
  background: #fff7f6;
  color: #d7a19b;
}

#aiModelPanel {
  display: grid;
  gap: 10px;
}

.hidden {
  display: none !important;
}

.params-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 0.5rem var(--panel-pad) 0.625rem;
}

.advanced {
  margin: 0.25rem var(--panel-pad) 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfc;
}

.advanced summary {
  padding: 12px;
  cursor: pointer;
  font-weight: 700;
}

.advanced textarea {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.25rem var(--panel-pad) var(--panel-pad);
}

.primary-btn {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: #111;
  color: #fff;
  font-weight: 800;
}

.primary-btn:hover {
  background: #2a2a2d;
}

.primary-btn:disabled {
  cursor: not-allowed;
  background: #a1a1aa;
}

.ghost-btn {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 12px;
  background: #f1f1f3;
  color: #27272a;
  font-weight: 700;
}

.ghost-btn:hover {
  background: #e5e5e9;
}

#formHint,
#configHint {
  color: var(--muted);
  font-size: 13px;
}

#maskedKey {
  padding: 0 var(--panel-pad) 0.625rem;
  overflow-wrap: anywhere;
}

.reference-preview {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 0.625rem var(--panel-pad) 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(135deg, #fafafa, #f0f0f2);
}

.reference-preview canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.empty-reference {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8b8b94;
  font-weight: 800;
}

.prompt-preview {
  flex: 1 1 0;
  min-height: 0;
  height: auto;
  max-height: none;
  margin: 0.5rem var(--panel-pad) var(--panel-pad);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161618;
  color: #f7f7f8;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 12px;
  overflow: auto;
}

.task-list {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 0.625rem var(--panel-pad) var(--panel-pad);
}

.task-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 0 var(--panel-pad);
  padding: 10px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.task-bulk-actions,
.task-page-strip,
.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.task-bulk-actions {
  min-width: max-content;
}

.task-bulk-actions .ghost-btn {
  white-space: nowrap;
}

.task-pagination {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.task-page-strip {
  width: max-content;
  min-width: max-content;
  margin-left: auto;
  padding-bottom: 1px;
}

.page-info,
.page-jump {
  flex: 0 0 auto;
  color: #52525b;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.page-jump input {
  width: 4rem;
  height: 2rem;
  padding: 0 0.45rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.task-pagination .ghost-btn {
  flex: 0 0 auto;
  height: 2rem;
  padding: 0 0.65rem;
  white-space: nowrap;
}

.task-toolbar > * {
  min-width: 0;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #3f3f46;
  font-size: 13px;
  font-weight: 800;
}

.check-row input,
.task-select input {
  width: 16px;
  height: 16px;
  accent-color: #111;
}

.task-item {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.task-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.task-thumb {
  position: relative;
  height: clamp(8.5rem, 19vw, 11rem);
  background: #f4f4f5;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  padding: 6px;
  color: #8b8b94;
  overflow: hidden;
}

.task-thumb.multi {
  overflow-x: auto;
}

.thumb-preview {
  flex: 1 1 100%;
  min-width: 0;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: #fff;
  overflow: hidden;
}

.task-thumb.multi .thumb-preview {
  flex: 0 0 clamp(5.75rem, 34%, 8rem);
}

.thumb-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: left center;
  background: #fff;
}

.task-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.76);
  color: #27272a;
  font-weight: 800;
}

.task-loading span {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(17, 17, 17, 0.16);
  border-top-color: #111;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.task-loading strong {
  font-size: 13px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.task-body {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
}

.task-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.task-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.task-title {
  min-width: 0;
  font-weight: 800;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.35;
}

.status {
  flex: none;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.status.queued {
  background: #eff6ff;
  color: var(--blue);
}

.status.running {
  background: #fff7d1;
  color: #8a6100;
}

.status.succeeded {
  background: #e8fff4;
  color: var(--green);
}

.status.failed {
  background: #fff0ef;
  color: var(--red);
}

.task-meta,
.task-error,
.task-warning {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.task-error {
  color: var(--red);
}

.task-time {
  color: #3f3f46;
  font-weight: 800;
}

.task-warning {
  color: #8a6100;
}

.task-actions button {
  min-height: 30px;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 0.375rem;
  background: #fff;
  color: #27272a;
  font-weight: 700;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.task-actions button.danger {
  color: var(--red);
}

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.config-dialog {
  width: min(48rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2.75rem);
  overflow: auto;
  padding: 0;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #f2f2f4;
  font-size: 20px;
}

.config-grid {
  display: grid;
  grid-template-columns: minmax(18rem, 0.8fr) minmax(20rem, 1.2fr);
  gap: var(--page-gap);
  padding: 0.5rem 0 0.75rem;
}

.config-grid-single {
  grid-template-columns: minmax(0, 1fr);
}

.template-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
}

.template-editor {
  max-height: min(35rem, 62dvh);
  overflow: auto;
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.template-row {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfc;
}

.template-row textarea {
  min-height: 84px;
  font-size: 12px;
}

.template-row button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #fff0ef;
  color: var(--red);
  font-weight: 900;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}

.image-dialog {
  width: min(70rem, calc(100vw - 1.25rem));
  height: min(44rem, calc(100dvh - 1.25rem));
  max-height: calc(100dvh - 1.25rem);
  overflow: hidden;
  padding: 0;
}

.image-dialog[open] {
  display: flex;
  flex-direction: column;
}

.image-dialog .dialog-head {
  flex: 0 0 auto;
}

.image-preview-frame {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 1.5rem);
  background: #f4f4f5;
  overflow: hidden;
}

.image-fit-box {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-dialog img {
  box-sizing: border-box;
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.small-dialog {
  width: min(39rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 0;
}

.small-dialog textarea {
  min-height: 190px;
}

@media (max-width: 75rem) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .api-badge {
    grid-column: auto;
    width: 100%;
    max-width: none;
    justify-self: stretch;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    height: auto;
    min-height: calc(100dvh - 3.75rem);
  }

  .controls,
  .preview-panel,
  .task-panel {
    height: auto;
    max-height: none;
  }

  .preview-panel {
    min-height: clamp(34rem, 72dvh, 42rem);
  }

  .task-panel {
    grid-column: 1 / -1;
  }

  .task-list {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  }
}

@media (max-width: 56rem) {
  .config-grid {
    grid-template-columns: 1fr;
  }

  .template-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .template-row textarea {
    grid-column: 1 / -1;
  }
}

@media (max-width: 48rem) {
  .login-view {
    place-items: start stretch;
    min-height: 100dvh;
    padding: 1rem;
  }

  .login-shell {
    width: 100%;
    max-width: 26rem;
    margin: 0 auto;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: stretch;
  }

  .login-brand {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding-top: clamp(0.5rem, 4dvh, 2rem);
    text-align: center;
  }

  .login-mark {
    width: 4.5rem;
    height: 4.5rem;
  }

  .login-brand strong {
    font-size: clamp(2.25rem, 12vw, 3.3rem);
  }

  .login-brand span {
    margin-top: 0.4rem;
    font-size: 0.98rem;
  }

  .login-panel {
    width: 100%;
    padding: 1rem;
  }

  :root {
    --page-gap: 0.5rem;
    --panel-pad: 0.75rem;
  }

  .topbar {
    position: static;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .brand {
    min-width: 0;
  }

  nav {
    width: 100%;
  }

  .nav-btn {
    flex: 1 0 auto;
  }

  .api-badge {
    grid-column: 1 / -1;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .panel {
    min-width: 0;
  }

  .preview-panel {
    min-height: 0;
  }

  .reference-preview {
    flex: 0 0 clamp(12rem, 42dvh, 18rem);
    min-height: clamp(12rem, 42dvh, 18rem);
  }

  .prompt-preview {
    flex: 0 1 auto;
    min-height: clamp(16rem, 52dvh, 24rem);
  }

  .upload-grid,
  .params-grid {
    grid-template-columns: 1fr;
  }

  .actions-row,
  .dialog-actions {
    flex-wrap: wrap;
  }

  .primary-btn,
  .actions-row .primary-btn,
  .dialog-actions .primary-btn {
    width: 100%;
  }

  .task-thumb {
    height: clamp(10rem, 52vw, 16rem);
  }

  .config-dialog,
  .small-dialog,
  .image-dialog {
    width: calc(100vw - 1rem);
    height: calc(100dvh - 1rem);
    max-height: calc(100dvh - 1rem);
  }

  .image-dialog img {
    max-width: 100%;
    max-height: 100%;
  }
}

@media (max-width: 28rem) {
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .task-toolbar {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 8px;
  }

  .task-bulk-actions {
    width: 100%;
    justify-content: space-between;
  }

  .task-pagination {
    width: 100%;
  }

  .task-page-strip {
    margin-left: 0;
  }

  .task-toolbar .ghost-btn,
  .page-info,
  .page-jump {
    flex: 0 0 auto;
  }

  .task-title-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }
}
