:root {
  --bg: #f1f6f4;
  --surface: #ffffff;
  --border: #e2eae6;
  --text: #1e2a26;
  --muted: #6d7d76;
  --primary: #2f9e75;
  --primary-dark: #237a59;
  --primary-soft: #e7f5ee;
  --danger: #d05353;
  --danger-soft: #fdecec;
  --warn: #b9821d;
  --warn-soft: #fdf4e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 45, 36, 0.04), 0 10px 28px rgba(22, 45, 36, 0.06);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary-dark);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
}

/* ---------------------------------------------------------------- 布局 */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

.brand-logo {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: block;
  flex: 0 0 auto;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 右上角的用户名下拉菜单 */
.user-menu {
  position: relative;
}

.user-menu-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 160px;
}

.user-menu-btn > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-btn:hover:not(:disabled) {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.user-menu-caret {
  flex: 0 0 auto;
  opacity: 0.65;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 152px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(22, 45, 36, 0.14);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}

.user-menu-panel[hidden] {
  display: none;
}

.user-menu-panel .menu-item {
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 500;
  text-align: left;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
}

.user-menu-panel .menu-item:hover:not(:disabled) {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.user-menu-panel .menu-item.danger {
  color: var(--danger);
}

.user-menu-panel .menu-item.danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 20px 60px;
}

.grid {
  display: grid;
  gap: 16px;
}

.cols-2 {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* ---------------------------------------------------------------- 卡片 */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card + .card {
  margin-top: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-head h2 {
  font-size: 16px;
}

.card-head .spacer {
  margin-left: auto;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.3px;
}

.stat-value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 3px;
}

.stat-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.down {
  color: var(--primary-dark);
}

.up {
  color: var(--danger);
}

/* ---------------------------------------------------------------- 表单 */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13.5px;
  color: var(--muted);
  font-weight: 500;
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfdfc;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}

.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row > * {
  flex: 1 1 140px;
  min-width: 0;
}

.row > .fixed {
  flex: 0 0 auto;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
}

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  transition: background 0.15s, opacity 0.15s;
}

button:hover:not(:disabled) {
  background: var(--primary-dark);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

button.ghost:hover:not(:disabled) {
  background: #f5f9f7;
}

button.subtle {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font-weight: 500;
}

button.subtle:hover:not(:disabled) {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

button.danger {
  background: var(--danger);
}

button.danger:hover:not(:disabled) {
  background: #b8433f;
}

button.danger-ghost {
  background: #fff;
  border-color: #f0cfcf;
  color: var(--danger);
}

button.danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

button.small {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 8px;
}

button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary-dark);
  text-decoration: underline;
  font-weight: 500;
}

/* 范围切换 */
.segmented {
  display: inline-flex;
  background: #f0f5f2;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
}

.segmented button:hover:not(:disabled) {
  background: #e4ece7;
  color: var(--text);
}

.segmented button.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ---------------------------------------------------------------- 图表 */

.chart {
  width: 100%;
  height: 340px;
}

.chart-empty {
  height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 6px;
  text-align: center;
}

/* ---------------------------------------------------------------- 表格 */

.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: #fafcfb;
}

td.note {
  white-space: normal;
  min-width: 140px;
  color: var(--muted);
}

td.actions {
  text-align: right;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 26px 10px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- 运动记录 */

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 999px;
}

.chip:hover:not(:disabled) {
  border-color: #cfe5da;
  color: var(--text);
  background: #fafcfb;
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.chip.active:hover:not(:disabled) {
  background: var(--primary-dark);
  color: #fff;
}

/* ---------------------------------------------------------------- 目标进度与解读 */

.goal {
  margin-bottom: 16px;
}

.goal-empty {
  color: var(--muted);
  font-size: 13.5px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px dashed var(--border);
}

.goal-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 7px;
}

.goal-range {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.goal-bar {
  height: 10px;
  border-radius: 999px;
  background: #eef4f1;
  overflow: hidden;
}

.goal-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4cb98d, #237a59);
  transition: width 0.4s ease;
}

.goal-foot {
  margin-top: 7px;
  font-size: 13px;
  color: var(--muted);
}

.insight {
  border-left: 3px solid var(--border);
  padding-left: 12px;
}

.insight-ok {
  border-left-color: var(--primary);
}

.insight-warn {
  border-left-color: var(--warn);
}

.insight-info {
  border-left-color: #c8d3ce;
}

.insight-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.insight-ok .insight-title {
  color: var(--primary-dark);
}

.insight-warn .insight-title {
  color: var(--warn);
}

.insight-line {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.65;
}

.insight-line + .insight-line {
  margin-top: 2px;
}

/* ---------------------------------------------------------------- 提示条 */

.alert {
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 14px;
  display: none;
  border: 1px solid transparent;
}

.alert.show {
  display: block;
}

.alert.error {
  background: var(--danger-soft);
  border-color: #f2cfcf;
  color: #9c3835;
}

.alert.ok {
  background: var(--primary-soft);
  border-color: #c8e8d9;
  color: #1f6b4e;
}

.alert.warn {
  background: var(--warn-soft);
  border-color: #f0dcb2;
  color: #8a6114;
}

/* ---------------------------------------------------------------- 登录页 */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #eaf5f0 0%, #f1f6f4 45%, #eef4f8 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(22, 45, 36, 0.1);
  padding: 30px 28px;
}

.login-logo {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: block;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(35, 122, 89, 0.22);
}

.login-card h1 {
  font-size: 23px;
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.login-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 22px;
}

.login-card button[type='submit'] {
  width: 100%;
  padding: 11px;
  margin-top: 4px;
}

/* ---------------------------------------------------------------- 管理台 */

.admin-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 62vh;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px;
}

.user-item {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
  cursor: pointer;
  background: #fff;
  text-align: left;
  width: 100%;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}

.user-item:hover {
  border-color: #cfe5da;
  background: #fafcfb;
}

.user-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.user-item .name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14.5px;
  color: var(--text);
}

.user-item .meta {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 400;
  margin-top: 2px;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 20px;
  font-weight: 600;
  line-height: 1.7;
}

.tag.pending {
  background: #fdf4e3;
  color: #8a6114;
}

.tag.admin {
  background: #e8f0fd;
  color: #2c5aa8;
}

.tag.off {
  background: #f1f1f1;
  color: #7c7c7c;
}

.badge-idle {
  color: var(--muted);
}

/* ---------------------------------------------------------------- 通知 */

#toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: #23332d;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.18s ease-out;
  max-width: 320px;
}

.toast.error {
  background: #a83c39;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  max-width: 400px;
  width: calc(100vw - 40px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(20, 35, 28, 0.35);
}

dialog h3 {
  font-size: 16px;
  margin-bottom: 10px;
}

/* 个人设置弹窗要并排放身高和目标体重，所以宽一点 */
.profile-dialog {
  max-width: 460px;
}

.dialog-split {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.dialog-actions .left {
  margin-right: auto;
}

/* ---------------------------------------------------------------- 响应式 */

@media (max-width: 900px) {
  .admin-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .user-list {
    max-height: 260px;
  }

  .stat-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14.5px;
  }

  .page {
    padding: 16px 12px 48px;
  }

  .topbar-inner {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand {
    font-size: 16px;
  }

  .stat-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .cols-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  /* 字号低于 16px 时 iOS 会自作主张放大页面 */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .card {
    padding: 15px;
    border-radius: 12px;
  }

  .stat {
    padding: 12px;
  }

  .stat-value {
    font-size: 21px;
  }

  .chart,
  .chart-empty {
    height: 260px;
  }

  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .row > * {
    flex: 1 1 auto;
  }

  th,
  td {
    padding: 8px 8px;
  }

  #toast-host {
    right: 12px;
    left: 12px;
    bottom: 12px;
  }

  .toast {
    max-width: none;
  }

  /* 手机上隐藏次要列，避免横向滚动 */
  .hide-sm {
    display: none;
  }
}
