/* ============ 设计变量 ============ */
:root {
  --brand: #4f7cff;
  --brand-deep: #3b5de7;
  --brand-grad: linear-gradient(135deg, #5a8bff 0%, #7f6bff 100%);
  --ok: #22b07d;
  --warn: #ff6b6b;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1d2433;
  --ink-2: #5b6478;
  --ink-3: #9aa3b8;
  --line: #e8ecf4;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(31, 45, 90, .07);
  --tabbar-h: calc(58px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
        "MiSans", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font: inherit; border: 0; background: none; cursor: pointer; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* ============ 登录/注册 ============ */
.auth-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 28px;
  background: radial-gradient(120% 80% at 50% 0%, #6f8dff 0%, #4f7cff 45%, #3d55c8 100%);
  padding: 24px;
}
.auth-hero { text-align: center; color: #fff; }
.auth-logo {
  width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 26px;
  background: rgba(255,255,255,.18); backdrop-filter: blur(8px);
  font-size: 44px; line-height: 84px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.auth-hero h1 { font-size: 26px; font-weight: 700; letter-spacing: 2px; }
.auth-hero p { opacity: .85; margin-top: 4px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 24px;
  padding: 22px 22px 26px; box-shadow: 0 24px 60px rgba(20, 35, 90, .35);
}
.auth-tabs { display: flex; gap: 8px; background: var(--bg); padding: 5px; border-radius: 14px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 9px 0; border-radius: 10px; color: var(--ink-2); font-weight: 600; }
.auth-tab.active { background: #fff; color: var(--brand); box-shadow: 0 2px 10px rgba(31,45,90,.1); }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fbfcfe; outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--brand); background: #fff; }
.auth-hint { margin-top: 16px; font-size: 12px; color: var(--ink-3); text-align: center; line-height: 1.7; }

/* ============ 应用骨架 ============ */
.app { max-width: 780px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#page-header {
  position: sticky; top: 0; z-index: 30; padding: 14px 18px 16px;
  background: var(--brand-grad); color: #fff;
  border-radius: 0 0 26px 26px; box-shadow: 0 10px 30px rgba(79,124,255,.25);
}
#page-header h2 { font-size: 19px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; }
#page-header .sub { font-size: 12.5px; opacity: .85; margin-top: 2px; }
#page-header .h-btn {
  font-size: 13px; background: rgba(255,255,255,.18); padding: 6px 14px;
  border-radius: 999px; color: #fff; font-weight: 600;
}
main#view { flex: 1; padding: 16px 16px calc(var(--tabbar-h) + 20px); }

/* 桌面浏览器居中呈现手机风格卡片流 */
@media (min-width: 780px) {
  body { background: #e9edf6; }
  .app { background: var(--bg); box-shadow: 0 0 60px rgba(30,45,90,.12); }
}

/* ============ 通用组件 ============ */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.card-title .add { color: var(--brand); font-size: 14px; font-weight: 600; }
.btn-primary {
  display: inline-block; background: var(--brand-grad); color: #fff; font-weight: 700;
  padding: 12px 22px; border-radius: 14px; box-shadow: 0 8px 20px rgba(79,124,255,.35);
  transition: transform .1s, opacity .15s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary[disabled] { opacity: .5; pointer-events: none; }
.btn-block { display: block; width: 100%; text-align: center; padding: 14px; font-size: 17px; }
.btn-ghost { padding: 11px 18px; border-radius: 12px; background: var(--bg); color: var(--ink-2); font-weight: 600; }
.btn-danger { padding: 11px 18px; border-radius: 12px; background: var(--warn); color: #fff; font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #eef2ff; color: var(--brand-deep);
}
.chip.warn { background: #ffecec; color: #e5484d; }
.chip.ok { background: #e3f7ee; color: var(--ok); }
.empty { text-align: center; padding: 44px 20px; color: var(--ink-3); }
.empty .emoji { font-size: 44px; display: block; margin-bottom: 10px; opacity: .8; }
.empty .t1 { color: var(--ink-2); font-weight: 600; }
.empty .t2 { font-size: 13px; margin-top: 4px; }

/* ============ 底部 Tab 栏 ============ */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 780px; height: var(--tabbar-h); z-index: 40;
  display: flex; background: rgba(255,255,255,.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.tab .tab-icon { font-size: 20px; filter: grayscale(1); opacity: .55; transition: all .15s; }
.tab.active { color: var(--brand); }
.tab.active .tab-icon { filter: none; opacity: 1; transform: translateY(-1px) scale(1.1); }

/* ============ 首页 ============ */
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.qa {
  border-radius: 16px; padding: 16px 6px; text-align: center; font-weight: 600; font-size: 13.5px;
  color: var(--ink); background: linear-gradient(180deg, #f3f6ff, #ffffff); border: 1px solid var(--line);
}
.qa .ico { font-size: 26px; display: block; margin-bottom: 6px; }
.child-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.remind { margin: 6px 0 10px; display: flex; flex-direction: column; gap: 6px; }
.remind-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: 12px; }
.remind-row .who { font-weight: 700; }
.remind-row .msg { color: var(--ink-2); }
.remind-row.lv-overdue { background: #fff1f2; color: var(--warn); }
.remind-row.lv-overdue .who, .remind-row.lv-overdue .msg { color: var(--warn); }
.remind-row.lv-soon { background: #fff8e6; }
.remind-row.lv-soon .msg { color: #907000; }
.remind-row.lv-none { background: #eef3ff; }
.remind-row.lv-none .msg { color: var(--ink-3); }
.child-item:last-child { border-bottom: 0; }
.avatar {
  width: 44px; height: 44px; border-radius: 14px; flex: 0 0 44px; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: var(--brand-grad);
}
.avatar.alt { background: linear-gradient(135deg, #ffb46f, #ff8fab); }
.child-info { flex: 1; min-width: 0; }
.child-info .name { font-weight: 700; }
.child-info .meta { font-size: 12.5px; color: var(--ink-3); }
.child-ops { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.mini-btn { font-size: 12px; padding: 6px 10px; border-radius: 10px; background: var(--bg); color: var(--ink-2); font-weight: 600; white-space: nowrap; flex-shrink: 0; }.mini-btn.danger { color: var(--warn); }

/* ============ 上传页 ============ */
.upload-area {
  border: 2px dashed #cdd8f4; border-radius: 18px; background: #f8faff;
  padding: 34px 16px; text-align: center; color: var(--ink-2); transition: border-color .15s;
}
.upload-area .big { font-size: 40px; margin-bottom: 8px; }
.upload-area .tip { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.preview-wrap { position: relative; }
.preview-wrap img { border-radius: 16px; max-height: 320px; object-fit: contain; margin: 0 auto; }
.preview-remove {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; font-size: 15px; line-height: 30px; text-align: center;
}
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.form-row:last-child { border-bottom: 0; }
.form-row label { color: var(--ink-2); font-weight: 600; font-size: 14px; white-space: 0; }
.form-row input, .form-row select {
  flex: 1; min-width: 0; text-align: right; border: 0; background: transparent; outline: none; padding: 8px 0;
}
.scan-tip { font-size: 12.5px; color: var(--brand); display: flex; align-items: center; gap: 6px; margin-top: 10px; }

/* ============ 问答页 ============ */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - var(--tabbar-h) - 76px); min-height: 380px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 4px 2px 12px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; margin-bottom: 14px; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 86%; padding: 11px 15px; border-radius: 18px; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.msg.user .bubble { background: var(--brand-grad); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 6px 16px rgba(79,124,255,.3); }
.msg.bot .bubble { background: #fff; color: var(--ink); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.viz-card { margin-top: 10px; background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 12px; max-width: 86%; }
.viz-chart { width: 100%; height: 240px; }
.src-line { font-size: 11.5px; color: var(--ink-3); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.src-tag { background: #f1f4fb; border-radius: 8px; padding: 3px 8px; }
.msg-time { font-size: 10.5px; color: var(--ink-3); margin-top: 4px; text-align: right; }
.msg.bot .msg-col { display: flex; flex-direction: column; align-items: flex-start; max-width: 86%; }
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #b9c4e2; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .3 } 40% { opacity: 1 } }
.suggest-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.suggest {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px;
  color: var(--brand-deep); font-weight: 600; font-size: 14px; text-align: left; box-shadow: var(--shadow);
}
.chat-input-bar {
  display: flex; gap: 10px; padding: 10px 2px 2px; align-items: center;
}
.chat-input-bar input {
  flex: 1; border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 12px 18px; outline: none; font-size: 15px;
}
.chat-input-bar input:focus { border-color: var(--brand); }
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; background: var(--brand-grad); color: #fff;
  font-size: 19px; flex: 0 0 46px; box-shadow: 0 6px 16px rgba(79,124,255,.35);
}
.send-btn[disabled] { opacity: .45; }
.child-picker { display: flex; align-items: center; gap: 8px; padding: 0 2px 8px; }
.child-picker select { border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 12px; background: #fff; font-weight: 600; color: var(--brand-deep); }
.history-link { margin-left: auto; font-size: 13px; color: var(--brand); font-weight: 600; }

/* 指标/数据表 */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { background: #f4f7ff; color: var(--ink-2); text-align: left; padding: 8px 10px; font-weight: 700; white-space: nowrap; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.data-table td.abn { color: var(--warn); font-weight: 700; }
.table-scroll { overflow-x: auto; }

/* ============ 报告页 ============ */
.report-card { position: relative; }
.report-top { display: flex; justify-content: space-between; align-items: flex-start; }
.report-date { font-size: 18px; font-weight: 800; }
.report-hosp { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.report-sum { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ind-group { margin-top: 14px; }
.ind-group h5 { font-size: 13.5px; color: var(--brand-deep); margin-bottom: 6px; }
.ind-edit-head, .ind-edit-row { display: grid; grid-template-columns: 1.3fr .7fr .6fr 1fr auto; gap: 6px; align-items: center; }
.ind-edit-head { font-size: 11px; color: var(--ink-3); padding: 4px 0; }
.ind-edit-head span:last-child { width: 28px; }
.ind-edit-row { margin-bottom: 8px; }
.ind-edit-row input { width: 100%; min-width: 0; padding: 8px 9px; border: 1.5px solid var(--line); border-radius: 9px; font-size: 12.5px; background: #fbfcfe; outline: none; }
.ind-edit-row input:focus { border-color: var(--brand); background: #fff; }
.ind-edit-row [data-remove] { width: 30px; padding: 8px 0; text-align: center; }
.trend-block { margin-top: 8px; }

/* ============ 我的 ============ */
.me-head { display: flex; align-items: center; gap: 14px; }
.me-head .avatar { width: 56px; height: 56px; flex-basis: 56px; font-size: 22px; border-radius: 18px; }
.me-head .nick { font-size: 19px; font-weight: 800; }
.me-head .uid { font-size: 12.5px; color: var(--ink-3); }
.stats { display: flex; }
.stats .stat { flex: 1; text-align: center; }
.stats .stat + .stat { border-left: 1px solid var(--line); }
.stats .num { font-size: 22px; font-weight: 800; color: var(--brand-deep); }
.stats .lbl { font-size: 12px; color: var(--ink-3); }
.list-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 2px; border-bottom: 1px solid var(--line); font-weight: 600; }
.list-row:last-child { border-bottom: 0; }
.list-row .arrow { color: var(--ink-3); }
.list-row.danger { color: var(--warn); }
.invite-box { display: flex; align-items: center; justify-content: space-between; background: #f4f7ff; border-radius: 14px; padding: 12px 16px; margin: 10px 0; }
.invite-box .code { font-size: 22px; font-weight: 800; letter-spacing: 4px; color: var(--brand-deep); }
.member-tag { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); padding: 6px 12px; border-radius: 999px; font-size: 13px; margin: 4px 6px 0 0; }
.invite-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.invite-row:last-child { border-bottom: 0; }
.invite-main { display: flex; align-items: center; gap: 10px; }
.invite-main .code { font-size: 18px; font-weight: 800; letter-spacing: 3px; color: var(--brand-deep); }
.invite-main small.free { color: #16a34a; font-weight: 700; }
.invite-main small.used { color: var(--ink-3); }

/* ============ 弹层 / 全局 ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 45, .45); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.sheet {
  width: 100%; max-width: 560px; background: #fff; border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); max-height: 82dvh; overflow-y: auto;
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0 } to { transform: none; opacity: 1 } }
.sheet h3 { font-size: 17px; margin-bottom: 16px; text-align: center; }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: -8px auto 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions button { flex: 1; }

.confirm-mask { position: fixed; inset: 0; background: rgba(15,23,45,.45); z-index: 70; display: flex; align-items: center; justify-content: center; }
.confirm-box { width: min(320px, 86vw); background: #fff; border-radius: 20px; padding: 22px; text-align: center; }
.confirm-box h4 { margin-bottom: 8px; }
.confirm-box p { color: var(--ink-2); font-size: 14px; margin-bottom: 18px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions button { flex: 1; }

.image-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 80; overflow: auto; display: flex; align-items: center; justify-content: center; }
.image-viewer img { max-width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 26px); transform: translateX(-50%) translateY(20px);
  background: rgba(29, 36, 51, .92); color: #fff; padding: 11px 20px; border-radius: 12px;
  font-size: 14px; z-index: 90; opacity: 0; pointer-events: none; transition: all .25s; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading-mask { position: fixed; inset: 0; background: rgba(255,255,255,.6); z-index: 85; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.loading-box { background: #fff; padding: 22px 28px; border-radius: 18px; box-shadow: 0 12px 40px rgba(30,45,90,.2); text-align: center; font-weight: 600; color: var(--ink-2); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 10px; border-radius: 50%;
  border: 3.5px solid #e3e9f7; border-top-color: var(--brand); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
