/* Clozit admin — the PHONE layout (#514). Staff run the pop-up booth from a phone, so every table
   renders as a list of CARDS below 1024px (one column on a phone, two on a tablet — a 988px pool row
   beside the sidebar only fits from there up). Below 1024px the sidebar is also a menu DRAWER behind
   a slim top bar's menu button (app.js owns its open/close, focus trap and scroll lock), and below
   760px the rest becomes a phone layout: bottom-sheet dialogs, sticky bars.

   There is ONE markup per page: each table row is a CSS grid whose cells carry a class (pc-* pool,
   cc-* confirmed payments, sc-* staff, prc-* promo codes, wc-* last 7 days, tc-* transactions). On a
   desktop those classes have no rules; here they are placed into grid-template-areas, so the card and
   the table are the same nodes with the same buttons and handlers. A cell's `data-label` is drawn as
   its caption here only — desktop has the column header instead.

   Screen only: printing tags from a phone must get the A4 print layout (floor.css), not this. Nothing
   here goes below 12px, inputs are 16px (iOS zooms the page on focus below that), tap targets 44px+. */

@media screen and (max-width: 1023px) {
  /* ---------- shell: a slim sticky top bar, and the sidebar as a left drawer ---------- */
  .shell { display: block; }
  .topbar {
    position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 4px;
    min-height: 56px; padding: env(safe-area-inset-top) 16px 0 max(6px, env(safe-area-inset-left));
    background: var(--card); border-bottom: 1px solid var(--sidebar-rule);
  }
  .menu-btn {
    position: relative; width: 44px; height: 44px; flex-shrink: 0; border: none; border-radius: 12px; background: none;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .menu-btn:active { background: var(--page); }
  .menu-icon, .menu-icon::before, .menu-icon::after { display: block; width: 20px; height: 2px; border-radius: 1px; background: var(--ink); }
  .menu-icon { position: relative; }
  .menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
  .menu-icon::before { top: -6px; }
  .menu-icon::after { top: 6px; }
  /* Payments are waiting: a dot on the menu button, so it is seen without opening the drawer. */
  .menu-dot { position: absolute; top: 9px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--warn); border: 2px solid var(--card); }
  .topbar-title { font-family: var(--serif); font-size: 18px; font-weight: 600; white-space: nowrap; }

  .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(26, 21, 16, 0.45); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: min(300px, 80vw); max-width: none;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    overflow-y: auto; overscroll-behavior: contain; gap: 4px;
    transform: translateX(-100%); visibility: hidden; transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  .sidebar:focus { outline: none; }
  html.drawer-open .sidebar { transform: none; visibility: visible; transition: transform 0.22s ease; box-shadow: 8px 0 28px rgba(26, 21, 16, 0.2); }
  /* The page behind the open drawer does not scroll. */
  html.drawer-open, html.drawer-open body { overflow: hidden; }
  .brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 0 10px 10px; }
  .brand-row .brand { padding: 0; font-size: 19px; }
  .drawer-close {
    display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex-shrink: 0;
    border: none; border-radius: 12px; background: none; font-size: 28px; line-height: 1; color: var(--ink);
  }
  .nav-link { min-height: 48px; padding: 0 14px; font-size: 16px; border-radius: 12px; }
  .who { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--hairline); font-size: 13px; gap: 2px; }
  .who b { color: var(--ink); }
  .who .link-button { min-height: 44px; font-size: 14px; }

  .main { padding: 24px max(24px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }

  /* ---------- skeletons in card lists ---------- */
  .pool-table > .sk-item, .staff-table > .sk-item, .conf-table > .sk-item, .promo-table > .sk-item, .event-table > .sk-item { border-radius: 16px; border-bottom: none; }
  .tx-table > .sk-item { padding: 16px 0; }

  /* ---------- every table → a list of cards ---------- */
  .table-box { background: none; border-radius: 0; overflow: visible; }
  /* One column on a phone; two side by side once there is room for two (a tablet). */
  .pool-table, .staff-table, .conf-table, .promo-table, .event-table {
    min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 10px;
  }
  .table-box .empty { grid-column: 1 / -1; }
  .pool-grid.table-head, .staff-grid.table-head, .conf-grid.table-head, .promo-grid.table-head,
  .tx-grid.table-head { display: none; }
  .pool-grid, .staff-grid, .conf-grid, .promo-grid, .event-grid {
    background: var(--card); border-radius: 16px; border-bottom: none; padding: 14px 16px; font-size: 14px;
  }
  .table-box .empty { background: var(--card); border-radius: 16px; }
  .table-box [data-label]::before, .tx-table [data-label]::before {
    content: attr(data-label) " "; color: var(--ink-2); font-weight: 600; font-family: var(--sans);
  }

  /* ---------- pop-up pool card ---------- */
  .pool-grid {
    /* The left column is capped at 60% (fit-content), never `auto`: an auto track sizes to its
       items' max-content even when they clip, so one long staff handle took the whole card and
       squeezed the right column — price, buyer, updated — to 0px, off the card's edge. 60% still
       holds the 172px status pill; the right column keeps ~112px on a 375px phone. */
    grid-template-columns: fit-content(60%) minmax(0, 1fr); gap: 10px 12px;
    grid-template-areas: "item item" "id tag" "status updated" "staff buyer";
  }
  .pc-item { grid-area: item; gap: 12px; align-items: flex-start; }
  .pc-item .thumb { width: 52px; height: 64px; border-radius: 10px; }
  .pc-item .item-name { font-size: 16px; white-space: normal; overflow-wrap: anywhere; }
  .pc-item .item-detail { font-size: 13px; white-space: normal; margin-top: 2px; }
  .pc-id { grid-area: id; font-size: 14px; }
  .pc-tag { grid-area: tag; text-align: right; font-size: 18px; }
  .pc-status { grid-area: status; }
  .pc-status .pill { width: 172px; }
  .pc-updated { grid-area: updated; text-align: right; font-size: 13px; }
  .pc-staff { grid-area: staff; font-size: 13px; }
  .pc-buyer { grid-area: buyer; text-align: right; font-size: 13px; }
  /* Auto-placed below the four named rows, so a SOLD card (no buttons, hidden) leaves no empty row. */
  .pool-grid .actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 2px; }
  .pool-grid .actions > div { flex: 1 1 0; display: flex; }
  .pool-grid .actions > div:empty, .pool-grid .actions:not(:has(button)) { display: none; }
  /* The desktop's pinned ACTIONS column has nothing to pin over in a card. */
  .pool-grid .sticky-end, .table-box.has-more .pool-grid .sticky-end { position: static; box-shadow: none; }
  .pool-grid .action-btn { width: 100%; height: 48px; border-radius: 12px; font-size: 15px; }
  .pool-grid .pick { width: 24px; height: 24px; }
  .pool-grid .pick-spacer { display: none; }
  .sel-bar { bottom: calc(8px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .sel-actions .btn { height: 48px; }
  .co-line .input { font-size: 16px; }

  /* ---------- payments: confirmed ---------- */
  .conf-grid {
    grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px;
    grid-template-areas: "type amount" "item item" "status status" "buyer time" "ref by" "act act";
  }
  .conf-grid.table-head > :last-child { display: none; }
  .cc-act { grid-area: act; }
  .cc-act:empty { display: none; }
  .cc-act .btn { width: 100%; height: 44px; }
  .cc-type {
    grid-area: type; justify-self: start; font-size: 12px; font-weight: 700; letter-spacing: 0.8px;
    text-transform: uppercase; padding: 3px 8px; border-radius: 999px;
  }
  .cc-type[data-type="popup"] { background: #F6DED6; color: #7A2E17; }
  .cc-type[data-type="platform_fee"] { background: #DCE8F2; color: #1F4E73; }
  .cc-amount { grid-area: amount; font-size: 18px; font-weight: 700; text-align: right; }
  .cc-item { grid-area: item; font-size: 15px; font-weight: 700; white-space: normal; }
  .cc-buyer { grid-area: buyer; font-size: 13px; }
  .cc-time { grid-area: time; font-size: 13px; color: var(--ink-2); text-align: right; }
  .cc-ref { grid-area: ref; font-size: 13px; }
  .cc-by { grid-area: by; font-size: 13px; text-align: right; }
  .cc-status { grid-area: status; }

  /* ---------- staff ---------- */
  .staff-grid { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; grid-template-areas: "acct acct" "pool since" "act act"; }
  .sc-acct { grid-area: acct; font-size: 15px; overflow-wrap: anywhere; }
  .sc-pool { grid-area: pool; font-size: 13px; }
  .sc-since { grid-area: since; font-size: 13px; text-align: right; }
  .sc-act { grid-area: act; }
  .sc-act .btn { width: 100%; height: 44px; }

  /* ---------- promo codes ---------- */
  .promo-grid { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; grid-template-areas: "code off" "valid valid" "used status" "act act"; }
  .event-grid { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; grid-template-areas: "name status" "dates dates" "act act"; }
  .event-grid.table-head { display: none; }
  .evc-name { grid-area: name; } .evc-dates { grid-area: dates; } .evc-status { grid-area: status; } .evc-act { grid-area: act; }
  .prc-code { grid-area: code; font-size: 18px; overflow-wrap: anywhere; }
  .prc-off { grid-area: off; font-size: 18px; font-weight: 700; text-align: right; }
  .prc-amt::after { content: " off"; font-weight: 600; color: var(--ink-2); font-size: 14px; }
  .prc-off.is-orbits .prc-amt::after { content: none; } /* an Orbits code takes nothing off (082) */
  .prc-usage { font-size: 13px; }
  .prc-valid { grid-area: valid; font-size: 13px; }
  .prc-used { grid-area: used; font-size: 13px; }
  .prc-status { grid-area: status; justify-self: end; }
  .prc-act { grid-area: act; }
  .prc-act:empty { display: none; }
  .prc-act .btn { flex: 1; height: 44px; }

  /* ---------- sales transactions ---------- */
  .tx-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; padding: 14px 0; font-size: 13px;
    grid-template-areas: "item item" "ch status" "seller buyer" "time ref" "price disc" "total dep";
  }
  .tx-table { min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); column-gap: 28px; }
  .tx-table .empty { grid-column: 1 / -1; }
  .tc-item { grid-area: item; font-size: 15px; font-weight: 700; white-space: normal; }
  .tc-ch { grid-area: ch; }
  .tc-status { grid-area: status; justify-self: end; }
  .tc-status .tx-pill { width: 156px; }
  .tc-seller { grid-area: seller; }
  .tc-seller::before { content: "Seller "; color: var(--ink-2); font-weight: 600; }
  .tc-buyer { grid-area: buyer; text-align: right; }
  .tc-buyer::before { content: "→ Buyer "; color: var(--ink-2); font-weight: 600; }
  .tc-time { grid-area: time; color: var(--ink-2); }
  .tc-ref { grid-area: ref; text-align: right; }
  .tc-money { background: var(--page); border-radius: 10px; padding: 6px 10px; font-size: 14px; }
  .tc-money::before { display: block; font-size: 12px; }
  .tc-price { grid-area: price; }
  .tc-disc { grid-area: disc; }
  .tc-total { grid-area: total; }
  .tc-dep { grid-area: dep; }
}

@media screen and (max-width: 760px) {
  .main { padding: 16px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); gap: 14px; }
  h1 { font-size: 24px; }
  .head-row { align-items: center; gap: 12px; }

  /* ---------- type floor + inputs ---------- */
  .table-head, .pill, .type-pill, .status-pill, .look-label, .field-label { font-size: 12px; }
  .input, .select, .select-sm, .input-sm, .search input, .sales-date { font-size: 16px; }
  /* Every field fills its column and never overflows it (iOS's date/time inputs did). */
  .input, .select, .select-sm, .input-sm { height: 44px; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; border-radius: 12px; padding-left: 14px; }
  select.select, select.select-sm { padding-right: 36px; }
  .search { height: 44px; flex: 1 1 100%; }
  .search input { align-self: stretch; }
  /* The pool's sort shares a row with Scan tag. */
  .sort { flex: 1 1 0; min-width: 0; }
  .btn-sm { height: 40px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }

  /* Filter chips: one swipeable row, edge to edge, never wrapping into a block. */
  .chips {
    flex: 1 1 100%; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-inline: -16px; padding: 2px 16px;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; white-space: nowrap; height: 40px; }

  /* ---------- payments ---------- */
  .pay-card { padding: 16px; gap: 14px; }
  .pay-title { font-size: 15px; }
  .pay-actions .btn { height: 48px; }
  .sk-pay .sk-look { flex: 1 1 100%; }
  .sk-pay .pay-actions .sk-btn { flex: 1 1 0; height: 48px; }
  .conf-head, .conf-filters { flex-direction: column; align-items: stretch; }
  .conf-filters .select { width: 100%; }
  .custom-range .input { flex: 1 1 0; min-width: 0; }
  .conf-section .footer-row .btn { flex: 1 1 100%; height: 44px; }

  /* ---------- staff ---------- */
  .card { padding: 16px; }
  .find, .hits { flex: 1 1 100%; }
  .hit .btn-sm { height: 44px; }


  /* ---------- promo codes ---------- */
  .promo-form { padding: 16px; }
  .promo-form .btn { height: 48px; }


  /* ---------- add items: a 2-up picker with a bar that is always in reach ---------- */
  .cand { padding: 10px; gap: 6px; }
  .cand-foot { align-items: flex-start; }
  .cand-name { overflow-wrap: anywhere; }
  .cand input { width: 26px; height: 26px; margin: 0; }
  .add-bar {
    position: sticky; bottom: 0; z-index: 5; flex-wrap: nowrap;
    margin: 0 -16px calc(-96px - env(safe-area-inset-bottom));
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--card); border-top: 1px solid var(--sidebar-rule);
  }
  .add-bar .btn { flex: 1 1 0; height: 48px; }
  .add-bar .btn-primary { flex-grow: 2; }

  /* ---------- print tags: a compact checklist; the A4 sheet itself is untouched ---------- */
  .tag-board { padding: 0; background: none; }
  .tag-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .tag-grid .tag {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "check name price" "check detail price";
    gap: 2px 12px; align-items: center; text-align: left; padding: 12px 14px; min-height: 64px;
    border: 1px solid var(--hairline); border-radius: 14px; background: var(--card);
  }
  .tag-grid .tag.is-off { opacity: 0.55; }
  .tag-grid .tag-check { position: static; grid-area: check; width: 24px; height: 24px; }
  .tag-grid .tag-brand, .tag-grid .tag-qr, .tag-grid .tag-line { display: none; }
  .tag-grid .tag-name { grid-area: name; overflow-wrap: anywhere; }
  .tag-grid .tag-detail { grid-area: detail; font-size: 13px; }
  .tag-grid .tag-price { grid-area: price; font-size: 20px; }
  .tag-buttons {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--card); border-top: 1px solid var(--sidebar-rule);
  }
  .tag-buttons .btn { flex: 1 1 0; height: 48px; }
  .main:has(.tag-buttons) { padding-bottom: calc(128px + env(safe-area-inset-bottom)); }
  .tag-grid .sk-tag { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
  .tag-grid .sk-qr { display: none; }

  /* ---------- sales ---------- */
  .seg-btn { height: 40px; }
  .sales-select { height: 44px; width: auto; flex: 1 1 0; }
  .sales-custom { flex: 1 1 100%; justify-content: stretch; }
  .sales-date-field { flex: 1 1 0; min-width: 0; }
  .sales-date { width: 100%; min-width: 0; height: 44px; }
  .sales-range-note { text-align: left; }
  .sales-csv { height: 44px; }
  .chart text { font-size: 12px; }
  .scroll-x { overflow: visible; }
  .panel .chips { margin-inline: -14px; padding-inline: 14px; }
  .week-table { min-width: 0; }
  .week-grid.table-head { display: none; }
  .week-grid [data-label]::before { content: attr(data-label) " "; color: var(--ink-2); font-weight: 600; }
  .week-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px 8px; padding: 12px 0;
    grid-template-areas: "day day day day orders" "market popup offline dod wow";
  }
  .week-grid:last-child { border-bottom: none; }
  .wc-day { grid-area: day; font-size: 14px; }
  .wc-orders { grid-area: orders; text-align: right; }
  .wc-market { grid-area: market; }
  .wc-popup { grid-area: popup; }
  .wc-offline { grid-area: offline; }
  .wc-dod { grid-area: dod; }
  .wc-wow { grid-area: wow; }
  .wc-market::before, .wc-popup::before, .wc-offline::before, .wc-dod::before, .wc-wow::before { display: block; font-size: 12px; }
  .tx-foot { flex-direction: column; align-items: stretch; }
  .tx-pager .btn { flex: 1 1 0; height: 44px; }

  /* ---------- dialogs: a bottom sheet, buttons stacked full width, the action at the bottom ---------- */
  .scrim { align-items: flex-end; padding: 0; }
  .dialog {
    max-width: none; border-radius: 20px 20px 0 0; gap: 12px;
    padding: 22px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .dialog-title { font-size: 20px; }
  .dialog-body { font-size: 15px; }
  .dialog-actions { flex-direction: column; gap: 10px; margin-top: 4px; }
  .dialog-actions .btn { width: 100%; height: 48px; font-size: 15px; }
  .rf-dialog { max-width: none; max-height: 92vh; border-radius: 20px 20px 0 0; padding: 0; gap: 0; }
  .rf-head, .rf-body, .rf-foot { padding-left: 18px; padding-right: 18px; }
  .rf-foot { flex-direction: column-reverse; }
  .rf-foot .btn { width: 100%; height: 48px; }
}

@media screen and (max-width: 1023px) and (prefers-reduced-motion: reduce) {
  .sidebar, html.drawer-open .sidebar { transition: none; }
}
