/* ===== 莫兰迪色系主题 ===== */
:root {
  --bg: #e8e3dc;
  --surface: rgba(247, 243, 237, 0.82);
  --surface-solid: #f4efe8;
  --ink: #4a4540;
  --ink-soft: #6f685f;
  --muted: #9a9286;
  --line: rgba(120, 110, 98, 0.18);
  --accent: #9c8e7e;
  --accent-soft: #c9bfb2;

  /* 莫兰迪调色板 */
  --m1: #a7b0a3; /* 灰绿 */
  --m2: #c2b1a3; /* 暖棕 */
  --m3: #b6a9b8; /* 灰紫 */
  --m4: #a9b3bb; /* 灰蓝 */
  --m5: #cdbfa6; /* 燕麦 */
  --m6: #bcae9e; /* 卡其 */

  /* 手势底色 */
  --done-bg: rgba(137, 156, 130, 0.30);
  --del-bg: rgba(178, 137, 137, 0.32);

  --radius: 18px;
  --shadow: 0 8px 24px rgba(70, 62, 52, 0.12);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* 背景层 */
.bg-layer {
  position: fixed; inset: 0; z-index: -2;
  background-size: cover; background-position: center;
  filter: saturate(0.85);
}
.bg-scrim {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, rgba(232,227,220,0.35), rgba(232,227,220,0.55));
  backdrop-filter: blur(2px);
}

/* 顶部栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  background: linear-gradient(180deg, rgba(244,239,232,0.92), rgba(244,239,232,0.55));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.app-title { font-size: 22px; font-weight: 700; margin: 0; flex: 1; letter-spacing: 1px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--surface); color: var(--ink-soft); font-size: 18px;
  box-shadow: var(--shadow); cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.filter-row { display: flex; gap: 8px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  transition: all .2s;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 主区域 */
.main { padding: 14px 14px 120px; min-height: 60vh; }
.view.hidden, .hidden { display: none !important; }

/* 列表 */
.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.item {
  position: relative; overflow: hidden; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  touch-action: pan-y;
}
.item-inner {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--surface-solid);
  border-left: 6px solid var(--accent-soft);
  min-height: 64px;
  transition: transform .12s ease;
}
.item.dragging { opacity: .85; box-shadow: 0 12px 30px rgba(0,0,0,.18); }

/* 手势背景提示 */
.gesture-bg {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; font-weight: 600; color: #fff;
  padding: 0 20px; font-size: 14px; opacity: 0;
}
.gesture-bg.done { background: var(--done-bg); justify-content: flex-start; }
.gesture-bg.del { background: var(--del-bg); justify-content: flex-end; color: #fff; }

/* 完成态 */
.item.done .item-inner { opacity: .62; }
.item.done .item-title { text-decoration: line-through; }

.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--accent-soft);
  flex: 0 0 auto; display: grid; place-items: center; font-size: 14px; color: #fff;
  transition: all .2s;
}
.item.done .check { background: #8a9b81; border-color: #8a9b81; }

.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.tag { padding: 1px 8px; border-radius: 999px; font-size: 11px; background: rgba(120,110,98,.1); color: var(--ink-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.empty-hint { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-hint p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 13px; }

/* 宫格 */
.item-list.grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.item-list.grid .item { min-height: 110px; }
.item-list.grid .item-inner { flex-direction: column; align-items: flex-start; min-height: 110px; }

/* 报表 */
.report-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }
.report-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.report-head .big { font-size: 28px; font-weight: 700; }
.insight {
  background: rgba(156,142,126,.12); border-radius: 12px; padding: 12px 14px;
  font-size: 13px; line-height: 1.6; margin-top: 10px;
}
.insight b { color: var(--accent); }
canvas { width: 100%; height: 180px; display: block; }

.timeline { margin-top: 10px; }
.tl-day { font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.tl-times { display: flex; flex-wrap: wrap; gap: 6px; }
.tl-time {
  background: rgba(167,176,163,.35); border-radius: 999px; padding: 3px 10px;
  font-size: 12px; color: var(--ink-soft);
}

/* 设置 */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.field > span { color: var(--ink-soft); font-size: 13px; }
input[type=text], input[type=time], input[type=datetime-local] {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font-size: 15px; background: #fff; color: var(--ink); width: 100%;
}
input[type=file] { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  padding: 10px; border-radius: 12px; font-size: 14px; cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
}
.swatch.active { border-color: var(--ink); transform: scale(1.05); }

.reminder-list { display: flex; flex-direction: column; gap: 8px; }
.reminder-row { display: flex; align-items: center; gap: 8px; }
.reminder-row input { flex: 1; }
.btn {
  border: none; border-radius: 12px; padding: 11px 16px; background: var(--accent);
  color: #fff; font-size: 14px; cursor: pointer; box-shadow: var(--shadow);
}
.btn:active { transform: scale(.97); }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.ghost { background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line); box-shadow: none; }
.btn.danger { background: #b08989; }

/* 底部导航 */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; background: rgba(244,239,232,.95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.nav-btn {
  flex: 1; border: none; background: none; padding: 12px 0; font-size: 13px;
  color: var(--muted); cursor: pointer;
}
.nav-btn.active { color: var(--accent); font-weight: 700; }

/* 圆形浮标 */
.fab {
  position: fixed; right: 20px; bottom: calc(78px + var(--safe-b)); z-index: 30;
  width: 62px; height: 62px; border-radius: 50%; border: none;
  background: radial-gradient(circle at 30% 30%, #b6a89a, var(--accent));
  color: #fff; font-size: 36px; line-height: 1; box-shadow: 0 10px 26px rgba(110,96,82,.4);
  cursor: pointer; display: grid; place-items: center;
  transition: transform .18s cubic-bezier(.2,1.2,.4,1);
}
.fab:active { transform: scale(.9) rotate(90deg); }
.fab-plus { margin-top: -4px; }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(60,54,46,.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
  width: 100%; max-width: 520px; background: var(--surface-solid);
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + var(--safe-b));
  box-shadow: 0 -10px 30px rgba(0,0,0,.2); max-height: 90vh; overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(40px) } to { transform: translateY(0) } }
.modal-card h2 { margin: 4px 0 16px; font-size: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  background: rgba(50,45,38,.92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 80; box-shadow: var(--shadow); transition: opacity .3s;
}

/* ===== 习惯库 ===== */
.lib-list { display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; }
.lib-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-solid); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.lib-icon {
  width: 48px; height: 48px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(135deg, var(--accent-soft), var(--m1));
}
.lib-body { flex: 1; min-width: 0; }
.lib-title { font-size: 16px; font-weight: 600; }
.lib-desc { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-add {
  width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--line);
  background: none; color: var(--muted); font-size: 20px; cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
}
.lib-add:active { background: rgba(120,110,98,.08); }

.full-btn {
  width: 100%; padding: 14px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; box-shadow: var(--shadow);
}
.full-btn:active { transform: scale(.98); }

/* ===== 星期选择器 ===== */
.weekday-picker { display: flex; gap: 8px; justify-content: space-between; margin-bottom: 4px; }
.wd-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line);
  background: var(--surface); color: var(--ink-soft); font-size: 14px; font-weight: 600;
  cursor: pointer; display: grid; place-items: center; transition: all .15s;
}
.wd-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.wd-btn:active { transform: scale(.9); }

/* ===== 分组标签 ===== */
.group-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.group-tag {
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft); font-size: 13px; cursor: pointer;
  transition: all .15s;
}
.group-tag.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.group-tag-add {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px dashed var(--line);
  background: none; color: var(--muted); font-size: 16px; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}

/* ===== 行内字段（目标/日期/天数）===== */
.row-field { margin-bottom: 14px; }
.row-field-inner {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 12px; padding: 4px 10px;
  background: #fff;
}
.row-field-inner input,
.row-field-inner select {
  flex: 1; border: none; background: none; padding: 8px 0;
  font-size: 15px; color: var(--ink); outline: none;
}
.field-arrow { color: var(--muted); font-size: 18px; }

/* ===== 开关 ===== */
.toggle-field { flex-direction: row; align-items: center; justify-content: space-between; }
.toggle-field > span { margin: 0; }
.switch { position: relative; width: 48px; height: 26px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 26px;
  background: var(--line); transition: .2s;
}
.slider::before {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ===== 链接按钮 ===== */
.link-btn {
  border: none; background: none; color: var(--accent); font-size: 14px;
  cursor: pointer; padding: 4px 0;
}
