/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  background: #F2F2F7;
  color: #1C1C1E;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}

/* ── Content Area ─────────────────────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ── Tab Bar ──────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.18);
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #8E8E93;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1px;
  transition: color 0.15s;
}

.tab-btn.active { color: #007AFF; }

.tab-icon {
  width: 26px;
  height: 26px;
}

/* ── Member Selector (Segmented Control) ─────────────────────────────────── */
.seg-ctrl {
  display: flex;
  background: rgba(118, 118, 128, 0.12);
  border-radius: 9px;
  padding: 2px;
  margin-bottom: 16px;
}

.seg-btn {
  flex: 1;
  padding: 7px 4px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 500;
  color: #3C3C43;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

.seg-btn.active {
  background: #FFFFFF;
  color: #000000;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 0.5px 0 rgba(0, 0, 0, 0.06);
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #FFFFFF;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* ── Height Row (adults) ─────────────────────────────────────────────────── */
.height-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 0.5px solid #E5E5EA;
}

.h-label {
  font-size: 14px;
  color: #8E8E93;
  font-weight: 500;
}

.h-value {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: #1C1C1E;
}

.h-unset {
  flex: 1;
  font-size: 14px;
  color: #FF9500;
}

.h-edit-btn {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: #007AFF;
  cursor: pointer;
  padding: 4px 8px;
}

/* ── Field Label ─────────────────────────────────────────────────────────── */
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: #8E8E93;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

/* ── Stepper ──────────────────────────────────────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  padding: 4px 0;
}

.stepper + .field-label {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 0.5px solid #E5E5EA;
}

.step-btn {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  border: none;
  background: #F2F2F7;
  color: #007AFF;
  font-size: 22px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
  transition: opacity 0.1s;
}

.step-btn:active { opacity: 0.5; }

.step-input {
  flex: 1;
  border: none;
  outline: none;
  text-align: center;
  background: transparent;
  font-family: inherit;
  font-size: 28px;
  font-weight: 600;
  color: #1C1C1E;
  min-width: 0;
}

/* Large stepper for weight */
.stepper.lg .step-btn {
  width: 54px;
  height: 54px;
  border-radius: 27px;
  background: rgba(0, 122, 255, 0.1);
  font-size: 26px;
}

.stepper.lg .step-input {
  font-size: 54px;
  font-weight: 700;
  letter-spacing: -1px;
}

/* Remove native number spinners */
input[type=number] {
  -webkit-appearance: none;
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* ── BMI Row ──────────────────────────────────────────────────────────────── */
.bmi-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 0.5px solid #E5E5EA;
}

.bmi-num {
  font-size: 26px;
  font-weight: 700;
  color: #1C1C1E;
}

.bmi-tag {
  font-size: 15px;
  font-weight: 600;
}

.bmi-lbl {
  font-size: 13px;
  color: #8E8E93;
  margin-right: 2px;
}

/* ── Date Row ────────────────────────────────────────────────────────────── */
.date-row {
  display: flex;
  align-items: center;
  background: #FFFFFF;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  gap: 12px;
}

.date-lbl {
  font-size: 15px;
  font-weight: 500;
  color: #8E8E93;
  flex-shrink: 0;
}

.date-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #1C1C1E;
  background: transparent;
  text-align: right;
}

/* ── Record Button ────────────────────────────────────────────────────────── */
.record-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: #007AFF;
  color: #FFFFFF;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: opacity 0.15s;
}

.record-btn:active { opacity: 0.8; }

/* ── History ──────────────────────────────────────────────────────────────── */
.hist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #FFFFFF;
  border-radius: 14px;
  padding: 14px 12px 14px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: opacity 0.25s, transform 0.25s;
}

.hist-date {
  font-size: 13px;
  color: #8E8E93;
  width: 36px;
  flex-shrink: 0;
  text-align: center;
  line-height: 1.3;
}

.hist-body { flex: 1; min-width: 0; }

.hist-weight {
  font-size: 20px;
  font-weight: 700;
  color: #1C1C1E;
}

.hist-weight small {
  font-size: 13px;
  font-weight: 400;
  color: #8E8E93;
}

.hist-sub {
  display: flex;
  gap: 10px;
  margin-top: 2px;
  font-size: 13px;
  color: #8E8E93;
}

.del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #C7C7CC;
  padding: 8px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.del-btn:active { color: #FF3B30; }

/* ── Chart ────────────────────────────────────────────────────────────────── */
.chart-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.pill-group {
  display: flex;
  gap: 6px;
}

.pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid #E5E5EA;
  background: #FFFFFF;
  font-size: 13px;
  font-weight: 500;
  color: #3C3C43;
  cursor: pointer;
  transition: all 0.15s;
}

.pill.active {
  background: #007AFF;
  color: #FFFFFF;
  border-color: #007AFF;
}

.chart-card { padding: 12px 4px 8px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat {
  background: #FFFFFF;
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.sv {
  font-size: 16px;
  font-weight: 700;
  color: #1C1C1E;
}

.sv.stat-good { color: #34C759; }
.sv.stat-warn { color: #FF9500; }

.sk {
  font-size: 11px;
  color: #8E8E93;
  margin-top: 2px;
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  color: #C7C7CC;
  padding: 60px 0 20px;
  font-size: 16px;
}

/* ── Modal (Bottom Sheet) ─────────────────────────────────────────────────── */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-bg.open {
  opacity: 1;
  pointer-events: all;
}

.modal-sheet {
  background: #FFFFFF;
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 430px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-bg.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: #E5E5EA;
  border-radius: 2px;
  margin: 0 auto 18px;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 18px;
  color: #1C1C1E;
}

.modal-input {
  width: 100%;
  padding: 14px;
  border: 1.5px solid #E5E5EA;
  border-radius: 12px;
  font-size: 22px;
  font-family: inherit;
  text-align: center;
  outline: none;
  margin-bottom: 16px;
  color: #1C1C1E;
  background: #FAFAFA;
  transition: border-color 0.15s;
}

.modal-input:focus { border-color: #007AFF; background: #FFFFFF; }

.modal-btns {
  display: flex;
  gap: 12px;
}

.m-cancel, .m-ok {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}

.m-cancel { background: #F2F2F7; color: #3C3C43; }
.m-ok     { background: #007AFF; color: #FFFFFF; }
.m-cancel:active, .m-ok:active { opacity: 0.75; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(0, 0, 0, 0.72);
  color: #FFFFFF;
  padding: 10px 22px;
  border-radius: 22px;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 400;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
