/* ============ 控糖助手 SugarCalc ============ */
:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #ccfbf1;
  --bg: #f6f8fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --low: #16a34a;
  --low-bg: #dcfce7;
  --mid: #d97706;
  --mid-bg: #fef3c7;
  --high: #dc2626;
  --high-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.7; font-size: 15px;
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 18px; }
@media (min-width: 1400px) {
  .container { max-width: 1280px; }
  .hero h1 { font-size: 40px; }
  .hero-search { max-width: 580px; }
}
@media (min-width: 1750px) {
  .container { max-width: 1440px; }
  .hero h1 { font-size: 44px; }
  .hero-search { max-width: 620px; }
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- 顶部导航 ---------- */
.nav {
  background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 62px; }
.nav-right { display: flex; align-items: center; gap: 6px; }
.font-size-ctrl { display: flex; gap: 4px; flex-shrink: 0; }
.font-toggle {
  border: 1.5px solid var(--line); background: #fff; color: var(--primary-dark);
  border-radius: 999px; min-width: 40px; height: 34px; font-size: 14px; font-weight: 800;
  cursor: pointer; line-height: 1; padding: 0 8px;
}
.font-toggle:hover { background: var(--primary-light); }
.font-toggle:disabled { color: #cbd5e1; cursor: not-allowed; background: #f8fafc; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none !important; }
.logo-icon { font-size: 26px; }
.logo-text { font-size: 18px; font-weight: 700; color: var(--text); display: flex; flex-direction: column; line-height: 1.2; }
.logo-text small { font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: .5px; }
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  padding: 8px 14px; border-radius: 999px; color: var(--text); font-weight: 500; text-decoration: none !important;
}
.nav-links a:hover { background: var(--primary-light); color: var(--primary-dark); }
.nav-links a.active { background: var(--primary); color: #fff; }
@media (max-width: 720px) {
  .nav-inner { flex-wrap: wrap; height: auto; padding: 10px 0; }
  .nav-links { width: 100%; overflow-x: auto; }
}

/* ---------- 首页 Hero ---------- */
.hero {
  background: linear-gradient(135deg, #0f766e 0%, #0d9488 55%, #14b8a6 100%);
  color: #fff; padding: 64px 0 56px; text-align: center;
}
.hero h1 { font-size: 34px; margin-bottom: 14px; letter-spacing: 1px; }
.hero-sub { opacity: .92; margin-bottom: 26px; font-size: 15.5px; }
.hero-search { display: flex; max-width: 520px; margin: 0 auto; border-radius: 999px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.hero-search input {
  flex: 1; border: none; padding: 15px 22px; font-size: 15.5px; outline: none; min-width: 0;
}
.hero-search button {
  border: none; background: #134e4a; color: #fff; padding: 0 28px; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.hero-search button:hover { background: #115e59; }
.hero-stats { display: flex; justify-content: center; gap: 40px; margin-top: 34px; flex-wrap: wrap; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats b { font-size: 26px; }
.hero-stats span { font-size: 12.5px; opacity: .85; }

/* ---------- 通用区块 ---------- */
.section { margin: 40px 0; }
.section-title { font-size: 20px; margin-bottom: 16px; }
.section-title small { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.more-link { font-size: 13.5px; }

.page-head { background: #fff; border-bottom: 1px solid var(--line); padding: 34px 0 26px; margin-bottom: 26px; }
.page-head h1 { font-size: 26px; }
.page-head h1 small { font-size: 13px; color: var(--muted); font-weight: 400; }
.page-head p { color: var(--muted); margin-top: 6px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}

/* ---------- 分类卡片 ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.cat-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); text-align: center;
  padding: 18px 8px 14px; text-decoration: none !important; transition: .15s;
}
.cat-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.cat-icon { font-size: 30px; display: block; margin-bottom: 6px; }
.cat-name { font-size: 13.5px; font-weight: 600; color: var(--text); }

/* ---------- 首页速查 ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.quick-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 5px; text-decoration: none !important; transition: .15s;
}
.quick-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.quick-emoji { font-size: 32px; }
.quick-name { font-weight: 600; font-size: 14px; color: var(--text); }

/* ---------- 徽章 ---------- */
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.sugar-low, .gi-low, .gl-low { background: var(--low-bg); color: var(--low); }
.sugar-mid, .gi-mid, .gl-mid { background: var(--mid-bg); color: var(--mid); }
.sugar-high, .gi-high, .gl-high { background: var(--high-bg); color: var(--high); }
.sugar-none { background: #f1f5f9; color: var(--muted); }
.pill.on { background: var(--low-bg); color: var(--low); }
.pill.off { background: var(--line); color: var(--muted); }
.quick-sugar { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; }

/* ---------- 双栏 ---------- */
.two-col { display: grid; grid-template-columns: 1.8fr 1fr; gap: 26px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 文章列表(首页) ---------- */
.article-list { display: flex; flex-direction: column; gap: 12px; }
.article-item {
  display: flex; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; text-decoration: none !important; transition: .15s;
}
.article-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.article-cover { font-size: 34px; flex-shrink: 0; }
.article-info h3 { font-size: 15.5px; margin-bottom: 4px; color: var(--text); }
.article-info p {
  font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.article-meta { font-size: 12px; color: var(--muted); }

.side-note { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.top-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.top-list li {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 13.5px;
}
.top-list li a { text-decoration: none !important; color: var(--text); font-weight: 500; }
.top-sugar { color: var(--high); font-size: 13px; }

/* ---------- 文章页 ---------- */
.article-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.article-card {
  display: flex; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; text-decoration: none !important; transition: .15s;
}
.article-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.article-card-cover { font-size: 40px; flex-shrink: 0; }
.article-card-body h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.article-card-body p {
  font-size: 13px; color: var(--muted); margin-bottom: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.article-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 26px; align-items: start; padding-top: 20px; }
@media (max-width: 860px) { .article-wrap { grid-template-columns: 1fr; } }
.back-link { display: inline-block; margin-bottom: 14px; font-size: 13.5px; }
.article-content h1 { font-size: 23px; line-height: 1.4; }
.article-head { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.article-head .article-cover { font-size: 46px; }
.article-content h2 { font-size: 19px; margin: 26px 0 10px; padding-left: 10px; border-left: 4px solid var(--primary); }
.article-content h3 { font-size: 16px; margin: 18px 0 8px; }
.article-content p { margin: 10px 0; }
.article-content ul, .article-content ol { padding-left: 24px; margin: 10px 0; }
.article-content blockquote {
  border-left: 4px solid var(--primary); background: var(--primary-light);
  padding: 10px 16px; border-radius: 0 10px 10px 0; margin: 14px 0; color: var(--primary-dark); font-weight: 600;
}
.article-content table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.article-content th, .article-content td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.article-content th { background: var(--primary-light); color: var(--primary-dark); }
.refs-box { margin-top: 26px; padding: 16px; background: #f8fafc; border: 1px dashed var(--line); border-radius: 10px; }
.refs-box h3 { font-size: 14.5px; margin-bottom: 8px; }
.refs-box ol { padding-left: 22px; font-size: 12.5px; color: var(--muted); }
.refs-box li { margin: 4px 0; }
.side-articles { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 10px; }
.side-articles h3 { font-size: 15px; }
.side-article {
  display: flex; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: 13.5px; text-decoration: none !important; color: var(--text);
}
.side-article span { flex-shrink: 0; }
.side-article:hover { border-color: var(--primary); }

/* ---------- 食物库 ---------- */
.filter-bar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.filter-search { display: flex; gap: 10px; }
.filter-search input {
  flex: 1; padding: 11px 16px; border: 1px solid var(--line); border-radius: 10px; font-size: 14.5px; outline: none;
}
.filter-search input:focus { border-color: var(--primary); }
.filter-search button {
  padding: 0 26px; border: none; background: var(--primary); color: #fff; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chips a {
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff;
  font-size: 13px; text-decoration: none !important; color: var(--text);
}
.cat-chips a:hover { border-color: var(--primary); }
.cat-chips a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.table-card { padding: 0; overflow: hidden; }
.legend-note { padding: 12px 16px; margin: 0; font-size: 12.5px; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--line); line-height: 1.8; }
.legend-note b { color: var(--text); }
.food-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.food-table thead th {
  background: #f1f5f9; text-align: left; padding: 12px 16px; font-size: 12.5px;
  color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.food-table tbody td { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; }
.food-table tbody tr { cursor: pointer; }
.food-table tbody tr:hover { background: #f0fdfa; }
.food-name-cell { font-weight: 600; white-space: nowrap; }
.food-emoji { margin-right: 8px; }
.empty-tip { text-align: center; color: var(--muted); padding: 34px 0 !important; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 22px 0 40px; font-size: 13.5px; }
.pagination a { padding: 7px 16px; border: 1px solid var(--line); border-radius: 999px; background: #fff; text-decoration: none !important; }
.pagination a:hover { border-color: var(--primary); }

/* ---------- 食物详情 ---------- */
.detail-wrap { padding-top: 20px; }
.detail-head { display: flex; flex-direction: column; gap: 10px; }
.detail-title { display: flex; align-items: center; gap: 18px; }
.detail-title h1 { font-size: 26px; }
.detail-emoji { font-size: 54px; }
.note { background: var(--mid-bg); color: #92400e; border-radius: 10px; padding: 10px 16px; font-size: 13.5px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin: 18px 0; }
.detail-grid .card h3 { font-size: 15.5px; margin-bottom: 14px; }
.nut-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.nut { background: #f8fafc; border-radius: 10px; padding: 12px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.nut b { font-size: 19px; }
.nut span { font-size: 12px; color: var(--muted); }
.nut.main { background: var(--primary-light); }
.nut.main b { color: var(--primary-dark); }
.nut-gi { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 13.5px; }
.serving-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.serving-grid > div { text-align: center; background: #f8fafc; border-radius: 10px; padding: 12px 6px; }
.serving-grid b { display: block; font-size: 18px; }
.serving-grid span { font-size: 12px; color: var(--muted); }
.calc-cta {
  display: block; text-align: center; margin-top: 14px; padding: 10px; border-radius: 10px;
  background: var(--primary); color: #fff; font-weight: 600; text-decoration: none !important;
}
.calc-cta:hover { background: var(--primary-dark); }
.source-card p { font-size: 13.5px; margin: 8px 0; }

/* ---------- 计算器 ---------- */
.calc-layout { display: grid; grid-template-columns: 1.9fr 1fr; gap: 20px; align-items: start; padding-bottom: 40px; }
@media (max-width: 900px) { .calc-layout { grid-template-columns: 1fr; } }
.search-row input {
  width: 100%; padding: 13px 18px; border: 2px solid var(--line); border-radius: 10px;
  font-size: 15px; outline: none;
}
.search-row input:focus { border-color: var(--primary); }
.search-box { position: relative; margin-bottom: 16px; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
  max-height: 360px; overflow-y: auto;
}
.sr-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: #f0fdfa; }
.sr-emoji { font-size: 22px; }
.sr-name { font-weight: 600; flex: 1; }
.sr-name small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.sr-sugar { font-size: 12px; color: var(--muted); }
.quick-add { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.quick-add button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 13px;
  font-size: 13px; cursor: pointer;
}
.quick-add button:hover { border-color: var(--primary); background: #f0fdfa; }
.fav-bar { background: var(--primary-light); border-radius: 10px; padding: 8px 12px; }
.fav-bar button { border-color: var(--primary); }
.fav-img { width: 20px; height: 20px; border-radius: 6px; object-fit: cover; vertical-align: -4px; margin-right: 2px; }
.fav-star {
  border: none; background: none; font-size: 20px; color: #cbd5e1; cursor: pointer; padding: 4px 8px; flex-shrink: 0; line-height: 1;
}
.fav-star.on { color: #f59e0b; }
.fav-star:hover { color: #f59e0b; }

.calc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.calc-table thead th { background: #f1f5f9; text-align: left; padding: 11px 12px; font-size: 12px; color: var(--muted); }
.calc-table tbody td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; }
.calc-table .food-name-cell { white-space: nowrap; }
.grams-input {
  width: 82px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; text-align: right;
}
.grams-input:focus { border-color: var(--primary); outline: none; }
.remove-btn {
  border: none; background: none; color: var(--high); font-size: 16px; cursor: pointer; padding: 4px 8px;
}
.calc-actions { display: flex; align-items: center; gap: 14px; padding: 14px 16px; flex-wrap: wrap; }
.calc-hint { font-size: 12px; color: var(--muted); }
.btn-ghost {
  display: inline-block; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 18px; font-size: 13.5px; cursor: pointer; text-decoration: none !important; color: var(--text);
}
.btn-ghost:hover { border-color: var(--high); color: var(--high); }
.btn-primary {
  display: inline-block; border: none; background: var(--primary); color: #fff; border-radius: 10px;
  padding: 10px 22px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none !important;
}
.btn-primary:hover { background: var(--primary-dark); }

.total-card { position: sticky; top: 80px; }
.total-card h3 { font-size: 16px; margin-bottom: 14px; }
.total-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.total-item { background: #f8fafc; border-radius: 10px; padding: 12px; text-align: center; display: flex; flex-direction: column; }
.total-item b { font-size: 21px; color: var(--primary-dark); }
.total-item span { font-size: 12px; color: var(--muted); }
.gl-badge {
  margin-top: 14px; text-align: center; padding: 10px; border-radius: 10px;
  font-weight: 700; font-size: 14.5px;
}
.gl-badge.none { background: #f1f5f9; color: var(--muted); font-weight: 400; }
.gl-badge.low { background: var(--low-bg); color: var(--low); }
.gl-badge.mid { background: var(--mid-bg); color: var(--mid); }
.gl-badge.high { background: var(--high-bg); color: var(--high); }
.advice { margin-top: 10px; font-size: 12.5px; color: var(--muted); text-align: center; }
.legend-card { margin-top: 16px; }
.legend-card h3 { font-size: 15px; margin-bottom: 10px; }
.legend-card ul { padding-left: 20px; font-size: 13px; }
.legend-card li { margin: 6px 0; }

/* ---------- 后台 ---------- */
.auth-wrap { display: flex; justify-content: center; padding: 60px 0; }
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px; }
.auth-card h2 { font-size: 19px; margin-bottom: 6px; }
.auth-card label { font-size: 13.5px; font-weight: 600; }
.auth-card input { padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; font-size: 14.5px; }
.form-error { background: var(--high-bg); color: var(--high); border-radius: 8px; padding: 8px 14px; font-size: 13.5px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table thead th { background: #f1f5f9; text-align: left; padding: 12px 16px; font-size: 12.5px; color: var(--muted); }
.admin-table tbody td { padding: 11px 16px; border-bottom: 1px solid #f1f5f9; }
.row-actions { display: flex; gap: 12px; align-items: center; }
.row-actions form { display: inline; }
.row-actions button.danger { border: none; background: none; color: var(--high); cursor: pointer; font-size: 13.5px; padding: 0; }

.edit-wrap { padding-top: 20px; }
.edit-card { display: flex; flex-direction: column; gap: 12px; }
.edit-card h2 { font-size: 19px; }
.edit-card label { font-size: 13.5px; font-weight: 600; }
.edit-card input[type=text], .edit-card textarea {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; outline: none; resize: vertical;
}
.edit-card input:focus, .edit-card textarea:focus { border-color: var(--primary); }
.edit-card textarea[name=content] { font-family: Consolas, Monaco, "Courier New", monospace; font-size: 13.5px; line-height: 1.8; }
.edit-row { display: grid; grid-template-columns: 1fr 130px; gap: 12px; }
.edit-row.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 720px) { .edit-row, .edit-row.three { grid-template-columns: 1fr; } }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 500 !important; }
.check-label input { width: 16px; height: 16px; }
.edit-actions { display: flex; gap: 12px; }

/* ---------- 页脚 ---------- */
.footer { background: #fff; border-top: 1px solid var(--line); padding: 28px 0; margin-top: 50px; }
.footer p { font-size: 12.5px; color: var(--muted); margin: 5px 0; }
.footer .copy { margin-top: 12px; }

/* ============ 食物图片 ============ */
.food-img { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; margin-right: 8px; vertical-align: middle; flex-shrink: 0; }
.sr-img { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.detail-img { width: 86px; height: 86px; border-radius: 16px; object-fit: cover; box-shadow: var(--shadow); flex-shrink: 0; }

/* ============ 药品库 ============ */
.med-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.med-card { text-decoration: none !important; color: var(--text); transition: .15s; display: flex; flex-direction: column; gap: 4px; padding: 18px; }
.med-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.med-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.med-name { font-size: 17px; font-weight: 700; }
.med-brands { font-size: 12.5px; }
.med-effect, .med-side { font-size: 13px; color: var(--muted); }
.med-effect b, .med-side b { color: var(--text); }
.warn-inline { color: #92400e; background: var(--mid-bg); border-radius: 8px; padding: 6px 12px; display: inline-block; margin-top: 10px; font-size: 13px; }
.med-detail-head { display: flex; flex-direction: column; gap: 12px; }
.med-effect-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.med-effect-bar span { background: var(--primary-light); color: var(--primary-dark); border-radius: 10px; padding: 10px 14px; font-size: 13.5px; }
.med-effect-bar b { display: block; font-size: 12px; opacity: .8; margin-bottom: 2px; }
.med-grid-detail .card h3 { font-size: 15.5px; margin-bottom: 8px; }
.med-text { font-size: 14px; line-height: 1.8; }
.med-text.warn { color: var(--high); background: var(--high-bg); border-radius: 8px; padding: 10px 14px; }
.exercise-card { border-color: var(--primary); }
.disclaimer-card { margin: 30px 0 50px; background: #fffbeb; border-color: #fde68a; }
.disclaimer-card h3 { font-size: 15.5px; margin-bottom: 8px; }
.disclaimer-card p, .disclaimer-card li { font-size: 13.5px; line-height: 1.8; }
.disclaimer-card ul { padding-left: 20px; }

/* ============ 运动页 ============ */
.ex-tips { margin-top: 14px; }
.ex-tips h3 { font-size: 15.5px; margin-bottom: 8px; }
.ex-tips li { font-size: 14px; margin: 7px 0; }
.ex-steps { padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.ex-steps li { font-size: 14px; line-height: 1.8; }

/* ============ 资源页 ============ */
.res-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.res-card { text-decoration: none !important; color: var(--text); transition: .15s; display: flex; flex-direction: column; gap: 4px; }
.res-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.res-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.res-title { font-size: 15px; font-weight: 700; line-height: 1.5; }
.res-pub { font-size: 12.5px; color: var(--primary-dark); }
.res-why { font-size: 13px; }
@media (max-width: 720px) {
  .med-grid, .res-list { grid-template-columns: 1fr; }
  .med-grid-detail { grid-template-columns: 1fr; }
}

/* ============ 首页工具卡 ============ */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tool-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  text-decoration: none !important; color: var(--text); padding: 20px 14px; transition: .15s;
}
.tool-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.tool-card b { font-size: 15.5px; }
.tool-card .muted { font-size: 12.5px; }
.tool-icon { font-size: 34px; margin-bottom: 4px; }

/* ============ 血糖记录 ============ */
.glucose-layout { display: grid; grid-template-columns: 1.8fr 1fr; gap: 20px; align-items: start; padding-bottom: 40px; }
@media (max-width: 860px) { .glucose-layout { grid-template-columns: 1fr; } }
.form-card h3, .chart-card h3, .stat-card h3, .tips-card h3 { font-size: 15.5px; margin-bottom: 12px; }
.glu-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.glu-field { display: flex; flex-direction: column; gap: 4px; }
.glu-field.wide { grid-column: 1 / -1; }
.glu-field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.glu-field input, .glu-field select {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px;
  font-family: inherit; outline: none; background: #fff;
}
.glu-field input:focus, .glu-field select:focus { border-color: var(--primary); }
.btn-block { width: 100%; min-height: 44px; }
.glu-hint { margin-top: 10px; font-size: 13.5px; color: var(--muted); min-height: 1.4em; }
.glu-hint.ok { color: var(--low); }
.glu-hint.low { color: var(--high); font-weight: 700; }
.glu-hint.high { color: var(--mid); }
.chart-card { margin-top: 16px; }
#gChart { width: 100%; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.chart-legend .dot.ok { background: #16a34a; }
.chart-legend .dot.high { background: #d97706; }
.chart-legend .dot.low { background: #dc2626; }
.record-title { padding: 16px 16px 0; }
.person-filter-card h3 { font-size: 15px; margin-bottom: 10px; }
.glu-chips { flex-wrap: wrap; }
.glu-chips a { cursor: pointer; }
.glu-table { margin-top: 4px; }
.glu-table td { font-size: 13.5px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat-item { background: #f8fafc; border-radius: 10px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.stat-item b { font-size: 19px; color: var(--primary-dark); }
.stat-item span { font-size: 11.5px; color: var(--muted); }
.stat-item.bad b { color: var(--high); }
.stat-item.warn b { color: var(--mid); }
.export-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.export-actions .btn-ghost { text-align: center; }
.danger-block { color: var(--high) !important; border-color: var(--high) !important; width: 100%; margin-top: 8px; }
.tips-card { margin-top: 16px; }
.tips-card li { font-size: 13px; margin: 6px 0; }

/* ============ 急救卡 ============ */
.card-page { max-width: 640px; padding-bottom: 50px; }
.ecard {
  background: #fff; border: 3px solid var(--primary); border-radius: 18px; padding: 26px;
  box-shadow: var(--shadow);
}
.ecard-head { display: flex; align-items: center; gap: 14px; padding-bottom: 14px; border-bottom: 2px dashed var(--line); margin-bottom: 14px; }
.ecard-icon { font-size: 42px; }
.ecard-head h2 { font-size: 24px; color: var(--primary-dark); }
.ecard-head p { font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.ecard-rows { display: flex; flex-direction: column; gap: 9px; margin-bottom: 16px; }
.erow { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: baseline; font-size: 14.5px; }
.erow > span { color: var(--muted); font-size: 13px; }
.erow .fill {
  border-bottom: 1.5px solid #cbd5e1; padding: 2px 4px; min-height: 1.5em; outline: none;
  font-weight: 600; color: var(--text);
}
.erow .fill:focus { border-bottom-color: var(--primary); background: #f0fdfa; }
.ecard-notice { background: #fef2f2; border: 1.5px solid #fecaca; border-radius: 12px; padding: 14px 16px; }
.ecard-notice p { font-size: 13.5px; line-height: 1.9; }
.card-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; align-items: center; }
@media print {
  body * { visibility: hidden; }
  .ecard, .ecard * { visibility: visible; }
  .ecard { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; }
  .no-print { display: none !important; }
}

/* ============ 404 ============ */
.notfound { display: flex; justify-content: center; padding: 70px 0; }
.nf-card { text-align: center; max-width: 480px; width: 100%; padding: 40px 26px; }
.nf-emoji { font-size: 50px; margin-bottom: 10px; }
.nf-card h1 { font-size: 22px; margin-bottom: 8px; }
.nf-links { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

/* ============ 首页桌面端居中排版 ============ */
@media (min-width: 861px) {
  .page-home .section-title {
    text-align: center;
    width: 100%;
  }
  .page-home .section-head {
    flex-direction: column;
    align-items: center;
    gap: 2px;
  }
  .page-home .side-note { text-align: center; }
  .page-home .two-col aside .section { max-width: 480px; margin-left: auto; margin-right: auto; width: 100%; }
  /* 卡片改 flex 换行: 每一行(含不满的最后一行)都自动居中 */
  .page-home .tools-grid,
  .page-home .cat-grid,
  .page-home .quick-grid {
    display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
  }
  .page-home .cat-grid .cat-card { width: 152px; }
  .page-home .quick-grid .quick-card { width: 186px; }
  .page-home .tools-grid .tool-card { width: 280px; }
  .page-home .two-col { gap: 36px; }
  .page-home .article-list { max-width: 760px; margin: 0 auto; }
}

/* ============ 家庭码同步 ============ */
.sync-page { max-width: 760px; display: flex; flex-direction: column; gap: 16px; padding-bottom: 50px; }
.sync-status-card h3 { font-size: 16px; margin-bottom: 10px; }
.sync-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.sync-actions .or { text-align: center; color: var(--muted); font-size: 13px; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; letter-spacing: 1px; text-transform: uppercase; min-width: 0;
}
.code-display {
  display: flex; align-items: center; gap: 12px; background: var(--primary-light);
  border-radius: 12px; padding: 14px 18px; margin: 8px 0;
}
.code-display b { font-size: 26px; letter-spacing: 3px; color: var(--primary-dark); font-family: Consolas, monospace; }
.ex-tips-list { padding-left: 20px; }
.ex-tips-list li { font-size: 13.5px; margin: 7px 0; }

/* ============ 大字模式(适老化) ============ */

/* ============ 手机适配 (≤720px) ============ */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .container { padding: 0 14px; }

  /* 输入框字号≥16px, 防止 iOS Safari 聚焦自动放大 */
  input[type=text], input[type=search], input[type=number],
  .hero-search input, .filter-search input, .search-row input, .grams-input {
    font-size: 16px !important;
  }

  /* 导航 */
  .nav-inner { flex-wrap: wrap; height: auto; padding: 10px 0 6px; gap: 8px; }
  .logo-text small { display: none; }
  .nav-right { width: 100%; justify-content: space-between; }
  .font-toggle { min-width: 46px; height: 40px; font-size: 16px; }
  .nav-links { flex: 1; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-links a { padding: 10px 14px; font-size: 16px; white-space: nowrap; flex-shrink: 0; }

  /* 首页 */
  .hero { padding: 44px 0 40px; }
  .hero h1 { font-size: 26px; }
  .hero-sub { font-size: 15px; }
  .hero-search { flex-wrap: nowrap; }
  .hero-search button { padding: 0 18px; font-size: 16px; }
  .hero-stats { gap: 22px; }
  .cat-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .cat-card { padding: 12px 4px 10px; }
  .quick-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .two-col { grid-template-columns: 1fr; }

  /* 通用表格 → 卡片化 */
  .food-table, .calc-table, .admin-table { font-size: 15px; }
  .food-table thead, .calc-table thead, .admin-table thead { display: none; }
  .food-table tbody tr, .calc-table tbody tr, .admin-table tbody tr {
    display: block; background: #fff; border: 1px solid var(--line);
    border-radius: 12px; padding: 10px 14px; margin: 10px 12px;
  }
  .food-table tbody tr:hover, .calc-table tbody tr:hover { background: #fff; }
  .food-table td, .calc-table td, .admin-table td {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; border-bottom: 1px dashed #eef2f6; padding: 9px 0; text-align: right;
  }
  .food-table td:last-child, .calc-table td:last-child, .admin-table td:last-child { border-bottom: none; }
  .food-table td::before, .calc-table td::before, .admin-table td::before {
    content: attr(data-label); color: var(--muted); font-size: 13px; flex-shrink: 0;
  }
  .food-table td.food-name-cell, .calc-table td.food-name-cell {
    justify-content: flex-start; font-size: 16.5px; border-bottom: 1px solid var(--line);
    padding-bottom: 10px; text-align: left;
  }
  .food-table td.food-name-cell::before, .calc-table td.food-name-cell::before { content: none; }
  .calc-table td .pill { font-size: 13.5px; }
  .grams-input { width: 96px; height: 42px; }
  .remove-btn { width: 44px; height: 44px; font-size: 18px; }
  .table-card { padding: 0; background: transparent; border: none; box-shadow: none; overflow: visible; }
  .empty-tip { text-align: center; color: var(--muted); }
  .calc-actions { padding: 4px 14px 14px; }
  .calc-hint { font-size: 13px; }
  .btn-ghost, .btn-primary { min-height: 44px; }

  /* 计算器: 合计固定在底部, 说明卡片隐藏 */
  .calc-layout { display: flex; flex-direction: column; padding-bottom: 250px; }
  .calc-side { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0; }
  .calc-side .total-card {
    border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.14);
    padding: 12px 16px calc(10px + env(safe-area-inset-bottom));
    position: static;
  }
  .total-card h3 { display: none; }
  .total-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .total-item { padding: 8px 4px; }
  .total-item b { font-size: 17px; }
  .total-item span { font-size: 11px; }
  .gl-badge { margin-top: 8px; padding: 8px; font-size: 14px; }
  .advice { font-size: 12px; }
  .legend-card { display: none; }
  .search-results { max-height: 46vh; }
  .sr-item { padding: 13px 16px; }
  .quick-add button { padding: 9px 16px; font-size: 15px; }

  /* 详情页 */
  .nut-grid { grid-template-columns: repeat(2, 1fr); }
  .serving-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-title h1 { font-size: 22px; }
  .detail-emoji { font-size: 44px; }

  /* 文章 */
  .article-wrap { grid-template-columns: 1fr; }
  .article-cards { grid-template-columns: 1fr; }
  .side-articles { position: static; }
  .article-content { padding: 16px; }
  .article-content h1 { font-size: 21px; }
  .article-content h2 { font-size: 18px; }

  /* 表单/后台 */
  .edit-row, .edit-row.three { grid-template-columns: 1fr; }
  .filter-search { gap: 8px; }
  .filter-search button { padding: 0 18px; }
  .cat-chips a { padding: 9px 15px; font-size: 14.5px; }
  .pagination a { padding: 11px 20px; font-size: 15px; }

  /* 页脚让出底部合计栏空间 */
  .footer { margin-bottom: 0; }
  body:has(.calc-side) .footer { padding-bottom: 170px; }
}
