/* Commission Due (HR) view — js/views/commission.js.
   Full-sales-force commission REPORT: every RSA's commission earned for the pay
   period, sorted highest first, terminated flagged with trailing-payout detail.
   PAYOUT-GRADE COMPENSATION PII: the nav item + dataset are gated to
   admin/executive/hr in view-policy.js and api data.js — change the two
   together. Reuses the portal design tokens and mirrors the RSA Bonus view's
   card / table treatment.
   REFRAME 2026-07-23c: was a departed-payout pay list, now the whole sales
   force. Four cards, a status filter (All/Active/Terminated/Unknown) over one
   sortable scroll-capped table, status badges + row tints, terminated-only
   trailing columns.
   TWO BASES 2026-07-23d: a Delivered / Written basis toggle re-points the whole
   view. Written (net written) reconciles to the STORIS written report on
   merchandise + protection and carries a short plain note; Delivered is the
   payout basis and carries a green "matches STORIS" pill.
   TIES TO STORIS 2026-07-24: each basis now carries six components; Furniture /
   Bedding / Protection / Delivery show in a period-level breakdown strip that
   sums to the headline, and per-row behind a "Show breakdown" toggle. */

.cm-empty {
  padding: 40px; text-align: center; color: var(--text-caption, #6b7280);
  font-family: var(--font-stack); font-size: 14px;
}

/* ── Summary cards ── */
.cm-cards {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin: 0 0 16px;
}
.cm-card {
  background: #fff; border: 1px solid var(--table-border, #d9dfe8);
  border-top: 3px solid var(--ashley-orange, #e87722);
  border-radius: var(--radius, 8px); padding: 12px 16px;
  box-shadow: var(--shadow, 0 1px 2px rgba(0,0,0,.05));
}
/* Headline card (commission earned this period) gets the navy accent. */
.cm-card.cm-card-headline { border-top-color: var(--navy, #1b2a4a); border-top-width: 4px; }
.cm-card-v {
  font-size: 24px; font-weight: 800; color: var(--navy, #1b2a4a);
  font-family: var(--font-stack); line-height: 1.1; white-space: nowrap;
}
.cm-card-l {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-caption, #6b7280); margin-top: 4px; font-weight: 600;
}
.cm-card-s { font-size: 11px; color: var(--text-caption, #6b7280); margin-top: 2px; }

/* ── Controls (period selector + search + CSV export) ── */
.cm-controls {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--table-border, #d9dfe8);
  border-radius: var(--radius, 8px); padding: 10px 14px; margin: 0 0 12px;
}
/* Pay-period selector. */
.cm-period-lbl {
  font-family: var(--font-stack); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-caption, #6b7280); display: inline-flex; align-items: center; gap: 6px;
}
.cm-period-select {
  padding: 6px 10px; font-size: 12px; font-family: var(--font-stack);
  border: 1px solid var(--table-border, #d9dfe8); border-radius: 6px;
  background: #fff; color: var(--navy, #1b2a4a); font-weight: 700;
  text-transform: none; letter-spacing: normal;
}
/* Calendar-provenance note beside the selector; full text is the tooltip
   (and repeated in the footer). The calendar is confirmed against the
   production commission system, so this is reassurance, not a warning. */
.cm-cal-note {
  font-family: var(--font-stack); font-size: 11px; font-weight: 600;
  color: #1e7a3c; background: #eaf7ee; border: 1px solid #b7e0c4;
  border-radius: 999px; padding: 3px 10px; cursor: help; white-space: nowrap;
}
.cm-search {
  padding: 6px 10px; font-size: 12px; font-family: var(--font-stack);
  border: 1px solid var(--table-border, #d9dfe8); border-radius: 6px;
  background: #fff; color: var(--navy, #1b2a4a); font-weight: 600;
  min-width: 170px; flex: 1;
}
/* Basis toggle (Delivered / Written) label. */
.cm-basis-lbl {
  font-family: var(--font-stack); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-caption, #6b7280);
}
/* Delivered is the validated basis: green confidence pill. */
.cm-tie-note {
  font-family: var(--font-stack); font-size: 11px; font-weight: 700;
  color: #1e7a3c; background: #eaf7ee; border: 1px solid #b7e0c4;
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
/* Amber reference note shown only when Written is the active basis, so its
   smaller (net) number is never mistaken for the payout basis or a bug. */
.cm-basis-note {
  background: #fff8ec; border: 1px solid #f0d39a; border-left: 4px solid #d9922b;
  border-radius: var(--radius, 8px); padding: 9px 14px; margin: 0 0 14px;
  font-family: var(--font-stack); font-size: 12.5px; line-height: 1.5;
  color: #7a5510;
}
.cm-basis-note strong { color: #6a4708; }

/* ── Component breakdown strip ──
   The four things commission is made of (Furniture / Bedding / Protection /
   Delivery) at period level; they sum to the headline card. Protection and the
   delivery charge are why the figure moved up 32.7%, so they are visible by
   default rather than hidden behind the per-row toggle. */
.cm-strip {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--table-border, #d9dfe8);
  border-radius: var(--radius, 8px); padding: 9px 14px; margin: 0 0 14px;
  font-family: var(--font-stack);
}
.cm-strip-l {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-caption, #6b7280);
}
.cm-part { display: inline-flex; align-items: baseline; gap: 6px; }
.cm-part-l { font-size: 11.5px; color: var(--text-caption, #6b7280); font-weight: 600; }
.cm-part-v { font-size: 13.5px; font-weight: 700; color: var(--navy, #1b2a4a); }
.cm-part-sum { margin-left: auto; padding-left: 18px; border-left: 1px solid var(--table-border, #d9dfe8); }
.cm-part-sum .cm-part-l { text-transform: uppercase; letter-spacing: 0.4px; font-size: 11px; }

/* Trailing-payout caveat (it excludes the delivery charge, ~7% low). */
.cm-trail-note {
  background: #fff8ec; border: 1px solid #f0d39a; border-left: 4px solid #d9922b;
  border-radius: var(--radius, 8px); padding: 8px 12px; margin: 0 0 10px;
  font-family: var(--font-stack); font-size: 12px; line-height: 1.5; color: #7a5510;
}

/* ── Status filter (All / Active / Terminated / Unknown) ── */
.cm-filter {
  display: flex; align-items: center; gap: 10px; margin: 0 0 4px;
  font-family: var(--font-stack);
}
/* "Show breakdown" toggle: adds the four component columns to the table. */
.cm-toggle-btn {
  margin-left: auto; cursor: pointer;
  font-family: var(--font-stack); font-size: 12px; font-weight: 700;
  color: var(--text-caption, #6b7280); background: #fff;
  border: 1px solid var(--table-border, #d9dfe8); border-radius: 7px;
  padding: 6px 12px; white-space: nowrap;
}
.cm-toggle-btn.active { background: var(--navy, #1b2a4a); color: #fff; border-color: var(--navy, #1b2a4a); }
.cm-filter-lbl {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-caption, #6b7280);
}
.cm-seg {
  display: inline-flex; border: 1px solid var(--table-border, #d9dfe8);
  border-radius: 7px; overflow: hidden; background: #eef1f6;
}
.cm-seg-btn {
  border: none; background: transparent; cursor: pointer;
  font-family: var(--font-stack); font-size: 12px; font-weight: 700;
  color: var(--text-caption, #6b7280); padding: 6px 14px; white-space: nowrap;
}
.cm-seg-btn + .cm-seg-btn { border-left: 1px solid var(--table-border, #d9dfe8); }
.cm-seg-btn.active { background: var(--navy, #1b2a4a); color: #fff; }
.cm-seg-n {
  display: inline-block; margin-left: 4px; font-weight: 800; opacity: 0.75;
}

/* ── Filtered count line ── */
.cm-count {
  font-size: 12.5px; color: var(--text-caption, #6b7280);
  font-family: var(--font-stack); margin: 10px 2px 8px;
}
.cm-count strong { color: var(--navy, #1b2a4a); }

/* ── Table ── */
.cm-table-wrap {
  background: #fff; border: 1px solid var(--table-border, #d9dfe8);
  border-radius: 8px; overflow-x: auto;
}
/* ~300 rows/period: cap the height and scroll, sticky header stays put. */
.cm-scroll { max-height: 620px; overflow-y: auto; }
.cm-table { border-collapse: collapse; width: 100%; font-size: 13px; font-family: var(--font-stack); }
.cm-table th {
  background: var(--navy, #1b2a4a); color: #fff; text-align: left;
  padding: 7px 10px; position: sticky; top: 0; z-index: 1; cursor: pointer;
  white-space: nowrap; user-select: none; font-weight: 600;
}
.cm-table td {
  padding: 6px 10px; border-bottom: 1px solid #eef1f6; white-space: nowrap;
  color: var(--text-body, #1f2937);
}
.cm-table tbody tr:hover td { background: #f6f8fc; }
.cm-table td.cm-num, .cm-table th.cm-num { text-align: right; }
.cm-none { padding: 30px; text-align: center; color: #6b7280; }

/* Commission Earned column emphasized. */
.cm-table td.cm-headline-cell { font-weight: 700; color: var(--navy, #1b2a4a); }
/* Eligibility that needs review (terminated rows). */
.cm-table td.cm-flag { background: #fff3cd; color: #7a5b00; font-weight: 700; }

/* Commission we could not compute: NEVER a fake $0. Reads as a problem. */
.cm-table td.cm-cant {
  color: #b3261e; font-weight: 700; background: #fdecea; text-align: right;
}
/* Negative money (net-written returns can net a rep below zero). */
.cm-table td.cm-neg { color: #b3261e; }

/* ── Status badges + row tints ──
   Terminated is the flagged slice that still carries the payout detail; Unknown
   is house / system codes + unmapped reps, surfaced not hidden. */
.cm-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 1px 8px; border-radius: 999px; white-space: nowrap;
}
.cm-badge.cm-st-active { background: #eaf7ee; color: #1e7a3c; border: 1px solid #b7e0c4; }
.cm-badge.cm-st-term { background: #fdecea; color: #b3261e; border: 1px solid #f0c4bf; }
.cm-badge.cm-st-unknown { background: #fff3e0; color: #92600a; border: 1px solid #f0d39a; }
.cm-table tr.cm-row-term td { background: #fdf5f4; }
.cm-table tr.cm-row-term:hover td { background: #fbe9e7; }
.cm-table tr.cm-row-unknown td { background: #fffaf1; }
.cm-table tr.cm-row-unknown:hover td { background: #fdf1de; }

/* TOTAL row: sums the rendered rows (ties the headline card at the default view). */
.cm-table tr.cm-total td {
  background: var(--navy, #1b2a4a); color: #fff; font-weight: 800;
  border-bottom: none;
}
.cm-table tr.cm-total:hover td { background: var(--navy, #1b2a4a); }

/* ── Footnote (methodology) ── */
.cm-foot {
  color: var(--text-caption, #6b7280); font-size: 12px;
  font-family: var(--font-stack); margin-top: 14px; line-height: 1.5;
}
.cm-method summary {
  cursor: pointer; font-weight: 700; color: var(--navy, #1b2a4a);
  padding: 6px 0;
}
.cm-method ul { margin: 4px 0 8px 18px; padding: 0; }
.cm-method li { margin: 2px 0; line-height: 1.5; }
.cm-how { line-height: 1.5; margin-bottom: 4px; }
.cm-prov-note { line-height: 1.5; margin-bottom: 4px; font-size: 11.5px; }
.cm-stamp { margin-top: 6px; font-size: 11.5px; }

@media (max-width: 1100px) {
  .cm-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .cm-cards { grid-template-columns: 1fr; }
}
