/* AI studio, client requests, AI observations and the client Ask drawer. Owned by the AI UI work package.
   Builds on the .studio, .chat, .proposal and .drawer rules in app.css; colors come from the theme variables. */

/* The hidden attribute must win over the display rules below (and in app.css). */
.studio [hidden], .studio-banner[hidden], .studio-feedback [hidden], .ask [hidden], #ask-root [hidden], .api-form [hidden], .insight-card [hidden] { display: none !important; }

/* ── Studio layout ─────────────────────────────────────────────────────── */
.studio { height: calc(100vh - 210px); min-height: 560px; position: relative; }
.studio--agency { height: calc(100vh - 200px); }
.studio__chat { position: relative; background: var(--surface); }
.studio__bar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.studio__picker { flex: 1; min-width: 0; height: 30px; padding: 4px 8px; font-size: 13px; }
.studio-banner { margin-bottom: 12px; }
.studio-feedback .flash { margin-bottom: 12px; }
.studio-callout { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--brand-soft); border-left: 3px solid var(--brand); font-size: 13px; color: var(--text-2); }

/* Preview controls */
.studio__control { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.studio__control select { width: auto; max-width: 220px; height: 30px; padding: 4px 8px; font-size: 13px; }
.studio__proposed { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); font-size: 12px; font-weight: 600; }
.studio__proposed-dot { width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; }
.studio__proposed .btn { height: 24px; color: var(--text-2); }
.studio__open { margin-left: auto; }
.studio__frame-wrap { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.studio__frame-wrap .empty { margin: auto; }
.studio__frame-wrap::after { content: ""; position: absolute; top: 0; left: 0; height: 2px; width: 0; background: var(--accent); opacity: 0; transition: opacity 0.2s; }
.studio__frame-wrap.is-loading::after { opacity: 1; animation: studio-loading 1.2s ease-in-out infinite; }
@keyframes studio-loading { 0% { left: 0; width: 0; } 50% { left: 20%; width: 60%; } 100% { left: 100%; width: 0; } }

/* ── Chat (shared by the studio and the Ask drawer) ─────────────────────── */
.chat__turn { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.chat__turn > .proposal, .chat__turn > .chat__warning, .chat__turn > .ask-sent { align-self: stretch; }
.chat__msg h3, .chat__msg h4 { font-size: 13.5px; margin: 6px 0 4px; }
.chat__msg a { text-decoration: underline; }
.chat__intro { color: var(--text-2); }
.chat__steps { font-size: 12px; color: var(--text-3); }
.chat__steps summary { cursor: pointer; width: fit-content; border-radius: var(--radius-sm); }
.chat__steps ul { margin: 4px 0 0; padding-left: 18px; }
.chat__warning { border: 1px solid #fcd34d; background: var(--warn-bg); color: #92400e; border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12.5px; }
.chat__warning p { margin: 2px 0 4px; }
.chat__warning ul { margin: 0; padding-left: 18px; }
.chat__warning .chat__numbers { display: flex; flex-wrap: wrap; gap: 4px 6px; list-style: none; padding: 0; margin: 2px 0 4px; }
.chat__numbers li { background: var(--surface); border: 1px solid #fcd34d; border-radius: 4px; padding: 0 6px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chat__error { border: 1px solid #fecaca; background: var(--bad-bg); color: #991b1b; border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; }
.chat__note { margin: 0; font-size: 12px; color: var(--text-3); }
.chat__buttons { display: flex; flex-direction: column; gap: 6px; }
.chat__form textarea { resize: none; }
.chat__hint { margin: 0; padding: 0 12px 8px; font-size: 11px; color: var(--text-3); }
.chat__suggestions { padding-top: 4px; }
.chip { text-align: left; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Status pills on these pages are labels in sentence case ("Needs review"), not raw status keys. */
.request-card .status, .insight-card .status, .request-table .status { text-transform: none; }

/* Proposal cards */
.proposal__summary { margin: 0 0 6px; font-size: 13px; }
.proposal__changes { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); }
.proposal__changes li + li { margin-top: 2px; }
.proposal__applied { align-self: center; font-size: 12.5px; font-weight: 600; color: var(--good); }
.proposal__note { margin: 8px 0 0; font-size: 12px; color: var(--text-2); }
.proposal__error { margin: 8px 0 0; font-size: 12px; color: var(--bad); }
.proposal--superseded { opacity: 0.6; }
.proposal [aria-pressed="true"] { border-color: var(--accent); color: var(--accent-ink); }

/* History panel: slides over the chat column */
.studio-history { position: absolute; inset: 0; z-index: 5; background: var(--surface); padding: 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.studio-history__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.studio-history__head h2 { font-size: 15px; }
.studio-history__status:empty { display: none; }
.studio-history__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.studio-history__item { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.studio-history__text { min-width: 0; overflow-wrap: anywhere; font-size: 13px; }

@media (max-width: 1000px) {
  .studio, .studio--agency { height: auto; min-height: 0; grid-template-columns: minmax(0, 1fr); }
  .studio__chat { border-right: 0; border-bottom: 1px solid var(--border); min-width: 0; }
  .studio__frame-wrap { min-height: 70vh; }
  .studio__open { margin-left: 0; }
  /* One scrolling row of suggestions, so the conversation keeps its room. */
  .studio .chat__suggestions { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 10px; }
  .studio .chip { white-space: nowrap; flex-shrink: 0; }
}

/* ── Client requests ───────────────────────────────────────────────────── */
.section-title { font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.request-list { display: flex; flex-direction: column; gap: 12px; }
.request-card__quote { margin: 0; padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.request-card__label { font-size: 13px; }
.request-card__changes .row { justify-content: space-between; margin-bottom: 6px; }
.request-card__actions { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding-top: 4px; }
.request-card__actions > .api-form { flex: 1 1 260px; }
.request-card__actions .field { margin-bottom: 8px; }
.request-card__decline { flex: 1 1 260px; }
.request-card__decline > summary { list-style: none; width: fit-content; }
.request-card__decline > summary::-webkit-details-marker { display: none; }
.request-card__decline[open] > summary { margin-bottom: 8px; }
.request-cell { max-width: 360px; overflow-wrap: anywhere; }
.api-form__error { margin: 6px 0 0; font-size: 12.5px; color: var(--bad); }
.api-form[aria-busy="true"] { opacity: 0.7; }

/* ── AI observations ───────────────────────────────────────────────────── */
.insight-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.insight-filters, .insight-generate { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.insight-review { gap: 12px; }
.insight-card { background: var(--surface); border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-sm); padding: 12px 14px; }
.insight-card.insight--positive { border-left-color: #10b981; }
.insight-card.insight--warning { border-left-color: #f59e0b; }
.insight-card.insight--critical { border-left-color: #ef4444; }
.insight-card__meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.insight-card .insight__title { font-size: 14px; }
.insight-card__created { margin: 6px 0 0; }
.insight-card__actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; margin-top: 10px; }
.insight-card__actions > .api-form { display: inline-block; }
.insight-card details > summary { list-style: none; width: fit-content; }
.insight-card details > summary::-webkit-details-marker { display: none; }
.insight-card__apply { margin-top: 10px; }
.insight-card__panel, .insight-card__edit[open] > .api-form { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.insight-card__panel .diff-list { margin: 6px 0 10px; }
.insight-card__edit[open] { flex-basis: 100%; }
.insight-card__numbers { margin: 8px 0 0; border: 1px solid #fcd34d; background: var(--warn-bg); color: #92400e; border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12.5px; }
.insight-card__numbers p { margin: 0; }

/* ── Ask drawer (client portal) ────────────────────────────────────────── */
.ask { max-width: 100vw; }
.ask:not(.is-open) { visibility: hidden; transition: transform 0.2s ease, visibility 0s linear 0.2s; }
.ask.is-open { visibility: visible; }
.ask__title { font-size: 16px; }
.ask__head-actions { display: flex; gap: 4px; align-items: center; }
.ask__close { font-size: 16px; width: 32px; justify-content: center; padding: 0; }
.ask__body { min-height: 0; }
.ask__log .chat__msg--user { background: var(--brand); color: var(--brand-ink); }
.ask__intro { font-size: 13.5px; color: var(--text-2); }
.ask__intro p:last-child { margin-bottom: 0; }
.ask__intro--offline { border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--text); overflow-wrap: anywhere; }
.ask__hint { margin: 0; padding: 0 12px 12px; font-size: 11px; color: var(--text-3); }
.ask-sent { border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; }
.ask-sent__title { display: block; color: var(--accent-ink); }
.ask-sent__text { margin: 4px 0; }
.ask-sent p:last-child { margin-bottom: 0; }
.ask-requests { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; }
.ask-requests summary { cursor: pointer; font-weight: 500; }
.ask-requests ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ask-requests__item { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.ask-requests__text { flex: 1 1 200px; overflow-wrap: anywhere; }
.ask-requests__note { flex-basis: 100%; }
body.ask-is-open { overflow: hidden; }
.ask-fab { display: none; }
@media (max-width: 860px) {
  .ask-fab { display: inline-flex; align-items: center; position: fixed; right: 16px; bottom: 16px; z-index: 30; height: 44px; padding: 0 16px; border: 0; border-radius: 999px; background: var(--btn-bg); color: var(--btn-ink); font: inherit; font-weight: 600; box-shadow: var(--shadow-lg); cursor: pointer; }
  .ask { width: 100vw; }
  .chat__form textarea { font-size: 16px; } /* 16px stops iOS zooming into the field */
}
@media (prefers-reduced-motion: reduce) {
  .drawer, .ask:not(.is-open) { transition: none; }
  .chat__status::before, .studio__frame-wrap.is-loading::after { animation: none; }
}
@media print { .ask-fab { display: none !important; } }
