:root {
  --bg: #f4f7ff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d9e2f2;
  --primary: #2563eb;
  --primary-700: #1d4ed8;
  --danger: #ef4444;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #f8faff 0%, #eef3ff 100%);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 14px calc(120px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand h1 {
  margin: 0;
  font-size: 28px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.main {
  display: grid;
  gap: 12px;
}

.card {
  border: 1px solid #e4eaf7;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.08);
  padding: 16px;
}

h2 {
  margin: 0 0 12px;
  font-size: 28px;
}

h3 {
  margin: 0;
  font-size: 24px;
}

label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
  display: block;
}

input,
textarea,
.picker,
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
  padding: 12px 13px;
  font-size: 16px;
  color: var(--text);
  margin-bottom: 12px;
}

textarea {
  resize: vertical;
  min-height: 110px;
}

input[type="date"],
input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
  min-inline-size: 0;
  width: 100%;
  max-width: 100%;
  background-clip: padding-box;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value {
  text-align: left;
}

/* Keep iOS date controls inside card bounds. */
input[type="date"] {
  padding-right: 38px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  margin: 0;
  padding: 0;
  opacity: 0.75;
}

#onboardingView,
#profileTab .card {
  overflow-x: hidden;
}

/* iOS/Safari occasionally exposes hidden file inputs; force-hide upload control. */
#photoInput,
input[type="file"][hidden],
input[type="file"].hidden {
  display: none !important;
  position: fixed !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, filter 0.12s ease, background 0.12s ease;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-700) 100%);
  color: #fff;
}

.btn.secondary {
  background: #eef2ff;
  color: #1e3a8a;
  border-color: #cbd5ff;
}

.btn.ghost {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.btn:active,
.pressable:active,
.radio:active,
.tab-btn:active,
.metric-tile:active,
.activity-card:active {
  transform: scale(0.97);
  opacity: 0.88;
  filter: brightness(0.92);
}

.hidden {
  display: none !important;
}

.radio-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.radio {
  border: 1px solid #d3dbeb;
  background: #fff;
  border-radius: 12px;
  min-height: 44px;
  font-size: 16px;
  color: #334155;
  cursor: pointer;
}

.radio.active {
  border-color: var(--primary);
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.msg {
  min-height: 20px;
  margin: 2px 0 0;
  color: #dc2626;
  font-size: 13px;
}

.baby-card {
  padding: 12px;
}

.photo-wrap {
  position: relative;
  width: 100%;
  height: 220px;
  border-radius: 14px;
  border: none;
  overflow: hidden;
  background: linear-gradient(130deg, #c7d2fe 0%, #93c5fd 100%);
  padding: 0;
}

.photo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 68px;
}

.photo-tip {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  color: #fff;
  background: rgba(15, 23, 42, 0.45);
  font-size: 13px;
}

.baby-banner {
  margin-top: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #e0e7ff;
  font-size: 22px;
}

#babyName {
  font-size: 20px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.head-row h2 {
  margin-bottom: 0;
  white-space: nowrap;
  flex: 0 0 auto;
}

.head-row .picker {
  margin-bottom: 0;
  width: auto;
}

.record-filter {
  width: 124px;
  min-width: 124px;
}

.metric-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-tile {
  border: 1px solid #dbe7ff;
  background: linear-gradient(180deg, #fbfcff 0%, #f4f8ff 100%);
  border-radius: 14px;
  min-height: 92px;
  text-align: center;
  padding: 10px 8px;
  cursor: pointer;
  position: relative;
}

.metric-tile.add {
  border-style: dashed;
  background: #f8fafc;
}

.metric-icon {
  font-size: 28px;
  display: block;
  margin-bottom: 6px;
}

.metric-name {
  font-size: 14px;
}

.metric-del {
  position: absolute;
  right: 4px;
  top: 4px;
  border: none;
  border-radius: 999px;
  width: 22px;
  height: 22px;
  line-height: 22px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
  cursor: pointer;
}

.activity-list {
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

.day-title {
  margin: 10px 0 6px;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
}

.activity-row {
  position: relative;
  overflow: hidden;
  margin-bottom: 8px;
}

.activity-delete-wrap {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 88px;
  display: grid;
  place-items: center;
  z-index: 1;
  pointer-events: none;
}

.activity-row.open .activity-delete-wrap {
  pointer-events: auto;
}

.delete-btn {
  border: none;
  width: 78px;
  height: 100%;
  border-radius: 12px;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.activity-row.open .delete-btn {
  opacity: 1;
}

.activity-card {
  width: 100%;
  border: 1px solid #eef2f7;
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 0;
  cursor: pointer;
  text-align: left;
  transition: transform 0.2s ease;
  position: relative;
  z-index: 2;
}

.activity-row.open .activity-card {
  transform: translateX(-88px);
}

.activity-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.activity-metric {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  font-weight: 600;
}

.activity-value {
  flex: 1;
  min-width: 0;
  text-align: right;
  font-weight: 700;
  line-height: 1.35;
  font-size: 23px;
  word-break: break-all;
}

.activity-time,
.activity-note {
  color: var(--muted);
  font-size: 16px;
  margin-top: 4px;
}

.chart-wrap {
  background: #f8fbff;
  border: 1px solid #e5edf9;
  border-radius: 14px;
  padding: 8px;
  min-height: 240px;
}

#trendCanvas {
  width: 100%;
  height: 260px;
  display: block;
}

.qa-answer {
  margin: 12px 0 0;
  background: #f8fbff;
  color: #0f172a;
  border: 1px solid #dbe7ff;
  border-radius: 12px;
  padding: 14px;
  line-height: 1.65;
  font-size: 15px;
}

.qa-answer h2,
.qa-answer h3,
.qa-answer h4 {
  margin: 0 0 8px;
  color: #0f172a;
}

.qa-answer h2 {
  font-size: 20px;
}

.qa-answer h3 {
  font-size: 18px;
}

.qa-answer h4 {
  font-size: 16px;
}

.qa-answer p {
  margin: 0 0 8px;
}

.qa-answer ul,
.qa-answer ol {
  margin: 0 0 8px;
  padding-left: 20px;
}

.qa-answer li {
  margin: 4px 0;
}

.qa-answer strong {
  color: #1d4ed8;
}

.qa-answer code {
  background: #e2e8f0;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 13px;
}

.qa-answer a {
  color: #2563eb;
  text-decoration: underline;
}

.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.invite-row code {
  font-size: 30px;
  font-weight: 700;
  color: #1e3a8a;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(68px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border-top: 1px solid #e5e7eb;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  z-index: 10;
}

.tab-btn {
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 54px;
  line-height: 1.2;
  cursor: pointer;
}

.tab-btn.active {
  background: #eff6ff;
  color: #2563eb;
}

.tab-icon {
  font-size: 18px;
}

.tab-text {
  font-size: 15px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: grid;
  place-items: end center;
  z-index: 20;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.panel {
  width: min(960px, 100%);
  max-height: min(78vh, 700px);
  overflow: auto;
  background: #fff;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border: 1px solid #e5e7eb;
  padding: 16px;
}

.panel.small {
  max-width: 640px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.panel-head .actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 640px) {
  .shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .brand h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 24px;
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .invite-row code {
    font-size: 24px;
  }
}
