:root {
  --bg: #faf7f8;
  --card: #ffffff;
  --ink: #2b1d22;
  --muted: #8a7278;
  --line: #eee1e5;
  --brand: #cf437a;
  --brand-soft: #fce4ec;
  --ok: #2f8f5b;
  --warn: #b4690e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 29, 34, .06), 0 8px 24px rgba(43, 29, 34, .05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; overflow-x: hidden; }
/* hidden 属性会被 display:flex 之类覆盖，必须显式兜底 */
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.view { display: none; width: 100%; max-width: 720px; margin: 0 auto; padding: 16px 16px 88px; }
.view.active { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: rgba(250, 247, 248, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; }
.topbar .sub { font-size: 12px; color: var(--muted); }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 0;
  background: var(--brand); color: #fff; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.line { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 15px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.hero { text-align: center; padding: 28px 0 18px; }
.hero .logo { font-size: 34px; font-weight: 700; color: var(--brand); letter-spacing: -1px; }
.hero p { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.tabs { display: flex; gap: 6px; background: var(--brand-soft); border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.tabs button {
  flex: 1; min-height: 36px; border: 0; border-radius: 8px; background: transparent;
  color: var(--brand); font-size: 14px; font-weight: 500; cursor: pointer;
}
.tabs button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.device {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.device .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.device .dot.off { background: #c9c2c4; }
.device .name { font-weight: 600; }
.device .meta { font-size: 12px; color: var(--muted); }
.device .arrow { margin-left: auto; color: var(--muted); }

.stat { display: flex; gap: 12px; }
.stat > div { flex: 1; text-align: center; }
.stat .num { font-size: 30px; font-weight: 700; color: var(--brand); line-height: 1.1; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

.rows { margin-top: 4px; }
.row {
  display: grid; grid-template-columns: 1fr 64px 64px; gap: 8px;
  padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.row.head { color: var(--muted); font-size: 12px; border-top: 0; padding-bottom: 4px; }
.row .r { text-align: right; font-variant-numeric: tabular-nums; }
.row .r.eff { color: var(--brand); font-weight: 600; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 96px; margin: 8px 0 4px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.bars .bar i { display: block; width: 100%; background: var(--brand-soft); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar b { font-size: 11px; color: var(--muted); font-weight: 400; }
.bars .bar span { font-size: 11px; color: var(--ink); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  flex: 1; min-height: 54px; border: 0; background: transparent;
  color: var(--muted); font-size: 12px; cursor: pointer;
}
.nav button.on { color: var(--brand); font-weight: 600; }

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.err { color: #b3261e; font-size: 13px; min-height: 18px; }
.ok { color: var(--ok); font-size: 13px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: 12px; }
.tag.gray { background: #f0eced; color: var(--muted); }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 0; }

/* ---- 设备列表：卡片里直接看今日三项主数据 ---- */
.device .dev-main { flex: 1; min-width: 0; }
.device .today3 { display: flex; margin: 6px 0 4px; }
.device .today3 > div { flex: 1; text-align: center; }
.device .today3 > div:first-child { text-align: left; }
.device .today3 > div:last-child { text-align: right; }
.device .today3 b { display: block; font-size: 22px; font-weight: 700; color: var(--brand); line-height: 1.15; font-variant-numeric: tabular-nums; }
.device .today3 span { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---- 小时明细合计行 ---- */
.row.total {
  border-top: 1px solid var(--line);
  margin-top: 2px;
  padding-top: 8px;
  font-weight: 600;
}
.row.total > div:first-child { color: var(--muted); font-weight: 500; }

/* ---- 设备信息：键值行 ---- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv:first-of-type { border-top: 0; }
.kv span { color: var(--muted); }
.kv b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- 无权限时只读展示 ---- */
.field .ro { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #faf8f9; color: var(--ink); }

/* ---- 邀请码 / 邀请链接 ---- */
.invite .code { font-size: 26px; font-weight: 700; letter-spacing: 4px; color: var(--brand); font-variant-numeric: tabular-nums; }
.linkrow { display: flex; gap: 8px; margin-top: 8px; }
.linkrow input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; color: var(--muted); background: #faf8f9; }
.linkrow .btn { flex: none; padding: 0 14px; min-height: 40px; }

/* ---- 轻提示 ---- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(43, 29, 34, .92); color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: 20px; z-index: 99;
  transition: opacity .3s; max-width: 80vw; text-align: center;
}
.toast.out { opacity: 0; }

/* ================= 结构改版：一级页只放设备，其余进二级页 ================= */

/* 顶栏右侧的圆形按钮（+ / 返回） */
.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 22px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 0 2px;
}
.icon-btn.back { font-size: 26px; padding-bottom: 4px; }
.icon-btn:active { background: var(--brand-soft); }

/* 分段控件：绑定 / 加入 */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 12px;
  background: var(--brand-soft); border-radius: 12px;
}
.seg button {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--brand); font-size: 14px; font-weight: 500;
}
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* 空状态 */
.empty-state { text-align: center; padding: 48px 8px 8px; }
.empty-state .glyph {
  width: 72px; height: 72px; margin: 0 auto 18px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-size: 34px; line-height: 72px; font-weight: 300;
}
.empty-state h2 { font-size: 17px; margin: 0 0 8px; }
.empty-state .hint { margin: 0 0 22px; }
.empty-state .btn { max-width: 280px; margin-left: auto; margin-right: auto; }

/* 我的：账号卡 */
.card.profile { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600;
}
.profile .name { font-size: 17px; font-weight: 600; }

/* 我的：菜单列表 */
.card.menu { padding: 0; overflow: hidden; }
.menu-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 52px; padding: 0 16px;
  border: 0; border-top: 1px solid var(--line); background: transparent;
  font-size: 15px; color: var(--ink); text-align: left; cursor: pointer;
}
.menu-row:first-child { border-top: 0; }
.menu-row:active { background: #faf6f7; }
.menu-row .arrow { color: var(--muted); font-size: 20px; }
.menu-row .val { color: var(--muted); font-size: 14px; }

/* 关于页 */
.about-logo {
  font-size: 30px; font-weight: 700; color: var(--brand);
  letter-spacing: -1px; margin-bottom: 6px;
}

/* 顶栏通栏：贴住屏幕顶部，背景盖住整宽 */
.view { padding: 0 16px 88px; }
.topbar { margin: 0 -16px 12px; }
.view#view-auth { padding-top: 8px; }

/* 设备卡片：状态点在名字行，箭头靠右 */
.device { display: block; }
.device .name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.device .name .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.device .name .dot.off { background: #c9c2c4; }
.device .name .arrow { margin-left: auto; color: var(--muted); font-size: 20px; }
.device .meta { margin-top: 2px; }

/* 在线 / 离线 药丸 */
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 18px; margin-right: 6px;
}
.pill.ok { background: #e6f4ec; color: var(--ok); }
.pill.off { background: #f1eeef; color: var(--muted); }
.ok-text { color: var(--ok); }
.off-text { color: var(--muted); }

/* 改名输入框：跟着键值行右对齐 */
.kv input {
  flex: 1; min-width: 0; min-height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px;
  text-align: right; font-size: 14px; color: var(--ink);
}


/* 记录详情：紧凑数据优先，不使用宣传横幅或装饰图片。 */
#view-detail { max-width: 1120px; --brand: #853e70; --brand-soft: #f3e9f2; --muted: #71636e; --line: #eadfe7; }
#view-detail .topbar h1 { min-width: 0; overflow-wrap: anywhere; }
#view-detail .card { border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 3px 15px rgba(54, 30, 46, .035); padding: 22px; margin-bottom: 16px; }
#view-detail .card h2 { color: #352332; font-size: 18px; line-height: 1.4; margin: 5px 0 12px; }
#view-detail .topbar { background: rgba(250,247,248,.97); margin-bottom: 20px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.eyebrow { font-size: 11px; letter-spacing: .12em; color: var(--muted); }
.date-label { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 6px; }
.small-btn { min-height: 38px; font-size: 13px; padding: 0 16px; }
.sync-line { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 12px; margin: 0 0 16px; flex-wrap: wrap; }
.journal-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.journal-metrics > div { border-radius: 12px; background: #faf4f7; padding: 16px 18px; }
.journal-metrics > div:nth-child(2) { background: #f5f1fa; }
.journal-metrics > div:nth-child(3) { background: #fbf4ed; }
.journal-metrics span { display: block; color: #604453; font-size: 13px; }
.journal-metrics strong { display: block; color: #6d2e59; font-size: clamp(28px,4vw,40px); line-height: 1.25; margin: 8px 0; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.journal-metrics small { display: block; font-size: 11px; color: var(--muted); }
.chart-caption { color: var(--muted); font-size: 12px; line-height: 1.7; margin: 12px 0 0; }
.reset-note, .estimate-note { font-size: 12px; color: #785b35; background: #fbf5eb; border-radius: 9px; padding: 11px 13px; margin: 12px 0 0; }
.care-note { display: flex; gap: 16px; align-items: baseline; border: 1px solid #ecdac8; background: #fff8ef; color: #74522f; border-radius: 12px; padding: 13px 18px; margin: 0 0 24px; font-size: 13px; }
.care-note b { flex: none; font-weight: 600; }
.journal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 15px; flex-wrap: wrap; }
.journal-toolbar h2 { font-size: 18px; margin: 0; }
.range-switch, .metric-switch { display: inline-flex; gap: 3px; padding: 4px; background: #f1e9ef; border-radius: 12px; }
.range-switch button, .metric-switch button { border: none; background: transparent; border-radius: 8px; min-height: 36px; padding: 0 14px; color: #6c4e62; font: inherit; font-size: 12px; cursor: pointer; }
.range-switch button[aria-pressed="true"] { background: #853e70; color: #fff; box-shadow: 0 2px 6px #853e7022; }
.metric-switch { background: #f7f2f6; }
.metric-switch button { padding: 0 10px; font-size: 11px; }
.metric-switch button[aria-pressed="true"] { background: #fff; color: #752e60; box-shadow: 0 1px 5px #392a3614; }
.journal-grid { display: grid; grid-template-columns: minmax(0,1.25fr) minmax(0,1fr); gap: 16px; }
#view-detail .journal-grid .card { min-width: 0; margin-bottom: 16px; }
.chart-stat { font-size: 29px; font-weight: 650; color: #6d2e59; font-variant-numeric: tabular-nums; margin: 18px 0 0; }
.chart-stat span { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.chart-stat small { float: right; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 14px; }
.trend-svg, .activity-svg { width: 100%; height: auto; display: block; overflow: visible; margin: 12px 0 0; }
.trend-svg text, .activity-svg text { font-size: 11px; fill: #71636e; font-family: inherit; }
.chart-grid { stroke: #eadfe7; stroke-width: 1; }
.trend-line { fill: none; stroke: #853e70; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.trend-dot { fill: #853e70; stroke: white; stroke-width: 2; }
.today-dot { fill: white; stroke: #853e70; }
.trend-svg .missing-mark { fill: #978a93; }
.hour-bar { fill: #d8bfd7; }
.peak-bar { fill: #853e70; }
.peak-time { color: #6d2e59; font-size: 26px; font-weight: 650; line-height: 1.3; margin-top: 17px; font-variant-numeric: tabular-nums; }
.chart-empty { min-height: 155px; display: grid; place-items: center; }
#view-detail .reference-card { background: #fcf9fc; }
.reference-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 24px; }
.reference-grid h3 { font-size: 13px; font-weight: 600; margin: 2px 0 7px; color: #65435b; }
.reference-grid p { font-size: 12px; line-height: 1.85; color: var(--muted); margin: 0; }
.journal-table summary { cursor: pointer; color: #493241; font-size: 14px; font-weight: 600; min-height: 24px; }
.journal-table summary span { float: right; font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.details-body { margin-top: 16px; }
.table-scroll { overflow-x: auto; margin-top: 14px; }
.journal-table table { border-collapse: collapse; width: 100%; font-size: 12px; font-variant-numeric: tabular-nums; }
.journal-table caption { text-align: left; color: var(--muted); padding: 0 0 10px; font-size: 11px; }
.journal-table th, .journal-table td { text-align: right; border-bottom: 1px solid var(--line); padding: 10px 8px; white-space: nowrap; }
.journal-table th:first-child { text-align: left; font-weight: 500; }
.journal-table thead th { color: var(--muted); font-weight: 400; }
.hour-table { margin-top: 18px; }
.partial-notice { background: #fff7e9; color: #74522f; padding: 12px 18px; border-radius: 10px; font-size: 13px; margin: 0 0 16px; }
.text-btn { border: 0; background: none; color: #703b60; text-decoration: underline; padding: 8px; cursor: pointer; }
.analysis-loading { color: var(--muted); min-height: 260px; display: grid; place-items: center; font-size: 13px; }
#view-detail :focus-visible { outline: 3px solid #853e70; outline-offset: 3px; }
#view-detail .kv b { min-width: 0; overflow-wrap: anywhere; text-align: right; }
@media (max-width: 760px) {
  .journal-grid { grid-template-columns: 1fr; gap: 0; }
  .reference-grid { grid-template-columns: 1fr; gap: 16px; }
  .care-note { display: block; font-size: 12px; }
  .care-note b { display: block; margin-bottom: 4px; }
  #view-detail .card { padding: 18px; }
  .journal-metrics { gap: 8px; }
  .journal-metrics > div { padding: 12px 10px; }
  .journal-metrics span { font-size: 12px; }
  .journal-metrics small { font-size: 10px; }
  .journal-toolbar h2 { font-size: 16px; }
  .range-switch button { padding: 0 10px; }
}
@media (max-width: 360px) {
  #view-detail { padding-left: 12px; padding-right: 12px; }
  #view-detail .card { padding: 14px; }
  .journal-metrics { gap: 6px; }
  .journal-metrics > div { padding: 10px 6px; }
  .journal-metrics span { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { #view-detail * { transition: none !important; } }

/* 首页设备概览：独立设备不相加，整张卡片可用键盘打开。 */
#view-devices { --brand: #853e70; --brand-soft: #f3e9f2; --muted: #71636e; --line: #eadfe7; }
#view-devices #dev-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
#view-devices .device { display: block; width: 100%; min-width: 0; margin: 0; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: white; color: var(--ink); text-align: left; font: inherit; box-shadow: 0 3px 15px rgba(54,30,46,.035); cursor: pointer; }
#view-devices .device:hover { border-color: #b78dab; }
#view-devices .device:focus-visible { outline: 3px solid #853e70; outline-offset: 3px; }
#view-devices .device-heading { display: flex; align-items: center; gap: 10px; min-width: 0; }
#view-devices .device-name { font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
#view-devices .device-heading .pill { flex: none; margin: 0 0 0 auto; }
#view-devices .device-heading .arrow { margin: 0; font-size: 24px; color: #95738b; }
#view-devices .device-role { display: block; font-size: 12px; color: var(--muted); margin: 4px 0 18px; }
#view-devices .today3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 16px 0 20px; border-top: 1px solid #f1e9ef; }
#view-devices .today3 > span { min-width: 0; text-align: center; }
#view-devices .today3 b { color: #6d2e59; font-size: 30px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
#view-devices .today3 > span > span { display: block; color: var(--muted); font-size: 11px; margin-top: 6px; }
#view-devices .device-footer { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid #f1e9ef; font-size: 12px; color: var(--muted); }
#view-devices .device-footer > span:last-child { color: #853e70; }
#view-devices .empty-state { grid-column: 1/-1; padding: 28px 20px; border: 1px solid var(--line); border-radius: 18px; background: white; }
#view-detail .today-sessions .table-scroll { margin-top: 4px; }
#view-detail .today-sessions td:first-child { text-align: left; }
#view-detail .today-sessions td.empty { text-align: center; }
#view-detail .today-sessions td.eff { color: #853e70; font-weight: 600; }
#view-detail .today-sessions tfoot { font-weight: 600; }
#view-detail .today-sessions .section-heading h2 { margin-bottom: 5px; }
@media (max-width: 760px) {
  #view-devices #dev-list { grid-template-columns: 1fr; gap: 12px; }
  #view-devices .device { padding: 18px; }
}
@media (max-width: 360px) {
  #view-devices .device { padding: 14px; }
  #view-devices .device-name { font-size: 15px; }
  #view-devices .today3 b { font-size: 26px; }
}
