/* 工作台 · iOS 分组式设计系统 */

:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --card-2: #F5F5F7;
  --text: #1C1C1E;
  --text-2: #8E8E93;
  --text-3: #AEAEB2;
  --accent: #0A84FF;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --success: #34C759;
  --success-soft: rgba(52, 199, 89, 0.14);
  --danger: #FF3B30;
  --border: #E5E5EA;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius-card: 14px;
  --radius-ctrl: 10px;
  --radius-pill: 999px;
  --topbar-h: 56px;
  --sidebar-w: 236px;
  --max-main: 1080px;
}

[data-theme="dark"] {
  --bg: #000000;
  --card: #1C1C1E;
  --card-2: #2C2C2E;
  --text: #FFFFFF;
  --text-2: #98989E;
  --text-3: #636366;
  --accent: #0A84FF;
  --accent-soft: rgba(10, 132, 255, 0.24);
  --success: #32D74B;
  --success-soft: rgba(50, 215, 75, 0.18);
  --danger: #FF453A;
  --border: #3A3A3C;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, "PingFang SC", "SF Pro Text", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
ul { list-style: none; }

.icon { width: 22px; height: 22px; flex-shrink: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: var(--topbar-h); max-width: 1440px; margin: 0 auto;
  padding: 0 20px; display: flex; align-items: center; gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hamburger { display: none; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.motto { flex: 1; text-align: center; color: var(--text-2); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-ctrl);
  display: flex; align-items: center; justify-content: center; color: var(--text-2);
  transition: background 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.theme-icon { display: none; }
[data-theme="light"] .theme-moon { display: block; }
[data-theme="dark"] .theme-sun { display: block; }

/* ---------- 侧边栏 ---------- */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.25s ease;
}
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 18px 14px; }
.sidebar-date { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.checkin-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-ctrl); padding: 10px 12px; font-size: 14px; font-weight: 600;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.checkin-btn:hover { opacity: 0.9; }
.checkin-btn:active { transform: scale(0.97); }
.checkin-btn.done { background: var(--success); color: #fff; }
.streak { margin-top: 8px; text-align: center; font-size: 12px; color: var(--text-2); }
.nav { margin-top: 18px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius-ctrl);
  font-size: 14px; color: var(--text); text-align: left;
  transition: background 0.15s ease;
}
.nav-item .icon { color: var(--text-2); }
.nav-item:hover { background: var(--card-2); }
.nav-item:active { transform: scale(0.98); }
.nav-item.active { background: var(--card-2); font-weight: 600; }
.nav-item.active .icon { color: var(--accent); }
.sidebar-foot {
  padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.scrim {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.35);
}

/* ---------- 主内容 ---------- */
.main { flex: 1; min-width: 0; padding: 28px 36px 60px; }
.view { display: none; max-width: var(--max-main); margin: 0 auto; }
.view.active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: 22px; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); margin-bottom: 6px; }
.greeting { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.page-desc { margin-top: 6px; font-size: 14px; color: var(--text-2); }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card {
  background: var(--card); border-radius: var(--radius-card);
  padding: 18px; box-shadow: var(--shadow); cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.stat-card:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07); }
.stat-card:active { transform: scale(0.98); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.stat-label { font-size: 11px; font-weight: 600; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }
.stat-title { margin-top: 12px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.stat-value { margin-top: 4px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value strong { color: var(--text); }
.stat-unit { font-size: 13px; font-weight: 600; color: var(--text-3); margin-left: 2px; }
.stat-note { margin-top: 10px; font-size: 12px; color: var(--text-2); }

/* ---------- 进度条 ---------- */
.progress { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; margin-top: 12px; }
.progress-lg { height: 8px; border-radius: 4px; margin: 14px 0 20px; }
.progress-fill {
  display: block; height: 100%; width: 0;
  border-radius: inherit; background: var(--accent);
  transition: width 0.25s ease;
}

/* ---------- 分组卡片 ---------- */
.home-group { margin-top: 26px; }
.group-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 10px; padding: 0 4px; }
.group-head h3 { font-size: 15px; font-weight: 600; }
.group-card {
  background: var(--card); border-radius: var(--radius-card);
  box-shadow: var(--shadow); overflow: hidden;
}
.group-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.group-row:last-child { border-bottom: none; }
.group-row .g-time { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 52px; }
.group-row .g-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row .g-side { color: var(--text-2); font-size: 12px; }
.text-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--accent); padding: 4px; border-radius: 6px; }
.text-btn .icon { width: 14px; height: 14px; }
.text-btn:hover { background: var(--accent-soft); }

/* ---------- 按钮与表单 ---------- */
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff;
  border-radius: var(--radius-ctrl); padding: 9px 16px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.primary-btn:hover { opacity: 0.9; }
.primary-btn:active { transform: scale(0.97); }
.pill-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-pill); padding: 9px 18px; font-size: 14px; font-weight: 600;
  transition: background 0.15s ease, transform 0.1s ease;
}
.pill-btn:hover { background: var(--card-2); }
.pill-btn:active { transform: scale(0.96); }
.ghost-btn { color: var(--text-2); font-size: 13px; padding: 6px 10px; border-radius: 8px; }
.ghost-btn:hover { color: var(--danger); background: rgba(255, 59, 48, 0.08); }

input[type="text"], input[type="number"], textarea {
  width: 100%; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-ctrl); padding: 9px 12px; font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-hint { margin-top: 8px; font-size: 12px; color: var(--danger); min-height: 0; }
.form-hint.ok { color: var(--success); }

.todo-form, .book-form { display: flex; gap: 10px; }
.todo-form input, .book-form input { flex: 1; }
.inline-form { display: flex; align-items: center; gap: 8px; }
.inline-form input { flex: 1; }
.inline-form .unit { color: var(--text-2); font-size: 13px; }

/* ---------- 空状态 ---------- */
.empty-state { padding: 40px 20px; text-align: center; }
.empty-state p { font-size: 15px; font-weight: 600; color: var(--text-2); }
.empty-state span { display: block; margin-top: 6px; font-size: 13px; color: var(--text-3); }

/* ---------- 待办 ---------- */
.todo-list { background: var(--card); border-radius: var(--radius-card); box-shadow: var(--shadow); overflow: hidden; }
.todo-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.todo-item:last-child { border-bottom: none; }
.todo-check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--text-3); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: transparent;
  transition: all 0.15s ease;
}
.todo-item.done .todo-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.todo-item .icon { width: 14px; height: 14px; }
.todo-text { flex: 1; font-size: 14px; }
.todo-item.done .todo-text { color: var(--text-3); text-decoration: line-through; }
.todo-del { color: var(--text-3); width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.todo-del:hover { color: var(--danger); background: rgba(255, 59, 48, 0.08); }
.todo-del .icon { width: 16px; height: 16px; }

/* ---------- 喝水 ---------- */
.water-card {
  background: var(--card); border-radius: var(--radius-card);
  box-shadow: var(--shadow); max-width: 460px; margin: 0 auto;
  padding: 32px 28px; text-align: center;
}
.water-amount { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; }
.water-amount .stat-unit { font-size: 15px; }
.water-target { margin-top: 6px; font-size: 13px; color: var(--text-2); }
.water-actions { display: flex; justify-content: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.water-card .ghost-btn { margin-top: 14px; }

/* ---------- 健身 ---------- */
.fit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.fit-card {
  background: var(--card); border-radius: var(--radius-card);
  box-shadow: var(--shadow); padding: 18px;
}
.fit-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.fit-card-head h3 { font-size: 15px; font-weight: 600; }
.fit-badge { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--card-2); padding: 4px 10px; border-radius: var(--radius-pill); }
.fit-badge.done { color: var(--success); background: var(--success-soft); }
.fit-today { font-size: 13px; color: var(--text-2); }
.fit-kcal { font-size: 14px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.macro-form { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 10px; align-items: end; }
.macro-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.macro-bars { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.macro-bar-row { font-size: 12px; color: var(--text-2); }
.macro-bar-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.macro-bar { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; margin-top: 4px; }
.macro-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.25s ease; }
.trend { margin-top: 16px; }
.trend svg { width: 100%; height: 120px; display: block; }
.trend-empty { text-align: center; font-size: 12px; color: var(--text-3); padding: 16px 0; }

/* ---------- 日历 ---------- */
.cal-head { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 4px 0 18px; }
.cal-title { font-size: 17px; font-weight: 700; min-width: 140px; text-align: center; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  background: var(--card); border-radius: var(--radius-card);
  box-shadow: var(--shadow); padding: 14px;
}
.cal-week { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 6px 0; }
.cal-cell {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: var(--radius-ctrl); font-size: 14px; color: var(--text);
  position: relative; transition: background 0.15s ease;
}
.cal-cell:hover { background: var(--card-2); }
.cal-cell.out { color: var(--text-3); opacity: 0.45; }
.cal-cell.today { color: var(--accent); font-weight: 700; }
.cal-cell.selected { background: var(--accent-soft); font-weight: 700; }
.cal-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); position: absolute; bottom: 7px; }
.cal-day-panel { margin-top: 16px; background: var(--card); border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 18px; }
.cal-day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-day-head h3 { font-size: 16px; font-weight: 700; }
.cal-form { display: grid; grid-template-columns: 120px 1fr auto auto; gap: 8px; margin-bottom: 14px; }
.cal-day-list { display: flex; flex-direction: column; }
.cal-day-list .cal-item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
.cal-day-list .cal-item:last-child { border-bottom: none; }
.cal-item .t { color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 52px; }
.cal-item .title { flex: 1; }
.cal-item .ops { display: flex; gap: 4px; }
.cal-item .ops .icon-btn { width: 30px; height: 30px; }
.cal-item .ops .icon-btn .icon { width: 15px; height: 15px; }

/* ---------- 复盘 ---------- */
.review-box { min-height: 200px; border-radius: var(--radius-card); padding: 16px; line-height: 1.7; resize: vertical; }
.save-hint { margin-top: 8px; font-size: 12px; color: var(--text-3); }
.history-row { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.history-row:last-child { border-bottom: none; }
.history-row .h-date { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.history-row .h-text { font-size: 14px; line-height: 1.6; color: var(--text); white-space: pre-wrap; }

/* ---------- 书架 ---------- */
.book-list { background: var(--card); border-radius: var(--radius-card); box-shadow: var(--shadow); overflow: hidden; }
.book-item { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.book-item:last-child { border-bottom: none; }
.book-top { display: flex; align-items: center; gap: 12px; }
.book-title { flex: 1; font-size: 14px; font-weight: 600; }
.book-title small { display: block; font-weight: 400; color: var(--text-2); margin-top: 2px; }
.book-status { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent); }
.book-status.done { background: var(--success-soft); color: var(--success); }
.book-progress { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.book-progress input[type="range"] { flex: 1; accent-color: var(--accent); }
.book-progress span { font-size: 12px; color: var(--text-2); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 每日要闻 ---------- */
.news-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.news-date { font-size: 13px; color: var(--text-2); }
.news-list { display: flex; flex-direction: column; }
.news-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  background: var(--card); text-decoration: none; color: var(--text);
  transition: background 0.15s ease;
}
.news-item:last-child { border-bottom: none; }
.news-item:hover { background: var(--card-2); }
.news-num { font-size: 13px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; min-width: 22px; }
.news-body { flex: 1; min-width: 0; }
.news-title { font-size: 14px; line-height: 1.5; }
.news-src { margin-top: 4px; font-size: 11px; color: var(--text-3); }
.news-skeleton { height: 16px; border-radius: 6px; background: linear-gradient(90deg, var(--card-2) 25%, var(--card) 50%, var(--card-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
#homeNews .news-item { padding: 12px 16px; }
@media (prefers-reduced-motion: reduce) { .news-skeleton { animation: none; } }

/* ---------- 保存失败横幅 ---------- */
.save-banner {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 90; background: var(--danger); color: #fff;
  padding: 10px 18px; border-radius: var(--radius-ctrl);
  font-size: 13px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .fit-grid { grid-template-columns: 1fr; }
  .macro-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .hamburger { display: flex; }
  .motto { display: none; }
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 60;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 20px 16px 48px; }
  .greeting { font-size: 24px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cal-form { grid-template-columns: 1fr; }
  .macro-form { grid-template-columns: 1fr; }
  .todo-form, .book-form { flex-direction: column; }
  .todo-form .primary-btn, .book-form .primary-btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: rgba(28, 28, 30, 0.92); color: #fff;
  padding: 9px 16px; border-radius: var(--radius-ctrl);
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease; z-index: 95;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-theme="dark"] .toast { background: rgba(60, 60, 62, 0.95); }

/* ---------- 体重趋势图 ---------- */
.trend polyline { stroke: var(--accent); }
.trend circle { fill: var(--accent); }
.trend-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); margin-top: 4px; }
