* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #2563eb;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ---------- 顶栏 ---------- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 56px;
  flex-shrink: 0;
}
.tabs { display: flex; gap: 8px; height: 100%; }
.tab {
  border: none;
  background: none;
  font-size: 17px;
  padding: 0 20px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
#today-stats { font-size: 15px; color: var(--muted); }

/* ---------- 页面切换 ---------- */
.page { display: none; flex: 1; overflow: hidden; }
.page.active { display: flex; }

/* ---------- 收银页 ---------- */
#tab-cashier { flex-direction: row; }
.cashier-left { flex: 1; display: flex; flex-direction: column; padding: 12px; overflow: hidden; }
.search-bar input {
  width: 100%;
  padding: 12px 16px;
  font-size: 17px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  outline: none;
}
.search-bar input:focus { border-color: var(--primary); }

.product-grid {
  flex: 1;
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  overflow-y: auto;
  align-content: start;
}
.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 90px;
}
.product-card:active { background: #dbeafe; }
.product-card .p-name { font-size: 16px; font-weight: 500; line-height: 1.3; }
.product-card .p-price { font-size: 18px; color: var(--primary); font-weight: 700; }
.product-card .p-stock { font-size: 12px; color: var(--muted); }
.product-card.out-of-stock { opacity: 0.4; }

.cashier-right {
  width: 380px;
  flex-shrink: 0;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.cart-list { flex: 1; overflow-y: auto; }
.cart-empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 15px; }
.cart-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.cart-item .ci-name { flex: 1; font-size: 15px; line-height: 1.3; }
.cart-item .ci-price { font-size: 14px; color: var(--muted); white-space: nowrap; }
.qty-ctrl { display: flex; align-items: center; gap: 4px; }
.qty-ctrl button {
  width: 34px; height: 34px;
  font-size: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
.qty-ctrl .qty { min-width: 32px; text-align: center; font-size: 16px; font-weight: 600; }
.ci-del { border: none; background: none; color: var(--danger); font-size: 20px; cursor: pointer; padding: 4px 8px; }

.cart-footer { border-top: 1px solid var(--border); padding: 14px 16px; }
.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}
.total-row #cart-total { color: var(--danger); }

/* ---------- 按钮 ---------- */
.btn {
  padding: 10px 22px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: #fff; }
.btn-small { padding: 4px 14px; font-size: 14px; }
.btn-checkout { width: 100%; padding: 16px; font-size: 20px; font-weight: 700; border-radius: 12px; }

/* ---------- 商品管理 / 订单 ---------- */
#tab-products, #tab-orders, #tab-stocktake, #tab-reports, #tab-users { flex-direction: column; padding: 16px; overflow-y: auto; }
.page-toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.page-toolbar input {
  flex: 1;
  padding: 10px 14px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  outline: none;
}
.data-table {
  width: 100%;
  background: var(--card);
  border-radius: 12px;
  border-collapse: collapse;
  overflow: hidden;
}
.data-table th, .data-table td {
  padding: 12px 14px;
  text-align: left;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.data-table th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.data-table .row-actions button { margin-right: 8px; }
.order-items-detail { color: var(--muted); font-size: 13px; }

/* ---------- 库存盘点 ---------- */
.stocktake-summary { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.stock-input {
  width: 90px;
  padding: 8px 10px;
  font-size: 16px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.stock-input:focus { border-color: var(--primary); }
.diff-plus { color: #16a34a; font-weight: 700; }
.diff-minus { color: var(--danger); font-weight: 700; }
.diff-none { color: var(--muted); }

/* ---------- 弹窗 ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
.modal.open { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-box h2 { font-size: 20px; margin-bottom: 6px; }
.modal-box label { font-size: 14px; color: var(--muted); }
.modal-box input {
  padding: 12px 14px;
  font-size: 18px;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.modal-box input:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.pay-total { font-size: 22px; font-weight: 700; text-align: center; }
.pay-total span { color: var(--danger); }
.pay-change { font-size: 18px; text-align: center; color: var(--primary); font-weight: 600; }
.quick-money { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-money button {
  flex: 1;
  min-width: 60px;
  padding: 10px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
}

/* ---------- 支付方式 ---------- */
.pay-methods { display: flex; gap: 8px; margin: 4px 0; }
.pm-btn {
  flex: 1;
  padding: 12px;
  font-size: 17px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  color: var(--text);
}
.pm-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; font-weight: 700; }
.pay-qr-tip { text-align: center; color: var(--muted); font-size: 15px; margin-bottom: 8px; }
.pay-qr {
  display: block;
  width: 240px;
  height: 240px;
  margin: 0 auto;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
#cash-panel { display: flex; flex-direction: column; gap: 8px; }

/* ---------- 小票 ---------- */
.receipt-box { max-width: 340px; }
.receipt {
  font-family: "Courier New", monospace;
  font-size: 13px;
  padding: 10px;
  border: 1px dashed var(--border);
  white-space: pre-wrap;
}
@media print {
  body * { visibility: hidden; }
  #receipt-content, #receipt-content * { visibility: visible; }
  #receipt-content { position: absolute; top: 0; left: 0; width: 100%; }
}

/* ---------- 登录页 ---------- */
#login-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  justify-content: center;
  align-items: center;
}
body.locked #login-screen { display: flex; }
body.locked header, body.locked .page { display: none; }
.login-box {
  background: var(--card);
  border-radius: 16px;
  padding: 36px 32px;
  width: 90%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.login-box h1 { font-size: 24px; text-align: center; margin-bottom: 10px; }
.login-box input {
  padding: 14px 16px;
  font-size: 17px;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.login-box input:focus { border-color: var(--primary); }
.login-box .btn { padding: 14px; font-size: 17px; }

.header-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 14px; color: var(--primary); font-weight: 600; }

/* ---------- 提示 ---------- */
#toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 200;
}
#toast.show { opacity: 0.95; }
#toast.error { background: var(--danger); }
#toast.success { background: #16a34a; }

/* 窄屏(竖屏)适配 */
@media (max-width: 800px) {
  #tab-cashier { flex-direction: column; }
  .cashier-right { width: 100%; height: 45%; border-left: none; border-top: 1px solid var(--border); }
}

/* ---------- 新增:通用 ---------- */
[hidden] { display: none !important; }
.modal-box { max-height: 90vh; overflow-y: auto; }
.modal-box select {
  padding: 12px 14px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  outline: none;
}
.modal-box select:focus { border-color: var(--primary); }
.toolbar-tip { flex: 1; align-self: center; color: var(--muted); font-size: 14px; }

/* ---------- 购物车头部操作 ---------- */
.cart-header-actions { display: flex; gap: 6px; }

/* ---------- 库存预警 ---------- */
.badge-low {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 12px;
  color: #fff;
  background: var(--danger);
  border-radius: 8px;
  vertical-align: middle;
}
.stock-low { color: var(--danger); font-weight: 700; }

/* ---------- 已退款订单 ---------- */
tr.order-refunded td { color: var(--muted); text-decoration: line-through; }
tr.order-refunded td.row-actions { text-decoration: none; }

/* ---------- 结账弹窗: 折扣 / 会员 ---------- */
.discount-row { display: flex; align-items: center; gap: 10px; }
.discount-row label { white-space: nowrap; }
.discount-row input { flex: 1; }
.member-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}
.member-row { display: flex; gap: 8px; }
.member-row input { flex: 1; }
.member-row .btn { white-space: nowrap; align-self: center; }
.member-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: var(--primary);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
}

/* ---------- 挂单列表 ---------- */
.holds-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}
.hold-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hold-head { display: flex; justify-content: space-between; font-weight: 600; font-size: 15px; }
.hold-items { color: var(--muted); font-size: 13px; }
.hold-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 报表页 ---------- */
.report-section {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.report-section h3 { font-size: 17px; margin-bottom: 10px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-head h3 { margin-bottom: 0; }
.section-actions { display: flex; gap: 8px; }
.section-empty { color: var(--muted); font-size: 14px; }
.section-tip { color: var(--muted); font-size: 13px; margin-top: 8px; }
.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 150px; background: var(--bg); border-radius: 10px; padding: 14px 16px; }
.sc-label { color: var(--muted); font-size: 14px; }
.sc-value { font-size: 24px; font-weight: 700; color: var(--primary); margin-top: 4px; }
.shift-current { font-size: 15px; line-height: 1.8; margin-bottom: 10px; }
.shift-summary { font-size: 16px; line-height: 2; white-space: pre-wrap; }
.export-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.export-row input {
  padding: 10px 14px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  outline: none;
}
.export-row input:focus { border-color: var(--primary); }

.qty-ctrl input.qty { width: 65px; min-width: 0; padding: 6px 2px; text-align: center; border: 1px solid var(--border); border-radius: 6px; }
.cart-header-actions { flex-wrap: wrap; }
details summary { cursor: pointer; padding: 10px 0; color: var(--primary); }
