/* ==========================================================================
   BBB — 极简视觉风格
   原则：黑白灰 + 一个强调色；大量留白；无多余装饰；一眼看懂。
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-elevated: #f7f7f6;
  --border: #e5e4e1;
  --text: #14140f;
  --text-dim: #6b6a64;
  --text-faint: #a3a29b;
  --accent: #d8672b;      /* 唯一强调色：暖橙，用于行动点 */
  --accent-weak: #fbe7d8;
  --danger: #b8442e;
  --success: #3f7d5c;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,20,15,0.04), 0 4px 16px rgba(20,20,15,0.04);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131311;
    --bg-elevated: #1c1b18;
    --border: #2c2b27;
    --text: #f2f1ec;
    --text-dim: #a3a29b;
    --text-faint: #6b6a64;
    --accent: #e37a3f;
    --accent-weak: #3a2a1c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input {
  font-family: inherit;
  color: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- 顶部区 ---------- */
.top-bar {
  padding: 28px 20px 4px;
}

.top-date {
  font-size: 14px;
  color: var(--text-dim);
}

.top-week {
  font-size: 13px;
  color: var(--text-faint);
  margin-top: 2px;
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  margin-left: 6px;
  font-weight: 600;
}

/* ---------- 视图容器 ---------- */
.view {
  flex: 1;
  display: none;
  flex-direction: column;
  padding: 0 20px 100px;
}
.view.active { display: flex; }

/* ---------- 首页大卡片 ---------- */
.hero {
  margin-top: 18px;
}

.hero-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.hero-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.hero-sub {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-dim);
}

.hero-note {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text-dim);
}

/* ---------- 主行动按钮 ---------- */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 18px;
  margin-top: 24px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
}
.btn-primary:active { opacity: 0.8; }

.btn-primary.accent { background: var(--accent); color: #fff; }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  margin-top: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
}

.btn-ghost {
  padding: 10px 14px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- 动作/热身列表 ---------- */
.exercise-list {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.exercise-row {
  background: var(--bg);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
}

.exercise-row .meta {
  font-size: 13px;
  color: var(--text-faint);
  margin-top: 2px;
}

.check-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.check-dot.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
  font-size: 13px;
}

/* ---------- 训练进行页 ---------- */
.workout-progress {
  font-size: 13px;
  color: var(--text-faint);
  margin-top: 20px;
}

.exercise-focus {
  margin-top: 8px;
}

.exercise-focus .name {
  font-size: 26px;
  font-weight: 700;
}

.exercise-focus .target {
  margin-top: 6px;
  font-size: 15px;
  color: var(--text-dim);
}

.exercise-focus .note {
  margin-top: 10px;
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-weak);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.set-tracker {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.set-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
}

.set-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.set-row .set-idx {
  font-size: 13px;
  color: var(--text-faint);
  font-weight: 600;
}

.set-row.done { opacity: 0.55; }

.set-fields {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stepper button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stepper input {
  width: 50px;
  text-align: center;
  padding: 5px 2px;
  font-size: 14.5px;
  font-weight: 600;
}

.stepper .unit {
  font-size: 12px;
  color: var(--text-faint);
}

.set-complete-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.set-row.done .set-complete-btn {
  background: var(--success);
}

/* ---------- 休息计时器 ---------- */
.rest-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  max-width: 480px;
  margin: 0 auto;
}
.rest-overlay.active { display: flex; }

.rest-label {
  font-size: 15px;
  color: var(--text-dim);
}

.rest-time {
  font-size: 72px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 14px 0 28px;
}

/* ---------- 底部导航 ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  font-size: 11px;
  color: var(--text-faint);
}
.tab-item.active { color: var(--text); }
.tab-item .tab-icon { font-size: 19px; }

/* ---------- 进度页 ---------- */
.metric-tabs {
  display: flex;
  gap: 6px;
  margin-top: 18px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.metric-tabs::-webkit-scrollbar { display: none; }

.metric-chip {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 13.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.metric-chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.chart-wrap {
  margin-top: 20px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-summary {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.chart-summary .value {
  font-size: 24px;
  font-weight: 700;
}
.chart-summary .delta {
  font-size: 13px;
  color: var(--success);
  align-self: flex-end;
}
.chart-summary .delta.down { color: var(--danger); }

.session-list {
  margin-top: 26px;
}

.session-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}
.session-item .d { color: var(--text-dim); }

/* ---------- 表单 / 设置 ---------- */
.field {
  margin-top: 16px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border-radius: var(--radius-sm);
}

.section-title {
  margin-top: 30px;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.diet-result {
  margin-top: 18px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
}
.diet-result .row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14.5px;
}
.diet-result .row .k { color: var(--text-dim); }
.diet-result .row .v { font-weight: 600; }

.note-list {
  margin-top: 14px;
  padding-left: 18px;
  font-size: 13.5px;
  color: var(--text-dim);
}
.note-list li { margin-bottom: 6px; }

/* ---------- 完成页 ---------- */
.done-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
}
.done-screen .emoji { font-size: 48px; margin-bottom: 10px; }
.done-screen h2 { margin: 0 0 8px; }
.done-screen p { color: var(--text-dim); margin: 0 0 4px; }

/* ---------- 顶部返回条 ---------- */
.flow-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
}
.flow-bar button { font-size: 15px; color: var(--text-dim); }

/* ---------- 提示 toast ---------- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 通用：虚线新建按钮 ---------- */
.btn-dashed {
  width: 100%;
  padding: 14px;
  margin-top: 6px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

/* ---------- 训练模板列表 ---------- */
.tpl-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
}
.tpl-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.tpl-card-name {
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.3;
}
.tpl-activate-btn {
  flex-shrink: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}
.tpl-card-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}
.tpl-card-actions {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.tpl-card-actions button {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ---------- 模板编辑：一周安排 ---------- */
.day-row {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.day-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.day-row-label {
  font-size: 14.5px;
  font-weight: 700;
  width: 44px;
  flex-shrink: 0;
}
.day-type-seg {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.day-type-btn {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.day-type-btn.active {
  background: var(--text);
  color: var(--bg);
}
.day-row-detail {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.day-title-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13.5px;
  background: var(--bg);
}
.day-edit-link {
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- 某一天的动作编辑 ---------- */
.ex-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.ex-edit-move {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.ex-edit-move button {
  width: 22px;
  height: 18px;
  font-size: 10px;
  color: var(--text-faint);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  line-height: 1;
}
.ex-edit-move button:disabled { opacity: 0.3; }
.ex-edit-main { flex: 1; min-width: 0; }
.ex-edit-name { font-size: 14.5px; font-weight: 700; }
.ex-edit-fields {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-faint);
  flex-wrap: wrap;
}
.ex-edit-fields input {
  text-align: center;
  padding: 4px 2px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ex-edit-remove {
  color: var(--text-faint);
  flex-shrink: 0;
  padding: 6px;
  font-size: 15px;
}

/* ---------- 动作库选择弹层 ---------- */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,20,15,0.4);
  display: none;
  align-items: flex-end;
  z-index: 70;
  max-width: 480px;
  margin: 0 auto;
}
.picker-overlay.active { display: flex; }
.picker-sheet {
  width: 100%;
  max-height: 78vh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}
.picker-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.picker-custom-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.picker-custom-row input {
  flex: 1;
  padding: 10px 12px;
  font-size: 13.5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.picker-custom-row button {
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  background: var(--text);
  border-radius: var(--radius-sm);
}
.picker-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
}
.picker-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  padding: 13px 14px;
  font-size: 14.5px;
  text-align: left;
}
.picker-row .meta {
  font-size: 12.5px;
  color: var(--text-faint);
}

.hidden { display: none !important; }
