/* H5Go 每日记录：简洁的健康类应用风格。浅灰底、白色圆角卡片、大号数字。 */
:root {
  --bg: #F1F3F5;
  --card: #FFFFFF;
  --text: #191919;
  --text-2: #5F6368;
  --text-3: #9AA0A6;
  --line: #E8EAED;
  --primary: #0A59F7;
  --primary-soft: #E7EFFF;
  --danger: #E84026;
  --danger-soft: #FDECEA;
  --ok: #24A148;
  --ok-soft: #E6F4EA;
  --warn: #ED6F21;
  --warn-soft: #FDF0E6;
  --c-steps: #FF7A1A;
  --c-steps-soft: #FFF1E6;
  --c-weight: #14A89B;
  --c-weight-soft: #E3F6F4;
  --c-sales: #0A59F7;
  --c-sales-soft: #E7EFFF;
  --c-ad: #7B61FF;
  --c-ad-soft: #EFEBFF;
  --radius: 20px;
  --radius-sm: 12px;
  --tabbar-h: 58px;
  --actionbar-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "HarmonyOS Sans SC", "HarmonyOS Sans", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; }
svg { display: block; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.boot-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.2); } }

/* ---------- 通用组件 ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card-title { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 46px; padding: 0 22px; border-radius: 23px; font-weight: 600; font-size: 16px;
  transition: background .15s, opacity .15s, transform .05s; white-space: nowrap; user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #0049D9; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.secondary:hover:not(:disabled) { background: #D9E6FF; }
.btn.ghost { color: var(--text-2); background: #F1F3F5; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); background: var(--card); }
.btn.small { height: 36px; padding: 0 16px; font-size: 14px; border-radius: 18px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn.secondary.loading::after { border-color: rgba(10,89,247,.3); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.badge { display: inline-block; font-size: 12px; line-height: 20px; padding: 0 8px; border-radius: 10px; font-weight: 500; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.none { background: #F1F3F5; color: var(--text-3); }

.seg { display: flex; background: #F1F3F5; border-radius: 22px; padding: 3px; gap: 2px; }
.seg-btn { flex: 1; height: 36px; border-radius: 18px; font-size: 14px; color: var(--text-2); font-weight: 500; min-width: 0; }
.seg-btn.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.form-error { color: var(--danger); font-size: 13px; margin: 6px 0 0; min-height: 0; }
.form-error:empty { display: none; }
.form-error.center { text-align: center; }
.notice { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: #9A4A12; font-size: 13px; display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.notice .link { color: var(--primary); font-weight: 600; font-size: 13px; }

/* ---------- 登录 ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 24px; padding: 32px 24px 28px; }
.login-logo svg { width: 52px; height: 52px; }
.login-card h1 { font-size: 24px; margin: 16px 0 4px; }
.login-sub { margin: 0 0 24px; color: var(--text-2); font-size: 14px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field input {
  width: 100%; height: 48px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  padding: 0 14px; font-size: 16px; background: #FAFBFC; outline: none;
}
.field input:focus { border-color: var(--primary); background: #fff; }
.login .btn { margin-top: 10px; }

/* ---------- 布局 ---------- */
.app { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(241,243,245,.92); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); }
.topbar-inner { max-width: 980px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 8px; display: flex; align-items: center; justify-content: space-between; }
.page-title { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: .5px; }
.tabs-top { display: none; }
.main { max-width: 980px; margin: 0 auto; padding: 4px 12px calc(var(--tabbar-h) + var(--actionbar-h) + var(--safe-b) + 16px); }
.app.no-actionbar .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b); background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  display: flex; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text-3); font-size: 11px; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--primary); }

.action-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 25;
  background: rgba(241,243,245,.94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0,0,0,.04);
}
.action-inner { max-width: 980px; margin: 0 auto; padding: 8px 12px 10px; }
.actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }
.save-status { font-size: 12.5px; color: var(--text-2); min-height: 18px; margin: 0 4px 6px; display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.save-status .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-3); }
.save-status.ok .dot { background: var(--ok); }
.save-status.dirty { color: var(--warn); }
.save-status.dirty .dot { background: var(--warn); }
.save-status.fail { color: var(--danger); white-space: normal; }
.save-status.fail .dot { background: var(--danger); }
.save-status button { color: var(--primary); font-weight: 600; font-size: 12.5px; }

/* ---------- 日期卡 ---------- */
.date-line { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.arrow { width: 40px; height: 40px; border-radius: 50%; background: #F1F3F5; display: grid; place-items: center; flex: none; }
.arrow svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.arrow:disabled { opacity: .3; }
.date-text { flex: 1; text-align: center; min-width: 0; }
.date-caption { font-size: 12.5px; color: var(--text-2); display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; }
.date-main { font-size: 21px; font-weight: 700; margin-top: 2px; letter-spacing: .3px; }

/* ---------- 汇总卡 ---------- */
.summary-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.ring { position: relative; width: 52px; height: 52px; flex: none; }
.ring svg { width: 52px; height: 52px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring-bg { stroke: #EEF0F2; }
.ring-fg { stroke: var(--ok); stroke-linecap: round; stroke-dasharray: 113.1; stroke-dashoffset: 113.1; transition: stroke-dashoffset .4s ease; }
.ring.partial .ring-fg { stroke: var(--warn); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.summary-text { min-width: 0; }
.summary-title { font-size: 16px; font-weight: 600; }
.summary-sub { font-size: 12.5px; color: var(--text-2); }

.load-error { text-align: center; color: var(--danger); }
.load-error p { margin: 0 0 10px; font-size: 14px; }

/* ---------- 指标卡 ---------- */
.metrics { display: grid; grid-template-columns: 1fr; gap: 12px; }
.metric {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px 12px; position: relative;
  border: 2px solid transparent; transition: border-color .15s; cursor: text; min-width: 0;
}
.metric.focused { border-color: var(--mc); }
.metric.invalid { border-color: var(--danger); }
.metric-head { display: flex; align-items: center; gap: 10px; }
.metric-icon { width: 32px; height: 32px; border-radius: 10px; background: var(--mc-soft); display: grid; place-items: center; flex: none; }
.metric-icon svg { width: 20px; height: 20px; }
.metric-label { font-size: 15px; font-weight: 600; }
.metric-prev { margin-left: auto; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.metric-body { display: flex; align-items: baseline; gap: 6px; margin-top: 8px; min-width: 0; }
.metric-prefix { font-size: 22px; font-weight: 600; color: var(--text-2); }
/* 输入框随内容自动变宽，单位紧跟数字 */
.metric-field { display: inline-grid; min-width: 0; max-width: 100%; flex: 0 1 auto; }
.metric-field::after {
  content: attr(data-mirror) " "; visibility: hidden; white-space: pre; grid-area: 1 / 1;
  font-size: 32px; font-weight: 700; letter-spacing: .3px; font-variant-numeric: tabular-nums; padding: 2px 0; overflow: hidden;
}
.metric-field.is-empty::after { font-size: 22px; font-weight: 500; }
.metric-field .metric-input { grid-area: 1 / 1; }
.metric-input {
  min-width: 3ch; width: 100%; border: 0; outline: none; background: transparent; padding: 2px 0;
  font-size: 32px; font-weight: 700; letter-spacing: .3px; font-variant-numeric: tabular-nums; caret-color: var(--mc);
}
.metric-input::placeholder { color: #C9CDD2; font-weight: 500; font-size: 22px; }
.metric-input:disabled { color: var(--text-3); }
.metric-unit { font-size: 15px; color: var(--text-2); font-weight: 500; flex: none; }
.metric-clear { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; align-self: center; color: var(--text-3); margin-left: auto; }
.metric-body::after { content: ""; flex: 1 1 0; order: 9; }
.metric-clear { order: 10; }
.metric-clear svg { width: 18px; height: 18px; fill: #D5D9DE; }
.metric-clear:hover svg { fill: #B9BEC4; }
.metric-foot { display: flex; justify-content: space-between; gap: 8px; min-height: 18px; font-size: 12px; margin-top: 2px; }
.metric-state { color: var(--text-3); }
.metric-state.filled { color: var(--mc); }
.metric-err { color: var(--danger); text-align: right; }
.kbd-hint { display: none; text-align: center; font-size: 12px; color: var(--text-3); margin: 8px 0 0; }

/* ---------- 历史 ---------- */
.filter-card .seg { max-width: 420px; }
.custom-range { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 12px; }
.custom-range label { flex: 1 1 130px; min-width: 0; }
.custom-range label span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.custom-range input, .date-input {
  width: 100%; height: 40px; border-radius: 10px; border: 1.5px solid var(--line); padding: 0 10px; background: #FAFBFC; font-size: 15px; min-width: 0;
}
.history-summary { font-size: 13px; color: var(--text-2); margin-top: 10px; }
.history-summary:empty { display: none; }
.history-list { display: grid; gap: 10px; }
.h-item { background: var(--card); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; transition: box-shadow .15s; }
.h-item:hover { box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.h-top { display: flex; align-items: center; gap: 8px; }
.h-date { font-size: 16px; font-weight: 700; }
.h-week { font-size: 13px; color: var(--text-2); }
.h-top .badge { margin-left: auto; }
.h-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; }
.h-cell { min-width: 0; }
.h-cell .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.h-cell .k i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.h-cell .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.h-cell .v.empty { color: var(--text-3); font-weight: 400; font-size: 14px; }
.h-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.h-foot .upd { font-size: 12px; color: var(--text-3); flex: 1; min-width: 0; }
.h-gap { border: 1.5px dashed #D5D9DE; border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: var(--text-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.h-gap .gap-date { color: var(--primary); font-weight: 600; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-2); }
.empty-state svg { width: 56px; height: 56px; margin: 0 auto 10px; fill: none; stroke: #C9CDD2; stroke-width: 1.5; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 16px 0; font-size: 13px; color: var(--text-2); }

/* ---------- 我的 ---------- */
.me-card { display: flex; align-items: center; gap: 14px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 20px; font-weight: 700; flex: none; }
.me-name { font-size: 18px; font-weight: 700; }
.me-sub { font-size: 13px; color: var(--text-2); }
.backup-list { display: grid; gap: 10px; }
.backup-row { display: flex; gap: 10px; align-items: flex-start; }
.backup-row .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: none; }
.backup-row .dot.ok { background: var(--ok); }
.backup-row .dot.bad { background: var(--danger); }
.backup-row .dot.off { background: var(--text-3); }
.backup-row .t { font-weight: 600; font-size: 14px; }
.backup-row .d { font-size: 12.5px; color: var(--text-2); }

/* ---------- 弹层 ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.38); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow: auto;
  border-radius: 24px 24px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); animation: up .2s ease-out;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: #D5D9DE; margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.sheet-title { font-size: 18px; font-weight: 700; margin: 0; }
.sheet-close { width: 32px; height: 32px; border-radius: 50%; background: #F1F3F5; display: grid; place-items: center; flex: none; }
.sheet-close svg { width: 16px; height: 16px; stroke: var(--text-2); stroke-width: 2.4; stroke-linecap: round; }
.dialog { background: var(--card); width: calc(100% - 32px); max-width: 400px; border-radius: 24px; padding: 22px 20px 16px; margin: auto; animation: pop .15s ease-out; }
.overlay.center { align-items: center; }
@keyframes pop { from { transform: scale(.96); opacity: .5; } }
.dialog h3 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 16px; color: var(--text-2); font-size: 14px; white-space: pre-line; }
.dialog-btns { display: grid; gap: 8px; }
.dialog-btns.row { grid-template-columns: 1fr 1fr; }
.dialog .compare { width: 100%; border-collapse: collapse; font-size: 13px; margin: 0 0 16px; }
.dialog .compare th, .dialog .compare td { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--line); }
.dialog .compare th { color: var(--text-2); font-weight: 500; }

.pick-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 12px 0 4px; scrollbar-width: none; }
.pick-row::-webkit-scrollbar { display: none; }
.pick-chip { flex: none; width: 54px; padding: 8px 0; border-radius: 14px; background: #F1F3F5; text-align: center; font-size: 12px; color: var(--text-2); }
.pick-chip b { display: block; font-size: 17px; color: var(--text); }
.pick-chip.active { background: var(--primary); color: #fff; }
.pick-chip.active b { color: #fff; }
.pick-chip .has { display: block; width: 5px; height: 5px; border-radius: 50%; margin: 3px auto 0; background: transparent; }
.pick-chip .has.on { background: var(--ok); }
.pick-chip.active .has.on { background: #fff; }

/* 日报 */
.report-preview { background: #F1F3F5; border-radius: 16px; padding: 10px; display: grid; place-items: center; min-height: 160px; }
.report-preview img { width: 100%; height: auto; border-radius: 10px; display: block; -webkit-touch-callout: default; user-select: auto; }
.report-preview .muted { font-size: 13px; text-align: center; }
.report-hint { font-size: 12.5px; color: var(--text-2); text-align: center; margin: 8px 0 0; }
.report-text {
  margin: 12px 0 0; padding: 12px 14px; background: #F7F8FA; border-radius: 14px; font-family: var(--font);
  font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text;
}
.report-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.report-actions .wide { grid-column: 1 / -1; }
.report-tabs { margin-bottom: 12px; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--actionbar-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: rgba(25,25,25,.88); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 200;
  max-width: calc(100% - 48px); text-align: center; animation: fade .15s;
}

/* ---------- 大屏 ---------- */
@media (min-width: 760px) {
  :root { --tabbar-h: 0px; }
  .tabbar { display: none; }
  .tabs-top { display: flex; gap: 4px; background: #E6E8EB; border-radius: 22px; padding: 3px; }
  .tab-top { height: 36px; padding: 0 20px; border-radius: 18px; font-size: 14px; color: var(--text-2); font-weight: 500; }
  .tab-top.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
  .topbar-inner { padding: 18px 24px 12px; }
  .main { padding: 8px 24px calc(var(--actionbar-h) + 24px); }
  .app.no-actionbar .main { padding-bottom: 32px; }
  .action-inner { padding: 10px 24px 14px; display: flex; align-items: center; gap: 16px; }
  .action-inner .save-status { flex: 1; margin: 0; }
  .actions { grid-template-columns: auto auto; }
  .actions .btn { min-width: 140px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  #view-record { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-content: start; }
  #view-record > .date-card { grid-column: 1; }
  #view-record > .summary-card { grid-column: 2; margin-bottom: 12px; }
  #view-record > .load-error, #view-record > .metrics, #view-record > .form-error, #view-record > .kbd-hint { grid-column: 1 / -1; }
  .kbd-hint { display: block; }
  .metric { padding: 18px 20px 14px; }
  .metric-input, .metric-field::after { font-size: 36px; }
  .h-grid { grid-template-columns: repeat(4, 1fr); }
  .overlay { align-items: center; }
  .sheet { border-radius: 24px; max-height: 90vh; padding: 16px 22px 20px; }
  .sheet-grip { display: none; }
  .toast { bottom: calc(var(--actionbar-h) + 24px); }
}
@media (max-width: 374px) {
  .metric-input, .metric-field::after { font-size: 28px; }
  .date-main { font-size: 19px; }
  .btn { padding: 0 16px; }
}
