/* Final viewport rules shared by the studio and account pages. */
@media (max-width: 1100px) {
  #studio-app.kind-image .history-media,
  #studio-app.kind-image .history-card:only-child .history-media {
    height: auto !important;
    min-height: 0 !important;
  }
  #studio-app.kind-image .history-media img {
    display: block;
    width: 100%;
    height: auto !important;
    max-height: min(46dvh, 520px);
    object-fit: contain;
  }
}

@media (max-width: 680px) {
  .page-header {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .page-header > div { min-width: 0; width: 100%; }
  .page-header .button {
    position: static !important;
    width: 100% !important;
    min-width: 0;
    margin: 0 !important;
  }
  .page-header h1,
  .pricing-intro h1 {
    font-size: clamp(29px, 9vw, 40px) !important;
    line-height: 1.08 !important;
    overflow-wrap: anywhere;
  }
  #studio-app.kind-image .studio-history-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px;
  }
  #studio-app.kind-image .history-card:only-child { grid-column: auto; }
  #studio-app.kind-image .generation-stage.history-stage {
    min-height: 0 !important;
    max-height: 50dvh !important;
    overscroll-behavior: contain;
  }
  #studio-app.kind-image .history-media img { max-height: 42dvh; }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .cf-composer {
    min-width: 0;
    max-width: 100% !important;
  }
  .usage-table-wrap { max-width: 100%; overflow-x: auto !important; }
}

/* Keep the image prompt dock visible while the results gallery scrolls. */
#studio-app.kind-image .cf-workspace:has(.history-stage) {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  height: calc(100dvh - 60px) !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding: 10px 12px 12px !important;
  gap: 10px !important;
}
#studio-app.kind-image .cf-result-workspace:has(.history-stage) {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 0 !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
#studio-app.kind-image .generation-stage.history-stage {
  flex: 1 1 auto !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: auto !important;
  overscroll-behavior: contain;
}
#studio-app.kind-image .cf-workspace:has(.history-stage) .cf-composer {
  display: flex !important;
  flex-direction: column !important;
  position: relative !important;
  order: 1 !important;
  flex: 0 1 auto !important;
  width: min(1040px,100%) !important;
  max-height: min(40dvh,350px) !important;
  min-height: 0 !important;
  margin: 0 auto !important;
  overflow: visible !important;
}
#studio-app.kind-image .cf-workspace:has(.history-stage) .composer-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}
#studio-app.kind-image .cf-workspace:has(.history-stage) .composer-head,
#studio-app.kind-image .cf-workspace:has(.history-stage) .composer-controls {
  flex: 0 0 auto !important;
}
@media (min-width: 681px) and (max-width: 900px) {
  #studio-app.kind-image .cf-workspace:has(.history-stage) { height: calc(100dvh - 68px) !important; }
}
@media (max-width: 680px) {
  #studio-app.kind-image .cf-workspace:has(.history-stage) {
    height: calc(100dvh - 56px) !important;
    padding: 7px !important;
    gap: 7px !important;
  }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .cf-composer {
    max-height: min(48dvh,390px) !important;
  }
  #studio-app.kind-image .generation-stage.history-stage {
    max-height: none !important;
  }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .composer-controls {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 7px !important;
    padding: 8px !important;
  }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .control-chips {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-wrap: nowrap !important;
    min-width: 0 !important;
    gap: 6px !important;
    overflow-x: auto !important;
    scrollbar-width: none;
  }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .control-chips::-webkit-scrollbar { display: none; }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .control-chips > *,
  #studio-app.kind-image .cf-workspace:has(.history-stage) .quick-settings {
    flex: 0 0 auto !important;
    order: 0 !important;
  }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .model-chip {
    width: auto !important;
    max-width: 145px !important;
  }
  #studio-app.kind-image .cf-workspace:has(.history-stage) .generate-button {
    flex: 0 0 108px !important;
    width: 108px !important;
    height: 44px !important;
  }
}
@media (max-width: 680px) {
  #studio-app .cf-workspace:has(.gallery-status.job-progress) {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  #studio-app .cf-result-workspace:has(.gallery-status.job-progress) {
    height: auto !important;
    min-height: 0 !important;
    flex: none !important;
    overflow: visible !important;
  }
  #studio-app .generation-stage.history-stage:has(.gallery-status.job-progress) {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  #studio-app .gallery-status.job-progress {
    position: relative !important;
    inset: auto !important;
    transform: none !important;
  }
  #studio-app.kind-video .cf-workspace:has(.gallery-status.job-progress) .cf-result-workspace {
    order: -1 !important;
  }
}
