/* ===== 血糖助手 全局样式 ===== */
:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #ccfbf1;
  --bg: #f2f6f5;
  --card: #ffffff;
  --text: #1e293b;
  --text-sub: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warn: #ea580c;
  --good: #16a34a;
  --low: #7c3aed;
  --shadow: 0 2px 10px rgba(15, 118, 110, .08);
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
[v-cloak] { display: none; }
button { font-family: inherit; }

/* 通用卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 16px; font-weight: 700; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; row-gap: 8px; flex-wrap: wrap;
}
.sub { color: var(--text-sub); font-size: 13px; }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; cursor: pointer;
  padding: 9px 18px; font-size: 14px; font-weight: 600;
  background: var(--primary); color: #fff; transition: .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-sub); }
.btn-ghost:hover { background: #eef2f1; color: var(--text); }
.btn-danger { background: #fff; color: var(--danger); border: 1.5px solid #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1.5px solid var(--border); border-radius: 10px; outline: none;
  background: #fff; color: var(--text); transition: .15s; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 148, 136, .12);
}
input[type=time].time-input, input[type=date].time-input { padding: 7px 9px; font-size: 14px; }
input[type=time], input[type=date] { font-family: inherit; }

/* 徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.b-normal { background: #dcfce7; color: var(--good); }
.b-high { background: #ffedd5; color: var(--warn); }
.b-very_high { background: #fee2e2; color: var(--danger); }
.b-low { background: #ede9fe; color: var(--low); }
.b-pending { background: #fee2e2; color: var(--danger); }
.b-scheduled { background: #e0f2fe; color: #0369a1; }
.b-idle { background: #f1f5f9; color: var(--text-sub); }
.b-info { background: #e0f2fe; color: #0369a1; }
.b-warn { background: #fef3c7; color: #b45309; }
.b-good { background: #dcfce7; color: var(--good); }
.b-gray { background: #f1f5f9; color: var(--text-sub); }

/* Toast */
#toast-wrap { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 10px 20px; border-radius: 10px; color: #fff; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18); animation: fadeIn .2s; max-width: 86vw;
}
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: #0f766e; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 400px;
  padding: 22px; animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* 测糖提醒弹窗 */
.rm-info {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 2px 14px; margin-bottom: 12px; background: #f8fafc;
}
.rm-info > div {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13px;
}
.rm-info > div:last-child { border-bottom: none; }
.rm-info span { color: var(--text-sub); }
.rm-info b { font-size: 14px; }
.rm-info b.hl { color: var(--primary-dark); font-size: 15px; }
.rm-info small { color: var(--text-sub); font-weight: 500; font-size: 11px; }

/* 用餐时间卡片内的提醒按钮 */
.btn-remind { width: 100%; margin-top: 8px; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(135deg, #0d9488, #0f766e);
  color: #fff; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 2px 8px rgba(13,148,136,.3);
}
.topbar .logo { font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.topbar .user-box { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar a, .topbar .link { color: #fff; text-decoration: none; cursor: pointer; opacity: .9; font-size: 13px; }
.topbar .link:hover { opacity: 1; text-decoration: underline; }

/* 容器 */
.container { max-width: 760px; margin: 0 auto; padding: 16px 14px 40px; }
.container-wide { max-width: 1080px; margin: 0 auto; padding: 16px 14px 40px; }

/* Tab 导航 */
.tabs {
  display: flex; background: #fff; border-radius: 12px; padding: 4px;
  box-shadow: var(--shadow); margin-bottom: 16px; gap: 4px;
}
.tabs .tab {
  flex: 1; text-align: center; padding: 9px 0; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--text-sub); cursor: pointer; transition: .15s;
  border: none; background: transparent;
}
.tabs .tab.active { background: var(--primary); color: #fff; }

/* 记录卡片 */
.rec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .rec-grid { grid-template-columns: 1fr; } }
.rec-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 15px; border-top: 4px solid var(--primary);
  display: flex; flex-direction: column; gap: 8px;
}
.rec-card.fast { border-top-color: #f59e0b; }
.rec-card.b2h { border-top-color: #3b82f6; }
.rec-card.l2h { border-top-color: #10b981; }
.rec-card.d2h { border-top-color: #8b5cf6; }
.rec-head { display: flex; justify-content: space-between; align-items: center; }
.rec-head .name { font-weight: 700; font-size: 15px; }
.rec-value { font-size: 30px; font-weight: 800; line-height: 1.2; }
.rec-value small { font-size: 12px; color: var(--text-sub); font-weight: 500; }
.rec-value.lv-normal { color: var(--good); }
.rec-value.lv-high { color: var(--warn); }
.rec-value.lv-very_high { color: var(--danger); }
.rec-value.lv-low { color: var(--low); }
.rec-meta { font-size: 12.5px; color: var(--text-sub); display: flex; flex-direction: column; gap: 3px; }
.rec-meta b { color: var(--text); font-weight: 600; }
.rec-meta .late { color: var(--warn); }
.rec-actions { display: flex; gap: 8px; margin-top: 4px; }

/* 三餐时间 */
.meal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 560px) { .meal-grid { grid-template-columns: 1fr; } }
.meal-item { background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.meal-item .m-name { font-weight: 700; font-size: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.meal-row { display: flex; gap: 6px; align-items: center; }
.meal-row input[type=time] { flex: 1; min-width: 0; }
.meal-item .exp { font-size: 12px; color: var(--primary-dark); margin-top: 6px; font-weight: 600; }

/* 统计页 */
.seg { display: inline-flex; background: #eef2f1; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  border: none; background: transparent; padding: 6px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; color: var(--text-sub); cursor: pointer;
}
.seg button.active { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.nav-range { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; row-gap: 6px; }
.mini-chart { width: 100%; height: 216px; }
@media (max-width: 560px) { .mini-chart { height: 190px; } }
.day-chart { width: 100%; height: 360px; }
@media (max-width: 560px) { .day-chart { height: 300px; } }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 640px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
.stat-item { background: #f8fafc; border-radius: 12px; padding: 12px; text-align: center; }
.stat-item .num { font-size: 22px; font-weight: 800; color: var(--primary-dark); }
.stat-item .num.red { color: var(--danger); }
.stat-item .num.orange { color: var(--warn); }
.stat-item .num.green { color: var(--good); }
.stat-item .num.purple { color: var(--low); }
.stat-item .lbl { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

/* 汇总表格 */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 9px 8px; text-align: center; border-bottom: 1px solid #f1f5f9; }
.tbl th { color: var(--text-sub); font-weight: 600; font-size: 12.5px; background: #f8fafc; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td:first-child, .tbl th:first-child { text-align: left; padding-left: 10px; }

/* 建议列表 */
.advice-item { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.advice-item:last-child { border-bottom: none; }
.advice-item .a-icon { font-size: 20px; flex-shrink: 0; }
.advice-item .a-title { font-weight: 700; font-size: 14.5px; margin-bottom: 3px; }
.advice-item .a-text { font-size: 13.5px; color: #475569; }
.advice-item.lv-danger .a-title { color: var(--danger); }
.advice-item.lv-warn .a-title { color: var(--warn); }
.advice-item.lv-good .a-title { color: var(--good); }
.advice-item.lv-info .a-title { color: #0369a1; }
.advice-item.lv-disclaimer .a-text { color: var(--text-sub); font-size: 12.5px; }

/* 历史页 */
.hist-day { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 10px; }
.hist-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.hist-head .d { font-weight: 700; }
.hist-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.hist-badge {
  flex: 1; min-width: 120px; background: #f8fafc; border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; display: flex; flex-direction: column; gap: 2px;
}
.hist-badge .hb-label { color: var(--text-sub); font-size: 11.5px; }
.hist-badge .hb-val { font-weight: 800; font-size: 16px; }
.hist-badge .hb-val.lv-normal { color: var(--good); }
.hist-badge .hb-val.lv-high { color: var(--warn); }
.hist-badge .hb-val.lv-very_high { color: var(--danger); }
.hist-badge .hb-val.lv-low { color: var(--low); }
.hist-badge .hb-miss { color: #cbd5e1; font-weight: 600; }

/* ===== 登录页 ===== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0d9488 0%, #0f766e 45%, #134e4a 100%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: 100%; max-width: 400px; padding: 34px 30px;
}
.login-logo { text-align: center; margin-bottom: 22px; }
.login-logo .ico { font-size: 44px; }
.login-logo h1 { font-size: 22px; margin-top: 6px; color: var(--text); }
.login-logo p { font-size: 13px; color: var(--text-sub); }
.login-switch { display: flex; background: #f1f5f9; border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.login-switch button { flex: 1; border: none; padding: 8px; border-radius: 8px; background: transparent; font-size: 14px; font-weight: 600; color: var(--text-sub); cursor: pointer; }
.login-switch button.active { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.login-tip { text-align: center; font-size: 12.5px; color: var(--text-sub); margin-top: 16px; }

/* ===== 管理后台 ===== */
.admin-layout { display: flex; min-height: 100vh; }
.admin-side {
  width: 200px; background: #134e4a; color: #d1fae5; padding: 18px 12px; flex-shrink: 0;
}
.admin-side .brand { font-weight: 800; font-size: 16px; padding: 6px 10px 18px; color: #fff; }
.admin-side .nav-item {
  display: block; padding: 10px 14px; border-radius: 9px; cursor: pointer;
  font-size: 14px; margin-bottom: 4px; transition: .15s; border: none; background: transparent;
  width: 100%; text-align: left; color: #ccfbf1;
}
.admin-side .nav-item:hover { background: rgba(255,255,255,.08); }
.admin-side .nav-item.active { background: var(--primary); color: #fff; font-weight: 700; }
.admin-main { flex: 1; padding: 22px; background: var(--bg); min-width: 0; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.admin-header h2 { font-size: 19px; }
@media (max-width: 700px) {
  .admin-layout { flex-direction: column; }
  .admin-side { width: 100%; display: flex; gap: 6px; padding: 10px; overflow-x: auto; }
  .admin-side .brand { padding: 6px 10px; white-space: nowrap; }
  .admin-side .nav-item { white-space: nowrap; width: auto; margin-bottom: 0; }
}
.ov-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
@media (max-width: 800px) { .ov-cards { grid-template-columns: repeat(2, 1fr); } }
.ov-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.ov-card .n { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.ov-card .t { font-size: 13px; color: var(--text-sub); }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; cursor: pointer; transition: .2s;
}
.switch .slider:before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid #f1f5f9; }
.switch-row .s-title { font-weight: 600; font-size: 14.5px; }
.switch-row .s-desc { font-size: 12.5px; color: var(--text-sub); }
.th-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.empty { text-align: center; color: var(--text-sub); padding: 30px 0; font-size: 14px; }

/* 随机血糖 */
.rand-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 2px; border-bottom: 1px dashed var(--border); font-size: 14px;
}
.rand-item:last-child { border-bottom: none; }
.rand-item .val { font-weight: 800; font-size: 16px; }
.rand-item .val.lv-normal { color: var(--good); }
.rand-item .val.lv-high { color: var(--warn); }
.rand-item .val.lv-very_high { color: var(--danger); }
.rand-item .val.lv-low { color: var(--low); }
.rand-item .r-meta { color: var(--text-sub); font-size: 12.5px; }
.rand-item .grow { flex: 1; }

/* 手机端适配增强 */
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .card { padding: 13px; border-radius: 12px; margin-bottom: 12px; }
  .container { padding: 12px 10px 36px; }
  .container-wide { padding: 12px 10px 36px; }
  .topbar { padding: 10px 12px; }
  .topbar .logo { font-size: 15.5px; }
  .tabs .tab { font-size: 13.5px; padding: 8px 0; }
  .rec-value { font-size: 26px; }
  .rec-card { padding: 13px; }
  .modal { padding: 18px; }
  .stat-item { padding: 10px 8px; }
  .stat-item .num { font-size: 19px; }
  .hist-badge { min-width: 104px; }
  .th-grid { grid-template-columns: 1fr; }
  .ov-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .btn { padding: 9px 14px; }
  .login-card { padding: 28px 22px; }
}
