/* ============================================================
   血糖守护系统 - 全局样式（移动优先，Bootstrap 5.3 增强）
   配色：蓝白医疗风
   ============================================================ */

:root {
  --cgm-primary: #2563eb;
  --cgm-primary-dark: #1d4ed8;
  --cgm-bg: #f1f5f9;
  --cgm-card-bg: #ffffff;
  --cgm-text: #1e293b;
  --cgm-text-muted: #64748b;
  --cgm-border: #e2e8f0;
  --cgm-success: #10b981;
  --cgm-warning: #f59e0b;
  --cgm-danger: #ef4444;
  --cgm-info: #0ea5e9;
  --cgm-radius: 14px;
  --cgm-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
}

* { -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--cgm-bg);
  color: var(--cgm-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* 大点击区域 */
.btn, .nav-link, .dropdown-item, .form-check-input, a { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.btn { border-radius: 10px; font-weight: 500; }
.btn-sm { min-height: 32px; }
.form-control, .form-select { border-radius: 10px; padding: .65rem .85rem; border-color: var(--cgm-border); }
.form-control:focus, .form-select:focus { border-color: var(--cgm-primary); box-shadow: 0 0 0 .2rem rgba(37,99,235,.12); }

/* ============ 导航栏 ============ */
.navbar-cgm {
  background: var(--cgm-primary);
  box-shadow: 0 2px 10px rgba(29,78,216,.25);
  position: sticky; top: 0; z-index: 1030;
  padding: .35rem .75rem;
}
.navbar-cgm .navbar-brand { color: #fff; font-weight: 700; letter-spacing: .5px; min-height: 44px; display: inline-flex; align-items: center; }
.navbar-cgm .navbar-brand i { margin-right: 6px; }
.navbar-cgm .brand-logo { height: 28px; width: 28px; margin-right: 8px; border-radius: 7px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.navbar-cgm .navbar-brand:hover .brand-logo { transform: scale(1.06); }
.navbar-cgm .navbar-brand .brand-logo { transition: transform .15s ease; }
.navbar-cgm .nav-link { color: rgba(255,255,255,.85); border-radius: 8px; padding: .45rem .9rem; min-height: 40px; }
.navbar-cgm .nav-link:hover, .navbar-cgm .nav-link.active { color: #fff; background: rgba(255,255,255,.15); }
.navbar-cgm .navbar-toggler { border: 1px solid rgba(255,255,255,.4); color: #fff; padding: .3rem .6rem; min-height: 40px; }
.navbar-cgm .dropdown-menu { border-radius: 12px; box-shadow: var(--cgm-shadow); border: none; }
.navbar-cgm .dropdown-menu .dropdown-item { min-height: 44px; justify-content: flex-start; }

/* 患者列表页手动刷新按钮旋转动效 */
#refreshBtn.spin i { display: inline-block; animation: cgm-spin .8s linear infinite; }
@keyframes cgm-spin { to { transform: rotate(360deg); } }

/* ============ 卡片 ============ */
.card-cgm {
  background: var(--cgm-card-bg);
  border: none;
  border-radius: var(--cgm-radius);
  box-shadow: var(--cgm-shadow);
}

/* 患者卡片 */
.patient-card {
  position: relative;
  overflow: hidden;
  border-top: 4px solid var(--cgm-success);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.patient-card:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(15,23,42,.12); }
.patient-card:active { transform: scale(.99); }
.patient-card .card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.patient-card .patient-name {
  font-size: 1.15rem; font-weight: 700; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.patient-card .pc-note {
  font-size: .78rem; color: var(--cgm-text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.patient-card .min-w-0 { min-width: 0; }
.patient-card .star-btn { border: none; background: none; color: #cbd5e1; font-size: 1.25rem; min-height: 44px; min-width: 44px; margin: -6px -6px -6px 0; }
.patient-card .star-btn.active { color: var(--cgm-warning); }

/* 当前血糖点时间 */
.reading-time { font-size: .72rem; color: var(--cgm-text-muted); line-height: 1; margin-bottom: 3px; font-variant-numeric: tabular-nums; }

/* 大号当前血糖值 */
.pc-value { font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pc-value .dir { font-size: 1.55rem; font-weight: 900; opacity: .95; margin-left: 4px; line-height: 1; position: relative; top: -.13em; }
.pc-value .unit { font-size: .76rem; font-weight: 500; letter-spacing: 0; color: var(--cgm-text-muted); margin-left: 3px; }
.pc-value .delta { font-size: .76rem; font-weight: 600; letter-spacing: 0; color: var(--cgm-text-muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.pc-value .delta .bi { margin-right: 2px; position: relative; top: -1px; }

/* 迷你血糖曲线 */
.spark-box { position: relative; height: 100px; margin-top: .5rem; }
.spark-chart { width: 100%; height: 100%; cursor: crosshair; }
.spark-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 6px; font-size: .8rem; color: #94a3b8; background: rgba(255,255,255,.6);
}
.spark-msg i { animation: spark-pulse 1.2s ease-in-out infinite; }
@keyframes spark-pulse { 0%,100% { opacity:.35 } 50% { opacity:1 } }

/* 曲线时间范围快捷切换 */
.spark-ranges { display: flex; gap: 5px; margin-top: .4rem; }
.spark-ranges button {
  flex: 1; border: 1px solid var(--cgm-border); background: #fff; border-radius: 999px;
  font-size: .68rem; line-height: 1; padding: 3px 0; color: var(--cgm-text-muted);
  transition: background .12s ease, color .12s ease;
}
.spark-ranges button:hover { border-color: var(--cgm-primary); color: var(--cgm-primary); }
.spark-ranges button.active { background: var(--cgm-primary); border-color: var(--cgm-primary); color: #fff; font-weight: 600; }

/* 卡片统计行 */
.pc-stats { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: .76rem; color: var(--cgm-text-muted); }
.pc-stats b { color: var(--cgm-text); font-weight: 600; font-variant-numeric: tabular-nums; }


/* 状态徽章 */
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: .25rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.status-NORMAL { background: #d1fae5; color: #047857; }
.status-LOW     { background: #fee2e2; color: #b91c1c; }
.status-HIGH    { background: #fef3c7; color: #b45309; }
.status-NO_DATA { background: #e2e8f0; color: #64748b; }

/* TIR 概览条 */
.tir-bars { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: #e2e8f0; }
.tir-bars .b-low { background: var(--cgm-danger); }
.tir-bars .b-in  { background: var(--cgm-success); }
.tir-bars .b-high{ background: var(--cgm-warning); }
.tir-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--cgm-text-muted); }
.tir-legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }

/* ============ 登录页 ============ */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #2563eb 0%, #1e40af 55%, #0f2a6e 100%);
  padding: 20px;
}
.login-card { width: 100%; max-width: 400px; border-radius: 18px; border: none; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-brand { text-align: center; margin-bottom: 1.2rem; }
.login-brand .logo-circle {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 18px;
  background: linear-gradient(135deg,#2563eb,#0ea5e9); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
  box-shadow: 0 8px 20px rgba(37,99,235,.28);
}
.login-brand .logo-circle .logo-img { width: 100%; height: 100%; border-radius: 18px; display: block; }
.login-brand h4 { font-weight: 700; color: var(--cgm-text); margin-bottom: 2px; }
.login-brand p { color: var(--cgm-text-muted); font-size: .85rem; margin: 0; }

/* ============ 详情页 ============ */
.stat-card { text-align: center; padding: .8rem .5rem; }
.stat-card .stat-label { font-size: .75rem; color: var(--cgm-text-muted); }
.stat-card .stat-value { font-size: 1.25rem; font-weight: 700; }
.range-picker .btn { border-radius: 999px; }
.range-picker .btn.active { background: var(--cgm-primary); color: #fff; }
.chart-box { width: 100%; height: 340px; }
.chart-box-sm { width: 100%; height: 180px; }
.analysis-chart { width: 100%; height: 150px; }
.analysis-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: .4rem 0; border-bottom: 1px dashed var(--cgm-border); font-size: .8rem; }
.analysis-item:last-child { border-bottom: none; }
.analysis-item span { color: var(--cgm-text-muted); white-space: nowrap; }
.analysis-item b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.analysis-empty { color: var(--cgm-text-muted); font-size: .82rem; text-align: center; padding: .6rem 0; }

/* ============ 管理表格 ============ */
.table-cgm { --bs-table-hover-bg: #f8fafc; }
.table-cgm td, .table-cgm th { vertical-align: middle; padding: .75rem .6rem; }

/* ============ 通用 ============ */
.page-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.text-muted-cgm { color: var(--cgm-text-muted); }
.section-title { font-size: .85rem; font-weight: 700; color: var(--cgm-text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: .6rem; }
.modal-content { border: none; border-radius: 16px; }
.modal-header { border-bottom: 1px solid var(--cgm-border); }
.modal-footer { border-top: 1px solid var(--cgm-border); }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--cgm-text-muted); }
.empty-state i { font-size: 3rem; color: #cbd5e1; display: block; margin-bottom: .8rem; }
.toast-container { z-index: 1080; }
.form-switch.form-switch-lg { min-height: 44px; }

/* 加载中 */
.spinner-wrap { display: flex; justify-content: center; padding: 3rem 0; }

/* ============ 桌面增强 ============ */
@media (min-width: 992px) {
  .page-title { font-size: 1.35rem; }
  .chart-box { height: 440px; }
  .navbar-cgm { padding: .5rem 1rem; }
  .navbar-cgm .nav-link { margin-left: 4px; }
}
