/* =========================================================
   AUDIENCE Q&A
   A rail of conversations that can be put away, and one answer sheet
   divided by hairlines into its own bands: the run the agent worked
   through, a summary, KPIs each with their own evidence, a chart grid,
   the query that ran, the rows it read, and the footnotes.
   Everything is drawn from the house tokens; the chart ramp is derived
   below from the one accent plus the house navy/slate.
========================================================= */

#page-audience-qa {
    --c1: var(--primary);
    --c2: color-mix(in oklch, var(--primary) 70%, var(--surface));
    --c3: color-mix(in oklch, var(--primary) 40%, var(--surface));
    --c4: var(--purple);
    --c5: var(--text-3);
}

/* The page fills the window: the rail and thread reach the bottom instead of
   leaving a dead strip under the panels. */
#page-audience-qa.active {
    display: flex;
    flex-direction: column;
    gap: 22px;
    min-height: calc(100dvh - var(--topbar));
}

#page-audience-qa .page-header { margin-bottom: 0; }

/* ---------- the lab: rail | thread ---------- */

.aqa-lab {
    display: grid;
    grid-template-columns: 288px minmax(0, 1fr);
    gap: 16px;
    flex: 1 1 auto;
    min-height: 560px;
}

.aqa-history { grid-column: 1; }
.aqa-main { grid-column: 2; }

/* Hiding the rail is a class, never [hidden]: .chat-history sets display:flex,
   which beats the attribute. The grid collapses and the thread takes the row. */
.aqa-lab.is-rail-hidden { grid-template-columns: minmax(0, 1fr); }
.aqa-lab.is-rail-hidden .chat-history { display: none; }
.aqa-lab.is-rail-hidden .aqa-main { grid-column: 1; }

.aqa-lab ::selection { background: var(--primary-soft); color: var(--text); }

/* The dotted ground is for the empty state; a full thread reads on plain white. */
.aqa-lab .chat-thread:not(.is-empty) { background: var(--surface); }
.aqa-lab .chat-thread { scrollbar-width: thin; }
.aqa-lab .chat-thread::-webkit-scrollbar { width: 10px; }
.aqa-lab .chat-thread::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid var(--surface);
    border-radius: 999px;
}

/* Rail head: the count and its own close button, then New question above the list. */
.chat-side-count { margin-left: auto; font-family: var(--lab-mono); font-size: 10px; color: var(--text-3); }
.chat-history-new { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-history-new .btn { width: 100%; justify-content: flex-start; }

/* ---------- header status ---------- */

.aqa-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 260px;
    padding: 7px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font: inherit;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.aqa-status::before {
    content: "";
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    box-shadow: 0 0 0 3px var(--surface-soft);
}

.aqa-status > span {
    /* The label is its own flex child: text-overflow on the flex container
       itself never ellipsizes, so the pill hard-clipped mid-word on mobile. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aqa-status:hover { border-color: var(--border-strong); color: var(--text); }
/* The dot and the soft ground carry the status colour; the text stays at body
   contrast (success-on-success-soft is only 4.1:1). */
.aqa-status.is-connected { background: var(--success-soft); border-color: transparent; color: var(--text); }
.aqa-status.is-connected::before { background: var(--success); box-shadow: 0 0 0 3px var(--surface); }
.aqa-status.is-off { background: var(--warning-soft); border-color: transparent; color: var(--text); }
.aqa-status.is-off::before { background: var(--warning); box-shadow: 0 0 0 3px var(--surface); }

/* ---------- conversation head ---------- */

.aqa-head-copy { flex: 1; min-width: 0; }
.aqa-head-copy .chat-title { cursor: text; }
.aqa-head-copy .chat-title:hover { color: var(--primary-dark); }

.aqa-title-input {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    outline: none;
}

/* Per-conversation delete, revealed on hover or keyboard focus. */
.chat-item-wrap { position: relative; }
.chat-item-delete {
    position: absolute;
    top: 50%;
    right: 5px;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 7px;
    background: var(--surface);
    color: var(--text-3);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition), color var(--transition);
}
.chat-item-delete svg { width: 13px; height: 13px; }
.chat-item-wrap:hover .chat-item-delete,
.chat-item-wrap:focus-within .chat-item-delete { opacity: 1; pointer-events: auto; }
.chat-item-delete:hover { color: var(--danger); }
@media (hover: none) { .chat-item-delete { opacity: 1; pointer-events: auto; } }

/* ---------- empty and no-database states: the house .empty block, tuned here ---------- */

#aqaThread .empty { margin: auto; max-width: 480px; padding: 30px 18px; }
#aqaThread .empty-icon {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--primary-soft-2);
    border: 1px solid var(--border);
    color: var(--primary);
}
#aqaThread .empty-icon svg { width: 19px; height: 19px; }
#aqaThread .empty h3 { margin-top: 13px; font-size: 15px; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
#aqaThread .empty p { margin: 6px auto 0; max-width: 42ch; font-size: 12.5px; line-height: 1.65; color: var(--text-2); }
#aqaThread .empty .btn { margin-top: 16px; }

.aqa-starters { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; text-align: left; }

.aqa-starter {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-2);
    text-align: left;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.aqa-starter svg { flex: 0 0 14px; width: 14px; height: 14px; color: var(--primary); }
.aqa-starter:hover { border-color: var(--primary); background: var(--primary-soft-2); color: var(--primary-dark); }

.aqa-guarantee {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-3);
}

.aqa-guarantee svg { width: 12px; height: 12px; }

/* ---------- run log: the agent's own trace ---------- */

.aqa-run { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-soft); overflow: hidden; }
.aqa-run-head { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 11px; text-align: left; }
button.aqa-run-head:hover { background: var(--surface-hover); }
.aqa-run-head.is-open, .aqa-run-head[aria-expanded="true"] { border-bottom: 1px solid var(--border); }
.aqa-run-mark { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.aqa-run.is-live .aqa-run-mark { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); animation: aqa-run-pulse 1.4s ease-in-out infinite; }
@keyframes aqa-run-pulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--primary-soft); }
    50% { box-shadow: 0 0 0 6px var(--primary-soft); }
}
.aqa-run-title { font-size: 12px; font-weight: 800; color: var(--text); }
.aqa-run-live-label, .aqa-run-head #aqaStageLabel { font-size: 12px; font-weight: 800; color: var(--primary-dark); }
.aqa-run-elapsed, .aqa-run-head #aqaElapsed {
    margin-left: auto;
    font-family: var(--lab-mono);
    font-size: 10px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}
.aqa-run-toggle { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; font-size: 10.5px; font-weight: 700; color: var(--text-2); }
.aqa-run-toggle svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2.2; transition: transform var(--transition); }
.aqa-run-head.is-open .aqa-run-toggle svg, .aqa-run-head[aria-expanded="true"] .aqa-run-toggle svg { transform: rotate(180deg); }

.aqa-run-steps { list-style: none; padding: 9px 12px 11px; display: flex; flex-direction: column; gap: 0; }
.aqa-run-steps[hidden] { display: none; }
.aqa-run.is-live .aqa-run-steps { padding-top: 10px; }
.aqa-run-step { position: relative; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 5px 0; }
.aqa-run-step::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 1px; background: var(--border-strong); }
.aqa-run-step:first-child::before { top: 13px; }
.aqa-run-step:last-child::before { bottom: calc(100% - 13px); }
.aqa-run-step i { position: relative; z-index: 1; width: 15px; height: 15px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--border-strong); display: grid; place-items: center; }
.aqa-run-step i::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.aqa-run-step.is-done i { border-color: var(--primary); background: var(--primary); }
.aqa-run-step.is-done i::after { background: var(--surface); }
.aqa-run-step.is-now i { border-color: var(--primary); border-width: 2px; }
.aqa-run-step.is-now i::after { background: var(--primary); animation: aqa-run-pulse 1.4s ease-in-out infinite; }
.aqa-run-label { font-size: 12px; font-weight: 600; color: var(--text-3); }
.aqa-run-step.is-done .aqa-run-label { color: var(--text-2); }
.aqa-run-step.is-now .aqa-run-label { color: var(--text); font-weight: 800; }
.aqa-run-note { display: block; margin-top: 2px; font-family: var(--lab-mono); font-size: 9.5px; color: var(--text-3); }
.aqa-run-step.is-now .aqa-run-note { color: var(--primary-dark); }
.aqa-run-took { font-family: var(--lab-mono); font-size: 9.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.aqa-run-step:not(.is-done):not(.is-now) { opacity: .55; }

.aqa-check-again { margin-top: 10px; padding: 0 12px 11px; }
.aqa-check-again .btn { padding: 6px 11px; font-size: 11px; }

/* ---------- answer sheet: one sheet, hairline bands ---------- */

.aqa-answer {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    animation: aqa-rise 240ms cubic-bezier(.22, 1, .36, 1) both;
}

@keyframes aqa-rise {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: none; }
}

.aqa-answer > * + * { border-top: 1px solid var(--border); }

.answer-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 11px 16px; }
.answer-stamp { font-family: var(--lab-mono); font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.answer-head-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.answer-head .btn { padding: 6px 11px; font-size: 11px; min-height: 30px; }

.summary { display: flex; gap: 10px; padding: 14px 16px; }
.summary p { font-size: 13.5px; line-height: 1.65; color: var(--text); max-width: 74ch; }

.band { padding: 14px 16px 16px; }
.band-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; margin-bottom: 12px; }
.band-title { font-size: 12.5px; font-weight: 800; }
.band-sub { font-size: 11px; color: var(--text-3); }
.band-head .btn { margin-left: auto; padding: 5px 10px; font-size: 11px; min-height: 28px; }

/* ---------- KPI cells: figure plus its own evidence ---------- */

.aqa-answer .kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: 0;
    margin: 0;
}

.aqa-answer .kpi {
    padding: 14px 16px;
    border: 0;
    border-left: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.aqa-answer .kpi:first-child { border-left: 0; }
.aqa-answer .kpi-label { font-family: var(--lab-mono); font-size: 9.5px; font-weight: 500; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.aqa-answer .kpi-value { margin-top: 0; font-size: 24px; line-height: 1; font-weight: 800; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.aqa-answer .kpi-context { font-size: 10.5px; line-height: 1.45; color: var(--text-3); max-width: 24ch; }

.kpi-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 26px; }
.kpi-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-delta { display: inline-flex; align-items: center; gap: 4px; margin-top: 1px; font-family: var(--lab-mono); font-size: 9.5px; font-weight: 500; }
.kpi-delta.is-up { color: var(--success); }
.kpi-delta.is-down { color: var(--danger); }
.kpi-delta svg { width: 10px; height: 10px; stroke: currentColor; fill: none; stroke-width: 2.4; }

/* The mounted trend line sits inside its own band; the SVG carries the padding. */
.aqa-answer .chart-area { min-height: 200px; padding: 0; }

/* ---------- chart grid: bands pair up, hairline between each ----------
   Flex, not grid: a lone compact band grows to the full row, so a single
   chart never leaves a hole beside it. */
.aqa-chart-grid { display: flex; flex-wrap: wrap; gap: 1px; background: var(--border); }
.aqa-chart-grid > .band { flex: 1 1 calc(50% - 1px); background: var(--surface); min-width: 0; }
.aqa-chart-grid > .band.is-wide { flex-basis: 100%; }
.aqa-chart-grid .bar-row { grid-template-columns: 96px minmax(0, 1fr) 54px 46px; gap: 8px; }
/* Half-width is too tight for a ring beside its legend — stack instead. */
.aqa-chart-grid .aqa-donut { flex-direction: column; align-items: stretch; gap: 14px; }
.aqa-chart-grid .aqa-donut-ring { align-self: center; }
.aqa-chart-grid .aqa-donut-legend { gap: 1px; }

/* ---------- sparklines (KPI evidence) ---------- */

.spark { flex: 0 0 auto; }
.spark-area { fill: var(--c1); fill-opacity: .12; }
.spark-line { fill: none; stroke: var(--c1); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.spark-dot { fill: var(--surface); stroke: var(--c1); stroke-width: 2; }
.spark-bar { fill: var(--c3); }
.spark-bar.is-top { fill: var(--c1); }

/* ---------- ranked bars ---------- */

.bars { display: flex; flex-direction: column; gap: 3px; }
.bar-row { display: grid; grid-template-columns: 132px minmax(0, 1fr) 62px 52px; align-items: center; gap: 12px; padding: 5px 7px; border-radius: 8px; }
.bar-row:hover { background: var(--surface-soft); }
.bar-name { font-size: 12px; font-weight: 700; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row.is-top .bar-name { color: var(--text); font-weight: 800; }
.bar-track { position: relative; height: 16px; border-radius: 4px; background: var(--surface-soft); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; background: var(--c3); }
.bar-row.is-top .bar-fill { background: var(--c1); }
.bar-grid { position: absolute; inset: 0; pointer-events: none; background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%); }
.bar-value { text-align: right; font-family: var(--lab-mono); font-size: 11px; font-weight: 500; color: var(--text); }
.bar-share { text-align: right; font-family: var(--lab-mono); font-size: 11px; color: var(--text-3); }
.bars-note { margin-top: 9px; font-size: 10.5px; color: var(--text-3); }

/* ---------- columns, and the columns half of a combo ---------- */

.cols { position: relative; padding-top: 12px; }
.cols-plot { position: relative; height: 162px; margin-left: 46px; }
.cols-yaxis { position: absolute; left: -46px; top: 0; bottom: 0; width: 42px; }
.cols-yaxis span { position: absolute; right: 0; transform: translateY(-50%); font-family: var(--lab-mono); font-size: 9px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.cols-grid { position: absolute; inset: 0; }
.cols-grid i { position: absolute; left: 0; right: 0; height: 1px; background: var(--border); }
.cols-grid i.is-base { background: var(--border-strong); }
.cols-track { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.col { position: relative; flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; border-radius: 6px 6px 0 0; transition: background var(--transition); }
.col:hover { background: var(--surface-soft); }
.col-fill { width: clamp(14px, 52%, 44px); height: var(--h); border-radius: 5px 5px 0 0; background: linear-gradient(180deg, var(--c1) 0%, var(--c2) 100%); transition: opacity var(--transition); }
.col-value { position: absolute; left: 50%; bottom: calc(var(--h) + 5px); transform: translateX(-50%); font-family: var(--lab-mono); font-size: 9.5px; font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; transition: opacity var(--transition); }
/* Point at one column and the others recede — no script needed. */
.cols-track:hover .col:not(:hover) .col-fill,
.cols-track:hover .col:not(:hover) .col-value { opacity: .3; }
.col-names { display: flex; margin: 9px 0 0 46px; }
.col-names span { flex: 1 1 0; min-width: 0; padding: 0 3px; text-align: center; font-size: 10px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-line { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.combo-dot { position: absolute; width: 9px; height: 9px; margin: 0 0 -4.5px -4.5px; border-radius: 50%; background: var(--c4); box-shadow: 0 0 0 2px var(--surface); }
.combo-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 11px; }
.combo-legend span { display: inline-flex; align-items: center; gap: 6px; font-family: var(--lab-mono); font-size: 9.5px; color: var(--text-2); }
.combo-legend i { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- heatmap: the two margins audit each other ---------- */

.heat { display: grid; grid-template-columns: 112px repeat(var(--heat-cols), minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.heat-wrap { overflow-x: auto; }
.heat-wrap .heat { min-width: 420px; }
.heat-cell { padding: 7px 4px; text-align: center; font-family: var(--lab-mono); font-size: 10px; font-variant-numeric: tabular-nums; border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.heat-cell.row-first { border-left: 0; }
.heat-head { border-top: 0; padding: 8px 4px; font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.heat-name { text-align: left; padding-left: 10px; font-family: inherit; font-size: 11.5px; font-weight: 700; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heat-total { background: var(--surface-soft); color: var(--text); font-weight: 500; }
.heat-foot { background: var(--surface-soft); text-align: left; padding-left: 10px; font-family: inherit; font-size: 11px; font-weight: 800; color: var(--text-2); }
.heat-scale { display: flex; align-items: center; justify-content: flex-end; gap: 7px; margin-top: 10px; font-family: var(--lab-mono); font-size: 9.5px; color: var(--text-3); }
.heat-scale i { display: block; width: 20px; height: 10px; border-radius: 2px; }

/* ---------- funnel ---------- */

.funnel { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.fn { display: grid; grid-template-columns: 170px minmax(0, 1fr) 74px 116px; align-items: center; gap: 12px; }
.fn-name { font-size: 12px; font-weight: 700; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fn-bar { position: relative; height: 26px; display: flex; justify-content: center; }
.fn-shape { height: 100%; width: var(--w); border-radius: 4px; background: linear-gradient(90deg, var(--c1) 0%, var(--c2) 100%); clip-path: polygon(0 0, 100% 0, calc(100% - 11px) 100%, 11px 100%); transition: opacity var(--transition); }
.fn:hover .fn-shape { opacity: .84; }
.fn-value { text-align: right; font-family: var(--lab-mono); font-size: 12px; font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.fn-rate { display: flex; flex-direction: column; gap: 1px; text-align: right; }
.fn-rate b { font-family: var(--lab-mono); font-size: 11px; font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.fn-rate em { font-style: normal; font-size: 9.5px; color: var(--text-3); }

/* ---------- donut ---------- */

.aqa-donut { display: flex; align-items: center; gap: 22px; }
.aqa-donut-ring { flex: 0 0 auto; }
.aqa-donut-track { fill: none; stroke: var(--surface-soft); }
.aqa-donut-seg { fill: none; transition: opacity var(--transition); }
.aqa-donut-center-value { fill: var(--text); font-size: 19px; font-weight: 800; }
.aqa-donut-center-label { fill: var(--text-3); font-family: var(--lab-mono); font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase; }
.aqa-donut.is-focused .aqa-donut-seg { opacity: .3; }
.aqa-donut.is-focused .aqa-donut-seg.is-hot { opacity: 1; stroke-width: 19; }
.aqa-donut-legend { flex: 1; min-width: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.aqa-donut-row { display: grid; grid-template-columns: 9px minmax(0, 1fr) auto auto; align-items: center; gap: 9px; padding: 5px 7px; border-radius: 8px; cursor: default; }
.aqa-donut-row:hover, .aqa-donut-row.is-hot { background: var(--surface-soft); }
.aqa-donut-dot { width: 9px; height: 9px; border-radius: 3px; }
.aqa-donut-name { font-size: 12px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aqa-donut-count { font-family: var(--lab-mono); font-size: 11px; color: var(--text-2); }
.aqa-donut-share { min-width: 46px; text-align: right; font-family: var(--lab-mono); font-size: 11px; font-weight: 500; color: var(--text); }
.aqa-donut-bar { grid-column: 2 / -1; height: 3px; border-radius: 2px; background: var(--surface-hover); overflow: hidden; }
.aqa-donut-bar i { display: block; height: 100%; border-radius: 2px; }

/* ---------- SQL provenance ---------- */

.sql > summary { display: flex; align-items: center; gap: 9px; padding: 12px 16px; cursor: pointer; list-style: none; }
.sql > summary::-webkit-details-marker { display: none; }
.sql > summary:hover { background: var(--surface-soft); }
.sql > summary svg { width: 13px; height: 13px; stroke: var(--text-3); fill: none; stroke-width: 2.2; transition: transform var(--transition); }
.sql[open] > summary svg { transform: rotate(180deg); }
.sql-title { font-size: 12.5px; font-weight: 800; }
.sql-summary-meta { margin-left: auto; font-family: var(--lab-mono); font-size: 9.5px; color: var(--text-3); }
.sql-body { padding: 0 16px 15px; }
.sql-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.sql-code {
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    overflow-x: auto;
    font-family: var(--lab-mono);
    font-size: 11.5px;
    line-height: 1.75;
    color: var(--text-2);
}
.sql-code .sql-k { color: var(--primary-dark); font-weight: 500; }
.sql-code .sql-f { color: var(--c4); }
.sql-code .sql-s { color: var(--success); }
.sql-code .sql-n { color: var(--text); }
.sql-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-family: var(--lab-mono); font-size: 9.5px; color: var(--text-2); }
.chip svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; }
.chip-ok { border-color: transparent; background: var(--success-soft); color: var(--text-2); }
.chip-ok svg { stroke: var(--success); }

/* ---------- rows table: a band of the sheet, never a card of its own ---------- */

.aqa-answer table { min-width: 0; }
.aqa-answer thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-soft); border-bottom: 1px solid var(--border-strong); }
.aqa-answer tbody tr { cursor: default; }
.aqa-answer tbody tr:hover { background: var(--surface-soft); }
.aqa-answer th[data-numeric] { text-align: right; }
.aqa-answer th[data-numeric] .aqa-sort { justify-content: flex-end; }
.aqa-answer td { font-size: 11.5px; color: var(--text-2); font-variant-numeric: tabular-nums; max-width: 280px; overflow-wrap: anywhere; }
.aqa-answer td[data-numeric] { text-align: right; }
.aqa-answer td b { color: var(--text); }

.aqa-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: inherit;
    cursor: pointer;
}

.aqa-sort svg { width: 10px; height: 10px; }
.aqa-sort:hover, .aqa-sort.is-sorted { color: var(--primary-dark); }

.aqa-pager { display: flex; align-items: center; gap: 9px; margin-top: 11px; }
.aqa-pager-note { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.aqa-pager .btn { padding: 5px 10px; font-size: 11.5px; }
.aqa-pager .btn[disabled] { opacity: .45; pointer-events: none; }

.aqa-table-loading { padding: 12px 0 2px; font-size: 11.5px; color: var(--text-3); }

/* ---------- footnotes ---------- */

.aqa-notes { display: flex; flex-direction: column; gap: 6px; padding: 12px 16px; }
.aqa-note { display: flex; gap: 7px; font-size: 10.5px; line-height: 1.55; color: var(--text-3); }
.aqa-note svg { flex: 0 0 12px; width: 12px; height: 12px; margin-top: 1.5px; }
.aqa-note-warn { color: var(--warning); }

/* ---------- clarification and failure ---------- */

.aqa-clarify {
    max-width: 620px;
    padding: 14px 16px;
    border: 1px solid var(--primary-soft);
    border-radius: var(--radius-lg);
    background: var(--primary-soft-2);
}

.aqa-clarify p { font-size: 13px; line-height: 1.65; color: var(--text); }
.aqa-clarify-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.aqa-clarify-options .btn { min-height: 32px; font-size: 11.5px; }

.aqa-failure {
    max-width: 620px;
    padding: 14px 16px;
    border: 1px solid var(--danger-soft);
    border-radius: var(--radius-lg);
    background: var(--danger-soft);
}

.aqa-failure p { font-size: 12.5px; line-height: 1.65; color: var(--danger); }
.aqa-failure code { font-family: var(--lab-mono); font-size: 11px; }
.aqa-failure-actions { display: flex; gap: 7px; margin-top: 12px; }
.aqa-failure-actions .btn { background: var(--surface); color: var(--danger); border-color: transparent; }

/* ---------- composer ---------- */

.aqa-main .chat-bar { justify-content: flex-start; }
.aqa-main .chat-bar .btn { margin-left: auto; }
.aqa-main .chat-hint { margin-top: 0; }

.chat-guard { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; background: var(--success-soft); font-size: 10.5px; font-weight: 700; color: var(--text-2); }
.chat-guard svg { width: 11px; height: 11px; stroke: var(--success); fill: none; stroke-width: 2; }

.aqa-main #aqaPrompt {
    width: 100%;
    min-height: 48px;
    max-height: 180px;
    resize: none;
    border: 0;
    padding: 11px 13px 4px;
    font: inherit;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text);
    background: transparent;
    outline: none;
    box-shadow: none;
    caret-color: var(--primary);
}

.aqa-main #aqaPrompt::placeholder { color: var(--text-3); }
.aqa-main #aqaPrompt:disabled { color: var(--text-3); }

/* ---------- responsive ---------- */

@media (max-width: 1280px) {
    .bar-row { grid-template-columns: 112px minmax(0, 1fr) 56px 48px; gap: 9px; }
    .aqa-donut { gap: 16px; }
}

@media (max-width: 1100px) {
    .aqa-lab {
        flex: none;
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        min-height: 0;
    }
    .aqa-history, .aqa-main { grid-column: 1; }
    .aqa-history { max-height: 268px; }
    .aqa-main { min-height: 560px; }
}

@media (max-width: 760px) {
    .aqa-chart-grid > .band { flex-basis: 100%; }
    /* The funnel keeps its conversion rates — they move under the bar. */
    .fn { grid-template-columns: minmax(0, 1fr) 62px 68px; gap: 8px; }
    .fn-name { grid-column: 1 / -1; }
    .fn-rate em { font-size: 9px; }
    .cols-plot, .col-names { margin-left: 40px; }
    .cols-yaxis { left: -40px; width: 36px; }
}

@media (max-width: 640px) {
    .aqa-lab { gap: 12px; }
    .aqa-status { max-width: 180px; }
    .answer-head,
    .summary,
    .band,
    .aqa-notes { padding-left: 12px; padding-right: 12px; }
    .aqa-answer .kpi { padding-left: 12px; padding-right: 12px; }
    .aqa-answer .kpi-value { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
    .aqa-answer { animation: none; }
    .aqa-run.is-live .aqa-run-mark,
    .aqa-run-step.is-now i::after { animation: none; }
}

/* ---------- audiences: panel toggle, detail card, save popup ---------- */

.aqa-history .chat-history-head { padding: 0 8px 0 4px; }
.aqa-aside-tabs { flex: 1; min-width: 0; margin: 0; border-bottom: 0; }
.aqa-aside-tabs .tab { padding: 12px 9px 10px; white-space: nowrap; }
.aqa-aside-tabs .chat-side-count { margin-left: 4px; }
.aqa-seg-covers { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aqa-seg-error { color: var(--danger); }
.aqa-main.is-segment .chat-composer { display: none; }
.aqa-seg-send { margin-top: 10px; }
.aqa-people-block { margin-top: 12px; }
.aqa-people-block:empty { display: none; }

/* the audience's people table, shared with the boost wizard */
.aqa-people-scroll { overflow-x: auto; max-width: 100%; }
.aqa-people { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 12.5px; }
.aqa-people caption { text-align: left; padding-bottom: 6px; color: var(--text-3); font-weight: 600; }
.aqa-people th, .aqa-people td { padding: 5px 10px 5px 0; font-size: 12.5px; background: none; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.aqa-people th { text-transform: none; letter-spacing: 0; color: var(--text-3); font-weight: 700; }
.aqa-people-pager { display: flex; gap: 8px; margin-top: 10px; }
.aqa-people-empty { margin: 0; font-size: 12.5px; color: var(--text-3); }

/* the brief: shared by the popup and the detail card */
.aqa-pv { display: flex; flex-direction: column; gap: 12px; }
.aqa-pv-count { margin: 0; font-size: 13px; color: var(--text-2); }
.aqa-pv-count b { font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: -.02em; }
.aqa-pv-empty { margin: 0; font-size: 12px; color: var(--text-2); }
.aqa-pv-table { width: 100%; font-size: 12px; }
.aqa-pv-line { display: flex; gap: 10px; align-items: baseline; margin: 0; font-size: 12px; color: var(--text-2); }
.aqa-pv-line b { color: var(--text); font-size: 13px; }
.aqa-pv .bar-row { grid-template-columns: 72px minmax(0, 1fr) 48px 44px; }
.aqa-pv.is-compact .aqa-pv-count b { font-size: 20px; }

.aqa-save-modal { width: min(520px, 100%); outline: none; }
.aqa-save-from { margin: 0 0 12px; font-size: 11px; color: var(--text-3); overflow-wrap: anywhere; }
.aqa-save-working { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-2); }
.aqa-save-working .aqa-run-mark { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); animation: aqa-run-pulse 1.4s ease-in-out infinite; }
.aqa-save-error { margin: 0; font-size: 12.5px; color: var(--danger); }
.aqa-save-note { margin: 10px 0 0; font-size: 11.5px; color: var(--text-2); }
.aqa-save-again { margin-top: 4px; padding-left: 0; }
.aqa-save-label { display: block; margin: 14px 0 6px; font-size: 11.5px; font-weight: 700; color: var(--text); }
.aqa-save-modal .lab-input { width: 100%; }
.aqa-save-hint { margin: 8px 0 0; font-size: 11px; color: var(--text-3); }

@media (prefers-reduced-motion: reduce) {
    .aqa-save-working .aqa-run-mark { animation: none; }
}
.aqa-seg-send:empty { display: none; }

/* send dialog: stacks above the boost modal (z 250) */
.aqa-send-overlay { z-index: 260; }
.aqa-save-warn { color: var(--warning); font-weight: 700; }
.aqa-send-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.aqa-send-grid .lab-select, .aqa-save-modal textarea.lab-input { width: 100%; }
.aqa-save-modal textarea.lab-input { resize: vertical; }
@media (max-width: 520px) { .aqa-send-grid { grid-template-columns: 1fr; } }
