/* The CRM's own additions on top of DESIGN.md's app.css, which ships
   unchanged. Each rule here is foundation, not design: add to DESIGN.md
   first if it changes how anything looks.

   Widths on a class scale. Bars (aged debt, meters, progress) take their
   share as a class, w-0 to w-100 in steps of 5, so no template needs an
   inline style (tests/test_foundation.py bans them). app.services.bars
   works out the classes. In a stacked .agebar the share is a flex weight,
   so the 4px gaps never push it past its track. */

.w-0 { width: 0%; }
.w-5 { width: 5%; }
.w-10 { width: 10%; }
.w-15 { width: 15%; }
.w-20 { width: 20%; }
.w-25 { width: 25%; }
.w-30 { width: 30%; }
.w-35 { width: 35%; }
.w-40 { width: 40%; }
.w-45 { width: 45%; }
.w-50 { width: 50%; }
.w-55 { width: 55%; }
.w-60 { width: 60%; }
.w-65 { width: 65%; }
.w-70 { width: 70%; }
.w-75 { width: 75%; }
.w-80 { width: 80%; }
.w-85 { width: 85%; }
.w-90 { width: 90%; }
.w-95 { width: 95%; }
.w-100 { width: 100%; }

.agebar > [class*="w-"] { width: auto; }
.agebar > .w-5 { flex: 5 1 0; }
.agebar > .w-10 { flex: 10 1 0; }
.agebar > .w-15 { flex: 15 1 0; }
.agebar > .w-20 { flex: 20 1 0; }
.agebar > .w-25 { flex: 25 1 0; }
.agebar > .w-30 { flex: 30 1 0; }
.agebar > .w-35 { flex: 35 1 0; }
.agebar > .w-40 { flex: 40 1 0; }
.agebar > .w-45 { flex: 45 1 0; }
.agebar > .w-50 { flex: 50 1 0; }
.agebar > .w-55 { flex: 55 1 0; }
.agebar > .w-60 { flex: 60 1 0; }
.agebar > .w-65 { flex: 65 1 0; }
.agebar > .w-70 { flex: 70 1 0; }
.agebar > .w-75 { flex: 75 1 0; }
.agebar > .w-80 { flex: 80 1 0; }
.agebar > .w-85 { flex: 85 1 0; }
.agebar > .w-90 { flex: 90 1 0; }
.agebar > .w-95 { flex: 95 1 0; }
.agebar > .w-100 { flex: 100 1 0; }

/* The authenticator setup code on the sign-in card. */
.auth-qr {
  align-self: center;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-tray);
  background: var(--ilivin-paper);
}

/* A state with no row in _stamps.html: visible on purpose, and caught by
   tests/test_design_guards.py before it ships. */
.stamp-unknown {
  outline: 1px dashed var(--danger-text);
}

/* Keys that only matter without JavaScript: a filter's Show or Apply and a
   picker's Add. app.js submits on change instead (DESIGN.md Departure 19). */
.js .no-js-only {
  display: none;
}

/* A filter's key in a .form-grid row lines up with the fields, not their
   labels. */
.field-key {
  display: flex;
  align-items: flex-end;
}

/* The expense form shows the part for the chosen "Who is it for". Without
   JavaScript both parts show, each saying which choice it is for. */
.js form:not(:has(input[name="who"][value="one"]:checked)) [data-who-section="one"],
.js form:not(:has(input[name="who"][value="shared"]:checked)) [data-who-section="shared"] {
  display: none;
}

/* DESIGN.md Departure 20: a table whose second cell is a field (an expense
   split, a cost allocation, tagged AWS costs) stacks on a phone, the name
   above its field, so neither is squeezed. */
@media (max-width: 720px) {
  .data-table.responsive.share-table tr {
    grid-template-columns: minmax(0, 1fr);
  }

  .data-table.responsive.share-table td.cell-amount {
    grid-row: 2;
    grid-column: 1;
    text-align: left;
  }
}

/* DESIGN.md Departure 21: three metric tiles sit three across, not in a
   four-column grid with an empty fourth. One column on a phone. */
.metric-grid.metric-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 720px) {
  .metric-grid.metric-grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* DESIGN.md Departure 22: a form in the narrow right rail puts each field on
   its own row, so a date keeps its year clear of the calendar key. The two
   columns of .grid-main are containers; the rail is the only one this
   narrow on a desktop, and below 720px .form-grid is one column anyway. */
.grid-main > * {
  container-type: inline-size;
}

@container (max-width: 420px) {
  .form-grid > * {
    grid-column: 1 / -1;
  }
}

/* DESIGN.md Departure 23: below 420px an invoice line's unit price takes the
   rest of its row and the amount moves to a row of its own, so a price such
   as 290.00 is never cut off. */
@media (max-width: 420px) {
  .lines .line-unit {
    grid-column: 2 / 5;
  }

  .lines .line-amount {
    grid-row: 3;
    grid-column: 1 / 5;
  }

  .lines .line-amount .line-value {
    padding-top: 0;
  }
}

/* DESIGN.md Departure 24: stacked tables on a phone.
   In a table with no amount the state stamps take their own row under the
   primary cell, so they never squeeze its title. A labelled cell's value
   hangs beside its label instead of wrapping under it. */
@media (max-width: 720px) {
  .data-table.responsive.no-amount td.cell-state {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-self: start;
  }

  .data-table.responsive.no-amount td.cell-meta {
    grid-row: 3;
  }

  /* The label column is a layout width (Departure 12), as wide as the
     label's 104px plus its 8px gap. */
  .data-table.responsive td[data-label] {
    --cell-label-width: 112px;
  }

  .data-table.responsive td[data-label]:not(:has(> :is(div, form, label, select, input, textarea, ul, ol, dl, table))) {
    padding-left: var(--cell-label-width);
    text-indent: calc(-1 * var(--cell-label-width));
  }

  .data-table.responsive td[data-label]::before,
  .data-table.responsive td[data-label] > * {
    text-indent: 0;
  }

  .data-table.responsive td[data-label]::before {
    min-width: var(--cell-label-width);
  }
}

/* DESIGN.md Departure 30: the pagination strip, ported from the Alert Hub
   console (its .pagination rules and pagerHtml markup). It sits flush under
   its table inside the card and carries the card's bottom corners; the card
   draws the frame, so the strip keeps only its top hairline (the Alert Hub's
   penalty-box variant). Its keys are the CRM's keycap (.btn, the Alert Hub's
   .ilv-peer-btn) and its numbers and sizes are capsules (.capsules/.capsule,
   its .ilv-view-switch/.ilv-view-option), the current one filled in Ink. */
.card > .pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  background: transparent;
}

/* A list of cards (agreement templates, backends by client) pages too: the
   strip then sits in a card of its own under them, with no hairline. */
.pagination-card > .pagination {
  border-top: 0;
}

.pagination-summary,
.pagination-size-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--ilivin-subtitle-size);
}

.pagination-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.pagination-pages.capsules {
  align-items: center;
}

.pagination-ellipsis {
  padding: 0 4px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.pagination-size {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Numbers line up in their capsules. */
.pagination-page,
.pagination-size-option {
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

/* A page number is the current page, not a chosen filter: the same Ink
   fill as .capsule[aria-current="true"]. */
.pagination-page[aria-current="page"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--card);
}

/* The Alert Hub drops the numbers, First/Last and the size choice on a
   phone (its 760px is the CRM's 720px phone breakpoint) and gives Previous
   and Next half the row each. */
@media (max-width: 720px) {
  .card > .pagination {
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-2) var(--space-4);
  }

  .pagination-pages,
  .pagination-endcap,
  .pagination-size {
    display: none;
  }

  .pagination-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
