:root {
  --bg: #f7f5fb;
  --card: rgba(255, 255, 255, 0.94);
  --ink: #1d2030;
  --muted: #74778a;
  --line: #e9e6ef;
  --primary: #7557e8;
  --primary-dark: #5638c6;
  --primary-soft: #eee9ff;
  --pink: #f57da0;
  --green: #20a477;
  --green-soft: #e8f8f2;
  --orange: #ee963a;
  --orange-soft: #fff2e3;
  --red: #d95757;
  --red-soft: #fff0f0;
  --shadow: 0 12px 36px rgba(44, 35, 85, 0.08);
  --radius: 24px;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 7% 0%, rgba(141, 114, 255, 0.12), transparent 31%),
    radial-gradient(circle at 100% 22%, rgba(255, 136, 170, 0.10), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 700px);
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(94px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) 20px 14px;
  background: rgba(247, 245, 251, 0.84);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
}

h1, h2, h3, p { margin-top: 0; }
.topbar h1 { margin: 0; font-size: 24px; line-height: 1.15; }

.avatar-button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 17px;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--pink));
  box-shadow: 0 8px 22px rgba(117, 87, 232, .25);
  font-weight: 900;
}

#app { padding: 8px 16px 30px; }

.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid rgba(232, 228, 240, .85);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.hero-card {
  position: relative;
  overflow: hidden;
  color: white;
  background: linear-gradient(135deg, #7155dc 0%, #8b6cf2 52%, #ef87aa 140%);
  border: 0;
}

.hero-card::after {
  content: "";
  position: absolute;
  width: 210px;
  height: 210px;
  right: -90px;
  top: -110px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
}

.hero-card .muted, .hero-card .subtle { color: rgba(255,255,255,.78); }
.hero-card h2 { margin-bottom: 8px; font-size: 27px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 3px 2px -2px;
}
.section-heading h2 { margin: 0; font-size: 18px; }

.muted { color: var(--muted); }
.subtle { color: #9294a3; font-size: 13px; }
.tiny { font-size: 11px; }
.strong { font-weight: 800; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 700;
}
.pill.green { color: #087355; background: var(--green-soft); }
.pill.orange { color: #a25c0b; background: var(--orange-soft); }
.pill.red { color: #a83f3f; background: var(--red-soft); }
.hero-card .pill { color: white; background: rgba(255,255,255,.16); }

.metric {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: rgba(255,255,255,.72);
}
.metric .value { display: block; margin: 4px 0; font-size: 22px; font-weight: 900; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .delta { color: var(--green); font-size: 11px; font-weight: 700; }

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece9f1;
}
.progress-track > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #a789ff);
}
.progress-track.green > span { background: linear-gradient(90deg, #20a477, #58caa4); }
.progress-track.orange > span { background: linear-gradient(90deg, #ef9c42, #ffbd6d); }

.calorie-ring {
  --percent: 0;
  width: 116px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--percent) * 1%), #ece8f5 0);
  position: relative;
  flex: 0 0 auto;
}
.calorie-ring::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: white;
}
.calorie-ring > div { position: relative; text-align: center; }
.calorie-ring strong { display: block; font-size: 22px; }
.calorie-ring small { color: var(--muted); }

.split { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.grow { flex: 1; min-width: 0; }

.primary-button, .secondary-button, .ghost-button, .danger-button {
  min-height: 46px;
  border: 0;
  border-radius: 15px;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button { color: white; background: linear-gradient(135deg, var(--primary), #926cf2); box-shadow: 0 8px 20px rgba(117,87,232,.20); }
.secondary-button { color: var(--primary-dark); background: var(--primary-soft); }
.ghost-button { color: var(--ink); background: #f2f0f6; }
.danger-button { color: var(--red); background: var(--red-soft); }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; }
.button-row > button { flex: 1; }
.small-button { min-height: 35px; padding: 7px 11px; border-radius: 11px; font-size: 12px; }

.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick-action {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  padding: 12px 6px;
  color: var(--ink);
}
.quick-action span { display: block; margin-bottom: 6px; font-size: 22px; }
.quick-action small { font-weight: 700; }

.exercise-card {
  padding: 15px 0;
  border-top: 1px solid var(--line);
}
.exercise-card:first-of-type { border-top: 0; padding-top: 3px; }
.exercise-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.exercise-head h3 { margin: 0 0 4px; font-size: 16px; }
.exercise-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-weight: 900;
  font-size: 12px;
}
.exercise-main { display: flex; gap: 10px; }
.exercise-meta { color: var(--primary-dark); font-weight: 800; font-size: 13px; }
.technique { margin: 10px 0 0 38px; color: var(--muted); font-size: 13px; line-height: 1.55; }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-chip {
  min-width: 0;
  border: 0;
  border-radius: 16px;
  padding: 9px 3px;
  color: var(--muted);
  background: #f0eef4;
  text-align: center;
}
.day-chip strong, .day-chip small { display: block; }
.day-chip strong { margin-top: 4px; color: var(--ink); font-size: 14px; }
.day-chip.active { color: white; background: var(--primary); }
.day-chip.active strong { color: white; }
.day-chip.done::after { content: "✓"; display: block; color: var(--green); font-size: 11px; font-weight: 900; }
.day-chip.active.done::after { color: white; }

.plan-day {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}
.plan-day:first-of-type { border-top: 0; }
.plan-date { color: var(--muted); font-size: 12px; text-align: center; }
.plan-date strong { display: block; color: var(--ink); font-size: 22px; }
.plan-day h3 { margin: 0 0 5px; font-size: 16px; }

.meal-item, .history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.meal-item:first-child, .history-item:first-child { border-top: 0; }
.meal-item h3, .history-item h3 { margin: 0 0 4px; font-size: 15px; }
.meal-kcal { font-weight: 900; white-space: nowrap; }

.macro-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.macro { padding: 12px; border-radius: 17px; background: #f5f2fb; text-align: center; }
.macro strong { display: block; margin-bottom: 3px; font-size: 17px; }
.macro small { color: var(--muted); }

.chart {
  height: 170px;
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 16px 6px 4px;
  border-bottom: 1px solid var(--line);
}
.chart-column { flex: 1; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 6px; height: 100%; }
.chart-bar { width: min(28px, 70%); min-height: 4px; border-radius: 9px 9px 3px 3px; background: linear-gradient(180deg, #9a7dff, var(--primary)); }
.chart-column small { color: var(--muted); font-size: 10px; }
.chart-column b { font-size: 10px; }

.chat-shell { display: grid; gap: 12px; }
.chat-list { display: grid; gap: 10px; min-height: 360px; align-content: start; }
.bubble {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-wrap;
}
.bubble.agent { justify-self: start; background: white; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.user { justify-self: end; color: white; background: var(--primary); border-bottom-right-radius: 5px; }
.suggestions { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestion { flex: 0 0 auto; border: 1px solid #ddd7f2; border-radius: 999px; padding: 8px 11px; background: white; color: var(--primary-dark); font-size: 12px; }
.chat-composer {
  position: sticky;
  bottom: calc(84px + env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,255,255,.95);
  box-shadow: var(--shadow);
}
.chat-composer textarea { flex: 1; min-height: 44px; max-height: 120px; resize: none; border: 0; outline: 0; padding: 10px; background: transparent; }
.chat-composer button { width: 46px; height: 46px; border: 0; border-radius: 15px; color: white; background: var(--primary); font-weight: 900; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100%, 700px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(226,222,234,.85);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
.nav-item { border: 0; background: none; color: #858594; padding: 3px; }
.nav-item span, .nav-item small { display: block; }
.nav-item span { margin-bottom: 3px; font-size: 22px; }
.nav-item small { font-size: 10px; font-weight: 700; }
.nav-item.active { color: var(--primary); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: 40px;
  background: rgba(23, 19, 40, .38);
}
.modal-backdrop.hidden { display: none; }
.modal-sheet {
  width: min(100%, 700px);
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 20px 18px calc(26px + env(safe-area-inset-bottom));
  border-radius: 30px 30px 0 0;
  background: #fbfaff;
  box-shadow: 0 -20px 60px rgba(22,15,52,.18);
}
.modal-handle { width: 48px; height: 5px; margin: -7px auto 19px; border-radius: 99px; background: #d9d5df; }
.modal-title { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.modal-title h2 { margin-bottom: 5px; }
.close-button { width: 36px; height: 36px; border: 0; border-radius: 12px; background: #ece9f2; }

.form-grid { display: grid; gap: 13px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
label.field { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid #dfdbe7;
  border-radius: 14px;
  outline: 0;
  padding: 11px 12px;
  color: var(--ink);
  background: white;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(117,87,232,.10); }

.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.choice {
  min-height: 46px;
  border: 1px solid #e1ddea;
  border-radius: 14px;
  background: white;
  color: var(--ink);
  padding: 9px;
  font-weight: 700;
}
.choice.selected { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }

.step-indicator { display: flex; gap: 6px; margin: 12px 0 18px; }
.step-indicator span { height: 5px; flex: 1; border-radius: 99px; background: #e6e2eb; }
.step-indicator span.active { background: var(--primary); }

.notice { padding: 12px 13px; border-radius: 15px; background: var(--orange-soft); color: #81501a; font-size: 13px; line-height: 1.5; }
.notice.green { color: #126d54; background: var(--green-soft); }
.notice.red { color: #943e3e; background: var(--red-soft); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(106px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: calc(100% - 34px);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 15px;
  border-radius: 13px;
  color: white;
  background: rgba(31,27,43,.92);
  font-size: 13px;
  transition: .24s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app-shell { min-height: calc(100vh - 36px); border-radius: 30px; overflow: hidden; box-shadow: 0 18px 80px rgba(36,26,72,.10); }
  .bottom-nav { bottom: 18px; border-radius: 0 0 30px 30px; }
}

@media (max-width: 390px) {
  .grid-3 { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); }
  .split.responsive { align-items: flex-start; flex-direction: column; }
  .calorie-ring { width: 104px; }
}
