:root {
  --primary: #1668dc;
  --primary-light: #2f7ee8;
  --text: #1d2b3f;
  --muted: #8a97a8;
  --border: #dbe2ea;
  --bg: #f2f5f9;
  --card: #ffffff;
  --low: #e5484d;
  --normal: #2f9e44;
  --high: #f08c00;
  --very-high: #c92a2a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 24px rgba(29, 43, 63, 0.08);
}

.app-content {
  padding: 12px;
  padding-bottom: 96px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar {
  color: #fff;
  padding: 14px 16px 10px;
  background: linear-gradient(135deg, #1668dc 0%, #1b6de0 60%, #2f7ee8 100%);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
}

.topbar-user {
  min-width: 0;
  font-size: 12px;
  opacity: 0.9;
  margin-top: 3px;
}

.icon-btn {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
}

.tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #e6ebf1;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: #6b7a8e;
  font-size: 14px;
  padding: 12px 2px 10px;
  position: relative;
}

.tab.on {
  color: var(--primary);
  font-weight: 600;
}

.tab.on::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: var(--primary);
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(27, 109, 224, 0.06);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}

.card-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 6px 2px 8px;
}

.login-page {
  min-height: 100vh;
  min-height: var(--app-height, 100dvh);
  display: flex;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 360px;
  margin: auto;
  background: #fff;
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: 0 10px 36px rgba(27, 109, 224, 0.14);
}

.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  display: block;
}

.login-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.remember-row {
  margin: -2px 0 16px;
  color: #4a5a70;
  font-size: 13px;
}

.remember-row label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.remember-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  color: #6b7a8e;
  font-size: 13px;
  margin: 12px 0 6px;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
}

.textarea {
  min-height: 84px;
  resize: vertical;
  font-family: inherit;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 9px;
  padding: 12px 14px;
  font-size: 15px;
  background: #eef2f7;
  color: var(--text);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-small {
  width: auto;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12px;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-row .select {
  flex: 1;
}

.latest {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  border-left: 4px solid var(--normal);
}

.latest-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.latest-label {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  color: #fff;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 20px;
}

.latest-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.latest-value {
  font-size: 46px;
  font-weight: 800;
  line-height: 1.1;
}

.unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

.latest-status {
  font-size: 15px;
  font-weight: 600;
}

.latest-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.stat-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-cell,
.metric-cell {
  background: #fff;
  border-radius: 12px;
  padding: 12px 6px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(27, 109, 224, 0.06);
}

.stat-number,
.metric-number {
  color: var(--primary);
  font-size: 19px;
  font-weight: 700;
}

.stat-label,
.metric-label {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.svg {
  width: 100%;
  height: auto;
}

.svg-line {
  stroke: var(--primary);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.svg-grid {
  stroke: #e6ebf1;
}

.svg-text {
  fill: var(--primary);
  font-size: 9px;
  font-weight: 600;
}

.svg-label {
  fill: var(--muted);
  font-size: 9px;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
}

.day {
  margin-bottom: 14px;
}

.day-title {
  color: #6b7a8e;
  font-size: 13px;
  font-weight: 700;
  margin: 2px 2px 6px;
}

.item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(27, 109, 224, 0.06);
}

.item-left {
  min-width: 0;
  flex: 1;
}

.item-value {
  font-size: 20px;
  font-weight: 700;
}

.item-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.item-note {
  color: #6b7a8e;
  font-size: 12px;
  margin-top: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.item-owner {
  display: inline-block;
  color: var(--primary);
  font-size: 11px;
  margin-right: 6px;
}

.item-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mini-btn {
  border: none;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  background: #eef2f7;
  color: #4a5a70;
}

.mini-danger {
  color: var(--low);
  background: #fdecec;
}

.range-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.range-tab {
  flex: 1;
  border: 1px solid var(--border);
  background: #fff;
  color: #4a5a70;
  border-radius: 8px;
  padding: 8px 0;
}

.range-tab.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.count-line {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ring-card {
  text-align: center;
}

.ring {
  width: 128px;
  height: 128px;
}

.ring-bg {
  fill: none;
  stroke: #eef2f7;
  stroke-width: 10;
}

.ring-fg {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring-number {
  fill: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.ring-label {
  fill: var(--muted);
  font-size: 11px;
}

.a1c-number {
  color: var(--primary);
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  padding: 8px 0 2px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  background: var(--bg);
  color: #6b7a8e;
  text-align: left;
  padding: 8px;
  font-weight: 600;
}

.table td {
  padding: 8px;
  border-bottom: 1px solid #eef2f7;
}

.user-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.form-inline {
  display: flex;
  gap: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: #fff;
  color: #4a5a70;
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
}

.chip.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.big-value-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.big-value {
  width: 180px;
  border: none;
  border-bottom: 2px solid var(--primary);
  color: var(--text);
  font-size: 56px;
  font-weight: 800;
  text-align: center;
  outline: none;
  background: transparent;
}

.big-value::-webkit-outer-spin-button,
.big-value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.medical-note {
  color: #9aa7b8;
  font-size: 11px;
  line-height: 1.7;
  margin-top: 14px;
}

.action-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 480px);
  display: flex;
  gap: 10px;
  background: #fff;
  border-top: 1px solid #e6ebf1;
  box-shadow: 0 -2px 10px rgba(27, 109, 224, 0.06);
  z-index: 40;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}

.action-btn {
  flex: 1;
  border: 1px solid #d5deea;
  background: #f4f7fb;
  color: #46586e;
  border-radius: 10px;
  padding: 12px 0;
  font-size: 15px;
}

.action-btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.empty {
  background: #fff;
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  width: min(90%, 420px);
  background: rgba(29, 43, 63, 0.92);
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  font-size: 13px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
}

.toast.success {
  background: rgba(47, 158, 68, 0.94);
}

.toast.error {
  background: rgba(229, 72, 77, 0.94);
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.modal-mask.hidden {
  display: none;
}

.modal {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 14px;
  padding: 18px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-message {
  color: #4a5a70;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  background: #eef2f7;
}

.modal-btn-primary {
  background: var(--primary);
  color: #fff;
}
