/* ===== 基础重置与变量 ===== */
:root {
  --primary: #4A90D9;
  --primary-light: #E8F0FE;
  --success: #34C759;
  --success-light: #E8F8ED;
  --warning: #FF9500;
  --danger: #FF3B30;
  --frozen: #8E8E93;
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --text-secondary: #8E8E93;
  --border: #E5E5EA;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ===== 顶部标题栏 ===== */
#header {
  padding: calc(var(--safe-top) + 8px) 20px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-shrink: 0;
}

#header h1 {
  font-size: 22px;
  font-weight: 700;
}

#header-date {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ===== 页面容器 ===== */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(70px + var(--safe-bottom));
}

.page.active {
  display: block;
}

/* ===== 底部导航 ===== */
#tab-bar {
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  flex-shrink: 0;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.2s;
}

.tab svg {
  fill: var(--text-secondary);
  transition: fill 0.2s;
}

.tab.active {
  color: var(--primary);
}

.tab.active svg {
  fill: var(--primary);
}

/* ===== 今日打卡列表 ===== */
.habit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habit-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: transform 0.15s;
}

.habit-card:active {
  transform: scale(0.98);
}

.habit-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.habit-checkbox {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s;
  background: var(--card);
}

.habit-checkbox.checked {
  background: var(--success);
  border-color: var(--success);
}

.habit-checkbox.checked::after {
  content: '';
  width: 8px;
  height: 14px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translateY(-1px);
}

.habit-info {
  flex: 1;
  min-width: 0;
}

.habit-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-title.completed {
  color: var(--text-secondary);
  text-decoration: line-through;
}

.habit-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-icon:active {
  background: var(--border);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  fill: var(--text-secondary);
}

.habit-note-preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  margin: 4px 0;
}

/* ===== 管理页工具栏 ===== */
.manage-toolbar {
  margin-bottom: 16px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.2s;
}

.btn-primary:active {
  opacity: 0.8;
}

/* ===== 管理卡片 ===== */
.manage-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  gap: 12px;
}

.manage-card-frozen {
  background: #F2F2F7;
  opacity: 0.75;
  border-left: 3px solid var(--frozen);
}

.manage-card .habit-info {
  flex: 1;
}

.manage-card .habit-status {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  margin-top: 4px;
}

.status-active {
  color: var(--success);
  background: var(--success-light);
}

.status-frozen {
  color: var(--frozen);
  background: #F2F2F7;
}

.manage-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 6px 10px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-sm:active { opacity: 0.7; }

.btn-edit { background: var(--primary-light); color: var(--primary); }
.btn-freeze { background: #F2F2F7; color: var(--frozen); }
.btn-unfreeze { background: var(--warning); color: white; }
.btn-delete { background: #FFE5E5; color: var(--danger); }

/* ===== 统计页 ===== */
.stats-period-label {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-weight: 500;
}

.stats-habit-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.stats-habit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.stats-habit-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.stats-habit-rate {
  font-size: 14px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.rate-good { color: #1B8C3A; background: var(--success-light); }
.rate-mid { color: #B06800; background: #FFF3E0; }
.rate-low { color: var(--danger); background: #FFE5E5; }

.chart-container-mini {
  padding: 0;
}

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-content h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  font-family: inherit;
  resize: none;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,144,217,0.15);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn-cancel {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.modal-actions .btn-primary {
  flex: 1;
}

/* ===== 确认删除 ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-box {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  max-width: 300px;
  width: 100%;
}

.confirm-box p {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

.confirm-actions {
  display: flex;
  gap: 12px;
}

.confirm-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.confirm-actions .btn-confirm-cancel {
  background: var(--bg);
  color: var(--text);
}

.confirm-actions .btn-confirm-ok {
  background: var(--danger);
  color: white;
}
