/* Màu mang nghĩa: chàm = ảnh chụp, xanh ngọc = bán, hổ phách = mua, hồng = đồng bộ, xám đậm = người xác nhận */
:root {
  color-scheme: light;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #94a3b8;
  --bg: #f8fafc;
  --card: #ffffff;
  --camera: #4338ca;
  --sale: #0f766e;
  --sale-soft: #f0fdfa;
  --buy: #b45309;
  --buy-soft: #fffbeb;
  --sync: #be123c;
  --sync-soft: #fff1f2;
  --confirm: #334155;
  --confirm-soft: #f1f5f9;
  --error: #b91c1c;
  --error-soft: #fee2e2;
  --warn: #92400e;
  --warn-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --radius: 10px;
  --nav-h: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0;
  text-wrap: balance;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.95rem;
}

p {
  margin: 0.4rem 0;
}

a {
  color: inherit;
}

.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.center {
  text-align: center;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.block {
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

:focus-visible {
  outline: 3px solid var(--camera);
  outline-offset: 2px;
}

/* Khung ứng dụng */
.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: 'top top' 'nav main';
}

.topbar {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--confirm);
  color: #fff;
}

.brand {
  font-weight: 600;
  text-decoration: none;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  text-decoration: none;
  background: rgb(255 255 255 / 0.14);
  white-space: nowrap;
}

.sync-pill .icon {
  width: 15px;
  height: 15px;
}

.sync-off,
.sync-bad {
  background: var(--sync);
}

.sync-busy .icon {
  animation: spin 1.2s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sync-busy .icon {
    animation: none;
  }
}

.nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  border-right: 1px solid var(--line);
  background: var(--card);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
}

.nav-item:hover {
  background: var(--bg);
}

.nav-item.is-on {
  background: var(--confirm-soft);
  color: var(--ink);
  font-weight: 600;
}

.page {
  grid-area: main;
  min-width: 0;
  padding: 16px;
}

.view {
  max-width: 1160px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.greeting {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
}

.section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.row-end {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.center-row {
  justify-content: center;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

/* Nút */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: var(--bg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--confirm);
  border-color: var(--confirm);
  color: #fff;
}

.btn-primary:hover {
  background: #1e293b;
}

.btn-confirm {
  background: var(--confirm);
  border-color: var(--confirm);
  color: #fff;
}

.btn-confirm:hover {
  background: #1e293b;
}

.btn-danger {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

.btn-danger:hover {
  background: #991b1b;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-small {
  min-height: 36px;
  padding: 4px 10px;
  font-size: 0.9rem;
}

.btn-large {
  min-height: 52px;
  font-size: 1.05rem;
}

.btn-wide {
  width: 100%;
}

.btn-fix {
  border-color: var(--confirm);
  color: var(--confirm);
}

.link-btn {
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Thông báo và nhãn */
.banner {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
}

.banner-error {
  background: var(--error-soft);
  border-color: #fca5a5;
  color: #7f1d1d;
}

.banner-warn {
  background: var(--warn-soft);
  border-color: #fcd34d;
  color: #78350f;
}

.banner-info {
  background: var(--info-soft);
  border-color: #93c5fd;
  color: #1e3a8a;
}

.banner-ok {
  background: var(--ok-soft);
  border-color: #86efac;
  color: #14532d;
}

.banner-sync {
  background: var(--sync-soft);
  border-color: #fda4af;
  color: #881337;
}

.link-banner {
  display: block;
  text-decoration: none;
}

.plain-list {
  margin: 0;
  padding-left: 18px;
}

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--confirm-soft);
  color: var(--confirm);
}

.chip-sync {
  background: var(--sync-soft);
  color: var(--sync);
}

.chip-error {
  background: var(--error-soft);
  color: var(--error);
}

.chip-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip-confirm {
  background: var(--confirm);
  color: #fff;
}

/* Biểu mẫu */
.input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}

.input-compact {
  width: auto;
  min-height: 36px;
  padding: 4px 8px;
  font-size: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 500;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}

.form-grid > .btn {
  align-self: end;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 130px auto;
  gap: 8px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.filters > .input {
  flex: 1 1 240px;
  width: auto;
}

.segments {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.seg {
  min-height: 40px;
  padding: 4px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.seg.is-on {
  background: var(--confirm);
  border-color: var(--confirm);
  color: #fff;
}

/* Trang chủ */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
}

.module-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--tone);
  border-radius: var(--radius);
}

.tone-buy {
  --tone: var(--buy);
  --tone-soft: var(--buy-soft);
}

.tone-sale {
  --tone: var(--sale);
  --tone-soft: var(--sale-soft);
}

.module-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-size: 1.1rem;
}

.module-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--tone-soft);
  color: var(--tone);
}

.module-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

/* Danh sách phiếu */
.doc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
}

.doc-row:hover {
  border-color: var(--line-strong);
}

.doc-row.is-void .doc-total {
  text-decoration: line-through;
  color: var(--muted);
}

.doc-main {
  min-width: 0;
}

.doc-title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.doc-total {
  font-weight: 600;
  white-space: nowrap;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

/* Phiếu theo mẫu giấy */
.paper {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--tone);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.paper-buy {
  --tone: var(--buy);
}

.paper-sale {
  --tone: var(--sale);
}

.paper-title {
  text-align: center;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

.paper-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 10px;
}

.paper-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
}

.table-wrap {
  overflow-x: auto;
}

.paper-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.paper-table th,
.paper-table td {
  border: 1px solid var(--line-strong);
  padding: 5px 7px;
}

.paper-table thead th {
  font-size: 0.8rem;
  background: var(--confirm-soft);
}

.data-table th,
.data-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.data-table .num {
  text-align: right;
}

/* Báo cáo theo kỳ: số phiếu nhỏ dưới số tiền, chênh lệch âm tô đỏ, dòng CỘNG đậm */
.cell-sub {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.num-neg {
  color: var(--error);
}

.report-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--line-strong);
  border-bottom: 0;
}

.report-filters .segments .seg {
  min-width: 64px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.history {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history > li {
  border-left: 3px solid var(--line-strong);
  padding-left: 10px;
}

/* Màn hình nhập và đối chiếu */
.editor {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.editor-main {
  flex: 1 1 auto;
}

.editor-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.row-grid {
  display: grid;
  grid-template-columns: 34px minmax(150px, 1fr) 64px 72px 108px 118px 36px;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}

.row-head {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 4px;
}

.cell-stt {
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cell {
  display: block;
  min-width: 0;
}

.cell-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.cell-input {
  min-height: 40px;
  padding: 6px 8px;
}

.tint-error {
  background: var(--error-soft);
  border-color: var(--error);
}

.tint-warn {
  background: var(--warn-soft);
  border-color: #d97706;
}

.tint-info {
  background: var(--info-soft);
  border-color: #60a5fa;
}

.row-del {
  display: grid;
  place-items: center;
  width: 36px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.row-del:hover {
  background: var(--error-soft);
  color: var(--error);
}

.row-del .icon {
  width: 17px;
  height: 17px;
}

/* Mũi tên gợi ý chiếm chỗ làm cụt chữ trong ô hẹp; gõ vào ô vẫn hiện danh sách gợi ý */
.row-grid input[list]::-webkit-calendar-picker-indicator {
  display: none !important;
}

/* Thành tiền của hóa đơn do ứng dụng tính, chỉ để xem */
.cell-auto {
  background: var(--confirm-soft);
  border-style: dashed;
  cursor: default;
}

/* Danh sách món xổ xuống dưới ô Tên */
.suggest {
  position: fixed;
  z-index: 40;
  max-height: min(340px, 50vh);
  overflow-y: auto;
  padding: 4px 0;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgb(15 23 42 / 0.2);
}

.suggest[hidden] {
  display: none;
}

.suggest-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 9px 12px;
  cursor: pointer;
}

.suggest-item:hover {
  background: var(--confirm-soft);
}

.suggest-item.is-active {
  background: var(--info-soft);
  box-shadow: inset 3px 0 0 var(--info);
}

.suggest-name {
  min-width: 0;
  font-weight: 500;
}

.suggest-meta {
  flex: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.suggest-hint {
  margin-top: 4px;
  padding: 6px 12px 3px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

/* Bảng danh mục món, bày như hóa đơn nhưng không có Số lượng, Thành tiền */
/* Phần đầu (tiêu đề, lời dẫn, ô tìm, tên bảng, hàng tên cột) đứng yên ngay dưới thanh trên cùng khi cuộn */
.menu-head {
  position: sticky;
  top: var(--topbar-h, 47px);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* Che các dòng cuộn lên phía sau, kể cả khoảng đệm giữa thanh trên cùng và tiêu đề */
  margin-top: -16px;
  padding-top: 16px;
  background: var(--bg);
}

.paper.menu-paper-top {
  border-bottom: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  padding-bottom: 0;
}

.menu-paper-top .row-head {
  padding-bottom: 8px;
}

.menu-paper-body {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 6px 14px 14px;
}

.menu-grid {
  display: grid;
  grid-template-columns: 40px minmax(180px, 1fr) 110px 140px 76px;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}

.menu-grid.row-head {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 4px;
}

.menu-grid.is-off .cell-input {
  text-decoration: line-through;
  color: var(--muted);
}

.menu-grid .row-del,
.menu-restore {
  justify-self: start;
}

.menu-grid input[list]::-webkit-calendar-picker-indicator {
  display: none !important;
}

.cell-input.is-changed {
  background: var(--warn-soft);
}

.menu-empty {
  padding: 12px 0;
}

.menu-save {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 -6px 18px rgb(15 23 42 / 0.08);
}

.menu-issues {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 30vh;
  overflow-y: auto;
}

.menu-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.row-total {
  display: grid;
  grid-template-columns: auto minmax(120px, 170px) auto;
  justify-content: end;
  align-items: end;
  gap: 14px;
  padding-top: 8px;
  border-top: 1px solid var(--line-strong);
}

.total-label {
  font-weight: 700;
  align-self: center;
}

.total-written {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.total-computed {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 110px;
  font-size: 1.1rem;
  padding-bottom: 8px;
}

.camera-step,
.camera-status {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.camera-preview {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.issues-panel,
.save-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.save-panel {
  border-color: var(--confirm);
}

.issues {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.issue {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  border-left: 4px solid var(--line-strong);
  background: var(--bg);
}

.issue-error {
  border-left-color: var(--error);
  background: var(--error-soft);
}

.issue-warn {
  border-left-color: #d97706;
  background: var(--warn-soft);
}

.issue-info {
  border-left-color: #60a5fa;
  background: var(--info-soft);
}

.issue-text {
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.issue-level {
  display: inline-block;
  margin-right: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

.confirm-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-weight: 500;
  cursor: pointer;
}

.confirm-check input {
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  flex: none;
}

.save-reason {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.save-reason:empty {
  display: none;
}

/* Xử lý xung đột */
.action-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--card);
  border: 1px solid #fda4af;
  border-radius: var(--radius);
}

.version-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.version-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

/* Báo cáo */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.stat {
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1.2rem;
}

.stat-sale {
  border-top: 4px solid var(--sale);
}

.stat-buy {
  border-top: 4px solid var(--buy);
}

.stat-neutral {
  border-top: 4px solid var(--confirm);
}

/* Danh mục, tài khoản */
.catalog-list,
.user-list,
.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.catalog-item,
.user,
.device {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.is-off {
  opacity: 0.6;
}

.catalog-main,
.user-main {
  min-width: 0;
}

.device .chip {
  margin-left: 6px;
}

.settings-links {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
}

/* Đăng nhập */
.auth {
  max-width: 420px;
  margin: 8vh auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Hộp thoại, thông báo nổi */
.dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0;
  border-radius: 12px;
  padding: 18px;
  color: var(--ink);
}

.dialog::backdrop {
  background: rgb(15 23 42 / 0.5);
}

/* Khung ẩn chứa file PDF đang in; cần có kích thước thì trình xem PDF mới nạp */
.print-frame {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 2px;
  height: 2px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-error {
  background: var(--error);
}

.toast-warn {
  background: var(--warn);
}

/* Màn hình rộng: cảnh báo và nút lưu nằm bên phải, luôn nhìn thấy khi cuộn */
@media (min-width: 1100px) {
  .editor {
    flex-direction: row;
    align-items: flex-start;
  }

  .editor-side {
    flex: 0 0 340px;
    position: sticky;
    top: 62px;
    max-height: calc(100dvh - 78px);
    overflow-y: auto;
  }
}

/* Điện thoại: thanh điều hướng dưới đáy, mỗi dòng phiếu thành một thẻ */
@media (max-width: 760px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'top' 'main';
  }

  .nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .nav-item {
    flex: 1 1 0;
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    font-size: 0.72rem;
    text-align: center;
    min-width: 0;
  }

  .wide-only {
    display: none;
  }

  .page {
    padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  }

  .toast {
    bottom: calc(var(--nav-h) + 16px);
  }

  .settings-links {
    display: flex;
  }

  body.editing .nav {
    display: none;
  }

  body.editing .page {
    padding-bottom: 24px;
  }

  body.editing .toast {
    bottom: 24px;
  }

  .paper-head {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Phiếu đủ sáu cột vẫn nằm gọn trong màn hình điện thoại, không phải kéo ngang mới thấy Thành tiền */
  .paper:not(.editor-main) {
    padding-inline: 10px;
  }

  .paper-table {
    font-size: 0.8rem;
  }

  .paper-table th,
  .paper-table td {
    padding: 4px 3px;
  }

  .paper-table thead th {
    font-size: 0.7rem;
  }

  .row-head {
    display: none;
  }

  .menu-grid {
    grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr) 40px;
    grid-template-areas: 'stt name name del' 'stt unit price del';
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }

  .menu-grid .cell-name {
    grid-area: name;
  }

  .menu-grid .cell-unit {
    grid-area: unit;
  }

  .menu-grid .cell-price {
    grid-area: price;
  }

  .menu-grid > :last-child {
    grid-area: del;
  }

  .menu-save {
    bottom: calc(var(--nav-h) + 8px);
  }

  /* Điện thoại: mỗi món là một thẻ có sẵn tên cột, không có hàng tên cột để giữ; để cả trang cuộn tự nhiên */
  .menu-head {
    position: static;
    margin-top: 0;
    padding-top: 0;
  }

  .menu-paper-body {
    padding-inline: 10px;
  }

  .row-grid {
    grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1fr) 36px;
    grid-template-areas: 'stt name name del' 'stt qty unit unit' 'stt price amount amount';
    gap: 6px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    align-items: start;
  }

  .cell-stt {
    grid-area: stt;
    padding-top: 24px;
    font-weight: 600;
  }

  .cell-name {
    grid-area: name;
  }

  .cell-qty {
    grid-area: qty;
  }

  .cell-unit {
    grid-area: unit;
  }

  .cell-price {
    grid-area: price;
  }

  .cell-amount {
    grid-area: amount;
  }

  .row-del {
    grid-area: del;
    margin-top: 22px;
  }

  .cell-label {
    position: static;
    display: block;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 2px;
  }

  .row-total {
    grid-template-columns: auto minmax(0, 1fr) auto;
    justify-content: stretch;
    gap: 10px;
  }

  .total-computed {
    min-width: 0;
    font-size: 1rem;
  }

  .editor-side {
    display: contents;
  }

  .editor {
    display: flex;
    flex-direction: column;
  }

  .inline-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .inline-form > :first-child,
  .inline-form > button {
    grid-column: 1 / -1;
  }
}

/* Cài lên điện thoại: địa chỉ và mã QR để quét */
.address-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin: 12px 0;
}

.address-block .qr {
  width: 180px;
  height: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.address-text {
  min-width: 0;
  flex: 1 1 220px;
}

.address-block .address {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.phone-access h3 {
  margin: 20px 0 4px;
  font-size: 1.05rem;
}

.phone-access h3:first-child {
  margin-top: 0;
}

.phone-access .steps {
  margin: 8px 0 12px;
  padding-left: 20px;
}

.phone-access .steps li + li {
  margin-top: 4px;
}

.phone-access code {
  padding: 1px 6px;
  background: var(--surface-2, rgba(0, 0, 0, 0.06));
  border-radius: 4px;
  font-size: 0.9em;
  user-select: all;
}

.wifi-address {
  margin: 12px 0;
}

.wifi-address summary {
  cursor: pointer;
  font-weight: 600;
}
