/* Retail POS — practical retail UI */

:root {
  --ink: #1c1917;
  --ink-soft: #44403c;
  --muted: #78716c;
  --line: #e7e5e4;
  --line-strong: #d6d3d1;
  --bg: #f5f2ed;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --brand: #0f3d2e;
  --brand-2: #1a5c45;
  --accent: #c45c26;
  --accent-soft: #f3e0d4;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --info: #1e3a5f;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06);
  --radius: 8px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.app-body { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--brand);
  color: #f5f5f4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  z-index: 40;
}
.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 6px;
  font-size: 13px;
}
.sidebar-brand strong { display: block; font-size: 14px; }
.sidebar-brand small { color: rgba(255,255,255,0.65); font-size: 12px; }
.sidebar-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.sidebar-nav a {
  color: rgba(255,255,255,0.82);
  padding: 10px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: rgba(255,255,255,0.14); color: #fff; }
.sidebar-foot {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-chip strong { display: block; font-size: 13px; }
.user-chip span { font-size: 12px; color: rgba(255,255,255,0.6); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; flex: 1; }
.topbar-right { color: var(--muted); font-size: 13px; }
.content { padding: 20px; }
.sidebar-toggle { display: none; }

.flash {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-2); text-decoration: none; color: #fff; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #a84c1d; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--ink); }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,0.05); color: inherit; }
.btn-danger { background: var(--err); }
.btn-sm { padding: 7px 10px; font-size: 13px; }
.btn-lg { padding: 14px 18px; font-size: 15px; }
.btn-block { width: 100%; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 16px; }
.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-header h2 { margin: 0; font-size: 15px; font-weight: 650; }

.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(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid rgba(15, 61, 46, 0.25);
  border-color: var(--brand-2);
}
.input-lg { padding: 14px 14px; font-size: 16px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.92em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
  font-weight: 600;
}
table.data tr:hover td { background: #fcfbf9; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.badge-shopify { background: #eef6f1; color: #0f3d2e; border-color: #cfe3d8; }
.badge-pos { background: #f3e8ff; color: #6b21a8; border-color: #e9d5ff; }
.badge-manual { background: var(--accent-soft); color: #9a3412; border-color: #f0c9b0; }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: #bbf7d0; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
.badge-err { background: var(--err-bg); color: var(--err); border-color: #fecaca; }
.badge-muted { background: #f5f5f4; color: var(--muted); }

/* Auth / setup */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top left, rgba(196, 92, 38, 0.12), transparent 45%),
    radial-gradient(ellipse at bottom right, rgba(15, 61, 46, 0.14), transparent 50%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-card .sub { color: var(--muted); margin-bottom: 22px; }

/* POS billing */
.pos-shell {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
  min-height: calc(100vh - 110px);
}
.pos-left, .pos-right {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pos-toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pos-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pos-results {
  flex: 1;
  overflow: auto;
  padding: 8px;
}
.product-hit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: transparent;
  color: inherit;
}
.product-hit:hover, .product-hit:focus {
  background: var(--surface-2);
  border-color: var(--line);
  outline: none;
}
.product-hit .name { font-weight: 650; }
.product-hit .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.product-hit .price { font-weight: 700; font-variant-numeric: tabular-nums; }
.pos-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.cart-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cart-header h2 { margin: 0; font-size: 16px; }
.cart-items { flex: 1; overflow: auto; padding: 8px; }
.cart-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.cart-line:last-child { border-bottom: none; }
.cart-line .title { font-weight: 650; }
.cart-line .meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.qty-controls { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; }
.qty-controls button {
  width: 32px; height: 32px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}
.qty-controls span {
  min-width: 28px;
  text-align: center;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.cart-line .line-total {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.cart-line .remove {
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--err);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.cart-summary {
  border-top: 1px solid var(--line);
  padding: 14px 16px;
  background: var(--surface-2);
}
.summary-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 14px;
}
.summary-row.total {
  font-size: 22px;
  font-weight: 750;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line-strong);
}
.pay-methods {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.pay-methods button {
  padding: 12px 8px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
}
.pay-methods button.active {
  border-color: var(--brand);
  background: #e8f2ed;
  color: var(--brand);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; }
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  min-width: 240px;
  max-width: 360px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }

.progress-bar {
  height: 10px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--brand-2);
  width: 0;
  transition: width 0.25s ease;
}

.receipt {
  width: 80mm;
  max-width: 100%;
  margin: 0 auto;
  background: #fff;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: #111;
}
.receipt h2 { text-align: center; margin: 0 0 4px; font-size: 14px; font-family: var(--font); }
.receipt .center { text-align: center; }
.receipt hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.receipt .r-row { display: flex; justify-content: space-between; gap: 8px; }
.receipt .r-item { margin-bottom: 6px; }

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .pos-shell { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .pay-methods { grid-template-columns: repeat(2, 1fr); }
  .pos-shell { min-height: auto; }
  .pos-left { min-height: 42vh; }
  .pos-right { min-height: 48vh; }
}

@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: absolute; left: 0; top: 0; width: 80mm; }
  .no-print { display: none !important; }
}
