/* Nimbus POS design system — single small stylesheet, no framework. */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08), 0 1px 2px rgb(15 23 42 / 0.04);
  --sidebar-w: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #26334a;
    --border: #334155;
    --text: #f1f5f9;
    --text-2: #94a3b8;
    --primary-soft: #1e3a5f;
    --success-soft: #14532d;
    --danger-soft: #7f1d1d;
    --warn-soft: #78350f;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  }
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
a { color: var(--primary); text-decoration: none; }

/* ---- App shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}
.sidebar .brand {
  font-weight: 700; font-size: 1.15rem; padding: .25rem .5rem 1rem;
  display: flex; align-items: center; gap: .5rem;
}
.sidebar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.sidebar a.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .65rem; border-radius: 8px;
  color: var(--text-2); font-weight: 500; font-size: .925rem;
}
@media (hover: hover) {
  .sidebar a.nav-item:hover { background: var(--surface-2); color: var(--text); }
}
.sidebar a.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.sidebar .spacer { flex: 1; }
.sidebar .context { font-size: .8rem; color: var(--text-2); padding: .5rem .35rem; border-top: 1px solid var(--border); }
.ctx-btn {
  display: flex; align-items: center; gap: .45rem; width: 100%;
  background: none; border: 0; border-radius: 8px; padding: .5rem .5rem;
  font: inherit; font-size: .85rem; color: var(--text); cursor: pointer; text-align: left;
  min-height: 44px; touch-action: manipulation;
}
@media (hover: hover) { .ctx-btn:hover { background: var(--surface-2); } }
.ctx-btn .ctx-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ctx-btn .ctx-chev { color: var(--text-2); font-size: .8rem; }
.ctx-static { padding: .5rem .5rem; font-size: .85rem; color: var(--text); font-weight: 600; }
.ctx-meta { padding: .15rem .5rem .45rem; font-size: .72rem; }
/* Logout as a nav item — visible only in the mobile bottom bar. */
.sidebar .nav-logout { display: none; margin: 0; }
.sidebar .nav-logout .nav-item { background: none; border: 0; cursor: pointer; width: 100%; font: inherit; }
main.content { flex: 1; padding: 1.25rem 1.5rem; max-width: 1280px; min-width: 0; }

/* Collapsible sidebar (icons only) — more grid room on tablets. The state
   class lives on <html>: hx-boost only swaps <body>, so it survives
   navigation; an inline head script restores it from localStorage. */
.nav-toggle {
  margin-left: auto; width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-2); cursor: pointer; font: inherit; font-size: 1rem;
  touch-action: manipulation;
}
@media (hover: hover) { .nav-toggle:hover { background: var(--surface-2); color: var(--text); } }
.nav-toggle::before { content: '«'; }
@media (min-width: 769px) {
  html.nav-collapsed .nav-toggle::before { content: '»'; }
  html.nav-collapsed .sidebar { width: 68px; padding: 1rem .5rem; }
  html.nav-collapsed .sidebar .nav-label,
  html.nav-collapsed .sidebar .brand-name,
  html.nav-collapsed .sidebar .brand .dot,
  html.nav-collapsed .sidebar .ctx-label,
  html.nav-collapsed .sidebar .ctx-chev,
  html.nav-collapsed .sidebar .ctx-meta { display: none; }
  html.nav-collapsed .sidebar .brand { padding: .25rem 0 1rem; justify-content: center; }
  html.nav-collapsed .nav-toggle { margin-left: 0; }
  html.nav-collapsed .sidebar a.nav-item { justify-content: center; padding: .55rem 0; font-size: 1.1rem; }
  html.nav-collapsed .sidebar .context { padding: .5rem 0; }
  html.nav-collapsed .ctx-btn { justify-content: center; padding: .5rem 0; }
  html.nav-collapsed .ctx-static { text-align: center; padding: .5rem 0; }
}

/* Phones & small tablets: sidebar becomes a labeled bottom bar. */
@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: fixed; bottom: 0; top: auto; z-index: 50;
    flex-direction: row; padding: .25rem .3rem calc(.25rem + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
    justify-content: flex-start; overflow-x: auto; gap: 0;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar .brand, .sidebar .context, .sidebar .spacer { display: none; }
  .sidebar .nav-logout { display: block; }
  .sidebar a.nav-item, .sidebar .nav-logout .nav-item {
    flex-direction: column; gap: .05rem; font-size: 1.05rem; padding: .35rem .45rem;
    min-width: 58px; min-height: 52px; justify-content: center; align-items: center; flex-shrink: 0;
  }
  .sidebar .nav-label { display: block; font-size: .58rem; font-weight: 600; }
  main.content { padding: 1rem .75rem 5.5rem; }
}

/* ---- Components ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.25rem; margin-bottom: 1rem;
}
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.stat { padding: .9rem 1.1rem; }
.stat .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.stat .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--text-2); }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-2); padding: .5rem .6rem; border-bottom: 2px solid var(--border);
}
table.data td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); }
@media (hover: hover) {
  table.data tr:hover td { background: var(--surface-2); }
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.num { white-space: nowrap; }
.table-wrap { overflow-x: auto; scrollbar-gutter: stable; }

/* Touch-first buttons: ≥48px primary, ≥44px small (fingers, not cursors). */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 48px; padding: .55rem 1.05rem; border-radius: 10px; border: 1px solid transparent;
  font-size: .95rem; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff;
  transition: background .12s;
  touch-action: manipulation;
}
@media (hover: hover) {
  .btn:hover { background: var(--primary-hover); }
  .btn.secondary:hover { background: var(--surface-2); }
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.sm { min-height: 44px; padding: .4rem .75rem; font-size: .85rem; }
.btn.lg { min-height: 58px; padding: .85rem 1.4rem; font-size: 1.1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: block; margin-bottom: .8rem; font-size: .85rem; font-weight: 500; }
label.field span { display: block; margin-bottom: .3rem; color: var(--text-2); }
/* 16px inputs: anything smaller makes iPad Safari zoom the page on focus. */
input, select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 1rem;
}
input[type="checkbox"], input[type="radio"] {
  min-height: 0; width: 1.35rem; height: 1.35rem; accent-color: var(--primary);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 140px; }

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 1.2rem 1.4rem;
  background: var(--surface); color: var(--text); width: min(440px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgb(0 0 0 / .45); }

.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--success-soft); color: var(--success); }

.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .grow { flex: 1; }
.muted { color: var(--text-2); font-size: .85rem; }
.mono { font-family: ui-monospace, monospace; font-size: .85em; }
.right { text-align: right; }

/* ---- POS screen ----
   Tablet-first: two columns from 720px (portrait iPad included); below that
   the cart stacks and a fixed jump bar keeps the total + checkout reachable. */
.pos-layout { display: grid; grid-template-columns: 1fr minmax(300px, 380px); gap: 1rem; align-items: start; }
@media (max-width: 719px) { .pos-layout { grid-template-columns: 1fr; } }
.pos-filter { display: flex; gap: .4rem; margin-bottom: .6rem; flex-wrap: wrap; }
/* POS toolbar context buttons: the sidebar covers this on desktop, so they
   only show where the sidebar context is hidden (phone bottom-bar layout). */
.ctx-toolbar-btn { display: none; }
.ctx-toolbar-btn .trunc { max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 768px) { .ctx-toolbar-btn { display: inline-flex; } }

/* ---- Context dialogs (operator / office switch) ---- */
dialog.ctx-dlg { padding: 0; width: min(420px, calc(100vw - 2rem)); max-height: min(85vh, calc(100dvh - 2rem)); }
dialog.ctx-dlg[open] { display: flex; flex-direction: column; }
.ctx-dlg .dlg-head { flex-shrink: 0; padding: 1rem 3.2rem .75rem 1.15rem; border-bottom: 1px solid var(--border); }
.ctx-dlg .dlg-head h3 { margin: 0; font-size: 1.05rem; }
.ctx-dlg .dlg-close {
  position: absolute; top: .45rem; right: .45rem; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 0; border-radius: 10px; font-size: 1.5rem; line-height: 1;
  color: var(--text-2); cursor: pointer; touch-action: manipulation;
}
@media (hover: hover) { .ctx-dlg .dlg-close:hover { background: var(--surface-2); color: var(--text); } }
.ctx-dlg .dlg-close:focus { outline: none; }
.ctx-dlg .dlg-close:focus-visible { outline: 2px solid var(--primary); }
.ctx-dlg .dlg-body { padding: .8rem 1.15rem 1.1rem; overflow-y: auto; outline: none; scrollbar-width: thin; }
/* Phones: bottom sheet instead of a floating box. */
@media (max-width: 600px) {
  dialog.ctx-dlg {
    margin: auto auto 0; width: 100vw; max-width: 100vw;
    border-left: 0; border-right: 0; border-bottom: 0; border-radius: 14px 14px 0 0;
    max-height: 90dvh;
  }
  .ctx-dlg .dlg-body { padding-bottom: calc(1.1rem + env(safe-area-inset-bottom)); }
}

/* Wide variant for form-heavy dialogs (product editor). */
dialog.ctx-dlg.dlg-wide { width: min(720px, calc(100vw - 2rem)); }
.dlg-section { margin: 1.1rem 0 .5rem; padding-top: .8rem; border-top: 1px solid var(--border); font-size: .95rem; }

/* Quick-range chips (reports presets). */
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: .3rem .85rem;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-size: .85rem; font-weight: 600; touch-action: manipulation;
}
@media (hover: hover) { .chip:hover { background: var(--surface-2); color: var(--text); } }
.chip.sel { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* In-table magnitude bars: single hue, value printed in the same row. */
.bar-cell { width: 18%; min-width: 48px; }
.mini-bar { height: 8px; min-width: 2px; border-radius: 4px; background: var(--primary); opacity: .7; }

.op-list { display: flex; flex-direction: column; gap: .4rem; }
.op-group { font-size: .74rem; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; margin: .8rem 0 .4rem; }
.op-group:first-child { margin-top: 0; }
.op-row {
  position: relative; display: flex; gap: .6rem; align-items: center;
  font-size: 1rem; min-height: 52px; padding: .5rem .8rem; border-radius: 10px; cursor: pointer;
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  font-family: inherit; color: var(--text); text-align: left;
  touch-action: manipulation;
}
@media (hover: hover) { .op-row:hover { background: var(--surface-2); } }
.op-row:active { background: var(--surface-2); }
.op-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .05rem; }
.op-name { font-weight: 600; }
.op-hint { font-size: .75rem; }
.op-go { color: var(--text-2); font-size: 1.25rem; line-height: 1; }
.op-row.is-current { cursor: default; background: var(--surface-2); }
.op-row.is-disabled { cursor: default; opacity: .55; }
.pos-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.pos-product {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .7rem .8rem; cursor: pointer; text-align: left; font: inherit; color: var(--text);
  display: flex; flex-direction: column; gap: .25rem; min-height: 84px;
  transition: border-color .1s, transform .05s;
}
@media (hover: hover) { .pos-product:hover { border-color: var(--primary); } }
.pos-product:active { transform: scale(.97); border-color: var(--primary); }
.pos-product .name { font-weight: 600; font-size: .88rem; line-height: 1.25; }
.pos-product .price { color: var(--primary); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: auto; }
.pos-product .stock { font-size: .72rem; color: var(--text-2); }
/* Product photos: contain (never crop) on white — the stored JPEGs are
   composited onto white, so the letterbox blends into the image. */
.pos-product .thumb {
  width: 100%; height: 72px; object-fit: contain; border-radius: 6px;
  background: var(--surface-2); pointer-events: none;
}
.pos-product img.thumb { background: #fff; }
.pos-product .thumb-empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; opacity: .45;
}
.product-thumb {
  width: 36px; height: 36px; object-fit: contain; border-radius: 6px;
  background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle;
}
img.product-thumb { background: #fff; }
.product-thumb-empty { opacity: .4; font-size: 1.1rem; }
.product-thumb-empty .icon-img { opacity: 1; }

/* Icon picker: thumb cell opens a dropdown grid of colored SVG icons. */
.icon-picker { position: relative; }
.icon-picker summary { list-style: none; cursor: pointer; }
.icon-picker summary::-webkit-details-marker { display: none; }
.icon-picker[open] summary .product-thumb { outline: 2px solid var(--primary); }
.icon-grid {
  position: absolute; z-index: 30; left: 0; top: calc(100% + 4px);
  display: grid; grid-template-columns: repeat(7, 34px); gap: 4px;
  padding: 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.icon-choice {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 6px; background: none;
  color: var(--text-2); cursor: pointer; font-size: .9rem;
}
.icon-choice:hover { background: var(--surface-2); }
.icon-choice.sel { border-color: var(--primary); background: var(--primary-soft); }
.icon-img { width: 22px; height: 22px; vertical-align: middle; }
.icon-img-lg { width: 40px; height: 40px; }
.print-buttons { display: inline-flex; gap: .6rem; flex-wrap: wrap; }
/* Two-column mode: the cart is its own scroll area, so a long product grid
   (page scroll) and a long cart no longer share one scrollbar. */
@media (min-width: 720px) {
  .pos-cart {
    position: sticky; top: 1rem;
    max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
    overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
  }
}
.pos-cart .lines { max-height: 40vh; overflow-y: auto; overscroll-behavior: contain; }
.cart-line { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--border); font-size: .95rem; }
.cart-line .n { flex: 1; min-width: 0; }
.cart-line .qty { display: flex; align-items: center; gap: .3rem; }
.cart-line .qty .qv { min-width: 1.6rem; text-align: center; font-weight: 600; }
/* The most-tapped controls on the POS — full finger size. */
.cart-line .qty button {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 700;
  font-size: 1.25rem; touch-action: manipulation;
}
.cart-line .qty button:active { background: var(--primary-soft); }
.cart-line .amt { width: 76px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.loyalty-opt { display: flex; gap: .5rem; align-items: center; font-size: .95rem; min-height: 44px; }
.pos-total { display: flex; justify-content: space-between; align-items: baseline; padding: .8rem 0 .4rem; font-size: 1.05rem; }
.pos-total .sum { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pay-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .5rem; }
.quick-cash { display: flex; gap: .5rem; margin: .4rem 0 .6rem; }
.quick-cash .btn { flex: 1; }
/* Fixed total shortcut when the cart is below the grid (phones). */
.cart-jump {
  display: none; position: fixed; left: .75rem; right: .75rem;
  bottom: calc(4.6rem + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--primary); color: #fff; text-align: center; font-weight: 700;
  padding: .85rem; border-radius: 12px; box-shadow: var(--shadow); font-size: 1.05rem;
}
@media (max-width: 719px) { .cart-jump { display: block; } }
/* In-flight spinner: visible feedback for every cart round-trip. */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#offline-banner {
  position: sticky; top: 0; z-index: 90; background: var(--danger); color: #fff;
  text-align: center; padding: .55rem .8rem; font-weight: 600; font-size: .92rem;
}

/* ---- Receipt ---- */
.receipt { font-family: ui-monospace, monospace; font-size: .82rem; background: #fff; color: #000; max-width: 340px; margin: 0 auto; padding: 1rem; }
.receipt hr { border: 0; border-top: 1px dashed #000; }
.receipt .c { text-align: center; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: .1rem 0; vertical-align: top; }
.receipt td.r { text-align: right; white-space: nowrap; }
.receipt .qr { display: flex; justify-content: center; margin: .5rem 0; }
.receipt .qr svg { width: 128px; height: 128px; }
@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: absolute; left: 0; top: 0; max-width: none; width: 72mm; }
}

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { text-align: center; font-size: 1.5rem; font-weight: 800; margin-bottom: 1.5rem; }

/* HTMX request indicator */
.htmx-indicator { opacity: 0; transition: opacity .15s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

#toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
#toast .t { background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 8px; font-size: .9rem; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
