/* Ad Engine (/ad-engine): the run form on the left, runs and a report on the
   right. Cards, fields and inputs are AI Studio's (car-studio.css). */

.studio-screen { max-width: 1560px; margin: 0 auto; padding: 28px 28px 72px; }
.ad-engine-screen .library-hero p { max-width: 640px; }

.ad-engine { container-type: inline-size; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 22px; }
@media (max-width: 1100px) { .ad-engine { grid-template-columns: minmax(0, 1fr); } }
.ad-engine-main { display: grid; gap: 16px; min-width: 0; }
.ad-run-form { align-content: start; }
.ad-run-form input[type="file"] { width: 100%; min-width: 0; color: var(--ink-2); font: inherit; font-size: var(--text-sm); }

.ad-runs { container-type: inline-size; min-width: 0; }
.ad-runs table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.ad-runs th { padding: 8px 8px 12px 0; color: var(--ink-3); font-size: var(--text-xs); font-weight: 650; letter-spacing: .04em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.ad-runs td { padding: 10px 8px 10px 0; border-top: 1px solid var(--line); color: var(--ink-2); vertical-align: middle; overflow-wrap: anywhere; }
.ad-runs td:last-child, .ad-runs th:last-child { padding-right: 0; text-align: right; }
.ad-runs a { color: var(--accent-text); }
.ad-run-file { max-width: 200px; }
.ad-run-note { display: block; color: var(--ink-3); font-size: var(--text-xs); white-space: normal; }
.ad-runs :is(.ad-run-house, .ad-run-phase, .ad-run-report) { white-space: nowrap; }
.ad-run-report .button { min-height: 34px; }

@container (max-width: 680px) {
  .ad-runs table, .ad-runs tbody { display: block; }
  .ad-runs thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .ad-runs tbody tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 5px 8px;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid var(--line);
  }
  .ad-runs td { padding: 0; border: 0; min-width: 0; }
  .ad-runs :is(.ad-run-start, .ad-run-file, .ad-run-by) { grid-column: 1 / -1; max-width: none; }
  .ad-runs .ad-run-start { grid-row: 2; color: var(--ink-3); }
  .ad-run-house { grid-area: 1 / 1; color: var(--ink); font-weight: 650; }
  .ad-run-phase { grid-area: 1 / 2; }
  .ad-run-status { grid-area: 1 / 3; justify-self: end; }
  .ad-run-next { grid-column: 1 / 3; }
  .ad-run-report { grid-column: 3; }
  .ad-run-report .button { height: 36px; }
}

.ad-report-body { max-height: 60vh; margin: 0; overflow: auto; padding: 12px; border-radius: var(--radius-sm); color: var(--ink); background: var(--surface-2); font: var(--text-xs)/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.ad-house-page { margin-top: -6px; font-size: var(--text-xs); }
.ad-house-page:empty { display: none; }
.ad-house-page a, .ad-message a { color: var(--accent-text); }
.ad-studio { display: grid; gap: 10px; max-width: 1120px; margin-inline: auto; }
.ad-back { justify-self: start; }
.ad-studio .ad-conversation { height: clamp(360px, calc(100dvh - 188px), 940px); grid-template-rows: auto minmax(0, 1fr) auto; gap: 0; padding: 0; overflow: hidden; }
.ad-chat-head, .ad-composer { padding: 14px 20px; }
.ad-chat-head, .ad-chat-actions, .ad-chat-meta, .ad-send-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.ad-chat-head, .ad-send-row { justify-content: space-between; }
.ad-chat-head { border-bottom: 1px solid var(--line); }
.ad-chat-head h2 { margin: 0 0 6px; color: var(--ink); font-size: var(--text-lg); overflow-wrap: anywhere; }
.ad-chat-meta small, .ad-send-row small { color: var(--ink-3); font-size: var(--text-xs); }
.ad-figma[aria-disabled="true"] { opacity: .55; cursor: default; }
.ad-feed { overflow: auto; overscroll-behavior: contain; }
.ad-entries { display: grid; align-content: start; gap: 9px; max-width: 880px; margin: auto; padding: 20px; }
.ad-message { justify-self: start; max-width: min(100%, 74ch); min-width: 0; padding: 10px 14px; border-radius: var(--radius); background: var(--surface-2); color: var(--ink); font-size: var(--text-md); line-height: 1.5; overflow-wrap: anywhere; }
.ad-message > strong { display: block; margin-bottom: 3px; color: var(--ink-2); font-size: var(--text-xs); }
.ad-user { justify-self: end; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); white-space: pre-wrap; }
.ad-agent > div { overflow-x: auto; }
.ad-agent > div > :first-child { margin-top: 0; }
.ad-agent > div > :last-child { margin-bottom: 0; }
.ad-agent :is(p, ul, ol, pre, table) { margin: .5em 0; }
.ad-agent table { border-collapse: collapse; white-space: nowrap; }
.ad-agent :is(td, th) { padding: 4px 10px; text-align: left; border: 1px solid var(--line-strong); }
.ad-activity, .ad-note { color: var(--ink-3); font-size: var(--text-xs); overflow-wrap: anywhere; }
.ad-activity::before { content: ''; display: inline-block; width: 6px; height: 6px; margin: 0 7px 1px 2px; border-radius: 50%; background: currentColor; }
.ad-activity.live::before { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .ad-activity.live::before { animation: ad-activity-pulse 1.4s ease-in-out infinite alternate; }
  @keyframes ad-activity-pulse { to { opacity: .35; } }
}
.ad-shots { display: flex; align-items: start; gap: 8px; max-width: 100%; overflow-x: auto; }
.ad-shots button { flex: 0 0 auto; display: grid; place-items: center; max-width: 100%; min-width: 0; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); cursor: zoom-in; }
.ad-shots img { display: block; max-height: 340px; max-width: 100%; width: auto; height: auto; }
.ad-note { justify-self: start; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink-2); }
.ad-error { color: var(--danger); }
.ad-composer { display: grid; gap: 8px; border-top: 1px solid var(--line); }
.ad-composer .car-field textarea { min-height: 48px; height: 52px; max-height: 18dvh; }
.ad-send-row { flex-wrap: nowrap; }
.ad-shot-dialog { max-width: 96vw; max-height: 94dvh; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: var(--surface); }
.ad-shot-dialog[open] { display: grid; justify-items: end; gap: 8px; }
.ad-shot-dialog img { display: block; max-width: 90vw; max-height: 78dvh; object-fit: contain; }
.ad-shot-dialog::backdrop { background: var(--overlay); }
@media (max-width: 640px) {
  .ad-chat-head, .ad-composer, .ad-entries { padding: 12px; }
  .ad-studio .ad-conversation { height: calc(100dvh - 145px); min-height: 330px; }
  .ad-chat-head { gap: 10px 16px; }
  .ad-shots button:not(:only-child) { max-width: 72%; }
  .ad-shots img { max-height: 180px; }
  .ad-chat-actions .button { min-height: 36px; }
}

.studio-screen [hidden] { display: none; }
.studio-history { margin-top: 22px; }
.ad-engine .studio-history { margin-top: 0; }
.studio-history-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-bottom: 14px; }
.studio-history-head h2 { margin: 0; margin-inline-end: auto; }
.studio-intake { width: min(820px, 100%); }
.studio-intake > .ad-back { margin-bottom: 10px; }
.studio-folders[open] { display: grid; gap: 6px; }
