/* ==========================================================================
   ZonPOS — styles
   Mobile-first dark theme. CSS custom properties drive colors & spacing.
   ========================================================================== */

:root {
  /* Brand */
  --brand-1: #1f3a8a;       /* deep brand blue */
  --brand-2: #2563eb;       /* action blue */
  --brand-3: #38bdf8;       /* highlight */
  --brand-grad: linear-gradient(135deg, #1f3a8a 0%, #2563eb 50%, #38bdf8 100%);

  /* Surface (dark) */
  --bg-0: #0b0e13;          /* page background */
  --bg-1: #11141b;          /* card background */
  --bg-2: #181c25;          /* raised */
  --bg-3: #222633;          /* hovered */
  --line:  #2a2f3a;
  --line-soft: #1f242e;

  /* Text */
  --fg-1: #f1f3f7;
  --fg-2: #c5cad4;
  --fg-3: #8b909c;
  --fg-4: #5b6170;

  /* Semantic */
  --ok:  #22c55e;
  --warn:#f59e0b;
  --err: #ef4444;
  --danger: #dc2626;

  /* Layout */
  --topbar-h: 56px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.25);
  --shadow-2: 0 6px 20px rgba(0,0,0,0.4);

  --t-fast: 120ms ease;
  --t-med:  200ms ease;
}

/* ---------- reset / base ---------- */
*,*::before,*::after { box-sizing: border-box; }
html, body { height: 100%; }
/* The `hidden` attribute must win over any display: rule on the element. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji",
               "Segoe UI Emoji", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--fg-1);
  background: var(--bg-0);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea { user-select: text; }
button {
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
  color: inherit;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--brand-3); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- splash (hides when app boots) ---------- */
.splash {
  position: fixed; inset: 0;
  z-index: 10000;
  background: #0b0e13;
  display: grid; place-items: center;
  pointer-events: none;
  transition: opacity 350ms ease;
}
.splash img { width: 100%; height: 100%; object-fit: cover; }
.splash.hide { opacity: 0; }
body.booted .splash { display: none; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center;
  background: rgba(11,14,19,0.85);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-title {
  flex: 1; text-align: center;
  font-weight: 600; letter-spacing: 0.2px;
  font-size: 16px;
  padding-right: 44px; /* keep visually centered when back button shows */
}
.topbar-actions {
  position: absolute; right: 4px; top: var(--safe-top);
  height: var(--topbar-h);
  display: flex; align-items: center;
}
.topbar .icon-btn:first-child {
  position: absolute; left: 4px; top: var(--safe-top);
  height: var(--topbar-h);
}

.icon-btn {
  width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border-radius: 10px;
  color: var(--fg-1);
  transition: background var(--t-fast);
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg-2); outline: none; }
.icon-btn:active { background: var(--bg-3); }
.icon-btn[hidden] { display: none; }

/* ---------- app + views ---------- */
.app {
  min-height: 100dvh;
  padding-bottom: calc(20px + var(--safe-bottom));
}
.view { animation: viewIn 180ms ease; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.view-pad { padding: 14px 16px 32px; max-width: 920px; margin: 0 auto; }

.h-section { font-size: 20px; margin: 4px 0 12px; font-weight: 700; letter-spacing: 0.2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--bg-2);
  color: var(--fg-1);
  border: 1px solid var(--line);
  font-weight: 600;
  transition: background var(--t-fast), transform var(--t-fast);
  min-height: 40px;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-1);
}
.btn.primary:hover { filter: brightness(1.08); background: var(--brand-grad); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.danger:hover { filter: brightness(1.1); background: var(--danger); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-weight: 600; font-size: 13px;
  border: 1px solid rgba(255,255,255,0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background var(--t-fast);
  min-height: 36px;
}
.chip:hover { background: rgba(0,0,0,0.7); }
.chip.danger { color: #fff; background: rgba(220, 38, 38, 0.85); border-color: transparent; }
.chip[hidden] { display: none; }

/* ---------- row / helpers ---------- */
.row { display: flex; align-items: center; }
.row-spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.right { justify-content: flex-end; }
.row.gap-2 { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.center { text-align: center; }
.muted { color: var(--fg-3); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }

/* ---------- card ---------- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 14px;
  margin: 10px 0;
  box-shadow: var(--shadow-1);
}
.card-title { font-weight: 700; font-size: 14px; letter-spacing: 0.4px; text-transform: uppercase; color: var(--fg-2); margin-bottom: 8px; }
.card.danger { border-color: rgba(220, 38, 38, 0.4); }

/* ---------- form fields ---------- */
.field { display: block; margin: 10px 0; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 13px; color: var(--fg-2); margin-bottom: 4px; }
.input, .select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--fg-1);
  outline: none;
  transition: border-color var(--t-fast), background var(--t-fast);
  min-height: 42px;
}
.input:focus, .select:focus { border-color: var(--brand-3); }
input[type=range] {
  width: 100%; -webkit-appearance: none; appearance: none; height: 36px; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 6px; background: var(--bg-3); border-radius: 3px;
}
input[type=range]::-moz-range-track { height: 6px; background: var(--bg-3); border-radius: 3px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand-2); border: 2px solid #fff; margin-top: -8px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand-2); border: 2px solid #fff;
}

.seg {
  display: inline-flex; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 3px; gap: 2px;
}
.seg-btn {
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 600; font-size: 13px;
  color: var(--fg-2);
  transition: background var(--t-fast), color var(--t-fast);
}
.seg-btn.active { background: var(--brand-2); color: #fff; }

/* ---------- orders list ---------- */
.orders-list { display: grid; gap: 8px; }
.order-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 12px;
  transition: background var(--t-fast), transform var(--t-fast);
  text-align: left;
  width: 100%;
}
.order-row:hover { background: var(--bg-2); }
.order-row .meta { flex: 1; min-width: 0; }
.order-row .meta .name { font-weight: 600; }
.order-row .meta .sub  { color: var(--fg-3); font-size: 12.5px; }
.order-row .total { font-weight: 700; font-variant-numeric: tabular-nums; }
.order-row .chev { color: var(--fg-3); }

.empty-state {
  margin: 30px auto;
  text-align: center;
  color: var(--fg-3);
}

/* ---------- order view ---------- */
.scanner-host {
  position: relative;
  background: #000;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 56dvh;
  overflow: hidden;
}
#scanner-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}
.scanner-frame {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
}
.scanner-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}
.scanner-cutout {
  position: absolute;
  top: 50%; left: 50%;
  width: min(82%, 480px);
  aspect-ratio: 4 / 1.4;
  transform: translate(-50%, -50%);
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  overflow: hidden;
}
.scanner-cutout::before, .scanner-cutout::after,
.scanner-cutout > .scanline-shimmer { display: none; }
.scanner-cutout::before, .scanner-cutout::after {
  content: ""; position: absolute; width: 24px; height: 24px;
  border: 3px solid var(--brand-3);
}
.scanner-cutout::before { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 16px; }
.scanner-cutout::after  { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 16px; }
.scanner-cutout {
  outline: 2px solid rgba(56, 189, 248, 0.85);
  outline-offset: -2px;
}
.scanline {
  position: absolute; left: 4%; right: 4%; top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--brand-3), transparent);
  box-shadow: 0 0 8px var(--brand-3);
  animation: scan 1.6s linear infinite;
}
@keyframes scan { 0% { top: 0; } 50% { top: calc(100% - 2px); } 100% { top: 0; } }
.scanner-hint {
  position: absolute; left: 0; right: 0; bottom: 60px;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6);
  font-size: 13px; font-weight: 600;
  padding: 0 16px;
  pointer-events: none;
}
.scanner-toolbar {
  position: absolute; left: 0; right: 0; bottom: 12px;
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
  padding: 0 10px;
  pointer-events: auto;
  z-index: 4;
}
#last-scan-toast {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(34, 197, 94, 0.92);
  color: #0a1a0a;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700; font-size: 13px;
  box-shadow: var(--shadow-1);
  z-index: 5;
  white-space: nowrap;
}
#last-scan-toast.warn { background: rgba(245, 158, 11, 0.95); color: #2a1700; }
#last-scan-toast.err  { background: rgba(239, 68, 68, 0.95);  color: #2a0808; }

/* order body */
.order-pad { padding: 12px 14px 32px; max-width: 920px; margin: 0 auto; }
.order-meta .strong { font-size: 14px; }
.action-row { display: flex; gap: 8px; justify-content: space-between; margin-top: 12px; }
.action-row .btn { flex: 1; justify-content: center; padding: 12px 14px; font-size: 15px; }

.items-card { padding: 8px 12px 10px; }
.items-head { padding: 6px 4px; }
.items-list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line-soft);
}
.item-row:last-child { border-bottom: 0; }
.item-row .name { font-weight: 600; }
.item-row .bc   { color: var(--fg-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.item-row .line { text-align: right; font-variant-numeric: tabular-nums; }
.item-row .line .price { font-weight: 600; }
.item-row .qty-ctrl {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 4px;
}
.qty-btn {
  width: 28px; height: 28px;
  display: inline-grid; place-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg-1);
  font-size: 16px; font-weight: 700;
}
.qty-btn:hover { background: var(--bg-3); }
.qty-btn.minus { color: var(--err); }
.qty-btn.plus  { color: var(--ok); }
.qty-val { min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.item-row .rm {
  color: var(--fg-3);
  padding: 4px;
  margin-left: 4px;
  border-radius: 6px;
}
.item-row .rm:hover { color: var(--err); background: var(--bg-2); }

.items-empty { padding: 24px 0; text-align: center; }

.totals { margin-top: 8px; padding: 8px 4px 0; border-top: 1px dashed var(--line); }
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals-row.grand {
  font-size: 18px; font-weight: 700; margin-top: 6px;
  padding-top: 8px; border-top: 1px solid var(--line);
}

/* ---------- settings ---------- */
.formats-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
  margin-top: 8px;
}
@media (min-width: 540px) {
  .formats-list { grid-template-columns: repeat(3, 1fr); }
}
.fmt-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 6px; border-radius: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
}
.fmt-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand-2); }
.fmt-row .label { font-weight: 600; }
.fmt-row .desc  { color: var(--fg-3); font-size: 11.5px; }

/* ---------- products ---------- */
.products-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}
@media (min-width: 540px) { .products-list { grid-template-columns: repeat(2, 1fr); } }
.product-row {
  display: flex; gap: 10px; align-items: center;
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 10px 12px;
}
.product-row .pname { font-weight: 600; }
.product-row .pbc   { color: var(--fg-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.product-row .pprice { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.55);
  display: grid; place-items: center;
  padding: 16px;
  animation: fade 150ms ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-2);
  max-height: 90dvh;
  overflow: auto;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.bill-card { max-width: 480px; }
.bill-text {
  background: #f8fafc;
  color: #0b1220;
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.35;
  white-space: pre;
  overflow: auto;
  max-height: 50dvh;
  user-select: text;
}

/* ---------- toast (global, fixed) ---------- */
.toast-fixed {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(17,20,27,0.95);
  color: var(--fg-1);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-2);
  z-index: 300;
  max-width: calc(100% - 24px);
  text-align: center;
  animation: toastIn 200ms ease;
}
.toast-fixed.err { background: rgba(220, 38, 38, 0.95); }
.toast-fixed.ok  { background: rgba(34, 197, 94, 0.95);  color: #0a1a0a; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- print: thermal-printer style (also reused for browser print) ---------- */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .scanner-host, .action-row, .modal, .toast-fixed { display: none !important; }
  .order-pad, .view-pad, .card, .items-card, .order-meta { box-shadow: none; background: #fff; color: #000; border-color: #ddd; }
  .item-row .qty-btn, .item-row .rm { display: none; }
  .totals-row.grand { font-size: 16px; }
}

/* ---------- small viewport polish ---------- */
@media (max-width: 360px) {
  .btn { padding: 9px 12px; }
  .topbar-title { font-size: 15px; }
}

/* ---------- accessibility ---------- */
:focus-visible { outline: 2px solid var(--brand-3); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .scanline { animation: none; }
}
