:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1f2933;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --accent-strong: #db2777;
  --who: #0ea5e9;
  --cn: #f97316;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
.navlink {
  text-decoration: none; color: var(--muted); font-weight: 600;
  padding: 7px 12px; border-radius: 10px; font-size: 14px;
}
.navlink:hover { background: var(--surface-2); color: var(--text); }
.nav-out { color: var(--danger); }

.container { max-width: 1080px; margin: 0 auto; padding: 22px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card.sub { background: var(--surface-2); border-style: dashed; }
.card h2 { margin: 0 0 14px; font-size: 16px; }

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

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.form-grid {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
}
.form-grid label {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
  color: var(--muted); min-width: 150px;
}
.form-grid input, .form-grid select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; color: var(--text); background: var(--surface);
}
.form-grid input:focus, .form-grid select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); text-decoration: none; display: inline-flex; align-items: center; }
.btn-del {
  background: transparent; color: var(--danger); border: 1px solid var(--border);
  cursor: pointer; padding: 5px 10px; border-radius: 8px; font-size: 12px;
}
.btn-del:hover { background: #fee2e2; }

.file-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.file-label input { font-size: 13px; }

/* dashboard */
.hero { display: flex; flex-direction: column; gap: 18px; }
.child-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.child-name { font-size: 22px; font-weight: 800; }
.child-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.edit-child summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.edit-child form { margin-top: 12px; }

.controls { display: flex; gap: 26px; flex-wrap: wrap; align-items: center; }
.ctl-group { display: flex; align-items: center; gap: 10px; }
.ctl-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.seg-btn {
  border: none; background: transparent; cursor: pointer; padding: 7px 14px;
  border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chart-card { padding: 16px; }
.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.chart-tip { color: var(--muted); font-size: 12.5px; }
.btn-sm {
  padding: 5px 12px; font-size: 12.5px; border-radius: 8px;
  background: var(--surface-2); cursor: pointer;
}
.btn-sm:hover { background: var(--border); }
.zoom-hint { color: var(--accent); font-size: 12.5px; margin-top: 6px; min-height: 16px; }
/* 关键：canvas 必须挂在一个【高度已确定】的容器里。
   之前 canvas 直接是 .chart-card 的子元素，而 .chart-card 高度又由 canvas 决定，
   配合 maintainAspectRatio:false + responsive:true 会形成
   「canvas 撑满父容器 → 父容器随 canvas 变高 → canvas 再撑满」的循环，
   表现为曲线永远在缓慢生长。容器给死高度，循环即断开。 */
.chart-box { position: relative; height: 420px; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; cursor: crosshair; }
.chart-box canvas.dragging { cursor: grabbing; }
/* 窄屏适当降高度，保证整图仍在一页内可见 */
@media (max-width: 640px) { .chart-box { height: 320px; } }
.range-note { color: var(--warn); font-size: 13px; margin-top: 8px; min-height: 18px; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.summary .metric {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
}
.summary .metric h3 { margin: 0 0 10px; font-size: 14px; display: flex; justify-content: space-between; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.badge.who { background: var(--who); color: #fff; }
.badge.cn { background: var(--cn); color: #fff; }
.summary .row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.summary .row .k { color: var(--muted); }
.summary .row .v { font-weight: 700; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.data-table td.num { font-variant-numeric: tabular-nums; }
.data-table tr:hover { background: var(--surface-2); }

.login-wrap { max-width: 360px; margin: 60px auto; }
