:root {
  --ink: #17322c;
  --muted: #66746e;
  --paper: #f4f1e9;
  --card: #fffdf7;
  --green: #285943;
  --green-soft: #dce9df;
  --gold: #d99b3d;
  --gold-soft: #f6e8ca;
  --red: #a74335;
  --line: #dce2dd;
  --shadow: 0 12px 34px rgba(31, 55, 46, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top right, #e3ecdf 0, transparent 34rem), var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 24px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px, 4vw, 44px); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -0.03em; }
h3 { margin-bottom: 14px; }
.eyebrow { margin-bottom: 5px; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; }
.muted, .inline-hint { color: var(--muted); line-height: 1.65; }
.inline-hint { margin: 0; font-size: 13px; }

.sync-status { padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--gold-soft); color: #78531c; }
.sync-status[data-state="online"] { background: var(--green-soft); color: var(--green); }
.sync-status[data-state="offline"] { background: #f3dcd7; color: var(--red); }

.tabbar {
  position: sticky;
  top: 0;
  z-index: 20;
  max-width: 720px;
  margin: 0 auto 24px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: rgba(255, 253, 247, 0.91);
  border: 1px solid rgba(220, 226, 221, 0.9);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(31, 55, 46, 0.06);
}

.tab { border: 0; border-radius: 11px; padding: 11px 8px; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { color: white; background: var(--green); }

main { max-width: 1180px; margin: 0 auto; padding: 0 24px 72px; }
.page { display: none; }
.page.active { display: block; animation: reveal 180ms ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { padding: 18px; min-height: 112px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); border: 1px solid rgba(220, 226, 221, 0.7); }
.stat-card strong { display: block; margin: 8px 0 5px; font-size: clamp(24px, 3vw, 34px); font-variant-numeric: tabular-nums; }
.stat-card span { color: var(--muted); font-size: 13px; }

.card { padding: 24px; background: var(--card); border: 1px solid rgba(220, 226, 221, 0.75); border-radius: 22px; box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.section-heading.compact { margin-bottom: 12px; }
.section-heading h3 { margin: 0; }
.page-heading { margin: 10px 0 20px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.compact-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: 1fr 1fr; }
.nutrition-grid { margin: 18px 0; }
.span-2 { grid-column: span 2; }
.meal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; margin-top: 18px; }
label { display: grid; gap: 8px; color: #334941; font-size: 14px; font-weight: 700; }
input, textarea, select {
  width: 100%;
  border: 1px solid #ccd7d1;
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(40, 89, 67, 0.12); }

.button { border: 1px solid transparent; border-radius: 12px; padding: 11px 16px; font-weight: 800; transition: transform 120ms, box-shadow 120ms, background 120ms; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--green); box-shadow: 0 8px 18px rgba(40, 89, 67, 0.18); }
.button.secondary { color: var(--green); background: var(--green-soft); }
.button.ghost { color: var(--green); background: transparent; border-color: #bfd0c6; }
.button.danger { color: var(--red); border-color: #dcb9b1; }
.button.small { padding: 8px 12px; font-size: 13px; }
.button.full { width: 100%; }
.text-button, .icon-button { border: 0; background: transparent; color: var(--green); font-weight: 800; }
.icon-button { font-size: 25px; line-height: 1; }
.action-row, .form-actions, .dialog-actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; }
.dialog-actions { justify-content: flex-end; }
.notice { margin-top: 16px; padding: 12px 14px; border-left: 4px solid var(--gold); border-radius: 8px; background: var(--gold-soft); line-height: 1.6; }
.hidden { display: none !important; }

.entry-panel { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.data-table th { padding: 11px 10px; text-align: left; color: #fff; background: var(--green); font-size: 13px; white-space: nowrap; }
.data-table th:first-child { border-radius: 10px 0 0 10px; }
.data-table th:last-child { border-radius: 0 10px 10px 0; }
.data-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .empty-cell { padding: 32px 10px; text-align: center; color: var(--muted); }
.entry-name { font-weight: 800; }
.entry-source { margin-top: 4px; color: var(--muted); font-size: 11px; max-width: 280px; }
.confidence { display: inline-block; margin-top: 5px; padding: 2px 7px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 800; }
.confidence.estimate, .confidence.photo { background: var(--gold-soft); color: #7f5519; }
.row-delete { border: 0; background: transparent; color: var(--red); font-weight: 700; }

.totals-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 20px; }
.total { padding: 14px; border-radius: 14px; background: #f0f5f1; }
.total span { display: block; color: var(--muted); font-size: 12px; }
.total strong { display: block; margin-top: 5px; font-size: 20px; font-variant-numeric: tabular-nums; }

.chart-card { margin-bottom: 18px; }
.chart-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chart-header h3 { margin-bottom: 0; }
.chart-header span { color: var(--muted); font-size: 13px; }
.chart-wrap { min-height: 260px; margin-top: 16px; }
.chart-empty { display: grid; place-items: center; min-height: 250px; color: var(--muted); border: 1px dashed #c7d2cc; border-radius: 14px; }
.weight-chart { width: 100%; height: 280px; overflow: visible; }
.chart-axis { stroke: #bbc9c2; stroke-width: 1; }
.chart-line { fill: none; stroke: var(--green); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#weightFill); }
.chart-dot { fill: var(--card); stroke: var(--green); stroke-width: 3; }
.chart-label { fill: var(--muted); font-size: 11px; }

.food-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr); gap: 18px; align-items: start; }
.upload-zone { position: relative; margin: 18px 0 12px; padding: 28px 18px; place-items: center; text-align: center; border: 2px dashed #b9cbc1; border-radius: 16px; background: #f5f8f5; color: var(--muted); cursor: pointer; }
.upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-title { display: block; margin-bottom: 5px; color: var(--green); font-weight: 800; }
.image-preview { width: 100%; max-height: 320px; object-fit: contain; margin: 4px 0 12px; border-radius: 14px; background: #eef1ed; }
.progress { height: 8px; margin-top: 14px; overflow: hidden; border-radius: 999px; background: #e2e8e4; }
.progress div { width: 0; height: 100%; background: var(--green); transition: width 180ms; }
.ocr-text-wrap { margin-top: 12px; }
.ocr-text-wrap textarea { margin-top: 8px; font-family: Consolas, monospace; font-size: 12px; }
.food-list { display: grid; gap: 10px; }
.food-item { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.food-item-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.food-item h4 { margin: 0 0 6px; }
.food-macros { color: var(--muted); font-size: 12px; line-height: 1.65; }
.pill { padding: 5px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 12px; font-weight: 800; }
.settings-form { margin-bottom: 18px; }
.button-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.file-button { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

dialog { width: min(520px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 20px; box-shadow: 0 28px 70px rgba(13, 34, 27, 0.28); }
dialog::backdrop { background: rgba(20, 38, 32, 0.5); backdrop-filter: blur(3px); }
.dialog-card { padding: 24px; display: grid; gap: 15px; background: var(--card); }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 28px; max-width: min(92vw, 520px); transform: translate(-50%, 20px); padding: 12px 16px; border-radius: 12px; background: #17322c; color: #fff; opacity: 0; pointer-events: none; transition: 180ms; box-shadow: 0 12px 32px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .hero-grid { grid-template-columns: repeat(2, 1fr); }
  .compact-grid { grid-template-columns: repeat(2, 1fr); }
  .meal-grid, .food-layout { grid-template-columns: 1fr; }
  .totals-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  .app-header { padding: 24px 16px 14px; }
  .tabbar { margin: 0 12px 18px; border-radius: 14px; }
  .tab { padding: 10px 4px; font-size: 13px; }
  main { padding: 0 12px 56px; }
  .card { padding: 18px; border-radius: 18px; }
  .hero-grid { gap: 9px; }
  .stat-card { padding: 14px; min-height: 96px; }
  .compact-grid, .form-grid { grid-template-columns: 1fr 1fr; }
  .nutrition-grid .span-2 { grid-column: span 2; }
  .totals-grid { grid-template-columns: repeat(2, 1fr); }
  .action-row, .form-actions { align-items: stretch; flex-direction: column; }
  .action-row .button, .form-actions .button { width: 100%; }
  .inline-hint { text-align: center; }
  .button-grid { display: grid; grid-template-columns: 1fr; }
}
