/**
 * Group page — header/avatar, lean roster table, and the billing tab
 * (fee/issue toolbar + student × month payment matrix).
 * Desktop = table (.hidden-mobile); mobile = cards (.hidden-desktop).
 * Reuses design tokens from 00-tokens.css.
 */

/* ---------- Group page header + avatar ---------- */
.group-page__header {
  display: flex; align-items: center; gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.group-page__title {
  display: flex; align-items: baseline; gap: var(--space-2); margin: 0;
}
.group-page__id {
  font-size: var(--font-size-sm); font-weight: var(--font-weight-normal);
  color: var(--color-muted-foreground); font-variant-numeric: tabular-nums;
}

.group-avatar { flex: none; display: inline-flex; }
.group-avatar__img,
.group-avatar__placeholder {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  object-fit: cover; background: var(--color-muted);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-muted-foreground); font-size: 1rem;
}
.group-avatar--lg .group-avatar__img,
.group-avatar--lg .group-avatar__placeholder {
  width: 64px; height: 64px; font-size: 1.5rem;
}
.group-avatar--edit { margin: 0; }
.group-avatar__label {
  position: relative; display: block; cursor: pointer; line-height: 0;
}
.group-avatar__input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.group-avatar__edit {
  position: absolute; right: -2px; bottom: -2px;
  width: 22px; height: 22px; border-radius: var(--radius-full);
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; border: 2px solid var(--color-card);
}

/* ---------- Lean roster table ---------- */
.roster-photo-col { width: 56px; }
.roster-avatar {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  object-fit: cover; background: var(--color-muted); display: block;
}

/* ---------- Billing tab ---------- */
.bill { display: flex; flex-direction: column; gap: var(--space-4); }

/* Fee + issue toolbar — one padded card; the fee block and issue block sit side
   by side on desktop (split by a hairline) and stack on mobile. No gray sub-box. */
.bill-toolbar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-5); align-items: stretch;
  padding: var(--space-4);
}
.bill-toolbar__fee { min-width: 0; }
.bill-toolbar__head {
  display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap; margin-bottom: var(--space-1);
}
.bill-toolbar__label {
  font-size: var(--font-size-xs); font-weight: var(--font-weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-muted-foreground);
}
.bill-chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.bill-chips .badge { font-variant-numeric: tabular-nums; }
.bill-help {
  font-size: var(--font-size-xs); color: var(--color-muted-foreground);
  margin: var(--space-1) 0 0;
}

.bill-fee-edit { margin-top: var(--space-1); }
.bill-fee-summary {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--font-size-sm); color: var(--color-link);
  cursor: pointer; list-style: none; padding: var(--space-1) 0;
}
.bill-fee-summary::-webkit-details-marker { display: none; }
.bill-fee-edit[open] .bill-fee-summary { color: var(--color-foreground); }
/* Inline fee editor: outlined (not gray-filled) so it doesn't read as a box-in-box. */
.bill-fee-form {
  margin-top: var(--space-2); padding: var(--space-3);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
}
.bill-fee-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--space-2); margin: var(--space-2) 0;
}
.bill-fee-field { display: flex; flex-direction: column; gap: 2px; }
.bill-fee-cur {
  font-size: var(--font-size-xs); font-weight: var(--font-weight-medium);
  color: var(--color-muted-foreground);
}

.bill-issue {
  display: flex; flex-direction: column; gap: var(--space-2);
}
.bill-issue__label {
  font-size: var(--font-size-xs); font-weight: var(--font-weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-muted-foreground);
}
.bill-issue__row { display: flex; gap: var(--space-2); align-items: center; }
.bill-issue__row .input { width: auto; }
/* Desktop: split the fee and issue halves with a hairline, not a gray box. */
@media (min-width: 768px) {
  .bill-issue {
    padding-left: var(--space-5); border-left: 1px solid var(--color-border);
  }
}

/* Overview card (matrix) — padded white card; flat sections split by hairlines. */
.bill-overview { padding: var(--space-4); }
.bill-section-title {
  font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold);
  margin: 0 0 var(--space-3);
}

/* Current-month summary strip — month label + paid / unpaid / not-issued counts.
   The coloured counts double as the legend, so no separate dots row is needed.
   Split from the roster below by a hairline (no gray fill). */
.bill-monthbar {
  display: flex; align-items: baseline; gap: var(--space-2) var(--space-4);
  flex-wrap: wrap; padding-bottom: var(--space-3); margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.bill-monthbar__title {
  font-weight: var(--font-weight-semibold); text-transform: capitalize;
}
.bill-monthbar__kpis { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.bill-kpi {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--font-size-sm); color: var(--color-muted-foreground);
}
.bill-kpi b { font-variant-numeric: tabular-nums; color: var(--color-foreground); }
.bill-kpi--paid b { color: var(--ctp-green); }
.bill-kpi--unpaid b { color: var(--ctp-red); }

/* Payment pills (shared by table + cards) */
.bill-pays { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.bill-act { margin: 0; display: inline-flex; }
.bill-pill {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 4px; min-width: 2.25rem; padding: 3px 10px;
  font-size: var(--font-size-xs); font-weight: var(--font-weight-medium);
  font-variant-numeric: tabular-nums; line-height: 1.4;
  border-radius: var(--radius-full); cursor: pointer; white-space: nowrap;
  border: 1px solid transparent; transition: all var(--transition-fast);
}
.bill-pill--pay {
  color: var(--ctp-red);
  background: color-mix(in srgb, var(--ctp-red) 8%, transparent);
  border-color: color-mix(in srgb, var(--ctp-red) 30%, transparent);
}
.bill-pill--pay:hover {
  color: #fff; background: var(--ctp-green); border-color: var(--ctp-green);
}
.bill-pill--paid {
  color: var(--ctp-green);
  background: color-mix(in srgb, var(--ctp-green) 14%, transparent);
  border-color: color-mix(in srgb, var(--ctp-green) 30%, transparent);
}
.bill-pill--paid:hover {
  color: var(--ctp-red);
  background: color-mix(in srgb, var(--ctp-red) 10%, transparent);
  border-color: color-mix(in srgb, var(--ctp-red) 30%, transparent);
}
.bill-empty { color: var(--color-border-strong); user-select: none; }

/* ---------- Desktop matrix table ---------- */
.bill-table-wrap { overflow-x: auto; }
.bill-table { width: 100%; border-collapse: collapse; }
.bill-table th, .bill-table td { padding: var(--space-2) var(--space-3); }
.bill-th-student { text-align: left; }
.bill-th-month {
  text-align: center; font-variant-numeric: tabular-nums;
  white-space: nowrap; font-size: var(--font-size-xs); text-transform: capitalize;
}
.bill-th-month--current { color: var(--color-foreground); font-weight: var(--font-weight-semibold); }
.bill-student {
  position: sticky; left: 0; z-index: 1; background: var(--color-card);
  font-weight: var(--font-weight-medium); white-space: nowrap;
}
.bill-cell { text-align: center; vertical-align: middle; }
.bill-cell--current, .bill-th-month--current {
  background: color-mix(in srgb, var(--color-primary) 4%, transparent);
}
.bill-table tbody tr:hover .bill-student,
.bill-table tbody tr:hover .bill-cell {
  background: var(--color-muted);
}

/* ---------- Mobile list (current month = hero) ----------
   Flat rows split by hairlines (no nested cards) so the matrix reads as one
   clean list inside the overview card instead of boxes-in-a-box. The current
   month sits at the right of the name row; charged earlier months trail below
   as compact inline pairs (empty months are omitted, not shown as dashes). */
.bill-cards { flex-direction: column; gap: 0; }
@media (max-width: 767px) { .bill-cards { display: flex; } }
.bill-card { padding: var(--space-3) 0; border-top: 1px solid var(--color-border); }
.bill-card:first-child { padding-top: var(--space-1); border-top: none; }
.bill-card:last-child { padding-bottom: 0; }
.bill-card__top {
  display: flex; align-items: center; gap: var(--space-3);
  justify-content: space-between;
}
.bill-card__name {
  font-weight: var(--font-weight-medium); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bill-card__current {
  flex: none; display: flex; flex-direction: column;
  align-items: flex-end; gap: 4px;
}
.bill-card__cur-month {
  align-self: flex-end;
  padding: 1px 8px; border-radius: var(--radius-full);
  font-size: var(--font-size-xs); font-weight: var(--font-weight-bold);
  text-transform: capitalize; letter-spacing: 0.02em;
  color: var(--color-primary); font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}
.bill-card__history {
  display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4);
  margin-top: var(--space-2);
}
.bill-card__hmonth { display: inline-flex; align-items: center; gap: var(--space-1); }
.bill-card__hlabel {
  font-size: var(--font-size-xs); color: var(--color-muted-foreground);
  text-transform: capitalize; font-variant-numeric: tabular-nums;
}

/* Stack the toolbar on mobile (grid → single column); fee and issue split by a
   hairline instead of a gray box. */
@media (max-width: 767px) {
  .bill-toolbar { grid-template-columns: 1fr; gap: var(--space-3); }
  .bill-issue { padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
  .bill-issue__row .input { flex: 1; }
}

/* ======================================================================
   Merged roster + payments (one student per row)
   ====================================================================== */

/* ---------- Group registration-link toolbar ---------- */
.group-toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ---------- Paid pill: checkmark + amount ---------- */
.bill-pill--paid .bill-pill__amt { font-variant-numeric: tabular-nums; }
.bill-pill--paid:hover .fa-check { display: none; }

/* ---------- Desktop roster table ---------- */
.bill-roster-table { width: 100%; border-collapse: collapse; }
.bill-roster-table thead th {
  padding: var(--space-2) var(--space-3);
  text-align: left; vertical-align: bottom;
  font-size: var(--font-size-xs); font-weight: var(--font-weight-semibold);
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-muted-foreground);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.bill-roster-table tbody td {
  padding: var(--space-2) var(--space-3);
  vertical-align: middle;
  border-bottom: 1px solid var(--color-border);
}
.bill-roster-table tbody tr:last-child td { border-bottom: none; }
.bill-roster-table tbody tr { transition: background var(--transition-fast); }
.bill-roster-table tbody tr:hover { background: var(--color-muted); }

.roster-select-col { width: 36px; text-align: center; }
.roster-select-col .roster-select {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--color-primary);
}
.bill-roster-table .roster-photo-col { width: 52px; }
.bill-roster-table .main-column { width: auto; }
.bill-roster-table .main-column .internal-link { font-weight: var(--font-weight-medium); }
.roster-course {
  color: var(--color-muted-foreground); font-size: var(--font-size-sm);
  white-space: nowrap;
}
/* Current-month cell — soft tinted focus column. */
.bill-roster-table .bill-cell--current {
  text-align: center;
  background: color-mix(in srgb, var(--color-primary) 4%, transparent);
}
.bill-roster-table thead th:nth-child(5) { text-align: center; }
.roster-actions { text-align: right; white-space: nowrap; }
.roster-actions .cluster,
.roster-actions > * { justify-content: flex-end; }
.roster-row--unconfirmed {
  background: color-mix(in srgb, var(--ctp-red) 4%, transparent);
}

/* ---------- Month-history disclosure (desktop + mobile) ---------- */
.bill-history-col { width: 1%; }
.bill-history { position: relative; display: inline-block; }
.bill-history__summary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; cursor: pointer; list-style: none;
  font-size: var(--font-size-xs); font-weight: var(--font-weight-medium);
  color: var(--color-muted-foreground);
  border: 1px solid var(--color-border); border-radius: var(--radius-full);
  white-space: nowrap; transition: all var(--transition-fast);
}
.bill-history__summary::-webkit-details-marker { display: none; }
.bill-history__summary:hover {
  color: var(--color-foreground); border-color: var(--color-border-strong);
  background: var(--color-muted);
}
.bill-history[open] .bill-history__summary {
  color: var(--color-foreground); border-color: var(--color-border-strong);
}
.bill-history__badge {
  min-width: 1.1rem; padding: 0 5px; font-size: 0.65rem; line-height: 1.3rem;
  font-variant-numeric: tabular-nums;
}
/* Expanded panel floats over the layout instead of reflowing the row. */
.bill-history__list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: var(--z-dropdown);
  min-width: 260px; padding: var(--space-2);
  display: flex; flex-direction: column; gap: 2px;
  background: var(--color-card); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.bill-history__row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
}
.bill-history__row + .bill-history__row { border-top: 1px solid var(--color-border); }
.bill-history__row:hover { background: var(--color-muted); }
.bill-history__label {
  font-size: var(--font-size-sm); font-weight: var(--font-weight-medium);
  color: var(--color-foreground);
  text-transform: capitalize; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bill-history__cell { flex: none; }
.bill-history__cell .bill-pays { flex-wrap: nowrap; }

/* ---------- Mobile roster cards (rebuilt for the merged view) ---------- */
.bill-card__id { min-width: 0; flex: 1; }
.bill-card__course {
  font-size: var(--font-size-xs); color: var(--color-muted-foreground);
  margin-top: 1px;
}
.bill-card__chips { margin-top: var(--space-1); }
.bill-card--unconfirmed { background: color-mix(in srgb, var(--ctp-red) 3%, transparent); }
.bill-card__actions {
  display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2);
}
.bill-card__actions .cluster { display: flex; flex-wrap: wrap; gap: var(--space-2); }
/* On mobile the history panel is centered + wider for thumb reach. */
@media (max-width: 767px) {
  .bill-card .bill-history { margin-top: var(--space-2); display: block; }
  .bill-card .bill-history__summary { width: 100%; justify-content: center; }
  .bill-card .bill-history__list { left: 0; right: 0; }
}
