:root {
  --bg: #F4F6F5;
  --card: #FFFFFF;
  --ink: #16211B;
  --muted: #5E6B63;
  --line: #E3E8E4;
  --brand: #1F8A5B;
  --brand-dark: #146B45;
  --brand-soft: #E9F5EF;
  --accent: #E07B39;
  --accent-soft: #FDF0E6;
  --warn: #B26A00;
  --warn-soft: #FDF3E1;
  --danger: #B23A2E;
  --danger-soft: #FBEDEB;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(22, 33, 27, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--brand-dark); text-decoration: none; }

/* ---------- 手机壳 ---------- */
.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: 28px;
}
@media (min-width: 620px) {
  body { background: #E9EDEA; }
  .app { box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(22, 33, 27, .12); }
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.iconbtn {
  border: 0; background: transparent; padding: 6px; font-size: 18px;
  line-height: 1; cursor: pointer; color: var(--ink); border-radius: 8px;
}
.iconbtn:active { background: var(--brand-soft); }

.page { padding: 16px; }

/* ---------- 通用 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card.tap { cursor: pointer; }
.card.tap:active { background: #FBFCFB; }
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--muted); font-size: 12.5px; }
.tiny { color: var(--muted); font-size: 12px; line-height: 1.6; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack > * + * { margin-top: 8px; }

.btn {
  display: block; width: 100%; padding: 12px; border: 0; border-radius: 11px;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 15px;
  cursor: pointer; text-align: center;
}
.btn:active { background: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.btn.small { width: auto; padding: 8px 14px; font-size: 13px; border-radius: 9px; }
.btn:disabled { background: #C9D4CD; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--brand-soft); color: var(--brand-dark); }
.badge.soon { background: var(--warn-soft); color: var(--warn); }
.badge.late { background: var(--danger-soft); color: var(--danger); }
.badge.plain { background: #F0F3F1; color: var(--muted); }

.avatar {
  width: 46px; height: 46px; border-radius: 14px; background: var(--brand-soft);
  display: flex; align-items: center; justify-content: center; font-size: 22px; flex: 0 0 auto;
}

.empty { text-align: center; padding: 30px 16px; color: var(--muted); font-size: 13px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }

.divider { height: 1px; background: var(--line); margin: 12px 0; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.input, select.input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 15px; outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 138, 91, .12); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  flex: 1 1 0; min-width: 68px; padding: 10px 8px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; font-size: 13.5px; color: var(--ink);
  cursor: pointer; text-align: center;
}
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.chip.wide { flex: 1 1 46%; }

.err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin: 4px 0 0; }

.progress { display: flex; gap: 5px; margin-bottom: 16px; }
.progress i { flex: 1; height: 4px; border-radius: 2px; background: #E1E7E3; }
.progress i.on { background: var(--brand); }

/* ---------- 数据块 ---------- */
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metrics > div { border: 1px solid var(--line); border-radius: 11px; padding: 10px 8px; text-align: center; background: #fff; }
.metrics small { display: block; color: var(--muted); font-size: 11.5px; }
.metrics b { display: block; font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.metrics b.sm { font-size: 13.5px; }

.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item b { font-weight: 600; font-size: 14px; }
.list-item small { display: block; color: var(--muted); font-size: 12px; }

.chart { margin: 6px 0 2px; }

/* ---------- 首页 ---------- */
.hero {
  border-radius: 18px; padding: 20px; color: #fff; margin-bottom: 14px;
  background: linear-gradient(135deg, #1F8A5B, #157049);
}
.hero h2 { margin: 0 0 6px; font-size: 20px; }
.hero p { margin: 0; font-size: 13px; opacity: .92; }

.pet-card { display: flex; gap: 12px; align-items: center; }
.pet-card .name { font-size: 15px; font-weight: 600; }
.pet-card .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.notice { border-left: 3px solid var(--warn); background: var(--warn-soft); color: #6B4500; padding: 8px 12px; border-radius: 0 8px 8px 0; font-size: 12.5px; margin-bottom: 12px; }

.section-title { font-size: 12px; letter-spacing: .06em; color: var(--muted); margin: 18px 2px 8px; }

/* ---------- 配方 ---------- */
.formula-main { border: 1px solid #BFE2CE; background: #fff; border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.formula-main .title { font-size: 16px; font-weight: 600; margin: 6px 0 2px; }
.reasons { margin: 8px 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.reason { font-size: 11.5px; background: var(--brand-soft); color: var(--brand-dark); padding: 3px 8px; border-radius: 999px; }

.bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: #EEF2EF; margin: 10px 0 4px; }
.bar i { display: block; height: 100%; }

/* ---------- 提醒 ---------- */
.reminder { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }
.reminder.done { opacity: .65; }

/* ---------- 占位 ---------- */
.unavailable { text-align: center; padding: 60px 24px; color: var(--muted); }
.unavailable .big { font-size: 40px; margin-bottom: 12px; }

/* ---------- 营养计算器 ---------- */
.nut-results { border: 1px solid var(--line); border-radius: 10px; max-height: 190px; overflow: auto; background: #fff; }
.nut-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; border: 0; border-bottom: 1px solid var(--line); background: #fff; font-family: inherit; color: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.nut-item:last-child { border-bottom: 0; }
.nut-item:active { background: var(--brand-soft); }
.nut-item small { color: var(--muted); }
.nut-selected { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 4px 10px; }
.nut-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.nut-row:last-child { border-bottom: 0; }
.nut-row .nm { flex: 1; min-width: 0; font-size: 13.5px; }
.nut-row input { width: 74px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; text-align: right; }
.nut-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.nut-table th, .nut-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.nut-table th { color: var(--muted); font-weight: 500; font-size: 11.5px; }
.nut-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.status-ok { color: var(--brand-dark); }
.status-low { color: var(--warn); }
.status-high { color: var(--danger); }
.nut-tag { font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: #F0F3F1; color: var(--muted); }

.admin-body { background: #F2F5F3; }
.admin { max-width: 1120px; margin: 0 auto; padding: 24px 20px 60px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-head h1 { font-size: 20px; margin: 0; }
.admin-grid { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 18px; align-items: start; }
.admin-nav { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.admin-nav a { display: block; padding: 9px 12px; border-radius: 9px; color: var(--muted); font-size: 13.5px; }
.admin-nav a.on { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.admin-panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.admin-panel h2 { font-size: 16px; margin: 0 0 4px; }
.admin-panel .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; background: #FAFBFA; }
.tbl tr.off td { opacity: .55; }
.tbl .name { font-weight: 600; }

.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #F0F3F1; color: var(--muted); }

.switch { position: relative; width: 44px; height: 26px; border-radius: 999px; background: #CFD8D2; border: 0; cursor: pointer; flex: 0 0 auto; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .16s; }
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(18px); }

.modal-mask { position: fixed; inset: 0; background: rgba(16, 24, 20, .45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; padding: 20px; }
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.modal-foot .btn { width: auto; padding: 9px 18px; font-size: 14px; }

.login-wrap { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.login-wrap h1 { font-size: 18px; margin: 0 0 6px; }
.login-wrap p { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: rgba(22, 33, 27, .92); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; z-index: 99; opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.toast.show { opacity: 1; }

@media (max-width: 780px) {
  .admin-grid { grid-template-columns: 1fr; }
  .admin-nav { display: flex; gap: 6px; overflow: auto; }
  .admin-nav a { white-space: nowrap; }
  .tbl { font-size: 12px; }
  .tbl th:nth-child(4), .tbl td:nth-child(4) { display: none; }
}
