/* ============================================================
   健身记录 App — Direction B · MOMENTUM 电光绿亮场
   近白底 + 电光绿强调色 + 数据仪表盘。
   移动优先：默认底部标签栏；>=768px 切换为顶部导航 + 居中容器。
   ============================================================ */

* { box-sizing: border-box; }

:root {
  /* —— Direction B 设计 token —— */
  --bg: #F4F6F1;
  --surface: #FFFFFF;
  --field: #F7F9F3;
  --line: #E6E9E0;
  --text: #0F1310;
  --muted: #6B7367;
  --faint: #98A193;

  --accent: #1FBF5F;
  --accent-deep: #16A64E;
  --accent-ink: #04170C;
  --accent-soft: #E6F7EC;

  --danger: #D64545;
  --danger-soft: #FBECEC;

  --toast-bg: #0F2E1C;
  --toast-fg: #E9FCEF;

  --radius: 12px;
  --radius-sm: 10px;
  --nav-h: 62px;
  --shadow: 0 10px 30px -20px rgba(15, 19, 16, .35);
}

html { -webkit-text-size-adjust: 100%; }

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

/* 通用图标尺寸 */
.ic { width: 22px; height: 22px; display: block; }

/* ---------- 内容容器（手机：底部留出标签栏高度 + iOS 安全区） ---------- */
main {
  padding: 14px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  max-width: 820px;
  margin-inline: auto;
}

h1 { font-size: 22px; font-weight: 800; letter-spacing: -.4px; margin: 0; }
h3 { font-size: 16px; font-weight: 800; margin: 0 0 8px; }
small { color: var(--muted); }

/* ---------- 页面标题 ---------- */
.page-head { margin: 4px 0 14px; }
.page-head p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* ---------- 底部标签栏（手机默认） ---------- */
#tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
  z-index: 10;
}
/* 修复：ID 选择器的 display:flex 会盖过 UA 的 [hidden]，此处显式兜底 */
#tabs[hidden] { display: none; }
#tabs button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 0;
  border: 0;
  background: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--faint);
  cursor: pointer;
  border-radius: 10px;
  transition: color .15s ease, background .15s ease;
}
#tabs button .ic { width: 22px; height: 22px; }
#tabs button.active { color: var(--accent-deep); }

/* ---------- 首屏激励头部 ---------- */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 4px 0 16px;
}
.greet { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.day-name { font-size: 25px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; }
.streak {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700;
  padding: 7px 11px; border-radius: 999px;
  background: var(--accent-soft); color: #0E8A47;
  white-space: nowrap;
}
.streak .ic { width: 14px; height: 14px; }
.streak.muted-streak { background: var(--field); color: var(--muted); }

/* ---------- 今日进度条 ---------- */
.bar-sec { margin: 0 0 14px; }
.progress-label { font-size: 12.5px; font-weight: 700; letter-spacing: .02em; margin-bottom: 8px; }
.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i {
  display: block; height: 100%; width: 0;
  background: var(--accent); border-radius: 999px;
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}
.bar-meta {
  display: flex; justify-content: space-between;
  font-size: 11.5px; font-weight: 700; color: var(--faint);
  margin-top: 6px;
}

/* ---------- 三格数据仪表盘 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 8px;
  text-align: center;
}
.stat b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -.4px; }
.stat span { font-size: 10px; font-weight: 700; color: var(--faint); }

/* ---------- 训练日 chips（横向可滚动，容纳真实长名） ---------- */
.chips {
  display: flex; gap: 8px;
  margin: 0 0 14px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px; font-weight: 700; color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.chip.active {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent);
}

/* ---------- 日期行 ---------- */
.date-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.date-row label { font-size: 13px; font-weight: 700; color: var(--muted); }

/* ---------- 卡片 ---------- */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--surface);
}
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- 动作卡 ---------- */
.ex {
  margin-bottom: 12px;
  padding: 13px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.ex-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ex-name { font-weight: 800; font-size: 15px; }
.ex-sub { font-size: 11.5px; font-weight: 600; color: var(--faint); }
.ex-check {
  flex: none;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-deep);
  font-size: 13px; font-weight: 800;
}
.ex-done .ex-name { opacity: .5; text-decoration: line-through; }

/* ---------- 组输入行 ---------- */
.set-row { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.set-no { font-size: 12px; font-weight: 700; color: var(--faint); width: 44px; flex: none; }
.set-field {
  flex: 1;
  display: flex; align-items: center; gap: 6px;
  height: 42px; padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--field);
  border: 1px solid var(--line);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.set-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.set-field input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  height: 100%; font-size: 16px; font-weight: 800;
  color: inherit; font-family: inherit;
}
.set-field input:focus { outline: none; }
.set-field .unit { font-size: 11px; font-weight: 600; color: var(--faint); }

/* 去掉数字输入框的原生步进箭头，保持干净 */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- 表单控件 ---------- */
input, select, button { font-family: inherit; }
input.control, select, input[type=password] {
  padding: 9px 11px;
  min-height: 42px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
}
input[type=password] { width: 100%; }
button { min-height: 40px; cursor: pointer; }

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  min-height: 44px;
  font-size: 16px;
  font-weight: 800;
  transition: background .15s ease, transform .1s ease;
}
button.primary:hover { background: var(--accent-deep); }
button.primary:active { transform: scale(.98); }
button.primary:disabled { opacity: .6; cursor: default; }
button.primary.big { display: block; width: 100%; min-height: 52px; font-size: 17px; border-radius: var(--radius); }

button.btn-del {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}
button.btn-del:hover { background: var(--danger-soft); border-color: var(--danger); }

/* 保存成功脉冲动效 */
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 191, 95, .5); }
  100% { box-shadow: 0 0 0 16px rgba(31, 191, 95, 0); }
}
.pulse { animation: pulse .6s ease-out; }

/* ---------- 计划列表 ---------- */
.plan-card h3 { margin-bottom: 10px; }
.plan-list { margin: 0; padding-left: 18px; }
.plan-list li { margin-bottom: 7px; }
.pe-name { font-weight: 700; }
.pe-meta { display: block; font-size: 12px; color: var(--faint); }

/* ---------- 历史记录 ---------- */
.hist-card { padding: 13px 14px; }
.hist-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hist-date { font-weight: 800; font-size: 15px; }
.hist-day { font-size: 12px; color: var(--muted); font-weight: 600; }
.hist-detail { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.hist-vol { font-size: 12px; font-weight: 700; color: var(--accent-deep); margin-bottom: 6px; }
.hist-ex { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin: 3px 0; }
.hist-ex-name { font-weight: 700; }
.hist-ex-sets { color: var(--muted); text-align: right; }
.loading-txt { color: var(--faint); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; font-size: 14px; }

/* ---------- 图表 ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; width: 100% !important; max-width: 100%; height: auto; }
.card canvas { display: block; width: 100% !important; max-width: 100%; height: auto; }

/* ---------- 每周打卡网格 ---------- */
.checkin-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.day-cell {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.day-cell .dc-w { font-size: 11px; font-weight: 700; color: var(--muted); }
.day-cell .dc-mark { font-size: 15px; font-weight: 800; color: var(--accent); min-height: 18px; }
.day-cell .dc-date { font-size: 10px; color: var(--faint); }
.day-cell.done { background: var(--accent-soft); border-color: var(--accent); }
.day-cell.today { box-shadow: 0 0 0 2px var(--accent) inset; }

/* ---------- 登录页 ---------- */
.login-main { display: flex; align-items: center; justify-content: center; min-height: 82vh; }
.login-card { width: 100%; max-width: 400px; text-align: center; padding: 26px 22px; }
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 12px;
  border-radius: 16px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-deep);
}
.login-logo .ic { width: 30px; height: 30px; }
.login-title { font-size: 22px; margin: 0; }
.login-sub { color: var(--muted); font-size: 13px; margin: 6px 0 18px; }
.login-card input[type=password] { margin-bottom: 12px; }
.load-fail { text-align: center; padding: 26px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--nav-h) + 22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 9px;
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--toast-bg); color: var(--toast-fg);
  font-size: 13.5px; font-weight: 700;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .25s cubic-bezier(.2, .8, .2, 1);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.toast-error { background: var(--danger); color: #fff; }
.toast .toast-dot {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 800;
}
.toast.toast-error .toast-dot { background: rgba(255, 255, 255, .25); }

/* ---------- 确认弹窗 ---------- */
.dialog-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 19, 16, .35);
  opacity: 0; transition: opacity .16s ease;
  z-index: 60;
  padding: 20px;
}
.dialog-overlay.show { opacity: 1; }
.dialog {
  width: 100%; max-width: 340px;
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .5);
  transform: translateY(10px) scale(.98);
  transition: transform .16s ease;
}
.dialog-overlay.show .dialog { transform: none; }
.dialog-msg { margin: 0 0 18px; font-size: 15px; font-weight: 600; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-ghost, .btn-danger {
  min-height: 42px; padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  cursor: pointer;
}
.btn-ghost { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.btn-danger { border: 0; background: var(--danger); color: #fff; }

/* ============================================================
   桌面端 >= 768px
   ============================================================ */
@media (min-width: 768px) {
  main { padding: 84px 20px 48px; }

  /* 标签栏：从底部挪到顶部并居中 */
  #tabs {
    top: 0; bottom: auto;
    padding: 0 0 0;
    justify-content: center;
    gap: 6px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
  }
  #tabs button {
    flex: 0 1 120px;
    flex-direction: row;
    gap: 8px;
    min-height: 56px;
    margin: 6px 2px;
    font-size: 14px;
  }
  #tabs button.active { background: var(--accent-soft); }

  input.control, select { width: auto; }
  input#pw { width: 100%; }
}

/* ============================================================
   无障碍：尊重「减少动态效果」
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
