/* المرحلة 38: «إنشاء صورة» (الصور المنتجة تظهر في جدول «ملفاتي» الموحّد).
   هاتف: عمود واحد وزر الإنشاء ثابت فوق شريط التبويب. لوحي: عمود واحد أعرض.
   حاسوب (≥960px): النموذج في عمود والنتيجة بجانبه. */

.ar-1x1 { aspect-ratio: 1 / 1; }
.ar-3x4 { aspect-ratio: 3 / 4; }
.ar-4x3 { aspect-ratio: 4 / 3; }
.ar-9x16 { aspect-ratio: 9 / 16; }
.ar-16x9 { aspect-ratio: 16 / 9; }

.create-layout {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 960px) {
  .create-layout {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 28px;
  }
  .create-side {
    position: sticky;
    inset-block-start: calc(var(--topbar-h) + 16px);
  }
}

.img-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
}

.img-lead {
  margin: 0;
  color: var(--muted);
}

.img-prompt {
  min-height: 132px;
  font-size: 1rem;
  line-height: 1.6;
}

.img-count {
  align-self: flex-end;
  font-size: 0.78rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.img-aspects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.img-aspect-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-variant-numeric: tabular-nums;
}

.img-aspect-shape {
  display: inline-block;
  block-size: 18px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.img-advanced summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
}

.img-advanced[open] {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.img-submit-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.img-generate {
  min-height: 48px;
  min-width: 180px;
  justify-content: center;
}

.img-usage {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.img-stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.img-frame {
  position: relative;
  inline-size: 100%;
  max-block-size: 70vh;
  margin-inline: auto;
  border-radius: var(--radius);
  border: 1px solid var(--edge-soft);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

/* إطار طويل (9:16) لا يتجاوز ارتفاع الشاشة: يضيق بدل أن يطول */
.img-frame.ar-9x16,
.img-frame.ar-3x4 {
  inline-size: auto;
  block-size: min(70vh, 720px);
  max-inline-size: 100%;
}

.img-frame.is-empty {
  background: var(--grad-soft);
}

.img-frame.is-failed {
  color: var(--err);
}

.img-frame-hint {
  padding-inline: 16px;
  text-align: center;
  font-size: 0.92rem;
}

.img-frame-elapsed {
  font-size: 0.8rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.img-frame-img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
  display: block;
}

.img-result-actions {
  flex-wrap: wrap;
}

.img-recent {
  margin-block-start: 22px;
}

.img-recent-title {
  font-size: 1rem;
  margin: 0 0 10px;
}

.img-recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.img-recent-item {
  padding: 0;
  border: 1px solid var(--edge-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  cursor: pointer;
}

.img-recent-item img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  display: block;
}

.img-recent-empty {
  color: var(--faint);
  margin: 0;
}

/* هاتف: زر الإنشاء يبقى في متناول الإبهام فوق شريط التبويب */
@media (max-width: 599px), (pointer: coarse) and (max-width: 899px), (pointer: coarse) and (orientation: portrait) {
  .img-form {
    padding: 16px;
  }
  .img-submit-bar {
    position: sticky;
    inset-block-end: calc(var(--bottomtabs-h) + env(safe-area-inset-bottom, 0px) + 8px);
    z-index: 5;
    padding: 10px;
    margin-inline: -10px;
    border-radius: var(--radius-sm);
    background: var(--glass);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
  .img-generate {
    flex: 1 1 auto;
  }
  .img-frame.ar-9x16,
  .img-frame.ar-3x4 {
    block-size: min(62vh, 620px);
  }
}

.img-viewer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.img-viewer-img {
  max-inline-size: 100%;
  max-block-size: 70vh;
  margin-inline: auto;
  border-radius: var(--radius-sm);
  display: block;
}

.img-viewer-prompt {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* المرحلة 39: «من نص» / «من صورة» والصور المرجعية */
.img-mode-field { margin-block-end: 4px; }
.img-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.img-ref {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  background-color: var(--surface-2);
  border: 1px solid var(--edge-soft);
  display: grid;
  place-items: center;
}
.img-ref-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-ref-remove {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background-color: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
}
.img-ref-remove svg { width: 16px; height: 16px; }
.img-ref-add { min-height: 72px; }

/* المرحلة 40: اختيار النموذج وخصائصه */
.img-model { width: 100%; }
.img-model-feats {
  display: block;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.img-resolutions { flex-wrap: wrap; }

/* المرحلة 41: الصوت بلا أبعاد — إطار قصير ومشغّل بعرضه */
.img-frame.img-frame-audio {
  min-block-size: 160px;
  padding: 20px;
}

.img-frame-audio-player,
.img-viewer-audio {
  inline-size: 100%;
  max-inline-size: 560px;
  display: block;
  margin-inline: auto;
}

.img-speech-fields {
  display: grid;
  gap: 14px;
}
