/* ==========================================================================
   生活管家 · 样式表
   模块顺序：变量与基础 → 布局 → 通用组件 → 任务 → 日历 → 餐单
             → 采购清单 → 任务组 → 隐私锁 → 响应式
   ========================================================================== */

/* ---------- 1. 变量与基础 ---------- */
:root {
  --bg: #f7f4f0;
  --card: #fffdf9;
  --ink: #2f2a26;
  --muted: #81766e;
  --accent: #b85c5c;
  --soft: #f0dfd8;
  --line: #e8ddd5;
  --green: #6f9578;
  --blue: #59799a;
  --danger: #b64b4b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", sans-serif;
}

/* ---------- 2. 布局 ---------- */
.wrap {
  max-width: 1080px;
  margin: auto;
  padding: 28px 18px 60px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.hero h1 {
  font-size: 34px;
  margin: 4px 0;
}

.hero p {
  margin: 0;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 5px 18px #6b48300b;
}

.card h2 {
  font-size: 20px;
  margin: 0 0 12px;
}

.card h3 {
  font-size: 16px;
  margin: 18px 0 7px;
}

.full {
  grid-column: 1 / -1;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.footer {
  margin-top: 26px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.small {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  color: var(--muted);
  padding: 14px 0;
  text-align: center;
}

/* ---------- 3. 通用组件 ---------- */
button {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font: inherit;
  cursor: pointer;
}

button.secondary {
  background: var(--soft);
  color: var(--ink);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  padding: 6px 0;
}

.pill {
  display: inline-block;
  background: var(--soft);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 13px;
  margin: 3px 4px 3px 0;
}

.badge {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  margin-left: 4px;
}

.badge-daily {
  background: var(--green);
}

.badge-skip {
  background: #a89b90;
}

.notice {
  background: #fff3e8;
  border-left: 4px solid #d28a55;
  padding: 12px 14px;
  border-radius: 10px;
  color: #6e4c35;
}

.progress {
  height: 10px;
  background: var(--soft);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.low {
  background: #eef5ef;
  border-color: #c9ddcc;
}

.low .eyebrow {
  color: var(--green);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.form-grid input,
.form-grid textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
  background: #fff;
  width: 100%;
}

.form-grid textarea {
  grid-column: 1 / -1;
  min-height: 62px;
  resize: vertical;
}

.date-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.date-row button.active {
  background: var(--blue);
  color: #fff;
}

.date-row input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 9px;
  margin-top: 10px;
}

.quick-grid button {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  padding: 12px;
}

.quick-grid button:hover {
  border-color: var(--accent);
}

.routine {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.routine > div {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
}

.routine > div:last-child {
  border-bottom: 0;
}

.routine > div > strong {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.routine > div > span {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.routine > div > small {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
}

.routine > div.is-today {
  background: #fff7f3;
  box-shadow: inset 3px 0 0 var(--accent);
}

.routine > div.is-today > strong {
  color: var(--danger);
}

/* 每天固定任务（洗内裤 / 买菜） */
.routine > div.is-daily {
  background: #f5f9f6;
  box-shadow: inset 3px 0 0 var(--green);
}

.routine > div.is-daily > strong {
  color: var(--green);
}

/* ---------- 4. 任务 ---------- */
.task {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.task:last-child {
  border-bottom: 0;
}

.task > span:first-child {
  flex: 1;
  min-width: 0;
}

.task input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
  margin-top: 3px;
}

.task.done .task-title {
  text-decoration: line-through;
  color: var(--muted);
}

.task small {
  display: block;
  color: var(--muted);
}

/* 已跳过的每日任务：整行淡化，不计入今日进度 */
.task.skipped {
  opacity: 0.55;
}

.task.skipped .task-title strong {
  text-decoration: line-through;
  color: var(--muted);
}

.task.skipped .task-progress-wrap {
  display: none;
}

.skip-btn {
  margin-top: 4px;
  font-size: 13px;
}

.task.assigned {
  border-left: 3px solid var(--blue);
  padding-left: 9px;
}

.task-progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 9px;
}

.task input.task-progress {
  display: block;
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 14px;
  margin: 0;
  accent-color: var(--green);
  cursor: grab;
}

.progress-number {
  min-width: 42px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.manage-actions {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  flex: none;
}

/*
 * 任务组里的「编辑 / 删除」按钮带 .ghost，
 * 必须显式给文字颜色，否则会继承 .manage-actions button 的深红底，
 * 变成深红底 + 深红字，几乎看不见。
 */
.manage-actions button {
  background: var(--danger);
  color: #fff;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.manage-actions button.ghost {
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 6px 10px;
}

.manage-actions button.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.manage-actions button[data-del-group],
.manage-actions button[data-delete-id] {
  background: var(--danger);
  color: #fff;
}

.account-line {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.account-line strong {
  color: var(--ink);
}

.sync {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.sync.ok {
  color: var(--green);
}

.sync.warn {
  color: #b07a3c;
}

/* ---------- 5. 日历 ---------- */
.calendar-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.calendar-day {
  min-height: 74px;
  min-width: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px;
  text-align: left;
  color: var(--ink);
}

.calendar-day.muted {
  opacity: 0.42;
}

.calendar-day.selected {
  border: 2px solid var(--accent);
  padding: 6px;
  background: #fff7f3;
}

.calendar-day.today {
  box-shadow: inset 0 0 0 2px var(--green);
}

.calendar-day strong {
  display: block;
}

.calendar-dot {
  display: none;
  font-size: 12px;
  color: var(--blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

.week-index {
  display: flex;
  gap: 7px;
  overflow: auto;
  padding: 10px 0;
}

.week-index button,
.week-chip {
  white-space: nowrap;
  font-size: 13px;
  background: var(--soft);
  color: var(--ink);
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: inherit;
}

.week-index button.active,
.week-chip.active {
  background: var(--blue);
  color: #fff;
}

/* 日期快捷按钮 */
.date-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 10px 0;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- 6. 餐单 ---------- */
.meal {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.meal:last-child {
  border-bottom: 0;
}

.meal strong {
  display: block;
}

.meal span {
  color: var(--muted);
  font-size: 14px;
}

/* 今日餐单行 */
.meal-row {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  align-items: start;
}

.meal-row:last-child {
  border-bottom: 0;
}

.meal-row strong {
  color: var(--accent);
  font-size: 14px;
  white-space: nowrap;
}

.meal-row span {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.meal-steps {
  margin-top: 10px;
  padding: 10px 12px;
  background: #fff8f2;
  border-radius: 10px;
}

.meal-steps summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}

.meal-steps p {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
}

/* 点菜记录 */
.meal-request {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 8px;
}

.meal-request > span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meal-request small {
  color: var(--muted);
  font-size: 12px;
}

.week-plan {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}

.week-plan > div {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.week-plan .day {
  color: var(--accent);
  font-weight: 700;
}

.meal-day {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.meal-day summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent);
  font-size: 17px;
}

.meal-block {
  margin-top: 9px;
  padding: 10px;
  background: #fff8f2;
  border-radius: 10px;
}

.meal-block strong {
  display: block;
  margin-bottom: 3px;
}

.meal-block .small {
  margin-top: 7px;
}

/* ---------- 7. 采购清单 ---------- */
.shopping-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.shopping-group {
  margin-bottom: 14px;
}

.shopping-group h4 {
  margin: 14px 0 8px;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.shopping-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  margin-bottom: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.shopping-item.done {
  border-color: var(--green);
  background: #f4f9f5;
}

.shopping-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.shopping-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
}

.shopping-count {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--soft);
  border-radius: 999px;
  padding: 2px 9px;
}

.shopping-item.done .shopping-count {
  color: #fff;
  background: var(--green);
}

.shopping-item .hint {
  color: var(--muted);
  font-size: 12px;
}

.shopping-bar {
  height: 7px;
  border-radius: 999px;
  background: var(--soft);
  overflow: hidden;
}

.shopping-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.2s ease;
}

.shopping-item.done .shopping-bar > span {
  background: var(--green);
}

.shopping-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.shopping-controls input[type="number"] {
  width: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  background: #fff;
}

.shopping-controls input[type="number"]:focus {
  outline: 2px solid var(--soft);
  border-color: var(--accent);
}

.shopping-controls button {
  padding: 5px 10px;
  font-size: 13px;
}

/* 单位标签：g / ml / 个 / 盒 */
.unit-tag {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  min-width: 18px;
}

/* ---------- 8. 任务组 ---------- */
.group-items-editor {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.group-item-row {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 110px auto;
  gap: 7px;
  align-items: center;
}

.group-item-row input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
}

/* 「移除」按钮：深红底必须配白字，否则 ghost 的深红字会糊在一起 */
.group-item-row button {
  background: var(--danger);
  color: #fff;
  padding: 7px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.group-item-row button.ghost {
  background: var(--danger);
  color: #fff;
  border: 0;
}

.group-item-row button.ghost:hover {
  background: #a03f3f;
  color: #fff;
}

.group-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 8px;
}

.group-row > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.group-row small {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- 9. 隐私锁 ---------- */
/*
 * 遮罩默认显示（不依赖 JS 添加 class），
 * 只有 body.privacy-unlocked 时才隐藏，避免脚本失败或缓存导致内容裸露。
 */
.privacy-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(247, 244, 240, 0.72);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
}

body.privacy-unlocked .privacy-gate {
  display: none;
}

.privacy-box {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(47, 42, 38, 0.14);
}

.privacy-box h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.privacy-box input {
  width: 100%;
  margin: 12px 0 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}

.privacy-box input:focus {
  outline: 2px solid var(--soft);
  border-color: var(--accent);
}

/* 未解锁时：内容模糊 + 禁止交互（默认生效，解锁后由 body.privacy-unlocked 关闭） */
body:not(.privacy-unlocked) .wrap > section,
body:not(.privacy-unlocked) .footer {
  filter: blur(18px);
  user-select: none;
  pointer-events: none;
}

body:not(.privacy-unlocked) .hero {
  position: relative;
}

body:not(.privacy-unlocked) .hero > div:first-child {
  filter: blur(12px);
  user-select: none;
}

body:not(.privacy-unlocked) .hero::after {
  content: "请输入共享密码解锁内容";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 18px;
  pointer-events: none;
}

/* ---------- 10. 响应式 ---------- */
@media (max-width: 760px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .hero {
    flex-direction: column;
  }

  .hero .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .hero .actions button:last-child {
    grid-column: 1 / -1;
  }

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

  .shopping-list {
    grid-template-columns: 1fr;
  }

  .calendar-day {
    min-height: 58px;
    padding: 5px;
    font-size: 14px;
  }

  .calendar-dot {
    font-size: 11px;
  }

  .week-index {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .week-index button {
    min-width: 0;
    white-space: normal;
    font-size: 12px;
    padding: 8px 5px;
  }

  .task-progress-wrap {
    width: 100%;
  }

  .task input.task-progress {
    min-width: 0;
    width: 100%;
    height: 14px;
  }

  #calendarPanel {
    margin-bottom: 0;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
  }

  #calendarPanel > #tasksCard {
    margin: 16px -18px -18px;
    border-radius: 0 0 10px 10px;
  }

  .meal-block {
    font-size: 15px;
  }

  .group-item-row {
    grid-template-columns: 1fr;
  }
}
