:root {
  --bg: #f6f6f8;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #86868b;
  --line: #e6e6ea;
  --brand: #f97362;
  --brand-soft: #fff0ed;
  --blue: #4b8bf5;
  --green: #34c759;
  --purple: #8b6bf0;
  --amber: #f5a623;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px -12px rgba(0,0,0,.18);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101013;
    --card: #1c1c20;
    --text: #f2f2f5;
    --muted: #96969e;
    --line: #2c2c33;
    --brand-soft: #3a2420;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.7);
  }
}

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

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: #e5484d; font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* ---------------------------------------------------------------- 登录页 */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.gate-card {
  width: 100%; max-width: 360px; background: var(--card);
  border-radius: 22px; padding: 28px 22px; box-shadow: var(--shadow);
}
.gate-logo { font-size: 44px; text-align: center; line-height: 1; }
.gate h1 { font-size: 22px; text-align: center; margin: 12px 0 4px; }
.gate p { text-align: center; margin: 0 0 18px; }
.gate-foot { font-size: 12px; color: var(--muted); margin: 18px 0 0 !important; }
.gate-foot code { background: var(--bg); padding: 1px 5px; border-radius: 5px; }

/* ---------------------------------------------------------------- 表单件 */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=date], input[type=number],
input[type=datetime-local], textarea, select {
  width: 100%; padding: 11px 13px; font-size: 15px; font-family: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 60px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-size: 15px; font-weight: 500;
  padding: 11px 16px; border-radius: 12px; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger  { color: #e5484d; border-color: #e5484d55; background: transparent; }
.btn-block   { display: block; width: 100%; }
.btn-sm      { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

.icon-btn {
  appearance: none; border: none; background: transparent; color: var(--muted);
  font-size: 18px; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--bg); }

/* ---------------------------------------------------------------- 布局 */
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(72px + var(--safe-b)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar-right { display: flex; align-items: center; gap: 6px; }

.baby-chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px 5px 6px; cursor: pointer;
  color: var(--text); font: inherit; max-width: 62%; min-width: 0;
}
#baby-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft);
  display: grid; place-items: center; font-size: 16px; flex: none;
}
.baby-chip-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; overflow: hidden; min-width: 0; }
.baby-chip-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.baby-chip-text small { font-size: 11px; color: var(--muted); }
.caret { color: var(--muted); font-size: 11px; }

.mode-badge {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap;
}
.mode-badge.local { background: #f5a62322; color: var(--amber); }

.view { padding: 6px 14px 20px; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; flex: none; }
.card-head > .muted, .card-head > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- 状态卡 */
.status-card {
  background: linear-gradient(135deg, var(--brand) 0%, #f5a06b 100%);
  color: #fff; border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
  box-shadow: 0 10px 26px -14px var(--brand);
}
.status-card.sleeping { background: linear-gradient(135deg, #6b6bf0 0%, #9b6bf0 100%); box-shadow: 0 10px 26px -14px #6b6bf0; }
.status-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.status-since { font-size: 12px; opacity: .85; }
.status-big { font-size: 30px; font-weight: 700; letter-spacing: -.5px; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.status-sub { font-size: 13px; opacity: .9; }
.status-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.25);
}
.status-grid div { text-align: center; }
.status-grid b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.status-grid span { font-size: 11px; opacity: .82; }
.status-actions { display: flex; gap: 8px; margin-top: 14px; }
.status-actions .btn {
  flex: 1; background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.4);
  color: #fff; backdrop-filter: blur(4px);
}

/* ---------------------------------------------------------------- 快记区 */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick {
  appearance: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 15px; padding: 13px 6px 11px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font: inherit; box-shadow: var(--shadow); transition: transform .08s;
}
.quick:active { transform: scale(.95); }
.quick i { font-size: 24px; font-style: normal; line-height: 1; }
.quick em { font-size: 12px; font-style: normal; font-weight: 500; }
.quick.accent { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.quick.accent em { color: var(--brand); }

/* ---------------------------------------------------------------- 时间线 */
.tl-day { margin-bottom: 6px; }
.tl-day-title {
  font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 14px 4px 8px; position: sticky; top: 54px; z-index: 5;
  background: var(--bg);
}
.tl-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  background: var(--card); border: none; border-bottom: 1px solid var(--line);
  padding: 12px 14px; text-align: left; color: var(--text); font: inherit; cursor: pointer;
}
.tl-item:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.tl-item:last-of-type { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.tl-item:only-of-type { border-radius: var(--radius); }
.tl-item:active { background: var(--bg); }
.tl-icon { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 17px; flex: none; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-size: 14px; font-weight: 500; }
.tl-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.tl-wrap { margin-bottom: 14px; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; font-size: 14px; }

/* ---------------------------------------------------------------- 统计 */
.seg {
  display: flex; background: var(--bg); border-radius: 11px; padding: 3px; margin-bottom: 14px;
}
.seg button {
  flex: 1; appearance: none; border: none; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; padding: 8px; border-radius: 9px; cursor: pointer;
}
.seg button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--card); border-radius: 14px; padding: 13px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.stat span { font-size: 12px; color: var(--muted); display: block; }
.stat b { font-size: 21px; font-variant-numeric: tabular-nums; display: block; margin-top: 3px; }
.stat b small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 2px; }

.chart { display: flex; align-items: flex-end; gap: 5px; height: 120px; margin-top: 6px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; justify-content: flex-end; }
.chart-bar {
  width: 100%; border-radius: 5px 5px 3px 3px; background: var(--brand);
  min-height: 3px; transition: height .25s;
}
.chart-bar.b2 { background: var(--purple); }
.chart-label { font-size: 10px; color: var(--muted); }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.dot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; margin-right: 5px; }

/* ---------------------------------------------------------------- 列表项 */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row-main { min-width: 0; }
.row-main strong { font-size: 14px; font-weight: 500; display: block; }
.row-main small { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex: none; }

/* ---------------------------------------------------------------- 弹层 */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; animation: fade .18s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin: 0 auto; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--card); border-radius: 22px 22px 0 0; padding-bottom: var(--safe-b);
  animation: slide .22s cubic-bezier(.32,.72,0,1);
}
@keyframes fade { from { opacity: 0 } }
@keyframes slide { from { transform: translateY(100%) } }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 9px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 4px; flex: none; }
.sheet-head h2 { font-size: 17px; margin: 0; }
.sheet-body { padding: 10px 16px 4px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 16px 16px; display: flex; gap: 10px; flex: none; }
.sheet-foot .btn { flex: 1; }

.pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pick button {
  appearance: none; font: inherit; font-size: 14px; cursor: pointer;
  padding: 9px 14px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
}
.pick button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pick button.on.neutral { background: var(--blue); border-color: var(--blue); }

/* ---------------------------------------------------------------- 提示条 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b)); z-index: 60;
  display: flex; align-items: center; gap: 12px;
  background: #1c1c1e; color: #fff; padding: 11px 16px;
  border-radius: 12px; font-size: 14px; box-shadow: 0 8px 26px -8px rgba(0,0,0,.5);
  animation: pop .2s; max-width: 90vw;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px) } }
.toast-action { background: none; border: none; color: #6cb2ff; font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 560px; margin: 0 auto;
  display: flex; padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; appearance: none; border: none; background: transparent; cursor: pointer;
  color: var(--muted); font: inherit; padding: 8px 0 9px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 19px; line-height: 1.1; }
.tab em { font-size: 11px; font-style: normal; }
.tab.active { color: var(--brand); }
