/* ============================================================
   WR 体重记录 · 设计系统（布局2 · 仪表盘式 · 奶油暖橙）
   主题色随体重趋势联动：health 绿 / ok 橙 / warn 深橙 / danger 红
   ============================================================ */
:root,
body.theme-ok {
  /* 默认档：奶油暖橙（1 个跨度上涨） */
  --primary: #E86A33;
  --primary-deep: #C2551F;
  --primary-soft: #FDE8D8;
  --primary-grad: linear-gradient(135deg, #F08545, #E86A33);
  --ring: rgba(232, 106, 51, .15);        /* 输入框 focus 光环 */
  --ring-strong: rgba(232, 106, 51, .5);  /* 键盘 focus-visible 描边 */
  --shadow: 0 6px 20px rgba(232, 106, 51, .10);
  --shadow-lg: 0 12px 32px rgba(232, 106, 51, .18);
  --shadow-btn: 0 6px 16px rgba(232, 106, 51, .28);
  --shadow-nav: 0 4px 12px rgba(232, 106, 51, .3);
  --shadow-modal: 0 20px 50px rgba(232, 106, 51, .3);
  --slider-off: #E8D5C3;                  /* 开关关闭态 */
  --dash-border: #EBC9A8;                 /* 上传虚线框 */
  --dash-bg: #FEFAF5;
  --dash-bg-hover: #FFF6EE;
  --chip-diff: rgba(255, 255, 255, .2);   /* 通用徽章底色（未用 diffClass 时） */
  --spark-bar: rgba(255, 255, 255, .4);   /* 趋势图普通柱 */
  --spark-latest: #fff;                   /* 趋势图最新柱 */
  --brand-fill: #E86A33;                  /* 品牌叶子图标 */
  --time-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23E86A33' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E"); /* time 控件时钟图标（随主题色） */

  --accent: #D97706;
  --success: #10B981;
  --success-bg: #D1FAE5;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --warn: #D97706;
  --warn-bg: #FEF3C7;
  --bg: #FBF7F2;
  --card: #FFFFFF;
  --text: #4A2C17;
  --muted: #A0775A;
  --border: #F3E3D3;
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

/* 健康向好：全部跨度下降/持平 → 绿色系 */
body.theme-health {
  --primary: #10B981;
  --primary-deep: #047857;
  --primary-soft: #D1FAE5;
  --primary-grad: linear-gradient(135deg, #34D399, #10B981);
  --ring: rgba(16, 185, 129, .15);
  --ring-strong: rgba(16, 185, 129, .5);
  --shadow: 0 6px 20px rgba(16, 185, 129, .12);
  --shadow-lg: 0 12px 32px rgba(16, 185, 129, .18);
  --shadow-btn: 0 6px 16px rgba(16, 185, 129, .28);
  --shadow-nav: 0 4px 12px rgba(16, 185, 129, .3);
  --shadow-modal: 0 20px 50px rgba(16, 185, 129, .3);
  --slider-off: #C7E5D8;
  --dash-border: #A7E3C8;
  --dash-bg: #F2FDF8;
  --dash-bg-hover: #E4FBF0;
  --spark-bar: rgba(255, 255, 255, .4);
  --spark-latest: #fff;
  --brand-fill: #10B981;
  --time-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2310B981' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}

/* 需要关注：2 个跨度上涨 → 深橙 */
body.theme-warn {
  --primary: #EA580C;
  --primary-deep: #C2410C;
  --primary-soft: #FDE3D1;
  --primary-grad: linear-gradient(135deg, #F97316, #EA580C);
  --ring: rgba(234, 88, 12, .15);
  --ring-strong: rgba(234, 88, 12, .5);
  --shadow: 0 6px 20px rgba(234, 88, 12, .12);
  --shadow-lg: 0 12px 32px rgba(234, 88, 12, .2);
  --shadow-btn: 0 6px 16px rgba(234, 88, 12, .3);
  --shadow-nav: 0 4px 12px rgba(234, 88, 12, .32);
  --shadow-modal: 0 20px 50px rgba(234, 88, 12, .32);
  --slider-off: #E5C6B0;
  --dash-border: #F2C6A0;
  --dash-bg: #FEF8F3;
  --dash-bg-hover: #FDEFE5;
  --spark-bar: rgba(255, 255, 255, .4);
  --spark-latest: #fff;
  --brand-fill: #EA580C;
  --time-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23EA580C' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}

/* 明显增长：≥3 个跨度上涨 → 红色系 */
body.theme-danger {
  --primary: #EF4444;
  --primary-deep: #B91C1C;
  --primary-soft: #FDE3E3;
  --primary-grad: linear-gradient(135deg, #F87171, #EF4444);
  --ring: rgba(239, 68, 68, .15);
  --ring-strong: rgba(239, 68, 68, .5);
  --shadow: 0 6px 20px rgba(239, 68, 68, .12);
  --shadow-lg: 0 12px 32px rgba(239, 68, 68, .2);
  --shadow-btn: 0 6px 16px rgba(239, 68, 68, .3);
  --shadow-nav: 0 4px 12px rgba(239, 68, 68, .32);
  --shadow-modal: 0 20px 50px rgba(239, 68, 68, .32);
  --slider-off: #E8C2C2;
  --dash-border: #F2B8B8;
  --dash-bg: #FEF6F6;
  --dash-bg-hover: #FDECEC;
  --spark-bar: rgba(255, 255, 255, .4);
  --spark-latest: #fff;
  --brand-fill: #EF4444;
  --time-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23EF4444' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom)); /* 给移动端底部Tab留空间 */
}
@media (min-width: 768px) { body { padding-bottom: 0; } }
/* 管理页无底部Tab，无需底部留白 */
body.admin-page { padding-bottom: 0; }

a { color: var(--primary-deep); }

/* ============ 顶部导航（桌面，仅 今日/历史 两项） ============ */
.topbar { display: none; }
@media (min-width: 768px) {
  .topbar {
    display: block;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .topbar-inner {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--primary-deep); }
  .brand svg { flex-shrink: 0; }
  .brand .brand-ico path { fill: var(--brand-fill); }
  .topnav { display: flex; gap: 6px; }
  .topnav a {
    display: flex; align-items: center; gap: 7px;
    text-decoration: none; color: var(--muted); font-weight: 600; font-size: .95rem;
    padding: 9px 16px; border-radius: 999px; transition: all .2s;
  }
  .topnav a:hover { background: var(--primary-soft); color: var(--primary-deep); }
  .topnav a.active { background: var(--primary-grad); color: #fff; box-shadow: var(--shadow-nav); }
}

/* ============ 管理页顶栏（独立，无用户入口） ============ */
.admin-topbar { position: sticky; top: 0; z-index: 100; background: var(--primary-grad); color: #fff; box-shadow: var(--shadow-lg); }
.admin-topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 0 16px; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
@media (min-width: 768px) { .admin-topbar-inner { padding: 0 24px; min-height: 64px; } }
.admin-topbar .brand { color: #fff; font-size: 1rem; }
.admin-topbar .brand svg { flex-shrink: 0; }
.admin-tag { font-size: .72rem; font-weight: 600; background: rgba(255, 255, 255, .2); padding: 3px 10px; border-radius: 999px; color: #fff; }
.admin-topbar .btn { width: auto; min-height: 36px; padding: 0 16px; font-size: .85rem; background: rgba(255, 255, 255, .2); color: #fff; box-shadow: none; }
.admin-topbar .btn:hover { background: rgba(255, 255, 255, .32); }

/* ============ 容器 & 页面标题 ============ */
.wrap { max-width: 1040px; margin: 0 auto; padding: 16px 16px 8px; }
@media (min-width: 768px) { .wrap { padding: 28px 24px 40px; } }

.page-title { display: none; }
@media (min-width: 768px) {
  .page-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
  .page-title h1 { font-size: 1.5rem; color: var(--text); }
  .page-title .date-chip { font-size: .85rem; color: var(--muted); background: #fff; border: 1px solid var(--border); padding: 6px 14px; border-radius: 999px; }
}

/* ============ 大数字 Hero 区 ============ */
.hero-dash {
  background: var(--primary-grad); border-radius: var(--radius);
  padding: 26px 22px; color: #fff; box-shadow: var(--shadow-lg);
  margin-bottom: 16px; position: relative; overflow: hidden;
}
.hero-dash::after { content: ""; position: absolute; right: -40px; top: -40px; width: 200px; height: 200px; border-radius: 50%; background: rgba(255, 255, 255, .1); }
.hero-dash::before { content: ""; position: absolute; right: 60px; bottom: -60px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.hero-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; position: relative; z-index: 1; }
.hero-top .greet { font-size: .9rem; color: rgba(255, 255, 255, .92); font-weight: 600; }
.hero-top .date-chip { background: rgba(255, 255, 255, .2); padding: 5px 12px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.hero-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; position: relative; z-index: 1; }
.hero-num { font-size: 2.4rem; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; white-space: nowrap; }
@media (min-width: 768px) { .hero-num { font-size: 4rem; line-height: 1; } }
.hero-num small { font-size: 1rem; font-weight: 600; }
@media (min-width: 768px) { .hero-num small { font-size: 1.2rem; } }
.hero-trend { text-align: right; flex-shrink: 0; }
.t-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .2); border-radius: 999px; padding: 7px 14px;
  font-weight: 800; font-size: 1.05rem; color: #fff;
}
.t-chip svg { flex-shrink: 0; }
.t-chip .t-label { font-size: .7rem; font-weight: 600; opacity: .92; }
.t-chip.up { background: rgba(255, 255, 255, .92); color: #C2410C; }
.t-chip.down { background: rgba(255, 255, 255, .92); color: #047857; }
.t-chip.flat { background: rgba(255, 255, 255, .25); color: #fff; }

/* 迷你趋势柱状图（div/i 模拟，非图表库） */
.spark { display: flex; align-items: flex-end; gap: 4px; height: 46px; margin-top: 18px; position: relative; z-index: 1; }
.spark i { flex: 1; min-width: 0; background: var(--spark-bar); border-radius: 4px 4px 0 0; height: 20%; transition: height .3s; }
.spark i.latest { background: var(--spark-latest); }

/* ============ 统计条 ============ */
.stat-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 640px) { .stat-strip { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat-card .sl { font-size: .76rem; color: var(--muted); font-weight: 600; }
.stat-card .sv { font-size: 1.35rem; font-weight: 800; margin-top: 4px; line-height: 1.2; letter-spacing: -.01em; }
.stat-card .sv small { font-size: .7rem; color: var(--muted); font-weight: 500; }
.stat-card .ss { font-size: .72rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-card.down .sv { color: var(--success); }
.stat-card.down { background: linear-gradient(180deg, #fff, #F0FDF4); border-color: #A7F3D0; }
.stat-card.up { background: linear-gradient(180deg, #fff, #FFF7ED); border-color: #FED7AA; }
.stat-card.up .sv { color: var(--danger); }
.stat-card.up .sl { color: var(--warn); }
.stat-card.flat .sv { color: var(--muted); }

/* ============ 卡片区块 ============ */
.section {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px; margin-bottom: 16px;
}
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-size: 1.1rem; display: flex; align-items: center; gap: 9px; }
.section-head h2 .ico {
  width: 32px; height: 32px; border-radius: 10px; background: var(--primary-soft);
  display: flex; align-items: center; justify-content: center; color: var(--primary-deep); flex-shrink: 0;
}
.section-head .more { font-size: .8rem; color: var(--muted); text-decoration: none; }

/* 双栏：左表单 右最近记录 */
.dash-cols { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .dash-cols { grid-template-columns: 1fr 1fr; align-items: start; } }

/* ============ 表单 ============ */
.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 7px; font-weight: 600; font-size: .92rem; }
.required { color: var(--danger); }
.hint { font-size: .78rem; color: var(--muted); margin-top: 6px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=time], textarea, select {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 16px; font-family: var(--font);
  color: var(--text); background: #FEFDFC; transition: all .2s; outline: none;
}
textarea { resize: vertical; min-height: 76px; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); background: #fff; }

/* time 控件：保留原生输入框，仅把右侧时钟图标替换为主题色（随 body.theme-* 联动） */
input[type=time]::-webkit-calendar-picker-indicator {
  background-image: var(--time-icon);
  background-size: contain;
  cursor: pointer;
}

/* 阶段行输入框前的名称标签（如「标题」「内容」「音量」） */
.tp-label {
  display: inline-flex;
  align-items: center;
  line-height: 44px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary-deep);
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 0 10px;
  flex-shrink: 0;
}

/* ============ 规则卡片内的字段网格 ============ */
/* 文字+开关横排（启用/已报不弹） */
.sw-txt {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
}
.sw-txt .switch { width: 42px; height: 26px; }
.sw-txt .slider:before { width: 20px; height: 20px; }
.sw-txt .switch input:checked + .slider:before { transform: translateX(16px); }

/* 字段网格：名称在输入框前面（横排） */
.stage-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px 12px;
  margin-bottom: 12px;
}
.stage-grid:last-child { margin-bottom: 0; }
.stage-grid .sg {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.stage-grid .sg label {
  flex-shrink: 0;
  font-size: .8rem;
  font-weight: 600;
  color: var(--primary-deep);
}
.stage-grid .sg input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  font-size: 15px;
}
/* 两行 grid 移动端各自 1 列；桌面端（≥900px）第一行 2 列、第二行 2 列 */
@media (min-width: 900px) {
  .stage-grid { grid-template-columns: 1fr 1fr; }
  .stage-grid + .stage-grid { grid-template-columns: 1fr 1fr; }
}

/* 自绘时间下拉面板（点击 time 输入框替代原生 picker，两端风格统一） */
.time-picker {
  position: absolute;
  z-index: 999;
  display: flex;
  gap: 6px;
  padding: 12px;
  background: #fff;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  animation: timePickerIn .18s ease;
}
@keyframes timePickerIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.time-picker .tp-col {
  width: 72px;
  height: 176px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #FEFDFC;
  scrollbar-width: thin;
  scrollbar-color: var(--primary-soft) transparent;
}
.time-picker .tp-col::-webkit-scrollbar { width: 6px; }
.time-picker .tp-col::-webkit-scrollbar-thumb { background: var(--primary-soft); border-radius: 3px; }
.time-picker .tp-item {
  display: block;
  width: 100%;
  padding: 8px 0;
  text-align: center;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font);
}
.time-picker .tp-item:hover { background: var(--primary-soft); color: var(--primary-deep); }
.time-picker .tp-item.sel { background: var(--primary-grad); color: #fff; }
.time-picker .tp-sep {
  align-self: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--muted);
}

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px dashed var(--border); }
.switch-row:last-child { border-bottom: none; }
.switch-row .txt { font-weight: 600; font-size: .92rem; }
.switch-row .txt small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--slider-off); border-radius: 30px; transition: .25s; cursor: pointer; }
.slider:before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .25s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* 上传区 */
.upload-zone {
  border: 2px dashed var(--dash-border); border-radius: var(--radius-sm); background: var(--dash-bg);
  padding: 18px; text-align: center; cursor: pointer; transition: all .2s; color: var(--muted);
}
.upload-zone:hover { border-color: var(--primary); background: var(--dash-bg-hover); }
.upload-zone .u-ico { width: 44px; height: 44px; margin: 0 auto 8px; border-radius: 14px; background: var(--primary-soft); display: flex; align-items: center; justify-content: center; color: var(--primary-deep); }
.upload-zone b { color: var(--primary-deep); }

/* ============ 按钮 ============ */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; border: none; border-radius: var(--radius-sm);
  font-size: 1.02rem; font-weight: 700; font-family: var(--font);
  background: var(--primary-grad); color: #fff; cursor: pointer; transition: all .2s;
  box-shadow: var(--shadow-btn); text-decoration: none;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active { transform: scale(.98); }
.btn-ghost { background: #fff; color: var(--primary-deep); border: 1.5px solid var(--border); box-shadow: none; min-height: 44px; }
.btn-sm { width: auto; min-height: 40px; padding: 0 16px; font-size: .88rem; box-shadow: none; }
.btn-danger { background: var(--danger); box-shadow: 0 6px 16px rgba(239, 68, 68, .25); }
.btn-test { background: var(--accent); box-shadow: 0 6px 16px rgba(217, 119, 6, .28); }
.btn-test:hover { filter: brightness(1.05); }

.form-actions { display: flex; gap: 12px; margin-top: 4px; }
.form-actions .btn { flex: 1; }

/* ============ 最近记录 / 月度列表（迷你卡） ============ */
.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-card { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.mini-card:last-child { border-bottom: none; }
.mini-date { width: 46px; flex-shrink: 0; text-align: center; background: var(--primary-soft); border-radius: 12px; padding: 5px 0; color: var(--primary-deep); }
.mini-date .d { font-size: .95rem; font-weight: 800; line-height: 1.2; }
.mini-date .m { font-size: .62rem; font-weight: 600; }
.mini-info { flex: 1; min-width: 0; }
.mini-info .w { font-weight: 800; font-size: 1rem; }
.mini-info .p { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-info .p-multi { font-size: .8rem; color: var(--muted); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.mini-info .n { font-size: .78rem; color: var(--muted); margin-top: 2px; word-break: break-word; }
.p-multi-inline { white-space: pre-wrap; word-break: break-word; }
.mini-status { display: flex; gap: 4px; flex-shrink: 0; margin-top: 2px; }
.dot { width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .62rem; font-weight: 800; }
.dot.ok { background: var(--success-bg); color: var(--success); }
.dot.no { background: var(--danger-bg); color: var(--danger); }
.dot.warn { background: var(--warn-bg); color: var(--warn); }
.see-all { margin-top: 12px; }

/* 历史页月度分组 */
.month-group { margin-bottom: 18px; }
.month-header { display: flex; align-items: center; gap: 10px; font-size: 1rem; color: var(--primary-deep); font-weight: 700; margin-bottom: 6px; }
.month-header::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* 历史页记录（保留完整徽章文字：任务✓/✗、运动✓/✗、进食超额/正常） */
.hist-mini { align-items: flex-start; }
.hist-mini .mini-info .w { color: var(--primary-deep); }
.hist-mini .mini-badges { margin-top: 6px; }
.hist-mini .mini-badges .badge { font-size: .72rem; padding: 3px 9px; }

.tag { display: inline-block; background: var(--primary-grad); color: #fff; font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-right: 6px; vertical-align: middle; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 600; padding: 4px 11px; border-radius: 999px; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.no { background: var(--danger-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.load-more { display: flex; justify-content: center; margin-top: 14px; }
.no-records { text-align: center; color: var(--muted); padding: 32px 0; }

/* 照片 */
.record-photo { margin-top: 8px; }
.photo-thumbnail { width: 100%; max-width: 240px; height: auto; max-height: 300px; object-fit: cover; border-radius: var(--radius-sm); cursor: pointer; box-shadow: var(--shadow); display: block; }
.load-image-btn {
  width: 100%; background: var(--dash-bg-hover); border: 1.5px dashed var(--dash-border); border-radius: var(--radius-sm);
  color: var(--primary-deep); font-size: .85rem; font-weight: 600; padding: 9px; cursor: pointer; min-height: 42px;
  transition: all .2s;
}
.load-image-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.current-photo { margin-bottom: 10px; }
.photo-preview { border-radius: var(--radius-sm); object-fit: cover; box-shadow: var(--shadow); }

/* ============ 历史页 Hero 数据小卡 ============ */
.hist-hero { padding: 22px 20px; }
.hist-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; position: relative; z-index: 1; margin-top: 14px; }
@media (min-width: 640px) { .hist-stats { grid-template-columns: repeat(4, 1fr); } }
.glass-card { background: rgba(255, 255, 255, .18); border-radius: 14px; padding: 12px 14px; text-align: center; backdrop-filter: blur(4px); }
.glass-card .gl { font-size: .72rem; color: rgba(255, 255, 255, .9); font-weight: 600; }
.glass-card .gv { font-size: 1.35rem; font-weight: 800; color: #fff; line-height: 1.25; margin-top: 2px; }
.glass-card .gv small { font-size: .72rem; font-weight: 500; opacity: .85; }
.glass-card.up .gv { color: #FFE0D1; }
.glass-card.down .gv { color: #D9FBE9; }
.glass-card.flat .gv { color: #fff; }

/* ============ 管理 ============ */
.admin-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.admin-toolbar h2 { font-size: 1.05rem; }
.admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; background: var(--primary-soft); padding: 6px; border-radius: 14px; }
.admin-tab { flex: 1; text-align: center; text-decoration: none; color: var(--muted); padding: 9px 12px; border-radius: 10px; font-size: .92rem; font-weight: 600; transition: all .2s; }
.admin-tab.active, .admin-tab:hover { background: var(--primary-grad); color: #fff; box-shadow: var(--shadow-nav); }

.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.admin-card-title { font-weight: 700; font-size: .95rem; color: var(--primary-deep); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-weight { color: var(--text); font-weight: 700; }
.admin-card-plan, .admin-card-note { font-size: .85rem; color: var(--text); word-break: break-word; }
.admin-card-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-card-actions form { flex: 1; min-width: 0; }
.admin-card-actions .btn { flex: 1; }

.login-section { max-width: 400px; margin: 1.5rem auto; }
.login-form { width: 100%; }

/* 通知渠道 */
.notify-card { gap: 8px; }
.type-badge, .status-badge, .pri-badge { display: inline-flex; align-items: center; font-size: .72rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.pri-badge { background: var(--primary-soft); color: var(--primary-deep); }
.type-qmsg { background: var(--success-bg); color: var(--success); }
.type-pushplus { background: var(--warn-bg); color: var(--warn); }
.type-wxpusher { background: var(--primary-soft); color: var(--primary-deep); }
.status-badge.on { background: var(--success-bg); color: var(--success); }
.status-badge.off { background: #F1E6DB; color: var(--muted); }
.param-summary { font-family: Consolas, Monaco, monospace; font-size: .8rem; letter-spacing: .02em; color: var(--muted); word-break: break-word; }

.field-group { display: none; }
.field-group.active { display: block; }

/* ============ 提示横幅 ============ */
.error-message { background: var(--danger-bg); color: var(--danger); border: 1px solid #FECACA; border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid #A7F3D0; border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: .9rem; display: flex; align-items: center; gap: 8px; }

/* agent_token 显示卡片（主题暖色，token 自动换行，无异常高度） */
.token-card {
  background: var(--primary-soft);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.token-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: .88rem; color: var(--primary-deep);
  margin-bottom: 8px;
}
.token-val {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: .85rem;
  color: var(--text);
  background: rgba(255,255,255,.6);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.6;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.token-tip { font-size: .78rem; color: var(--muted); margin-top: 8px; }

/* ============ 模态框 ============ */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(74, 44, 23, .5);
  z-index: 1000; align-items: center; justify-content: center; padding: 20px;
}
.modal[style*="display: block"], .modal[style*="display:flex"], .modal[style*="display: flex"] { display: flex !important; }
.modal.visible { display: flex !important; }
.modal-content { background: #fff; padding: 22px; border-radius: var(--radius); width: 100%; max-width: 380px; position: relative; box-shadow: var(--shadow-modal); }
.modal-content h3 { text-align: center; margin-bottom: 18px; color: var(--text); }
.close-btn { position: absolute; top: 12px; right: 12px; font-size: 24px; font-weight: 700; color: var(--muted); cursor: pointer; background: var(--bg); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.close-btn:hover { background: var(--primary-soft); color: var(--primary-deep); }
.modal-btn { width: 100%; margin-bottom: 10px; background: var(--primary-grad); color: #fff; border: none; cursor: pointer; min-height: 50px; font-size: 1rem; font-weight: 700; border-radius: var(--radius-sm); font-family: var(--font); }
.modal-btn:last-child { margin-bottom: 0; }
.modal-btn.cancel { background: var(--bg); color: var(--text); }
#modalImg { max-width: 100%; max-height: 80vh; object-fit: contain; display: block; margin: 0 auto; border-radius: var(--radius-sm); }

/* ============ 移动端底部 Tab（仅 今日/历史 两项） ============ */
.bottomnav { display: none; }
@media (max-width: 767px) {
  .bottomnav {
    display: block;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav-inner { display: flex; max-width: 480px; margin: 0 auto; }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 7px; text-decoration: none; color: var(--muted); font-size: .68rem; font-weight: 600; transition: color .2s; }
  .bottomnav a svg { width: 24px; height: 24px; }
  .bottomnav a.active { color: var(--primary-deep); }
  .bottomnav a.active svg circle, .bottomnav a.active svg path { stroke: var(--primary-deep); fill: var(--primary-deep); }
}

/* ============ 提醒规则卡片（嵌套规则树） ============ */
.rule-card {
  background: #fff;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

/* 规则头：层级编号 + 启用开关 + 删除 */
/* flex-wrap + 标签禁换行：窄屏下整体折到第二行，而不是把「启用」「当天只弹一次」
   挤成竖排单字（加了「文本」按钮后 5 个元素在手机宽度下放不下一行）。 */
.rule-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.rule-head .sw-txt { white-space: nowrap; }
.rule-head .btn { flex: none; white-space: nowrap; }
.rule-idx {
  font-size: .82rem;
  font-weight: 800;
  color: var(--primary-deep);
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 4px 10px;
}

/* 子规则容器：左侧缩进轨 + 更浅的描边，直观表达嵌套层级 */
.rule-children {
  margin: 12px 0 0 14px;
  padding-left: 12px;
  border-left: 2px solid var(--primary-soft);
}
.rule-children .rule-card {
  border-color: var(--dash-border);
  box-shadow: none;
  background: var(--dash-bg);
}
.rule-add-child { margin-top: 10px; }

/* 规则工具条：添加规则 + 文本编辑 */
.rule-toolbar {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* 两个控件等宽等高：内容字数不同（「＋ 添加规则」/「文本编辑」），
   用同一 min-width + 均分剩余空间，避免一宽一窄看着别扭。 */
.rule-toolbar .btn {
  flex: 1 1 0;
  min-width: 132px;
  justify-content: center;
}

/* 规则文本编辑模式（2026-11-03）：与表单区互斥显示 */
.rule-text { margin-top: 10px; }
#rule-text-box textarea { white-space: pre; overflow: auto; min-height: 320px; }
.rule-text-tip {
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.rule-text textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  resize: vertical;
  background: #fff;
  color: var(--text);
}
.rule-text textarea:focus { outline: none; border-color: var(--primary); }
.rule-text-actions { margin-top: 8px; display: flex; gap: 8px; }

/* ---- 条件（JSON）输入 ---- */
/* 标签 + 片段按钮同一行；窄屏自动换行，不挤压 */
.cond-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.cond-row .tp-label { line-height: 32px; }
/* 排序：与同级规则互换（下拉 + 替换按钮） */
.rule-swap-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.rule-swap-row .tp-label { line-height: 32px; }
.rule-swap-sel {
  width: auto;
  min-width: 130px;
  max-width: 220px;
  padding: 6px 10px;
  font-size: .82rem;
  min-height: 32px;
}
.rule-swap-row .btn { min-height: 32px; padding: 0 12px; font-size: .8rem; }
/* 排序改动后、尚未点「保存设置」时的提示条 */
.rule-dirty-tip {
  margin: 10px 0;
  padding: 9px 12px;
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: .82rem;
  font-weight: 600;
}
.cond-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.cond-actions .btn {
  min-height: 32px;
  padding: 0 12px;
  font-size: .8rem;
}
/* 条件框独占整行：等宽字体便于对齐核对，输入体验优先于视觉对称 */
.cond-json {
  display: block;
  width: 100%;
  /* ⚠️ 不要给 .cond-json 写 height/min-height：高度由 JS 按「内容行数 + 2 行」算
     （见 admin_agent.html 的 autoGrowCond）。全局 `textarea{min-height:76px}` 会
     干扰测量，autoGrowCond 量高前会临时把它清掉。 */
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  /* pre-wrap：长行按宽度自动换行（原来 pre + overflow-x 是横向滚动，读条件要左右拖） */
  white-space: pre-wrap;
  /* anywhere：JSON 里连续的长 token（如超长字符串）也能断开，否则撑破容器 */
  overflow-wrap: anywhere;
  overflow-x: hidden;
  /* 高度由 JS 按「内容行数 + 2 行」自动调整，见 autoGrowCond()。
     ⚠️ height 必须留空：若在 CSS 写成 auto 会盖过 JS 的行内高度（CSS 优先于行内），
     框就永远只有 rows 属性撑出的高度。rows="3" 仅作无 JS 时的兜底。
     ⚠️ transition 必须排除 height/min-height：全局 `transition: all .2s` 会让高度
     处于动画中间值，autoGrowCond 量高度时会读到未收敛的 76px（全局 min-height，
     style.css:268），把空框算成 5 行。只保留取景框的过渡效果。 */
  transition: border-color .2s, box-shadow .2s, background-color .2s;
  /* ⚠️ min-height 必须是 0：全局 `textarea { min-height: 76px }`（style.css:268）
     会把框撑到 76px，autoGrowCond 量出来就是 3 行而不是 1 行，+2 行后变 5 行。
     这里显式覆盖掉，高度完全交给 JS。 */
  min-height: 0;
  overflow-y: hidden;
  /* ⚠️ resize 必须是 none：高度完全由 autoGrowCond 按内容算（含自动收缩）。
     若开放 vertical 拖拽，用户拖完的高度会被下一次输入立刻弹回，看起来像坏了；
     而用 min-height 去「钉住」用户拖的高度又会让内容删空后【缩不回去】
     （用户 2026-09-30 报的 bug）。所以不提供手动拖拽。 */
  resize: none;
  background: #fff;
  color: var(--text);
  box-sizing: border-box;
  margin-bottom: 10px;
}
.cond-json:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

/* ---- 字段说明（折叠） ---- */
.rule-help {
  margin-top: 10px;
  border: 1px dashed var(--dash-border);
  border-radius: var(--radius-sm);
  background: var(--dash-bg);
  padding: 10px 12px;
}
.rule-help > summary {
  cursor: pointer;
  font-size: .84rem;
  font-weight: 700;
  color: var(--primary-deep);
}
.rule-help-body { padding-top: 10px; }
.rule-help-body p {
  font-size: .82rem;
  color: var(--text);
  line-height: 1.6;
  margin: 0 0 8px;
}
.rule-sample {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 10px;
  overflow-x: auto;
  color: var(--text);
}
.rule-fields {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
  margin-bottom: 8px;
}
.rule-fields th, .rule-fields td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.rule-fields th { color: var(--primary-deep); font-weight: 700; white-space: nowrap; }
.rule-fields code, .rule-help-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .95em;
  background: var(--primary-soft);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--primary-deep);
}
.rule-tip {
  font-size: .8rem !important;
  color: var(--muted) !important;
  margin: 0 !important;
}

/* ---- 判定口径说明（常显，不折叠） ---- */
/* 规则说明区：口径说明与「条件 JSON 怎么写」是同一组，样式统一为虚线框，
   与上方的规则卡片（实线卡片）区分开，避免看起来像「添加规则」的子内容。 */
.rule-note {
  margin-top: 10px;
  border: 1px dashed var(--dash-border);
  border-left: 3px solid var(--primary-deep);
  border-radius: var(--radius-sm);
  background: var(--dash-bg);
  padding: 12px 14px;
  font-size: .82rem;
  line-height: 1.7;
  color: var(--text);
}
.rule-note > b {
  display: block;
  margin-bottom: 6px;
  font-size: .84rem;
  color: var(--primary-deep);
}
/* 列表与标题左对齐：padding-left 用 1.1em 只留序号缩进，视觉上与标题同一条左边线。
   原 18px 让每行正文整体右移，窄屏下每行只剩十来个字，读起来很挤。 */
.rule-note ul { margin: 0; padding-left: 1.1em; }
.rule-note li { margin-bottom: 5px; }
.rule-note li:last-child { margin-bottom: 0; }
.rule-note code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .95em;
  background: var(--primary-soft);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--primary-deep);
}

/* ============ 可访问性 ============ */
:focus-visible { outline: 3px solid var(--ring-strong); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
