/* ========== 基础重置 & 变量 ========== */
:root {
  --primary: #4CAF50;
  --primary-light: #81C784;
  --primary-dark: #388E3C;
  --danger: #f44336;
  --danger-light: #ff7961;
  --warning: #FF9800;
  --bg: #f0f4f0;
  --card-bg: #ffffff;
  --text: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.25s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ========== 通用组件 ========== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.btn:active { transform: translateY(0); }

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

.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }

.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; background: var(--card-bg); border: 1px solid var(--border); font-size: 14px; }
.btn-block { width: 100%; }

.btn-add {
  width: 100%;
  background: transparent;
  border: 2px dashed var(--border);
  color: var(--text-secondary);
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-top: 12px;
}
.btn-add:hover { border-color: var(--primary); color: var(--primary); background: rgba(76,175,80,0.04); }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: var(--transition);
  outline: none;
  background: #fff;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(76,175,80,0.1); }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

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

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  background: #f5f5f5;
  color: var(--text-secondary);
  margin-right: 4px;
  margin-top: 2px;
}
.calorie-tag { background: #FFF3E0; color: #E65100; }
.calorie-tag.burned { background: #E8F5E9; color: #2E7D32; }
.time-tag { background: #E3F2FD; color: #1565C0; }
.note-tag { background: #F3E5F5; color: #7B1FA2; }
.intensity-tag.intensity-low { background: #E8F5E9; color: #2E7D32; }
.intensity-tag.intensity-medium { background: #FFF8E1; color: #F57F17; }
.intensity-tag.intensity-high { background: #FFEBEE; color: #C62828; }

/* ========== 认证页 ========== */
#authPage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 50%, #A5D6A7 100%);
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.auth-footer a {
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: none;
  transition: var(--transition);
}

.auth-footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.police-record {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: none;
}

.police-record:hover {
  color: var(--primary);
  text-decoration: underline;
}

.police-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  flex-shrink: 0;
}

#mainPage {
  display: none;
}

.auth-container {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.12);
}

.auth-logo {
  text-align: center;
  margin-bottom: 30px;
}

.logo-icon {
  font-size: 56px;
  margin-bottom: 12px;
}

.auth-logo h1 {
  font-size: 24px;
  color: var(--primary-dark);
  margin-bottom: 6px;
}

.auth-logo p {
  color: var(--text-muted);
  font-size: 14px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--primary);
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--primary);
}

.auth-tab.active {
  background: var(--primary);
  color: #fff;
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-error { color: var(--danger); font-size: 13px; margin-top: 10px; text-align: center; min-height: 20px; }

.auth-link {
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
}

.auth-link a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}

.auth-link a:hover {
  text-decoration: underline;
}

.code-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.code-row input {
  flex: 1;
}

.code-row .btn {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 12px;
}

/* ========== 设置模态框 ========== */
.settings-section {
  margin-bottom: 16px;
}

.settings-section h4 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text);
}

.settings-divider {
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.settings-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ========== 主页面头部 ========== */
.header {
  background: #fff;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.logo-icon-small { font-size: 24px; }
.app-title { font-size: 18px; font-weight: 600; color: var(--primary-dark); }

.header-right { display: flex; align-items: center; gap: 12px; }
.user-info { font-size: 14px; color: var(--text-secondary); }

/* ========== 主布局 ========== */
.main-layout {
  display: flex;
  gap: 20px;
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

.content-area { flex: 1; min-width: 0; }
.sidebar { width: 320px; flex-shrink: 0; }

/* ========== 日期栏 ========== */
.date-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 16px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.date-display {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.date-input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  cursor: pointer;
}
.date-input:focus { border-color: var(--primary); }

.weekday {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ========== 体重+血压双栏 ========== */
.health-metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* ========== 体重卡片 ========== */
.weight-card .card-header { margin-bottom: 10px; }

.weight-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.weight-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: var(--transition);
}
.weight-input:focus { border-color: var(--primary); }

.weight-unit {
  font-size: 16px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ========== 血压卡片 ========== */
.blood-pressure-card .card-header { margin-bottom: 10px; }

.bp-input-row {
  display: flex;
  gap: 12px;
}

.bp-input-group {
  flex: 1;
}

.bp-input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.bp-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bp-input {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: var(--transition);
  min-width: 0;
}
.bp-input:focus { border-color: var(--primary); }

.bp-unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* ========== 双栏日记 ========== */
.diary-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.diet-card, .exercise-card {
  min-height: 300px;
}

.calorie-badge {
  padding: 4px 12px;
  background: #FFF3E0;
  color: #E65100;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.calorie-badge.burned {
  background: #E8F5E9;
  color: #2E7D32;
}

/* ========== 餐别Tab ========== */
.meal-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.meal-tab {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
}
.meal-tab:hover { border-color: var(--primary-light); color: var(--primary); }
.meal-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 餐别标签 */
.meal-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: #E8F5E9;
  color: #2E7D32;
  margin-right: 6px;
  vertical-align: middle;
}

/* ========== 记录列表 ========== */
.record-list { min-height: 100px; }

.record-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: var(--transition);
}
.record-item:hover { border-color: var(--primary-light); background: rgba(76,175,80,0.02); }

.record-name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.record-meta { display: flex; flex-wrap: wrap; gap: 2px; }

.record-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* ========== 侧边栏 ========== */
.stats-card .stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f5f5f5;
}
.stats-card .stat-item:last-child { border-bottom: none; }

.stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-value { font-size: 18px; font-weight: 700; color: var(--primary-dark); }
.stat-value.burned { color: #E65100; }
.stat-value span { font-size: 12px; font-weight: 400; color: var(--text-muted); }

.weight-trend-card { min-height: 200px; }

.chart-container {
  min-height: 120px;
  display: flex;
  flex-direction: column;
}

.weight-svg {
  width: 100%;
  height: 100px;
  border-bottom: 1px solid #eee;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.history-list { max-height: 300px; overflow-y: auto; }

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
}
.history-item:hover { background: #f5f5f5; }
.history-item.active { background: #E8F5E9; color: var(--primary-dark); font-weight: 600; }
.history-date { font-weight: 500; flex-shrink: 0; }
.history-metrics {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.history-weight { color: var(--text-secondary); white-space: nowrap; }
.history-bp { color: var(--text-muted); white-space: nowrap; font-size: 13px; }
.history-item.active .history-weight { color: var(--primary-dark); }
.history-item.active .history-bp { color: var(--primary-dark); opacity: 0.8; }

/* ========== 模态框 ========== */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.active { display: flex; }

.modal-content {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 460px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 0;
}

.modal-header h3 { font-size: 18px; }

.modal-close {
  width: 32px; height: 32px;
  border: none; background: #f5f5f5;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.modal-close:hover { background: #e0e0e0; }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 20px 20px;
}

.intensity-group {
  display: flex;
  gap: 12px;
}

.intensity-option {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-secondary);
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: #fff;
  padding: 12px 28px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 2000;
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); }

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
  .main-layout {
    flex-direction: column;
    padding: 12px;
  }
  .sidebar {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .sidebar .card { margin-bottom: 0; }
  .history-card { grid-column: 1 / -1; }
}

@media (max-width: 768px) {
  .diary-columns { grid-template-columns: 1fr; }
  .health-metrics-row { grid-template-columns: 1fr; }

  .sidebar { grid-template-columns: 1fr; }

  .header { padding: 10px 16px; }
  .app-title { font-size: 16px; }
  .user-info { display: none; }

  .auth-container { padding: 24px; margin: 16px; }

  .modal-content { width: 95%; border-radius: 16px 16px 0 0; margin-top: auto; max-height: 90vh; }
  .modal { align-items: flex-end; }
}

@media (max-width: 480px) {
  .date-bar { flex-wrap: wrap; }
  .meal-tabs { justify-content: center; }
  .meal-tab { flex: 1; text-align: center; min-width: 60px; }
}
