/* ============================================================
   Affiliate Raccoon — MOBILE styles
   ------------------------------------------------------------
   Drop-in stylesheet. Load it AFTER app.css:
       <link rel="stylesheet" href="app.css">
       <link rel="stylesheet" href="mobile.css">

   Phone breakpoint: 700px. Everything here is wrapped in a
   media query, so it has ZERO effect on desktop.

   ⚠ ONE markup requirement (manager table → cards):
   the manager table <td> cells need data-label attributes, and
   the first/last cells need helper classes. See the note at the
   very bottom of this file for the exact markup.
   ============================================================ */

@media (max-width: 700px) {

  /* ---------- Top bar ---------- */
  .topbar-inner { padding: 12px 16px; gap: 10px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand-name { font-size: 15px; }
  .brand-sub { display: none; }                 /* save width */
  .role-chip { display: none; }                 /* role is obvious from the page */
  .topbar-actions { gap: 2px; }
  .topbar-actions .btn--text { padding: 8px 9px; font-size: 13px; }

  /* ---------- Page canvas ---------- */
  .page { padding: 22px 16px 72px; }
  .page--narrow { max-width: 100%; }
  .page-title { font-size: 21px; }

  /* Manager page head: stack the title and make "Add affiliate" full-width.
     (uses !important only to beat the inline align-items on this element) */
  .page-head.flex { flex-direction: column; align-items: stretch !important; gap: 14px; }
  .page-head.flex > .btn { width: 100%; justify-content: center; padding: 12px; }

  /* ---------- KPI strip → single column ---------- */
  .kpis { grid-template-columns: 1fr; }
  .kpi { border-left: 0 !important; border-top: 1px solid var(--line); padding: 18px 18px; }
  .kpi:first-child { border-top: 0; }
  .kpi--hero .kpi-value { font-size: 42px; }
  .kpi-value { font-size: 26px; }

  /* ---------- Panel head + period picker ---------- */
  .panel-head { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
  .panel-head .spacer { display: none; }
  .periodbar { width: 100%; }
  .period-selects { flex: 1 1 auto; }
  .period-sel { flex: 1; }

  /* ============================================================
     Manager affiliates table  →  stacked cards
     Each row becomes a bordered card; each cell shows its
     column name (from data-label) on the left, value on right.
     ============================================================ */
  .tablewrap { overflow-x: visible; }
  table.grid { min-width: 0; }
  .grid thead { display: none; }
  .grid, .grid tbody { display: block; }

  .grid tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 2px 16px;
    margin-bottom: 12px;
    background: var(--paper);
  }
  .grid tbody tr:last-child { margin-bottom: 0; }
  .grid tbody tr:hover { background: var(--paper); }   /* no hover fill on touch */

  .grid tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 11px 0; border-bottom: 1px solid var(--line);
    text-align: right; font-size: 14px; white-space: normal;
  }
  .grid tbody td:last-child { border-bottom: 0; }
  .grid tbody td::before {
    content: attr(data-label);
    font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--faint); font-weight: 600; text-align: left; white-space: nowrap;
  }
  .grid .num-col { text-align: right; }

  /* card header: the affiliate name (no label) */
  .grid tbody td.td-name { display: block; padding: 14px 0 12px; text-align: left; }
  .grid tbody td.td-name::before { display: none; }
  .grid tbody td.td-name .cell-name { white-space: normal; font-size: 15.5px; }

  /* card footer: the invoice button, full width */
  .grid tbody td.td-invoice { display: block; padding: 8px 0 14px; }
  .grid tbody td.td-invoice::before { display: none; }
  .grid tbody td.td-invoice .btn-inv { width: 100%; justify-content: center; padding: 12px; font-size: 13.5px; }
  .grid tbody td.td-invoice .muted-act,
  .grid tbody td.td-invoice .cell-dash { display: block; text-align: center; padding: 4px 0; }

  /* ---------- Unattributed redemptions ---------- */
  .quiet { padding: 16px; }
  .quiet-head { flex-wrap: wrap; row-gap: 4px; }
  .quiet-row { flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px 0; }
  .quiet-amt { flex-direction: row; align-items: baseline; gap: 8px; }

  /* ============================================================
     Affiliate portal
     ============================================================ */
  /* code + commission blocks stack to one column */
  .codeblocks { grid-template-columns: 1fr; }
  .codeblock { padding: 24px 20px; }
  .codeval { font-size: 32px; }

  /* the three numbers stack to one column */
  .statrow { grid-template-columns: 1fr; }
  .statrow .stat { border-left: 0; border-top: 1px solid var(--line); }
  .statrow .stat:first-child { border-top: 0; }

  /* invoice list rows: period on the left, amount over button on the right */
  .invrow {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 4px 14px;
    padding: 14px 16px;
  }
  .invrow > :nth-child(1) { grid-row: 1 / 3; }      /* period block spans both rows */
  .invrow > .inv-amt { grid-column: 2; grid-row: 1; text-align: right; }
  .invrow > .right   { grid-column: 2; grid-row: 2; }
  .invrow .btn-inv--lg { padding: 8px 16px; }

  /* ============================================================
     Modals → full-screen sheets
     ============================================================ */
  /* open scrim is a plain block on mobile so the modal grows with its
     content (flex stretch was forcing modal height = viewport, which let
     the page bleed through below tall forms) */
  .scrim.is-open { display: block; padding: 0; }
  .modal, .modal--wide, .docmodal {
    max-width: 100%; width: 100%; min-height: 100vh;
    border-radius: 0;
    background: var(--paper);
  }
  .modal-head { padding: 20px 18px 16px; }
  .modal-head h2 { font-size: 17px; }
  .modal-body { padding: 20px 18px; }
  .modal-foot { padding: 14px 18px; position: sticky; bottom: 0; }
  .field-row, .field-row--3 { grid-template-columns: 1fr; }

  /* the affiliate is reachable from their row; drop the footer invoice
     link on phones so the foot is just Cancel / Save changes */
  #edit-invoice { display: none !important; }

  /* invoice document sheet */
  .sheet { padding: 26px 18px; }
  .sheet-top { flex-direction: column; gap: 14px; }
  .doc-issuer { text-align: left; }
  .doc-meta { grid-template-columns: 1fr; gap: 18px; }
  .doc-numrow { flex-wrap: wrap; gap: 16px 28px; }
  .doc-totals { width: 100%; }
  .btn-generate { font-size: 15px; padding: 18px; }
}

/* ============================================================
   MARKUP NOTE for the manager table (required for the cards)
   ------------------------------------------------------------
   In the row template, label every cell with the column name and
   tag the first + invoice cells, e.g.:

     <tr data-id="...">
       <td class="td-name"> …name + firm… </td>
       <td data-label="Code"> …code chip… </td>
       <td data-label="Rate"> …rate… </td>
       <td data-label="Type"> …type… </td>
       <td class="num-col" data-label="Customers"> … </td>
       <td class="num-col" data-label="Net maintained"> … </td>
       <td class="num-col" data-label="Commission"> … </td>
       <td class="td-invoice" data-label="Invoice"> …button… </td>
     </tr>

   data-label drives the left-hand label of each card line; .td-name
   is the card header; .td-invoice is the full-width action button.
   ============================================================ */
