:root {
  --red: #d90000;
  --red-dark: #a60000;
  --red-soft: #fff5f5;
  --text: #171717;
  --muted: #666b73;
  --line: #e1e4e8;
  --bg: #ffffff;
  --orange: #f47a16;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #ececec; }
body {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.mobile-stage {
  width: 100%; height: 100dvh; min-height: 100svh;
  display: grid; place-items: stretch center;
}

.app-shell {
  position: relative;
  width: min(100vw, 520px);
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  box-shadow: 0 0 30px rgba(0,0,0,.11);
}

.topbar {
  min-height: 62px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: #fff;
  background: linear-gradient(120deg, #b60000 0%, #d60000 63%, #a30000 100%);
}
.topbar h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(20px, 5.3vw, 28px);
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 38px; height: 38px; padding: 7px;
  display: grid; place-items: center;
  color: inherit; background: transparent; border: 0; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.14); }
.icon-btn svg { width: 100%; height: 100%; }

.fixed-meta {
  padding: 10px 14px 7px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
}

.week-card {
  position: relative;
  min-height: 66px;
  padding: 10px 10px 10px 58px;
  border: 1px solid var(--line);
  border-radius: 9px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  background: #fff;
}
.calendar-badge {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; background: #c80000;
}
.calendar-badge svg { width: 24px; height: 24px; }
.week-select-wrap { min-width: 0; }
.week-select {
  width: 100%;
  appearance: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: #161616;
  font-weight: 700;
  font-size: clamp(15px, 4vw, 19px);
  line-height: 1.1;
  padding: 0 22px 3px 0;
  background-image: linear-gradient(45deg, transparent 50%, #777 50%), linear-gradient(135deg, #777 50%, transparent 50%);
  background-position: calc(100% - 11px) 50%, calc(100% - 6px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.week-range { color: var(--muted); font-size: clamp(12px, 3.3vw, 15px); white-space: nowrap; }
.deadline-pill {
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid #ffc46f;
  border-radius: 7px;
  background: #fff9ef;
  color: var(--orange);
  display: flex; align-items: center; gap: 6px;
  font-size: clamp(10px, 2.65vw, 13px);
  white-space: nowrap;
}
.deadline-pill svg { width: 18px; height: 18px; flex: 0 0 auto; }

.info-box {
  margin-top: 9px;
  padding: 9px 11px;
  display: grid; grid-template-columns: 26px 1fr; gap: 9px; align-items: start;
  border: 1px solid #ffb7b7;
  border-radius: 9px;
  background: linear-gradient(90deg, #fff9f9, #fff4f4);
  color: #c90000;
}
.info-box svg { width: 24px; height: 24px; }
.info-box p { margin: 0; font-size: clamp(11.5px, 3.15vw, 14px); line-height: 1.45; }

.day-tabs {
  margin-top: 9px;
  display: flex;
  align-items: stretch;
  gap: 8px;

  /*
   * Track ngày không giới hạn số lượng.
   * 5 tab đầu vừa đúng chiều rộng như mockup; từ tab thứ 6 trở đi vuốt ngang.
   */
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 1px 3px;

  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 1px;
  scrollbar-width: none;
}
.day-tabs::-webkit-scrollbar {
  display: none;
}
.day-tab {
  /*
   * Không cho tab co lại khi số ngày tăng.
   * Công thức này luôn chia đúng 5 tab trên chiều rộng hiện tại.
   */
  flex: 0 0 calc((100% - 32px) / 6);
  width: calc((100% - 32px) / 6);
  min-width: calc((100% - 32px) / 6);
  max-width: calc((100% - 32px) / 6);
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #5e6269;
  display: grid; place-items: center;
  padding: 4px 2px;
  cursor: pointer;
  scroll-snap-align: start;
}
.day-tab strong, .day-tab span { display: block; line-height: 1.1; }
.day-tab strong { font-size: clamp(14px, 3.8vw, 18px); font-weight: 600; }
.day-tab span { margin-top: 4px; font-size: clamp(12px, 3.4vw, 16px); }
.day-tab.active {
  color: #fff;
  border-color: var(--red);
  background: linear-gradient(145deg, #e60000, #bd0000);
  box-shadow: 0 2px 5px rgba(189,0,0,.18);
}
.day-counter { margin-top: 7px; color: #666a70; font-size: 13px; }

.meal-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #c9c9c9 transparent;
  background: #fff;
}
.meal-scroll::-webkit-scrollbar { width: 4px; }
.meal-scroll::-webkit-scrollbar-thumb { background: #c9c9c9; border-radius: 999px; }
.meal-scroll-inner { padding: 11px 14px 16px; }
.section-heading h2 { margin: 0; font-size: clamp(18px, 4.8vw, 23px); line-height: 1.2; }
.section-heading p { margin: 6px 0 12px; color: #696d73; font-size: clamp(12px, 3.2vw, 14px); }
.meal-options { display: grid; gap: 10px; }

.meal-card {
  position: relative;
  padding: 12px 11px 10px;
  border: 1.2px solid #dfe2e6;
  border-radius: 10px;
  background: #fff;
  display: grid;
  grid-template-columns: minmax(112px, .88fr) minmax(160px, 1.35fr);
  gap: 8px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.meal-card.selected {
  border-color: #ee1515;
  background: linear-gradient(105deg, #fff7f7 0%, #fff 48%);
  box-shadow: inset 0 0 0 .5px #ee1515;
}
.meal-card:active { transform: scale(.998); }
.meal-copy { min-width: 0; }
.option-chip {
  display: inline-flex; align-items: center;
  min-height: 26px; padding: 4px 8px;
  border-radius: 6px;
  background: #e8e8e8;
  color: #222;
  font-weight: 600;
  font-size: clamp(10.5px, 2.9vw, 13px);
}
.meal-card.selected .option-chip { background: #d60808; color: #fff; }
.meal-title {
  margin: 10px 0 13px;
  padding-right: 4px;
  font-size: clamp(18px, 4.5vw, 23px);
  line-height: 1.1;
  font-weight: 750;
}
.meal-details { display: grid; gap: 8px; font-size: clamp(10.5px, 2.9vw, 13.5px); }
.detail-row { display: grid; grid-template-columns: 68px minmax(0,1fr); gap: 5px; line-height: 1.25; }
.detail-row dt, .detail-row dd { margin: 0; }
.detail-row dt { color: #2f3135; }
.detail-row dd { color: #303338; }
.illustration { margin-top: 11px; color: #8b8e93; font-size: clamp(10px, 2.8vw, 13px); }

.meal-visual {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0 3px;
}
.meal-visual img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.12));
}
.radio-mark {
  position: absolute; right: 10px; top: 10px;
  width: 25px; height: 25px;
  border-radius: 50%;
  border: 2px solid #9aa0a7;
  background: #fff;
  display: grid; place-items: center;
}
.meal-card.selected .radio-mark { border-color: #df0909; }
.meal-card.selected .radio-mark::after {
  content: ""; width: 13px; height: 13px; border-radius: 50%; background: #df0909;
}

.fixed-bottom {
  position: relative;
  z-index: 3;
  padding: 8px 14px calc(5px + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid #f0f0f0;
  box-shadow: 0 -4px 12px rgba(0,0,0,.03);
}
.day-nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.day-nav-btn {
  height: 44px;
  border: 1px solid #dfe2e6;
  border-radius: 8px;
  background: #fff;
  color: #8d9298;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer;
  font-size: clamp(12px, 3.5vw, 16px);
}
.day-nav-btn svg { width: 18px; height: 18px; }
.day-nav-btn.primary-outline { border-color: #e10000; color: #d90000; }
.day-nav-btn:disabled { opacity: .42; cursor: default; border-color: #dfe2e6; color: #8d9298; }
.submit-btn {
  width: 100%; height: 47px; margin-top: 8px;
  border: 0; border-radius: 8px;
  background: linear-gradient(90deg, #df0000, #c70000);
  color: #fff;
  font-size: clamp(17px, 4.6vw, 21px);
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 2px 3px rgba(185,0,0,.16);
}
.submit-btn:active { filter: brightness(.94); }
.privacy-note {
  min-height: 25px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  color: #555b62;
  font-size: clamp(9.5px, 2.65vw, 12px);
  white-space: nowrap;
}
.privacy-note svg { width: 15px; height: 15px; color: #e30000; flex: 0 0 auto; }
.bottom-nav {
  height: 52px;
  border-top: 1px solid #e7e7e7;
  display: grid; grid-template-columns: repeat(4, 1fr);
  margin: 0 -14px -5px;
}
.bottom-item {
  border: 0; background: #fff; color: #696e75;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10px; cursor: pointer;
}
.bottom-item svg { width: 23px; height: 23px; }
.bottom-item.active { color: #df0000; }

.toast {
  position: absolute;
  left: 50%; bottom: calc(156px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  width: max-content; max-width: calc(100% - 36px);
  padding: 9px 13px;
  border-radius: 999px;
  color: #fff; background: rgba(20,20,20,.88);
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .fixed-meta, .meal-scroll-inner, .fixed-bottom { padding-left: 10px; padding-right: 10px; }
  .week-card { padding-left: 50px; }
  .calendar-badge { left: 9px; width: 34px; height: 34px; }
  .deadline-pill { padding-inline: 6px; }
  .day-tabs { gap: 5px; }
  .day-tab {
    flex-basis: calc((100% - 20px) / 5);
    width: calc((100% - 20px) / 5);
    min-width: calc((100% - 20px) / 5);
    max-width: calc((100% - 20px) / 5);
  }
  .meal-card { grid-template-columns: minmax(100px, .82fr) minmax(145px, 1.28fr); padding-inline: 9px; }
  .detail-row { grid-template-columns: 60px minmax(0,1fr); }
  .bottom-nav { margin-left: -10px; margin-right: -10px; }
}

@media (max-height: 720px) {
  .topbar { min-height: 52px; padding-top: max(5px, env(safe-area-inset-top)); }
  .fixed-meta { padding-top: 6px; padding-bottom: 5px; }
  .week-card { min-height: 56px; padding-top: 7px; padding-bottom: 7px; }
  .info-box { min-height: 48px; margin-top: 6px; padding-top: 6px; padding-bottom: 6px; }
  .day-tabs { margin-top: 6px; }
  .day-tab { min-height: 45px; }
  .day-counter { margin-top: 4px; }
  .fixed-bottom { padding-top: 6px; }
  .day-nav-btn { height: 38px; }
  .submit-btn { height: 41px; margin-top: 6px; }
  .privacy-note { min-height: 21px; }
  .bottom-nav { height: 46px; }
  .bottom-item svg { width: 20px; height: 20px; }
}


