:root {
  font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  line-height: 1.5;
  color: #202124;
  background: #f4f5f7;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #ffffff;
  --surface-soft: #f8f9fa;
  --border: #dfe3e8;
  --text-soft: #667085;
  --primary: #a91520;
  --primary-dark: #7f1018;
  --danger: #b42318;
  --success: #16794b;
  --shadow: 0 12px 34px rgba(16, 24, 40, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background: #f4f5f7;
}

body.cart-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #222222;
  border-radius: 10px;
  background: #ffffff;
  color: #202124;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  background: #f5f5f5;
}

button:focus-visible,
input:focus-visible,
.category-nav a:focus-visible {
  outline: 3px solid rgba(169, 21, 32, 0.25);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(16, 24, 40, 0.05);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 27px);
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 14px;
}

.table-entry,
.table-info {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.table-entry input {
  width: 180px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #b8bec7;
  border-radius: 10px;
  background: #ffffff;
  font-size: 16px;
}

.table-entry button,
#refreshButton {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.table-entry button:hover,
#refreshButton:hover {
  background: var(--primary-dark);
}

.table-info {
  flex-wrap: wrap;
}

#tableLabel {
  max-width: 420px;
  overflow-wrap: anywhere;
  font-weight: 700;
}

#logoutButton {
  border-color: #b8bec7;
}

main {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 16px 18px 90px;
}

.status-panel {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid #d8e7de;
  border-radius: 10px;
  background: #eef8f2;
  color: #185c3b;
  overflow-wrap: anywhere;
}

.status-panel.error {
  border-color: #f0b8b8;
  background: #fff0f0;
  color: #9c1c1c;
}

.status-panel.saving {
  border-color: #f0d58b;
  background: #fff8dc;
  color: #73510b;
}

.status-panel.saved {
  border-color: #a8d8bd;
  background: #eaf8ef;
  color: var(--success);
}

.category-nav {
  position: sticky;
  top: 82px;
  z-index: 20;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 14px;
  background: linear-gradient(#f4f5f7 75%, rgba(244, 245, 247, 0));
  scrollbar-width: thin;
}

.category-nav a {
  flex: 0 0 auto;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: #202124;
  text-decoration: none;
  white-space: nowrap;
}

.category-nav a:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.category-section {
  margin-bottom: 32px;
  scroll-margin-top: 150px;
}

.category-heading,
.subcategory-heading {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.category-title {
  margin: 14px 0 4px;
  font-size: 25px;
}

.subcategory-title {
  margin: 14px 0 4px;
  font-size: 20px;
}

.category-title-en,
.subcategory-title-en {
  color: var(--text-soft);
}

.subcategory-section {
  margin-top: 14px;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.menu-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  min-height: 140px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.04);
}

.item-main {
  min-width: 0;
  flex: 1 1 auto;
}

.item-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.item-code {
  color: #7a8089;
  font-size: 13px;
}

.item-name-zh {
  margin: 4px 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.item-name-en,
.item-meta {
  color: var(--text-soft);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.item-meta:empty {
  display: none;
}

.item-price {
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.item-qty,
.cart-item-qty {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}

.qty-btn,
.cart-qty-btn {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: #ffffff;
  font-size: 23px;
  font-weight: 700;
  line-height: 1;
}

.qty-btn:hover,
.cart-qty-btn:hover {
  background: #eceff2;
}

.qty-plus,
.cart-qty-plus {
  background: var(--primary);
  color: #ffffff;
}

.qty-plus:hover,
.cart-qty-plus:hover {
  background: var(--primary-dark);
}

.qty-display,
.cart-qty-display {
  min-width: 30px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.cart-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 42;
  width: 62px;
  min-width: 62px;
  height: 62px;
  min-height: 62px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.cart-toggle:hover {
  background: var(--primary-dark);
}

.cart-icon {
  font-size: 28px;
}

.cart-badge {
  position: absolute;
  top: -4px;
  right: -3px;
  min-width: 24px;
  height: 24px;
  padding: 1px 6px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #ffcf33;
  color: #332500;
  font-size: 13px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.cart-overlay {
  position: fixed;
  inset: 0;
  z-index: 49;
  visibility: hidden;
  background: rgba(15, 23, 42, 0.46);
  opacity: 0;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.cart-overlay.open,
.cart-overlay.active {
  visibility: visible;
  opacity: 1;
}

.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(430px, 100vw);
  height: 100dvh;
  border-left: 1px solid var(--border);
  background: var(--surface);
  box-shadow: -16px 0 42px rgba(16, 24, 40, 0.2);
  transform: translateX(105%);
  transition: transform 200ms ease;
}

.cart-drawer.open,
.cart-drawer.active {
  transform: translateX(0);
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.cart-header h2 {
  margin: 0;
  font-size: 22px;
}

#cartClose {
  width: 44px;
  min-width: 44px;
  padding: 0;
  border-color: transparent;
  font-size: 20px;
}

.cart-items {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px 16px;
}

.cart-empty {
  margin: 40px 0;
  color: var(--text-soft);
  text-align: center;
}

.cart-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid #eceff2;
}

.cart-item-info {
  min-width: 0;
}

.cart-item-name {
  margin-bottom: 4px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.cart-item-detail {
  color: var(--text-soft);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.cart-item-actions {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-items: end;
  gap: 8px;
}

.cart-item-price {
  grid-column: 1 / -1;
  color: #344054;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.cart-remove-btn {
  width: 42px;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border-color: #e9b7b7;
  color: var(--danger);
}

.cart-footer {
  padding: 14px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.cart-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 19px;
  font-weight: 800;
}

#cartTotalPrice {
  font-variant-numeric: tabular-nums;
}

.cart-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
}

#clearCartButton {
  border-color: #d5dae0;
}

#saveDraftButton {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

#saveDraftButton:hover {
  background: var(--primary-dark);
}

.draft-status,
.cart-draft-status {
  margin: 0 0 10px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #f2f4f7;
  color: #475467;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.draft-status.saving,
.cart-draft-status.saving {
  background: #fff5d6;
  color: #7a5100;
}

.draft-status.saved,
.cart-draft-status.saved {
  background: #e9f7ee;
  color: var(--success);
}

.draft-status.error,
.cart-draft-status.error {
  background: #fff0f0;
  color: var(--danger);
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 13px 14px;
  }

  .table-entry,
  .table-info {
    width: 100%;
    justify-content: stretch;
  }

  .table-entry input {
    min-width: 0;
    width: auto;
    flex: 1 1 auto;
  }

  .table-info {
    align-items: stretch;
  }

  #tableLabel {
    width: 100%;
    max-width: none;
  }

  .table-info button {
    flex: 1 1 0;
  }

  main {
    padding: 12px 12px 92px;
  }

  .category-nav {
    top: 0;
    margin: 0 -12px;
    padding: 8px 12px 13px;
  }

  .item-grid {
    grid-template-columns: 1fr;
  }

  .menu-item {
    min-height: 126px;
    padding: 13px;
  }

  .cart-toggle {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  .topbar h1 {
    font-size: 20px;
  }

  .topbar p {
    font-size: 13px;
  }

  .table-entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .table-info {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
  }

  #tableLabel {
    grid-column: 1 / -1;
  }

  .category-title {
    font-size: 22px;
  }

  .subcategory-title {
    font-size: 18px;
  }

  .menu-item {
    align-items: flex-start;
  }

  .item-right {
    gap: 10px;
  }

  .item-price {
    font-size: 17px;
  }

  .qty-btn {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
  }

  .cart-item {
    grid-template-columns: 1fr;
  }

  .cart-item-actions {
    grid-template-columns: auto minmax(0, 1fr) auto;
    justify-items: stretch;
  }

  .cart-item-price {
    grid-column: auto;
    justify-self: start;
  }

  .cart-item-qty {
    justify-self: center;
  }

  .cart-remove-btn {
    justify-self: end;
  }

  .cart-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* 顾客菜单主体容器：明确防止网格或长文本撑破页面 */
.menu-root {
  min-width: 0;
  width: 100%;
}

/* 减号按钮沿用通用数量按钮，并明确普通次级操作外观 */
.qty-minus {
  color: #344054;
  background: #ffffff;
}

.qty-minus:hover {
  background: #eceff2;
}
