:root {
  --ink: #1a1512;
  --paper: #f6f1ea;
  --panel: #fffdf9;
  --line: rgba(26, 21, 18, 0.12);
  --accent: #b44a2a;
  --accent-deep: #8f3518;
  --teal: #2f6b5c;
  --free: #3d7a4a;
  --busy: #b44a2a;
  --muted: #6b5f56;
  --radius: 6px;
  --font: "Noto Sans SC", sans-serif;
  --display: "ZCOOL XiaoWei", "Noto Sans SC", serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(180, 74, 42, 0.08), transparent 55%),
    linear-gradient(180deg, #f8f4ef, var(--paper));
  min-height: 100vh;
}

button, input, select { font: inherit; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-deep); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-block { width: 100%; margin-top: 0.75rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: rgba(246, 241, 234, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  font-family: var(--display);
}
.brand a {
  color: var(--ink);
  text-decoration: none;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
}
.brand span { color: var(--muted); font-size: 0.95rem; font-family: var(--font); }
.license-pill {
  margin-left: auto;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(47, 107, 92, 0.12);
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 700;
}
.license-pill.expired {
  background: rgba(180, 74, 42, 0.14);
  color: var(--accent-deep);
}
.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tab {
  border: 0;
  background: transparent;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
}
.tab.active { background: var(--ink); color: #fff; }

main { padding: 1.25rem; }
.view { display: none; }
.view.active { display: block; }
.view-head { margin-bottom: 1rem; max-width: 640px; }
.view-head h2 { margin: 0 0 0.35rem; font-size: 1.45rem; }
.view-head p { margin: 0; color: var(--muted); }

.table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.85rem;
}
.table-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1rem 0.85rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.table-card:hover { transform: translateY(-2px); }
.table-card strong { display: block; font-size: 1.2rem; margin-bottom: 0.35rem; }
.table-card .status { font-size: 0.85rem; font-weight: 700; }
.table-card.free .status { color: var(--free); }
.table-card.busy .status { color: var(--busy); }
.table-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(180, 74, 42, 0.15); }

.order-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  min-height: 70vh;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}
.panel h3 { margin: 0 0 0.35rem; }
#current-table { margin: 0 0 0.85rem; color: var(--muted); }
.cart { flex: 1; overflow: auto; display: grid; gap: 0.55rem; align-content: start; }
.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.cart-item .qty {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}
.cart-item button {
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.cart-foot { padding-top: 0.85rem; border-top: 1px solid var(--line); }
.total { margin-bottom: 0.75rem; }
.total strong { font-size: 1.35rem; color: var(--accent); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.cat-bar { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.85rem; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.dish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}
.dish-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
  cursor: pointer;
}
.dish-card:hover { border-color: rgba(180, 74, 42, 0.45); }
.dish-card strong { display: block; margin-bottom: 0.35rem; }
.dish-card span { color: var(--accent); font-weight: 700; }

.ticket-list, .menu-admin, .bill-list { display: grid; gap: 0.75rem; }
.ticket, .menu-row, .bill-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.ticket header, .bill-row header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}
.ticket ul { margin: 0 0 0.75rem; padding-left: 1.1rem; color: var(--muted); }
.menu-form {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.9fr auto;
  gap: 0.55rem;
  margin-bottom: 1rem;
}
.menu-form input, .menu-form select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.7rem;
  background: #fff;
}
.menu-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
}
.menu-row-meta {
  color: #6b5f56;
  font-size: 0.85rem;
}
.menu-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}
.rename-box {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.45rem;
  align-items: center;
}
.rename-box[hidden] {
  display: none !important;
}
.rename-input {
  flex: 1;
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  background: #fff;
}
.menu-row-actions .btn,
.rename-box .btn {
  min-height: 2.2rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.88rem;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.stat span { display: block; color: var(--muted); font-size: 0.85rem; }
.stat strong { font-size: 1.5rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  z-index: 50;
}
.modal[hidden], .lock-screen[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 10, 0.45);
}
.modal-panel {
  position: relative;
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.pay-ways { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 1rem 0; }

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(26, 21, 18, 0.88);
  padding: 1.25rem;
}
.lock-card {
  width: min(460px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  text-align: center;
}
.lock-card h1 { margin: 0 0 0.75rem; font-size: 1.5rem; }
.lock-card p { color: var(--muted); }
.lock-tip { color: var(--accent-deep) !important; font-weight: 500; }
.lock-card .btn { margin-top: 1rem; text-decoration: none; }

@media (max-width: 900px) {
  .order-layout, .menu-form, .stats { grid-template-columns: 1fr; }
  .panel { min-height: auto; }
  .license-pill { margin-left: 0; }
}
