/* ============================================================
   肾管家 · 移动端样式（原生 CSS，无预处理器、无构建步骤）
   目标：iPhone 上单手可用、点击目标 ≥ 44px、少输入
   ============================================================ */

:root {
  --brand: #0f766e;
  --brand-dark: #0b5d57;
  --brand-soft: #e6f4f2;
  --green: #16a34a;
  --green-soft: #e8f8ee;
  --yellow: #b45309;
  --yellow-soft: #fdf3e3;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --bg: #f4f6f7;
  --card: #ffffff;
  --fg: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.05);
  --tab-h: 58px;
  --top-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: contain; }

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; line-height: 1.35; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--brand); text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }
/* pre-line：让错误文案里的 \n 能正常换行显示 */
.error { color: var(--red); font-size: 14px; margin: 8px 0 0; white-space: pre-line; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; }
.icon-btn {
  border: 0; background: transparent; font-size: 15px; color: var(--brand);
  min-width: 44px; min-height: 44px; border-radius: 10px;
}
.icon-btn:active { background: var(--brand-soft); }

/* ---------- 主体 ---------- */
.view {
  padding: calc(var(--top-h) + var(--safe-top) + 12px) 14px calc(var(--tab-h) + var(--safe-bottom) + 20px);
  max-width: 640px;
  margin: 0 auto;
}
.section { margin-bottom: 18px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 600; color: var(--muted);
  margin: 0 2px 8px;
}

/* ---------- 底部标签栏 ---------- */
#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; padding: 0;
}
.tab-ico { font-size: 19px; line-height: 1; }
.tab.is-active { color: var(--brand); font-weight: 600; }
.tab.is-active .tab-ico { transform: translateY(-1px); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card.tight { padding: 10px 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  background: #eef1f3;
  color: var(--fg);
  min-height: 46px;
}
.btn:active { opacity: 0.85; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--fg); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; min-height: 36px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 16px; /* ≥16px 可避免 iOS 聚焦时自动放大 */
  color: var(--fg);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > input { flex: 1; }

/* 大号数字输入（血压主输入场景，专为「少打字」优化） */
.big-input {
  font-size: 30px; font-weight: 700; text-align: center;
  min-height: 66px; padding: 8px; letter-spacing: 1px;
}
.big-input-label { text-align: center; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 分段选择（chip） */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--fg);
  border-radius: 999px; padding: 9px 15px; font-size: 14px; font-family: inherit;
  min-height: 40px;
}
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* 数量快捷按钮 */
.quick-amounts { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.quick-amounts .chip { padding: 7px 12px; font-size: 13px; min-height: 34px; }

/* ---------- 预算进度条 ---------- */
.budget { margin-bottom: 12px; }
.budget-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.budget-top .name { color: var(--muted); }
.budget-top .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.bar { height: 9px; border-radius: 999px; background: #eef1f3; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--brand); transition: width .25s ease; }
.bar.green > i { background: var(--green); }
.bar.yellow > i { background: #f59e0b; }
.bar.red > i { background: var(--red); }

/* ---------- 判定徽标与结论框 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.gray { background: #eef1f3; color: var(--muted); }

.verdict-box { border-radius: 12px; padding: 12px 14px; margin: 10px 0; }
.verdict-box.green { background: var(--green-soft); }
.verdict-box.yellow { background: var(--yellow-soft); }
.verdict-box.red { background: var(--red-soft); }
.verdict-box h3 { margin: 0 0 6px; font-size: 15px; }
.verdict-box ul { margin: 0; padding-left: 18px; font-size: 14px; }
.verdict-box li { margin-bottom: 3px; }

/* ---------- 列表 ---------- */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-size: 15px; font-weight: 500; }
.list-row .sub { font-size: 12px; color: var(--muted); }
.row-del {
  border: 0; background: transparent; color: var(--muted); font-size: 18px;
  min-width: 40px; min-height: 40px; border-radius: 10px;
}
.row-del:active { background: var(--red-soft); color: var(--red); }

/* ---------- 首页数字卡 ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .u { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 3px; }

/* ---------- 图表 ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { width: 100%; height: 190px; display: block; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ---------- 待办 ---------- */
.todo { display: flex; align-items: center; gap: 9px; font-size: 14px; padding: 7px 0; }
.todo .dot { width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; flex: none; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 26px 12px; }
.empty .ico { font-size: 30px; display: block; margin-bottom: 8px; }

/* ---------- 免责声明 ---------- */
.disclaimer {
  background: #fffaf0; border: 1px solid #f5e0b7; border-radius: 12px;
  padding: 11px 13px; font-size: 12.5px; color: #8a6d3b; line-height: 1.65;
}

/* ---------- 登录层 ---------- */
.login-layer {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: linear-gradient(180deg, #0f766e 0%, #0b5d57 100%);
}
.login-card {
  width: 100%; max-width: 340px; background: #fff; border-radius: 18px;
  padding: 26px 20px; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .22);
}
.login-logo {
  width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 15px;
  background: var(--brand); color: #fff; font-size: 26px; font-weight: 700;
  display: grid; place-items: center;
}
.login-card h1 { margin-bottom: 4px; }
.login-hint { margin: 10px 0 0; font-size: 12px; }

/* 登录/注册表单：竖排字段，间距统一 */
.stack { display: grid; gap: 10px; margin: 16px 0 14px; }

/* 口令行：输入框 + 显示/隐藏按钮（随机口令肉眼核对几乎是必需的） */
.pw-row { position: relative; margin: 0; display: flex; gap: 8px; align-items: stretch; }
.pw-row input { text-align: center; letter-spacing: .5px; }

/* 用 CSS 遮罩代替 type="password"：既保住隐私，又不会触发 iOS 的密码自动填充面板。
   不支持该属性时，JS 会自动退回 type="password"。 */
.pw-masked { -webkit-text-security: disc; }
.pw-masked.is-shown { -webkit-text-security: none; }
.pw-toggle {
  flex: none; min-width: 62px; min-height: 46px;
  border: 1px solid var(--line); background: #fff; color: var(--brand);
  border-radius: 11px; font-size: 14px; font-weight: 600; font-family: inherit;
}
.pw-toggle:active { background: var(--brand-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 200; max-width: 88vw;
  background: rgba(31, 41, 55, .93); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

/* ---------- 底部操作条 ---------- */
.action-bar {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tab-h) + var(--safe-bottom));
  z-index: 25; padding: 10px 14px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
@media (min-width: 700px) { .action-bar { max-width: 640px; margin: 0 auto; border-radius: 14px 14px 0 0; } }

.spinner { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.simple th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
table.simple td.num { font-variant-numeric: tabular-nums; }

