:root {
  --primary: #0ea5b7;
  --primary-dark: #0c8ea0;
  --primary-deep: #0b7c8d;
  --primary-soft: #e6f7f9;
  --primary-soft2: #f0fbfc;
  --accent: #f97316;
  --accent-soft: #fff1e6;
  --text: #1e2a33;
  --text-muted: #7a8894;
  --border: #e4ebf0;
  --bg: #f2f6f8;
  --card: #ffffff;
  --danger: #e23b4c;
  --success: #16a34a;
  --radius: 18px;
  --shadow-sm: 0 1px 2px rgba(20, 40, 52, .05), 0 2px 8px rgba(20, 40, 52, .05);
  --shadow-md: 0 6px 24px rgba(20, 40, 52, .10);
  --grad-main: linear-gradient(135deg, #14b8c4 0%, #0ea5b7 45%, #0d8aa8 100%);
  --grad-header: linear-gradient(150deg, #12b5c2 0%, #0ea5b7 55%, #1393b0 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 480px; margin: 0 auto; min-height: 100%; padding-bottom: 74px; }

/* ---------- 顶部栏 ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--grad-header);
  color: #fff;
  padding: 15px 18px;
  font-size: 17px; font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 2px 10px rgba(14, 165, 183, .28);
  display: flex; align-items: center; gap: 10px;
}
#topbar::before {
  content: '';
  width: 9px; height: 9px; border-radius: 3px;
  background: rgba(255,255,255,.9);
  transform: rotate(45deg);
  flex: 0 0 auto;
}

/* ---------- 视图区 ---------- */
#view { padding: 16px 14px; }

/* ---------- 底部导航 ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(20,40,52,.06);
}
.tab {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-muted); text-decoration: none; font-size: 11px; font-weight: 600;
  transition: color .18s;
}
.tab svg { transition: transform .18s; }
.tab.active { color: var(--primary); }
.tab.active svg { transform: translateY(-1px); }
.tab.active::after {
  content: ''; position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--grad-main);
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 18px; margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title::before { content: ''; width: 4px; height: 16px; border-radius: 2px; background: var(--grad-main); }
.card.center { text-align: center; padding: 36px 18px; }
.muted { color: var(--text-muted); font-size: 13px; }
.empty { color: var(--text-muted); text-align: center; padding: 30px 12px; }
.loading { color: var(--text-muted); text-align: center; padding: 30px 12px; }

/* ---------- 首页 Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  background: var(--grad-header);
  border-radius: 22px; padding: 24px 20px;
  color: #fff; margin-bottom: 18px;
  box-shadow: var(--shadow-md);
}
.hero::after {
  content: ''; position: absolute; right: -34px; top: -34px;
  width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255,255,255,.10);
}
.hero::before {
  content: ''; position: absolute; right: 24px; bottom: -44px;
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,.07);
}
.hero .hi { font-size: 13px; opacity: .85; }
.hero .who { font-size: 22px; font-weight: 800; margin: 4px 0 2px; letter-spacing: .5px; }
.hero .meta { font-size: 12px; opacity: .9; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; position: relative; z-index: 1; }
.who-row .who { font-size: 22px; font-weight: 800; margin: 4px 0 0; letter-spacing: .5px; }
.who-row .idm { font-size: 12px; opacity: .85; }
.arch-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; position: relative; z-index: 1; font-size: 12.5px; }
.arch-line .arch-k { opacity: .85; }
.arch-line b { font-weight: 600; background: rgba(255,255,255,.16); padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(255,255,255,.24); word-break: break-all; }

.hero-stats { display: flex; margin-top: 18px; gap: 10px; position: relative; z-index: 1; }
.hero-stat {
  flex: 1; background: rgba(255,255,255,.16);
  border-radius: 14px; padding: 10px 12px; text-align: center;
  border: 1px solid rgba(255,255,255,.22);
  backdrop-filter: blur(2px);
}
.hero-stat b { display: block; font-size: 18px; font-weight: 800; }
.hero-stat span { font-size: 11px; opacity: .85; }

/* ---------- 服务宫格 ---------- */
.service-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.service-grid .svc { display: flex; flex-direction: column; align-items: center; gap: 7px; text-decoration: none; }
.svc-icon {
  width: 52px; height: 52px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(20,40,52,.12);
  transition: transform .15s;
}
.svc-icon:active { transform: scale(.93); }
.svc-label { font-size: 12px; color: var(--text); font-weight: 500; }
.icon-1 { background: linear-gradient(135deg,#2fb9cd,#0e9dba); }
.icon-2 { background: linear-gradient(135deg,#38bdf8,#1d8fd6); }
.icon-3 { background: linear-gradient(135deg,#f97316,#f2641d); }
.icon-4 { background: linear-gradient(135deg,#a78bfa,#7c5ff0); }
.icon-5 { background: linear-gradient(135deg,#34d399,#0ba778); }
.icon-6 { background: linear-gradient(135deg,#fb7185,#ee3f63); }

/* ---------- 分类标题 ---------- */
.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 12px;
}
.sec-head .t { font-size: 16px; font-weight: 800; }
.sec-head .t::before { content: ''; display:inline-block; width:4px;height:16px;background:var(--grad-main);border-radius:2px;margin-right:8px;vertical-align:-2px; }
.sec-head .more { font-size: 12px; color: var(--primary); text-decoration: none; }

/* ---------- 健康提示 ---------- */
.tip-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: linear-gradient(180deg,#fdf8f2,#fffaf3);
  border: 1px solid #f2e3cd; border-radius: 16px; padding: 14px 16px;
}
.tip-icon { font-size: 20px; flex: 0 0 auto; line-height: 1.3; }
.tip-card b { font-size: 13px; color: #b45309; display: block; margin-bottom: 3px; }
.tip-card p { font-size: 13px; color: #7c5a2a; line-height: 1.6; }

/* ---------- 健康提示轮播 ---------- */
.tip-carousel { margin-bottom: 18px; }
.tip-card { min-height: 96px; transition: opacity .18s ease; }
#tip-title.tip-fade { opacity: 0; transform: translateX(-8px); }
#tip-title, #tip-content { transition: opacity .18s ease, transform .18s ease; }
.tip-dots { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.tip-dot { width: 6px; height: 6px; border-radius: 999px; background: #d6dfe4; cursor: pointer; transition: all .2s; }
.tip-dot.on { width: 16px; background: var(--primary); }

/* ---------- 家庭成员 ---------- */
.fam-list { display: flex; flex-direction: column; gap: 10px; }
.fam-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--primary-soft2); border: 1px solid var(--primary-soft);
  border-radius: 14px; padding: 12px 14px;
}
.fam-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--grad-main); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700; flex: 0 0 auto;
}
.fam-avatar.is-self { background: linear-gradient(135deg,#f97316,#f2641d); }
.fam-info { flex: 1; min-width: 0; }
.fam-info b { font-size: 15px; display: block; }
.fam-info span { font-size: 12px; color: var(--text-muted); }
.fam-town { font-size: 12px; color: var(--text-muted); }
.chip {
  display: inline-block; padding: 2px 9px; font-size: 11px;
  border-radius: 999px; font-weight: 600;
}
.chip-self { background: var(--accent-soft); color: var(--accent); }
.chip-fam { background: var(--primary-soft); color: var(--primary); }

/* ---------- 按钮 ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 12px 16px; margin-top: 14px;
  border: 1px solid transparent; border-radius: 13px;
  font-size: 15px; font-weight: 600; cursor: pointer; text-align: center;
  transition: transform .12s, box-shadow .12s;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--grad-main); color: #fff; box-shadow: 0 4px 14px rgba(14,165,183,.28); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--primary); }
.btn.ghost-sm { background: transparent; border-color: var(--border); color: var(--primary); padding: 6px 13px; font-size: 13px; margin: 0; border-radius: 10px; }
.btn.sm { width: auto; padding: 6px 13px; margin: 0; font-size: 13px; border-radius: 10px; }
.btn.danger-text { color: var(--danger); }

/* ---------- 表单 ---------- */
.form label { display: block; font-size: 13px; color: var(--text-muted); margin: 16px 0 6px; font-weight: 500; }
.form input, .form select, .form textarea {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 15px; background: #fbfdfe; color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus, .form textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,183,.12);
}
.select-wrap { position: relative; }
.select-wrap select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 34px; cursor: pointer;
}
.select-wrap::after {
  content: ''; position: absolute; right: 15px; top: 50%; margin-top: -3px;
  width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid var(--text-muted); pointer-events: none;
}

/* ---------- 链接入口行 ---------- */
.linkrow {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 4px; text-decoration: none; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.linkrow:last-child { border-bottom: none; }
.linkrow .ri {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.ri-1 { background: linear-gradient(135deg,#2fb9cd,#0e9dba); }
.ri-2 { background: linear-gradient(135deg,#34d399,#0ba778); }
.ri-3 { background: linear-gradient(135deg,#a78bfa,#7c5ff0); }
.ri-4 { background: linear-gradient(135deg,#f97316,#f2641d); }
.ri-5 { background: linear-gradient(135deg,#38bdf8,#1d8fd6); }
.linkrow .rt { flex: 1; }
.linkrow .rt b { font-size: 14.5px; display: block; }
.linkrow .rt span { font-size: 12px; color: var(--text-muted); }
.linkrow .arrow { color: #c2ccd4; font-size: 16px; }
.badge-new { background: var(--accent); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 1px; }
.badge-soon { background: var(--border); color: var(--text-muted); font-size: 10px; padding: 1px 6px; border-radius: 6px; margin-left: 6px; }

/* ---------- 档案展示 ---------- */
.sec-title { font-size: 14px; font-weight: 700; color: var(--primary-deep); margin-bottom: 12px; display: flex; align-items: center; gap: 7px; }
.sec-title::before { content: ''; width: 4px; height: 15px; border-radius: 2px; background: var(--grad-main); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; }
.kv .k { color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.kv .v { font-size: 14px; word-break: break-all; font-weight: 500; }
.kv .v.empty-v { color: #c3ccd3; font-weight: 400; }

/* 档案摘要卡 */
.arch-summary {
  background: var(--grad-header); color: #fff; border-radius: 20px;
  padding: 22px 20px; margin-bottom: 14px; box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.arch-summary::after { content:''; position:absolute; right:-30px; top:-30px; width:120px;height:120px;border-radius:50%;background:rgba(255,255,255,.10); }
.arch-summary .nm { font-size: 22px; font-weight: 800; }
.arch-summary .row2 { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; opacity:.95; }
.arch-summary .file { margin-top: 12px; font-size: 12.5px; background: rgba(255,255,255,.16); border-radius: 10px; padding: 8px 12px; display: inline-block; }

/* 状态标签 */
.state-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.state-ok { background:#e6f9ee; color:#15803d; }
.state-warn { background:#fff3e0; color:#c06a12; }
.state-info { background:#e6f6ff; color:#1d7db0; }

/* ---------- 表格 ---------- */
.tbl-wrap { overflow-x: auto; margin-top: 4px; border-radius: 12px; }
table.tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.tbl th, .tbl td {
  border-bottom: 1px solid var(--border); padding: 10px 9px;
  text-align: left; white-space: nowrap;
}
.tbl th { background: var(--primary-soft2); color: var(--primary-deep); font-weight: 700; }
.tbl th:first-child { border-radius: 10px 0 0 0; }
.tbl th:last-child { border-radius: 0 10px 0 0; }
.tbl tbody tr:nth-child(even) { background: #fafcfd; }
.tbl tbody tr:last-child td { border-bottom: none; }

/* ---------- 我的页面 ---------- */
.profile-card {
  overflow: hidden; border-radius: 22px; background: var(--card);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.profile-top { background: var(--grad-header); padding: 24px 20px; color: #fff; position: relative; overflow: hidden; }
.profile-top::after { content:''; position:absolute; right:-26px; top:-26px; width:110px;height:110px;border-radius:50%;background:rgba(255,255,255,.09); }
.profile-top .av {
  width: 54px; height: 54px; border-radius: 50%; background: rgba(255,255,255,.22);
  border: 2px solid rgba(255,255,255,.4); display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; margin-bottom: 10px;
}
.profile-top .cli { font-size: 19px; font-weight: 800; }
.profile-top .cid { font-size: 11.5px; opacity: .85; margin-top: 3px; word-break: break-all; }
.profile-body { padding: 6px 8px; }

/* ---------- 人次统计 ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.stat-box { text-align: center; padding: 14px 6px; border-radius: 14px; background: var(--primary-soft2); }
.stat-box b { display: block; font-size: 18px; color: var(--primary-deep); font-weight: 800; }
.stat-box span { font-size: 11.5px; color: var(--text-muted); }

/* ---------- 空态 ---------- */
.state-box { text-align: center; padding: 34px 20px; color: var(--text-muted); }
.state-box .big { font-size: 40px; margin-bottom: 10px; }
.state-box p { font-size: 13px; }

/* ---------- 家庭生成摘要 ---------- */
.summary-pills { display: flex; gap: 8px; }

/* ---------- 分类可折叠卡片 ---------- */
.cat-card { padding: 0; overflow: hidden; }
.cat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; cursor: pointer; user-select: none;
}
.cat-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.cat-title::before { content: ''; width: 4px; height: 16px; border-radius: 2px; background: var(--grad-main); }
.cat-arrow { color: var(--text-muted); font-size: 13px; transition: transform .2s; }
.cat-head.open .cat-arrow { transform: rotate(180deg); }
.cat-body { border-top: 1px solid var(--border); padding: 16px 18px; transition: max-height .25s ease, opacity .2s; max-height: 2000px; opacity: 1; overflow: hidden; }
.cat-body.collapsed { max-height: 0; padding-top: 0; padding-bottom: 0; opacity: 0; border-top: none; }
.cat-body .kv { gap: 10px 12px; }
.kv .v.empty-v { color: #c3ccd3; font-weight: 400; }
.kv .v.has { color: var(--text); font-weight: 500; }

/* ---------- 慢病随访（三级交互：健康管理 → 随访日期 → 随访详情） ---------- */
.card-title-row { display: flex; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--text-muted); }
.fu-card { padding: 0; overflow: hidden; }
.fu-card-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 16px 18px; cursor: pointer; user-select: none;
  background: none; border: none; text-align: left; color: var(--text);
}
.fu-card-head:active { background: var(--primary-soft2); }
.fu-card-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.fu-card-title::before { content: ''; width: 4px; height: 16px; border-radius: 2px; background: var(--grad-main); }
.fu-card-caret { color: var(--text-muted); font-size: 13px; transition: transform .2s; }
.fu-card-head.open .fu-card-caret { transform: rotate(180deg); }
.fu-card-body { border-top: 1px solid var(--border); padding: 16px 18px; transition: max-height .3s ease, opacity .2s; max-height: 2000px; opacity: 1; overflow: hidden; background: #fbfdfe; }
.fu-card-body.collapsed { max-height: 0; padding-top: 0; padding-bottom: 0; opacity: 0; border-top: none; }
.fu-records .fu-year { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.fu-dates { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.date-chip {
  padding: 8px 15px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--primary-deep); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.date-chip:active { transform: scale(.96); }
.date-chip.on { background: var(--grad-main); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(14,165,183,.28); }
.fu-detail { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 14px 16px; }
.fu-detail-date { font-size: 14px; font-weight: 700; color: var(--primary-deep); margin-bottom: 12px; }
.fu-detail .kv { gap: 10px 14px; }

/* ---------- 页脚 ---------- */
.footer-note { text-align: center; color: var(--text-muted); font-size: 12px; padding: 10px 16px 24px; }
.footer-note b { color: var(--primary-deep); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; top: 16%; transform: translateX(-50%) scale(.9);
  background: rgba(25, 35, 45, .92); color: #fff;
  padding: 11px 20px; border-radius: 12px; font-size: 14px;
  z-index: 100; max-width: 80%; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  backdrop-filter: blur(4px);
}
#toast.show { opacity: 1; transform: translateX(-50%) scale(1); }
#toast.err { background: rgba(200, 55, 70, .94); }

/* captcha 兼容（管理员页会用到） */
.captcha-row { display: flex; gap: 10px; align-items: flex-end; }
.captcha-row img { height: 52px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }