:root {
  --bg: #f2f4f9;
  --card: #ffffff;
  --text: #1e2233;
  --muted: #8b93a7;
  --line: #eceef4;
  --brand: #4f7cff;
  --brand-soft: #eaf0ff;
  --danger: #ef4444;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 14px calc(78px + var(--safe-b));
  min-height: 100vh;
}

/* ---------- 通用 ---------- */
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }

.hd { padding: 22px 4px 12px; }
.hd h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.3px; }
.hd-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(30, 34, 51, 0.04);
}

.row-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}

.link-btn {
  background: none; border: none; padding: 0;
  color: var(--brand); font-size: 13px; font-weight: 500;
}

.text-input, .date-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
  outline: none;
}
.text-input:focus, .date-input:focus { border-color: var(--brand); background: #fff; }
.date-input { min-height: 44px; }

.primary-btn {
  width: 100%;
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 14px;
  border-radius: 14px;
  margin-bottom: 12px;
  font-family: inherit;
}
.primary-btn:active { opacity: 0.85; }
.primary-btn.ghost { background: var(--brand-soft); color: var(--brand); }

/* ---------- 快捷日期 ---------- */
.quick-dates { display: flex; gap: 8px; margin-top: 10px; }
.quick-dates button {
  flex: 1;
  border: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 10px;
  padding: 7px 0;
  font-size: 13px;
  color: var(--muted);
  font-family: inherit;
}
.quick-dates button.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- 项目选择 ---------- */
.proj-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.proj-item {
  border: 1.5px solid var(--line);
  background: #fafbfe;
  border-radius: 12px;
  padding: 12px 4px;
  text-align: center;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 68px;
  justify-content: center;
}
.proj-item .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.proj-item.on { border-color: currentColor; }
.proj-item .name { line-height: 1.25; word-break: break-all; }

/* ---------- 时长 chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chips button {
  border: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--muted);
  font-family: inherit;
}
.chips button.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- 记录行 ---------- */
.rec {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.rec:last-child { border-bottom: none; }
.rec .bar { width: 4px; height: 30px; border-radius: 3px; flex: none; }
.rec .info { flex: 1; min-width: 0; }
.rec .t1 { font-size: 14px; font-weight: 600; }
.rec .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec .del {
  border: none; background: none; color: var(--muted);
  font-size: 13px; padding: 4px 6px; font-family: inherit;
}
.rec-ops { display: flex; align-items: center; gap: 2px; flex: none; }
.rec .edit { border: none; background: none; color: var(--brand); font-size: 13px; padding: 4px 6px; font-family: inherit; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 16px 0; }

/* ---------- 日历 ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-title { font-size: 16px; font-weight: 700; }
.nav-btn {
  border: none; background: #f3f5fb; color: var(--text);
  width: 32px; height: 32px; border-radius: 10px; font-size: 18px; line-height: 1;
  font-family: inherit;
}
.cal-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 4px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-cell {
  aspect-ratio: 1 / 1.05;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 13px;
  border: none;
  background: none;
  font-family: inherit;
  color: var(--text);
  padding: 0;
}
.cal-cell.out { color: #cfd4e0; }
.cal-cell.today { background: var(--brand-soft); font-weight: 700; color: var(--brand); }
.cal-cell:active { background: #eef1f8; }
.cal-cell.sel { background: var(--brand); color: #fff; font-weight: 700; }
.cal-cell.sel .cal-dots i { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85); }
.cal-cell.sel .cal-dots .more { color: rgba(255, 255, 255, 0.9); box-shadow: none; }
.cal-dots { display: flex; gap: 2px; height: 6px; align-items: center; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }
.cal-dots .more { font-size: 9px; color: var(--muted); font-style: normal; width: auto; height: auto; line-height: 1; }

/* ---------- 日历下方：当日详情 + 内联添加 ---------- */
.day-panel { border: 1.5px solid var(--brand-soft); }
.day-panel .row-label { margin-bottom: 6px; }

.add-entry {
  width: 100%;
  border: 1px dashed #c8d3f5;
  background: #fafbff;
  color: var(--brand);
  border-radius: 12px;
  padding: 11px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  margin-top: 8px;
}
.add-entry:active { background: var(--brand-soft); }

.inline-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } }
.inline-form .row-label.mt { margin-top: 14px; }

.form-btns { display: flex; gap: 10px; margin-top: 14px; }
.sub-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 12px;
  padding: 11px;
  font-size: 15px;
  font-family: inherit;
}
.sub-btn.main { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.sub-btn:active { opacity: 0.85; }

/* ---------- 统计 ---------- */
.stat-row { display: flex; gap: 10px; margin-bottom: 12px; }
.stat {
  flex: 1; background: var(--card); border-radius: var(--radius);
  padding: 14px 6px; text-align: center;
  box-shadow: 0 1px 2px rgba(30, 34, 51, 0.04);
}
.stat b { display: block; font-size: 20px; font-weight: 700; }
.stat span { font-size: 12px; color: var(--muted); }

.ms-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: 14px; }
.ms-row .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ms-row .n { flex: 1; }
.ms-row .v { color: var(--muted); font-size: 13px; }

/* ---------- 项目管理 ---------- */
.proj-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.proj-row:last-child { border-bottom: none; }
.proj-row .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.proj-row .n { flex: 1; font-size: 15px; }
.proj-row button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 5px 10px; font-size: 13px; color: var(--muted); font-family: inherit; margin-left: 6px;
}
.proj-row button.danger { color: var(--danger); border-color: #fde2e2; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  max-width: 520px; margin: 0 auto;
}
.tab {
  flex: 1; border: none; background: none; padding: 8px 0 7px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-family: inherit;
}
.tab i { font-style: normal; font-size: 18px; line-height: 1.1; }
.tab.active { color: var(--brand); }

/* ---------- 弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 24, 40, 0.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 14px calc(16px + var(--safe-b));
  max-height: 82vh; overflow-y: auto;
  animation: up 0.2s ease;
}
@keyframes up { from { transform: translateY(30px); opacity: 0.6; } }
.sheet-hd { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-hd b { font-size: 17px; }
.close-btn { border: none; background: #f3f5fb; width: 28px; height: 28px; border-radius: 50%; color: var(--muted); font-family: inherit; }
.sheet-bd { margin-bottom: 12px; }

.color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 4px; }
.color-grid button {
  aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; padding: 0;
}
.color-grid button.on { border-color: var(--text); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(30, 34, 51, 0.9); color: #fff;
  padding: 9px 18px; border-radius: 999px; font-size: 14px; z-index: 60;
  max-width: 80%; text-align: center;
}

/* 小屏（iPhone SE 等）适配 */
@media (max-width: 360px) {
  body { font-size: 14px; }
  .proj-item { font-size: 12px; min-height: 62px; }
  .chips button { padding: 6px 11px; }
}

/* 自定义时间范围 */
.custom-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  animation: fadeIn 0.18s ease;
}
.custom-range .date-input { flex: 1; min-width: 0; }
.custom-range span { color: var(--muted); font-size: 13px; }

/* ---------- 统计页：按项目汇总 ---------- */
.stat-row-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  margin-bottom: 10px; background: var(--card);
  box-shadow: 0 1px 2px rgba(30, 34, 51, 0.04);
}
.sr-hd { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sr-hd .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.sr-hd b { font-size: 15px; }
.sr-hd .sr-n { margin-left: auto; color: var(--muted); font-size: 13px; }
.sr-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.sr-grid > div { text-align: center; background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.sr-grid b { display: block; font-size: 15px; font-weight: 700; }
.sr-grid span { font-size: 11px; color: var(--muted); }
@media (max-width: 360px) {
  .sr-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 登录 / 注册 ---------- */
.auth-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: linear-gradient(160deg, #eaf0ff 0%, #f2f4f9 60%);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--card); border-radius: 20px;
  padding: 26px 22px; box-shadow: 0 12px 40px rgba(30, 34, 51, 0.12);
}
.auth-card h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.4px; }
.auth-sub { margin: 6px 0 18px; color: var(--muted); font-size: 13px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; padding: 9px 0; border: 1px solid var(--line); background: var(--bg);
  border-radius: 12px; font-size: 14px; color: var(--muted); cursor: pointer;
}
.auth-tab.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.auth-title { font-size: 16px; margin: 4px 0 12px; }
.auth-card .text-input { width: 100%; margin-bottom: 12px; }
.auth-code-row { margin-bottom: 12px; }
.auth-code-inline { display: flex; gap: 8px; align-items: center; }
.auth-code-inline .text-input { flex: 1; margin-bottom: 0; }
.auth-code-inline .link-btn { flex: none; white-space: nowrap; }
.auth-links { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; align-items: center; }
.text-btn {
  background: none; border: none; color: var(--brand); font-size: 13px;
  cursor: pointer; padding: 4px;
}

/* ---------- 我的 / 账号页 ---------- */
.danger-btn { background: #fff; color: var(--danger); border: 1px solid var(--danger); margin-top: 14px; }
.danger-btn:active { background: var(--danger); color: #fff; }
.proj-row .n { flex: 1; }

/* ---------- 孩子标签 / chips ---------- */
.rec .t1 .ch {
  display: inline-block; font-size: 11px; font-weight: 700; color: #fff;
  background: var(--brand); border-radius: 6px; padding: 1px 6px; margin-right: 4px;
  vertical-align: middle;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip {
  padding: 7px 14px; border: 1px solid var(--line); background: var(--bg);
  border-radius: 20px; font-size: 14px; color: var(--text); cursor: pointer;
}
.chips .chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.chips .chip:disabled { opacity: 0.5; cursor: default; }

/* ================= 管理后台 ================= */
.admin-login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #eaf0ff 0%, #f2f4f9 60%); padding: 18px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 20px; padding: 28px 24px; box-shadow: 0 12px 40px rgba(30,34,51,0.12); text-align: center; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login-card .text-input { width: 100%; margin-bottom: 12px; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }
.login-card .back { display: inline-block; margin-top: 14px; color: var(--muted); font-size: 13px; text-decoration: none; }

.admin-app { display: flex; min-height: 100vh; }
.admin-side { width: 220px; flex: none; background: #1e2233; color: #fff; padding: 20px 14px; display: flex; flex-direction: column; }
.admin-side .brand { font-size: 18px; font-weight: 700; line-height: 1.3; margin-bottom: 22px; }
.admin-side .brand small { font-weight: 400; color: #9aa3bd; font-size: 12px; }
.admin-side nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.admin-side .nav-i { text-align: left; background: transparent; border: none; color: #c7cde0; padding: 11px 12px; border-radius: 10px; font-size: 15px; cursor: pointer; font-family: inherit; }
.admin-side .nav-i.on, .admin-side .nav-i:hover { background: #2c3148; color: #fff; }
.admin-side .side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid #2c3148; }
.admin-side .who { font-size: 12px; color: #9aa3bd; margin-bottom: 8px; word-break: break-all; }
.admin-side .sub-btn { width: 100%; }

.admin-main { flex: 1; padding: 22px 26px; max-width: 1100px; }
.admin-main h2 { margin: 0 0 16px; font-size: 20px; }
.page .panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel-hd { font-weight: 600; margin-bottom: 12px; font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-card .v { font-size: 26px; font-weight: 800; color: var(--brand); }
.stat-card .k { font-size: 13px; color: var(--muted); margin-top: 4px; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; overflow-x: auto; }
.bar { flex: 1; min-width: 14px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-fill { width: 70%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-d { font-size: 9px; color: var(--muted); margin-top: 4px; transform: rotate(-45deg); white-space: nowrap; }
.bar-n { font-size: 9px; color: var(--text); }

.tbl { width: 100%; border-collapse: collapse; background: var(--card); font-size: 13px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; background: #fafbfe; }
.tbl tbody tr:hover { background: #f7f9ff; }
.lnk { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 13px; padding: 0; font-family: inherit; }
.lnk:disabled { color: var(--muted); cursor: default; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.text-input.sm { width: auto; min-width: 120px; padding: 8px 10px; }
.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 12px; color: var(--muted); font-size: 13px; }

.form-grid { display: grid; gap: 12px; margin-bottom: 16px; }
.set-row { display: grid; grid-template-columns: 200px 1fr; gap: 12px; align-items: center; }
.set-row span { color: var(--muted); font-size: 14px; }
.ustats { margin-top: 12px; color: var(--muted); font-size: 13px; }

@media (max-width: 720px) {
  .admin-app { flex-direction: column; }
  .admin-side { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 12px; }
  .admin-side .brand { margin: 0 12px 0 0; }
  .admin-side nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .admin-side .nav-i { padding: 8px 10px; font-size: 13px; }
  .admin-side .side-foot { width: 100%; border-top: none; padding-top: 8px; display: flex; align-items: center; gap: 10px; }
  .admin-side .who { margin: 0; flex: 1; }
  .admin-main { padding: 16px 14px; }
  .set-row { grid-template-columns: 1fr; gap: 4px; }
}

