/* ===== FORMS: ANALYTICS PANE ===== */
/* Styles for public/js/form-analytics.js (#frmPane-analytics). Leans on the
   shared design system (frm-shared.css: .frm-kpi / .frm-btn / .frm-select /
   .frm-table-* / .frm-empty) and the dashboard tokens (--card/--border/
   --accent/--text*, --r*, --s*, --fz-*), so the pane reads as one product and is
   correct in dark (default) AND [data-theme=light]. Only analytics-specific
   surfaces (funnel strip, qualification bar, SVG chart, drop-off bars, the
   per-answer drill) carry bespoke rules here. Every class is .frm-an- prefixed.
   Loaded AFTER frm-shared.css, so these win on this pane's own surfaces. */

.frm-an {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  padding: var(--s6);
  max-width: 1280px;
  margin-inline: auto;
  color: var(--text);
  font-size: var(--fz-base);
}

/* ── header: sub-tabs + range picker ── */
.frm-an-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}
.frm-an-tabs {
  display: inline-flex;
  gap: var(--s1);
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: 3px;
}
.frm-an-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  background: transparent;
  border: none;
  border-radius: var(--r2);
  color: var(--text2);
  padding: 7px 14px;
  font-size: var(--fz-md);
  font-weight: var(--fw-semibold);
  font-family: inherit;
  cursor: pointer;
  transition:
    background var(--tr-base),
    color var(--tr-base);
}
.frm-an-tab .mi,
.frm-an-tab .frm-ico {
  width: 15px;
  height: 15px;
}
.frm-an-tab:hover {
  color: var(--text);
}
.frm-an-tab-on {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.frm-an-tab-on .frm-ico {
  color: var(--accent);
}

.frm-an-rangebar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}
.frm-an-range-ico {
  display: inline-flex;
  align-items: center;
  color: var(--text3);
}
.frm-an-range-ico .frm-ico {
  width: 16px;
  height: 16px;
}
select.frm-select.frm-an-rangesel {
  width: auto;
  min-width: 156px;
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: var(--fz-sm);
}
.frm-an-date.frm-input {
  width: auto;
  padding: 7px 10px;
  font-size: var(--fz-sm);
}
.frm-an-dash {
  display: inline-flex;
  align-items: center;
  color: var(--text3);
}
.frm-an-rangelabel {
  color: var(--text3);
  font-size: var(--fz-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  padding-left: var(--s1);
}
.frm-btn.frm-an-refresh {
  color: var(--text2);
}

/* Dashboard "View all" / "Retry" affordance — a subtle accent link-button
   (dashboard-only class; kept dark-correct instead of a bare white <button>). */
.frm-an-apply {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r2);
  color: var(--accent);
  padding: 4px 8px;
  font-size: var(--fz-sm);
  font-weight: var(--fw-semibold);
  font-family: inherit;
  cursor: pointer;
  transition:
    background var(--tr-base),
    color var(--tr-base);
}
.frm-an-apply:hover {
  background: var(--accent-dim);
}
.frm-an-apply:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── segmented toggle chips (denominator + count/rate) ── */
.frm-an-segrow {
  display: inline-flex;
  gap: 2px;
  background: var(--track);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.frm-an-seg {
  background: transparent;
  color: var(--text2);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: var(--fz-sm);
  font-weight: var(--fw-semibold);
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--tr-base),
    color var(--tr-base);
}
.frm-an-seg:hover {
  color: var(--text);
}
.frm-an-seg-on {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ── KPI stat tiles (built on shared .frm-kpi) ── */
/* Fixed column count, NOT auto-fit: on an ultrawide viewport (3000px+) a
   `repeat(auto-fit, minmax(200px,1fr))` grid spawns ~15 tracks, collapses the
   11 empty ones to 0 and stretches the 4 real tiles to ~800px each. An explicit
   N-column grid plus a capped, centered row keeps every tile a comfortable
   StatCard width at every width. */
.frm-an-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s4);
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
}
/* Explicit N-column siblings (only -4 is emitted today; keep the family
   consistent so a future -2 / -3 KPI row lands correct). */
.frm-an-tiles-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.frm-an-tiles-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.frm-an-tiles-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
/* Collapse 4/3 → 2 → 1 as the pane narrows. */
@media (max-width: 920px) {
  .frm-an-tiles,
  .frm-an-tiles-3,
  .frm-an-tiles-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 480px) {
  .frm-an-tiles,
  .frm-an-tiles-2,
  .frm-an-tiles-3,
  .frm-an-tiles-4 {
    grid-template-columns: minmax(0, 1fr);
  }
}
.frm-an-tile .frm-ico {
  color: var(--text3);
}

/* ── dashboard StatCard (Marketing Overview KPI tiles) ── */
/* forms.js _dashTile renders these as real cards on the shared .frm-kpi
   primitive, led by a colored icon badge per metric (ROASform StatCard). The
   .frm-an-tile* hooks are kept for the DOM tests. */
.frm-dash-kpi {
  gap: var(--s3);
}
.frm-dash-kpi-top {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
}
.frm-dash-kpi-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: var(--r3);
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
}
.frm-dash-kpi-badge .frm-ico {
  width: 18px;
  height: 18px;
  color: inherit; /* beat `.frm-an-tile .frm-ico { color: var(--text3) }` above */
}
.frm-dash-kpi .frm-an-tile-label {
  margin: 0;
}
/* per-metric badge tones (red rationed for "act now", so none here) */
.frm-dash-kpi-badge-leads {
  color: var(--blue);
  background: var(--accent-dim);
}
.frm-dash-kpi-badge-appts {
  color: var(--green);
  background: color-mix(in srgb, var(--green) 13%, transparent);
}
.frm-dash-kpi-badge-qual {
  color: var(--purple);
  background: color-mix(in srgb, var(--purple) 14%, transparent);
}
.frm-dash-kpi-badge-conv {
  color: var(--gold);
  background: rgba(217, 170, 69, 0.12);
}
.frm-an-up {
  color: var(--green);
}
.frm-an-down {
  color: var(--red);
}
.frm-an-bad {
  color: var(--red);
}
.frm-an-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--fz-2xl);
  font-weight: var(--fw-bold);
}
.frm-an-delta .frm-ico {
  color: inherit;
}

/* ── cards ── */
.frm-an-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r4);
  padding: var(--s5);
}
.frm-an-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
  color: var(--text);
  font-size: var(--fz-lg);
  font-weight: var(--fw-bold);
  margin-bottom: var(--s4);
}
.frm-an-title-lead {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}
.frm-an-title-lead .frm-ico {
  width: 17px;
  height: 17px;
  color: var(--text3);
  flex-shrink: 0;
}
/* Callers render 2 or 3 cards (never more). auto-fit is kept as-is here
   (unlike .frm-an-tiles-4/.frm-kpi-row): this grid already lives inside the
   1280px-capped .frm-an pane, so the worst-case stretch (2 cards filling
   ~600px each) is mild — nowhere near the ~900px+ blowout those fixed-count
   rows hit at full viewport width. (A minmax(300px, min(460px,1fr)) cap was
   tried instead; Chrome's auto-repeat track-counting doesn't resolve a
   min()-wrapped flex max and silently collapses the grid to one column at
   every width — don't reintroduce that.) */
.frm-an-cards3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--s4);
}
.frm-an-big {
  color: var(--text);
  font-size: var(--fz-4xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
}
.frm-an-sub {
  color: var(--text3);
  font-size: var(--fz-sm);
  margin-top: var(--s2);
}

/* ── funnel strip ── */
.frm-an-funnel {
  display: flex;
  align-items: stretch;
  gap: var(--s2);
  overflow-x: auto;
}
.frm-an-funnel-stage {
  flex: 1 1 0;
  min-width: 150px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.frm-an-funnel-top {
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.frm-an-funnel-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--r2);
  background: color-mix(in srgb, currentColor 14%, transparent);
  flex-shrink: 0;
}
.frm-an-funnel-icon .frm-ico {
  width: 15px;
  height: 15px;
}
.frm-an-funnel-label {
  color: var(--text3);
  font-size: var(--fz-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: var(--lh-snug);
}
.frm-an-funnel-count {
  color: var(--text);
  font-size: var(--fz-3xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
}
.frm-an-funnel-conv {
  color: var(--text3);
  font-size: var(--fz-xs);
  font-weight: var(--fw-medium);
}
.frm-an-funnel-arrow {
  align-self: center;
  display: inline-flex;
  color: var(--text3);
  flex: 0 0 auto;
}
.frm-an-funnel-arrow .frm-ico {
  width: 20px;
  height: 20px;
}
.frm-an-spark {
  width: 100%;
  max-width: 150px;
  height: 30px;
  display: block;
  margin-top: var(--s1);
}

/* ── qualification stacked bar ── */
.frm-an-stack {
  display: flex;
  height: 20px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--track);
  margin-top: var(--s2);
  gap: 2px;
}
.frm-an-stack-seg {
  height: 100%;
  transition: width var(--tr-slow);
}
.frm-an-stack-q {
  background: var(--green);
}
.frm-an-stack-u {
  background: var(--orange);
}
.frm-an-stack-n {
  background: var(--text3);
}
.frm-an-legend {
  display: flex;
  gap: var(--s4);
  flex-wrap: wrap;
  color: var(--text2);
  font-size: var(--fz-sm);
  font-weight: var(--fw-medium);
  margin-top: var(--s3);
}
.frm-an-legend span {
  display: inline-flex;
  align-items: center;
}
.frm-an-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}

/* ── all-time footnote ── */
.frm-an-alltime {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text3);
  font-size: var(--fz-sm);
  font-weight: var(--fw-medium);
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--s3) var(--s4);
}
.frm-an-alltime .frm-ico {
  width: 14px;
  height: 14px;
  color: var(--text3);
  flex-shrink: 0;
}

/* ── trend explorer ── */
.frm-an-trend-controls {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}
select.frm-select.frm-an-select {
  width: auto;
  min-width: 170px;
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: var(--fz-sm);
}
.frm-an-tiles-4 {
  margin-bottom: var(--s4);
}
.frm-an-chart-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--s3) var(--s3) var(--s2);
}
.frm-an-chart {
  width: 100%;
  height: auto;
  display: block;
}
.frm-an-chart-legend {
  margin-bottom: var(--s3);
}
.frm-an-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.7;
}
.frm-an-axis {
  stroke: var(--border2);
  stroke-width: 1.25;
}
.frm-an-tick {
  fill: var(--text3);
  font-size: 11px;
  font-weight: var(--fw-medium);
  font-family: inherit;
}
.frm-an-area {
  opacity: 0.12;
}
.frm-an-pt {
  opacity: 0.9;
}
.frm-an-chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  color: var(--text3);
  font-size: var(--fz-base);
  padding: var(--s8) var(--s4);
}
.frm-an-chart-empty-ico {
  display: inline-flex;
  color: var(--text3);
}
.frm-an-chart-empty-ico .frm-ico {
  width: 26px;
  height: 26px;
}

/* ── question breakdown (shared .frm-table look + drop-off bars) ── */
.frm-an-section {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.frm-an-section-head {
  display: flex;
  align-items: center;
  color: var(--text);
  font-size: var(--fz-lg);
  font-weight: var(--fw-bold);
}
.frm-an-qwrap {
  /* .frm-table-wrap supplies the card frame + overflow-x */
}
.frm-an-qtable {
  font-size: var(--fz-base);
}
.frm-an-qnum {
  width: 40px;
  color: var(--text3);
  text-align: center !important;
  font-variant-numeric: tabular-nums;
}
.frm-an-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.frm-an-qtable td.frm-an-num {
  color: var(--text);
  font-weight: var(--fw-semibold);
}
.frm-an-qtitle {
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: var(--fw-medium);
}
.frm-an-qtwist {
  display: inline-flex;
  align-items: center;
  color: var(--text3);
  margin-right: var(--s2);
  vertical-align: middle;
  transition: color var(--tr-base);
}
.frm-an-qrow:hover .frm-an-qtwist {
  color: var(--accent);
}
.frm-an-qrow-open {
  background: var(--accent-dim) !important;
}
.frm-an-qrow-open .frm-an-qtwist {
  color: var(--accent);
}

/* ── dashboard tables (Top Forms / Upcoming Appointments / By Client) ── */
/* These render as a bare .frm-an-qtable inside .frm-an-card (no shared
   .frm-table-el frame), so give their cells the padded, ruled look here.
   Scoped to .frm-dash so the analytics pane's .frm-table-el qtable is untouched. */
.frm-dash .frm-an-qtable {
  width: 100%;
  border-collapse: collapse;
}
.frm-dash .frm-an-qtable thead th {
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: var(--fz-xs);
  font-weight: var(--fw-semibold);
  color: var(--text3);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border2);
  white-space: nowrap;
}
.frm-dash .frm-an-qtable thead th.frm-an-num {
  text-align: right;
}
.frm-dash .frm-an-qtable tbody td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.frm-dash .frm-an-qtable tbody tr:last-child td {
  border-bottom: none;
}
.frm-dash .frm-an-qrow {
  cursor: pointer;
  transition: background var(--tr-base);
}
.frm-dash .frm-an-qrow:hover {
  background: var(--card-hover);
}

/* ── per-client rollup card ── */
.frm-dash-rollup-hint {
  margin-top: 0;
  font-weight: var(--fw-medium);
  white-space: nowrap;
}
.frm-dash-rollup-internal td {
  color: var(--text3);
}
.frm-an-dropcol {
  width: 150px;
}
.frm-an-dropcell {
  color: var(--text);
  font-weight: var(--fw-semibold);
}
.frm-an-dropwrap {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  justify-content: flex-end;
}
.frm-an-dropbar {
  display: inline-block;
  width: 64px;
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
  flex-shrink: 0;
}
.frm-an-dropbar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
}
.frm-an-drop-lo .frm-an-dropbar-fill {
  background: var(--green);
}
.frm-an-drop-mid .frm-an-dropbar-fill {
  background: var(--orange);
}
.frm-an-drop-hi .frm-an-dropbar-fill {
  background: var(--red);
}
.frm-an-dropval {
  min-width: 46px;
  text-align: right;
}

/* per-answer drill */
.frm-an-drillrow > td {
  background: var(--bg2);
  padding: var(--s4) var(--s5) !important;
  white-space: normal;
}
.frm-an-drilltable {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fz-sm);
}
.frm-an-drilltable th {
  text-align: left;
  color: var(--text3);
  font-size: var(--fz-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border2);
}
.frm-an-drilltable th.frm-an-num {
  text-align: right;
}
.frm-an-drilltable td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  color: var(--text2);
}
.frm-an-drilltable td.frm-an-num {
  color: var(--text);
  font-weight: var(--fw-semibold);
}
.frm-an-drilltable tr:last-child td {
  border-bottom: none;
}
.frm-an-drilllabel {
  color: var(--text);
  font-weight: var(--fw-medium);
}
.frm-an-sharebar {
  display: inline-block;
  width: 54px;
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
  margin-right: var(--s3);
  vertical-align: middle;
}
.frm-an-sharebar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* ── states ── */
.frm-an-empty {
  color: var(--text3);
  font-size: var(--fz-base);
  text-align: center;
  padding: var(--s6) var(--s4);
}
.frm-an-inline-empty {
  margin-top: var(--s2);
}
.frm-an-state {
  margin: var(--s8) auto;
  max-width: 460px;
}
.frm-an-error .frm-empty-icon {
  background: color-mix(in srgb, var(--red) 14%, transparent);
  color: var(--red);
}
.frm-an-error .frm-empty-title {
  color: var(--red);
}
.frm-an-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  color: var(--text2);
  padding: var(--s8) var(--s4);
}
.frm-an-loading-ico {
  display: inline-flex;
  color: var(--accent);
  animation: frm-an-spin 0.9s linear infinite;
}
.frm-an-loading-ico .frm-ico {
  width: 18px;
  height: 18px;
}
@keyframes frm-an-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── narrow screens ── */
@media (max-width: 760px) {
  .frm-an {
    padding: var(--s4);
    gap: var(--s4);
  }
  .frm-an-head {
    gap: var(--s3);
  }
  .frm-an-funnel {
    flex-direction: column;
  }
  .frm-an-funnel-arrow {
    transform: rotate(90deg);
  }
  .frm-an-qtitle {
    max-width: 190px;
  }
  .frm-an-dropcol {
    width: auto;
  }
  .frm-an-dropbar {
    display: none;
  }
}
@media (max-width: 640px) {
  .frm-an-tabs {
    flex: 1 1 100%;
  }
  .frm-an-tab {
    flex: 1 1 0;
    justify-content: center;
  }
  .frm-an-rangebar {
    flex: 1 1 100%;
  }
  select.frm-select.frm-an-rangesel {
    flex: 1 1 auto;
  }
}
