/* ==========================================================================
   editorial-response.css — Adaptive Editorial Response (Figma 498:973 / 499:1227)
   --------------------------------------------------------------------------
   ONE reusable response surface driven by structured data. The Figma Hans Zimmer
   frame is sample content only — this file owns the visual grammar (title,
   gallery, intro, sections, dividers) while content varies per response.

   Extends the existing `.msg-answer` token layer in orchestration.css; does not
   fork it. Namespaced `.oc-ed` for editorial-specific layout only.
   Source of truth: Figma "New Chat — response ready" (498:973).
   ========================================================================== */

.oc-ed {
  max-width: 700px;
  width: 100%;
  align-self: flex-start;
}

/* ------------------------------ title ----------------------------------- */
.oc-ed__title {
  font-family: var(--font-serif);
  font-weight: var(--font-weight-normal);
  font-size: 20px;
  letter-spacing: 0.2px;
  line-height: 1;
  color: var(--color-foreground);
  margin: 0;
}

/* ------------------------- lead (gallery + intro) ----------------------- */
.oc-ed__lead {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

/* ------------------------------ gallery --------------------------------- */
.oc-ed__gallery {
  display: flex;
  gap: 4px;
  width: 100%;
  align-items: flex-end;
}

/* 1 image — full-width hero */
.oc-ed__gallery--solo {
  align-items: stretch;
}
.oc-ed__gallery--solo .oc-ed__figure {
  flex: 1 1 auto;
  max-width: 100%;
}

/* 2 images — equal row */
.oc-ed__gallery--duo {
  align-items: stretch;
}
.oc-ed__gallery--duo .oc-ed__figure {
  flex: 1 1 0;
  min-width: 0;
}

/* 3 images — Figma mosaic: hero left + stack right */
.oc-ed__gallery--mosaic .oc-ed__figure--hero {
  flex: 0 0 min(249px, 58%);
  max-width: 58%;
}
.oc-ed__gallery--mosaic .oc-ed__stack {
  flex: 1 1 0;
  min-width: 0;
  max-width: 42%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 4+ images — responsive grid */
.oc-ed__gallery--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 4px;
  align-items: stretch;
}
.oc-ed__gallery--grid .oc-ed__stack { display: contents; }

/* ------------------------------ figure ---------------------------------- */
.oc-ed__figure {
  position: relative;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-card-background);
}
.oc-ed__figure--hero .oc-ed__img {
  aspect-ratio: 249 / 199;
}
.oc-ed__figure--landscape .oc-ed__img {
  aspect-ratio: 123 / 97;
}
.oc-ed__figure--portrait .oc-ed__img {
  aspect-ratio: 3 / 4;
}
.oc-ed__figure--square .oc-ed__img {
  aspect-ratio: 1 / 1;
}

.oc-ed__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}
.oc-ed__img--placeholder {
  background: linear-gradient(145deg,
    rgba(189, 196, 198, 0.35) 0%,
    rgba(225, 229, 230, 0.55) 100%);
  min-height: 120px;
}

.oc-ed__caption {
  margin-top: 6px;
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 1.35;
  color: var(--color-text-secondary);
}

/* ------------------------------ intro ----------------------------------- */
.oc-ed__intro {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--color-foreground);
}
.oc-ed__intro p { margin: 0 0 0.35em; }
.oc-ed__intro p:last-child { margin-bottom: 0; }

/* ----------------------------- sections --------------------------------- */
.oc-ed__section {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}
.oc-ed__section .msg-answer__h { margin: 0; }
.oc-ed__section .msg-answer__list {
  margin: 0;
  padding-left: 20px;
}
.oc-ed__section .msg-answer__list li {
  font-size: 13.5px;
  line-height: 1.75;
  letter-spacing: -0.405px;
}
.oc-ed__section .oc-ed__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: var(--text-sm);
  line-height: 1.4;
}
.oc-ed__section .oc-ed__body p { margin: 0; }

/* --------------------------- metadata block ----------------------------- */
.oc-ed__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--color-text-secondary);
}
.oc-ed__meta-item::before {
  content: "·";
  margin-right: 6px;
  opacity: 0.6;
}
.oc-ed__meta-item:first-child::before { content: none; margin: 0; }

/* -------------------------- related topics ------------------------------ */
.oc-ed__related {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.oc-ed__related-label {
  font-size: 11.5px;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  margin-right: 2px;
}
.oc-ed__related-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--color-card-background);
  border: 1px solid var(--color-card-border);
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-foreground);
}

/* ============================ responsive ================================ */
@media (max-width: 560px) {
  .oc-ed { max-width: 100%; }

  .oc-ed__gallery--mosaic {
    flex-direction: column;
    align-items: stretch;
  }
  .oc-ed__gallery--mosaic .oc-ed__figure--hero {
    flex: 1 1 auto;
    max-width: 100%;
  }
  .oc-ed__gallery--mosaic .oc-ed__stack {
    flex-direction: row;
    max-width: 100%;
  }
  .oc-ed__gallery--mosaic .oc-ed__stack .oc-ed__figure {
    flex: 1 1 0;
    min-width: 0;
  }

  .oc-ed__gallery--duo { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .oc-ed__img { transition: none; }
}

/* ----------------------------- body slot -------------------------------- */
.oc-ed__body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}
.oc-ed__block { width: 100%; }
.oc-ed__p { font-size: var(--text-sm); line-height: 1.4; margin: 0; }
.oc-ed__p--meta { font-size: 11.5px; color: var(--color-text-secondary); }

/* --------------------------- quote / code ------------------------------- */
.oc-ed__quote {
  margin: 0;
  padding: 12px 16px;
  border-left: 2px solid var(--color-card-border);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-foreground);
}
.oc-ed__quote p { margin: 0; }
.oc-ed__quote-cite {
  display: block;
  margin-top: 8px;
  font-size: 11.5px;
  font-style: normal;
  color: var(--color-text-secondary);
}
.oc-ed__code {
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--color-card-background);
  border: 1px solid var(--color-card-border);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.oc-ed__attribution {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: var(--color-text-secondary);
}

/* ------------------------ image resilience ------------------------------ */
.oc-ed__figure--failed { min-height: 0; background: transparent; }
.oc-ed__img-fallback {
  display: block;
  padding: 12px;
  font-size: 11px;
  color: var(--color-text-secondary);
  font-style: italic;
}
.oc-ed__img--loading {
  background: rgba(225, 229, 230, 0.45);
  min-height: 120px;
}

/* ------------------------------ states ---------------------------------- */
.oc-ed[data-state="loading"] .oc-ed__body,
.oc-ed[data-state="streaming"] .oc-ed__body { min-height: 48px; }
.oc-ed.is-loading .oc-ed__title { opacity: 0.35; }

.oc-ed__loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 8px;
}
.oc-ed__loading-title {
  width: 42%;
  height: 18px;
  border-radius: 4px;
  background: rgba(189, 196, 198, 0.28);
}
.oc-ed__loading-line {
  width: 100%;
  height: 12px;
  border-radius: 4px;
  background: rgba(189, 196, 198, 0.18);
}
.oc-ed__loading-line--short { width: 72%; }

.oc-ed__error { margin-top: 8px; }
.oc-ed__error.msg-error,
.oc-ed .msg-error {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.04);
  font-size: 13px;
  color: var(--color-foreground);
}
.msg-error__retry {
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: 6px;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: var(--font-weight-medium);
  color: var(--color-foreground);
  cursor: pointer;
}
.msg-error__retry:hover { background: rgba(220, 38, 38, 0.06); }
.oc-ed__footer:empty { display: none; }

/* screen-reader live region only */
.oc-ed__live--sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* block reveal inherits msg-answer stagger */
.oc-ed__body > .oc-ed__block,
.oc-ed__body > .msg-answer__rule {
  opacity: 0;
  transform: translateY(4px);
  animation: orch-answer-in 420ms var(--orch-ease, ease) forwards;
  animation-delay: var(--reveal-delay, 0ms);
}

@media (prefers-reduced-motion: reduce) {
  .oc-ed__body > .oc-ed__block,
  .oc-ed__body > .msg-answer__rule {
    animation-duration: 1ms !important;
    transform: none !important;
    opacity: 1 !important;
  }
}
