/*
 * HPAY point of sale (/hpay/pos). Layered on base.css, paylink.css and hpayTools.css: the same black and red, one accent, no new
 * palette, no new font.
 *
 * Direction (hartii-ui-craft, written before the code):
 *   subject    a counter terminal that takes QUAI for a price typed in dollars.
 *   audience   a shop owner or cashier on a phone or tablet, hands busy, a customer waiting; and the customer who scans the code.
 *   one job    type a price, show the code, know from the chain the moment the money has really arrived.
 *   mood       steady, exact, and loud only when the money is in.
 *   signature  the whole screen turns green and a check is drawn in dots, one dot after another, only when a payment is confirmed
 *              on the chain. Nothing on this page is green for any other reason.
 * Roles: red = the one primary action (Charge) and a payment being confirmed; green = money has arrived; amber = needs a look or
 * a storage warning; grey = over. Numbers use tabular figures. Spacing runs on 4 and 8. Touch targets are at least 44px, and the
 * keys and the Charge button at least 64px.
 */

.pos-wrap { max-width: var(--max); margin: 0 auto; padding-inline: var(--pad); }
.ht-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* once the shop is open the page header gets out of the way */
.pos-working .pl-page { padding-block: 22px 40px; }
.pos-working .ht-head h1 { font-size: 1.5rem; margin-top: 2px; }
.pos-working .ht-head .eyebrow { margin-bottom: 4px; }
.pos-working .ht-mark svg { width: 24px; height: auto; }

.pos-warn {
  margin: 12px 0 0; padding: 10px 14px; border-radius: 11px; font-size: 13px; line-height: 1.5;
  color: var(--warn); background: rgba(255, 176, 32, 0.08); border: 1px solid rgba(255, 176, 32, 0.35);
}
.pos-notice:empty { display: none; }

/* ---- first use ---- */
.pos-setup { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 20px 48px; align-items: start; }
.pos-how { padding-top: 32px; max-width: 460px; }
.pos-how h2 { font: 500 11px/1 var(--body); letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg-3); margin: 0 0 18px; }
.pos-how ol { list-style: none; margin: 0; padding: 0; counter-reset: how; display: grid; gap: 18px; }
.pos-how li { counter-increment: how; position: relative; padding-left: 44px; color: var(--fg-2); font-size: 14px; line-height: 1.6; }
.pos-how li::before { content: "0" counter(how); position: absolute; left: 0; top: 1px; font: 500 13px/1.6 var(--mono); color: var(--red-hi); }
.pos-how strong { display: block; color: var(--fg); font-weight: 600; font-size: 15px; }
.pos-setup .hp-state { color: var(--fg-3); font-size: 13px; margin: 10px 0 0; }
.pos-setup .hp-state.is-looking::before {
  content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 8px; background: var(--red); animation: pos-blink 1s steps(2, jump-none) infinite;
}
@keyframes pos-blink { 50% { opacity: 0.2; } }
.hp-resolved { margin-top: 12px; padding: 12px 14px; border-radius: 11px; border: 1px solid rgba(74, 222, 128, 0.3); display: grid; gap: 4px; }
.hp-resolved-tag { font: 500 11px/1 var(--body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ok); }
.hp-resolved-name { font: 600 20px/1.2 var(--display); }
.hp-resolved-addr { font: 400 12px/1.5 var(--mono); color: var(--fg-2); word-break: break-all; }
.pos-save, .pos-cancel { width: 100%; justify-content: center; min-height: 56px; margin-top: 14px; font-size: 16px; }
.pos-cancel { margin-top: 10px; }
.pos-save:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }

/* ---- the bar above the terminal ---- */
.pos-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 8px 0 4px; }
.pos-shop { font: 600 1.05rem/1.2 var(--display); letter-spacing: -0.01em; word-break: break-all; }
.pos-bar .ht-live { margin: 0; }
.pos-bar-actions { margin-left: auto; display: flex; gap: 8px; }
.pos-bar-actions .btn { min-height: 44px; justify-content: center; }

/* ---- the terminal: keypad and sale ---- */
.pos-grid { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 12px; }
.pos-pad, .pos-sale {
  border: 1px solid var(--line-2); border-radius: var(--r); padding: 18px;
  background: linear-gradient(160deg, rgba(25, 17, 19, 0.92), rgba(11, 7, 8, 0.82));
}

.pos-usd {
  margin: 0; text-align: right; font: 700 clamp(3rem, 11vw, 4.4rem)/1 var(--display); letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; word-break: break-all;
}
.pos-usd.is-zero { color: var(--fg-3); }
.pos-quai { margin: 8px 0 0; min-height: 1.5em; text-align: right; font: 400 14px/1.5 var(--mono); color: var(--fg-2); font-variant-numeric: tabular-nums; }
.pos-quai[data-state="loading"] { color: var(--fg-3); }
.pos-quai[data-state="error"] { color: var(--warn); }

.pos-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.pos-key {
  min-height: clamp(64px, 9.5vh, 84px); padding: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  font: 600 1.7rem/1 var(--display); color: var(--fg); font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.045); border: 1px solid var(--line-2); border-radius: 14px;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
.pos-key:hover { border-color: var(--red-hi); }
.pos-key:active { transform: scale(0.97); background: rgba(255, 78, 96, 0.16); }
.pos-key[data-key="back"] { font: 600 1rem/1 var(--body); letter-spacing: 0.04em; color: var(--fg-2); }

.pos-pad-tools { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 16px; margin-top: 10px; }
.pos-clear {
  min-height: 48px; padding: 0 4px; background: none; border: 0; cursor: pointer; font: 500 14px/1 var(--body); color: var(--fg-2);
  text-decoration: underline; text-underline-offset: 4px;
}
.pos-clear:hover { color: var(--fg); }
.pos-note-box { flex: 1 1 200px; margin-top: 0; border-top: 0; }
.pos-note-box > summary { min-height: 48px; }
.pos-note-box .pl-input { margin-top: 2px; }
.pos-charge-error { color: #ff8a8a; font-size: 13px; line-height: 1.5; margin-top: 6px; }
.pos-charge-error:empty { display: none; }
.pos-charge {
  width: 100%; justify-content: center; min-height: 72px; margin-top: 10px; border-radius: 14px;
  font: 700 1.35rem/1 var(--display); letter-spacing: -0.01em; font-variant-numeric: tabular-nums;
}
.pos-charge:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; transform: none; }

/* the sale on the counter */
.pos-hint { font: 600 1.25rem/1.3 var(--display); letter-spacing: -0.01em; }
.pos-idle .pl-help { margin-top: 10px; font-size: 13px; }
.pos-today { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: 10px; margin: 16px 0 8px; }
.pos-tile { margin: 0; padding: 14px 14px 12px; display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.025); }
/* The total of the day is money that gets read between two sales, so it is never cut across lines: the tiles wrap into rows instead. */
.pos-tile b { font: 700 clamp(1.1rem, 2.4vw, 1.6rem)/1 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos-tile span { font: 500 11px/1.3 var(--body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-3); white-space: nowrap; }
.pos-sale-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; }
.pos-sale-ref { font: 500 12px/1 var(--mono); letter-spacing: 0.12em; color: var(--fg-3); }
.pos-sale-head .ht-lock { margin: 0; }
.pos-sale-usd { margin: 10px 0 0; font: 700 clamp(2.6rem, 8vw, 3.6rem)/1 var(--display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.pos-sale-quai { margin: 6px 0 0; font: 400 1.15rem/1.3 var(--mono); color: var(--fg-2); font-variant-numeric: tabular-nums; }
.pos-soon { margin: 12px 0 0; padding: 10px 14px; border-radius: 11px; font-size: 14px; line-height: 1.5; color: var(--warn); background: rgba(255, 176, 32, 0.08); border: 1px solid rgba(255, 176, 32, 0.4); }
.pos-qr { display: flex; justify-content: center; margin: 16px 0 12px; transition: opacity 0.3s ease; }
.pos-qr.is-dim { opacity: 0.18; }
.pos-plate { display: inline-block; line-height: 0; padding: 8px; background: #fff; border-radius: 14px; max-width: 100%; }
.pos-plate canvas { display: block; max-width: 100%; }
.pos-link-box .pl-input { font-size: 12px; }
.pos-link-box .btn { min-height: 44px; justify-content: center; }
.pos-live #pos-status, .pos-live .ht-status { margin-top: 14px; }
.pos-new { width: 100%; justify-content: center; min-height: 56px; margin-top: 16px; font-size: 16px; }
.pos-live .pl-help { margin-top: 10px; }
.pos-live[data-clock="over"] .pos-sale-usd { color: var(--fg-2); }
.ht-lock.is-over { color: var(--warn); }

/* ---- the full screen Paid ---- */
html:has(dialog[open]) { overflow: hidden; }
.pos-paid {
  position: fixed; inset: 0; margin: 0; padding: 0; border: 0; max-width: none; max-height: none;
  width: 100vw; height: 100vh; height: 100dvh; background: var(--ok); color: #04210f;
}
.pos-paid[open] { display: grid; place-items: center; }
.pos-paid::backdrop { background: var(--ok); }
.pos-paid-inner { display: grid; justify-items: center; gap: 4px; padding: 24px var(--pad); text-align: center; max-width: 720px; }
.pos-paid-glyph { display: inline-flex; line-height: 0; color: #04210f; margin-bottom: 8px; }
.pos-paid-glyph svg { max-width: 60vw; height: auto; }
.pos-paid h2 { font: 700 clamp(4rem, 17vw, 8.5rem)/0.95 var(--display); letter-spacing: -0.04em; color: #04210f; margin: 0; }
.pos-paid-usd { margin: 8px 0 0; font: 700 clamp(2.4rem, 10vw, 4.6rem)/1 var(--display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.pos-paid-quai { margin: 6px 0 0; font: 500 1.3rem/1.3 var(--mono); font-variant-numeric: tabular-nums; }
.pos-paid-from { margin: 10px 0 0; font: 500 1rem/1.4 var(--body); opacity: 0.85; }
.pos-paid-actions { display: grid; justify-items: center; gap: 6px; margin-top: 28px; width: 100%; }
.pos-paid-new {
  min-height: 64px; width: min(100%, 420px); padding: 0 32px; cursor: pointer; border: 0; border-radius: 16px;
  font: 700 1.3rem/1 var(--display); background: #04210f; color: var(--ok);
}
.pos-paid-new:hover { background: #06310f; }
.pos-paid-new:focus-visible, .pos-paid-receipt:focus-visible { outline: 3px solid #04210f; outline-offset: 4px; }
.pos-paid-receipt { display: inline-flex; align-items: center; min-height: 48px; color: #04210f; font: 600 1rem/1 var(--body); text-underline-offset: 4px; }
@media (prefers-reduced-motion: no-preference) {
  .pos-paid[open] .pos-paid-inner > :not(.pos-paid-glyph) { animation: pos-rise 0.5s ease-out 0.15s backwards; }
  @keyframes pos-rise { from { opacity: 0; transform: translateY(14px); } }
}

/* ---- a sale paid while the shop looked elsewhere ---- */
/* The toast sits under the page header, not at the bottom: the Charge button is down there, and a cashier who taps it for the next customer must reach it. */
.pos-toast {
  position: fixed; left: 50%; top: 72px; bottom: auto; transform: translateX(-50%); z-index: 60; max-width: calc(100vw - 32px); pointer-events: none;
  padding: 14px 20px; border-radius: 14px; font: 600 15px/1.4 var(--body); color: var(--fg);
  background: var(--ink-800); border: 1px solid rgba(74, 222, 128, 0.5); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.pos-toast::before { content: ''; display: inline-block; width: 9px; height: 9px; margin-right: 10px; border-radius: 50%; background: var(--ok); }

/* ---- settings ---- */
.pos-settings {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  padding: 22px; color: var(--fg); background: var(--ink-850); border: 1px solid var(--line-2); border-radius: var(--r);
}
.pos-settings::backdrop { background: rgba(0, 0, 0, 0.72); }
.pos-settings h2 { font-size: 1.25rem; margin-bottom: 12px; }
.pos-settings .ht-field { margin-top: 18px; }
.pos-settings .ht-row { gap: 2px; padding: 10px 0; }
.pos-settings .ht-row dt, .pos-settings .ht-row dd { flex: 1 1 100%; min-width: 0; text-align: left; }
.pos-settings .btn { min-height: 48px; justify-content: center; }
.pos-settings-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.pos-settings-actions .btn { flex: 1 1 150px; }
.pos-danger { color: #ff8a8a; border-color: rgba(196, 30, 58, 0.5); }
.pos-danger:hover { border-color: #ff8a8a; }

/* ---- the log ---- */
.pos-log { margin-top: 36px; scroll-margin-top: 80px; }
.pos-log-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.pos-log-head h2 { font-size: 1.25rem; }
.pos-summary { flex: 1 1 260px; margin: 0; color: var(--fg-2); font: 400 13px/1.5 var(--mono); font-variant-numeric: tabular-nums; }
.pos-log-head .btn { min-height: 44px; justify-content: center; }
.pos-log-head .btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.pos-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 14px; }
.pos-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pos-chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px; cursor: pointer; font: 500 13px/1 var(--body); color: var(--fg-2);
  background: transparent; border: 1px solid var(--line-2);
}
.pos-chip:hover { border-color: var(--red-hi); color: var(--fg); }
.pos-chip[aria-pressed="true"] { color: var(--fg); background: rgba(255, 78, 96, 0.14); border-color: var(--red-hi); }
.pos-search { flex: 1 1 240px; max-width: 380px; font-family: var(--body); }
.pos-sortbox { display: none; align-items: center; gap: 10px; flex: 1 1 100%; }
.pos-sortbox label { font: 500 13px/1 var(--body); color: var(--fg-2); }
.pos-sortbox select { flex: 1 1 auto; min-height: 44px; font-family: var(--body); }
.pos-customer { margin: 0 0 12px; text-align: center; font-size: 14px; line-height: 1.5; color: var(--fg-2); }

.pos-table { width: 100%; margin-top: 12px; border-collapse: collapse; }
.pos-table th {
  text-align: left; padding: 0 12px 0 0; font: 500 11px/1 var(--body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-3);
  border-bottom: 1px solid var(--line-2);
}
.pos-table th button {
  min-height: 44px; padding: 0; background: none; border: 0; cursor: pointer; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit;
}
.pos-table th button:hover { color: var(--fg); }
.pos-table th[aria-sort="ascending"] button::after { content: " \2191"; }
.pos-table th[aria-sort="descending"] button::after { content: " \2193"; }
.pos-table th[aria-sort="ascending"], .pos-table th[aria-sort="descending"] { color: var(--fg); }
.pos-table th[data-col="usd"], .pos-table th[data-col="quai"] { text-align: right; }
.pos-table td { padding: 12px 12px 12px 0; vertical-align: middle; border-bottom: 1px solid var(--line); font-size: 14px; }
.pos-table .pos-num { text-align: right; font: 400 13px/1.4 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos-table .pos-when { font: 400 12px/1.4 var(--mono); color: var(--fg-2); font-variant-numeric: tabular-nums; }
.pos-table .pos-ref { font: 600 13px/1.3 var(--mono); white-space: nowrap; }
.pos-memo, .pos-sub { display: block; margin-top: 2px; font: 400 12px/1.4 var(--body); color: var(--fg-3); word-break: break-word; }
.pos-links { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; }
.pos-actions a, .pos-show { min-height: 44px; display: inline-flex; align-items: center; color: var(--fg); font: 500 13px/1 var(--body); text-underline-offset: 3px; }
.pos-show { padding: 0 14px; border-radius: 10px; cursor: pointer; background: transparent; border: 1px solid var(--line-2); }
.pos-show:hover { border-color: var(--red-hi); }

.pos-badge {
  display: inline-flex; align-items: center; gap: 7px; min-height: 28px; padding: 0 11px; border-radius: 999px;
  font: 600 12px/1 var(--body); color: var(--fg-2); border: 1px solid var(--line-2); white-space: nowrap;
}
.pos-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pos-badge[data-tone="paid"] { color: var(--ok); border-color: rgba(74, 222, 128, 0.4); background: rgba(74, 222, 128, 0.08); }
.pos-badge[data-tone="attention"], .pos-badge[data-tone="unchecked"] { color: var(--warn); border-color: rgba(255, 176, 32, 0.45); background: rgba(255, 176, 32, 0.08); }
.pos-badge[data-tone="wait"] { color: var(--fg); }
.pos-badge[data-tone="expired"] { color: var(--fg-3); }
.pos-empty { margin: 18px 0 0; padding: 22px 18px; text-align: center; color: var(--fg-2); border: 1px dashed var(--line-2); border-radius: var(--r); }
.pos-more { display: flex; margin: 16px auto 0; min-height: 48px; justify-content: center; }
.pos-foot { margin-top: 28px; max-width: 70ch; }


/* ---- a phone: one thing at a time ---- */
@media (max-width: 719px) {
  .pos-grid { grid-template-columns: minmax(0, 1fr); }
  .pos-work[data-view="sale"] .pos-pad { display: none; }
  .pos-work[data-view="pad"] .pos-sale { display: none; }
  .pos-pad, .pos-sale { padding: 14px 12px; }
  .pos-plate { padding: 8px; }
  .pos-bar-actions { margin-left: 0; width: 100%; }
  .pos-bar-actions .btn { flex: 1 1 0; }
  .pos-link-box .pl-input { flex-basis: 100%; }
  .pos-link-box .btn { flex: 1 1 0; }
  .pos:has(.pos-work[data-view="sale"]) .ht-head { display: none; }

  /* The column headings are not drawn on a phone, so their sort buttons must not be focusable either: a labelled list sorts instead. */
  .pos-table thead { display: none; }
  .pos-sortbox { display: flex; }
  .pos-table, .pos-table tbody { display: block; }
  .pos-table tr { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  .pos-table td { display: block; padding: 0; border: 0; min-width: 0; }
  .pos-table td::before { content: attr(data-label); display: block; margin-bottom: 4px; font: 500 10px/1 var(--body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-3); }
  .pos-table .pos-when, .pos-table .pos-actions { grid-column: 1 / -1; }
  .pos-table .pos-actions::before { display: none; }
  .pos-table .pos-num { text-align: left; white-space: normal; }
  .pos-tools .pos-search { max-width: none; flex-basis: 100%; }
}
@media (max-width: 860px) {
  .pos-setup { grid-template-columns: minmax(0, 1fr); }
  .pos-how { padding-top: 8px; }
}
@media (max-width: 480px) {
  .pos-keys { gap: 8px; }
  .pos-tile { padding: 12px 10px 10px; }
  .pos-tile b { font-size: 1.25rem; }
  .pos-paid h2 { font-size: clamp(3.6rem, 22vw, 6rem); }
}
@media print {
  .pos-paid, .pos-toast, #nav, .nav, .footer { display: none !important; }
}
