:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-alt: #f7f5f1;
  --text: #1d2321;
  --muted: #5d6662;
  --primary: #1f3a34;
  --primary-text: #ffffff;
  --primary-hover: #2b5047;
  --soft: #e7ece9;
  --soft-hover: #d9e1dd;
  --error: #a3261c;
  --ok: #1f6b3a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 6px 18px rgba(0, 0, 0, .05);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 18px 16px;
  background: var(--primary);
  color: var(--primary-text);
}
.brand { margin: 0; font-size: 1.4rem; font-weight: 700; letter-spacing: .02em; }
.topbar .btn { position: absolute; right: 16px; }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.view-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 16px;
}
.view-head h2 { margin: 0; text-align: center; font-size: 1.5rem; }
.view-head .btn { justify-self: start; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 0 auto 18px;
}
.card.narrow { max-width: 380px; margin-top: 40px; }
.card h2, .card h3 { margin: 0 0 14px; text-align: center; }

.home-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  max-width: 720px;
  margin: 40px auto 0;
}
.tile {
  flex: 0 0 calc(50% - 9px);
  height: 150px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--primary);
  font: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
}
.tile:hover { background: var(--soft); }
.tile.tile-main { flex-basis: 100%; background: var(--primary); color: var(--primary-text); }
.tile.tile-main:hover { background: var(--primary-hover); }

/* Checkout */
.checkout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: start;
}
.checkout .card { margin: 0; min-width: 0; }
.customer-no {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 14px;
}
.scan-input { font-size: 1.2rem; padding: 14px; }
.price-box { background: var(--surface-alt); border-radius: 10px; padding: 16px; margin-top: 16px; }
.co-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 16px 0 12px;
  font-size: 1.2rem;
  font-weight: 600;
}
.co-total strong { font-size: 2rem; }
.btn.big { min-height: 64px; font-size: 1.25rem; }
.row-btns + .row-btns { margin-top: 12px; }
.camera-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
  background: #111614;
  color: #fff;
}
.camera-box {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}
.camera-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-guide {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 30%;
  bottom: 30%;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35);
  outline: 3px solid rgba(255, 255, 255, .9);
}
.camera-msg { margin: 0; min-height: 1.5em; text-align: center; font-size: 1.1rem; font-weight: 600; }
.camera-msg.ok { color: #8fe0a8; }
.camera-msg.error { color: #ff9b8f; }
.camera-total { font-size: 1.2rem; text-align: center; }
.camera-total strong { font-size: 1.6rem; margin-left: 8px; }
.camera-panel .row-btns { width: 100%; max-width: 640px; margin: 0 auto; }
.camera-panel .btn.primary { background: #fff; color: var(--primary); }
body.camera-on { overflow: hidden; }

/* Today's sales */
.card.today { margin-top: 18px; }
.today-scroll { max-height: 420px; overflow: auto; border-radius: 8px; }
.today-table thead th { position: sticky; top: 0; z-index: 1; }
.today-table tbody tr:nth-child(even) { background: transparent; }
.today-table tr.band-a td { background: #ffffff; }
.today-table tr.band-b td { background: #e9f0ec; }
.today-table tr.cust-total td { font-weight: 700; }
.today-table .cust-no { font-weight: 700; color: var(--primary); }
.today-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 14px 18px;
  margin-top: 12px;
  font-weight: 600;
}
.today-total strong { font-size: 1.5rem; }

.table .neg { color: var(--error); }
.adjust-box { background: var(--surface); outline: 2px solid var(--primary); }

.empty-row td { text-align: center; color: var(--muted); padding: 22px 12px; }
.tile:focus-visible, .btn:focus-visible { outline: 3px solid var(--primary-hover); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1; }
.field label { font-weight: 600; font-size: .95rem; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: 20px; height: 20px; }

input, select {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid #c9cfcc;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary-hover); outline-offset: 0; }
input:disabled { background: var(--surface-alt); color: var(--muted); }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 12px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  cursor: pointer;
  min-height: 46px;
}
.btn:hover { background: var(--soft-hover); }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: wait; }

.row-btns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 12px;
  max-width: 620px;
  margin: 6px auto 0;
}

.msg { text-align: center; min-height: 1.5em; margin: 12px 0 0; color: var(--muted); }
.msg.error { color: var(--error); }
.msg.ok { color: var(--ok); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 10px 12px;
}
.table td { padding: 10px 12px; vertical-align: middle; }
.table tbody tr:nth-child(even) { background: var(--surface-alt); }
.table .num { text-align: right; white-space: nowrap; }
.table th.num { text-align: right; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 170px; }

.preview-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border-radius: 8px;
  margin: 6px 0 16px;
  overflow: hidden;
}
#label-preview .label { transform: scale(3); transform-origin: center; background: #fff; box-shadow: 0 0 0 .3px #999; }

.report-head { text-align: center; margin-bottom: 16px; }
.report-head h3 { margin: 0; }
.report-head p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat { background: var(--surface-alt); border-radius: 10px; padding: 14px; text-align: center; }
.stat .k { font-size: .85rem; color: var(--muted); }
.stat .v { font-size: 1.4rem; font-weight: 700; }

.report-section-title { text-align: center; margin: 20px 0 10px; }

/* Labels */
#print-area { display: none; }

.label {
  display: flex;
  align-items: center;
  gap: 1.5mm;
  padding: 1mm 2mm;
  overflow: hidden;
  background: #fff;
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
}
.label-text { flex: 0 0 42%; display: flex; flex-direction: column; justify-content: center; overflow: hidden; }
.label-name {
  font-size: 7pt;
  font-weight: 700;
  line-height: 1.1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.label-price { font-size: 11pt; font-weight: 800; line-height: 1.15; }
.label-code { flex: 1; height: 100%; display: flex; flex-direction: column; min-width: 0; }
.label-code svg { flex: 1; width: 100%; min-height: 0; }
.label-sku { font-size: 5.5pt; text-align: center; letter-spacing: .5px; line-height: 1.2; }

@media (max-width: 860px) {
  .checkout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .table th, .table td { padding: 9px 8px; }
  #co-rows .btn.small { padding: 6px 10px; font-size: .85rem; }
  #label-preview .label { transform: scale(2); }
}

@media (max-width: 640px) {
  .tile { flex-basis: 100%; }
  .row-btns { grid-auto-flow: row; }
}

@media print {
  body { background: #fff; }

  body.print-labels .topbar,
  body.print-labels main { display: none !important; }
  body.print-labels #print-area { display: block !important; }
  body.print-labels .label { break-after: page; page-break-after: always; }

  body.print-report .topbar,
  body.print-report .view-head,
  body.print-report .report-controls,
  body.print-report #print-area { display: none !important; }
  body.print-report main { padding: 0; max-width: none; }
  body.print-report .card { box-shadow: none; padding: 0; }
  body.print-report .stat, body.print-report .table th,
  body.print-report .table tbody tr:nth-child(even) {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
