:root {
  --ink: #163333;
  --muted: #708382;
  --paper: #f7fbfa;
  --card: #ffffff;
  --brand: #176b67;
  --brand-dark: #0f514f;
  --brand-soft: #dff3ef;
  --sun: #ffd36a;
  --sun-soft: #fff5d9;
  --line: #dfeae7;
  --danger: #b84b43;
  --danger-soft: #fff0ee;
  --shadow: 0 18px 50px rgba(22, 51, 51, 0.12);
}

* { box-sizing: border-box; }

html { background: #dbe9e6; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 5%, rgba(255, 211, 106, .28), transparent 24rem),
    linear-gradient(135deg, #eaf4f1, #d7e8e5);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
}

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

#app {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.screen {
  min-height: 100vh;
  padding: max(22px, env(safe-area-inset-top)) 20px calc(96px + env(safe-area-inset-bottom));
}

.topbar, .section-head, .row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: .875rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.75rem; line-height: 1.25; }
h2 { margin-bottom: 12px; font-size: 1.25rem; }
h3 { margin-bottom: 8px; font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: white;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(23, 107, 103, .22);
}

.summary-card {
  margin: 22px 0 18px;
  padding: 20px;
  border-radius: 26px;
  color: white;
  background: linear-gradient(145deg, var(--brand), #248a82);
  box-shadow: 0 14px 28px rgba(23, 107, 103, .22);
  position: relative;
  overflow: hidden;
}

.summary-card::after {
  content: "";
  position: absolute;
  width: 130px;
  height: 130px;
  right: -38px;
  top: -52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
}

.summary-label { font-size: .88rem; opacity: .8; }
.summary-title { margin: 8px 0 5px; font-size: 1.35rem; font-weight: 800; }
.summary-copy { margin: 0; opacity: .84; line-height: 1.55; font-size: .9rem; max-width: 88%; }
.summary-stats { display: flex; gap: 20px; margin-top: 18px; }
.summary-stats strong { display: block; font-size: 1.25rem; }
.summary-stats span { font-size: .78rem; opacity: .78; }
.summary-link {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 15px;
  background: rgba(255,255,255,.12);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.primary-action {
  width: 100%;
  border: 0;
  border-radius: 22px;
  padding: 18px 20px;
  background: var(--sun);
  color: #473714;
  font-size: 1.08rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 10px 22px rgba(198, 153, 42, .2);
  cursor: pointer;
}

.action-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255,255,255,.58);
}

.quick-title { margin: 24px 0 12px; font-size: .95rem; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick-button {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 5px 11px;
  background: var(--card);
  cursor: pointer;
}
.quick-button .icon { display: block; font-size: 1.35rem; margin-bottom: 6px; }
.quick-button span:last-child { font-size: .78rem; }
.demo-link { width: 100%; margin-top: 11px; padding: 11px 13px; border: 1px dashed #b8ceca; border-radius: 15px; background: rgba(255,255,255,.55); color: var(--brand); display: flex; justify-content: space-between; font-size: .82rem; cursor: pointer; }

.section-head { margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 1.05rem; }
.text-button { border: 0; background: none; color: var(--brand); padding: 6px; cursor: pointer; }

.timeline { display: grid; gap: 10px; }
.timeline-item {
  display: grid;
  grid-template-columns: 46px 38px 1fr;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
}
.timeline-time { color: var(--muted); font-size: .78rem; }
.timeline-icon { width: 36px; height: 36px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; }
.timeline-title { font-weight: 700; font-size: .9rem; }
.timeline-note { color: var(--muted); font-size: .78rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty {
  padding: 26px 18px;
  border: 1px dashed #bfd1cd;
  border-radius: 20px;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,.55);
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  bottom: 0;
  width: min(100%, 460px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.nav-button { border: 0; background: none; color: #80908f; padding: 5px; font-size: .75rem; cursor: pointer; }
.nav-button .nav-icon { display: block; font-size: 1.15rem; margin-bottom: 2px; }
.nav-button.active { color: var(--brand); font-weight: 800; }

.sheet-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  background: rgba(10, 29, 28, .42);
}
.sheet {
  width: min(100%, 460px);
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 30px 30px 0 0;
  background: var(--paper);
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -18px 60px rgba(10, 29, 28, .2);
}
.handle { width: 44px; height: 5px; border-radius: 99px; background: #c9d7d4; margin: 2px auto 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.sheet-head h2 { margin-bottom: 4px; }
.close-button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: #e8f0ee; font-size: 1.15rem; cursor: pointer; }

.field { margin: 20px 0; }
.field-label { display: block; font-weight: 800; margin-bottom: 10px; }
.field-hint { display: block; margin-top: -5px; margin-bottom: 10px; color: var(--muted); font-size: .78rem; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  border: 1px solid #cfddda;
  background: white;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: .88rem;
  cursor: pointer;
}
.chip.selected { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); font-weight: 800; }
.chip.warning.selected { border-color: #d16960; background: var(--danger-soft); color: var(--danger); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.meal-grid { grid-template-columns: repeat(4, 1fr); }
.segment { border: 1px solid var(--line); border-radius: 16px; background: white; padding: 13px 5px; cursor: pointer; }
.segment.selected { background: var(--brand); color: white; border-color: var(--brand); font-weight: 800; }

.text-input, .textarea {
  width: 100%;
  border: 1px solid #cbdad7;
  border-radius: 16px;
  background: white;
  padding: 13px 14px;
  color: var(--ink);
  outline: none;
}
.textarea { min-height: 86px; resize: vertical; }
.text-input:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(23,107,103,.1); }

.sheet-footer { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 24px; }
.button-secondary, .button-primary {
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 800;
  cursor: pointer;
}
.button-secondary { border: 1px solid var(--line); background: white; }
.button-primary { border: 0; background: var(--brand); color: white; }
.button-primary:disabled { opacity: .45; cursor: not-allowed; }
.full-button { width: 100%; margin-top: 14px; }

.food-step { display: flex; align-items: center; gap: 9px; margin: 16px 0 10px; }
.food-step > span { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 9px; background: var(--brand); color: white; font-size: .78rem; font-weight: 800; }
.food-step strong { font-size: .95rem; }

.onboarding {
  min-height: 100vh;
  padding: max(28px, env(safe-area-inset-top)) 22px calc(26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.brand-mark { width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; background: var(--brand); color: white; font-size: 1.5rem; box-shadow: 0 12px 24px rgba(23,107,103,.2); }
.progress { display: flex; gap: 6px; margin: 30px 0 26px; }
.progress span { height: 5px; flex: 1; border-radius: 99px; background: #dce7e5; }
.progress span.done { background: var(--brand); }
.onboarding h1 { margin: 0 0 10px; font-size: 1.75rem; }
.onboarding-copy { color: var(--muted); line-height: 1.65; }
.onboarding-content { flex: 1; }
.onboarding .sheet-footer { position: sticky; bottom: 0; background: var(--paper); padding-top: 12px; }

.advice-card, .profile-card, .trend-card {
  border: 1px solid var(--line);
  background: white;
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 12px;
}
.advice-card.highlight { background: var(--sun-soft); border-color: #f0db9e; }
.advice-number { width: 28px; height: 28px; border-radius: 10px; background: var(--brand); color: white; display: grid; place-items: center; font-size: .82rem; font-weight: 800; flex: 0 0 auto; }
.advice-row { display: flex; gap: 12px; align-items: flex-start; }
.advice-row p { margin-bottom: 0; line-height: 1.55; font-size: .9rem; }
.advice-note { margin: 2px 6px 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.evidence-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.evidence-list span { padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.72); color: #5a4b25; font-size: .78rem; }
.evidence-box { padding: 15px; border-radius: 18px; background: var(--sun-soft); margin-bottom: 14px; }
.mini-advice { display: flex; gap: 12px; align-items: flex-start; padding: 16px 0; }
.mini-advice p { margin: 0; line-height: 1.6; font-size: .92rem; }
.row-start { display: flex; align-items: center; gap: 9px; }
.row-start h2 { margin: 0; }
.ai-pending { padding: 4px 8px; border-radius: 999px; background: var(--sun-soft); color: #7b5b0c; font-size: .72rem; font-weight: 800; }

.week-chart { height: 150px; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; padding-top: 20px; }
.bar-wrap { flex: 1; text-align: center; color: var(--muted); font-size: .72rem; }
.bar { min-height: 8px; border-radius: 8px 8px 4px 4px; background: var(--brand-soft); margin-bottom: 7px; position: relative; }
.bar.today { background: var(--brand); }
.bar-count { position: absolute; left: 0; right: 0; top: -19px; font-size: .7rem; color: var(--ink); }

.tag-list { display: flex; flex-wrap: wrap; gap: 7px; }
.tag { padding: 7px 10px; border-radius: 999px; background: #edf4f2; color: #496360; font-size: .78rem; }
.profile-row { padding: 15px 0; border-bottom: 1px solid var(--line); }
.profile-row:last-child { border-bottom: 0; }

.chat-fab {
  position: fixed;
  z-index: 21;
  right: max(calc((100vw - 460px)/2 + 18px), 18px);
  bottom: calc(82px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 18px;
  background: var(--brand);
  color: white;
  box-shadow: 0 10px 24px rgba(23,107,103,.3);
  font-size: 1.3rem;
  cursor: pointer;
}
.chat-log { display: grid; gap: 10px; min-height: 230px; max-height: 46vh; overflow-y: auto; padding: 4px 0 12px; }
.bubble { max-width: 86%; padding: 12px 14px; border-radius: 18px; line-height: 1.55; font-size: .88rem; }
.bubble.ai { background: white; border: 1px solid var(--line); border-top-left-radius: 6px; }
.bubble.user { margin-left: auto; background: var(--brand); color: white; border-bottom-right-radius: 6px; }
.chat-input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; position: sticky; bottom: 0; background: var(--paper); padding-top: 10px; }
.send-button { border: 0; border-radius: 14px; background: var(--brand); color: white; padding: 0 16px; font-weight: 800; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 100px;
  transform: translate(-50%, 20px);
  padding: 11px 16px;
  border-radius: 999px;
  background: #193837;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: .25s ease;
  font-size: .85rem;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  body { padding: 24px 0; }
  #app { min-height: calc(100vh - 48px); border-radius: 34px; }
  .screen, .onboarding { min-height: calc(100vh - 48px); }
  .bottom-nav { bottom: 24px; border-radius: 0 0 34px 34px; }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 30px; max-height: 88vh; }
}

@media (max-width: 360px) {
  .quick-grid { grid-template-columns: repeat(2, 1fr); }
  .segmented { grid-template-columns: 1fr; }
}
