/* =========================================================
   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, Pali's briefing, KPIs each with their own evidence, a chart
   grid, 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-hub {
    --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);
    --s1: var(--primary);
    --s2: #c4510a;
    --s3: #00806a;
    --s4: #8f4bb8;
}

/* is-open guard: this hardcoded display beats .hub-view[hidden] (audience-hub.css),
   so without it qa stayed rendered under the other hub views (only panel.hidden hides them). */
#page-audience-hub.active #hubViewQa.is-open {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: calc(100vh - var(--topbar) - var(--hub-pad-t) - var(--hub-quick-h));
    height: calc(100dvh - var(--topbar) - var(--hub-pad-t) - var(--hub-quick-h));
    padding-bottom: 20px;
}

/* ---------- the lab: one surface, rail | thread ---------- */

#hubViewQa .aqa-lab {
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    flex: 1 1 auto;
    min-height: 420px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* Only the thread and the rail list scroll; the panels stay put. */
#page-audience-hub .aqa-history,
#page-audience-hub .aqa-main { min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
.aqa-lab .chat-thread { min-height: 0; overscroll-behavior: contain; }
.aqa-lab .chat-thread > * { flex-shrink: 0; min-width: 0; max-width: 100%; }
.aqa-lab .msg-agent-body { min-width: 0; }
.chat-head { flex: 0 0 auto; }

.aqa-history { grid-column: 1; }
#page-audience-hub .aqa-history { border-right: 1px solid var(--border); }
.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. */
#hubViewQa .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); }

#page-audience-hub .chat-thread { background: var(--bg, var(--surface)); padding: 24px 20px 12px; gap: 22px; scrollbar-width: thin; }
#page-audience-hub .chat-thread > * { width: 100%; max-width: 860px; margin-left: auto; margin-right: auto; }
.aqa-lab .chat-thread::-webkit-scrollbar { width: 10px; }
.aqa-lab .chat-thread::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid var(--bg, var(--surface));
    border-radius: 999px;
}

/* the person's question: a bubble on the right */
#aqaThread .msg-user { align-self: flex-end; width: auto; max-width: min(560px, 86%); margin-right: 0; }

/* ---------- rail ---------- */

#page-audience-hub .chat-history-head { padding: 16px 14px 10px 16px; border-bottom: 0; gap: 8px; justify-content: flex-start; }
.chat-side-count { margin-left: 2px; font-size: 11px; font-weight: 700; color: var(--text-3); }
#page-audience-hub .chat-history-new { padding: 2px 14px 6px 16px; border-bottom: 0; }
#page-audience-hub .chat-history-new .btn {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
    min-height: 40px;
    border: 1px dashed var(--border-strong);
    background: transparent;
    color: var(--primary-dark);
    font-weight: 700;
    box-shadow: none;
}
#page-audience-hub .chat-history-new .btn:hover { background: var(--primary-soft-2); border-color: var(--primary); }
#page-audience-hub .chat-history-new svg { width: 16px; height: 16px; }

#page-audience-hub .chat-history-list { padding: 4px 8px 16px; }
#page-audience-hub .chat-day { padding: 14px 10px 6px; font-size: 12px; letter-spacing: 0; color: var(--text-3); }
#page-audience-hub .chat-item { padding: 9px 30px 9px 10px; border-radius: var(--radius-sm); }
#page-audience-hub .chat-item-title { font-size: 13px; font-weight: 600; }
#page-audience-hub .chat-item-meta { font-size: 12px; margin-top: 1px; }

.aqa-aside-title { flex: 1; min-width: 0; margin: 0; font-size: 14px; font-weight: 700; color: var(--text); }

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

#page-audience-hub .chat-head { gap: 8px; padding: 12px 20px; background: var(--surface); }
.aqa-head-copy { flex: 0 1 auto; min-width: 0; }
.aqa-head-copy .chat-title { cursor: text; font-size: 15px; letter-spacing: -.01em; }
.aqa-head-copy .chat-title:hover { color: var(--primary-dark); }
.aqa-sub { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text-3); }

.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: 8vh auto auto; max-width: 640px; padding: 0 4px; text-align: center; }
#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 h2, #aqaThread .empty h3 { margin: 13px 0 0; font-size: 26px; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
#aqaThread .empty h3 { font-size: 15px; }
#aqaThread .empty h2 { margin-top: 0; }
#aqaThread .empty p { margin: 6px auto 0; max-width: 52ch; font-size: 14px; line-height: 1.6; color: var(--text-2); }
#aqaThread .empty .btn { margin-top: 16px; }

.aqa-starters { display: grid; gap: 8px; margin-top: 22px; text-align: left; }

.aqa-starter {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: border-color var(--transition), background 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); }
.aqa-starter:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.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-mark { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
@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-note { display: block; margin-top: 1px; font-size: 11px; font-weight: 500; color: var(--text-3); }

/* the shared agent console, sized for the thread */
.msg-agent-body .agent { margin: 0; }
.msg-agent-body .agent-head { min-height: 44px; }
.msg-agent-body .agent-head:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.agent-line.is-warn .agent-mark { color: var(--warning); }
.agent-t, .agent-meta { font-size: 11px; }

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

/* ---------- source lanes: one pill per database, moving while its step runs ---------- */

.aqa-lanes { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 2px; }
.aqa-lane { display: inline-flex; align-items: center; gap: 7px; min-height: 26px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.aqa-lane-mark { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--border-strong); background: var(--surface); }
.aqa-lane.is-moving .aqa-lane-mark { border-color: var(--primary); background: var(--primary); animation: aqa-run-pulse 1.4s ease-in-out infinite; }
.aqa-lane.is-done .aqa-lane-mark { border-color: var(--success); background: var(--success); }
.aqa-lane.is-skipped .aqa-lane-mark { border-color: var(--border-strong); background: var(--border-strong); }
.aqa-lane.is-failed .aqa-lane-mark { border-color: var(--danger); background: var(--danger); }
.aqa-lane-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 700; color: var(--text-2); }
.aqa-lane.is-moving .aqa-lane-name { color: var(--text); }
.aqa-lane.is-failed .aqa-lane-name { color: var(--danger); }
.aqa-lane-dots { display: inline-flex; gap: 3px; margin-right: -2px; }
.aqa-lane-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--primary); opacity: 0; }
.aqa-lane.is-moving .aqa-lane-dots i { animation: aqa-lane-flow 1.1s linear infinite; }
.aqa-lane.is-moving .aqa-lane-dots i:nth-child(2) { animation-delay: .18s; }
.aqa-lane.is-moving .aqa-lane-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes aqa-lane-flow {
    0% { opacity: 0; transform: translateX(-3px); }
    30% { opacity: 1; }
    100% { opacity: 0; transform: translateX(4px); }
}
.aqa-lane-note { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--lab-mono); font-size: 11px; color: var(--text-2); }
.aqa-lane.is-failed .aqa-lane-note { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
    .aqa-lane.is-moving .aqa-lane-mark { animation: none; }
    .aqa-lane-dots { display: none; }
}

/* ---------- 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: 10px; padding: 10px 12px 10px 18px; }
.answer-meta { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; color: var(--text-3); }
.answer-meta svg { flex: none; width: 14px; height: 14px; }
.answer-meta > span { white-space: nowrap; }
.answer-stamp { overflow: hidden; text-overflow: ellipsis; }
.aqa-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--border-strong); }
.answer-head-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.answer-head .btn { gap: 6px; min-height: 34px; height: 34px; padding: 0 12px; font-size: 13px; }
.answer-head .btn svg { width: 16px; height: 16px; }
.answer-head .aqa-icon-btn { width: 34px; padding: 0; justify-content: center; }
.aqa-icon-btn.is-spinning svg { animation: aqa-save-spin .9s linear infinite; }

/* a full-width strip under the head, never squeezed beside the buttons */
.aqa-answer > .aqa-notice { border-top: 1px solid var(--border); }
.aqa-notice { display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 10px 18px; background: var(--warning-soft); font-size: 13px; line-height: 1.5; color: var(--text); }
.aqa-notice > svg { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--warning); }
.aqa-notice .crm-link { display: inline; min-height: 24px; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; color: var(--primary-dark); }

/* ---------- the summary as Pali's briefing ---------- */

.summary { display: flex; flex-direction: column; gap: 8px; padding: 18px 20px; background: var(--identity-gradient); border-bottom: 1px solid var(--border-strong); }
.aqa-brief-head { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); }
.aqa-brief-head b { color: var(--text); font-weight: 800; }
.aqa-pali { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 9px; background: var(--primary); color: var(--surface); }
.aqa-pali svg { width: 16px; height: 16px; }
.summary .aqa-lead { margin: 0; font-size: clamp(15px, 1.6vw, 17px); line-height: 1.3; letter-spacing: -.02em; font-weight: 800; text-wrap: balance; max-width: 56ch; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.summary .aqa-lead.is-solo { font-size: 14px; line-height: 1.55; letter-spacing: 0; font-weight: 600; }
.summary p { margin: 0; white-space: pre-line; font-size: 14px; line-height: 1.6; color: var(--text); max-width: 70ch; }

/* the databases an answer was built on */
.aqa-used { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 9px 16px; }
.aqa-used-label { font-family: var(--lab-mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.aqa-used-src { padding: 2px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); font-size: 11px; font-weight: 600; color: var(--text-2); }

.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); }
.aqa-rows > summary { list-style: none; cursor: pointer; margin-bottom: 0; align-items: center; }
.aqa-rows > summary::-webkit-details-marker { display: none; }
.aqa-rows[open] > summary { margin-bottom: 12px; }
.aqa-rows-caret { display: grid; place-items: center; color: var(--text-3); transition: transform .15s; }
.aqa-rows-caret svg { width: 16px; height: 16px; }
.aqa-rows[open] .aqa-rows-caret { transform: rotate(180deg); }
.aqa-rows > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { .aqa-rows-caret { transition: none; } }
.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-fill.is-stack { display: flex; flex-direction: column-reverse; justify-content: flex-start; overflow: hidden; background: none; }
.col-seg { flex: 0 0 auto; height: var(--h); }
.col-seg + .col-seg { box-shadow: 0 2px 0 var(--surface); }
.aqa-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 11px 0 0; padding: 0; font-size: 11.5px; color: var(--text-2); }
.aqa-legend li { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.aqa-legend-dot { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 3px; }
.aqa-chart-na { margin: 0; padding: 14px 0; font-size: 12.5px; color: var(--text-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; }

/* ---------- 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-note { text-align: center; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.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 ---------- */

#page-audience-hub .chat-composer { padding: 6px 20px 14px; border-top: 0; background: var(--bg, var(--surface)); }
#page-audience-hub .chat-box { max-width: 860px; margin: 0 auto; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
#page-audience-hub .chat-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.aqa-main .chat-bar { justify-content: flex-start; flex-wrap: nowrap; padding: 8px 10px 10px; }
.aqa-main .chat-bar .btn { margin-left: 8px; min-height: 34px; padding: 0 16px; }
.aqa-main .chat-hint { max-width: 860px; margin: 6px auto 0; text-align: center; font-size: 12px; }
.aqa-main .chat-hint kbd { font-size: 11px; padding: 1px 5px; }

.chat-guard { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--text-3); }
.chat-guard svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

.aqa-main #aqaPrompt {
    width: 100%;
    min-height: 54px;
    max-height: 180px;
    resize: none;
    border: 0;
    padding: 14px 16px 4px;
    font: inherit;
    font-size: 15px;
    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); }

/* database chip + popover */
.aqa-src-wrap { position: relative; min-width: 0; }
.aqa-src-wrap[hidden], .aqa-pop[hidden], .aqa-sources-note[hidden] { display: none; }
.aqa-src-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); font: inherit; font-size: 13px; font-weight: 700; color: var(--text-2); cursor: pointer; transition: border-color var(--transition), background var(--transition), color var(--transition); }
.aqa-src-chip:hover:not(:disabled), .aqa-src-chip[aria-expanded="true"] { border-color: var(--primary); background: var(--primary-soft-2); color: var(--primary-dark); }
.aqa-src-chip:focus-visible, .aqa-src:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.aqa-src-chip.is-static:disabled { cursor: default; opacity: 1; color: var(--text-2); }
.aqa-src-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aqa-led { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.aqa-led.is-warn { background: var(--warning); }
.aqa-chev { flex: none; width: 14px; height: 14px; }
.aqa-chev.is-hidden { display: none; }
.aqa-pop { position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 10; width: 340px; max-width: calc(100vw - 40px); padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: 0 12px 32px rgba(13, 27, 42, .14); }
.aqa-pop h3 { margin: 6px 8px 4px; font-size: 13px; font-weight: 700; }
.aqa-pop-hint { margin: 0 8px 6px; font-size: 12.5px; color: var(--text-3); }
.aqa-pop-foot { margin: 6px 0 0; padding: 8px 8px 4px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); }
.aqa-pop-foot .crm-link { display: inline; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; color: var(--primary-dark); }
.aqa-sources-list { display: flex; flex-direction: column; }
.aqa-src { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 9px 8px; border: 0; border-radius: var(--radius-sm); background: transparent; font: inherit; color: var(--text); text-align: left; cursor: pointer; transition: background var(--transition); }
.aqa-src:hover:not([aria-disabled="true"]) { background: var(--surface-soft); }
.aqa-src[aria-disabled="true"] { cursor: not-allowed; color: var(--text-3); }
.aqa-chk { display: grid; place-items: center; flex: none; width: 18px; height: 18px; border: 1.5px solid var(--border-strong); border-radius: 5px; background: var(--surface); transition: background var(--transition), border-color var(--transition); }
.aqa-chk svg { width: 12px; height: 12px; stroke: #fff; stroke-width: 3; opacity: 0; }
.aqa-src[aria-checked="true"] .aqa-chk { border-color: var(--primary); background: var(--primary); }
.aqa-src[aria-checked="true"] .aqa-chk svg { opacity: 1; }
.aqa-src-text { min-width: 0; }
.aqa-src-name, .aqa-src-desc { display: block; }
.aqa-src-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 700; }
.aqa-src-desc { font-size: 12.5px; color: var(--text-3); }
.aqa-src-status { margin-left: auto; flex: none; font-size: 12px; font-weight: 700; color: var(--success); }
.aqa-src-status.is-failed { color: var(--danger); }
.aqa-src-status.is-refreshing, .aqa-src-status.is-connecting { color: var(--warning); }
.aqa-sources-note { max-width: 860px; margin: 6px auto 0; font-size: 12.5px; color: var(--text-2); }

/* ---------- 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: 900px) {
    #page-audience-hub.active { padding-left: 12px; padding-right: 12px; }
    #hubViewQa .aqa-lab { grid-template-columns: minmax(0, 1fr); }
    .aqa-history, .aqa-main { grid-column: 1; }
    /* the rail is a slide-over drawer; the toggle in the top bar opens it */
    .aqa-lab .aqa-history { position: fixed; z-index: 40; inset: var(--topbar) auto 0 0; width: min(300px, 86vw); display: flex; border-right: 1px solid var(--border); box-shadow: 0 12px 32px rgba(13, 27, 42, .14); transition: transform var(--transition); }
    .aqa-lab.is-rail-hidden .aqa-history { display: flex; visibility: hidden; transform: translateX(-102%); }
    .aqa-pop { width: min(340px, calc(100vw - 40px)); }
    .aqa-sub { display: none; }
    .aqa-main .chat-hint { display: none; }
    .aqa-src, .aqa-src-chip, .aqa-starter, #page-audience-hub .chat-item, #page-audience-hub .chat-history-new .btn { min-height: 44px; }
    .answer-head .btn { min-height: 44px; height: 44px; }
    .answer-head .aqa-icon-btn { width: 44px; }
    .aqa-main .chat-bar .btn { min-height: 44px; }
    #page-audience-hub .icon-btn { min-width: 44px; min-height: 44px; }
}

@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) {
    #page-audience-hub .chat-thread { padding-left: 12px; padding-right: 12px; }
    .answer-head { padding-left: 12px; }
    .aqa-notice { padding-left: 12px; padding-right: 12px; }
    .aqa-main .chat-bar { gap: 6px; padding: 8px; }
    .summary { padding-left: 14px; padding-right: 14px; }
    .answer-head,
    .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; }
}

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

.aqa-history .chat-history-head { padding: 0 8px 0 4px; }
.aqa-seg-error { color: var(--danger); }
.aqa-seg-attn { color: var(--warning); }
.aqa-note.aqa-seg-attn { margin: 0; padding: 4px 16px 0; font-size: 12.5px; }
.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-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: 12px; padding: 8px 0; font-size: 12.5px; color: var(--text-2); }
:where(.aqa-save-working, .aqa-save-fail) p { margin: 0; }
.aqa-save-working-title { font-size: 14px; font-weight: 700; color: var(--text); }
.aqa-save-working-note { margin-top: 4px; font-size: 12px; color: var(--text-3); }
.aqa-save-spin { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--primary-soft); border-top-color: var(--primary); animation: aqa-save-spin .9s linear infinite; }
@keyframes aqa-save-spin { to { transform: rotate(360deg); } }
.aqa-save-fail { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.aqa-save-fail-icon { flex: 0 0 32px; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--warning-soft); color: var(--warning); }
.aqa-save-fail-icon svg { width: 18px; height: 18px; }
.aqa-save-fail-title { font-size: 14px; font-weight: 700; color: var(--text); }
.aqa-save-fail-text, .aqa-save-wait { margin-top: 4px; font-size: 12.5px; color: var(--text-2); }
.aqa-save-nocontact { display: flex; gap: 8px; align-items: center; margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--warning-soft); color: var(--warning); font-size: 12px; font-weight: 600; }
.aqa-save-nocontact svg { flex: 0 0 14px; width: 14px; height: 14px; }
.aqa-reach { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 0 8px; font-size: 12px; color: var(--text-2); }
.aqa-reach-stat b { font-size: 14px; color: var(--text); }

/* group picker */
.aqa-pick-intro { margin: 0 0 12px; font-size: 12.5px; color: var(--text-2); }
.aqa-pick-tabs { display: flex; gap: 4px; margin-bottom: 10px; padding: 3px; border-radius: 10px; background: var(--surface-hover); overflow-x: auto; }
.aqa-pick-tab { flex: 1 0 auto; min-height: 44px; padding: 0 14px; border: 0; border-radius: 8px; background: none; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.aqa-pick-tab.is-on { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.aqa-pick-search { margin-bottom: 4px; min-height: 44px; }
.aqa-pick-tools { display: flex; gap: 4px; margin: 2px 0; }
.aqa-pick-tools .btn { min-height: 44px; padding-inline: 8px; color: var(--primary); }
.aqa-pick-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.aqa-pick-item { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; cursor: pointer; font-size: 13px; color: var(--text); }
.aqa-pick-item + .aqa-pick-item { border-top: 1px solid var(--border); }
.aqa-pick-item:hover { background: var(--surface-soft); }
.aqa-pick-item:focus-within { outline: 2px solid var(--primary); outline-offset: -2px; }
.aqa-pick-item input { flex: 0 0 auto; width: 16px; height: 16px; accent-color: var(--primary); }
.aqa-pick-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.aqa-pick-count { flex: 0 0 auto; padding: 2px 8px; border-radius: 999px; background: var(--surface-hover); font: 600 11px var(--mono, ui-monospace, monospace); color: var(--text-2); }
.aqa-pick-empty { margin: 0; padding: 16px; text-align: center; font-size: 12.5px; color: var(--text-3); }
.aqa-pick-sum { margin: 10px 0 0; font-size: 12.5px; font-weight: 700; color: var(--text); }
.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-modal .modal-footer .btn, .aqa-save-modal .aqa-save-again { min-height: 44px; }
.aqa-save-hint { margin: 8px 0 0; font-size: 11px; color: var(--text-3); }

@media (prefers-reduced-motion: reduce) {
    .aqa-save-spin { animation: none; }
}
@media (max-width: 600px) {
    #aqaSaveModal { align-items: flex-end; padding: 0; }
    .aqa-save-modal { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
}
.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; } }

@media (prefers-reduced-motion: reduce) {
    .aqa-src-chip, .aqa-src, .aqa-chk, .aqa-icon-btn.is-spinning svg { transition: none; animation: none; }
}
