:root {
  color-scheme: light;
  --ink: #1d2228;
  --muted: #68707a;
  --line: #e7e1d7;
  --paper: #fffdf8;
  --surface: #ffffff;
  --wash: #f6efe5;
  --accent: #b73e2e;
  --accent-dark: #8f2d24;
  --gold: #c8a45d;
  --green: #296b4f;
  --shadow: 0 16px 40px rgba(62, 45, 28, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(246, 239, 229, 0.82), rgba(255, 253, 248, 0.94)),
    var(--paper);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid rgba(183, 62, 46, 0.16);
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(18px);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent);
  color: #fff9ef;
  font-weight: 800;
  font-size: 22px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.18;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.city-tabs {
  display: flex;
  max-width: 100%;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

body:not([data-view="menu"]) .category-rail,
body:not([data-view="menu"]) .selection-panel,
body:not([data-view="menu"]) .mobile-bar,
body:not([data-view="menu"]) .search-box {
  display: none;
}

body:not([data-view="menu"]) .page-shell {
  grid-template-columns: minmax(0, 1fr);
  width: min(1080px, 100%);
}

.city-tab {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}

.city-tab.active {
  border-color: transparent;
  background: var(--ink);
  color: #fff;
}

.page-shell {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 360px;
  gap: 22px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) 42px;
}

.category-rail,
.selection-panel {
  position: sticky;
  top: 96px;
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.category-rail {
  max-height: calc(100vh - 118px);
  overflow: hidden;
}

.rail-title {
  padding: 16px 16px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.category-list {
  display: grid;
  gap: 4px;
  max-height: calc(100vh - 165px);
  overflow-y: auto;
  padding: 0 8px 10px;
}

.category-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.category-button.active,
.category-button:hover {
  background: var(--wash);
  color: var(--accent-dark);
}

.category-button span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-button .count {
  color: var(--gold);
  font-size: 12px;
}

.menu-area {
  min-width: 0;
}

.menu-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.breadcrumb {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  display: flex;
  align-items: center;
  width: min(320px, 45%);
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0 0 0 8px;
  background: transparent;
}

.menu-content {
  display: grid;
  gap: 28px;
}

.directory-grid,
.restaurant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.directory-card,
.restaurant-card {
  display: grid;
  gap: 12px;
  min-height: 172px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.directory-card p,
.restaurant-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.directory-meta {
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.restaurant-card {
  align-content: start;
}

.restaurant-card.is-pending {
  background: rgba(255, 255, 255, 0.72);
}

.status-badge {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--wash);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-badge.ready {
  background: rgba(41, 107, 79, 0.12);
  color: var(--green);
}

.category-section {
  scroll-margin-top: 112px;
}

.category-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.category-head small {
  color: var(--muted);
}

.dish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.dish-card {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 12px;
  min-height: 136px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.dish-card.is-added {
  border-color: rgba(183, 62, 46, 0.65);
  box-shadow: 0 0 0 3px rgba(183, 62, 46, 0.12), var(--shadow);
}

.dish-image {
  width: 94px;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  object-fit: cover;
  background: var(--wash);
}

.image-fallback {
  display: grid;
  place-items: center;
  color: var(--accent-dark);
  font-size: 28px;
  font-weight: 800;
}

.dish-card.is-soldout {
  opacity: 0.72;
}

.dish-body {
  display: grid;
  min-width: 0;
  align-content: space-between;
  gap: 8px;
}

.dish-title {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  min-width: 0;
}

.dish-title h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.soldout {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: #f1ebe3;
  color: var(--muted);
  font-size: 12px;
}

.dish-meta {
  color: var(--muted);
  font-size: 12px;
}

.dish-foot {
  display: grid;
  grid-template-columns: minmax(78px, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.price {
  min-width: 0;
  color: var(--accent-dark);
  font-weight: 800;
  white-space: nowrap;
}

.stepper {
  display: grid;
  grid-template-columns: 30px 28px 30px;
  align-items: center;
  justify-items: center;
  width: 88px;
  min-width: 88px;
  height: 34px;
}

.stepper button {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: #fff;
  color: var(--accent-dark);
  font-size: 22px;
  line-height: 1;
}

.stepper button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.qty {
  min-width: 24px;
  text-align: center;
  font-weight: 700;
}

.selection-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

@media (min-width: 1181px) {
  .selection-panel {
    position: relative;
    top: auto;
    max-height: none;
    overflow: visible;
  }
}

.selection-head,
.total-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ghost-button,
.primary-button,
.download-link {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  text-decoration: none;
}

.ghost-button {
  padding: 0 12px;
  background: var(--wash);
  color: var(--accent-dark);
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.compact {
  width: fit-content;
  min-width: 106px;
  padding: 0 14px;
}

.ghost-button:disabled,
.primary-button:disabled {
  opacity: 0.48;
}

.empty-state {
  display: grid;
  gap: 8px;
  min-height: 220px;
  place-content: center;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.selection-table-wrap {
  overflow: visible;
}

@media (min-width: 1181px) {
  .selection-table-wrap {
    overflow: visible;
    padding-right: 0;
  }
}

.selection-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--wash);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-chip.total {
  background: rgba(183, 62, 46, 0.11);
  color: var(--accent-dark);
}

.selection-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.selection-table th,
.selection-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.selection-table th {
  background: var(--wash);
  color: var(--muted);
  font-weight: 800;
}

.selection-group-row th {
  position: static;
  padding: 8px 10px;
  background: var(--ink);
  color: #fff;
}

.selection-group-row th span,
.selection-group-row th em {
  display: inline-block;
}

.selection-group-row th em {
  float: right;
  color: #fff6e9;
  font-style: normal;
  font-weight: 700;
}

.selection-table td:nth-child(2),
.selection-table td:nth-child(3),
.selection-table th:nth-child(2),
.selection-table th:nth-child(3) {
  text-align: right;
  white-space: nowrap;
}

.selection-table th:nth-child(1),
.selection-table td:nth-child(1) {
  width: 62%;
}

.selection-table th:nth-child(2),
.selection-table td:nth-child(2) {
  width: 46px;
}

.selection-table th:nth-child(3),
.selection-table td:nth-child(3) {
  width: 72px;
}

.selection-table td strong,
.selection-table td small {
  display: block;
}

.selection-table td small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.note-input {
  width: 100%;
  min-height: 34px;
  margin-top: 8px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
}

.selection-dish {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.selection-thumb {
  width: 34px;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  object-fit: cover;
  background: var(--wash);
}

.selection-dish-main {
  min-width: 0;
}

.selection-name-line {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  justify-content: space-between;
}

.selection-name-line strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.note-toggle {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.note-display {
  margin-top: 6px;
  color: var(--accent-dark);
  font-size: 12px;
  line-height: 1.35;
}

.note-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200, 164, 93, 0.16);
}

.dish-note-input {
  margin-top: 0;
}

.selection-empty {
  display: none;
  padding: 28px 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.selection-empty.show {
  display: block;
}

.total-line {
  padding-top: 4px;
}

.total-line strong {
  color: var(--accent-dark);
  font-size: 22px;
}

.capture-preview {
  display: grid;
  gap: 10px;
}

.capture-preview img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.capture-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.download-link {
  display: grid;
  width: 100%;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.mobile-bar {
  display: none;
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(29, 34, 40, 0.92);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.app-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1180px) {
  .page-shell {
    grid-template-columns: 150px minmax(0, 1fr);
  }

  .selection-panel {
    position: relative;
    top: auto;
    grid-column: 2;
  }
}

@media (max-width: 820px) {
  body {
    padding-bottom: 74px;
  }

  body:not([data-view="menu"]) {
    padding-bottom: 0;
  }

  .topbar {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  h1 {
    font-size: 20px;
  }

  .top-actions {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .directory-grid,
  .restaurant-grid {
    grid-template-columns: 1fr;
  }

  .page-shell {
    display: grid;
    grid-template-columns: 94px minmax(0, 1fr);
    gap: 10px;
    padding: 12px 8px 24px;
  }

  body:not([data-view="menu"]) .page-shell {
    display: grid;
    padding: 16px 12px 24px;
  }

  .category-rail {
    position: sticky;
    top: 8px;
    z-index: 15;
    margin: 0;
    max-height: calc(100vh - 88px);
    border-radius: 8px;
    overflow: hidden;
  }

  .rail-title {
    display: none;
  }

  .category-list {
    display: grid;
    gap: 4px;
    max-height: calc(100vh - 104px);
    padding: 8px;
    overflow-y: auto;
  }

  .category-button {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    gap: 4px;
    padding: 0 6px;
    font-size: 13px;
    white-space: normal;
  }

  .category-button span:first-child {
    white-space: nowrap;
  }

  .category-button .count {
    font-size: 11px;
  }

  .menu-area {
    min-width: 0;
  }

  .menu-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

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

  .dish-card {
    grid-template-columns: 60px minmax(0, 1fr);
    min-height: 120px;
  }

  .dish-image {
    width: 60px;
  }

  .dish-foot {
    grid-template-columns: minmax(54px, 1fr) auto;
    gap: 4px;
  }

  .price {
    font-size: 14px;
  }

  .stepper {
    grid-template-columns: 24px 22px 24px;
    width: 70px;
    min-width: 70px;
  }

  .stepper button {
    width: 24px;
    height: 24px;
    font-size: 18px;
  }

  .selection-panel {
    grid-column: 1 / -1;
    margin-top: 18px;
  }

  body.viewing-selection .page-shell {
    display: block;
    padding: 0;
  }

  body.viewing-selection .category-rail {
    display: none;
  }

  body.viewing-selection .menu-area {
    display: none;
  }

  body.viewing-selection .selection-panel {
    position: fixed;
    top: 10px;
    right: 10px;
    bottom: 74px;
    left: 10px;
    z-index: 60;
    display: block;
    margin: 0;
    overflow-y: auto;
    border-radius: 8px;
    box-shadow: 0 20px 54px rgba(29, 34, 40, 0.24);
  }

  .mobile-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 64px;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.96);
    box-shadow: 0 -10px 28px rgba(62, 45, 28, 0.12);
  }

  .mobile-bar div {
    display: grid;
    gap: 2px;
  }

  .mobile-bar span {
    color: var(--muted);
    font-size: 12px;
  }

  .mobile-bar strong {
    color: var(--accent-dark);
    font-size: 18px;
  }

  .mobile-bar a {
    display: grid;
    min-height: 42px;
    min-width: 116px;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
  }
}

@media (max-width: 420px) {
  .topbar {
    padding: 14px 12px;
  }

  .city-tab {
    padding: 0 12px;
  }

  .dish-card {
    gap: 10px;
    padding: 9px;
  }

  .stepper {
    grid-template-columns: 24px 22px 24px;
    width: 70px;
    min-width: 70px;
  }
}
