/* The selectable fee list on a phone - see Views/Shared/_FeeProgramTable.cshtml
   (the table these rules style), Views/Shared/_FeeSelection.cshtml and
   Views/DistrictFees/Index.cshtml (the two pages that render it), and
   wwwroot/js/fee-selection.js.
 *
 * .fee-cards IS APPLIED BY THE SHARED PARTIAL, not by the pages. It used to be
 * hand-written on each table, and District Fees simply never got it: for four
 * days from 2026-09-17 that page kept the sideways scroll these rules exist to
 * replace, six boxes of it on one screen. Adding the class to a new table is
 * not a step anyone should have to remember - render _FeeProgramTable instead.
 *
 * WHY THIS IS NOT app-grid.css's job. The fee list is deliberately not an
 * <app-grid> (every row is an input in one form, and the totals, the allowed
 * methods and the Pay button are fee-selection.js's), so it cannot inherit the
 * .app-grid-cards rules. The layout below is deliberately the SAME SHAPE as
 * those, because the two should read as one system on a phone: the header is
 * clipped rather than hidden, each row becomes a bordered card, and each cell
 * carries its own heading from a data-label. If you change one, look at the
 * other.
 *
 * WHAT IT REPLACED, because "it scrolls sideways" sounds survivable and was
 * not: at 375px the fee table was 376px of content in a 295px box. The 81px
 * behind the swipe were Status and Paperwork - whether you still owe the fee,
 * and whether a purchase order is already on file for it. The two facts a
 * coach opens this screen to find were the two you could not see, and with
 * three tables on the page there were three separate scroll regions that did
 * not move together. */

@media (max-width: 767.98px) {

  /* Clipped, not display:none - a display:none header leaves the accessibility
     tree, and the cells below still reference it. Same treatment as
     .app-grid-cards thead. */
  .fee-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .fee-cards,
  .fee-cards tbody,
  .fee-cards td {
    display: block;
    width: auto;
  }

  /* THE ROW IS A FLEX CONTAINER rather than a stack of blocks, so the tick and
     the fee name can sit together on the card's first line while everything
     else takes a full line of its own. A checkbox on a line by itself, above
     the thing it selects, reads as a fourth field rather than as the control
     that picks this fee. */
  .fee-cards tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.625rem;
    border: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    background-color: var(--bs-body-bg);
  }

  .fee-cards td {
    padding: 0.1875rem 0;
    border: 0;
    /* Alignment is a column idea. Down a card, everything reads left. */
    text-align: left !important;
  }

  /* Line one: the tick, then the fee name as the card's title.
     A FIXED BASIS, not auto, and it is what lines the titles up. An unpayable
     fee (paid, cancelled, locked into a batch) renders no checkbox, so an
     auto-width cell collapses and that card's title starts ~26px left of every
     payable one - a ragged column of headings down the page. Border-box, so
     the basis covers the padding and the cell is the same 26px whether it
     holds a checkbox or nothing. */
  .fee-cards td[data-fee-cell="select"] {
    flex: 0 0 1.625rem;
    padding-right: 0.625rem;
  }

  .fee-cards td[data-fee-cell="name"] {
    flex: 1 1 auto;
    font-weight: 600;
    /* The desktop table indents this under the team header; down a card there
       is nothing to indent away from. */
    padding-left: 0 !important;
  }

  /* Every labelled cell takes its own full line: heading left, value right. */
  .fee-cards td[data-label] {
    flex: 1 0 100%;
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    justify-content: space-between;
  }

  .fee-cards td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
  }

  /* The paperwork cell - the PO line and the Invoice/Quote buttons - spans the
     card under a rule, so the buttons read as the end of the card rather than
     as another field. Matches .app-grid-cards td:not([data-label]). */
  .fee-cards td[data-fee-cell="docs"] {
    flex: 1 0 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
    padding-top: 0.625rem;
    border-top: var(--bs-border-width) solid var(--bs-border-color);
  }

  /* A fee with no PO and no documents would otherwise render as a lone
     horizontal rule at the bottom of the card. */
  .fee-cards td[data-fee-cell="docs"]:empty {
    display: none;
  }

  /* THE TEAM HEADER stays a header and does not become a card: it is the thing
     the cards below belong to. Full width, no border, and the payment-type
     control drops onto its own line - inline with ms-3 the <select> is the
     widest thing in the row and went off the right edge. */
  /* The team row is a flex line like a fee card's first line (2026-10-18): its
     box in the tree sits beside the team's name, in the same fixed select cell,
     rather than on a line of its own above it. */
  .fee-cards tr.fee-team-row {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.25rem 0.25rem;
    margin-bottom: 0.375rem;
    border: 0;
    border-radius: 0;
    background-color: transparent;
  }

  .fee-cards tr.fee-team-row td:empty {
    display: none;
  }

  /* ...but the select cell stays, empty or not, so team names line up with
     the fee names under them whether or not the team has a box. */
  .fee-cards tr.fee-team-row td[data-fee-cell="select"] {
    display: block;
  }

  /* The name takes the rest of the line and wraps inside it; at its own
     width, a long team name wrapped the whole cell under the box. */
  .fee-cards tr.fee-team-row td:not([data-fee-cell]) {
    flex: 1 1 0;
    min-width: 0;
  }

  .fee-cards .fee-team-paytype {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.375rem;
  }

  /* The label's desktop spacing, undone: it is no longer trailing the team
     name on one line. */
  .fee-cards .fee-team-paytype > .ms-3 {
    margin-left: 0 !important;
  }

  .fee-cards .fee-team-paytype select {
    margin-left: 0 !important;
    /* Fills the line rather than sitting at its content width, which on the
       longest option ("Purchase Order") was near enough the full width anyway
       and on the shortest looked like a mistake. */
    flex: 1 1 auto;
    width: auto !important;
  }

  /* The pay bar wraps to three lines on a phone; without this its own padding
     makes it taller than it needs to be under the cards.

     MEASURED 2026-09-21 AND IT IS A NO-OP - left in place, and here is why it
     is not worth either fixing or believing. The element it targets carries
     Bootstrap's .gap-3, which sets row-gap: 1rem !IMPORTANT and wins; computed
     row-gap on the District Fees pay bar at 375px is 14px (1rem at this app's
     14px root), not the 10px below. The second selector is dead for a
     different reason: .fee-cards is the <table>, and the pay bar's previous
     sibling is the .table-responsive wrapping it, never the table itself.
     Both have been inert since the wrapper arrived on 2026-09-16, which means
     the pay bar that shipped and was signed off at 375px on 2026-09-17 is the
     one WITHOUT this rule. Adding !important now would change a verified
     screen for no reported problem. */
  .fee-cards + .card .card-body,
  [data-fee-selection] .sticky-bottom .card-body {
    row-gap: 0.625rem;
  }
}
