:root {
  --ink: #18221c;
  --muted: #69736c;
  --line: #dfe4df;
  --paper: #ffffff;
  --canvas: #f2f4f1;
  --brand: #1f392b;
  --brand-soft: #e6eee8;
  --accent: #c45f32;
  --danger: #a33d35;
  --shadow: 0 12px 35px rgba(20, 31, 24, 0.15);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
small { color: var(--muted); }

.login-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; background: #e7ebe7; }
.login-box { width: min(380px, 100%); display: grid; gap: 16px; padding: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); }
.login-box > img { width: 180px; height: 112px; object-fit: contain; }
.login-box h1 { font-size: 28px; }
.login-box > p { color: var(--muted); }
.login-box label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-box input { height: 48px; border: 1px solid var(--line); border-radius: 6px; padding: 0 13px; color: var(--ink); }
.login-box button { height: 50px; border: 0; border-radius: 6px; background: var(--brand); color: white; font-weight: 700; }
.form-error { color: var(--danger) !important; }

.pos-app { height: 100%; display: grid; grid-template-rows: 68px 1fr; overflow: hidden; }
.pos-topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: var(--brand); color: white; }
.pos-brand, .top-actions { display: flex; align-items: center; gap: 12px; }
.pos-brand img { width: 42px; height: 42px; }
.pos-brand strong, .pos-brand small { display: block; }
.pos-brand strong { font-size: 18px; }
.pos-brand small, .user-button small { color: #c9d4cc; }
.top-actions button { border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.08); color: white; border-radius: 6px; }
.top-button { height: 42px; padding: 0 15px; }
.top-button span { display: inline-grid; min-width: 22px; height: 22px; place-items: center; margin-left: 6px; border-radius: 11px; background: var(--accent); font-size: 12px; }
.icon-button { width: 42px; height: 42px; font-size: 23px; }
.user-button { min-width: 98px; height: 42px; padding: 0 12px; text-align: left; }
.user-button span, .user-button small { display: block; }

.workspace { min-height: 0; display: grid; grid-template-columns: 108px minmax(360px, 1fr) 370px; }
.category-rail { min-height: 0; overflow-y: auto; padding: 12px 10px; border-right: 1px solid var(--line); background: #f8faf8; }
.category-rail > div { display: grid; gap: 7px; }
.category { width: 100%; min-height: 48px; margin-bottom: 7px; padding: 8px 5px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); }
.category.active { border-color: #c6d3ca; background: var(--brand-soft); color: var(--brand); font-weight: 700; }

.menu-pane { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr; padding: 18px; }
.menu-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding-bottom: 15px; }
.menu-toolbar h1 { font-size: 22px; }
.menu-toolbar p { margin-top: 4px; color: var(--muted); font-size: 13px; }
.menu-toolbar input { width: min(240px, 45%); height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.pos-products { min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); grid-auto-rows: 198px; align-content: start; gap: 12px; padding-right: 3px; }
.pos-product { display: grid; grid-template-rows: 118px 1fr; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); text-align: left; box-shadow: 0 2px 5px rgba(20,31,24,.04); overflow: hidden; }
.pos-product:active { border-color: var(--brand); background: var(--brand-soft); transform: translateY(1px); }
.pos-product small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos-product strong { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 16px; line-height: 1.32; }
.pos-product b { display: block; margin-top: 4px; color: var(--accent); font-size: 19px; }
.pos-product-photo { width: 100%; height: 118px; object-fit: cover; border-radius: 7px; background: #edf0ed; }
.pos-product-photo.photo-fallback { display: grid; place-items: center; color: #fff; background: var(--brand); font-size: 42px; font-weight: 800; }
.empty-products { grid-column: 1 / -1; color: var(--muted); }

.order-pane { min-height: 0; display: grid; grid-template-rows: auto auto 1fr auto auto auto; border-left: 1px solid var(--line); background: var(--paper); }
.order-title { display: flex; justify-content: space-between; align-items: center; padding: 17px 18px 12px; }
.order-title h2 { font-size: 20px; }
.order-title small { display: block; margin-top: 3px; }
.text-button { border: 0; background: transparent; color: var(--danger); }
.service-switch { display: grid; grid-template-columns: 1fr 1fr; margin: 0 18px 12px; padding: 3px; border-radius: 6px; background: #edf0ed; }
.service-switch button { height: 38px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
.service-switch button.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px rgba(20,31,24,.14); font-weight: 700; }
.pos-cart { min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 8px; padding: 0 18px 12px; }
.cart-empty { padding: 40px 12px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 6px; }
.pos-cart-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.pos-cart-item strong, .pos-cart-item small { display: block; }
.pos-cart-item small { margin-top: 4px; }
.cart-line-price { color: var(--accent); font-weight: 700; text-align: right; }
.cart-stepper { display: grid; grid-template-columns: 34px 34px 34px; align-items: center; margin-top: 8px; }
.cart-stepper button { width: 32px; height: 30px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); color: var(--brand); }
.cart-stepper span { text-align: center; font-weight: 700; }
.order-fields { display: grid; gap: 7px; padding: 10px 18px; border-top: 1px solid var(--line); }
.order-fields input { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; }
.order-summary { display: grid; grid-template-columns: 90px 1fr; padding: 11px 18px; border-top: 1px solid var(--line); }
.order-summary div { display: flex; align-items: baseline; justify-content: space-between; }
.order-summary span { color: var(--muted); }
.order-summary .amount { justify-content: flex-end; gap: 14px; }
.order-summary strong { color: var(--accent); font-size: 28px; }
.order-actions { display: grid; grid-template-columns: 110px 1fr; gap: 9px; padding: 0 18px 18px; }
.order-actions button { height: 54px; border-radius: 6px; font-weight: 700; }
.hold-button { border: 1px solid var(--brand); background: white; color: var(--brand); }
.checkout-button { border: 0; background: var(--brand); color: white; font-size: 18px; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translateX(-50%); padding: 11px 18px; border-radius: 6px; background: #16201a; color: white; box-shadow: var(--shadow); }
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.shade { position: absolute; inset: 0; background: rgba(9,15,11,.62); }
.payment-sheet, .pending-drawer, .receipt-window { position: relative; z-index: 1; background: var(--paper); border-radius: 8px; box-shadow: var(--shadow); }
.payment-sheet { width: min(520px, 100%); padding: 22px; }
.payment-sheet header, .pending-drawer header { display: flex; justify-content: space-between; gap: 12px; }
.payment-sheet header p, .pending-drawer header p { margin-top: 5px; color: var(--muted); }
.close-button { width: 38px; height: 38px; border: 0; border-radius: 5px; background: #eef1ee; color: var(--ink); font-size: 25px; }
.payment-amount { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0; padding: 15px; background: var(--brand-soft); border-radius: 7px; }
.payment-amount strong { color: var(--accent); font-size: 34px; }
.payment-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.payment-methods button { min-height: 84px; display: grid; align-content: center; gap: 5px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink); }
.payment-methods button.active { border: 2px solid var(--brand); background: var(--brand-soft); }
.payment-methods small { font-size: 11px; }
.confirm-payment { width: 100%; height: 52px; margin-top: 18px; border: 0; border-radius: 6px; background: var(--brand); color: white; font-size: 17px; font-weight: 700; }

.pending-drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 92vw); border-radius: 0; padding: 22px; overflow-y: auto; }
.pending-orders { display: grid; gap: 10px; margin-top: 20px; }
.pending-card { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; }
.pending-card strong, .pending-card small { display: block; }
.pending-card small { margin-top: 5px; }
.pending-card .pending-price { text-align: right; color: var(--accent); font-size: 18px; }
.pending-card button { grid-column: 1 / -1; height: 40px; border: 0; border-radius: 5px; background: var(--brand); color: white; }
.pending-empty { padding: 35px; text-align: center; color: var(--muted); }
.live-alert { position:fixed; z-index:30; top:82px; left:50%; width:min(520px,calc(100% - 32px)); display:grid; grid-template-columns:44px 1fr auto; align-items:center; gap:12px; transform:translateX(-50%); padding:14px 15px; border:1px solid #d7b674; border-radius:7px; color:#3e321c; background:#fff8e8; box-shadow:0 12px 35px #17221935; }
.live-alert.paid { border-color:#8ab19a; color:#183e29; background:#edf8f1; }
.live-alert > span { width:42px; height:42px; display:grid; place-items:center; border-radius:50%; color:#fff; background:#b77a22; font-size:21px; font-weight:700; }
.live-alert.paid > span { background:#2b7b4b; }
.live-alert strong { font-size:17px; }.live-alert p { margin:3px 0 0; }.live-alert button { border:0; color:inherit; background:transparent; font-size:22px; }

.receipt-window { width: min(390px, 100%); max-height: calc(100vh - 40px); padding: 18px; overflow: auto; background: #e9ece9; }
.receipt { width: 80mm; max-width: 100%; margin: 0 auto; padding: 8mm 6mm; background: white; color: #111; font-size: 13px; }
.receipt header, .receipt footer { text-align: center; }
.receipt header { padding-bottom: 11px; border-bottom: 1px dashed #555; }
.receipt .pickup { display: block; margin: 7px 0; font-size: 42px; }
.receipt-meta, .receipt-items, .receipt footer { display: grid; gap: 6px; padding: 11px 0; }
.receipt-meta { border-bottom: 1px dashed #555; }
.receipt-items div, .receipt-total { display: flex; justify-content: space-between; gap: 10px; }
.receipt-total { padding: 11px 0; border-top: 1px dashed #555; border-bottom: 1px dashed #555; font-size: 18px; }
.receipt-note { padding: 9px 0; font-weight: 700; }
.receipt-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.receipt-buttons button { height: 44px; border: 0; border-radius: 5px; background: var(--brand); color: white; }
.receipt-buttons .secondary-button { border: 1px solid var(--line); background: white; color: var(--ink); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 88px minmax(300px, 1fr) 330px; }
  .menu-pane { padding: 12px; }
  .pos-products { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}

@media (max-width: 720px) {
  .pos-app { height: auto; min-height: 100%; overflow: visible; }
  .workspace { grid-template-columns: 74px 1fr; }
  .menu-pane { min-height: 620px; }
  .order-pane { grid-column: 1 / -1; min-height: 650px; border-left: 0; border-top: 1px solid var(--line); }
  .category-rail { max-height: 620px; }
  .user-button { min-width: auto; }
  .user-button small, .pos-brand small { display: none; }
}

@media print {
  @page { size: 80mm auto; margin: 0; }
  body * { visibility: hidden !important; }
  #posReceiptModal, #posReceiptModal * { visibility: visible !important; }
  #posReceiptModal { position: absolute; inset: 0 auto auto 0; display: block; padding: 0; }
  .shade, .receipt-buttons { display: none !important; }
  .receipt-window { width: 80mm; max-height: none; overflow: visible; padding: 0; border-radius: 0; box-shadow: none; background: white; }
  .receipt { width: 80mm; max-width: none; }
}
