:root {
  --bg: #f3f1eb;
  --bg-accent: #e7efe8;
  --panel: #fffdf8;
  --ink: #1c2421;
  --muted: #5f6b66;
  --line: #d7ddd8;
  --brand: #0f6a4b;
  --brand-dark: #0a4d37;
  --accent: #c45c26;
  --warn: #9a3412;
  --danger: #a11d2d;
  --ok: #0f6a4b;
  --sidebar: #12241d;
  --sidebar-text: #d7e4dd;
  --radius: 14px;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --display: "Space Grotesk", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 106, 75, 0.08), transparent 28%),
    linear-gradient(180deg, #f7f4ee 0%, var(--bg) 40%, #ebe8e1 100%);
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand strong { display: block; color: #fff; font-size: 16px; }
.brand span { display: block; font-size: 12px; opacity: 0.75; margin-top: 2px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; letter-spacing: 0.04em;
}
.brand-mark.lg { width: 56px; height: 56px; font-size: 18px; margin: 0 auto 12px; }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav a {
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,0.08); color: #fff; }
.logout { color: #9fb6ab; font-size: 14px; }

.main { padding: 28px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 16px;
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 28px;
  letter-spacing: -0.02em;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 999px;
  padding: 10px 18px; cursor: pointer; text-decoration: none;
  background: #fff; color: var(--ink);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-checkout { width: 100%; padding: 16px; font-size: 18px; border-radius: 12px; margin-top: 8px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.panel.narrow { max-width: 720px; }
.panel-head, .detail-head, .toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-head h2, .panel-title, .detail-head h2 { margin: 0; font-size: 18px; }
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stats article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stats span { color: var(--muted); font-size: 13px; }
.stats strong {
  display: block; margin-top: 8px;
  font-family: var(--display); font-size: 28px;
}
.stats .warn { border-color: #f0c2b0; background: #fff7f3; }
.grid-2 { display: grid; grid-template-columns: 1.3fr 0.9fr; gap: 18px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }
.muted-row { opacity: 0.55; }
.warn-text { color: var(--warn); font-weight: 600; }
.actions { display: flex; gap: 10px; white-space: nowrap; }
.danger { color: var(--danger); }
.linkish {
  background: none; border: none; color: var(--brand); cursor: pointer; padding: 0; font: inherit;
}

.alert {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 14px;
  border: 1px solid var(--line);
}
.alert-ok { background: #eaf6ef; border-color: #b7dcc6; color: var(--ok); }
.alert-error { background: #fdecec; border-color: #efc0c5; color: var(--danger); }

.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid label, .inline-form label {
  display: grid; gap: 6px; font-size: 14px; color: var(--muted);
}
.form-grid input, .form-grid select,
.inline-form input, .inline-form select,
.member-box input, .pos-search input, .cart-summary input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
}
.form-actions { display: flex; gap: 10px; align-items: center; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { width: auto; min-width: 160px; }
.full { grid-column: 1 / -1; }
.row-form {
  display: grid;
  grid-template-columns: 1.5fr 100px 80px auto auto;
  gap: 8px; align-items: center;
}
.summary-chip {
  background: var(--bg-accent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
}
.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.meta-grid div {
  background: #f7faf7;
  border-radius: 10px;
  padding: 12px;
}
.meta-grid span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15,106,75,0.12), transparent 40%),
    linear-gradient(180deg, #f7f4ee, #e9efe9);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  text-align: center;
}
.auth-card h1 { margin: 0 0 6px; font-family: var(--display); font-size: 28px; }
.auth-card .form-grid { text-align: left; margin-top: 18px; }
.muted { color: var(--muted); margin: 0; }
.install-card { width: min(560px, 100%); text-align: left; }
.install-card h1 { text-align: center; }

/* POS */
.pos-page { background: #101916; color: #f4f7f5; }
.pos-shell { min-height: 100vh; display: flex; flex-direction: column; }
.pos-top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.pos-top h1 { margin: 4px 0 0; font-family: var(--display); font-size: 24px; }
.back-link { color: #9fb6ab; font-size: 13px; }
.pos-search { display: flex; gap: 10px; flex: 1; max-width: 720px; }
.pos-search input { background: #1a2822; border-color: #2b3d34; color: #fff; }
.pos-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  min-height: 0;
}
.pos-catalog { padding: 16px; overflow: auto; }
.cat-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.cat-tabs button, .pay-methods button {
  border: 1px solid #31453c;
  background: #18241f;
  color: #dce7e1;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.cat-tabs button.active, .pay-methods button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.product-card {
  background: #18241f;
  border: 1px solid #2c3f36;
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  color: inherit;
  cursor: pointer;
  min-height: 110px;
}
.product-card:hover { border-color: var(--brand); }
.product-card strong { display: block; margin-bottom: 8px; }
.product-card span { color: #9fb6ab; font-size: 12px; }
.product-card em {
  display: block; margin-top: 10px;
  font-style: normal; font-family: var(--display); color: #f0c9a4;
}

.pos-cart {
  background: #0c1411;
  border-left: 1px solid rgba(255,255,255,0.08);
  display: flex; flex-direction: column;
  min-height: 0;
}
.cart-head, .member-box, .cart-summary { padding: 14px 16px; }
.cart-head { display: flex; justify-content: space-between; align-items: center; }
.cart-head h2 { margin: 0; font-size: 18px; }
.btn-clear-cart {
  background: #2a1818;
  border: 1px solid #e07a7a;
  color: #ffc9c9;
  font-weight: 600;
}
.btn-clear-cart:hover {
  background: #c44a4a;
  border-color: #c44a4a;
  color: #fff;
}
.btn-pos-action {
  background: #1a2f28;
  border: 1px solid #6ecf9a;
  color: #c8f5dc;
  font-weight: 600;
}
.btn-pos-action:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.member-box { display: grid; grid-template-columns: 1fr auto; gap: 8px; border-top: 1px solid rgba(255,255,255,0.06); }
.member-box .sub { grid-column: 1 / -1; color: #9fb6ab; }
.cart-list { flex: 1; overflow: auto; padding: 0 16px 16px; }
.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.cart-item .qty-ctrl { display: flex; gap: 6px; align-items: center; }
.cart-item button {
  width: 28px; height: 28px; border-radius: 8px;
  border: 1px solid #31453c; background: #18241f; color: #fff; cursor: pointer;
}
.cart-summary { border-top: 1px solid rgba(255,255,255,0.08); }
.cart-summary label { display: grid; gap: 6px; color: #9fb6ab; margin-bottom: 10px; }
.total-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.total-row strong { font-family: var(--display); font-size: 32px; color: #f0c9a4; }
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pos-message { min-height: 20px; margin-top: 10px; color: #f0c9a4; font-size: 14px; }
.pos-message.error { color: #ffb4b4; }

@media (max-width: 960px) {
  .app-shell, .pos-body, .grid-2, .stats, .meta-grid, .form-grid.two {
    grid-template-columns: 1fr;
  }
  .sidebar { padding-bottom: 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .pos-top { flex-direction: column; align-items: stretch; }
  .row-form { grid-template-columns: 1fr; }
}

/* Puzzle captcha (login) */
.puzzle-captcha {
  display: grid;
  gap: 10px;
  text-align: left;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.puzzle-stage {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 2 / 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #e8f4ec;
  margin: 0 auto;
  touch-action: none;
}
.puzzle-bg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}
.puzzle-piece {
  position: absolute;
  left: 0;
  top: 0;
  width: 42px;
  height: 42px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}
.puzzle-refresh {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.puzzle-track {
  position: relative;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f2f5f2;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.puzzle-track-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: rgba(15, 106, 75, 0.18);
}
.puzzle-knob {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: grab;
  z-index: 2;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(15, 106, 75, 0.35);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.puzzle-knob:active { cursor: grabbing; }
.puzzle-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  padding-left: 42px;
}
.puzzle-status {
  min-height: 18px;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.puzzle-status.ok { color: var(--ok); }
.puzzle-status.error { color: var(--danger); }
.puzzle-captcha.is-ok .puzzle-track {
  border-color: #b7dcc6;
  background: #eaf6ef;
}
.puzzle-captcha.is-ok .puzzle-knob { background: var(--ok); }
.puzzle-captcha.is-bad .puzzle-track {
  border-color: #efc0c5;
  background: #fdecec;
}
.auth-card .btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Product images */
.product-thumb {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  background: #e8efe9;
  display: block;
}
.product-thumb-lg {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  object-fit: cover;
  background: #e8efe9;
  display: block;
}
.image-upload {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 6px;
}
.barcode-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.barcode-row input { flex: 1; }

/* POS product cards with image */
.product-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 88px;
  padding: 10px !important;
}
.product-card-img {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: cover;
  background: #102018;
}
.product-card-body {
  text-align: left;
  min-width: 0;
}
.product-card-body strong {
  display: block;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-card-wrap {
  position: relative;
}
.product-card-wrap .product-card {
  width: 100%;
}
.price-edit-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  border: 1px solid #3d5a4c;
  background: rgba(12, 20, 17, 0.92);
  color: #f0c9a4;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
.price-edit-btn:hover {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}
.sold-tag {
  display: inline-block !important;
  margin-top: 4px;
  color: #8fd3b0 !important;
}
.price-dialog {
  max-width: 420px;
}
.price-form {
  display: grid;
  gap: 12px;
  padding: 8px 0 16px;
}
.price-form label {
  display: grid;
  gap: 6px;
  color: #c5d7cd;
  font-size: 14px;
}
.price-form input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #31453c;
  background: #102018;
  color: #fff;
  font-size: 18px;
}

/* Camera scan modal */
.scan-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: grid;
  place-items: center;
  z-index: 9999;
  padding: 16px;
}
.scan-modal[hidden] { display: none !important; }
.scan-dialog {
  width: min(520px, 100%);
  background: #111a16;
  color: #f4f7f5;
  border-radius: 16px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.08);
}
.auth-body .scan-dialog,
.scan-dialog {
  background: #fffdf8;
  color: var(--ink);
}
.scan-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.scan-reader {
  width: 100%;
  min-height: 280px;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
  position: relative;
}
.scan-stage {
  position: relative;
  width: 100%;
  min-height: 280px;
  background: #000;
}
.scan-stage video,
.scan-reader video {
  width: 100% !important;
  height: auto !important;
  min-height: 280px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}
.scan-frame {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 38%;
  height: 22%;
  border: 2px solid #3ecf8e;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
  pointer-events: none;
}
.scan-frame::before,
.scan-frame::after {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  background: rgba(62, 207, 142, 0.85);
  top: 50%;
}
.scan-tip {
  margin: 10px 0 0;
  text-align: center;
  font-size: 13px;
}
#scanStatus {
  color: var(--brand);
  font-weight: 600;
  min-height: 1.2em;
}
#scanCompatTip {
  color: #b86b2d;
  font-size: 12px;
  line-height: 1.45;
  padding: 0 6px;
}
.scan-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.scan-actions .btn {
  min-width: 0;
  padding: 10px 12px;
}
.scan-home {
  color: #dce7e1;
  padding: 18px 14px;
  min-height: 180px;
}
.scan-dialog .scan-home {
  color: var(--ink);
  background: #f3f6f4;
  border-radius: 12px;
}
.scan-home p {
  margin: 0 0 10px;
  font-weight: 600;
}
.scan-home ol {
  margin: 0;
  padding-left: 1.2em;
  line-height: 1.7;
  color: var(--muted);
}
.pos-page .scan-home ol { color: #9fb6ab; }
.scan-manual {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.scan-manual input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}
.pos-page .scan-manual input {
  background: #18241f;
  border-color: #31453c;
  color: #fff;
}
.pos-search .btn-accent {
  white-space: nowrap;
  border-radius: 10px;
}

@media (max-width: 960px) {
  .pos-search {
    flex-wrap: wrap;
  }
  .pos-search input,
  .pos-search .btn-accent {
    width: 100%;
    max-width: none;
  }
}
