/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ── App Shell ─────────────────────────────────────────── */
#app {
  max-width: 430px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  box-shadow: var(--sh-md);
}

/* ── Pages ─────────────────────────────────────────────── */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding-bottom: var(--tab-h);
}
.page.active { display: block; }

/* ── Bottom Tab Bar ────────────────────────────────────── */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: var(--tab-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-mute);
  font-size: 11px;
  transition: color .15s;
}
.tab-btn.active { color: var(--primary); }
.tab-btn svg { width: 22px; height: 22px; }

/* ── Page Header ───────────────────────────────────────── */
.page-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-header h1 { font-size: 17px; font-weight: 600; }

/* ── Section ───────────────────────────────────────────── */
.section { padding: 16px; }
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 12px;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sm);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.card-sub { font-size: 13px; color: var(--text-sec); }

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-cog  { background: color-mix(in srgb, var(--dim-cog) 15%, white); color: var(--dim-cog); }
.badge-lang { background: color-mix(in srgb, var(--dim-lang) 15%, white); color: var(--dim-lang); }
.badge-mot  { background: color-mix(in srgb, var(--dim-mot) 15%, white); color: var(--dim-mot); }
.badge-emo  { background: color-mix(in srgb, var(--dim-emo) 15%, white); color: var(--dim-emo); }
.badge-hab  { background: color-mix(in srgb, var(--dim-hab) 15%, white); color: var(--dim-hab); }

/* 里程碑状态徽章 */
.badge-pending  { background: #F5F5F5; color: var(--text-mute); }
.badge-watching { background: color-mix(in srgb, var(--info) 15%, white); color: var(--info); }
.badge-achieved { background: color-mix(in srgb, var(--success) 15%, white); color: var(--success); }
.badge-delayed  { background: color-mix(in srgb, var(--warning) 15%, white); color: var(--warning); }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  transition: opacity .15s, transform .1s;
}
.btn:active { opacity: .85; transform: scale(.98); }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-accent    { background: var(--accent); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-sec); border: 1px solid var(--border); }
.btn-full      { width: 100%; }
.btn-sm        { padding: 8px 14px; font-size: 13px; border-radius: var(--r-sm); }

/* ── Form Fields ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text-sec); margin-bottom: 6px; display: block; }
.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 15px;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--primary); }
.form-textarea { resize: vertical; min-height: 80px; max-height: 240px; overflow-y: auto; }

/* Segmented control */
.seg-control {
  display: flex;
  background: #F0F0F0;
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  flex: 1;
  padding: 8px 4px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-sec);
  text-align: center;
  transition: all .15s;
}
.seg-btn.active { background: var(--card); color: var(--text); box-shadow: var(--sh-sm); }

/* ── Modal (全屏弹窗) ──────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  width: 100%;
  max-width: 430px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  z-index: 200;
  flex-direction: column;
}
.modal.open { display: flex; }

.modal-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-title { font-size: 16px; font-weight: 600; flex: 1; }
.modal-body { flex: 1; overflow-y: auto; padding: 16px; }

/* ── Overlay (底部弹出层) ──────────────────────────────── */
.overlay-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 300;
}
.overlay-backdrop.open { display: block; }

.overlay {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: var(--card);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 301;
  max-height: 90dvh;
  overflow-y: auto;
}
.overlay-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.overlay-title { font-size: 17px; font-weight: 600; margin-bottom: 16px; }

/* ── Misc utilities ────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 8px 0; }
.text-sec { color: var(--text-sec); }
.text-mute { color: var(--text-mute); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.btn-full { width: 100%; }

/* ── 育儿日记时间线 ─────────────────────────────────────── */
.diary-timeline .diary-year-details,
.diary-timeline .diary-week-details {
  border-bottom: 1px solid var(--border);
}
.diary-timeline .diary-year-summary,
.diary-timeline .diary-week-summary {
  list-style: none;
  display: flex;
  align-items: center;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.diary-timeline .diary-year-summary::before,
.diary-timeline .diary-week-summary::before {
  content: '▶';
  font-size: 10px;
  margin-right: 8px;
  color: var(--text-mute);
  transition: transform .2s;
  display: inline-block;
}
.diary-timeline .diary-year-details[open] > .diary-year-summary::before,
.diary-timeline .diary-week-details[open] > .diary-week-summary::before {
  transform: rotate(90deg);
}
.diary-week-summary {
  font-weight: 500 !important;
  font-size: 13px !important;
  color: var(--text-sec) !important;
  padding-left: 12px !important;
}
.diary-entry-card:hover { background: var(--primary-light); }

/* ── 日记图片缩略图 ──────────────────────────────────────── */
.diary-thumb-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.diary-thumb-wrap {
  position: relative;
  flex-shrink: 0;
}
.diary-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  display: block;
}
.diary-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ── inline confirm ──────────────────────────────────────── */
.inline-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* ── 时光选项卡：微信朋友圈瀑布流 ─────────────────────── */
.moments-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 12px;
}

.moment-date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0 16px;
  position: relative;
}

.moment-date-separator::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

.moment-date-text {
  background: var(--bg-main);
  padding: 0 12px;
  font-size: 12px;
  color: var(--text-sec);
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.moment-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.moment-card:active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

.moment-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
  flex: 1;
}

.moment-time {
  font-size: 12px;
  color: var(--text-sec);
  white-space: nowrap;
}

.moment-delete-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: #f5f5f5;
  color: #999;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.moment-delete-btn:active {
  background: #e8e8e8;
  color: #666;
}

.moment-edit-hint {
  font-size: 11px;
  color: var(--text-mute);
  text-align: right;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.moment-card:hover .moment-edit-hint,
.moment-card:active .moment-edit-hint {
  opacity: 1;
}

.moment-content {
  color: var(--text-main);
  line-height: 1.6;
  word-break: break-word;
}

.moment-content p {
  margin: 0 0 12px;
  font-size: 14px;
}

.moment-content p:last-child {
  margin-bottom: 0;
}

/* 日记卡片特化 */
.diary-card {
  background: linear-gradient(135deg, #fff9e6 0%, #fff 100%);
}

.moment-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.moment-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: transform 0.2s;
  border: 1px solid var(--border);
}

.moment-image:active {
  transform: scale(0.95);
}

/* 活动记录卡片特化 */
.record-card {
  background: linear-gradient(135deg, #e6f7ff 0%, #fff 100%);
}

.record-activity {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}

.record-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0;
  font-size: 13px;
}

.record-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-sec);
}

.record-type {
  display: inline-block;
  padding: 4px 8px;
  background: var(--bg-sec);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-sec);
  margin-top: 8px;
}

.record-note {
  margin-top: 8px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.02);
  border-left: 3px solid var(--primary);
  border-radius: 2px;
  font-size: 13px;
  color: var(--text-main);
}

/* 图片预览模态框 */
.image-preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  cursor: pointer;
}

.image-preview-container {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  z-index: 1;
}

.image-preview-container img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r-md);
}

.image-preview-close {
  position: absolute;
  top: -40px;
  right: 0;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
