:root {
  --primary: #f97316;
  --primary-dark: #ea580c;
  --primary-soft: #fff3e6;
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2d2a26;
  --text-soft: #8a837b;
  --border: #eee5d9;
  --green: #16a34a;
  --green-soft: #e8f7ee;
  --red: #dc2626;
  --red-soft: #fdecec;
  --blue: #2563eb;
  --blue-soft: #e8f0fe;
  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(45, 42, 38, 0.08), 0 4px 16px rgba(45, 42, 38, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-x: clip;
  max-width: 100%;
  touch-action: pan-y;
  overscroll-behavior-x: none;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; padding-top: 100px; padding-bottom: 76px; width: 100%; }

input, select, textarea { max-width: 100%; }
img, video, svg, canvas, iframe { max-width: 100%; height: auto; }

button {
  font: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 48px;
  padding: 0 12px;
  background: linear-gradient(135deg, var(--primary), #fbbf24);
  color: #fff;
  box-shadow: 0 2px 10px rgba(234, 88, 12, 0.25);
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.lang-select {
  font: inherit;
  font-size: 11px;
  padding: 4px 4px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  outline: none;
  max-width: 82px;
}
.lang-select option { color: #2d2a26; }

.logout-btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.32); }

.sync {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.2);
  padding: 5px 10px;
  border-radius: 999px;
}

.sync .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fbbf24;
}
.sync.online .dot { background: #86efac; }
.sync.offline .dot { background: #fecaca; }

/* ---------- 标签栏 ---------- */
.tabs {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 48px;
  padding: 6px 8px;
  background: var(--bg);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.35);
}

/* ---------- 主体 ---------- */
#main { max-width: 1100px; margin: 0 auto; padding: 14px; width: 100%; min-width: 0; overflow-x: clip; }
.tab { display: none; }
.tab.active { display: block; }
.tab, .row, .filter-row, .cat-chips, .dish-grid, .order-layout, .week, .date-group { min-width: 0; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 12px;
  flex-wrap: wrap;
}
.section-title { font-size: 17px; font-weight: 700; margin: 0; }
.section-sub { font-size: 13px; color: var(--text-soft); margin: 2px 0 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--primary-soft); color: var(--primary-dark); }
.btn-soft { background: #f1ece4; color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-green { background: var(--green); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 5px;
}
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12); }
.textarea { min-height: 64px; resize: vertical; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.chip-baby { background: #fce7f3; color: #be185d; }
.chip-done { background: var(--green-soft); color: var(--green); }
.chip-open { background: var(--blue-soft); color: var(--blue); }
.chip-struck { background: #f1ece4; color: var(--text-soft); }
.chip-missing { background: var(--red-soft); color: var(--red); }
.chip-low { background: var(--amber-soft); color: var(--amber); }
.chip-ok { background: var(--green-soft); color: var(--green); }
.chip-meal { color: #fff; }

.meal-breakfast { background: #f59e0b; }
.meal-lunch { background: #10b981; }
.meal-dinner { background: #6366f1; }
.meal-tea { background: #ec4899; }

.empty {
  text-align: center;
  color: var(--text-soft);
  padding: 40px 16px;
  font-size: 14px;
}
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- 点菜 ---------- */
.order-layout {
  display: grid;
  gap: 14px;
}

.meal-types {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.meal-type-btn {
  padding: 10px 4px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  text-align: center;
}
.meal-type-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.meal-type-btn .icon { display: block; font-size: 20px; margin-bottom: 2px; }

.order-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.order-row .input { flex: 1 1 160px; }

.date-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.date-field label { font-size: 13px; font-weight: 600; color: var(--text-soft); white-space: normal; }
.date-field .input { width: 165px; }

.baby-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  background: #fff;
  border: 2px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.baby-toggle.active { border-color: #ec4899; background: #fdf2f8; color: #be185d; }

.dish-filters {
  display: flex;
  gap: 10px;
  margin: 4px 0 14px;
  flex-wrap: wrap;
}
.dish-filters .input { flex: 1 1 200px; }

.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 10px;
}
.cat-head h3 { margin: 0; font-size: 16px; }
.cat-count { font-size: 12px; color: var(--text-soft); background: #f1ece4; border-radius: 999px; padding: 2px 8px; }

.dish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.dish-grid > * { min-width: 0; }

.dish-card {
  position: relative;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.dish-card:active { transform: scale(0.98); }

.dish-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}

.dish-info { padding: 9px 10px 11px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.dish-name { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.dish-ing { font-size: 11px; color: var(--text-soft); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dish-rating { font-size: 11px; color: #d97706; }

.dish-add {
  margin: 2px 10px 10px;
  padding: 7px 0;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}
.dish-add:hover { background: #ffe4c9; }

.qty-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 2px 10px 10px;
  padding: 4px 8px;
  border-radius: 9px;
  background: var(--primary-soft);
}
.qty-inline button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: 700;
}
.qty-inline .n { font-weight: 700; min-width: 20px; text-align: center; color: var(--primary-dark); }

.cart-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.cart-empty {
  padding: 7px 14px calc(7px + env(safe-area-inset-bottom));
}
.cart-empty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
}
.cart-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.cart-row:last-of-type { border-bottom: none; }
.cart-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-qty { display: flex; align-items: center; gap: 6px; }
.cart-qty button {
  width: 24px; height: 24px; border-radius: 7px;
  background: #f1ece4; font-weight: 700; font-size: 14px;
}
.cart-qty .n { min-width: 18px; text-align: center; font-weight: 700; }
.cart-remove { color: var(--text-soft); font-size: 16px; padding: 2px 4px; }
.cart-remove:hover { color: var(--red); }
.cart-submit {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
}
.cart-submit .btn { flex: 1; }
.cart-meta { font-size: 12px; color: var(--text-soft); }

@media (min-width: 900px) {
  .order-layout {
    grid-template-columns: 1fr 330px;
    align-items: start;
  }
  .cart-bar {
    position: static;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
  }
  body { padding-bottom: 20px; }
}

/* ---------- 订单列表 ---------- */
.order-card { margin-bottom: 12px; }
.order-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.order-top .who { font-weight: 700; font-size: 15px; }
.order-time { margin-left: auto; font-size: 12px; color: var(--text-soft); }

.order-items { list-style: none; margin: 0 0 10px; padding: 0; }
.order-items li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
}
.order-items li.struck .oi-name {
  text-decoration: line-through;
  color: var(--text-soft);
}
.oi-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clickable { cursor: pointer; }
.clickable:hover { color: var(--primary-dark); text-decoration: underline; }
.oi-qty { color: var(--text-soft); font-size: 13px; white-space: nowrap; }
.order-note {
  font-size: 13px;
  color: var(--text-soft);
  background: #faf6ef;
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 10px;
}
.order-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 本周计划 ---------- */
.week-day { margin-bottom: 12px; }
.week-day.has-orders { border-color: #fcd9b8; }
.week-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}
.week-date { font-size: 15px; font-weight: 700; }
.week-date .today-mark { color: var(--primary-dark); }
.week-date small { color: var(--text-soft); font-weight: 500; margin-left: 6px; }
.week-count { font-size: 12px; color: var(--text-soft); }
.meal-slots { display: grid; gap: 8px; }
.meal-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #faf7f2;
  flex-wrap: wrap;
}
.meal-slot .chip { flex: 0 0 auto; }
.slot-dishes { flex: 1; min-width: 0; font-size: 13px; line-height: 1.5; }
.slot-dishes .struck { text-decoration: line-through; color: var(--text-soft); }
.slot-empty { color: var(--text-soft); }
.slot-dish { cursor: pointer; color: var(--text); }
.slot-dish:hover { color: var(--primary-dark); text-decoration: underline; }

/* ---------- 订单按日期分组 ---------- */
.date-group { margin-bottom: 18px; }
.date-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  margin: 4px 0 8px;
}
.date-head .count { font-weight: 400; color: var(--text-soft); font-size: 12px; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

/* ---------- 菜单管理 ---------- */
.cat-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}
.cat-chip .count { color: var(--text-soft); font-weight: 400; }

.menu-dish-actions { display: flex; gap: 6px; margin-top: 6px; }

/* ---------- 厨房 ---------- */
.pantry-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px dashed var(--border);
  flex-wrap: wrap;
}
.pantry-item:last-child { border-bottom: none; }
.pantry-name { flex: 0 0 92px; font-weight: 600; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-seg { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
.stock-seg .seg {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 2px;
  border-radius: 8px;
  background: #f1ece4;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  text-align: center;
  transition: all 0.12s;
}
.stock-seg .seg.on { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(249, 115, 22, 0.3); }
.pantry-unit { color: var(--text-soft); font-size: 13px; min-width: 28px; }

/* ---------- 购物建议 ---------- */
.sugg-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  border-bottom: 1px dashed var(--border);
  flex-wrap: wrap;
}
.sugg-item:last-child { border-bottom: none; }
.sugg-name { flex: 1 1 110px; font-weight: 700; font-size: 14px; }
.sugg-nums { font-size: 13px; color: var(--text-soft); }
.sugg-nums b { color: var(--text); }

/* ---------- 点评 ---------- */
.review-card { margin-bottom: 12px; }
.review-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.stars { color: #f59e0b; letter-spacing: 1px; font-size: 14px; }
.stars .off { color: #e4ddd3; }
.review-comment { font-size: 14px; line-height: 1.6; margin: 0 0 6px; white-space: pre-wrap; }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(45, 42, 38, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 24px; }
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px;
  animation: slideUp 0.18s ease-out;
}
@media (min-width: 640px) {
  .modal { border-radius: 18px; animation: fadeUp 0.18s ease-out; }
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@keyframes fadeUp { from { transform: translateY(8px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close { font-size: 22px; color: var(--text-soft); padding: 2px 8px; border-radius: 8px; }
.modal-close:hover { background: #f1ece4; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

.ing-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.ing-row .input:first-child { flex: 1.4; }
.ing-row .input:nth-child(2) { flex: 1; }
.ing-del { color: var(--red); font-size: 17px; padding: 6px; }

.img-preview {
  width: 100%;
  max-height: 150px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-top: 8px;
  background: #faf6ef;
}

.edit-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.edit-item.struck .ei-name { text-decoration: line-through; color: var(--text-soft); }
.ei-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ei-qty { display: flex; align-items: center; gap: 5px; }
.ei-qty button { width: 24px; height: 24px; border-radius: 7px; background: #f1ece4; font-weight: 700; }
.ei-qty .n { min-width: 16px; text-align: center; font-weight: 700; }
.ei-action { font-size: 12px; color: var(--blue); padding: 4px 6px; }
.ei-action.restore { color: var(--green); }

.star-pick { display: flex; gap: 6px; font-size: 30px; cursor: pointer; }
.star-pick span { color: #e4ddd3; transition: transform 0.1s; }
.star-pick span.on { color: #f59e0b; }
.star-pick span:active { transform: scale(1.2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  z-index: 80;
  background: rgba(45, 42, 38, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: 90vw;
  text-align: center;
  animation: fadeUp 0.2s ease-out;
}
.toast.error { background: rgba(220, 38, 38, 0.95); }
.toast.success { background: rgba(22, 163, 74, 0.95); }

/* ---------- 登录 ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(150deg, #fff7ed, #ffedd5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 22px;
  text-align: center;
}
.login-logo { font-size: 52px; margin-bottom: 8px; }
.login-title { font-size: 19px; font-weight: 700; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--text-soft); margin: 0 0 18px; }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.login-card .input { text-align: center; letter-spacing: 2px; }
.login-card .btn { width: 100%; margin-top: 10px; }
.login-lang { margin-bottom: 14px; }

/* ---------- 工具 ---------- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.mt { margin-top: 10px; }
.mb { margin-bottom: 10px; }
.muted { color: var(--text-soft); font-size: 13px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-dark); }
