:root {
  --bg: #faf3e8;
  --card: #ffffff;
  --ink: #4a3f35;
  --sub: #7d7263;
  --faint: #a89a86;
  --muted: #b8ab97;
  --line: #f2ead9;
  --accent: #d97757;
  --accent-soft: #fdeadd;
  --marker: #e8926e;
  --green: #7fb069;
  --green-dark: #4c7a3a;
  --amber: #f0b84c;
  --amber-dark: #9a7716;
  --red: #e0685c;
  --red-dark: #a8443a;
  --pink: #f2a0aa;
  --num-font: ui-rounded, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  font-family: -apple-system, 'PingFang SC', 'Hiragino Sans GB', sans-serif;
  color: var(--ink);
  overscroll-behavior-y: none;
}
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
.hidden { display: none !important; }
.num { font-family: var(--num-font); }

/* ---------- 布局 ---------- */
#pages { height: 100dvh; overflow: hidden; }
.page { position: relative; height: 100%; overflow: hidden; }
.content {
  position: relative; z-index: 2; height: 100%;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 10px) 0 0 0;
}
.page-end { height: calc(96px + env(safe-area-inset-bottom)); }

/* 背景贴纸与装饰 */
.decor { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.stk { position: absolute; }
.di { position: absolute; transform: translate(-50%, -50%); }
.sparkle { fill: var(--amber); opacity: 0.55; }
.heartd { fill: var(--pink); opacity: 0.6; }
.fishd { fill: var(--marker); opacity: 0.32; }
.pawfill { fill: var(--marker); opacity: 0.3; }
.pawstroke { fill: none; stroke: var(--marker); stroke-width: 1.6; }
.legend .pawfill, .legend .pawstroke { opacity: 1; }

/* 日历页贴纸 */
.stk-tree { left: 52px; bottom: calc(74px + env(safe-area-inset-bottom)); height: 130px; }
.stk-curl { right: 20px; bottom: calc(68px + env(safe-area-inset-bottom)); width: 138px; }
/* 猫粮页贴纸 */
.stk-can { left: 58px; bottom: calc(102px + env(safe-area-inset-bottom)); height: 70px; transform: rotate(-8deg); }
.stk-coffee { left: 150px; bottom: calc(174px + env(safe-area-inset-bottom)); height: 30px; transform: rotate(8deg); }
.stk-lick { right: 18px; bottom: calc(66px + env(safe-area-inset-bottom)); width: 90px; transform: rotate(4deg); }
/* 体重页贴纸 */
.stk-collar { left: 18px; bottom: calc(68px + env(safe-area-inset-bottom)); width: 132px; transform: rotate(-5deg); }
.stk-bread { right: 118px; bottom: calc(194px + env(safe-area-inset-bottom)); height: 34px; transform: rotate(-8deg); }
.stk-taiyaki { right: 24px; bottom: calc(156px + env(safe-area-inset-bottom)); height: 38px; transform: rotate(6deg); }
.stk-donut { right: 68px; bottom: calc(110px + env(safe-area-inset-bottom)); height: 40px; }
/* 事件页贴纸 */
.stk-box { left: 26px; bottom: calc(282px + env(safe-area-inset-bottom)); height: 52px; transform: rotate(-12deg); }
.stk-blanket { left: 50%; transform: translateX(-50%); bottom: calc(70px + env(safe-area-inset-bottom)); width: 140px; }
.stk-chair { right: 40px; bottom: calc(220px + env(safe-area-inset-bottom)); height: 70px; transform: rotate(12deg); }

/* ---------- 通用组件 ---------- */
.card {
  background: var(--card); border-radius: 22px;
  box-shadow: 0 4px 16px rgba(74, 63, 53, 0.06);
  margin: 0 16px;
}
.page-head, .cal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 22px 8px 22px;
}
.h1 { font-size: 24px; font-weight: 700; }
.subtitle { font-size: 13px; color: var(--faint); margin-top: 2px; }
.add-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 24px; font-weight: 600;
  box-shadow: 0 4px 10px rgba(217, 119, 87, 0.35);
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.section-label { font-size: 13px; font-weight: 600; color: var(--faint); padding: 14px 22px 8px 22px; display: flex; gap: 8px; align-items: baseline; }
.section-label .num { color: var(--muted); font-weight: 700; font-size: 12px; }

/* ---------- 日历页 ---------- */
.cal-title { display: flex; align-items: baseline; gap: 8px; }
.cal-title .big { font-size: 30px; font-weight: 800; font-family: var(--num-font); }
.cal-title .year { font-size: 15px; font-weight: 700; color: var(--faint); font-family: var(--num-font); }
.nav-btns { display: flex; gap: 10px; }
.nav-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 20px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding-bottom: 3px;
}
.legend-wrap { display: flex; align-items: center; gap: 8px; padding: 0 24px 10px 24px; }
.legend { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.lrow { display: flex; gap: 14px; align-items: center; font-size: 11px; color: var(--sub); }
.litem { display: flex; align-items: center; gap: 5px; }
.litem b { font-size: 12px; }
#st-normal { color: var(--green-dark); } #st-warning { color: var(--amber-dark); } #st-abnormal { color: var(--red-dark); }
#st-events, #st-upcoming { color: var(--marker); }
.sw { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.sw-g { background: rgba(127, 176, 105, 0.22); }
.sw-y { background: rgba(240, 184, 76, 0.26); }
.sw-r { background: rgba(224, 104, 92, 0.20); }
.poop-stk { height: 52px; margin-right: 16px; }

.cal-card { padding: 14px 12px 10px 12px; }
.week-row { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 6px; }
.week-row span { text-align: center; font-size: 11px; font-weight: 600; color: var(--faint); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cell {
  position: relative; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; font-family: var(--num-font);
  color: var(--ink); border: none; background: none;
}
.cell.st-normal { background: rgba(127, 176, 105, 0.14); color: var(--green-dark); }
.cell.st-warning { background: rgba(240, 184, 76, 0.16); color: var(--amber-dark); }
.cell.st-abnormal { background: rgba(224, 104, 92, 0.13); color: var(--red-dark); }
.cell.future { color: rgba(184, 171, 151, 0.6); }
.cell.today { box-shadow: inset 0 0 0 1.5px rgba(232, 146, 110, 0.45); }
.cell.selected { box-shadow: inset 0 0 0 2px var(--marker); }
.cell .mark { position: absolute; top: 3px; right: 4px; width: 11px; height: 11px; }

.day-card { margin-top: 14px; padding: 18px; }
.day-head { display: flex; align-items: center; justify-content: space-between; }
.day-title { font-size: 15px; font-weight: 600; }
.clear-btn { font-size: 12px; color: var(--faint); }
.chips { display: flex; gap: 8px; margin-top: 12px; }
.chip {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 99px;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; }
.chip-normal { background: rgba(127, 176, 105, 0.14); color: var(--green-dark); }
.chip-warning { background: rgba(240, 184, 76, 0.16); color: var(--amber-dark); }
.chip-abnormal { background: rgba(224, 104, 92, 0.13); color: var(--red-dark); }
.chip-normal i { background: var(--green); } .chip-warning i { background: var(--amber); } .chip-abnormal i { background: var(--red); }
.chip.on-normal { background: var(--green); color: #fff; } .chip.on-normal i { background: #fff; }
.chip.on-warning { background: var(--amber); color: #fff; } .chip.on-warning i { background: #fff; }
.chip.on-abnormal { background: var(--red); color: #fff; } .chip.on-abnormal i { background: #fff; }
.note-input {
  width: 100%; margin-top: 12px; padding: 10px; border: none; resize: none;
  background: var(--bg); border-radius: 12px; font-size: 13px; color: var(--sub);
  font-family: inherit;
}
.day-events { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.dev-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.dev-row .tag {
  margin-left: auto; font-size: 11px; font-weight: 600; color: var(--marker);
  background: var(--accent-soft); padding: 3px 8px; border-radius: 99px;
}
.dev-row .enote { font-size: 12px; color: var(--faint); }

/* ---------- 猫粮页 ---------- */
.food-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.food-top { display: flex; gap: 14px; align-items: center; }
.food-photo {
  width: 76px; height: 76px; border-radius: 18px; object-fit: cover;
  background: var(--accent-soft); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--accent);
}
.food-brand { font-size: 12px; font-weight: 600; color: var(--accent); }
.food-name { font-size: 16px; font-weight: 600; margin: 3px 0; }
.food-spec { font-size: 13px; color: var(--sub); font-family: var(--num-font); }
.food-dates {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 12px; padding: 8px 12px;
  font-size: 12px; color: var(--sub); font-family: var(--num-font);
}
.count-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cchip { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; }
.cchip i { width: 7px; height: 7px; border-radius: 50%; }
.cchip-ok { background: rgba(127,176,105,0.13); color: var(--green-dark); } .cchip-ok i { background: var(--green); }
.cchip-warn { background: rgba(240,184,76,0.13); color: var(--amber-dark); } .cchip-warn i { background: var(--amber); }
.cchip-bad { background: rgba(224,104,92,0.13); color: var(--red-dark); } .cchip-bad i { background: var(--red); }
.count-src { font-size: 11px; color: var(--muted); }
.food-note { font-size: 13px; color: var(--sub); display: flex; gap: 8px; align-items: flex-start; }
.food-note span { flex: 1; }

#food-timeline { padding: 16px; }
.tl-months { display: flex; margin-left: 70px; margin-bottom: 8px; }
.tl-months span { flex: 1; text-align: center; font-size: 9px; color: var(--muted); font-family: var(--num-font); }
.tl-row { display: flex; align-items: center; margin-bottom: 8px; border: none; background: none; width: 100%; padding: 0; }
.tl-label { width: 70px; font-size: 11px; color: var(--sub); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.tl-lane {
  flex: 1; position: relative; height: 20px;
  background-image: linear-gradient(90deg, transparent calc(100% - 1px), var(--line) calc(100% - 1px));
  background-size: calc(100% / 12) 100%;
}
.tl-bar { position: absolute; top: 5px; height: 10px; border-radius: 99px; min-width: 6px; }
.tl-active { position: absolute; top: 3px; font-size: 9px; font-weight: 600; color: var(--accent); }
.tl-hint { font-size: 11px; color: var(--muted); padding-top: 6px; }
.empty-hint { text-align: center; font-size: 13px; color: var(--faint); padding-top: 30px; }

/* ---------- 体重页 ---------- */
.wt-current { padding: 20px; display: flex; align-items: flex-end; justify-content: space-between; }
.wt-label { font-size: 12px; color: var(--faint); }
.wt-big { font-size: 40px; font-weight: 800; font-family: var(--num-font); line-height: 1.1; }
.wt-big small { font-size: 16px; color: var(--faint); font-weight: 700; }
.delta-chip {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; font-family: var(--num-font);
  padding: 5px 10px; border-radius: 99px;
}
.delta-up { background: rgba(127,176,105,0.13); color: var(--green-dark); }
.delta-down { background: rgba(224,104,92,0.13); color: var(--red-dark); }
.chart-card { margin-top: 14px; padding: 16px; }
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.wt-list { margin-top: 4px; padding: 4px 16px; }
.wt-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--line);
  width: 100%; border-radius: 0; background: none; text-align: left;
}
.wt-row:last-child { border-bottom: none; }
.wt-date { font-size: 13px; color: var(--sub); font-family: var(--num-font); }
.wt-kg { font-size: 14px; font-weight: 700; font-family: var(--num-font); }
.wt-delta { font-size: 12px; font-family: var(--num-font); width: 60px; text-align: right; }
.d-up { color: var(--green-dark); } .d-down { color: var(--red-dark); } .d-none { color: var(--muted); }

/* ---------- 事件页 ---------- */
.upcoming-card {
  margin: 0 16px; background: var(--accent-soft); border-radius: 22px;
  padding: 16px 18px; display: flex; align-items: center; gap: 14px;
}
.upcoming-card .uc-label { font-size: 12px; font-weight: 600; color: var(--marker); }
.upcoming-card .uc-title { font-size: 15px; font-weight: 600; margin: 3px 0; }
.upcoming-card .uc-date { font-size: 12px; color: var(--sub); font-family: var(--num-font); }
.event-list { display: flex; flex-direction: column; gap: 10px; margin: 0 16px; }
.event-card {
  background: var(--card); border-radius: 18px; padding: 14px 16px;
  box-shadow: 0 4px 16px rgba(74, 63, 53, 0.05);
  width: 100%; text-align: left;
}
.ec-head { display: flex; align-items: center; gap: 6px; }
.ec-title { font-size: 14px; font-weight: 600; }
.ec-clip { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--faint); font-family: var(--num-font); }
.ec-date { margin-left: auto; font-size: 12px; color: var(--faint); font-family: var(--num-font); }
.ec-note { font-size: 12px; color: var(--sub); margin-top: 4px; }
.backup-row { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 22px 0 4px 0; }
.text-btn { font-size: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.dot-sep { color: var(--line); }

/* ---------- 标签栏 ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 16px rgba(74, 63, 53, 0.06);
  padding: 10px 10px calc(env(safe-area-inset-bottom) + 8px) 10px;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); }
.tab svg { width: 24px; height: 24px; stroke: currentColor; }
.tab .pawtab { fill: currentColor; stroke: none; }
.tab span { font-size: 11px; }
.tab.active { color: var(--accent); }
.tab.active span { font-weight: 600; }

/* ---------- 弹窗表单 ---------- */
#sheet {
  border: none; border-radius: 22px 22px 0 0; padding: 0;
  width: 100%; max-width: 100%; margin: auto 0 0 0;
  background: var(--bg); max-height: 88dvh;
}
#sheet::backdrop { background: rgba(74, 63, 53, 0.35); }
.sheet-inner { display: flex; flex-direction: column; max-height: 88dvh; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; position: sticky; top: 0; background: var(--bg);
}
.sheet-title { font-size: 16px; font-weight: 600; }
.sheet-btn { font-size: 15px; color: var(--accent); font-weight: 600; padding: 4px 6px; }
.sheet-btn.plain { color: var(--faint); font-weight: 400; }
.sheet-btn:disabled { opacity: 0.4; }
.sheet-body { overflow-y: auto; padding: 0 16px calc(env(safe-area-inset-bottom) + 20px) 16px; }
.fgroup { background: var(--card); border-radius: 16px; margin-bottom: 14px; overflow: hidden; }
.fgroup-label { font-size: 12px; color: var(--faint); padding: 0 6px 6px 6px; }
.frow {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.frow:last-child { border-bottom: none; }
.frow label { color: var(--ink); flex-shrink: 0; }
.frow input[type="text"], .frow input[type="number"], .frow textarea {
  flex: 1; border: none; background: none; font-size: 15px; font-family: inherit;
  color: var(--ink); text-align: right; min-width: 0; outline: none;
}
.frow textarea { text-align: left; resize: none; }
.frow input[type="date"] {
  flex: 1; border: none; background: none; font-size: 15px; font-family: inherit;
  color: var(--ink); text-align: right; outline: none;
}
.frow .unit { color: var(--faint); font-size: 14px; }
.frow-switch { justify-content: space-between; }
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 99px; background: #e5ddd0; transition: 0.2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }
.danger-btn { width: 100%; padding: 14px; color: var(--red); font-size: 15px; background: var(--card); border-radius: 16px; }
.photo-strip { display: flex; gap: 10px; overflow-x: auto; padding: 12px 14px; }
.pthumb { position: relative; flex-shrink: 0; }
.pthumb img { width: 68px; height: 68px; object-fit: cover; border-radius: 10px; display: block; }
.pthumb .px {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.photo-add-row { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-size: 15px; color: var(--accent); }
.fphoto-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.fphoto-row .food-photo { width: 56px; height: 56px; border-radius: 14px; font-size: 24px; }
.fphoto-row .pick { color: var(--accent); font-size: 15px; }
.fphoto-row .rm { color: var(--red); font-size: 14px; margin-left: auto; }

/* ---------- 大图查看 ---------- */
#photo-viewer {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: flex; flex-direction: column;
}
#pv-close {
  position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 16px; z-index: 2;
  color: #fff; font-size: 15px; background: rgba(255,255,255,0.15);
  padding: 6px 14px; border-radius: 99px;
}
#pv-scroll { flex: 1; overflow: auto; display: flex; }
#pv-img { margin: auto; max-width: 100%; max-height: 100%; transition: transform 0.2s; transform-origin: center center; }
#pv-img.zoomed { max-width: none; max-height: none; width: 250%; }
