/* =====================================================================
   POS 888 — styles
   Flat + minimal, slate with a stock-green call to action.
   Tokens and rules: docs/DESIGN-SYSTEM.md
   ===================================================================== */

:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --fg: #0F172A;
  --fg-muted: #64748B;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  --primary: #334155;
  --primary-hover: #1E293B;
  --on-primary: #FFFFFF;
  --accent: #047857;
  --accent-hover: #065F46;
  --on-accent: #FFFFFF;
  --danger: #DC2626;
  --danger-hover: #B91C1C;
  --ring: #2563EB;

  --expired-fg: #B91C1C;  --expired-bg: #FEE2E2;
  --expiring-fg: #C2410C; --expiring-bg: #FFEDD5;
  --low-fg: #A16207;      --low-bg: #FEF9C3;
  --ok-fg: #15803D;       --ok-bg: #DCFCE7;
  --info-fg: #1D4ED8;     --info-bg: #DBEAFE;
  --off-fg: #475569;      --off-bg: #E2E8F0;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --touch: 48px;
  --touch-lg: 56px;
  --topbar-h: 60px;
  --sidebar-w: 248px;
  --shadow-float: 0 12px 32px -8px rgba(15, 23, 42, .28);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);

  /* z-index scale */
  --z-topbar: 20;
  --z-sidebar: 40;
  --z-scrim: 30;
  --z-dialog: 100;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .75rem; }

a { color: var(--ring); }
a:hover { color: var(--primary-hover); }

.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--fg-muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.icon { width: 20px; height: 20px; flex: 0 0 auto; }

:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 200;
  background: var(--primary); color: var(--on-primary);
  padding: 10px 16px; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------ top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-gap { flex: 1; }

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--fg); text-decoration: none; font-weight: 700;
  min-width: 0;
}
.brand:hover { color: var(--fg); }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: var(--radius);
  background: var(--primary); color: var(--on-primary);
  font-size: .72rem; letter-spacing: .04em;
}
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: var(--touch); height: var(--touch); padding: 0 10px;
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--fg); font: inherit; font-size: .9rem; cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }

.shop-chip {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--fg); text-decoration: none; font-weight: 600; font-size: .9rem;
  min-width: 0; max-width: 46vw;
}
.shop-chip:hover { border-color: var(--border-strong); color: var(--fg); }
.shop-chip.is-static { pointer-events: none; }
.shop-chip-code {
  background: var(--primary); color: var(--on-primary);
  border-radius: 4px; padding: 0 6px; font-size: .75rem; letter-spacing: .03em;
}
.shop-chip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop-chip-swap { width: 16px; height: 16px; color: var(--fg-muted); }

/* ------------------------------------------------------------ sidebar */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  z-index: var(--z-sidebar);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
}
.sidebar-head { display: none; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: var(--touch); padding: 0 14px;
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--fg); text-decoration: none; font: inherit; font-weight: 550;
  cursor: pointer; text-align: left;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--fg); }
.nav-item.is-active { background: var(--primary); color: var(--on-primary); }
.nav-item.is-active .icon { color: var(--on-primary); }
.nav-item .icon { color: var(--fg-muted); }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); display: grid; gap: 4px; }
.sidebar-foot form { margin: 0; }
.nav-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--fg); text-decoration: none; min-height: var(--touch);
}
.nav-user:hover, .nav-user.is-active { background: var(--surface-2); color: var(--fg); }
.nav-user-text { display: grid; line-height: 1.25; min-width: 0; }
.nav-user-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-text small { color: var(--fg-muted); }
.avatar {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 700;
}
.nav-logout { color: var(--danger); }
.nav-logout .icon { color: var(--danger); }

.nav-toggle { display: none; }
.scrim { display: none; }

/* ------------------------------------------------------------ main */
.main {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 20px) 24px 48px;
  max-width: calc(var(--sidebar-w) + 1280px);
  outline: none;
}

.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.page-title { display: grid; gap: 4px; min-width: 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back-link {
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--fg-muted); text-decoration: none; font-size: .9rem; min-height: 32px;
}
.back-link .icon { width: 18px; height: 18px; }

.tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tab {
  display: inline-flex; align-items: center; min-height: var(--touch);
  padding: 0 16px; color: var(--fg-muted); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab.is-active { color: var(--fg); border-bottom-color: var(--primary); }

/* ------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.card-narrow { max-width: 640px; }
.card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 16px;
}
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 16px 20px 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; display: grid; gap: 4px; min-width: 0;
}
.stat-label { color: var(--fg-muted); font-size: .875rem; font-weight: 550; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-hint { color: var(--fg-muted); font-size: .8rem; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-weight: 600; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  touch-action: manipulation;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.is-disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-lg { min-height: var(--touch-lg); padding: 0 24px; font-size: 1.05rem; }
.btn-block { width: 100%; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn-accent { background: var(--accent); color: var(--on-accent); }
.btn-accent:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--fg); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn-danger-ghost { background: var(--surface); color: var(--danger); border-color: #FCA5A5; }
.btn-danger-ghost:hover { background: var(--expired-bg); color: var(--danger-hover); }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: .9rem; }

/* ------------------------------------------------------------ forms */
.form { display: grid; gap: 18px; }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > label, .field-label { font-weight: 600; font-size: .95rem; }
.req { color: var(--danger); }
.hint { color: var(--fg-muted); font-size: .85rem; margin: 0; }

.input, .select, .textarea {
  width: 100%; min-height: var(--touch);
  padding: 10px 14px;
  font: inherit; font-size: 16px; color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .2);
}
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.input-lg { min-height: var(--touch-lg); font-size: 1.15rem; }
.input-code { text-transform: uppercase; letter-spacing: .04em; }

.field-error {
  display: flex; align-items: center; gap: 6px;
  color: var(--expired-fg); font-size: .875rem; font-weight: 550; margin: 0;
}
.field-error .icon { width: 16px; height: 16px; }

.input-wrap { position: relative; }
.input-wrap .input { padding-right: 52px; }
.input-wrap .icon-btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); }

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-actions .spacer { flex: 1; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 650; padding: 0; margin-bottom: 10px; }

/* toggle switch */
.toggle { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; min-height: var(--touch); padding: 6px 0; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track {
  flex: 0 0 auto; position: relative; width: 48px; height: 28px; margin-top: 2px;
  background: var(--border-strong); border-radius: 999px;
  transition: background-color .15s var(--ease);
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  background: #fff; border-radius: 50%;
  transition: transform .15s var(--ease);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--ring); outline-offset: 2px; }
.toggle-text { display: grid; gap: 2px; }
.toggle-label { font-weight: 600; }
.toggle-hint { color: var(--fg-muted); font-size: .85rem; }

/* choice cards (role picker, shop checklist) */
.choices { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice-box {
  display: grid; gap: 2px; min-height: var(--touch-lg);
  padding: 12px 14px 12px 44px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s var(--ease), background-color .15s var(--ease);
}
.choice-box::before {
  content: ""; position: absolute; left: 14px; top: 16px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--surface);
}
.choice input[type="checkbox"] + .choice-box::before { border-radius: 5px; }
.choice input:checked + .choice-box { border-color: var(--primary); background: var(--surface-2); }
.choice input:checked + .choice-box::before {
  border-color: var(--primary); background: var(--primary);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.choice input[type="checkbox"]:checked + .choice-box::before { box-shadow: none; background: var(--primary); }
.choice input[type="checkbox"]:checked + .choice-box::after {
  content: ""; position: absolute; left: 21px; top: 19px;
  width: 6px; height: 11px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.choice input:focus-visible + .choice-box { outline: 3px solid var(--ring); outline-offset: 2px; }
.choice input:disabled + .choice-box { opacity: .5; cursor: not-allowed; }
.choice-title { font-weight: 600; }
.choice-sub { color: var(--fg-muted); font-size: .85rem; }

/* ------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: 12px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-2); color: var(--fg-muted); font-size: .8rem; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.table tbody tr:hover { background: #FAFBFD; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: 4px; }
.row-title { font-weight: 600; }
.row-sub { color: var(--fg-muted); font-size: .85rem; }
.is-dim td { color: var(--fg-muted); }

/* ------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 650; white-space: nowrap; line-height: 1.6;
}
.badge-expired  { color: var(--expired-fg);  background: var(--expired-bg); }
.badge-expiring { color: var(--expiring-fg); background: var(--expiring-bg); }
.badge-low      { color: var(--low-fg);      background: var(--low-bg); }
.badge-ok       { color: var(--ok-fg);       background: var(--ok-bg); }
.badge-info     { color: var(--info-fg);     background: var(--info-bg); }
.badge-off      { color: var(--off-fg);      background: var(--off-bg); }
.badge-neutral  { color: var(--primary);     background: var(--surface-2); border: 1px solid var(--border); }
.badge-role-admin      { color: #fff; background: var(--primary); }
.badge-role-shopkeeper { color: var(--info-fg); background: var(--info-bg); }
.badge-role-accounts   { color: #6D28D9; background: #EDE9FE; }

/* ------------------------------------------------------------ alerts */
.flash-stack { display: grid; gap: 8px; margin-bottom: 8px; }
.flash-stack:empty { display: none; }
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid; font-weight: 550;
}
.alert > span { flex: 1; padding-top: 1px; }
.alert-success { color: var(--ok-fg); background: var(--ok-bg); border-color: #BBF7D0; }
.alert-error   { color: var(--expired-fg); background: var(--expired-bg); border-color: #FECACA; }
.alert-warning { color: var(--expiring-fg); background: var(--expiring-bg); border-color: #FED7AA; }
.alert-info    { color: var(--info-fg); background: var(--info-bg); border-color: #BFDBFE; }
.alert-close {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  width: 32px; height: 32px; margin: -6px -6px -6px 0; border-radius: var(--radius-sm);
  display: inline-grid; place-items: center;
}
.alert-close:hover { background: rgba(0, 0, 0, .06); }

/* ------------------------------------------------------------ misc */
.empty { display: grid; justify-items: center; gap: 10px; padding: 36px 16px; text-align: center; color: var(--fg-muted); }
.empty-icon { width: 40px; height: 40px; color: var(--border-strong); }
.empty p { margin: 0; max-width: 46ch; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.toolbar .field { flex: 1 1 180px; }
.toolbar .field-grow { flex: 3 1 260px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px; }
.pager-info { color: var(--fg-muted); font-size: .9rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; font-weight: 550; min-width: 0; overflow-wrap: anywhere; }

.notice {
  margin-bottom: 16px;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--info-bg); color: var(--info-fg); font-weight: 550;
}
.notice-warn { background: var(--expiring-bg); color: var(--expiring-fg); }

.secret {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--fg); color: #fff;
  font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ shop picker */
.pick-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.pick-card {
  display: grid; gap: 6px; text-align: left;
  min-height: 96px; padding: 18px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--fg); font: inherit; cursor: pointer;
  transition: border-color .15s var(--ease), background-color .15s var(--ease);
  width: 100%;
}
.pick-card:hover { border-color: var(--primary); background: var(--surface-2); }
.pick-card.is-current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pick-code { font-size: .8rem; font-weight: 700; color: var(--fg-muted); letter-spacing: .05em; }
.pick-name { font-size: 1.15rem; font-weight: 700; }

/* ------------------------------------------------------------ dialog */
.dialog {
  border: 0; padding: 0; border-radius: var(--radius-lg);
  width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow-float);
  color: var(--fg);
}
.dialog::backdrop { background: rgba(15, 23, 42, .5); }
.dialog-body { display: grid; gap: 12px; padding: 24px; justify-items: center; text-align: center; margin: 0; }
.dialog-icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--expiring-bg); color: var(--expiring-fg);
}
.dialog-icon .icon { width: 26px; height: 26px; }
.dialog-text { color: var(--fg-muted); margin: 0; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 8px; }

/* ------------------------------------------------------------ login / install */
.auth-body { display: grid; place-items: center; padding: 24px 16px; min-height: 100dvh; }
.auth-card {
  width: min(420px, 100%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 28px;
}
.auth-card-wide { width: min(640px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand .brand-mark { width: 44px; height: 44px; font-size: .8rem; }
.auth-brand h1 { font-size: 1.3rem; }
.auth-brand p { margin: 0; color: var(--fg-muted); font-size: .9rem; }
.auth-foot { margin-top: 16px; display: flex; justify-content: center; }
.check-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.check-list li { display: flex; align-items: center; gap: 8px; }
.check-list-spaced { margin: 10px 0 20px; }
.check-list .ok { color: var(--ok-fg); }
.check-list .bad { color: var(--expired-fg); }

/* ------------------------------------------------------------ placeholder */
.coming { display: grid; justify-items: center; gap: 12px; padding: 48px 16px; text-align: center; }
.coming .icon { width: 44px; height: 44px; color: var(--fg-muted); }
.coming p { color: var(--fg-muted); max-width: 52ch; margin: 0; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1023.98px) {
  .nav-toggle { display: inline-flex; }
  .sidebar {
    top: 0; width: min(300px, 86vw);
    transform: translateX(-102%);
    transition: transform .2s var(--ease);
    box-shadow: var(--shadow-float);
    padding-top: 8px;
  }
  .sidebar.is-open { transform: none; }
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px 10px; }
  .sidebar-title { font-weight: 700; }
  .scrim { display: block; position: fixed; inset: 0; z-index: var(--z-scrim); background: rgba(15, 23, 42, .45); }
  .scrim[hidden] { display: none; }
  .main { margin-left: 0; padding: calc(var(--topbar-h) + 16px) 16px 40px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767.98px) {
  h1 { font-size: 1.3rem; }
  .brand-name { display: none; }
  .lang-btn span { display: none; }
  .form-row, .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }

  /* Tables become stacked cards: each cell shows its column name. */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: var(--fg-muted); font-size: .85rem; text-align: left; font-weight: 550; }
  .table-stack td.cell-main { display: block; text-align: left; padding-bottom: 6px; }
  .table-stack td.cell-main::before { content: none; }
  .table-stack td.actions { justify-content: flex-start; padding-top: 10px; }
  .table-stack td.actions::before { content: none; }
  .table-stack td.actions .btn { margin: 0 6px 0 0; }
  .table-stack td.num { text-align: right; }
}

@media (max-width: 420px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .shop-chip-name { display: none; }
}

@media print {
  .topbar, .sidebar, .scrim, .page-actions, .tabs, .flash-stack, .skip-link { display: none !important; }
  .main { margin: 0; padding: 0; }
  body { background: #fff; }
}
.card > h2 + form, .card > h2 + .form, .card > h2 + .table-wrap, .card > h2 + .nav-list { margin-top: 16px; }

/* `hidden` must win over any display rule (.form is a grid). */
[hidden] { display: none !important; }
.card > [data-show-when] { margin-top: 18px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.setup-list { margin-top: 12px; }
.setup-list .is-done { color: var(--ok-fg); }

/* ------------------------------------------------------------ scan box */
.scanbox { display: grid; gap: 8px; }
.scanbox-label { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.scanbox-row { display: flex; gap: 8px; }
.scanbox-row .input { flex: 1; min-width: 0; font-size: 1.2rem; letter-spacing: .03em; }
@media (max-width: 520px) {
  .scanbox-row { flex-wrap: wrap; }
  .scanbox-row .input { flex-basis: 100%; }
  .scanbox-row .btn { flex: 1; }
}

/* ------------------------------------------------------------ camera overlay */
.cam {
  position: fixed; inset: 0; z-index: var(--z-dialog);
  background: rgba(2, 6, 23, .92);
  display: grid; place-items: center; align-content: center; gap: 16px;
  padding: 16px;
}
.cam-stage { position: relative; width: min(560px, 100%); aspect-ratio: 4 / 3; border-radius: var(--radius-lg); overflow: hidden; background: #000; }
.cam-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-frame {
  position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%;
  border: 3px solid rgba(255, 255, 255, .85); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .25);
  transition: border-color .15s var(--ease);
}
.cam.is-hit .cam-frame { border-color: #22C55E; }
.cam-hint { color: #E2E8F0; text-align: center; margin: 0; max-width: 40ch; }
.cam-close { min-width: 200px; }

/* ------------------------------------------------------------ products */
.thumb {
  width: 44px; height: 44px; border-radius: var(--radius-sm); object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border); flex: 0 0 auto;
}
.thumb-empty { display: inline-grid; place-items: center; color: var(--border-strong); }
.thumb-empty .icon { width: 22px; height: 22px; }
.prod-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.prod-cell > div { min-width: 0; }
.photo { width: 100%; max-width: 220px; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.tile {
  display: grid; gap: 2px; padding: 14px 16px; border-radius: var(--radius-lg);
  border: 1px solid var(--border); background: var(--surface); color: var(--fg); text-decoration: none;
  border-left-width: 6px; min-height: var(--touch-lg);
}
.tile:hover { color: var(--fg); border-color: var(--border-strong); }
.tile.is-active { box-shadow: inset 0 0 0 2px var(--primary); }
.tile-num { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-label { font-size: .85rem; font-weight: 600; color: var(--fg-muted); }
.tile-expired  { border-left-color: var(--danger); }
.tile-expiring { border-left-color: #EA580C; }
.tile-low      { border-left-color: #CA8A04; }
.tile-ok       { border-left-color: #16A34A; }
@media (max-width: 767.98px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.calc {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2);
}
.calc-label { color: var(--fg-muted); font-size: .85rem; }
.calc-value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.calc-value.is-neg { color: var(--expired-fg); }
.price-warn { color: var(--expired-fg); font-weight: 600; font-size: .9rem; }

.summary-row { display: flex; flex-wrap: wrap; gap: 12px 28px; align-items: flex-end; }
.summary-item { display: grid; gap: 2px; }
.summary-item .calc-value { font-size: 1.4rem; }
.badges-line { margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.disclosure { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 8px; }
.disclosure > summary {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--touch);
  cursor: pointer; font-weight: 600; color: var(--primary); list-style: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure[open] > summary { margin-bottom: 12px; }
.card > .disclosure:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.calc-value.is-neg { color: var(--expired-fg); }
.mt { margin-top: 16px; }
.toolbar-tight { margin: 0; gap: 8px; align-items: center; flex-wrap: nowrap; }
.card-pad { padding: 12px 20px 16px; margin: 0; }
a.prod-cell { color: var(--fg); text-decoration: none; }
a.prod-cell:hover .row-title { text-decoration: underline; }
a.prod-cell .row-title { color: var(--fg); }

/* =====================================================================
   POS sell screen
   ===================================================================== */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.pos-page .page-head { display: none; }
.pos-main { display: grid; gap: 12px; min-width: 0; }
.pos-scan { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; display: grid; gap: 8px; }
.pos-scan .input { font-size: 1.25rem; }
.pos-msg { margin: 0; min-height: 1.5em; font-weight: 600; color: var(--fg-muted); }
.pos-msg.is-ok { color: var(--ok-fg); }
.pos-msg.is-error { color: var(--expired-fg); }
.pos-msg a { margin-left: 6px; }

.pos-results { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: 8px; display: grid; gap: 6px; }
.results-head { margin: 4px 8px; color: var(--fg-muted); font-size: .9rem; font-weight: 600; }
.result {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left;
  min-height: var(--touch); padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font: inherit; color: var(--fg); cursor: pointer;
}
.result:hover { border-color: var(--primary); background: var(--surface-2); }
.result[disabled] { opacity: .45; cursor: not-allowed; }
.result-name { font-weight: 600; }
.result-meta { color: var(--fg-muted); font-size: .9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

.pos-cart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-height: 280px; }
.cart-list { list-style: none; margin: 0; padding: 0; }
.cart-line {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 110px 44px; gap: 12px; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.cart-line:last-child { border-bottom: 0; }
.cart-line.is-new { animation: line-in .6s var(--ease); }
@keyframes line-in { from { background: var(--ok-bg); } to { background: transparent; } }
.cl-name { display: grid; min-width: 0; }
.cl-name strong { overflow-wrap: anywhere; }
.cl-name span { color: var(--fg-muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.cl-total { font-weight: 700; font-size: 1.05rem; text-align: right; }
.cl-remove { color: var(--fg-muted); font-size: 1.1rem; }
.cl-remove:hover { color: var(--danger); }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.qty-btn { width: 44px; height: 44px; border: 0; background: var(--surface-2); font-size: 1.3rem; font-weight: 700; cursor: pointer; color: var(--fg); touch-action: manipulation; }
.qty-btn:hover { background: var(--border); }
.qty-btn[disabled] { opacity: .35; cursor: not-allowed; }
.qty-in { width: 52px; height: 44px; border: 0; text-align: center; font: inherit; font-weight: 700; font-size: 1.05rem; }
.qty-in:focus { outline: 2px solid var(--ring); outline-offset: -2px; }

.pos-side {
  position: sticky; top: calc(var(--topbar-h) + 16px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; display: grid; gap: 14px;
}
.totals { display: grid; gap: 6px; }
.tot-row { display: flex; justify-content: space-between; color: var(--fg-muted); }
.tot-discount { color: var(--ok-fg); }
.tot-total { display: flex; justify-content: space-between; align-items: baseline; border-top: 2px solid var(--fg); padding-top: 10px; margin-top: 4px; }
.tot-total span:first-child { font-weight: 700; font-size: 1.1rem; }
.tot-total .num { font-size: 2rem; font-weight: 800; }

.pay-methods legend { font-size: .9rem; color: var(--fg-muted); margin-bottom: 8px; }
.pay-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pay-opt { position: relative; cursor: pointer; }
.pay-opt:last-child { grid-column: span 2; }
.pay-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pay-opt span {
  display: flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 8px; text-align: center;
  border: 1px solid var(--border-strong); border-radius: var(--radius); font-weight: 650; background: var(--surface);
}
.pay-opt input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.pay-opt input:focus-visible + span { outline: 3px solid var(--ring); outline-offset: 2px; }

.cash-box { display: grid; gap: 8px; }
.cash-box > label { font-weight: 600; }
.cash-box .input.is-bad { border-color: var(--danger); }
.quick-cash { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.quick-cash .btn { padding: 0 4px; font-size: .85rem; }
.change { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px; border-radius: var(--radius); background: var(--ok-bg); color: var(--ok-fg); }
.change strong { font-size: 1.5rem; }
.change strong.is-neg { color: var(--expired-fg); }
.pay-btn { min-height: 64px; font-size: 1.2rem; }

.pos-bar { display: none; }
.dialog-left { justify-items: stretch; text-align: left; }
.choices-2 { grid-template-columns: 1fr 1fr; }
.dialog-actions-3 { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 860px) {
  .has-cart .pos-bar {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-topbar);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border);
  }
  .has-cart .main { padding-bottom: 96px; }
  .pos-bar strong { font-size: 1.3rem; margin-left: 6px; }
}

/* =====================================================================
   Receipt (screen + thermal print)
   ===================================================================== */
.mb { margin-bottom: 16px; }
.sale-done {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px;
  padding: 16px 18px; margin-bottom: 16px; border-radius: var(--radius-lg);
  background: var(--ok-bg); border: 1px solid #BBF7D0;
}
.sale-done-main { display: flex; align-items: center; gap: 12px; color: var(--ok-fg); }
.sale-done-icon { width: 40px; height: 40px; }
.sale-done-title { font-size: 1.3rem; font-weight: 800; }
.sale-done-change { font-size: 1.1rem; }
.sale-done-change strong { font-size: 1.6rem; }
.sale-done-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.receipt {
  position: relative; width: 80mm; max-width: 100%; margin: 0 auto; padding: 14px 12px;
  background: #fff; color: #000; border: 1px dashed var(--border-strong);
  font: 13px/1.4 ui-monospace, "Cascadia Mono", Consolas, "Courier New", "Microsoft YaHei", monospace;
}
.paper-58 .receipt { width: 58mm; font-size: 11px; }
.r-head { text-align: center; display: grid; gap: 2px; padding-bottom: 8px; border-bottom: 1px dashed #000; }
.r-biz { font-weight: 800; font-size: 1.15em; }
.r-shop { font-weight: 700; }
.r-pre { white-space: pre-line; }
.r-meta { padding: 6px 0; border-bottom: 1px dashed #000; }
.r-meta div, .r-totals div { display: flex; justify-content: space-between; gap: 8px; }
.r-items { width: 100%; border-collapse: collapse; margin: 4px 0; }
.r-items td { padding: 1px 0; vertical-align: top; }
.r-items td.r-name { padding-top: 4px; overflow-wrap: anywhere; }
.r-line td:first-child { padding-left: 10px; }
.r-totals { border-top: 1px dashed #000; padding-top: 6px; display: grid; gap: 1px; }
.r-totals div.r-grand { font-weight: 800; font-size: 1.25em; border-top: 1px solid #000; border-bottom: 1px solid #000; padding: 3px 0; margin: 3px 0; }
.r-foot { text-align: center; margin-top: 10px; padding-top: 6px; border-top: 1px dashed #000; }
.r-void { margin: 8px 0 0; font-weight: 700; }
.void-stamp {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg);
  border: 4px solid #B91C1C; color: #B91C1C; font-size: 28px; font-weight: 900; padding: 2px 14px; letter-spacing: .1em;
  opacity: .8; pointer-events: none;
}

@media print {
  .no-print, .sale-done, .form-actions, .page-head, .pos-bar { display: none !important; }
  .receipt-page .main { margin: 0; padding: 0; max-width: none; }
  .receipt { border: 0; margin: 0; padding: 0 2mm; width: auto; }
  @page { margin: 3mm; }
}

/* ---- POS gets the whole width: the menu becomes a drawer at every size ---- */
.pos-page .nav-toggle { display: inline-flex; }
.pos-page .main { margin-left: 0; max-width: none; padding-left: 16px; padding-right: 16px; }
.pos-page .sidebar {
  top: 0; width: min(300px, 86vw);
  transform: translateX(-102%);
  transition: transform .2s var(--ease);
  box-shadow: var(--shadow-float);
  padding-top: 8px;
}
.pos-page .sidebar.is-open { transform: none; }
.pos-page .sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px 10px; }
.pos-page .sidebar-title { font-weight: 700; }
.pos-page .scrim { display: block; position: fixed; inset: 0; z-index: var(--z-scrim); background: rgba(15, 23, 42, .45); }
.pos-page .scrim[hidden] { display: none; }

/* Lay the till out by the space it really has, not the screen size. */
.main { container-type: inline-size; container-name: main; }
.cart-line { grid-template-columns: minmax(120px, 1fr) auto minmax(84px, auto) 40px; }
@container main (max-width: 760px) {
  .pos { grid-template-columns: minmax(0, 1fr); }
  .pos-side { position: static; }
}
@container main (max-width: 520px) {
  .cart-line { grid-template-columns: minmax(0, 1fr) auto; }
  .cl-name { grid-column: 1 / -1; }
  .cl-remove { display: none; }
}

/* =====================================================================
   Reports & dashboard
   ===================================================================== */
:root { --chart: #2a78d6; --chart-hover: #1d5fae; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--chart); transition: fill .15s var(--ease); }
.chart .bar-row:hover .bar { fill: var(--chart-hover); }
.chart .hit { fill: transparent; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-label { fill: var(--fg); font-size: 13px; font-weight: 600; }
.chart-value { fill: var(--fg); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-tick { fill: var(--fg-muted); font-size: 11px; }
.chart-col { max-height: 260px; }

.section-title { font-size: 1rem; color: var(--fg-muted); margin: 4px 0 10px; }
.rank {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-2); font-size: .8rem; font-weight: 700; margin-right: 4px;
}

.report-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg-item { position: relative; cursor: pointer; }
.seg-item input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-item span { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 14px; font-weight: 600; border-right: 1px solid var(--border); }
.seg-item:last-child span { border-right: 0; }
.seg-item input:checked + span { background: var(--primary); color: var(--on-primary); }
.seg-item input:focus-visible + span { outline: 3px solid var(--ring); outline-offset: -3px; }
.period-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period-nav .btn { padding: 0 12px; }
.period-nav .input { width: auto; }
.period-label { font-weight: 700; margin-left: 4px; }
.shop-pick { position: relative; }
.shop-pick > summary { list-style: none; }
.shop-pick > summary::-webkit-details-marker { display: none; }
.shop-pick-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 260px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-float); padding: 8px; display: grid; gap: 2px;
}
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 8px; border-radius: var(--radius-sm); cursor: pointer; }
.check-row:hover { background: var(--surface-2); }
.check-row input { width: 20px; height: 20px; accent-color: var(--primary); }
.shop-pick-menu .hint { padding: 4px 8px; }

.print-only { display: none; }
@media print {
  .print-only { display: block; }
  .report-page .main { margin: 0; padding: 0; max-width: none; }
  .report-page .card { break-inside: avoid; border-color: #ccc; }
  .report-page .table-stack thead { display: table-header-group; }
  .report-page .table-stack, .report-page .table-stack tbody { display: table; width: 100%; }
  .report-page .table-stack tr { display: table-row; }
  .report-page .table-stack td { display: table-cell; }
  .report-page .table-stack td::before { content: none; }
  .no-print { display: none !important; }
  .chart .bar { fill: #444; }
}
