/* Company OS prototype v3 - shared/insight-layout.css
 * ONE layout for the ad insight, loaded by BOTH AdLauncher (al/index.html) and ImageLauncher (il/index.html).
 * LAYOUT ONLY: grid, order, spacing scale, type SIZES and line-heights (so text wraps the same), breakpoints, mount shells.
 * No colours, no font families, no radii, no shadows: those live in al/insight-skin.css and il/insight-skin.css.
 * A layout difference between the apps is a bug: tools/parity.js compares every [data-ins] box (+-4px).
 *
 * Spacing scale (px): 4 8 12 16 20 24.  Type scale: 11/14, 12/16, 13/20, 14/20, 20/28, 22/28, 30/36.
 * Breakpoints are CONTAINER queries on .ins-root (not viewport), so the sheet (760), split (640) and full page behave the same in both apps:
 *   < 520  : 1 column, KPI tiles 2 across, trend charts stacked
 *   >= 520 : KPI tiles 3 across, trend charts 3 across
 *   >= 680 : creative | fatigue and D7 | lineage side by side (7/5)
 *   >= 880 : KPI tiles all in one row
 */

/* ---------- reset inside the insight (hosts differ: Tailwind preflight vs IL base). :where() = zero specificity, so every .ins-* class below wins ---------- */
.ins-root, .ins-root *, .ins-root *::before, .ins-root *::after { box-sizing: border-box; }
:where(.ins-root) h1, :where(.ins-root) h2, :where(.ins-root) h3, :where(.ins-root) p, :where(.ins-root) dl, :where(.ins-root) dd, :where(.ins-root) dt, :where(.ins-root) ol, :where(.ins-root) ul, :where(.ins-root) li,
:where(.ins-root) figure { margin: 0; padding: 0; }
:where(.ins-root) ol, :where(.ins-root) ul { list-style: none; }
:where(.ins-root) h1, :where(.ins-root) h2, :where(.ins-root) h3 { font-size: inherit; line-height: inherit; font-weight: inherit; letter-spacing: 0; text-transform: none; }
:where(.ins-root) button { font: inherit; letter-spacing: 0; text-transform: none; margin: 0; background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-align: inherit; }
:where(.ins-root) a { color: inherit; text-decoration: none; }
:where(.ins-root) svg, :where(.ins-root) img { display: block; max-width: 100%; }
:where(.ins-root) table { border-collapse: collapse; }
.ins-root :focus-visible { outline-offset: 2px; }
.ins-vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- root: the container ---------- */
.ins-root {
  container-type: inline-size; container-name: ins;
  display: block; width: 100%; max-width: 960px; margin-inline: auto;
  font-size: 13px; line-height: 20px; font-weight: 400; letter-spacing: 0; text-align: left;
  font-variant-numeric: tabular-nums; font-feature-settings: normal; font-kerning: normal; -webkit-font-smoothing: antialiased;
  --ins-gap: 16px; --ins-pad: 16px;
}
.ins-flow { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--ins-gap); align-items: stretch; }
.ins-sec { grid-column: 1 / -1; min-width: 0; padding: var(--ins-pad); border: 1px solid transparent; display: flex; flex-direction: column; gap: 12px; }
.ins-creative { min-height: 640px; }  /* contract rev 1.1 section 5: same floor in AL and IL */
.ins-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; flex-wrap: wrap; }
.ins-h2 { font-size: 14px; line-height: 20px; font-weight: 600; }
.ins-meta { font-size: 12px; line-height: 16px; }
.ins-micro { font-size: 11px; line-height: 14px; }
.ins-mono { font-size: 12px; line-height: 16px; }
.ins-note { font-size: 12px; line-height: 16px; padding: 8px 12px; border: 1px solid transparent; }
.ins-note b { font-weight: 600; }

/* ---------- atoms: size only; colour/radius come from the skin ---------- */
.ins-chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; font-size: 11px; line-height: 14px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; max-width: 100%; }
.ins-chips { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.ins-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; font-size: 13px; line-height: 20px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.ins-btn--sm { height: 28px; padding: 0 10px; font-size: 12px; line-height: 16px; }
.ins-btn[disabled], .ins-btn[aria-disabled=true] { cursor: not-allowed; }
.ins-seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid transparent; }
.ins-seg button { height: 28px; padding: 0 12px; font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; border: 0; }
.ins-seg button[disabled] { cursor: not-allowed; }
.ins-skel-bar { display: block; height: 12px; }

/* ---------- 1. header ---------- */
.ins-header { gap: 12px; }
.ins-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ins-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ins-title { font-size: 20px; line-height: 28px; font-weight: 600; overflow-wrap: anywhere; }
.ins-ids { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 12px; line-height: 16px; }
.ins-ids > span { white-space: nowrap; }

/* ---------- 2. KPI row ---------- */
.ins-kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ins-kpi-hero { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ins-kpi { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid transparent; min-width: 0; }
.ins-kpi-label { font-size: 12px; line-height: 16px; font-weight: 600; min-height: 32px; }
.ins-kpi-value { font-size: 22px; line-height: 28px; font-weight: 600; }
.ins-kpi--hero .ins-kpi-value { font-size: 30px; line-height: 36px; }
.ins-kpi-delta { font-size: 12px; line-height: 16px; font-weight: 600; min-height: 16px; }
.ins-kpi-delta .ins-delta-ref { font-weight: 400; }
.ins-kpi-asof { font-size: 11px; line-height: 14px; min-height: 14px; }
.ins-kpis-foot { font-size: 11px; line-height: 14px; }

/* ---------- 3. trend ---------- */
.ins-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.ins-chart { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid transparent; min-width: 0; }
.ins-chart-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-height: 32px; }
.ins-chart-label { font-size: 12px; line-height: 16px; font-weight: 600; }
.ins-chart-now { font-size: 16px; line-height: 20px; font-weight: 600; white-space: nowrap; }
.ins-plot { position: relative; height: 72px; }
.ins-plot svg { width: 100%; height: 72px; overflow: visible; }
.ins-plot .ins-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.ins-plot .ins-area { stroke: none; }
.ins-plot .ins-d7line { stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.ins-d7tag { position: absolute; top: -2px; transform: translateX(-50%); font-size: 10px; line-height: 12px; font-weight: 700; padding: 0 4px; border: 1px solid transparent; }
.ins-chart-axis { display: flex; justify-content: space-between; font-size: 11px; line-height: 14px; }
.ins-trend-foot { font-size: 11px; line-height: 14px; }

/* ---------- 4. creative ---------- */
.ins-cr-grid { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px 16px; align-items: start; }
.ins-fig { width: 120px; aspect-ratio: 4 / 5; overflow: hidden; border: 1px solid transparent; }
.ins-fig img { width: 100%; height: 100%; object-fit: cover; }
.ins-cr-meta { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ins-kv { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 4px 8px; font-size: 12px; line-height: 16px; }
.ins-kv dt { font-weight: 600; }
.ins-kv dd { min-width: 0; overflow-wrap: anywhere; }
.ins-paras { display: flex; flex-direction: column; gap: 8px; }
.ins-para { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; align-items: start; }
.ins-para-tag { font-size: 11px; line-height: 14px; font-weight: 700; padding-top: 3px; }
.ins-para p { font-size: 13px; line-height: 20px; }

/* ---------- 5. fatigue ---------- */
.ins-fat { display: flex; flex-direction: column; }
.ins-fat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 8px 0; border-top: 1px solid transparent; }
.ins-fat-row:first-child { border-top-color: transparent; }
.ins-fat-name { font-size: 13px; line-height: 20px; font-weight: 600; }
.ins-fat-limit { font-size: 11px; line-height: 14px; grid-column: 1; }
.ins-fat-val { font-size: 16px; line-height: 20px; font-weight: 600; text-align: right; grid-column: 2; grid-row: 1; }
.ins-fat-state { grid-column: 2; grid-row: 2; justify-self: end; }

/* ---------- 6. D7 review ---------- */
.ins-d7-sum { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.ins-d7-rec { display: flex; flex-direction: column; gap: 12px; }
.ins-rationale { font-size: 13px; line-height: 20px; }
.ins-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.ins-field dt { font-size: 11px; line-height: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.ins-field dd { font-size: 13px; line-height: 20px; }
.ins-evid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px; border: 1px solid transparent; }
.ins-evid div { display: flex; flex-direction: column; gap: 0; }
.ins-evid dt { font-size: 11px; line-height: 14px; }
.ins-evid dd { font-size: 14px; line-height: 20px; font-weight: 600; }
.ins-d7-act { display: flex; flex-direction: column; gap: 8px; }
.ins-d7-act-label { font-size: 12px; line-height: 16px; font-weight: 600; }

/* ---------- 7. lineage ---------- */
.ins-steps { display: flex; flex-direction: column; gap: 0; }
.ins-step { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px; align-items: center; min-height: 32px; font-size: 13px; line-height: 20px; }
.ins-step-mark { width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; line-height: 14px; font-weight: 700; border: 1px solid transparent; }
.ins-step-state { font-size: 11px; line-height: 14px; font-weight: 600; }
.ins-receipt { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 4px 8px; font-size: 12px; line-height: 16px; padding: 12px; border: 1px solid transparent; }
.ins-receipt dt { font-weight: 600; }
.ins-receipt dd { min-width: 0; overflow-wrap: anywhere; }

/* ---------- states (empty / error) ---------- */
.ins-state { align-items: center; text-align: center; gap: 12px; padding: 40px 24px; min-height: 280px; justify-content: center; }
.ins-state-ic { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; line-height: 24px; font-weight: 700; border: 1px solid transparent; }
.ins-state p { max-width: 44ch; font-size: 13px; line-height: 20px; }
.ins-state .ins-actions { justify-content: center; }

/* ---------- loading: SAME dom, values masked (0 layout shift) ---------- */
.ins-loading [data-v], .ins-loading [data-v] * { color: transparent !important; border-color: transparent !important; text-shadow: none !important; user-select: none; }
.ins-loading [data-v] { border-radius: 4px; }
.ins-loading .ins-plot svg { visibility: hidden; }
.ins-loading .ins-d7tag { visibility: hidden; }

/* ---------- container breakpoints ---------- */
@container ins (min-width: 520px) {
  .ins-kpi-grid { grid-template-columns: repeat(var(--ins-c, 3), minmax(0, 1fr)); }
  .ins-charts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ins-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ins-evid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container ins (min-width: 680px) {
  .ins-flow { --ins-pad: 20px; }
  .ins-creative { grid-column: span 7; }
  .ins-fatigue { grid-column: span 5; }
  .ins-d7 { grid-column: span 7; }
  .ins-lineage { grid-column: span 5; }
  .ins-fields { grid-template-columns: minmax(0, 1fr); }
  .ins-evid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container ins (min-width: 880px) {
  .ins-kpi-grid { grid-template-columns: repeat(var(--ins-n, 3), minmax(0, 1fr)); }
  .ins-fields { grid-template-columns: minmax(0, 1fr); }
  .ins-evid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container ins (max-width: 359px) {
  .ins-kpi-hero { grid-template-columns: minmax(0, 1fr); }
}

/* =========================================================================================================
 * MOUNT SHELLS (shared): where the insight sits in each host. Variants of V1 "container".
 *   A  full page      the pane replaces the list area
 *   B  side sheet     a 760px sheet over the list, with a scrim
 *   C  split view     list on the left, a 640px insight pane on the right
 * Pane padding is equal in both apps, so the root gets the same width in both. Below 760px viewport B and C
 * fall back to a full-width pane (the list is hidden), like A.
 * ======================================================================================================= */
.ins-stage { position: relative; min-width: 0; }
.ins-stage > .ins-list { min-width: 0; }
.ins-pane { display: none; min-width: 0; padding: 20px 24px calc(var(--pv-bar-h, 0px) + 24px); }
.ins-stage[data-open="1"] > .ins-pane { display: block; }
.ins-stage[data-open="1"][data-variant="A"] > .ins-list { display: none; }
.ins-scrim { display: none; }

/* B: side sheet */
.ins-stage[data-open="1"][data-variant="B"] > .ins-pane {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 80; width: 760px; max-width: 100vw; overflow: auto; padding: 20px 20px calc(var(--pv-bar-h, 0px) + 24px);
}
.ins-stage[data-open="1"][data-variant="B"] > .ins-scrim { display: block; position: fixed; inset: 0; z-index: 79; }

/* C: split view */
.ins-stage[data-open="1"][data-variant="C"] { display: flex; align-items: flex-start; }
.ins-stage[data-open="1"][data-variant="C"] > .ins-list { flex: 1 1 0; min-width: 0; overflow-x: auto; overflow-y: hidden; }
.ins-stage[data-open="1"][data-variant="C"] > .ins-pane {
  flex: 0 0 640px; width: 640px; padding: 20px 20px calc(var(--pv-bar-h, 0px) + 24px);
  position: sticky; top: var(--ins-top, 0px); height: calc(100vh - var(--ins-top, 0px)); overflow: auto;
}

@media (max-width: 759px) {
  /* --ins-pane-x-s: per-host gutter so the mount's inner width is equal in both hosts (IL's frame adds margin + border; AL compensates) */
  .ins-pane { padding: 12px var(--ins-pane-x-s, 12px) calc(var(--pv-bar-h, 0px) + 24px); }
  .ins-stage[data-open="1"][data-variant="B"] > .ins-pane { width: 100vw; padding: 12px 12px calc(var(--pv-bar-h, 0px) + 24px); }
  .ins-stage[data-open="1"][data-variant="B"] > .ins-scrim { display: none; }
  .ins-stage[data-open="1"][data-variant="B"] > .ins-list { display: none; }
  .ins-stage[data-open="1"][data-variant="C"] { display: block; }
  .ins-stage[data-open="1"][data-variant="C"] > .ins-list { display: none; }
  .ins-stage[data-open="1"][data-variant="C"] > .ins-pane { position: static; width: auto; height: auto; overflow: visible; padding: 12px var(--ins-pane-x-s, 12px) calc(var(--pv-bar-h, 0px) + 24px); }
}

/* QA B3 (01/11): long chip text must wrap inside the creative meta column, never widen the page */
.ins-cr-grid > *, .ins-kv dd { min-width: 0; }
.ins-kv .ins-chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
