/* ============================================================
   消费与健康管家 - 样式（响应式，手机/电脑通用）
   ============================================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --yellow: #ca8a04;
  --orange: #ea580c;
  --red: #dc2626;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --nav-h: 64px;
  --top-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-top: var(--top-h);
  padding-bottom: var(--nav-h);
}

/* 顶部栏 */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h);
  background: var(--primary); color: #fff; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; box-shadow: 0 1px 6px rgba(0,0,0,0.1);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.logo-emoji { font-size: 22px; }
.topbar-user {
  background: rgba(255,255,255,0.18); padding: 4px 12px; border-radius: 20px;
  font-size: 13px; cursor: pointer;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn-dot { font-size: 10px; color: #4ade80; }
.conn-dot.off { color: #f87171; }

.conn-banner {
  background: #fef2f2; color: #b91c1c; padding: 10px 16px; font-size: 13px;
  text-align: center; border-bottom: 1px solid #fecaca;
}
.conn-banner.hidden { display: none; }

/* 内容区 */
.view { max-width: 920px; margin: 0 auto; padding: 16px; min-height: calc(100vh - var(--top-h) - var(--nav-h)); }
.page-title { font-size: 20px; font-weight: 700; margin: 4px 0 16px; }
.section-title { font-size: 15px; font-weight: 600; margin: 20px 0 10px; color: var(--muted); }

/* 卡片 */
.card {
  background: var(--card); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* 统计卡片 */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat {
  background: var(--card); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow); text-align: center;
}
.stat .num { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.green .num { color: var(--green); }
.stat.orange .num { color: var(--orange); }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 12px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s; width: 100%;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(0.98); }
.btn.secondary { background: #eef2ff; color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn.danger { background: #fee2e2; color: var(--red); }
.btn.small { padding: 8px 12px; font-size: 13px; width: auto; }

/* 上传区 */
.upload-zone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 28px 16px;
  text-align: center; cursor: pointer; background: #fafbff; transition: border-color .15s;
}
.upload-zone:active { border-color: var(--primary); }
.upload-zone .big-emoji { font-size: 44px; }
.upload-zone .hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
#previewImg { max-width: 100%; border-radius: 12px; margin-top: 12px; display: block; }

/* 表单 */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; background: #fff; color: var(--text);
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 90px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* 明细项 */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.items-table th { color: var(--muted); font-weight: 600; }
.items-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.tag.good { background: #dcfce7; color: var(--green); }
.tag.moderate { background: #fef9c3; color: var(--yellow); }
.tag.caution { background: #ffedd5; color: var(--orange); }
.tag.avoid { background: #fee2e2; color: var(--red); }
.cat-pill { background: #eef2ff; color: var(--primary); padding: 2px 10px; border-radius: 10px; font-size: 12px; }

/* 列表 */
.receipt-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 10px;
  cursor: pointer;
}
.receipt-item .thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: #eee; flex-shrink: 0; }
.receipt-item .thumb.placeholder { display: flex; align-items: center; justify-content: center; font-size: 24px; }
.receipt-item .info { flex: 1; min-width: 0; }
.receipt-item .merchant { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt-item .meta { font-size: 12px; color: var(--muted); }
.receipt-item .amount { font-weight: 700; font-size: 16px; }
.receipt-item .del { color: var(--red); font-size: 12px; cursor: pointer; padding: 6px; }

/* 明细编辑：行内删除按钮 */
.items-table .row-del {
  border: none; background: #fee2e2; color: var(--red);
  border-radius: 8px; width: 30px; height: 30px; font-size: 14px;
  cursor: pointer; line-height: 1; transition: background .15s;
}
.items-table .row-del:hover { background: #fecaca; }

/* 进度条 */
.progress { background: #e5e7eb; border-radius: 8px; height: 10px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* 健康打分环 */
.score-ring {
  width: 110px; height: 110px; border-radius: 50%; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  font-weight: 800; font-size: 32px; color: #fff;
}
.advice-item { padding: 10px 12px; background: #f8fafc; border-radius: 10px; margin-bottom: 8px; font-size: 14px; line-height: 1.6; }

/* 家庭成员 */
.member {
  display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--card);
  border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 10px;
}
.member .avatar { width: 44px; height: 44px; border-radius: 50%; background: #eef2ff; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.member .name { font-weight: 600; }
.member .role { font-size: 12px; color: var(--muted); }

/* 遮罩与提示 */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.overlay.hidden { display: none; }
.overlay-box {
  background: #fff; border-radius: 14px; padding: 28px; text-align: center; min-width: 220px;
}
.overlay-box #overlayText { margin-top: 14px; font-size: 14px; }
.spinner {
  width: 38px; height: 38px; border: 4px solid #e5e7eb; border-top-color: var(--primary);
  border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 14px; z-index: 200; opacity: 0; transition: opacity .25s; pointer-events: none;
  max-width: 80%;
}
.toast.show { opacity: 1; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .emoji { font-size: 50px; }

/* 详情弹层 */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal.hidden { display: none; }
.modal-sheet {
  background: #fff; width: 100%; max-width: 600px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px; animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-close { float: right; font-size: 22px; cursor: pointer; color: var(--muted); }

/* 桌面端适配 */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .view { padding: 24px; }
  .bottomnav {
    position: fixed; top: var(--top-h); bottom: auto; left: 0; right: 0; height: 52px;
    flex-direction: row; background: #fff; border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 6px rgba(0,0,0,0.04); padding: 0; z-index: 40;
  }
  .navbtn { flex-direction: row; gap: 8px; width: auto; height: 52px; }
  .navbtn span { font-size: 18px; }
  .navbtn label { font-size: 14px; }
  body { padding-top: calc(var(--top-h) + 52px); }
  .modal { align-items: center; }
  .modal-sheet { border-radius: 18px; }
}

/* 底部导航（移动端固定底部） */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  background: #fff; border-top: 1px solid var(--border); display: flex;
  z-index: 50; box-shadow: 0 -1px 8px rgba(0,0,0,0.04);
}
.navbtn {
  flex: 1; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); padding: 0;
}
.navbtn span { font-size: 20px; }
.navbtn label { font-size: 11px; }
.navbtn.active { color: var(--primary); font-weight: 600; }
