:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --border: #e7e8ec;
  --border-strong: #d9dbe1;
  --text: #1c1d21;
  --text-2: #5b5f6b;
  --text-3: #8b8f9a;
  --accent: #3b6ef5;
  --accent-soft: #eef3ff;
  --danger: #e5484d;
  --warn: #f2a60c;
  --ok: #12a150;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 22, 28, .04), 0 8px 24px rgba(20, 22, 28, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
}

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 17px;
}

.brand-name { font-weight: 600; font-size: 14px; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--text-3); margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-2);
  text-align: left;
  transition: background .12s, color .12s;
}

.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item .ico { font-size: 14px; width: 18px; text-align: center; }
.nav-item .cnt {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}
.nav-item.active .cnt { background: #fff; color: var(--accent); }

.sidebar-foot { margin-top: auto; padding-top: 12px; }

.ghost-btn {
  display: block;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: .12s;
}
.ghost-btn:hover { background: var(--panel-2); border-color: var(--border-strong); color: var(--text); }
.ghost-btn.small { width: auto; padding: 6px 12px; font-size: 12.5px; display: inline-block; }

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  gap: 16px;
  flex-shrink: 0;
}

.topbar-title { font-weight: 600; font-size: 15px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.search-wrap input {
  width: 240px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  outline: none;
  transition: .15s;
}
.search-wrap input:focus { border-color: var(--accent); background: #fff; width: 280px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  cursor: pointer;
  transition: .12s;
}
.icon-btn:hover { background: var(--bg); }

/* 提醒条 */
.reminder-bar {
  background: #fff8e6;
  border-bottom: 1px solid #f5e3b3;
  padding: 9px 20px;
  font-size: 13px;
  color: #7a5a05;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.reminder-bar b { color: #b8790a; }

/* 视图 */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }

/* ---------- 对话 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 10px; max-width: 780px; width: 100%; margin: 0 auto; }
.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 14px;
  flex-shrink: 0;
  background: var(--accent-soft);
}
.msg.user .avatar { background: #eef0f3; }

.bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  line-height: 1.65;
  max-width: 84%;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(20,22,28,.03);
}
.msg.user .bubble { background: var(--accent); color: #fff; border-color: var(--accent); }

.msg-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.mini-card {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: .12s;
}
.mini-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.mini-card .k { font-size: 13px; }
.mini-card .t { font-weight: 500; }
.mini-card .d { color: var(--text-3); font-size: 11.5px; margin-top: 2px; }

.msg-note {
  max-width: 780px; margin: 0 auto; width: 100%;
  font-size: 11.5px; color: var(--text-3);
  text-align: center; padding: 2px 0;
}

/* 输入区 */
.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 20px 14px;
  flex-shrink: 0;
}

.quick-chips {
  display: flex; gap: 6px; margin-bottom: 8px;
  max-width: 780px; margin-left: auto; margin-right: auto;
  flex-wrap: wrap;
}
.quick-chips button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-2);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: .12s;
}
.quick-chips button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 780px;
  margin: 0 auto;
}

#input {
  flex: 1;
  resize: none;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  line-height: 1.55;
  max-height: 160px;
  background: var(--panel);
  transition: border-color .15s;
}
#input:focus { border-color: var(--accent); }

.send {
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  transition: .12s;
}
.send:hover { background: #2f5fe0; }
.send:disabled { background: #b9c6e8; cursor: default; }

/* ---------- 列表 ---------- */
.list-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  gap: 12px;
  flex-shrink: 0;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }

.cards {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  align-content: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
  transition: .15s;
  display: flex;
  flex-direction: column;
  gap: 7px;
  position: relative;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }

.card-top { display: flex; align-items: center; gap: 7px; }
.tag {
  font-size: 11px;
  padding: 1.5px 7px;
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-2);
  font-weight: 500;
}
.tag.schedule { background: #eaf1ff; color: #2f5fe0; }
.tag.todo { background: #e9f8ef; color: #0e8a45; }
.tag.credential { background: #fdeeee; color: #cc3a3f; }
.tag.person { background: #f3eefe; color: #6d43c7; }
.tag.sop { background: #fff5e6; color: #a86a08; }
.tag.note { background: #eef6fa; color: #2b7a99; }

.card-title { font-weight: 550; line-height: 1.45; }
.card-body.locked { color: var(--text-3); font-style: normal; letter-spacing: 1px; }
.card-body {
  color: var(--text-2);
  font-size: 12.8px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}
.card-meta {
  display: flex; gap: 10px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-3);
  margin-top: 2px;
}
.card-meta .due.soon { color: var(--warn); font-weight: 500; }
.card-meta .due.overdue { color: var(--danger); font-weight: 500; }

.card.flash { animation: flash 1.4s ease; }
@keyframes flash {
  0% { background: var(--accent-soft); border-color: var(--accent); }
  100% { background: var(--panel); }
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(18, 20, 26, .34);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-mask[hidden] { display: none; }

.modal {
  background: var(--panel);
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(20, 22, 28, .18);
  animation: pop .16s ease;
}
.modal.wide { max-width: 620px; }
.modal.narrow { max-width: 380px; }
.unlock-tip { margin: 0 0 12px; font-size: 12px; color: var(--text-3); line-height: 1.6; }
.err-text { color: var(--danger); font-size: 12.5px; min-height: 16px; margin-top: 8px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  background: var(--panel);
  transition: border-color .15s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; line-height: 1.6; }
.hint { font-size: 11.5px; color: var(--text-3); line-height: 1.5; }

hr { border: 0; border-top: 1px solid var(--border); margin: 2px 0; width: 100%; }

.primary-btn {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: .12s;
}
.primary-btn:hover { background: #2f5fe0; }
.primary-btn.small { padding: 6px 12px; font-size: 12.5px; align-self: flex-start; }

.danger-btn {
  padding: 8px 16px;
  background: #fff;
  color: var(--danger);
  border: 1px solid #f3c9ca;
  border-radius: 8px;
  cursor: pointer;
  margin-right: auto;
}
.danger-btn:hover { background: #fdf2f2; }

.check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.check input { width: auto; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.qr-box[hidden] { display: none; }
.qr-img img { display: block; width: 200px; height: 200px; border-radius: 6px; }
.qr-url {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

.answer {
  min-height: 60px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  line-height: 1.7;
  white-space: pre-wrap;
  font-size: 13px;
}
.answer:empty { display: none; }

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d3d6dd; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #bcbfc8; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    flex-direction: row; overflow-x: auto;
    padding: 8px; border-right: 0; border-top: 1px solid var(--border);
    z-index: 50;
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-item { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 10px; white-space: nowrap; }
  .nav-item .cnt { display: none; }
  .main { padding-bottom: 64px; }
  .search-wrap input { width: 140px; }
  .search-wrap input:focus { width: 160px; }
  .cards { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
}

/* ---------- 身材管理仪表盘 ---------- */
#view-body { overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 14px; }
.body-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.body-act {
  flex: 1; min-width: 120px; padding: 12px 8px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--panel); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; color: var(--text);
}
.body-act:hover { border-color: var(--accent); background: var(--accent-soft); }
.body-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.bc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; }
.bc-head b { font-size: 14px; }
.bc-head .ghost-btn { margin-left: auto; }
.bc-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.bc-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.bc-form input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--panel-2); color: var(--text); width: 100%;
}
.bc-inline { grid-template-columns: 1fr 1fr auto; }
.body-save {
  padding: 9px 22px; border: none; border-radius: 8px; background: var(--accent);
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
.body-save:hover { filter: brightness(1.08); }
.bc-sum { font-size: 13px; font-weight: 600; color: var(--text); margin: 8px 0 2px; }
.bc-note { font-size: 12px; color: var(--text-3); margin-top: 6px; line-height: 1.5; white-space: pre-wrap; }
.meal-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.meal-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--text-2); }
.meal-table td:last-child { text-align: right; color: var(--text); font-weight: 600; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-box { height: 220px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.body-log-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-2);
}
.body-log-item span:first-child { color: var(--text); white-space: nowrap; }
.body-log-item span:nth-child(2) { flex: 1; }
.body-del {
  border: none; background: none; color: var(--text-3); font-size: 16px;
  cursor: pointer; padding: 0 6px; border-radius: 6px;
}
.body-del:hover { color: var(--danger); background: var(--panel-2); }

@media (max-width: 720px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-box { height: 180px; }
  .bc-inline { grid-template-columns: 1fr 1fr; }
  .bc-inline .body-save { grid-column: span 2; }
}

/* ---------- 档案与目标 ---------- */
.targets-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }
.target-cell {
  background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 6px; text-align: center;
}
.tc-label { font-size: 11px; color: var(--text-3); margin-bottom: 2px; }
.tc-val { font-size: 16px; font-weight: 700; color: var(--text); }
.tc-unit { font-size: 11px; font-weight: 400; color: var(--text-3); }
.bc-form select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--panel-2); color: var(--text); width: 100%;
}
@media (max-width: 720px) { .targets-row { grid-template-columns: repeat(3, 1fr); } }

/* ---------- ECharts 与主题切换 ---------- */
.chart-div { width: 100%; height: 100%; }
.chart-box canvas, .chart-box div { min-width: 0; }
.theme-switch { display: flex; gap: 4px; margin-left: auto; }
.bc-head .theme-switch + .ghost-btn { margin-left: 6px; }
.theme-btn {
  padding: 4px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel-2); color: var(--text-2); cursor: pointer;
}
.theme-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 聊天贴图 ---------- */
.attach-btn {
  border: none; background: none; font-size: 20px; cursor: pointer;
  padding: 0 6px; opacity: .65; align-self: center;
}
.attach-btn:hover { opacity: 1; }
.attach-preview {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
  padding: 5px 10px; background: var(--accent-soft); border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px; color: var(--text-2);
}
.attach-remove {
  border: none; background: none; color: var(--text-3); font-size: 15px;
  cursor: pointer; padding: 0 4px; border-radius: 4px;
}
.attach-remove:hover { color: var(--danger); }

/* ---------- 修复：hidden 被 display:flex 覆盖 ---------- */
.attach-preview[hidden] { display: none !important; }
#view-body { display: none; }
#view-body.active { display: flex; overflow-y: auto; padding: 14px 18px; flex-direction: column; gap: 14px; }

/* ---------- 移动端抽屉导航（替代底部条） ---------- */
.menu-btn, .drawer, .drawer-mask { display: none; }

@media (max-width: 760px) {
  /* 底部条整个移除，避免误触 iOS 滑页 */
  .sidebar { display: none !important; }
  .main { padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important; }

  .menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; margin-right: 10px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--panel); color: var(--text); cursor: pointer;
  }
  .menu-btn:active { background: var(--accent-soft); }

  .drawer-mask {
    display: block; position: fixed; inset: 0; z-index: 190;
    background: rgba(15, 18, 28, 0.4); opacity: 0; transition: opacity .2s;
  }
  .drawer-mask.open { opacity: 1; }

  .drawer {
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
    width: min(76vw, 300px);
    background: var(--panel); box-shadow: 8px 0 32px rgba(0,0,0,.12);
    transform: translateX(-102%); transition: transform .22s ease;
    padding-top: env(safe-area-inset-top);
  }
  .drawer:not([hidden]) { display: flex; }
  .drawer.open { transform: translateX(0); }

  .drawer-head {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 20px 14px; font-size: 17px; font-weight: 700; color: var(--text);
  }
  .drawer-logo { font-size: 22px; }
  .drawer-nav { flex: 1; overflow-y: auto; padding: 4px 12px; }
  .drawer-item {
    display: flex; align-items: center; gap: 14px; width: 100%;
    padding: 15px 14px; margin: 2px 0;
    border: none; background: none; border-radius: 14px;
    font-size: 15.5px; font-weight: 600; color: var(--text);
    cursor: pointer; text-align: left; transition: background .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .drawer-item:active { background: var(--panel-2); }
  .drawer-item svg { color: var(--text-2); flex-shrink: 0; }
  .drawer-item.active { background: var(--accent-soft); color: var(--accent); }
  .drawer-item.active svg { color: var(--accent); }
  .drawer-foot { padding: 8px 12px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
}

/* ---------- 全局修复：hidden 属性必须真正隐藏（防止 display 规则覆盖） ---------- */
[hidden] { display: none !important; }

/* ---------- 卡片关闭按钮 ---------- */
.body-close {
  margin-left: auto; border: none; background: var(--panel-2); color: var(--text-3);
  font-size: 18px; line-height: 1; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; flex-shrink: 0;
}
.body-close:hover { color: var(--danger); }
.bc-head .body-close { margin-left: auto; }
.bc-head .body-close ~ .ghost-btn { margin-left: 6px; }

/* ---------- 页脚备案号 ---------- */
.site-footer {
  position: fixed;
  right: 10px;
  bottom: 4px;
  z-index: 40;
  font-size: 10px;
  opacity: 0.55;
  pointer-events: none;
}
.site-footer a {
  pointer-events: auto;
  color: inherit;
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; opacity: 1; }
