:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #edf2f7;
  --text: #17202a;
  --muted: #667085;
  --line: #d9e2ec;
  --teal: #0f766e;
  --teal-2: #115e59;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c2410c;
  --green: #15803d;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
.hidden { display: none !important; }

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--red);
  color: #fff;
  text-align: center;
  padding: 8px 12px;
  font-size: 14px;
}

.pos-shell {
  min-height: 100vh;
  padding: 18px;
}
.pos-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 16px;
  max-width: 1500px;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
h1, h2 { margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 16px; }
.header-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  gap: 8px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 96px;
}
.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.metric b {
  display: block;
  margin-top: 2px;
  font-size: 20px;
}

.pos-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}
.catalog-panel, .cart-card, .checkout-card, .receipt {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.catalog-panel {
  padding: 14px;
  min-height: calc(100vh - 118px);
}
.catalog-tools {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
  margin-bottom: 12px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}
.search-box span { color: var(--muted); font-size: 18px; }
.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  min-height: 44px;
  color: var(--text);
}
.icon-btn, .ghost-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
}
.icon-btn { min-height: 44px; font-size: 18px; }
.ghost-btn { padding: 7px 12px; }
.ghost-btn:hover, .icon-btn:hover { border-color: var(--teal); color: var(--teal); }

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.category-tabs button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  white-space: nowrap;
}
.category-tabs button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
}
.product-btn {
  min-height: 118px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.product-btn:hover {
  border-color: var(--teal);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.12);
  transform: translateY(-1px);
}
.product-name { font-size: 16px; font-weight: 800; line-height: 1.25; }
.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.product-price {
  margin-top: auto;
  color: var(--teal-2);
  font-size: 20px;
  font-weight: 900;
}
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}
.tag.token { background: rgba(37, 99, 235, 0.1); color: var(--blue); }
.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 36px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
}

.order-panel {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 18px;
}
.cart-card, .checkout-card, .receipt { padding: 14px; }
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.cart-list {
  display: grid;
  gap: 8px;
  max-height: 38vh;
  overflow-y: auto;
}
.cart-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.cart-name { font-weight: 800; }
.cart-line-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.qty-controls {
  display: grid;
  grid-template-columns: 34px 36px 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.qty-controls button {
  height: 34px;
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 900;
}
.qty-controls span { text-align: center; font-weight: 800; }
.cart-empty {
  color: var(--muted);
  text-align: center;
  padding: 30px 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.cart-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.cart-summary strong {
  color: var(--text);
  font-size: 26px;
}
.pay-methods {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.pay-methods label {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
}
.pay-methods label:has(input:checked) {
  border-color: var(--teal);
  color: var(--teal-2);
  background: rgba(15, 118, 110, 0.08);
  font-weight: 800;
}
.field-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.staff-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: 0;
}
.staff-input:focus { border-color: var(--teal); }
.checkout-btn, .new-order-btn {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  margin-top: 12px;
}
.checkout-btn:hover, .new-order-btn:hover { background: var(--teal-2); }
.receipt { border-color: rgba(15, 118, 110, 0.35); }
.receipt-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}
.receipt-total {
  font-size: 28px;
  font-weight: 900;
  color: var(--green);
  margin-bottom: 12px;
}
.receipt-codes {
  display: grid;
  gap: 12px;
}
.code-block {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.code-block svg {
  width: min(180px, 100%);
  height: auto;
}
.code-text {
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  color: var(--text);
}

@media (max-width: 980px) {
  .pos-shell { padding: 12px; }
  .pos-header { align-items: stretch; flex-direction: column; }
  .pos-layout { grid-template-columns: 1fr; }
  .catalog-panel { min-height: auto; }
  .order-panel { position: static; }
}

@media print {
  body { background: #fff; }
  .pos-header, .catalog-panel, .checkout-card, .cart-card, .offline-banner, .receipt .ghost-btn, .new-order-btn { display: none !important; }
  .pos-shell { padding: 0; }
  .pos-layout { display: block; }
  .order-panel { display: block; position: static; }
  .receipt { box-shadow: none; border: 0; }
}
