/* =========================================================================
   Post-call — Agent Evaluation / QA card
   ========================================================================= */

/* ---- Card header: title left, score block right, both top-aligned ------ */
.qa-eval-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.qa-eval-header .card-title { margin-bottom: 0; }

/* Score block (right column of header) */
.qa-overall-score-row { text-align: right; flex-shrink: 0; }
.qa-overall-score-main {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 900;
  color: var(--yellow);
  letter-spacing: -0.03em;
  line-height: 1;
}
.qa-overall-score-pct {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: -0.02em;
  line-height: 1;
  margin-top: 4px;
}

/* ---- Criteria list ----------------------------------------------------- */
.qa-criteria { list-style: none; padding: 0; margin: 8px 0 0; }

.qa-item {
  display: flex;
  flex-wrap: wrap;
  /* Column-only gap: collapsible detail rows (reasoning/dispute) sit at
     0 height when closed, so a row-gap would leak vertical space. Their
     own inner padding provides spacing when open. */
  gap: 0 8px;
  padding: 3px 0;
  font-size: 0.875rem;
  color: var(--text);
  cursor: help;
  align-items: baseline;
  animation: qaItemEnter var(--dur-comp) var(--ease) both;
}

/* Stagger up to 20 items at 40 ms intervals */
.qa-item:nth-child(1)  { animation-delay:  0ms; }
.qa-item:nth-child(2)  { animation-delay: 40ms; }
.qa-item:nth-child(3)  { animation-delay: 80ms; }
.qa-item:nth-child(4)  { animation-delay: 120ms; }
.qa-item:nth-child(5)  { animation-delay: 160ms; }
.qa-item:nth-child(6)  { animation-delay: 200ms; }
.qa-item:nth-child(7)  { animation-delay: 240ms; }
.qa-item:nth-child(8)  { animation-delay: 280ms; }
.qa-item:nth-child(9)  { animation-delay: 320ms; }
.qa-item:nth-child(10) { animation-delay: 360ms; }
.qa-item:nth-child(11) { animation-delay: 400ms; }
.qa-item:nth-child(12) { animation-delay: 440ms; }
.qa-item:nth-child(13) { animation-delay: 480ms; }
.qa-item:nth-child(14) { animation-delay: 520ms; }
.qa-item:nth-child(15) { animation-delay: 560ms; }
.qa-item:nth-child(16) { animation-delay: 600ms; }
.qa-item:nth-child(17) { animation-delay: 640ms; }
.qa-item:nth-child(18) { animation-delay: 680ms; }
.qa-item:nth-child(19) { animation-delay: 720ms; }
.qa-item:nth-child(20) { animation-delay: 760ms; }

/* Training prescription (secondary line) */
.qa-prescription {
  flex-basis: 100%;
  margin-left: calc(1.1em + 8px);
  margin-top: 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.35;
}
.qa-prescription.qa-prescription-critical { color: var(--red); font-weight: 600; }

/* KB / Policy reference line */
.qa-kb-line {
  flex-basis: 100%;
  margin-left: calc(1.1em + 8px);
  margin-top: 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.35;
  font-style: italic;
}

/* KB expand toggle */
.qa-kb-toggle {
  flex-basis: 100%;
  margin-left: calc(1.1em + 8px);
  margin-top: 2px;
  padding: 0.15rem 0;
  background: none;
  border: none;
  color: var(--teal);
  font: inherit;
  font-size: 0.75rem;
  text-align: left;
  cursor: pointer;
}
.qa-kb-toggle:hover { text-decoration: underline; text-underline-offset: 2px; }
.qa-kb-toggle:focus-visible { outline: 1px dashed var(--teal); outline-offset: 2px; }

.qa-kb-detail {
  display: none;
  flex-basis: 100%;
  margin-left: calc(1.1em + 8px);
  margin-top: 0.3rem;
  padding: 0.5rem 0.75rem;
  border-left: 2px solid var(--teal-border);
  background: var(--teal-soft);
  border-radius: var(--radius-xs);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text);
}
.qa-kb-detail.expanded  { display: block; }
.qa-kb-detail h3,
.qa-kb-detail h4        { margin: 0.3rem 0 0.4rem; font-size: 0.85rem; }
.qa-kb-detail p         { margin: 0.3rem 0; }
.qa-kb-detail ul,
.qa-kb-detail ol        { margin: 0.3rem 0 0.3rem 1.2rem; padding: 0; }
.qa-kb-detail strong    { color: var(--text); }
.qa-kb-detail code      { font-family: var(--font-mono); background: rgba(0,0,0,0.2); padding: 0 0.2em; border-radius: 3px; }

/* Score column */
.qa-score {
  flex-shrink: 0;
  min-width: 3.2em;
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* Stage group header */
.qa-stage-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 0 3px;
  border-bottom: 1px solid var(--border);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-weight: 700;
}
.qa-stage-header:first-child { margin-top: 0; }
.qa-stage-label { flex: 1; min-width: 0; }
.qa-stage-score { font-family: var(--font-mono); font-weight: 700; color: var(--text); min-width: 3.2em; text-align: right; }

/* Status icon */
.qa-icon          { font-weight: 700; width: 1.1em; text-align: center; flex-shrink: 0; }
.qa-icon.qa-pass  { color: var(--teal); }
.qa-icon.qa-warn  { color: var(--yellow); }
.qa-icon.qa-fail  { color: var(--red); }
.qa-icon.qa-na    { color: var(--text-faint); }
.qa-label         { flex: 1; min-width: 0; }

/* N/A rows — muted text instead of opacity so evaluated rows stand out */
.qa-item.qa-item-na { color: var(--text-muted); }
.qa-item.qa-item-na .qa-label { color: var(--text-muted); }
.qa-item.qa-item-na .qa-score { color: var(--text-faint); }

/* Hide N/A rows when "Evaluated" filter is active */
#qa-eval-card.qa-hide-na .qa-item-na { display: none; }
.qa-na-reason { font-style: italic; }

/* Auto-fail row */
.qa-item.qa-auto-fail {
  padding-left: 8px;
  border-left: 3px solid var(--red);
  background: var(--red-soft);
  border-radius: var(--radius-xs);
  margin: 2px 0;
}

/* ---- Attribution chips ------------------------------------------------- */
.qa-rta-chips { display: inline-flex; gap: 4px; margin: 0 0.5rem; flex-shrink: 0; }
.qa-rta-chip {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  animation: chipEnter 280ms var(--ease-spring) both;
}
.qa-rta-chip.qa-rta-fired    { background: var(--blue-soft);    color: var(--blue); }
.qa-rta-chip.qa-rta-acted    { background: var(--teal-soft);    color: var(--teal); }
.qa-rta-chip.qa-emotion-chip { background: var(--yellow-soft);  color: var(--yellow); text-transform: none; letter-spacing: 0.01em; }
.qa-rta-chip.qa-sim-trigger  { background: var(--red-soft);     color: var(--red); }
.qa-rta-chip.qa-ksa-chip     { background: var(--surface-raised); color: var(--text-dim); text-transform: none; letter-spacing: 0.01em; border: 1px solid var(--border); }

/* ---- Inline reasoning (shown when .qa-show-reasoning on card) ----------- */
.qa-reasoning {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s var(--ease);
  flex-basis: 100%;
  margin-left: calc(1.1em + 8px);
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.45;
  font-style: italic;
}
#qa-eval-card.qa-show-reasoning .qa-reasoning { grid-template-rows: 1fr; }
.qa-reasoning > .qa-collapsible-inner { padding-top: 3px; }

/* Shared collapsible inner: clipped + shrinkable so the grid-rows trick
   can animate the wrapper's height open/closed in 0.25s. */
.qa-collapsible-inner { overflow: hidden; min-height: 0; }

/* Per-row expand reveal — not scoped to #qa-eval-card so the same
   expandable/disputable row works in the training recap Evaluation card. */
.qa-item.qa-item-expanded .qa-reasoning { grid-template-rows: 1fr; }

/* KB elements inside .qa-reasoning already inherit its indentation */
.qa-reasoning .qa-kb-toggle,
.qa-reasoning .qa-kb-detail,
.qa-reasoning .qa-kb-line { margin-left: 0; }
.qa-reasoning .qa-kb-toggle { margin-top: 0.35rem; font-style: normal; }

/* ---- Click-to-expand row + Dispute affordance -------------------------- */
.qa-item-expandable { cursor: pointer; }
.qa-item-expandable:hover .qa-label { color: var(--text); }
/* Expanded rows get a subtle frame to anchor the revealed detail */
.qa-item.qa-item-expanded {
  background: var(--surface-raised);
  border-radius: var(--radius-xs);
  padding: 6px 8px;
  margin: 2px 0;
}

/* Dispute bar — only present on expandable rows, animates open when the
   row is expanded (height grows in 0.25s alongside the reasoning). */
.qa-dispute-bar {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s var(--ease);
  flex-basis: 100%;
}
.qa-item.qa-item-expanded .qa-dispute-bar { grid-template-rows: 1fr; }
.qa-dispute-bar > .qa-collapsible-inner {
  display: flex;
  justify-content: flex-end;
  padding-top: 6px;
}

.qa-dispute-btn {
  font: inherit;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 14px;
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-micro) var(--ease),
              color      var(--dur-micro) var(--ease);
}
.qa-dispute-btn:hover { background: var(--red); color: #fff; }
.qa-dispute-btn:focus-visible { outline: 1px dashed var(--red); outline-offset: 2px; }

/* Dispute composer — animates open/closed in 0.25s when the trigger
   toggles .qa-dispute-open. */
.qa-dispute-area {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s var(--ease);
  flex-basis: 100%;
}
.qa-item.qa-dispute-open .qa-dispute-area { grid-template-rows: 1fr; }
.qa-dispute-area > .qa-collapsible-inner { padding-top: 6px; }
.qa-dispute-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
}
.qa-dispute-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 6px;
}
.qa-dispute-send {
  font: inherit;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 14px;
  background: var(--red);
  color: #fff;
  border: 1px solid var(--red);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-micro) var(--ease), opacity var(--dur-comp) var(--ease);
}
.qa-dispute-send:hover { background: var(--red-dark); }
.qa-dispute-send:focus-visible { outline: 1px dashed var(--red); outline-offset: 2px; }

/* Confirmation message — hidden until Send flips .qa-dispute-sent */
.qa-dispute-confirm {
  display: none;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal);
  font-style: normal;
}
.qa-dispute-area.qa-dispute-sent .qa-dispute-confirm {
  display: inline-block;
  animation: disputeConfirm 360ms var(--ease-spring) both;
}
/* On send, fade out the composer inputs while the confirmation pops */
.qa-dispute-area.qa-dispute-sent .qa-dispute-input,
.qa-dispute-area.qa-dispute-sent .qa-dispute-send {
  opacity: 0.35;
  pointer-events: none;
}

/* ---- Toolbar (Criteria / Reasoning toggles) ----------------------------- */
.qa-eval-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  margin-bottom: 0.35rem;
  border-top: 1px solid var(--border);
}
.qa-toolbar-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  user-select: none;
}
.qa-toolbar-sep {
  width: 1px;
  height: 1rem;
  background: var(--border);
  margin: 0 0.15rem;
  flex-shrink: 0;
}
.qa-toggle-group {
  display: flex;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px;
  gap: 2px;
}
.qa-toggle-btn {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  cursor: pointer;
  line-height: 1.4;
  transition: background var(--dur-micro) var(--ease),
              color     var(--dur-micro) var(--ease);
}
.qa-toggle-btn:hover:not(.qa-toggle-active) { color: var(--text); }
.qa-toggle-btn.qa-toggle-active {
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid var(--teal-border);
}

/* ---- Status banner (top of eval card) ---------------------------------- */
.qa-status-banner {
  padding: 0.5rem 0.85rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid;
  border-radius: var(--radius-xs);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.qa-status-banner.qa-status-passed         { background: var(--teal-soft);   color: var(--teal);        border-left-color: var(--teal); }
.qa-status-banner.qa-status-failed         { background: var(--red-soft);    color: var(--red);         border-left-color: var(--red); }
.qa-status-banner.qa-status-coaching,
.qa-status-banner.qa-status-needs-coaching { background: var(--yellow-soft); color: var(--yellow);      border-left-color: var(--yellow); }
.qa-status-banner.qa-status-pending-review { background: var(--surface-raised); color: var(--text-muted); border-left-color: var(--border-emph); }
