* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: #f2f0eb; color: #222; font-size: 16px;
  user-select: none; -webkit-user-select: none; overflow: hidden;
}
input, textarea, select { font: inherit; user-select: text; -webkit-user-select: text; }
button {
  font: inherit; border: 0; border-radius: 10px; cursor: pointer;
  background: #fff; color: #222; padding: 10px 14px; touch-action: manipulation;
}
button:active { transform: scale(0.97); filter: brightness(0.92); }
button:disabled { opacity: .45; }
.btn-primary { background: #1f7a4d; color: #fff; }
.btn-dark { background: #2b2b2b; color: #fff; }
.btn-warn { background: #c0392b; color: #fff; }
.btn-blue { background: #2463a6; color: #fff; }
.btn-ghost { background: transparent; border: 2px solid #ccc; }

/* ---------- 顶部 ---------- */
.topbar {
  height: 58px; background: #2b2b2b; color: #fff; display: flex; align-items: center;
  gap: 10px; padding: 0 12px;
}
.topbar .title { font-size: 20px; font-weight: 700; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar button { background: #444; color: #fff; padding: 10px 16px; font-size: 16px; }
.topbar .clock { font-variant-numeric: tabular-nums; opacity: .8; margin-right: 6px; }
.badge { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 11px; background: #e67e22; color: #fff; font-size: 14px; margin-left: 4px; }

/* ---------- 点单主画面 ---------- */
.pos { display: grid; grid-template-columns: 150px 1fr 390px; height: calc(100% - 58px); }
.cats { background: #e4e1d9; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.cats button { padding: 18px 8px; font-size: 17px; font-weight: 600; text-align: center; word-break: break-all; }
.cats button.on { background: #1f7a4d; color: #fff; }
.items { overflow-y: auto; padding: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; align-content: start; }
.items button { height: 96px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.items .n { font-size: 18px; font-weight: 600; line-height: 1.2; text-align: center; word-break: break-word; }
.items .p { font-size: 15px; color: #1f7a4d; font-weight: 600; }

.order { background: #fff; display: flex; flex-direction: column; border-left: 1px solid #ddd; min-height: 0; }
.order-head { padding: 10px; border-bottom: 1px solid #eee; display: flex; flex-direction: column; gap: 8px; }
.order-head .row { display: flex; gap: 8px; align-items: center; }
.seg { display: flex; border-radius: 10px; overflow: hidden; border: 2px solid #1f7a4d; }
.seg button { border-radius: 0; background: #fff; color: #1f7a4d; padding: 10px 16px; font-weight: 600; }
.seg button.on { background: #1f7a4d; color: #fff; }
.tablebtn { flex: 1; background: #f4f4f4; font-size: 18px; font-weight: 700; text-align: left; }
.order-no { font-size: 14px; color: #666; }
.lines { flex: 1; overflow-y: auto; min-height: 0; }
.line { display: grid; grid-template-columns: 1fr auto; padding: 10px 12px; border-bottom: 1px solid #f0f0f0; gap: 2px 8px; }
.line:active { background: #f6f6f6; }
.line .ln { font-size: 17px; font-weight: 600; }
.line .lq { color: #1f7a4d; }
.line .la { font-size: 17px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.line .lnote { grid-column: 1 / -1; color: #c0392b; font-size: 14px; }
.empty { color: #999; text-align: center; padding: 40px 10px; }
.totals { padding: 8px 12px; border-top: 1px solid #eee; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; color: #555; }
.totals .grand { font-size: 26px; font-weight: 800; color: #222; margin-top: 4px; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 10px; border-top: 1px solid #eee; }
.actions button { padding: 16px 6px; font-size: 17px; font-weight: 700; }
.actions .pay { grid-column: span 3; font-size: 22px; padding: 18px; }

/* ---------- 弹窗 ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 18px; width: min(560px, 94vw); max-height: 92vh; overflow-y: auto; }
.modal.wide { width: min(900px, 96vw); }
.modal h2 { margin: 0 0 12px; font-size: 22px; }
.modal .foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.modal .foot button { padding: 14px 22px; font-size: 18px; font-weight: 700; }
.display { font-size: 34px; font-weight: 800; text-align: right; background: #f4f4f4; border-radius: 10px; padding: 10px 14px; min-height: 62px; font-variant-numeric: tabular-nums; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.pad button { background: #f0f0f0; font-size: 26px; font-weight: 700; padding: 16px 0; }
.letters { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.letters button { background: #e8eef6; font-size: 20px; font-weight: 700; padding: 10px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { background: #f0f0f0; padding: 12px 16px; font-size: 17px; }
.chips button.on { background: #c0392b; color: #fff; }
.qtyrow { display: flex; align-items: center; gap: 16px; justify-content: center; margin: 10px 0 16px; }
.qtyrow button { width: 70px; height: 70px; font-size: 34px; font-weight: 800; background: #f0f0f0; }
.qtyrow .q { font-size: 40px; font-weight: 800; min-width: 70px; text-align: center; }
.field { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 10px; font-size: 18px; margin-top: 10px; }
.paytotal { display: flex; justify-content: space-between; align-items: baseline; font-size: 20px; margin-bottom: 10px; }
.paytotal b { font-size: 38px; }
.methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.methods button { padding: 18px 0; font-size: 20px; font-weight: 700; background: #f0f0f0; }
.methods button.on { background: #2463a6; color: #fff; }
.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 10px; }
.quick button { background: #e7f3ec; font-size: 18px; font-weight: 700; padding: 14px 0; }
.change { font-size: 22px; margin-top: 10px; text-align: right; }
.change b { font-size: 30px; color: #1f7a4d; }
.bigchange { text-align: center; padding: 10px 0 4px; }
.bigchange .lbl { font-size: 22px; color: #555; }
.bigchange .amt { font-size: 64px; font-weight: 900; color: #1f7a4d; }
.opengrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.opengrid button { text-align: left; background: #f6f3ea; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.opengrid .t { font-size: 22px; font-weight: 800; }
.opengrid .s { color: #666; font-size: 14px; }
.opengrid .m { font-size: 18px; font-weight: 700; color: #1f7a4d; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: #222; color: #fff; padding: 14px 24px; border-radius: 12px; font-size: 18px; z-index: 99; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast.err { background: #c0392b; }

/* ---------- 管理 / 报表页面 ---------- */
.page { height: calc(100% - 58px); overflow-y: auto; padding: 16px; }
.card { background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs button { padding: 12px 22px; font-size: 17px; font-weight: 600; }
.tabs button.on { background: #1f7a4d; color: #fff; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 10px 8px; border-bottom: 1px solid #eee; text-align: left; }
table.grid th { background: #faf9f6; font-size: 14px; color: #666; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.off td { color: #aaa; text-decoration: line-through; }
.form { display: grid; grid-template-columns: 180px 1fr; gap: 10px 14px; align-items: center; max-width: 720px; }
.form input, .form select, .form textarea { padding: 10px; border: 2px solid #ddd; border-radius: 8px; width: 100%; }
.hint { color: #888; font-size: 14px; }
.stat { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat div { background: #f6f3ea; border-radius: 10px; padding: 12px; }
.stat .k { color: #666; font-size: 14px; }
.stat .v { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }

@media (max-width: 1100px) {
  .pos { grid-template-columns: 120px 1fr 340px; }
  .items { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
table.grid button { background: #eef3ef; border: 1px solid #cfdcd3; padding: 8px 16px; }
.card .chips button.on { background: #1f7a4d; }

/* ---------- 手机 ---------- */
html, body { height: 100dvh; }
.mobilebar, .order-close { display: none; }
@media (max-width: 760px) and (orientation: portrait) {
  body { font-size: 15px; }
  .topbar { height: 52px; gap: 6px; padding: 0 8px; overflow-x: auto; }
  .topbar .clock { display: none; }
  .topbar .title { font-size: 16px; min-width: 60px; }
  .topbar button { padding: 8px 10px; font-size: 14px; white-space: nowrap; flex: 0 0 auto; }
  .topbar input[type=date] { flex: 0 0 auto; }
  .pos { display: flex; flex-direction: column; height: calc(100dvh - 52px); }
  .cats { flex-direction: row; overflow-x: auto; overflow-y: hidden; flex: 0 0 auto; padding: 6px; gap: 6px; }
  .cats button { padding: 12px 16px; white-space: nowrap; flex: 0 0 auto; font-size: 15px; }
  .items { flex: 1; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 8px 86px; }
  .items button { height: 82px; padding: 6px; }
  .items .n { font-size: 15px; }
  .items .p { font-size: 14px; }
  .order { position: fixed; top: 52px; left: 0; right: 0; bottom: 0; z-index: 20; border: 0;
           transform: translateY(105%); transition: transform .22s ease; }
  body.show-order .order { transform: none; }
  body.show-order .mobilebar { display: none; }
  .order-close { display: block; background: #f0f0f0; font-weight: 700; padding: 12px; }
  .mobilebar { display: flex; justify-content: space-between; align-items: center; position: fixed;
               left: 8px; right: 8px; bottom: 8px; z-index: 15; background: #1f7a4d; color: #fff;
               padding: 16px 18px; font-size: 17px; border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
  .actions button { padding: 14px 4px; font-size: 16px; }
  .actions .pay { padding: 16px; font-size: 20px; }
  .totals .grand { font-size: 22px; }
  .modal { padding: 14px; }
  .modal h2 { font-size: 19px; }
  .display { font-size: 26px; min-height: 52px; }
  .pad button { font-size: 22px; padding: 12px 0; }
  .paytotal b { font-size: 30px; }
  .methods button { font-size: 15px; padding: 14px 0; }
  .quick { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .quick button { font-size: 15px; padding: 12px 0; }
  .qtyrow button { width: 60px; height: 60px; }
  .bigchange .amt { font-size: 48px; }
  .page { height: calc(100dvh - 52px); padding: 10px; }
  .form { grid-template-columns: 1fr; gap: 4px; }
  .form label { margin-top: 8px; font-weight: 600; }
  table.grid th, table.grid td { padding: 8px 4px; font-size: 14px; }
  .stat { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 19px; }
}

/* Phone held upright on the POS screen: ask to rotate */
.rotate { display: none; }
@media (max-width: 760px) and (orientation: portrait) {
  .rotate { display: flex; position: fixed; inset: 0; z-index: 100; background: #2b2b2b; color: #fff;
            flex-direction: column; align-items: center; justify-content: center; gap: 18px; font-size: 20px; text-align: center; padding: 20px; }
  .rotate .phone { font-size: 70px; animation: turn 1.6s ease-in-out infinite; }
  @keyframes turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
}

/* ---------- Phone in landscape (short screens) ---------- */
.fsbtn { display: none; }
@media (orientation: landscape) and (max-height: 540px) {
  body { font-size: 14px; }
  .topbar { height: 44px; gap: 6px; padding: 0 8px 0 max(8px, env(safe-area-inset-left)); }
  .topbar .title { font-size: 16px; }
  .topbar .clock { font-size: 13px; }
  .topbar button { padding: 6px 10px; font-size: 14px; border-radius: 8px; white-space: nowrap; }
  .fsbtn { display: inline-block; font-size: 16px !important; }
  .badge { font-size: 12px; min-width: 18px; padding: 0 5px; }

  .pos { grid-template-columns: 104px 1fr 290px; height: calc(100dvh - 44px); }
  .cats { padding: 6px; gap: 6px; padding-left: max(6px, env(safe-area-inset-left)); }
  .cats button { padding: 11px 4px; font-size: 14px; border-radius: 8px; }
  .items { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; padding: 6px; }
  .items button { height: 62px; gap: 3px; padding: 4px; border-radius: 8px; }
  .items .n { font-size: 14px; }
  .items .p { font-size: 13px; }

  .order { padding-right: env(safe-area-inset-right); }
  .order-head { padding: 6px 8px; gap: 4px; }
  .seg { border-width: 1.5px; border-radius: 8px; }
  .seg button { padding: 6px 10px; font-size: 13px; }
  .tablebtn { font-size: 14px; padding: 6px 10px; }
  .order-no { font-size: 12px; }
  .line { padding: 6px 10px; }
  .line .ln, .line .la { font-size: 14px; }
  .line .lnote { font-size: 12px; }
  .empty { padding: 16px 8px; }
  .totals { padding: 4px 10px; font-size: 13px; }
  .totals .grand { font-size: 18px; margin-top: 0; }
  .actions { grid-template-columns: 1fr 1fr 0.8fr 1.5fr; gap: 6px; padding: 6px 8px; }
  .actions button { padding: 10px 2px; font-size: 14px; border-radius: 8px; }
  .actions .pay { grid-column: auto; font-size: 17px; padding: 10px 2px; }

  /* Pop-ups: wider and shorter so they fit */
  .modal-bg { align-items: center; }
  .modal { padding: 10px 14px; width: min(640px, 92vw); max-height: 96dvh; border-radius: 12px; }
  .modal h2 { font-size: 16px; margin-bottom: 6px; }
  .modal .foot { margin-top: 8px; }
  .modal .foot button { padding: 9px 18px; font-size: 15px; }
  .display { font-size: 22px; min-height: 40px; padding: 4px 12px; }
  .modal.kp { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; align-content: start;
              grid-template-areas: "h p" "d p" "l p" "f p"; width: min(600px, 92vw); }
  .modal.kp h2 { grid-area: h; }
  .modal.kp .display { grid-area: d; }
  .modal.kp .letters { grid-area: l; }
  .modal.kp .pad { grid-area: p; margin-top: 0; }
  .modal.kp .foot { grid-area: f; align-self: end; flex-wrap: wrap; }
  .modal.kp .foot button { flex: 1; padding: 9px 6px; }
  .pad { gap: 6px; margin-top: 6px; }
  .pad button { font-size: 20px; padding: 9px 0; }
  .letters { gap: 6px; margin-top: 6px; }
  .letters button { font-size: 16px; padding: 7px 0; }
  .chips { gap: 6px; }
  .chips button { padding: 8px 12px; font-size: 14px; }
  .qtyrow { margin: 4px 0 8px; }
  .qtyrow button { width: 50px; height: 50px; font-size: 26px; }
  .qtyrow .q { font-size: 30px; }
  .field { padding: 8px 10px; font-size: 15px; margin-top: 6px; }
  .paytotal { font-size: 15px; margin-bottom: 4px; }
  .paytotal b { font-size: 28px; }
  .methods { gap: 6px; margin-bottom: 6px; }
  .methods button { padding: 10px 0; font-size: 15px; }
  .quick { gap: 6px; margin-top: 6px; }
  .quick button { padding: 9px 0; font-size: 15px; }
  .change { font-size: 15px; margin-top: 4px; }
  .change b { font-size: 22px; }
  .bigchange .lbl { font-size: 16px; }
  .bigchange .amt { font-size: 44px; }
  .opengrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .opengrid button { padding: 10px; }
  .opengrid .t { font-size: 18px; }
  .toast { bottom: 14px; padding: 10px 18px; font-size: 15px; }

  .page { height: calc(100dvh - 44px); padding: 10px max(10px, env(safe-area-inset-left)); }
  .stat .v { font-size: 20px; }
}
@media (orientation: landscape) and (max-height: 540px) and (max-width: 720px) {
  .topbar .clock { display: none; }
}

/* ---------- bill preview ---------- */
.modal.preview { width: min(440px, 96vw); }
.modal.preview .paper { background: #d9d6cf; border-radius: 10px; padding: 12px; max-height: 62dvh; overflow-y: auto; }
.modal.preview iframe { display: block; margin: 0 auto; width: 330px; max-width: 100%; height: 400px; border: 0; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.modal.preview .foot { flex-wrap: wrap; }

/* ---------- table picker ---------- */
.zone { font-weight: 700; color: #666; margin: 10px 0 6px; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.tgrid button { background: #e7f3ec; padding: 12px 6px; display: flex; flex-direction: column; gap: 2px; align-items: center; min-height: 74px; justify-content: center; }
.tgrid .tn { font-size: 20px; font-weight: 800; }
.tgrid .ts { font-size: 12px; color: #555; }
.tgrid button.busy { background: #f6c58f; }
.tgrid button.busy .tm { font-weight: 700; }
.tgrid button.cur { outline: 3px solid #2463a6; }
.items button.out { opacity: .45; }
.items .st { font-size: 12px; color: #c0392b; font-weight: 600; }
.paxbtn { background: #f4f4f4; font-weight: 700; white-space: nowrap; }
.staffbtn { background: #1f7a4d !important; }
.status-pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; }
.st-open { background: #e8eef6; color: #2463a6; } .st-paid { background: #e7f3ec; color: #1f7a4d; }
.st-void { background: #eee; color: #777; } .st-refunded { background: #fbe3e0; color: #c0392b; }
@media (orientation: landscape) and (max-height: 540px) {
  .modal.preview { width: min(560px, 96vw); }
  .modal.preview .paper { max-height: 58dvh; padding: 8px; }
  .tgrid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; }
  .tgrid button { min-height: 56px; padding: 6px 4px; }
  .tgrid .tn { font-size: 16px; }
  .paxbtn { padding: 6px 8px; font-size: 13px; }
}
.seg button { white-space: nowrap; }
.order-head .row { min-width: 0; }
.tablebtn { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (orientation: landscape) and (max-height: 540px) {
  .tablebtn .lbl { display: none; }
  .tablebtn { padding: 6px 6px; text-align: center; flex: 1 1 60px; }
  .order-head .row { gap: 5px; }
  .seg button { font-size: 12.5px; }
  .paxbtn .lbl { display: none; }
  .paxbtn::before { content: "👥 "; }
  .seg button { padding: 6px 8px; }
}
