/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f4f3ed;
  --border: rgba(0,0,0,0.10);
  --border-strong: rgba(0,0,0,0.18);
  --text: #2c2c2a;
  --text-muted: #5f5e5a;
  --text-soft: #888780;
  --accent: #1D9E75;
  --accent-dark: #0F6E56;
  --danger: #D85A30;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-strong: 0 6px 24px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  background: var(--surface);
  min-height: 100vh;
  box-shadow: var(--shadow);
  padding-bottom: 6rem;
}

/* ========== 顶部栏 ========== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 22px; }
.brand h1 { font-size: 19px; font-weight: 600; color: var(--text); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.today-badge { font-size: 13px; color: var(--text-muted); }

.icon-btn {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ========== 月份导航 ========== */
.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem 0.5rem;
  flex-wrap: wrap;
  gap: 10px;
}
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  min-width: 130px;
  text-align: center;
}
.nav-btn {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.today-btn { width: auto; padding: 0 12px; font-size: 13px; }

.view-tabs { display: flex; gap: 4px; }
.view-tab {
  border: 1px solid var(--border);
  background: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  transition: all 0.15s;
}
.view-tab.active {
  background: var(--text);
  color: white;
  border-color: var(--text);
  font-weight: 500;
}

/* ========== 统计卡片 ========== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 1.5rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-val { font-size: 22px; font-weight: 600; color: var(--text); margin-top: 2px; }

/* ========== 成员条 ========== */
.members-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 1.5rem 1rem;
  flex-wrap: wrap;
}
.member-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px 5px 6px;
  border-radius: 24px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  user-select: none;
}
.member-chip.inactive { opacity: 0.35; }
.member-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: white;
}
.add-member-btn {
  border: 1px dashed var(--border-strong);
  background: none;
  padding: 5px 12px;
  border-radius: 24px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.add-member-btn:hover { background: var(--surface-2); color: var(--text); }

/* ========== 月视图 ========== */
.calendar-grid { padding: 0 1.5rem; }
.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 6px;
}
.weekday-label {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
  font-weight: 500;
}
.days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.day-cell {
  background: var(--surface);
  min-height: 100px;
  padding: 6px 6px 4px;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day-cell:hover { background: var(--surface-2); }
.day-cell.other-month .day-num { color: #c0bfb8; }
.day-cell.today { background: #f0faf5; }
.day-num {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.day-cell.today .day-num {
  background: var(--accent);
  color: white;
}
.event-pill {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  max-width: 100%;
  cursor: pointer;
  border-left: 3px solid;
}
.more-label {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 2px;
  cursor: pointer;
}

/* ========== 日程表视图 ========== */
.agenda-view {
  padding: 0 1.5rem;
  display: none;
}
.agenda-day { margin-bottom: 1.25rem; }
.agenda-date-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.agenda-event {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
}
.agenda-event:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.agenda-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.agenda-body { flex: 1; min-width: 0; }
.agenda-title { font-size: 14px; font-weight: 500; color: var(--text); }
.agenda-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.agenda-owner-badge {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 500;
  flex-shrink: 0;
}
.agenda-empty {
  color: var(--text-soft);
  font-size: 14px;
  padding: 2rem 0;
  text-align: center;
}

/* ========== 浮动按钮 ========== */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
}
.fab button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-strong);
  transition: transform 0.15s, background 0.15s;
  font-family: inherit;
  line-height: 1;
}
.fab button:hover {
  transform: scale(1.08);
  background: var(--accent-dark);
}

/* ========== 弹窗 ========== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
/* 「添加成员」弹窗会叠在「成员管理」弹窗之上，需更高层级，否则会被挡在背后 */
#member-modal { z-index: 120; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-strong);
}
.modal.ical-modal { max-width: 600px; }
.modal-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}
.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.form-row { margin-bottom: 0.85rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
  font-weight: 500;
}
.form-input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29,158,117,0.15);
}

.btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 1.25rem;
}
.btn {
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: none;
  color: var(--text);
  font-family: inherit;
  transition: all 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  margin-right: auto;
}
.btn.btn-danger:hover { background: var(--danger); color: white; }
.hidden { display: none; }

.member-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected {
  border-color: var(--text);
  transform: scale(1.15);
}

/* iCal 弹窗 */
.ical-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 1.25rem 0 0.5rem;
}
.ical-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.ical-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  min-width: 60px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ical-name-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.ical-url {
  flex: 1;
  font-size: 11px;
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.ical-copy-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
}
.ical-copy-btn:hover { background: var(--text); color: white; border-color: var(--text); }

.ical-help {
  margin-top: 1.25rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.ical-help summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  user-select: none;
}
.help-content {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
}
.help-content ol { padding-left: 1.25rem; margin: 4px 0 10px; }
.help-content strong { color: var(--text); }

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c2c2a;
  color: #f1efe8;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  box-shadow: var(--shadow-strong);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ========== 推送通知 section ========== */
.section-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 1rem;
}
.section-card-push { background: #f0faf5; border: 1px solid rgba(29,158,117,0.2); }

.push-warning {
  background: #fdf6ea;
  border: 1px solid #e0b56b;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  color: #6b4a1a;
  margin-bottom: 10px;
  line-height: 1.5;
}
.ios-warning { background: #e6f1fb; border-color: #88baea; color: #1d4f7c; }

.push-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.push-list { display: flex; flex-direction: column; gap: 6px; }
.push-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.push-name {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.push-actions { display: flex; gap: 6px; }
.push-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
  font-weight: 500;
}
.push-btn:hover { background: var(--surface-2); }
.push-btn:disabled { opacity: 0.5; cursor: wait; }
.push-on {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.push-on:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.push-off {
  color: var(--danger);
  border-color: var(--danger);
}
.push-off:hover { background: var(--danger); color: white; }
.push-test { color: var(--text-muted); }

.bell-icon {
  font-size: 11px;
  margin-left: 2px;
}

/* ========== 响应式 (移动端) ========== */
@media (max-width: 640px) {
  .top-bar { padding: 1rem; flex-wrap: wrap; gap: 10px; }
  .brand h1 { font-size: 17px; }
  .nav-row { padding: 0.75rem 1rem 0.5rem; }
  .month-label { min-width: 100px; font-size: 16px; }
  .stats-row { padding: 0 1rem; }
  .members-strip { padding: 0 1rem 0.75rem; }
  .calendar-grid, .agenda-view { padding: 0 1rem; }
  .day-cell { min-height: 70px; padding: 4px; }
  .day-num { font-size: 12px; width: 20px; height: 20px; }
  .event-pill { font-size: 9px; padding: 1px 4px; }
  .stat-val { font-size: 18px; }
  .fab { bottom: 16px; right: 16px; }
  .fab button { width: 50px; height: 50px; font-size: 24px; }
}

/* ===== 登录 / 账号（每位家人独立登录）===== */
.login-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-backdrop.hidden { display: none; }   /* 高优先级，盖过默认 flex */
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-strong);
  padding: 28px 24px;
}
.login-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px; }
.login-brand h2 { font-size: 20px; font-weight: 600; color: var(--text); }
.login-tip { text-align: center; color: var(--text-muted); font-size: 14px; margin: 6px 0 18px; }
.login-accounts { display: flex; flex-direction: column; gap: 10px; }
.login-account {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-size: 15px; color: var(--text);
  transition: background .15s, border-color .15s;
}
.login-account:hover { background: var(--surface-2); border-color: var(--border-strong); }
.login-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 15px;
}
.login-account .login-admin-tag { margin-left: auto; font-size: 11px; color: var(--text-soft); }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-who { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 600; color: var(--text); }
.login-error { color: var(--danger); font-size: 13px; min-height: 16px; }
.login-empty { text-align: center; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; margin-top: 14px; }
.login-account .login-pending-tag { background: var(--surface-2); color: var(--text-soft); border-radius: 999px; padding: 1px 8px; }
.claim-tip { font-size: 12.5px; color: var(--text-muted); margin: 0; line-height: 1.5; }
/* 全家暗号区（成员管理弹窗内）*/
.family-code-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin: 4px 0 12px; background: var(--surface-2); }
.family-code-box .fc-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.family-code-box #fc-value { letter-spacing: 1px; font-size: 15px; color: var(--text); }
.family-code-box .fc-tip { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; line-height: 1.5; }

.me-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.me-badge .me-dot { width: 9px; height: 9px; border-radius: 50%; }

/* 成员管理列表 */
.members-admin-list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 14px; max-height: 50vh; overflow: auto; }
.member-admin-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
}
.member-admin-row .ma-name { font-size: 14px; color: var(--text); display: flex; align-items: center; gap: 8px; flex: 1 1 150px; min-width: 0; white-space: nowrap; }
.member-admin-row .ma-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.ma-tag { font-size: 11px; color: var(--text-soft); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.ma-btn {
  font-size: 12px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.ma-btn:hover { background: var(--surface-2); color: var(--text); }
.ma-btn.danger { color: var(--danger); }

/* 兜底：确保 .hidden 始终能盖过后定义的 display 规则（如 .login-form / .me-badge）*/
.hidden { display: none !important; }
