/* ==========================================================
   漫希的工作台 — 设计系统 / Design Tokens
   健康 · 养生 · 健身
   主色：喜金水配色（默认深海蓝 · 水）
   ========================================================== */

:root {
  /* 底色系统 —— 金水：银白 · 水蓝灰 */
  --bg:            #eef2f8;
  --bg-deep:       #e3e9f2;
  --surface:       #ffffff;
  --surface-2:     #f7f9fc;
  --surface-3:     #eef2f8;

  /* 品牌色 —— 深海蓝（水 · 喜金水默认主色） */
  --brand:         #2f6db0;
  --brand-hover:   #245a93;
  --brand-soft:    #e6eef7;
  --brand-softer:  #f2f7fb;
  --brand-line:    #bcd4ea;
  /* 品牌色 RGB 三元组，供阴影/聚焦环随主题变化 */
  --brand-rgb:     47,109,176;

  /* 模块识别色 —— 协调金水 */
  --c-sleep:       #3f7fc4;
  --c-sleep-soft:  #e8f0f9;
  --c-habit:       #c9a227;
  --c-habit-soft:  #f7f0d8;
  --c-recipe:      #c77b3b;
  --c-recipe-soft: #fbeede;
  --c-fitness:     var(--brand);
  --c-fitness-soft:var(--brand-soft);

  /* 文字（冷调，贴合水气） */
  --text:          #1f2733;
  --text-2:        #4a5563;
  --text-3:        #8a96a6;
  --text-4:        #b4bdc9;
  --text-inv:      #ffffff;

  /* 线条（冷灰） */
  --line:          #e2e8f0;
  --line-2:        #d2dae6;

  /* 状态色 —— 睡眠日历（业务语义：熬夜浅红 / 早睡浅绿 / 未记录浅灰，保持不变） */
  --late-bg:       #fceae7;
  --late-line:     #f0b6ac;
  --late-text:     #b2453a;
  --early-bg:      #e3f3e9;
  --early-line:    #a6d8b9;
  --early-text:    #2d7a4d;
  --empty-bg:      #eef1f5;
  --empty-text:    #aab2bf;

  --danger:        #c0503f;
  --warn:          #c9a227;
  --ok:            var(--brand);

  /* 圆角 */
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-full: 999px;

  /* 阴影 */
  --sh-1: 0 1px 2px rgba(31,39,51,.05), 0 1px 3px rgba(31,39,51,.04);
  --sh-2: 0 2px 6px rgba(31,39,51,.06), 0 6px 16px rgba(31,39,51,.05);
  --sh-3: 0 8px 24px rgba(31,39,51,.09), 0 2px 8px rgba(31,39,51,.05);
  --sh-pop: 0 16px 48px rgba(31,39,51,.16);

  --ease: cubic-bezier(.22,.61,.36,1);

  --font: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC",
          "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-num: "SF Mono", "DIN Alternate", "Bahnschrift", ui-monospace, "Menlo", monospace;
}

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

html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 不锁死 body 滚动：交由 window 原生滚动（顶/底栏用 fixed 浮层） */
body { overflow: visible; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
h1,h2,h3,h4,h5 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cdd7e4; border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b3c0d2; background-clip: content-box; }
.scroll-y { overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: #cdd7e4 transparent; }

/* ---------- 通用原子 ---------- */
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--text-3); }
.row { display: flex; align-items: center; }
.row-b { display: flex; align-items: center; justify-content: space-between; }
.gap-4{gap:4px}.gap-6{gap:6px}.gap-8{gap:8px}.gap-10{gap:10px}.gap-12{gap:12px}.gap-16{gap:16px}
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-h {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 15px 18px 13px;
  border-bottom: 1px solid var(--line);
}
.card-h h3 { font-size: 14.5px; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.card-h .sub { font-size: 11.5px; color: var(--text-3); font-weight: 400; }
.card-b { padding: 16px 18px; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 15px;
  border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--text); font-size: 13px; font-weight: 500;
  transition: all .16s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--text-4); }
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 3px rgba(var(--brand-rgb),.28); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-sm { height: 28px; padding: 0 11px; font-size: 12px; border-radius: var(--r-xs); }
.btn-lg { height: 44px; padding: 0 22px; font-size: 14.5px; border-radius: var(--r-md); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fbeeec; border-color: #eec4bd; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-block { width: 100%; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.input, .select, textarea.input {
  height: 38px; padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font-size: 13.5px; outline: none; width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus {
  border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb),.13);
}
.select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='M1 1l4.5 4.5L10 1' stroke='%238a96a6' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
input[type="date"], input[type="time"], input[type="datetime-local"] { cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .5; }
.input::placeholder { color: var(--text-4); }

/* 分段选择 */
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button {
  padding: 0 13px; height: 28px; border-radius: 6px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
  transition: all .16s var(--ease);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

/* 徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 21px; padding: 0 8px; border-radius: var(--r-full);
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-3); color: var(--text-2);
}
.badge-late  { background: var(--late-bg);  color: var(--late-text); }
.badge-early { background: var(--early-bg); color: var(--early-text); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

/* 空状态 */
.empty { padding: 34px 20px; text-align: center; color: var(--text-3); }
.empty .ico { font-size: 30px; opacity: .35; margin-bottom: 9px; }
.empty .t { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 3px; }
.empty .d { font-size: 12px; line-height: 1.6; }

/* ---------- 睡眠日历（双端共用） ---------- */
.cal-head { display: grid; grid-template-columns: repeat(7,1fr); gap: 6px; margin-bottom: 7px; }
.cal-head span {
  text-align: center; font-size: 11px; font-weight: 600;
  color: var(--text-3); letter-spacing: .06em; padding: 3px 0;
}
.cal-head span.we { color: var(--c-recipe); }
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 6px; }

.cal-cell {
  position: relative; border-radius: var(--r-sm);
  background: var(--empty-bg); border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 2px 5px; min-height: 62px;
  cursor: pointer; transition: transform .14s var(--ease), box-shadow .14s var(--ease);
  overflow: hidden;
}
.cal-cell:hover { transform: translateY(-1.5px); box-shadow: var(--sh-2); z-index: 2; }
.cal-cell.void { background: transparent; cursor: default; pointer-events: none; }
.cal-cell.void:hover { transform: none; box-shadow: none; }
/* 相邻月份（上月/下月）补位的日期：有记录的略浅显示仍可点开；无记录的与卡片同色、不加灰底 */
.cal-cell.other { opacity: .62; }
.cal-cell.other:hover { opacity: .82; }
.cal-cell.other.other-empty { opacity: 1; background: transparent; }
.cal-cell.other.other-empty .d { color: var(--empty-text); }
.cal-cell .d { font-size: 13px; font-weight: 650; color: var(--empty-text); line-height: 1.15; font-family: var(--font-num); }
.cal-cell .t { font-size: 10.5px; font-weight: 600; margin-top: 3px; font-family: var(--font-num); letter-spacing: -.02em; }
.cal-cell .h { font-size: 9.5px; margin-top: 1px; opacity: .82; font-family: var(--font-num); }
.cal-cell.late  { background: var(--late-bg);  border-color: var(--late-line); }
.cal-cell.late .d, .cal-cell.late .t, .cal-cell.late .h { color: var(--late-text); }
.cal-cell.early { background: var(--early-bg); border-color: var(--early-line); }
.cal-cell.early .d, .cal-cell.early .t, .cal-cell.early .h { color: var(--early-text); }
.cal-cell.today { box-shadow: 0 0 0 2px var(--brand); }
.cal-cell.today::after {
  content: ''; position: absolute; top: 4px; right: 4px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--brand);
}
.cal-cell.sel { box-shadow: 0 0 0 2px var(--text); }
.cal-cell.future { opacity: .42; }

.legend { display: flex; flex-wrap: wrap; gap: 13px; font-size: 11.5px; color: var(--text-3); }
.legend i { width: 11px; height: 11px; border-radius: 3.5px; display: inline-block; margin-right: 5px; vertical-align: -1.5px; border: 1px solid; }
.lg-early i { background: var(--early-bg); border-color: var(--early-line); }
.lg-late  i { background: var(--late-bg);  border-color: var(--late-line); }
.lg-none  i { background: var(--empty-bg); border-color: var(--line-2); }

/* ---------- 周打卡预览 ---------- */
.wk { display: grid; grid-template-columns: repeat(7,1fr); gap: 5px; }
.wk-d {
  aspect-ratio: 1; border-radius: 8px;
  background: var(--surface-3); border: 1px solid transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--text-4);
  font-family: var(--font-num);
  cursor: pointer; transition: all .15s var(--ease); position: relative;
}
.wk-d:hover { transform: scale(1.09); }
.wk-d.on { color: #fff; border-color: transparent; background: var(--brand); }
.wk-d.on::after {
  content: ''; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E") center/54% no-repeat;
}
.wk-d.on span { opacity: 0; }
.wk-d.td { box-shadow: 0 0 0 2px var(--text-4); }
.wk-d.fu { opacity: .38; pointer-events: none; }

/* ---------- 弹层 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(28,36,51,.42);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 900; padding: 24px;
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0 } }
.modal {
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--sh-pop); width: 100%; max-width: 440px;
  max-height: 88vh; display: flex; flex-direction: column;
  animation: pop .26s var(--ease); overflow: hidden;
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97) } }
.modal-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line); flex: none;
}
.modal-h h3 { font-size: 15.5px; }
.modal-b { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.modal-f { padding: 14px 20px 18px; display: flex; gap: 9px; justify-content: flex-end; border-top: 1px solid var(--line); flex: none; }
.x-btn {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  color: var(--text-3); font-size: 19px; line-height: 1; transition: all .15s;
}
.x-btn:hover { background: var(--surface-3); color: var(--text); }

/* 弹窗打开时锁定页面背景滚动，防止滑动穿透到下方内容 */
body.modal-open {
  position: fixed; left: 0; right: 0; width: 100%;
  overflow: hidden;
}
/* 弹窗内部可滚动 + 阻断滚动链：内容多时弹窗内滑动，
   滑到顶/底不再带动背景（与 body 锁定双保险） */
.modal, .modal-b { overscroll-behavior: contain; }

/* Toast */
#toast-wrap {
  position: fixed; z-index: 2000; left: 50%; transform: translateX(-50%);
  bottom: 34px; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(31,39,51,.93); color: #fff;
  padding: 10px 18px; border-radius: var(--r-full);
  font-size: 13px; font-weight: 500; box-shadow: var(--sh-3);
  animation: tin .3s var(--ease); backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 7px; max-width: 84vw;
}
.toast.out { animation: tout .28s var(--ease) forwards; }
@keyframes tin  { from { opacity: 0; transform: translateY(14px) scale(.94) } }
@keyframes tout { to   { opacity: 0; transform: translateY(-8px) scale(.96) } }

/* 进度环 */
.ring { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-linecap: round; transition: stroke-dashoffset .7s var(--ease); }

/* 条形进度 */
.bar { height: 6px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: var(--r-full); transition: width .6s var(--ease); }

/* 食谱卡 */
.meal-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-full);
}
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px;
  background: var(--surface-3); border-radius: var(--r-full);
  font-size: 11.5px; color: var(--text-2); font-weight: 500;
}
.chip-anti { background: var(--brand-softer); color: var(--brand); border: 1px solid var(--brand-line); }

.steps { display: flex; flex-direction: column; gap: 9px; counter-reset: s; }
.steps li {
  display: flex; gap: 10px; font-size: 13px; line-height: 1.62; color: var(--text-2);
}
.steps li::before {
  counter-increment: s; content: counter(s);
  flex: none; width: 19px; height: 19px; margin-top: 1px;
  border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  font-size: 10.5px; font-weight: 700; display: grid; place-items: center;
  font-family: var(--font-num);
}

/* 同步状态点 */
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-4); flex: none; transition: background .3s; }
.sync-dot.on   { background: var(--ok); box-shadow: 0 0 0 3px rgba(var(--brand-rgb),.16); }
.sync-dot.busy { background: var(--warn); animation: bl 1s infinite; }
.sync-dot.err  { background: var(--danger); }
@keyframes bl { 50% { opacity: .3 } }

.fade-in { animation: fi .32s var(--ease); }
@keyframes fi { from { opacity: 0; transform: translateY(7px) } }

.skel { background: linear-gradient(90deg,var(--surface-3) 25%,#e9eef4 37%,var(--surface-3) 63%); background-size: 400% 100%; animation: sk 1.3s infinite; border-radius: var(--r-sm); }
@keyframes sk { 0%{background-position:100% 50%} 100%{background-position:0 50%} }

/* ---------- 主题选择（设置面板） ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-card {
  position: relative; border: 1.5px solid var(--line-2); border-radius: var(--r-md);
  padding: 11px 10px 10px; cursor: pointer; background: var(--surface-2);
  transition: all .16s var(--ease); text-align: left;
}
.theme-card:hover { border-color: var(--text-4); transform: translateY(-1px); }
.theme-card.on { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb),.12); }
.theme-swatch { display: flex; gap: 4px; margin-bottom: 8px; }
.theme-swatch i { flex: 1; height: 26px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.04); }
.theme-name { font-size: 12.5px; font-weight: 600; color: var(--text); }
.theme-elem { font-size: 10.5px; color: var(--text-3); margin-top: 1px; }
.theme-card.on::after {
  content: '✓'; position: absolute; top: 8px; right: 9px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--brand); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
