/*
 * Client Table CANON — CR-A116-5 (orders-r1.html §1 "Full desktop page" +
 * §4 "States" + §5 "Phone — the sanctioned LIST degradation").
 *
 * Every rule below is copied verbatim (selector + values) from the ratified
 * card's <style> block — this is the LIST canon Invoices/Statements/
 * Payments/Packing Slips all inherit unchanged (orders-r1.html §6
 * "Inherits to"). Requires tokens.css.
 *
 * Two additions beyond the card, both flagged in the CR-A116-5 forge report
 * as build-time extensions (not visual deviations — no new colors/values):
 *   1. `.p-row-card` / `.p-row-*` — the card's phone reflow used
 *      order-specific class names (`.p-order-card`). Renamed generic so the
 *      canon itself is reusable by the pages orders-r1 says inherit it;
 *      values are byte-identical to `.p-order-card` in the card.
 *   2. `.sort-icon.desc` — see client-table.js `sortIconFor()`: the card
 *      never draws an active+descending sort icon, so descending reuses the
 *      card's own `i-arrow-up` glyph flipped via `transform: scaleY(-1)`
 *      rather than inventing a new symbol.
 */

/* ================= page head row (title + count + search + CTA) ================= */
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.ph-left h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }
.ph-left .ph-count { font-size: 13px; color: var(--muted); }
.ph-left .ph-count b { color: var(--ink-soft); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ph-right { display: flex; align-items: center; gap: var(--sp-3); }
.search-field { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; background: var(--field); border: 1.5px solid var(--line); border-radius: var(--r-md); width: 240px; }
.search-field .icon { color: var(--faint); }
.search-field input { border: none; background: transparent; outline: none; font-size: 13px; color: var(--ink); width: 100%; font-family: var(--font); }
.search-field input::placeholder { color: var(--faint); }
.search-field:focus-within { border-color: var(--blue); }
.btn-primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 24px; border-radius: var(--r-md); background: var(--blue); color: #fff; font-size: 14px; font-weight: 700; border: none; cursor: pointer; white-space: nowrap; font-family: var(--font); }
.btn-primary .icon { stroke: #fff; }
.btn-ghost { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: var(--r-md); background: var(--bg); color: var(--blue-deep); font-size: 13px; font-weight: 700; border: 1.5px solid var(--line); cursor: pointer; font-family: var(--font); }
.btn-primary:focus-visible, .btn-ghost:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ================= filter chips ================= */
.chip-bar { display: flex; align-items: center; gap: 8px; margin-bottom: var(--sp-4); flex-wrap: wrap; }
/* Drew's ruling, 2026-08-13: "۴۴ بمونه، همه جا یکدست بشه" ("44 stays, make
   it consistent everywhere") — the pixel gate named this chip at 32px as
   the touch-target inconsistency (44px already shipped elsewhere per
   CR-A116-15's Rulings #9/#10); min-height only, visual height/padding
   unchanged. */
.filter-chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; min-height: 44px; padding: 0 14px; border-radius: var(--r-full); border: 1.5px solid var(--line); background: var(--bg); color: var(--ink-soft); font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: var(--font); }
.filter-chip .n { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--faint); font-weight: 700; }
.filter-chip.active { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-deep); }
.filter-chip.active .n { color: var(--blue-deep); }
.filter-chip:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ================= the client Table (the canon) ================= */
.table-wrap { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
table.client-table { width: 100%; border-collapse: collapse; }
table.client-table thead th { text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  background: var(--field); padding: 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.client-table thead th.right { text-align: right; }
table.client-table thead th .th-inner { display: inline-flex; align-items: center; gap: 5px; padding: 12px 16px; border: none; background: none; font: inherit; color: inherit; cursor: pointer; width: 100%; text-align: inherit; text-transform: inherit; letter-spacing: inherit; }
table.client-table thead th:not(.sortable) { padding: 12px 16px; }
table.client-table thead th.right .th-inner { flex-direction: row-reverse; justify-content: flex-end; }
table.client-table thead th .sort-icon { width: 12px; height: 12px; stroke: var(--faint); flex-shrink: 0; }
table.client-table thead th .sort-icon.desc { transform: scaleY(-1); }
table.client-table thead th.active { color: var(--blue-deep); }
table.client-table thead th.active .sort-icon { stroke: var(--blue); }
table.client-table thead th .th-inner:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; border-radius: var(--r-sm); }

table.client-table tbody tr { border-bottom: 1px solid var(--line-soft); cursor: pointer; transition: background var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease); }
table.client-table tbody tr:last-child { border-bottom: none; }
table.client-table tbody tr:hover, table.client-table tbody tr:focus-visible { background: var(--blue-soft); box-shadow: inset 3px 0 0 var(--blue); }
table.client-table tbody tr:focus-visible { outline: none; }
table.client-table tbody td { padding: 14px 16px; font-size: 13px; color: var(--ink-soft); vertical-align: middle; height: 56px; }
table.client-table tbody td.right { text-align: right; }

.cell-order .ref { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13.5px; color: var(--ink); margin-bottom: 2px; }
.cell-order .prod { font-size: 12px; color: var(--muted); }
.cell-site { display: flex; align-items: center; gap: 7px; max-width: 190px; }
.cell-site .icon { color: var(--faint); flex-shrink: 0; }
.cell-site span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-po { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.cell-due { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.cell-due .wd { color: var(--faint); font-weight: 400; margin-right: 5px; }
.cell-due.past { color: var(--muted); }
.cell-total { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 700; color: var(--navy); font-size: 13.5px; }

.badge { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: var(--r-full); white-space: nowrap; }
.badge-pending { background: var(--amber-soft); color: var(--amber); }
.badge-new { background: #DBEAFE; color: #1D4ED8; }
.badge-progress { background: #EDE9FE; color: #6D28D9; }
.badge-ready { background: #D1FAE5; color: #047857; }
.badge-delivery { background: #F3E8FF; color: #7E22CE; }
.badge-delivered { background: #D1FAE5; color: #065F46; }
/* Extensions beyond the 6 badge hues the card draws — real orders can carry
   Queue / Pending Vendor / Canceled / Returned (order_status.py), none of
   which appear in orders-r1.html's 7 sample rows. Hues chosen from the
   SAME token palette already in tokens.css, matched to the LOCKED admin
   hue mapping (docs/LOCKS/status-badge-standard-v1.md: Indigo/Orange/Red/
   Rose) so the client and admin panels never disagree on what a status
   "means" — no new colors invented. */
.badge-queue { background: #E0E7FF; color: #4338CA; }
.badge-vendor { background: #FFEDD5; color: #C2410C; }
.badge-canceled { background: var(--danger-soft); color: var(--danger); }
.badge-returned { background: #FFE4E6; color: #9F1239; }

.hover-caption { font-size: 12px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.hover-caption .icon { color: var(--blue); width: 13px; height: 13px; }
.hover-caption b { color: var(--ink-soft); }

/* ================= pagination footer ================= */
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-top: 1px solid var(--line); background: var(--field); flex-wrap: wrap; gap: 10px; }
.table-foot .showing { font-size: 12.5px; color: var(--muted); }
.table-foot .showing b { color: var(--ink-soft); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.page-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.page-btn { min-width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--bg); color: var(--ink-soft); font-size: 13px; font-weight: 700; font-family: var(--mono); cursor: pointer; padding: 0 8px; }
.page-btn.active { border-color: var(--blue); background: var(--blue); color: #fff; }
.page-btn.nav .icon { color: var(--ink-soft); }
.page-btn.disabled { opacity: .4; cursor: default; pointer-events: none; }
.page-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ================= states: loading / empty / error ================= */
.skel-table { padding: 6px 0; }
.skel-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.skel-row:last-child { border-bottom: none; }
.skel { background: linear-gradient(90deg, var(--line-soft) 25%, var(--line) 37%, var(--line-soft) 63%); background-size: 400% 100%; border-radius: var(--r-sm); animation: ct-shimmer 1.6s ease infinite; }
@keyframes ct-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skel.sw { width: 52%; height: 10px; margin-bottom: 6px; }
.skel.sw2 { width: 34%; height: 8px; }
.skel.badge-skel { width: 56px; height: 18px; border-radius: 999px; margin-left: auto; }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* This empty-state is shared, byte-for-byte, across every list page
   (Orders/Invoices/Statements/Packing Slips/Payments — client-table.js's
   header docs). Its frozen cards do NOT agree with each other on the exact
   padding (orders-r1/invoices-statements-r1 34px·20px, payments-packing-
   slips-r1 32px·20px, packing-slips-r1/statements-r1 30px·18px) — 48px·20px
   matched none of them (measured 165->218px / 169->218px box height on
   Packing Slips/Payments — CR-A116-integration-pixel-report §3.4/finding
   #5). 32px·20px is the value within +/-2px of every card's own number;
   picking one of the six cards' exact values would move the OTHER five
   further away. Flagged, not silently invented — a per-page override is
   the alternative if Drew wants exact-per-card over one shared constant. */
.empty-state-mini { padding: 32px 20px; text-align: center; }
.es-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--band); color: var(--navy); display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; }
.es-icon.warn { background: var(--amber-soft); color: var(--amber); }
.es-title { font-size: 12.5px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.es-sub { font-size: 11px; line-height: 1.5; color: var(--muted); margin-bottom: 14px; max-width: 280px; margin-left: auto; margin-right: auto; }
.btn-create { display: inline-flex; align-items: center; gap: 6px; background: var(--blue); color: #fff; border: none; border-radius: var(--r-md); padding: 0 14px; height: 36px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: var(--font); }
.btn-create .icon { stroke: #fff; width: 13px; height: 13px; }
.btn-clear { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); color: var(--blue-deep); border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 0 14px; height: 36px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: var(--font); }
.btn-create:focus-visible, .btn-clear:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ================= phone reflow (~390px): table -> row-cards ================= */
.p-mobile-list { display: none; }
@media (max-width: 480px) {
  .table-wrap > table.client-table, .table-wrap > .table-foot { display: none; }
  .p-mobile-list { display: flex; flex-direction: column; gap: 10px; }
  .table-wrap { background: none; border: none; overflow: visible; }
}
.p-row-card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.p-row-card:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.p-row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.p-row-ref { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; color: var(--ink); }
.p-row-sub { font-size: 11.5px; color: var(--muted); }
.p-row-site { font-size: 11.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; }
.p-row-site .icon { width: 13px; height: 13px; color: var(--faint); }
.p-row-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.p-row-due { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.p-row-total { font-size: 12.5px; font-weight: 700; color: var(--navy); font-family: var(--mono); }
.p-pagefoot { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px 0; margin-top: 2px; border-top: 1px solid var(--line); }
.p-pagefoot .showing { font-size: 11px; color: var(--muted); }
.p-pagefoot .pc { display: flex; gap: 6px; }
/* Drew's ruling, 2026-08-13: "۴۴ بمونه، همه جا یکدست بشه" ("44 stays, make it consistent everywhere") —
   the phone-footer pager was the desktop .page-btn's own smaller sibling
   (40px); raised to match, min-height only. */
.p-pagefoot .page-btn { min-width: 40px; height: 40px; min-height: 44px; font-size: 12px; }

/* Chips scroll horizontally on phone rather than wrap (card §5 "Filter chips
   become a horizontally-scrollable strip"), and sort affordance is dropped
   from the header entirely at this width — the table itself is hidden in
   favor of .p-mobile-list, so there is no header to show. */
@media (max-width: 480px) {
  .chip-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .filter-chip { flex-shrink: 0; }
  .page-head-row { flex-direction: column; align-items: stretch; }
  .ph-right { flex-direction: column; align-items: stretch; }
  .search-field { width: 100%; }
}
