/* ============================================================
   Ledger POS - design system
   Every color, radius, font and shadow reads a CSS custom
   property that POS.theme.apply() derives from the store theme.
   The :root values below are the Emerald Light fallbacks so the
   page is styled before any JavaScript runs.

   Sections
     1. Tokens
     2. Reset & base
     3. Typography & utilities
     4. Login
     5. App shell (sidebar, bottom nav, page)
     6. Buttons
     7. Forms
     8. Cards & stats
     9. Tables
    10. Badges, chips, segmented, date presets
    11. Skeletons & empty states
    12. Modal, sheet, backdrop
    13. Toasts
    14. Menu
    15. Chart
    16. Views (sell redesigned; others ported)
    17. Responsive
    18. Print
    19. Reduced motion
   ============================================================ */

/* ---------------- 1. Tokens ---------------- */
:root {
  /* Theme (overwritten by POS.theme.apply / pre-paint cache) */
  --accent: #047857;
  --accent-hover: #046a4d;
  --accent-soft: #e1efeb;
  --accent-contrast: #ffffff;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #f5f6f6;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #bfc2c8;
  --success: #16a34a;
  --success-soft: #e3f4e9;
  --warning: #d97706;
  --warning-soft: #faefe1;
  --danger: #dc2626;
  --danger-soft: #fbe5e5;
  --danger-contrast: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);

  /* Static system tokens */
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sidebar-w: 240px;
  --sidebar-w-compact: 72px;
  --bottom-nav-h: 64px;
  --control-h: 40px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 150ms;
  --overlay: rgba(9, 12, 20, .5);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.12), 0 24px 48px -12px rgba(0,0,0,.28);
  --ring: 0 0 0 3px var(--accent-soft);
  --z-sidebar: 20;
  --z-bottom-nav: 30;
  --z-modal: 50;
  --z-menu: 70;
  --z-toast: 90;

  color-scheme: light;
}
:root[data-scheme="dark"] {
  color-scheme: dark;
  --overlay: rgba(0, 0, 0, .62);
}

/* ---------------- 2. Reset & base ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, p { margin: 0; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
::selection { background: var(--accent-soft); color: var(--text); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* #main receives script focus on route change / layer close (a landmark target, not a control);
   Chromium treats that as focus-visible after keyboard use, which ringed the whole page. */
#main:focus, #main:focus-visible { outline: none; }

/* ---------------- 3. Typography & utilities ---------------- */
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.profit-value { font-weight: 600; } /* profit/loss figures in report tables (stat tiles are already bold) */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.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;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* ---------------- 4. Login ---------------- */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; margin-bottom: 8px; }
.login-brand .brand-mark { width: 56px; height: 56px; font-size: 20px; border-radius: var(--radius); margin-bottom: 8px; }
.login-brand h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.login-brand p { font-size: 14px; }
.login-card .btn-primary { margin-top: 4px; }

/* ---------------- 5. App shell ---------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 12px;
  min-width: 0;
}
.brand-mark {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .02em;
  overflow: hidden;
}
.brand-mark.has-logo { background: var(--surface); border: 1px solid var(--border); }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
/* Dark themes: a light plate behind logo images (sidebar, login, settings previews) so dark or
   transparent logos stay visible. --text is the light foreground token there; initials are unaffected. */
:root[data-scheme="dark"] .brand-mark.has-logo img {
  padding: 3px;
  background: var(--text);
  border-radius: var(--radius-sm);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; min-width: 0; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-height: 0;
  margin: 0 -4px;
  padding: 0 4px;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 4px 10px 6px;
}
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link i { width: 20px; text-align: center; font-size: 16px; flex: none; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-link.active i { color: var(--accent); }
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--border);
  min-width: 0;
}
.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.user-meta { flex: 1; min-width: 0; line-height: 1.25; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role { font-size: 12px; color: var(--muted); text-transform: capitalize; }

/* Bottom nav (mobile only) */
.bottom-nav { display: none; }

/* Main & page */
.main {
  min-width: 0;
  padding: 28px 32px 40px;
}
.page { display: flex; flex-direction: column; gap: 20px; max-width: 1400px; margin: 0 auto; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 20px;
}
.page .page-head { margin-bottom: 0; }
.page-head h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* More sheet nav list */
.sheet-nav { display: flex; flex-direction: column; gap: 2px; }
.sheet-nav .nav-link { min-height: 48px; font-size: 15px; }
.sheet-nav .nav-link.active::before { display: none; }
.sheet-user { display: flex; align-items: center; gap: 10px; padding: 12px 10px 4px; border-top: 1px solid var(--border); margin-top: 8px; }

/* ---------------- 6. Buttons ---------------- */
.btn {
  --spinner: var(--text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-h);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  --spinner: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger {
  --spinner: var(--danger-contrast);
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-contrast);
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); filter: brightness(.92); }
.btn-ghost.is-danger, .btn-ghost.danger { color: var(--danger); }
.btn-ghost.is-danger:hover, .btn-ghost.danger:hover { background: var(--danger-soft); }

.btn.small, .btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn-lg { min-height: 52px; padding: 12px 22px; font-size: 16px; font-weight: 600; border-radius: var(--radius); }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: var(--control-h); min-width: var(--control-h); padding: 0; }
.btn-icon.small, .btn-icon.btn-sm { width: 32px; min-width: 32px; }

.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  border: 2px solid var(--spinner);
  border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 7. Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:not(.input-group), .field-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }

.input, .select, textarea.input,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
.field select, .field textarea,
.toolbar input[type="text"], .toolbar input[type="date"], .toolbar input[type="search"], .toolbar select {
  width: 100%;
  min-height: var(--control-h);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.toolbar input, .toolbar select { width: auto; }
.field textarea, textarea.input { min-height: 80px; resize: vertical; line-height: 1.45; }
.input::placeholder, .field input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .field input:hover, .field select:hover, .field textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus,
.field input:focus, .field select:focus, .field textarea:focus,
.toolbar input:focus, .toolbar select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.input:disabled, .select:disabled { opacity: .6; cursor: not-allowed; }
.select, .field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* Input with leading icon / trailing button */
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .input { padding-left: 38px !important; }
.input-group > .input-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
  font-size: 14px;
}
.input-group > .input.has-trailing { padding-right: 44px !important; }
.input-group > .input-trailing {
  position: absolute;
  right: 4px;
  width: 36px;
  min-width: 36px;
  min-height: 32px;
  color: var(--muted);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Checkbox & switch */
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color var(--dur) var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }

/* ---------------- 8. Cards & stats ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h3 { margin: 0; }
.card-flush { padding: 0; overflow: hidden; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.page .stat-grid { margin-bottom: 0; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
}
.stat .s-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat .s-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .s-sub { font-size: 13px; color: var(--muted); }

/* ---------------- 9. Tables ---------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card > .table-wrap:only-child { margin: -4px 0; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  white-space: nowrap;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background-color var(--dur) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num, .table th.num { text-align: right; }
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; width: 1%; }

.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

/* ---------------- 10. Badges, chips, segmented ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid transparent;
}
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
:root[data-scheme="light"] .badge-ok,
:root:not([data-scheme]) .badge-ok { color: color-mix(in srgb, var(--success) 75%, var(--text)); }
:root[data-scheme="light"] .badge-warn,
:root:not([data-scheme]) .badge-warn { color: color-mix(in srgb, var(--warning) 70%, var(--text)); }

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 2px 4px;
  margin-bottom: 14px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chip:hover { border-color: var(--border-strong); }
.chip.active, .chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.segmented {
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
  padding: 3px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.segmented::-webkit-scrollbar { display: none; }
.segmented-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 14px;
  border: 0;
  border-radius: max(calc(var(--radius-sm) - 3px), 0px);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.segmented-btn:hover { color: var(--text); }
.segmented-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border);
}
.segmented-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

.date-presets { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; min-width: 0; max-width: 100%; }
.date-presets-seg { min-width: 0; max-width: 100%; }
.date-custom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-custom label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.date-custom .input { width: auto; min-height: 38px; font-size: 14px; }

/* ---------------- 11. Skeletons & empty states ---------------- */
.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-line { height: 12px; }
.skeleton-line.lg { height: 26px; width: 60%; }
.skeleton-line.sm { width: 40%; }
.skeleton-stat { gap: 10px; }
.skeleton-table { display: flex; flex-direction: column; }
.skeleton-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 16px; padding: 14px 4px; border-bottom: 1px solid var(--border); }
.skeleton-row:last-child { border-bottom: 0; }
.skeleton-tile { min-height: 120px; border-radius: var(--radius); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 40px 20px;
}
.empty-icon {
  width: 52px;
  height: 52px;
  margin-bottom: 8px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 20px;
}
.empty h3 { font-size: 16px; font-weight: 600; margin: 0; }
.empty p { color: var(--muted); font-size: 14px; max-width: 360px; }
.empty .btn { margin-top: 10px; }

/* ---------------- 12. Modal, sheet, backdrop ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--overlay);
  animation: fade-in var(--dur) ease-out;
}
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 180ms var(--ease);
}
.modal-lg { max-width: 760px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.modal-close { color: var(--muted); margin-right: -6px; }
.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 24px;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-footer:empty { display: none; }
.confirm-message { color: var(--muted); font-size: 14px; }

.sheet-backdrop { align-items: flex-end; padding: 0; }
.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  max-height: 88dvh;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: sheet-in 220ms var(--ease);
}
.sheet::before {
  content: "";
  align-self: center;
  width: 40px;
  height: 4px;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--border-strong);
}
.sheet .modal-head { padding-top: 10px; }
.sheet .modal-body { padding: 12px 16px 20px; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }

/* ---------------- 13. Toasts ---------------- */
.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--success);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  animation: toast-in 200ms var(--ease);
}
.toast i { margin-top: 2px; color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-error i { color: var(--danger); }
.toast-info { border-left-color: var(--accent); }
.toast-info i { color: var(--accent); }
.toast.is-leaving { opacity: 0; transform: translateY(-4px); transition: opacity 180ms ease, transform 180ms ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------------- 14. Menu ---------------- */
.menu {
  position: fixed;
  z-index: var(--z-menu);
  min-width: 190px;
  max-width: 280px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  animation: fade-in 120ms ease-out;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 0;
  border-radius: max(calc(var(--radius-sm) - 3px), 0px);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
}
.menu-item i { width: 16px; text-align: center; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.danger, .menu-item.danger i { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-soft); }

/* ---------------- 15. Chart ---------------- */
.chart { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-grid.base { stroke: var(--border-strong); }
.chart-bar { fill: var(--accent); transition: fill var(--dur) var(--ease); }
.chart-bar:hover { fill: var(--accent-hover); }
.chart-label { font-size: 10px; fill: var(--muted); font-family: var(--font); }
.chart-max { font-size: 10px; fill: var(--muted); font-family: var(--font); font-weight: 600; }

/* ---------------- 16. Views ---------------- */
/* ============ Sell (register) ============ */
.sell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  align-items: start;
  max-width: 1600px;
  margin: 0 auto;
}
.sell-main { min-width: 0; }

/* Search */
.sell-search { position: relative; display: flex; align-items: center; }
.sell .sell-search-input {
  min-height: 52px;
  padding: 12px 48px 12px 46px;
  border-radius: var(--radius);
  font-size: 16px;
  box-shadow: var(--shadow);
}
.sell-search-icon, .sell-search-scan {
  position: absolute;
  color: var(--muted);
  pointer-events: none;
  font-size: 16px;
}
.sell-search-icon { left: 17px; }
.sell-search-scan { right: 17px; font-size: 18px; opacity: .75; }
.sell-shortcuts {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--muted);
}
.sell-shortcuts kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-right: 4px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
}
.sell-chips { margin: 14px 0 16px; }

/* Tiles */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.tile-grid > .skeleton-tile { min-height: 138px; }
.tile-empty { grid-column: 1 / -1; }
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-height: 138px;
  padding: 12px;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--dur) var(--ease), transform 100ms ease, box-shadow var(--dur) var(--ease);
}
.tile:hover:not(:disabled) { border-color: var(--accent); }
.tile:active:not(:disabled) { transform: scale(.97); }
.tile:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.tile:disabled { cursor: not-allowed; box-shadow: none; }
.tile.is-out .tile-badge, .tile.is-out .tile-name, .tile.is-out .tile-price { opacity: .45; }
.tile-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
/* Category tint: hue from a hash of the category (set inline as --h) */
.tile-badge {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, hsl(var(--h, 160) 65% 60%) 22%, var(--surface));
  color: hsl(var(--h, 160) 50% 28%);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .02em;
}
:root[data-scheme="dark"] .tile-badge {
  background: color-mix(in srgb, hsl(var(--h, 160) 65% 60%) 24%, var(--surface));
  color: hsl(var(--h, 160) 75% 82%);
}
.tile-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.tile-price { margin-top: auto; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.stock-chip {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stock-chip.ok { color: var(--muted); background: var(--surface-2); }
.stock-chip.warn { color: var(--warning); background: var(--warning-soft); }
.stock-chip.danger { color: var(--danger); background: var(--danger-soft); }
:root:not([data-scheme="dark"]) .stock-chip.warn { color: color-mix(in srgb, var(--warning) 70%, var(--text)); }
.tile--pulse { animation: tile-pulse 300ms var(--ease); }
@keyframes tile-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
  50% { transform: scale(.97); }
  100% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 0%, transparent); }
}

/* Cart panel (desktop/tablet) and cart sheet (mobile) share this markup */
.cart {
  display: flex;
  flex-direction: column;
  min-height: 0;
  font-size: 14px;
}
.card.cart {
  position: sticky;
  top: 28px;
  max-height: calc(100vh - 56px);
  max-height: calc(100dvh - 56px);
  padding: 0;
  overflow: hidden;
}
.cart-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.cart-title { margin: 0; font-size: 16px; font-weight: 600; }
.cart-clear { margin-left: auto; }
.cart-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.cart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}
.cart-empty i { font-size: 26px; opacity: .6; }
.cart-lines { list-style: none; margin: 0; padding: 0; }
.cart-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 10px;
  padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.cart-line:last-child { border-bottom: 0; }
.cart-line-info { min-width: 0; }
.cart-line-name { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.cart-line-each { font-size: 12.5px; color: var(--muted); }
.cart-line-remove { color: var(--muted); align-self: start; }
.cart-line-remove:hover { color: var(--danger); background: var(--danger-soft); }
.cart-line-total { text-align: right; font-weight: 700; font-size: 15px; padding-right: 6px; }
.stepper {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.stepper-btn {
  width: 40px;
  height: 38px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  transition: background-color var(--dur) var(--ease);
}
.stepper-btn:hover { background: var(--surface-2); }
.stepper-btn[aria-disabled="true"] { color: var(--muted); }
.stepper-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.stepper-qty {
  min-width: 34px;
  text-align: center;
  font-weight: 600;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  line-height: 38px;
}
.cart-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.cart-discount { min-height: 32px; display: flex; align-items: center; }
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.cart-discount-form { display: flex; align-items: center; gap: 6px; width: 100%; }
.cart .discount-input { flex: 1; min-width: 0; min-height: 36px; padding: 6px 10px; font-size: 14px; text-transform: uppercase; }
.cart .discount-input::placeholder { text-transform: none; }
.discount-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 10px;
  border-radius: 999px;
  background: var(--success-soft);
  color: color-mix(in srgb, var(--success) 75%, var(--text));
  font-weight: 600;
  font-size: 13px;
}
:root[data-scheme="dark"] .discount-chip { color: var(--success); }
.discount-chip-remove {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
}
.discount-chip-remove:hover { background: color-mix(in srgb, var(--success) 18%, transparent); }
.cart-summary { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.cart-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.cart-row dt, .cart-row dd { margin: 0; }
.cart-row dd { color: var(--text); }
.cart-row.is-discount dd { color: var(--success); }
.cart-row.is-total { margin-top: 4px; padding-top: 8px; border-top: 1px dashed var(--border-strong); color: var(--text); font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.cart-charge { font-variant-numeric: tabular-nums; }

/* Mobile sheet variant: the sheet supplies the title and scrolls as a whole */
.cart--sheet .cart-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.cart--sheet .cart-head { padding: 0 0 10px; }
.cart--sheet .cart-line { padding-left: 2px; padding-right: 0; }
.cart--sheet .cart-body { overflow: visible; }
.cart--sheet .cart-foot { padding: 12px 0 4px; position: sticky; bottom: 0; }

/* Floating cart bar (mobile only) */
.cart-bar { display: none; }

/* Payment modal */
.pay { display: flex; flex-direction: column; gap: 16px; }
.pay-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.pay-total-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pay-total-value { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.pay-methods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pay-method {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 72px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.pay-method i { font-size: 20px; color: var(--muted); }
.pay-method:hover { border-color: var(--border-strong); }
.pay-method[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
  font-weight: 600;
}
.pay-method[aria-pressed="true"] i { color: var(--accent); }
.pay-cash { display: flex; flex-direction: column; gap: 10px; }
.pay .pay-tendered { min-height: 50px; font-size: 20px; font-variant-numeric: tabular-nums; }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; }
.quick-cash-chip {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}
.quick-cash-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.pay-change {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
}
.pay-change-label { font-weight: 600; }
.pay-change-value { font-size: 26px; font-weight: 700; color: var(--text); }
.pay-change.is-ok { background: var(--success-soft); }
.pay-change.is-ok .pay-change-value, .pay-change.is-ok .pay-change-label { color: var(--success); }
.pay-change.is-short { background: var(--danger-soft); }
.pay-change.is-short .pay-change-value, .pay-change.is-short .pay-change-label { color: var(--danger); }
:root:not([data-scheme="dark"]) .pay-change.is-ok .pay-change-value,
:root:not([data-scheme="dark"]) .pay-change.is-ok .pay-change-label { color: color-mix(in srgb, var(--success) 75%, var(--text)); }

/* Checkout success */
.pay-success { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 6px 0 2px; }
.pay-success-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 28px;
  animation: modal-in 240ms var(--ease);
}
/* Live region: only the outcome lines, not the actions or receipt preview */
.pay-success-status { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pay-success-title { font-size: 20px; font-weight: 700; }
.pay-success-receipt { color: var(--muted); }
.pay-success-receipt strong { color: var(--text); }
.pay-success-change { display: flex; flex-direction: column; align-items: center; gap: 0; margin-top: 4px; }
.pay-success-change span { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pay-success-change strong { font-size: 34px; letter-spacing: -0.02em; line-height: 1.2; }
.pay-success-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin-top: 10px; }
.pay-receipt { width: 100%; text-align: left; margin-top: 4px; }
.pay-receipt summary { cursor: pointer; padding: 6px 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.pay-receipt summary:hover { color: var(--text); }
.pay-receipt .print-receipt { margin-top: 6px; }
.print-only { display: none; }

/* Sell: tablet */
@media (min-width: 768px) and (max-width: 1099.98px) {
  .sell { grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
  .card.cart { top: 24px; max-height: calc(100dvh - 48px); }
  .sell-shortcuts { display: none; }
  .sell-chips { margin-top: 12px; }
}

/* Sell: mobile */
@media (max-width: 767.98px) {
  .sell { grid-template-columns: minmax(0, 1fr); }
  .sell.has-cart-bar { padding-bottom: 76px; }
  .sell-shortcuts, .card.cart { display: none; }
  .sell-chips { margin: 12px -16px 12px; padding-left: 16px; padding-right: 16px; }
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .tile { min-height: 128px; }
  .cart-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 10px);
    z-index: var(--z-bottom-nav);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
    padding: 8px 8px 8px 16px;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-contrast);
    box-shadow: var(--shadow-lg);
    text-align: left;
    animation: sheet-in 200ms var(--ease);
  }
  .cart-bar-info { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; font-size: 15px; }
  .cart-bar-count { white-space: nowrap; }
  .cart-bar-action {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--accent-contrast) 16%, transparent);
    font-weight: 600;
    font-size: 14px;
  }
  .cart-bar:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
  body:has(.sell.has-cart-bar):not(:has(.modal-backdrop)) .toast-stack { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 76px); }
  .pay-total-value { font-size: 32px; }
  .pay-method { min-height: 64px; }
}

/* Printable receipt */
.receipt-rule { border: 0; border-top: 1px dashed var(--border-strong); margin: 12px 0; }
.print-receipt {
  font-family: var(--mono);
  font-size: 13px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.print-receipt .pr-center { text-align: center; }
.print-receipt table { width: 100%; border-collapse: collapse; }
.print-receipt td { padding: 2px 0; }
.print-receipt .pr-right { text-align: right; }

/* Dashboard */
.dash-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.dash-grid-full { grid-column: 1 / -1; }

/* Reusable horizontal share-bar (dashboard payment methods + top products; reused by Reports) */
.share-bars { display: flex; flex-direction: column; gap: 14px; }
.share-bar { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.share-bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; }
.share-bar-label { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-bar-meta { display: inline-flex; gap: 6px; align-items: baseline; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
.share-bar-pct { font-weight: 600; color: var(--text); }
.share-bar-track { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.share-bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }

/* Top products ranked list */
.rank-list { display: flex; flex-direction: column; gap: 14px; list-style: none; padding: 0; margin: 0; }
.rank-item { display: flex; align-items: flex-start; gap: 12px; }
.rank-item .share-bar { flex: 1; }
.rank-num {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.rank-item:first-child .rank-num { background: var(--accent-soft); color: var(--accent); }

/* Low-stock list */
.dash-list { display: flex; flex-direction: column; list-style: none; padding: 0; margin: 0; }
.dash-list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.dash-list-item:last-child { border-bottom: none; }
.dash-list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.dash-list-link { flex: none; font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.dash-list-link:hover { text-decoration: underline; }

/* Products */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.page > .toolbar { margin-bottom: 0; }
.toolbar label.small { display: inline-flex; align-items: center; gap: 6px; }
.margin-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.margin-preview-val { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.card[tabindex="-1"]:focus { outline: none; }

.products-toolbar .products-search { flex: 1 1 260px; max-width: 380px; }
.products-toolbar .products-search .input { width: 100%; }
.products-toolbar .products-category { min-width: 170px; max-width: 240px; }
.products-table { min-width: 680px; }
.prod-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.prod-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}
.prod-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.prod-name { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.prod-sku { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.table tr.is-archived .prod-avatar { background: var(--surface-2); color: var(--muted); }
.table tr.is-archived .prod-name { color: var(--muted); }

/* Product & stock modals */
.form-section { display: flex; flex-direction: column; gap: 12px; }
.form-section + .form-section { padding-top: 16px; border-top: 1px solid var(--border); }
.form-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.margin-pill-wrap { display: inline-flex; align-items: center; gap: 10px; }
.margin-pill-wrap .badge { font-size: 13px; padding: 3px 11px; }
.form-static { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; min-height: var(--control-h); padding-top: 8px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.stock-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.stock-summary strong { font-size: 18px; }
.qty-stepper { display: flex; align-items: stretch; gap: 8px; }
.qty-stepper .input { flex: 1; min-width: 0; text-align: center; font-size: 16px; }
.qty-stepper .btn-icon { flex: none; }
.stock-preview {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
}
.stock-preview strong { font-size: 18px; }
/* Warn, not error: the preview uses the loaded stock; the server check is authoritative */
.stock-preview.is-negative { background: var(--warning-soft); border-color: transparent; }
.stock-preview.is-negative strong { color: var(--warning); }
:root:not([data-scheme="dark"]) .stock-preview.is-negative strong { color: color-mix(in srgb, var(--warning) 70%, var(--text)); }

/* Sales */
.sales-toolbar { align-items: flex-start; }
.sales-toolbar > #sales-range { min-width: 0; max-width: 100%; }
.range-hint { display: flex; align-items: center; gap: 6px; min-height: 38px; font-size: 13px; font-weight: 500; color: var(--danger); }
.sales-table { min-width: 720px; }
.receipt-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
.receipt-no { font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.sale-pay { display: inline-flex; align-items: center; gap: 7px; }
.sale-pay i { width: 16px; text-align: center; color: var(--muted); }
.table tr.is-refunded td:not(:first-child):not(.actions) { color: var(--muted); }
.table tr.is-refunded td strong { text-decoration: line-through; font-weight: 500; }
.sales-list .pagination { justify-content: space-between; }
.pagination-btns { display: inline-flex; align-items: center; gap: 8px; }
/* Invalid custom range: rows still belong to the previous range */
#sales-table.is-stale { opacity: .55; transition: opacity var(--dur) var(--ease); }
.pagination-page { min-width: 44px; text-align: center; }

/* Reports */
.report-filters { margin-bottom: 16px; }
.report-filters-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.report-filters-row #rpt-period { flex: none; }
.report-filters-row > #rpt-range { min-width: 0; max-width: 100%; } /* lets the preset strip scroll instead of widening the page on phones */
.report-tabs { margin-bottom: 20px; }
.report-tabs .segmented { max-width: 420px; }
.report-section { display: flex; flex-direction: column; gap: 16px; }
.report-section .stat-grid { margin-bottom: 0; }

/* Discounts */
.discounts-table { min-width: 640px; }
.code-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 2px 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.code-pill-text { font-size: 13px; font-weight: 600; letter-spacing: .01em; }
.usage-cell { display: flex; flex-direction: column; gap: 4px; min-width: 72px; }
.usage-bar {
  display: block;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.usage-bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.usage-bar-fill.is-full { background: var(--danger); }

/* Users */
.users-table { min-width: 560px; }
.usr-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.usr-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}
.usr-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.usr-name { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.usr-username { font-size: 12px; color: var(--muted); }

/* Settings */
.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}
.settings-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.settings-aside { position: sticky; top: 20px; min-width: 0; }
#set-appearance > .card-head { flex-wrap: wrap; align-items: flex-start; }
.settings-block { padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--border); }
.settings-subhead {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Receipt card */
.receipt-settings { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 260px); gap: 16px; align-items: start; }
.receipt-sample-wrap { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.receipt-sample { font-size: 12px; padding: 12px; overflow-wrap: anywhere; }

/* Preset gallery */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.preset-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.preset-card:hover { border-color: var(--border-strong); }
.preset-card:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.preset-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.preset-swatch {
  display: flex;
  align-items: flex-end;
  height: 52px;
  padding: 8px 8px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.preset-swatch-panel {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid;
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.preset-swatch-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; }
.preset-swatch-line { flex: 1; height: 4px; border-radius: 2px; opacity: .85; }
.preset-name { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 13px; font-weight: 600; padding: 0 2px; }
.preset-card[aria-pressed="true"] .preset-name::after {
  content: "\f00c";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 11px;
  color: var(--accent);
}

/* Logo */
.logo-row { display: flex; align-items: flex-start; gap: 12px; }
.logo-preview { width: 44px; height: 44px; font-size: 15px; }
.logo-field { flex: 1; }
.logo-field .field-hint.text-danger { color: var(--danger); }
.logo-field .field-hint.text-warning { color: var(--warning); }
:root[data-scheme="light"] .logo-field .field-hint.text-warning { color: color-mix(in srgb, var(--warning) 70%, var(--text)); }

/* Colors */
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 16px; margin-bottom: 8px; }
.color-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.color-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.color-label { font-size: 14px; font-weight: 500; }
.color-meta .field-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.color-pick {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.color-pick::-webkit-color-swatch-wrapper { padding: 0; }
.color-pick::-webkit-color-swatch { border: 0; border-radius: 4px; }
.color-pick::-moz-color-swatch { border: 0; border-radius: 4px; }
.color-pick:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.input.color-hex { flex: none; width: 104px; font-size: 14px; }
.input.is-invalid, .field input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus, .field input.is-invalid:focus { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* Radius slider */
.range { width: 100%; height: var(--control-h); accent-color: var(--accent); cursor: pointer; }
.range-value { margin-left: 6px; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Contrast guard */
.contrast-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: 0 0 8px; padding: 0; }
.contrast-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--text);
  font-size: 13px;
}
.contrast-item i { color: var(--warning); margin-top: 2px; }
.contrast-ok { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.contrast-ok i { color: var(--success); }

/* Live preview */
.theme-preview .card-head { flex-wrap: wrap; gap: 2px 12px; }
.tp-canvas {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  pointer-events: none;
  user-select: none;
}
.tp-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
/* Undo the compact-sidebar (tablet) rules for the preview copies of shell classes */
.theme-preview .brand { justify-content: flex-start; padding: 2px 4px 8px; }
.theme-preview .brand-name { display: block; }
.theme-preview .nav-link { width: auto; height: auto; justify-content: flex-start; padding: 8px 10px; }
.theme-preview .nav-link .nav-label { display: inline; }
.theme-preview .nav-link.active::before { left: -4px; }
.tp-card { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.tp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tp-card .table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tp-card .table th { position: static; }

/* Sticky save bar */
.save-bar { position: sticky; bottom: 16px; z-index: 15; }
.save-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px 10px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: save-bar-in var(--dur) var(--ease);
}
.save-bar-text { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.save-bar-text i { color: var(--accent); }
.save-bar-actions { display: flex; gap: 8px; margin-left: auto; }
@keyframes save-bar-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 1099.98px) {
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-aside { position: static; }
  .tp-canvas { flex-direction: row; align-items: flex-start; }
  .tp-side { flex: 0 0 200px; }
  .tp-card { flex: 1; min-width: 0; }
}
@media (max-width: 767.98px) {
  .receipt-settings { grid-template-columns: minmax(0, 1fr); }
  .tp-canvas { flex-direction: column; align-items: stretch; }
  .tp-side { flex: none; }
  .color-grid { grid-template-columns: minmax(0, 1fr); }
  .save-bar { bottom: calc(var(--bottom-nav-h) + 10px + env(safe-area-inset-bottom, 0px)); }
  .save-bar-inner { padding: 10px 12px; }
  .save-bar-text { font-size: 13px; }
  .save-bar-actions { flex: 1; }
  .save-bar-actions .btn { flex: 1; }
}

/* ---------------- 17. Responsive ---------------- */
@media (pointer: coarse) {
  :root { --control-h: 44px; }
  .segmented-btn { min-height: 38px; }
  .chip { min-height: 40px; }
}

/* Tablet: 768-1099px - icon-only sidebar with tooltips */
@media (min-width: 768px) and (max-width: 1099.98px) {
  .app { grid-template-columns: var(--sidebar-w-compact) minmax(0, 1fr); }
  .sidebar { padding: 14px 10px; align-items: center; }
  .brand { padding: 2px 0 10px; justify-content: center; }
  .brand-name, .nav-group-label, .nav-label, .user-meta { display: none; }
  /* Scrolls on short landscape tablets so sign-out stays reachable; tooltips are
     rendered outside it (.rail-tooltip, positioned by app.js) so they aren't clipped */
  .sidebar-nav {
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
    align-items: center;
    margin: 0 -10px;
    padding: 0 10px;
    gap: 10px;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-group { align-items: center; }
  .nav-group + .nav-group { border-top: 1px solid var(--border); padding-top: 10px; }
  .nav-link { width: 48px; height: 44px; justify-content: center; padding: 0; }
  .nav-link i { font-size: 17px; }
  .nav-link.active::before { left: -10px; }
  .user-card { flex-direction: column; padding: 10px 0 0; gap: 8px; }
  .main { padding: 24px; }
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal { max-width: 560px; }
  .modal-lg { max-width: 720px; }
}

/* Sidebar tooltips (icon rail links + sign-out). One fixed element in <body>,
   shown/positioned by app.js, so the scrollable rail can't clip it. */
.rail-tooltip {
  position: fixed;
  z-index: calc(var(--z-sidebar) + 1);
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-4px, -50%);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.rail-tooltip.is-visible { opacity: 1; transform: translate(0, -50%); }

/* Narrow desktop / tablet portrait: stack sell & dashboard */
@media (max-width: 899.98px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Mobile: <768px - bottom tab bar */
@media (max-width: 767.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main {
    padding: 16px 16px calc(var(--bottom-nav-h) + 24px + env(safe-area-inset-bottom, 0px));
  }
  .page-head h2 { font-size: 21px; }
  .page { gap: 16px; }

  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-bottom-nav);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(0,0,0,.05);
  }
  .bottom-nav-link {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    transition: color var(--dur) var(--ease);
  }
  .bottom-nav-link i { font-size: 19px; }
  .bottom-nav-link.active { color: var(--accent); font-weight: 600; }
  .bottom-nav-link.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 30%;
    right: 30%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
  }
  .bottom-nav-link span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .toast-stack {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: calc(var(--bottom-nav-h) + 12px + env(safe-area-inset-bottom, 0px));
    align-items: stretch;
  }
  .toast { max-width: none; min-width: 0; }

  .modal-backdrop:not(.sheet-backdrop) { padding: 12px; }
  .modal { max-height: calc(100dvh - 24px); }
  .modal-head { padding: 14px 14px 12px 18px; }
  .modal-body { padding: 16px 18px; }
  .modal-footer { padding: 12px 18px; }

  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat .s-value { font-size: 20px; }
  .card { padding: 16px; }
  .toolbar > input[type="text"] { flex: 1 1 100%; }
  .products-toolbar .products-search { flex: 1 1 100%; max-width: none; }
  .products-toolbar .products-category { flex: 1 1 auto; max-width: none; }
  .table { font-size: 13px; }
  .table td, .table th { padding: 10px 8px; }
}

/* ---------------- 18. Print ---------------- */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; }
  body * { visibility: hidden; }
  #app:not(:has(.print-area)), #login-screen, #toast-root, .bottom-nav { display: none !important; }
  .modal-backdrop { position: static; background: none; padding: 0; animation: none; display: block; }
  .modal, .sheet {
    position: static; max-height: none; overflow: visible; box-shadow: none; border: 0;
    animation: none; transform: none; max-width: none; background: #fff;
  }
  .modal-body { overflow: visible; padding: 0; }
  .modal-head, .modal-footer, .modal-actions { display: none; }
  .print-area, .print-area * { visibility: visible; color: #000; }
  .print-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: none;
    background: #fff;
    padding: 0;
  }
  .receipt-rule { border-top-color: #000; }
  .print-only { display: block !important; text-align: left; }
  .pay-success > :not(.print-only) { display: none !important; }
}

/* ---------------- 19. Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton { animation: none !important; }
  .btn.is-busy::after { animation: spin 1.5s linear infinite !important; }
}
