/* ============================================================================
 * COREX — the money screens on the design system (UI upgrade, Wave B)
 * ============================================================================
 * The counter, the cash-up (Drawers / The day / The Book / Loans) and the
 * owner's Money place, restyled on the --cx-* tokens of public/ui.css.
 * Loaded after app.css and corex-v2.css, so a rule here wins over the older
 * one it replaces; the older rule stays where a test still reads it.
 * Look, layout and interaction only: no amount, rule or permission is
 * decided here, and nothing a cashier must not see is hidden by CSS — the
 * server never sends it (src/output-policy.js).
 * Tokens only (no colour literals), logical sides only (RTL), every control
 * 44px, every box 16px. Breakpoints: 760 (phone) and 1100 only.
 * ========================================================================== */

/* No capitals and no tracking anywhere on the money screens (components §15):
   the older rules that shouted a label (table heads, tile names, the pulse
   line, the bank fold) are quietened here in one place. A word the shop
   writes in capitals (COREX, VOUCHERS) is typed that way and stays so. */
:is(#view-till,#view-cashup,#view-history,#view-expenses,#view-operations,#view-kuwait,#receiptModal .modal-head,.cx-money-scope) *{
  text-transform:none;letter-spacing:normal}

/* ================================================================ COUNTER */
/* A search with no match is said, not shouted: it is not an error. */
.scan-msg.info{color:var(--cx-text-muted)}
.scan-msg.show{height:auto;min-height:26px;font-size:var(--cx-fs-sm)}
.scan-bar{border-color:var(--cx-border-strong);border-width:1px;border-radius:var(--cx-radius-md);background:var(--cx-surface)}
.scan-bar:focus-within{border-color:var(--cx-focus);box-shadow:none;outline:2px solid var(--cx-focus);outline-offset:1px}
#scanInput{color:var(--cx-text)}

/* the product card: flat, the price is the one loud thing (components §18) */
#view-till .pcard{box-shadow:var(--cx-shadow-0);border-color:var(--cx-border);border-radius:var(--cx-radius-lg);color:var(--cx-text)}
#view-till .pcard:hover{transform:none;box-shadow:var(--cx-shadow-0);border-color:var(--cx-focus)}
#view-till .pcard-name{font-size:var(--cx-fs-body);font-weight:var(--cx-fw-semibold)}
#view-till .pcard-sku{font-size:var(--cx-fs-xs)}
#view-till .pcard-price{color:var(--cx-text);font-size:var(--cx-fs-lg);font-weight:var(--cx-fw-bold)}
#view-till .qty-tag{font-size:var(--cx-fs-xs)}

/* the category chips: 44px, the chosen one raised by weight and fill */
#view-till .cat-pill{min-height:var(--cx-hit);display:inline-flex;align-items:center}
#view-till .cat-pill.active{font-weight:var(--cx-fw-bold)}
/* the product Enter selected when several match (U-011): a raised border and
   a check mark word in the message — not colour alone */
#view-till .pcard.is-picked{border:2px solid var(--cx-focus);background:var(--cx-accent-soft)}

/* the basket's lines and totals read on the tokens */
.cart-head h2{font-size:var(--cx-fs-body);font-weight:var(--cx-fw-semibold);flex:1;min-width:0}
.cline-name{font-size:var(--cx-fs-body)}
.cline-meta,.cline-was,.cline-lock{font-size:var(--cx-fs-xs)}
.cline-total{font-size:var(--cx-fs-body)}
.trow{font-size:var(--cx-fs-sm)}
.trow.grand{font-size:var(--cx-fs-body)}
.trow.grand b{color:var(--cx-text);letter-spacing:0;font-size:var(--cx-fs-2xl)}
.trow.lbp,.trow.lbp b{font-size:var(--cx-fs-sm)}
.pm{min-height:var(--cx-hit);font-size:var(--cx-fs-body)}
.pm.active{font-weight:var(--cx-fw-bold)}
.change-row b{font-size:var(--cx-fs-xl)}
/* COMPLETE floats over the pane's foot: a band of the pane's own surface
   round it, so the note buttons behind never show through */
#completeSale{box-shadow:0 0 0 var(--cx-space-2) var(--cx-surface)}
.pay-inputs input,.change-ll input,.cust-row input,#billDisc{font-size:var(--cx-fs-input)}

/* the basket bar and the back button exist on a phone only */
.cx-basketbar{display:none}
.pay-back{display:none}

@media (max-width:760px){
  /* the grid is the page: no box inside a box, it scrolls with the screen */
  #view-till .product-grid{max-height:none;overflow:visible;grid-template-columns:repeat(2,minmax(0,1fr));gap:var(--cx-space-2)}
  #view-till .till-left{padding:var(--cx-space-3)}
  /* the basket is not under the grid: it is the pay sheet */
  #view-till .till-right{display:none}
  #view-till .till.pay-open .till-right{
    display:flex;position:fixed;inset:0;z-index:var(--cx-z-sheet);width:auto;
    border:0;background:var(--cx-surface);
    padding-block:var(--cx-safe-top) var(--cx-safe-bottom);
    padding-inline:var(--cx-safe-start) var(--cx-safe-end)}
  #view-till .till.pay-open .cart{height:100%;overflow-y:auto;overscroll-behavior:contain}
  #view-till .till.pay-open .cart-lines{max-height:none;flex:none}
  #view-till .till.pay-open .cline{min-height:56px}
  .cart-head{gap:var(--cx-space-2);padding:var(--cx-space-2) var(--cx-space-3)}
  .pay-back{display:inline-flex}
  .pay-back svg{width:20px;height:20px;stroke:currentColor;stroke-width:1.75;fill:none;stroke-linecap:round;stroke-linejoin:round}
  /* the total and the change: the screen's loud figures (components §17-18) */
  #view-till .till.pay-open .trow.grand b{font-size:var(--cx-fs-3xl)}
  #view-till .till.pay-open .change-row b{font-size:var(--cx-fs-4xl);line-height:var(--cx-lh-tight)}
  /* COMPLETE: the sheet's sticky primary, above the home bar */
  #view-till .till.pay-open #completeSale{bottom:var(--cx-space-2);box-shadow:0 0 0 var(--cx-space-2) var(--cx-surface)}

  .cx-basketbar:not([hidden]){
    display:flex;align-items:center;justify-content:space-between;gap:var(--cx-space-3);
    position:sticky;inset-block-end:0;z-index:var(--cx-z-sticky);
    background:var(--cx-surface);border-block-start:1px solid var(--cx-border);box-shadow:var(--cx-shadow-2);
    padding:var(--cx-space-3) calc(var(--cx-space-4) + var(--cx-safe-end)) var(--cx-space-3) calc(var(--cx-space-4) + var(--cx-safe-start))}
  .bb-sum{display:flex;flex-direction:column;min-width:0}
  .bb-count{font-size:var(--cx-fs-sm);color:var(--cx-text-muted)}
  .bb-total{font-size:var(--cx-fs-2xl);font-weight:var(--cx-fw-bold);color:var(--cx-text);line-height:var(--cx-lh-tight)}
  .bb-last{font-size:var(--cx-fs-sm);color:var(--cx-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
  .bb-last[hidden]{display:none}
  .cx-basketbar{cursor:pointer}
  #bbPay{min-width:140px}
  /* the open sheet owns the screen: the page under it does not scroll */
  body.cx-pay-open #view-till{overflow:hidden}
}

/* ================================================================ CASH UP */
/* Words carry the hierarchy by size and weight, never capitals or tracking
   (components §15), on the tokens in both looks. */
.cu-card{background:var(--cx-surface);border-color:var(--cx-border);border-radius:var(--cx-radius-lg);color:var(--cx-text)}
.cu-card h2{font-size:var(--cx-fs-lg);font-weight:var(--cx-fw-bold)}
.cu-card h3{text-transform:none;letter-spacing:0;font-size:var(--cx-fs-body);font-weight:var(--cx-fw-semibold);color:var(--cx-text)}
.cu-sub,.cu-field>span{color:var(--cx-text-muted)}
.cu-field>span{font-size:var(--cx-fs-sm);font-weight:var(--cx-fw-semibold)}
.cu-bank h4,.dn-title,.ct-name,.ct-state{text-transform:none;letter-spacing:0}
.cu-var-big{letter-spacing:0}
.btn-ghost-count{letter-spacing:0}

/* THE DRAWER STRIP: four drawers, always in view above the count. On a
   phone a row that scrolls sideways (never wraps into two screens of tiles) */
.cu-tile{border-width:1px;border-color:var(--cx-border);background:var(--cx-surface);color:var(--cx-text);min-height:var(--cx-hit)}
.cu-tile:hover{transform:none;border-color:var(--cx-focus)}
.cu-tile.active{background:var(--cx-surface);color:var(--cx-text);border:2px solid var(--cx-text);box-shadow:none}
.cu-tile.active .ct-sub,.cu-tile.active .ct-name,.cu-tile.active .ct-state{color:var(--cx-text-muted)}
.cu-tile.active .ct-name{color:var(--cx-text)}
.cu-tile.is-live:not(.active){box-shadow:none}
.ct-name{font-size:var(--cx-fs-sm);font-weight:var(--cx-fw-bold);color:var(--cx-text)}
.ct-state{font-size:var(--cx-fs-xs)}
.ct-sub{font-size:var(--cx-fs-xs)}
.ct-dot{background:var(--cx-success);box-shadow:none}
@media (max-width:760px){
  .cu-rail:not(.cu-rail-money){flex-wrap:nowrap;overflow-x:auto;scroll-snap-type:x proximity;padding:var(--cx-space-3) var(--cx-space-3) 0;gap:var(--cx-space-2);scrollbar-width:none}
  .cu-rail:not(.cu-rail-money)::-webkit-scrollbar{display:none}
  .cu-rail:not(.cu-rail-money) .cu-tile{flex:0 0 auto;min-width:132px;max-width:160px;scroll-snap-align:start;padding:var(--cx-space-2) var(--cx-space-3)}
  .cu-rail:not(.cu-rail-money) .ct-amt{display:none}
  .cu-pulse-slot{padding:var(--cx-space-2) var(--cx-space-3) 0}
}

/* THE STEPS: set aside for Kuwait (when there is something), count, close —
   numbered by the page, so a step that is not needed leaves no gap */
.cu-card{counter-reset:cu-step}
.cu-step-h{display:flex;align-items:center;gap:var(--cx-space-2)}
.cu-step-h::before{counter-increment:cu-step;content:counter(cu-step);flex:none;
  display:inline-grid;place-items:center;width:28px;height:28px;border-radius:50%;
  background:var(--cx-text);color:var(--cx-surface);font-size:var(--cx-fs-sm);font-weight:var(--cx-fw-bold)}
.cu-close-step{border-top:1px solid var(--cx-border);padding-top:var(--cx-space-5);margin-top:var(--cx-space-2)}
.cu-close-step .cu-check-note{margin-bottom:var(--cx-space-3)}

/* COUNT BY NOTES: each note's face, then − count + at 44px; the box is 16px */
.dn-wrap{background:var(--cx-surface-2);border-color:var(--cx-border)}
.dn-wrap>summary{min-height:var(--cx-hit);font-size:var(--cx-fs-body)}
.dn-title{font-size:var(--cx-fs-sm);color:var(--cx-text-muted)}
.dn-grid{grid-template-columns:repeat(auto-fill,minmax(min(100%,250px),1fr));gap:var(--cx-space-2)}
.dn-cell{flex-direction:row;align-items:center;justify-content:space-between;gap:var(--cx-space-3)}
.dn-face{font-size:var(--cx-fs-body);font-weight:var(--cx-fw-bold);color:var(--cx-text);
  font-feature-settings:var(--cx-num);min-width:84px;min-height:var(--cx-hit);display:inline-flex;align-items:center}
.dn-stepper{display:inline-flex;align-items:center;gap:var(--cx-space-1)}
.dn-step{min-width:var(--cx-hit);min-height:var(--cx-hit);border:1px solid var(--cx-border-strong);border-radius:var(--cx-radius-md);
  background:var(--cx-surface);color:var(--cx-text);font-size:var(--cx-fs-lg);font-weight:var(--cx-fw-semibold);line-height:1}
.dn-step:hover{background:var(--cx-surface-2)}
.dn-in{width:72px;min-height:var(--cx-hit);font-size:var(--cx-fs-input);background:var(--cx-surface);color:var(--cx-text);
  border:1px solid var(--cx-border-strong);-moz-appearance:textfield}
.dn-in::-webkit-outer-spin-button,.dn-in::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
.dn-sum{font-feature-settings:var(--cx-num)}

/* the money boxes: 16px, 44px, LTR in both languages */
.cu-field .money-in{min-height:var(--cx-hit)}
.cu-field input[type=text],.cu-field select{min-height:var(--cx-hit);font-size:var(--cx-fs-input)}

/* ONE close: the two end buttons sit in the sticky bar at the foot of the
   count, the close the one primary (components §13) */
.cu-end-btns.cx-actionbar{margin:var(--cx-space-2) calc(-1 * var(--cx-space-5)) calc(-1 * var(--cx-space-5));
  border-radius:0 0 var(--cx-radius-lg) var(--cx-radius-lg);flex-wrap:nowrap}
.cu-end-btns.cx-actionbar>button{flex:1 1 0;min-height:56px}
.cu-end-btns .btn-ghost-count{border:1px solid var(--cx-border-strong);color:var(--cx-text);background:var(--cx-surface);border-radius:var(--cx-radius-md)}
.cu-end-btns .btn-ghost-count:hover{background:var(--cx-surface-2);color:var(--cx-text)}
.cu-end-btns .btn-complete{flex:1.4 1 0}
@media (max-width:760px){
  .cu-end-btns.cx-actionbar{margin-inline:calc(-1 * var(--cx-space-4));margin-block-end:calc(-1 * var(--cx-space-4))}
  /* the page scrolls, not a box inside it, so the bar sticks to the screen */
  #view-cashup .cu-wrap{overflow:visible;height:auto}
}

/* folds read on the tokens; their summary is a 44px row */
details.cu-fold{border-color:var(--cx-border);background:var(--cx-surface)}
details.cu-fold>summary{min-height:var(--cx-hit)}
details.cu-fold>summary:hover{background:var(--cx-surface-2)}
@media (max-width:760px){
  /* the label on its line, what is set to happen under it — no 3-line squeeze */
  details.cu-fold>summary{flex-wrap:wrap;align-items:center;row-gap:2px}
  details.cu-fold>summary>span{flex:1 1 auto;min-width:0}
  details.cu-fold>summary em{flex:1 1 100%;order:3;white-space:normal;overflow:visible;text-overflow:clip;max-width:none}
}

/* ======================================================= CARD ROWS (tables)
   components.md §4: on a phone a table is a list of cards, by data-pri —
   1: the identity (start) and the headline amount ([data-amount], end);
   1s: the status (start) and the row's action ([data-act], end);
   2: up to four "label: value" lines; 3: not on a phone. Money cells stay
   LTR and end-aligned. Nothing hidden here is a secret: the server decides
   what a screen is sent. */
@media (max-width:760px){
  table.cx-cards,table.cx-cards>tbody{display:block;width:100%;min-width:0}
  table.cx-cards>thead{display:none}
  table.cx-cards>tbody>tr{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:var(--cx-space-1) var(--cx-space-3);
    align-items:center;padding:var(--cx-space-3);margin-block-end:var(--cx-space-2);
    background:var(--cx-surface);border:1px solid var(--cx-border);border-radius:var(--cx-radius-lg)}
  table.cx-cards>tbody>tr>td{display:block;padding:0;border:0;min-width:0;text-align:start;background:none;white-space:normal}
  table.cx-cards td[data-pri="1"]{grid-row:1;grid-column:1;font-weight:var(--cx-fw-semibold)}
  table.cx-cards td[data-pri="1"][data-amount]{grid-column:2;text-align:end;font-size:var(--cx-fs-lg);font-weight:var(--cx-fw-bold);white-space:nowrap}
  table.cx-cards td[data-pri="1s"]{grid-row:2;grid-column:1}
  table.cx-cards td[data-pri="1s"][data-act]{grid-column:2;text-align:end;display:flex;gap:var(--cx-space-2);justify-content:flex-end;flex-wrap:wrap}
  table.cx-cards td[data-pri="2"]{grid-column:1 / -1;font-size:var(--cx-fs-sm);color:var(--cx-text)}
  table.cx-cards td[data-pri="2"][data-label]:not(:empty)::before{content:attr(data-label) ": ";color:var(--cx-text-muted);font-weight:var(--cx-fw-semibold)}
  table.cx-cards td[data-pri="2"]:empty,table.cx-cards td[data-pri="3"]{display:none}
  /* a row with one cell (nothing yet / a sub-row of payments) spans the card */
  table.cx-cards td[colspan]{grid-column:1 / -1;text-align:center}
  table.cx-cards tr.bk-sub td[colspan]{text-align:start}
  table.cx-cards .op-time{margin-inline-start:var(--cx-space-2)}
  table.cx-cards td button{min-height:var(--cx-hit);min-width:var(--cx-hit)}
  /* the wrapper no longer needs to scroll sideways: the cards fit */
  .table-wrap:has(> table.cx-cards),.mv-wrap:has(> table.cx-cards),.mv-scroll:has(> table.cx-cards){overflow:visible;border:0;background:none;box-shadow:none}
  .mv-wrap:has(> table.cx-cards)::before,.mv-wrap:has(> table.cx-cards)::after{display:none}
  /* any other owner table on the money screens that is still a grid scrolls
     inside its own box, with the edge shadow, and never slides the page */
  :is(#view-cashup,#view-kuwait,#view-expenses,#view-operations) table.tbl:not(.cx-cards){display:block;max-width:100%;overflow-x:auto;
    background:linear-gradient(to right,var(--cx-surface) 30%,transparent),linear-gradient(to left,var(--cx-surface) 30%,transparent) 100% 0,
      radial-gradient(farthest-side at 0 50%,var(--cx-overlay),transparent),radial-gradient(farthest-side at 100% 50%,var(--cx-overlay),transparent) 100% 0;
    background-repeat:no-repeat;background-size:40px 100%,40px 100%,12px 100%,12px 100%;background-attachment:local,local,scroll,scroll}
  /* Kuwait wallets: the share boxes in a card */
  table.kwm-shares td[data-pri="2"] .money-in,table.cx-cards td[data-pri="2"] .money-in{display:inline-flex;vertical-align:middle;min-height:var(--cx-hit)}
}

/* ================================================================== MONEY */
/* the EVERYTHING tile on every Money tab, and the Overview's three cards */
.cu-overview{display:grid;gap:var(--cx-space-4);padding:var(--cx-space-4) var(--cx-space-5)}
@media (max-width:760px){.cu-overview{padding:var(--cx-space-3);gap:var(--cx-space-3)}}
.cu-rail-money .cu-tile.grand{max-width:420px}
/* the line under EVERYTHING at full ink: at .8 it measured 4.01:1 in light
   (round 3); hierarchy by size and weight instead */
.cu-tile.grand .ct-sub,.cu-tile.grand .ct-name{opacity:1}
.cu-tile.grand .ct-sub{font-weight:var(--cx-fw-regular)}
.cu-move-link{display:flex;align-items:center;justify-content:space-between;gap:var(--cx-space-3);flex-wrap:wrap}
.cu-move-link .cu-sub{margin:var(--cx-space-1) 0 0}

/* Expenses and Operations: the figures first, on the tokens */
.kpi{background:var(--cx-surface);border-color:var(--cx-border);box-shadow:var(--cx-shadow-0)}
.kpi-label{font-size:var(--cx-fs-sm);color:var(--cx-text-muted)}
.kpi-value{letter-spacing:0;font-feature-settings:var(--cx-num)}
.exp-cat span{text-transform:none;font-size:var(--cx-fs-sm)}
.exp-locked svg{flex:none}
#view-expenses .month-pick,#view-operations .month-pick{display:flex;flex-direction:column;gap:var(--cx-space-1);font-size:var(--cx-fs-sm);color:var(--cx-text-muted)}
#view-expenses .month-pick input,#view-operations .month-pick input,#view-operations .select{min-height:var(--cx-hit);font-size:var(--cx-fs-input)}
@media (max-width:760px){
  /* four figures in two rows, not four screens */
  #opsKpi{grid-template-columns:repeat(2,minmax(0,1fr));gap:var(--cx-space-2);margin-bottom:var(--cx-space-3)}
  #opsKpi .kpi{padding:var(--cx-space-3)}
  #opsKpi .kpi-value{font-size:var(--cx-fs-xl)}
  /* the total and Add on the first line, the dates under them */
  #view-expenses .toolbar,#view-operations .toolbar{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);align-items:end}
  #view-expenses .toolbar .grow,#view-operations .toolbar .grow{display:none}
  #expTotal{order:-2;align-self:center}
  #addExpense{order:-1}
  #view-operations .select{width:100%}
  #opsCount{grid-column:1 / -1;justify-self:start}
}
/* Where is the money: each row's explanation under its name, not glued to it */
.wm-row .buy-note{display:block;color:var(--cx-text-muted);font-size:var(--cx-fs-sm);font-weight:var(--cx-fw-regular,400)}
.buy-row .buy-note{color:var(--cx-text-muted)}
.move-card #mvNote{min-height:var(--cx-hit);font-size:var(--cx-fs-input)}
