:root {
  --brand: #FF9812;
  --brand-light: #FFF3E0;
  --brand-deep: #C77500;
  --success: #27AE60;
  --success-light: #E8F5E9;
  --danger: #E74C3C;
  --danger-light: #FDECEA;
  --info: #3498DB;
  --info-light: #EAF4FC;
  --t1: #333;
  --t2: #666;
  --t3: #999;
  --t4: #BBB;
  --bg: #F4F4F4;
  --white: #fff;
  --neutral: #F2F3F5;
  --border: #E5E5E5;
  --divider: #F0F0F0;
  --fs-title: 17px;
  --fs-body: 16px;
  --fs-sub: 14px;
  --fs-cap: 12px;
  --fs-micro: 10px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --r-pill: 999px;
  --r-card: 12px;
  --r-input: 6px;
  --r-tag: 4px;
  --sh-card: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 12px -4px rgba(16, 24, 40, .06);
  --sh-float: 0 8px 24px -8px rgba(16, 24, 40, .25);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100%;
  margin: 0;
  color: var(--t1);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(255, 152, 18, .3);
  outline-offset: 2px;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
}

.loading-screen, .auth-screen, .setup-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
}

.loading-screen { align-items: center; color: var(--t3); font-size: var(--fs-sub); }
.loading-mark, .auth-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  color: var(--brand);
  background: var(--brand-light);
  border-radius: 50%;
}
.loading-mark svg, .auth-mark svg { width: 30px; height: 30px; }

.auth-screen { background: var(--white); }
.auth-mark { margin: 0 auto 20px; }
.auth-screen h1, .setup-screen h1 { text-align: center; font-size: 26px; line-height: 1.35; margin: 0 0 8px; }
.auth-subtitle, .setup-subtitle { margin: 0 auto 28px; color: var(--t3); font-size: var(--fs-sub); text-align: center; }
.auth-form, .setup-form { width: 100%; max-width: 360px; margin: 0 auto; }
.auth-form .primary-button, .setup-form .primary-button { width: 100%; margin-top: 22px; }
.auth-error, .form-error { min-height: 20px; color: var(--danger); font-size: var(--fs-cap); margin: 8px 0 0; }
.auth-hint { margin-top: 24px; color: var(--t4); font-size: var(--fs-cap); text-align: center; line-height: 1.7; }

.page { min-height: 100vh; min-height: 100dvh; padding-bottom: 76px; }
.page.home-page { background: var(--bg); }
.topbar {
  min-height: 56px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--white);
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--divider);
}
.topbar .title { font-size: var(--fs-title); font-weight: 700; flex: 1; }
.topbar .top-action { color: var(--t2); background: transparent; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }
.topbar .top-action:hover { background: var(--neutral); }
.back-button { color: var(--t2); background: transparent; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }
.back-button:hover { background: var(--neutral); }

.baby-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--white);
}
.baby-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  color: var(--brand);
  background: var(--brand-light);
  border-radius: 50%;
}
.baby-avatar svg { width: 22px; height: 22px; }
.baby-name { font-size: var(--fs-body); font-weight: 700; }
.baby-age { margin-top: 2px; color: var(--t3); font-size: var(--fs-cap); }
.header-settings { margin-left: auto; color: var(--t2); background: transparent; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }

.since-card {
  margin: 0 16px;
  padding: 16px;
  border-radius: var(--r-card);
  background: var(--brand-light);
}
.since-label { color: var(--brand-deep); font-size: var(--fs-cap); }
.since-value { margin-top: 2px; font-size: 28px; line-height: 1.35; font-weight: 700; }
.since-note { color: var(--t2); font-size: var(--fs-cap); line-height: 1.5; }
.since-empty { color: var(--t2); font-size: var(--fs-sub); padding: 8px 0 2px; }

.sleeping-card {
  margin: 12px 16px 0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(52, 152, 219, .22);
  border-radius: var(--r-card);
  background: var(--info-light);
}
.sleeping-card .sleep-copy { flex: 1; }
.sleeping-card .sleep-copy strong { display: block; font-size: var(--fs-body); }
.sleeping-card .sleep-copy small { color: var(--t2); font-size: var(--fs-cap); }
.sleeping-icon { color: var(--info); }
.small-outline-button { height: 36px; padding: 0 12px; color: var(--t2); background: var(--white); border: 1px solid var(--border); border-radius: var(--r-input); font-size: var(--fs-cap); }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; background: var(--white); }
.action-tile {
  min-height: 100px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--t1);
  background: var(--neutral);
  border-radius: var(--r-card);
  font-weight: 700;
  transition: transform .12s ease, background .12s ease;
}
.action-tile:active { transform: scale(.98); }
.action-tile .action-icon { width: 38px; height: 38px; display: grid; place-items: center; background: var(--white); border-radius: 50%; }
.action-tile.feed .action-icon { color: var(--brand); }
.action-tile.diaper .action-icon { color: var(--info); }
.action-tile.sleep .action-icon { color: var(--t2); }
.action-tile.other .action-icon { color: var(--success); }

.today-card { padding: 12px 16px 16px; background: var(--white); }
.section-heading { margin: 0 0 10px; font-size: var(--fs-sub); font-weight: 700; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.stat-number { font-size: 20px; line-height: 1.25; font-weight: 700; }
.stat-label { margin-top: 3px; color: var(--t3); font-size: var(--fs-cap); }
.empty-card { padding: 36px 24px; text-align: center; color: var(--t3); font-size: var(--fs-sub); }

.bottom-nav {
  position: fixed;
  z-index: 15;
  left: 50%;
  bottom: 0;
  width: min(480px, 100%);
  height: calc(60px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateX(-50%);
  display: flex;
  background: rgba(255, 255, 255, .98);
  border-top: 1px solid var(--divider);
}
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--t3); background: transparent; font-size: var(--fs-micro); }
.nav-item.on { color: var(--brand); font-weight: 700; }
.nav-item svg { width: 19px; height: 19px; }

.content-area { background: var(--bg); min-height: calc(100vh - 56px); }
.filter-row { display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; background: var(--white); border-bottom: 1px solid var(--divider); scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip, .choice-chip, .quick-chip {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 13px;
  color: var(--t2);
  background: var(--neutral);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: var(--fs-cap);
}
.filter-chip.on, .choice-chip.on, .quick-chip.on { color: var(--brand-deep); background: var(--brand-light); border-color: var(--brand); font-weight: 700; }
.timeline { padding: 0 0 16px; }
.day-header { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px 8px; color: var(--t3); font-size: var(--fs-cap); }
.day-summary { text-align: right; }
.event-row {
  width: 100%;
  min-height: 64px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--t1);
  text-align: left;
  background: var(--white);
  border-bottom: 1px solid var(--divider);
}
.event-row:hover { background: #FFFEFC; }
.event-time { width: 42px; flex: 0 0 42px; color: var(--t2); font-size: var(--fs-sub); }
.event-icon { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border-radius: 50%; }
.event-icon.feed { color: var(--brand); background: var(--brand-light); }
.event-icon.diaper { color: var(--info); background: var(--info-light); }
.event-icon.sleep { color: var(--t2); background: var(--neutral); }
.event-icon.other, .event-icon.growth { color: var(--success); background: var(--success-light); }
.event-copy { min-width: 0; flex: 1; }
.event-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-body); }
.event-by { margin-top: 3px; color: var(--t3); font-size: var(--fs-cap); }
.tag { display: inline-flex; align-items: center; min-height: 20px; padding: 0 6px; border-radius: var(--r-tag); font-size: var(--fs-micro); vertical-align: 1px; }
.tag.grey { color: var(--t2); background: var(--neutral); }
.tag.warning { color: #A63E32; background: var(--danger-light); }
.tag.green { color: var(--success); background: var(--success-light); }
.load-more { display: block; margin: 16px auto 0; padding: 10px 18px; color: var(--t2); background: var(--white); border: 1px solid var(--border); border-radius: var(--r-pill); font-size: var(--fs-cap); }

.growth-toolbar { padding: 8px 16px; background: var(--white); border-bottom: 1px solid var(--divider); display: flex; gap: 8px; }
.metric-tab { flex: 1; height: 36px; color: var(--t2); background: var(--neutral); border-radius: var(--r-input); font-size: var(--fs-sub); }
.metric-tab.on { color: var(--brand-deep); background: var(--brand-light); font-weight: 700; }
.data-card { margin: 12px 16px; padding: 16px; background: var(--white); border-radius: var(--r-card); box-shadow: var(--sh-card); }
.data-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: var(--fs-body); font-weight: 700; }
.data-card-head .link-button { color: var(--brand-deep); background: transparent; font-size: var(--fs-sub); font-weight: 600; }
.chart-box { height: 250px; position: relative; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
.legend-row { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; color: var(--t3); font-size: var(--fs-cap); }
.legend-dot { width: 10px; height: 10px; display: inline-block; margin-right: 4px; border-radius: 2px; vertical-align: -1px; }
.growth-note { margin: 8px 0 0; color: var(--t3); font-size: var(--fs-cap); line-height: 1.7; }
.growth-kpi { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.growth-kpi .kpi { padding: 12px; background: var(--neutral); border-radius: var(--r-input); }
.kpi-value { font-size: 20px; font-weight: 700; }
.kpi-label { margin-top: 4px; color: var(--t3); font-size: var(--fs-cap); }

.settings-list { margin: 12px 0; background: var(--white); }
.settings-section-label { padding: 12px 16px 6px; color: var(--t3); font-size: var(--fs-cap); background: var(--bg); }
.settings-row { min-height: 58px; padding: 10px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--divider); }
.settings-row:last-child { border-bottom: 0; }
.settings-row .row-copy { flex: 1; min-width: 0; }
.settings-row .main { font-size: var(--fs-body); }
.settings-row .sub { margin-top: 3px; color: var(--t3); font-size: var(--fs-cap); }
.settings-row .row-action { color: var(--t2); background: transparent; }
.danger-button { width: calc(100% - 32px); height: 46px; margin: 20px 16px; color: var(--danger); background: var(--white); border: 1px solid rgba(231, 76, 60, .35); border-radius: var(--r-input); }

.sheet-backdrop { position: fixed; z-index: 30; inset: 0; display: flex; align-items: flex-end; background: rgba(0, 0, 0, .34); }
.sheet { width: min(480px, 100%); max-height: 92vh; max-height: 92dvh; overflow-y: auto; padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); margin: 0 auto; background: var(--white); border-radius: 16px 16px 0 0; box-shadow: var(--sh-float); }
.sheet-handle { width: 34px; height: 4px; margin: 0 auto 12px; background: var(--border); border-radius: var(--r-pill); }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 2px; }
.sheet-title { margin: 0; font-size: 20px; }
.sheet-close { width: 36px; height: 36px; display: grid; place-items: center; color: var(--t2); background: var(--neutral); border-radius: 50%; }
.sheet-sub { color: var(--t3); font-size: var(--fs-cap); line-height: 1.6; }
.sheet-link { color: var(--brand-deep); background: transparent; font-size: var(--fs-cap); }
.chips { display: flex; gap: 8px; margin: 14px 0; }
.chips .choice-chip { flex: 1; height: 40px; border-radius: var(--r-input); }
.form-group { margin: 14px 0; }
.form-label { display: block; margin-bottom: 7px; color: var(--t2); font-size: var(--fs-cap); }
.text-input, .select-input, .number-input, .date-input, .textarea-input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  color: var(--t1);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.textarea-input { min-height: 80px; resize: vertical; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.amount-control { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.stepper-button { width: 42px; height: 42px; display: grid; place-items: center; color: var(--t1); background: var(--neutral); border-radius: 50%; }
.amount-value { font-size: 32px; font-weight: 700; }
.amount-value small { margin-left: 3px; color: var(--t3); font-size: var(--fs-sub); font-weight: 400; }
.quick-row { display: flex; gap: 8px; margin-bottom: 16px; }
.quick-row .quick-chip { flex: 1; padding: 0; border-radius: var(--r-tag); }
.primary-button { min-height: 46px; padding: 0 20px; color: var(--white); background: var(--brand); border-radius: var(--r-pill); font-weight: 700; }
.secondary-button { min-height: 44px; padding: 0 18px; color: var(--t2); background: var(--white); border: 1px solid var(--border); border-radius: var(--r-input); }
.full-button { width: 100%; }
.button-row { display: flex; gap: 10px; margin-top: 18px; }
.button-row > * { flex: 1; }
.timer-tip { margin: 2px 0 12px; color: var(--t3); font-size: var(--fs-cap); }
.timer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.timer-box { padding: 12px 8px; text-align: center; border: 1px solid var(--border); border-radius: var(--r-input); }
.timer-box.run { border-color: var(--brand); }
.timer-box .timer-title { color: var(--t3); font-size: var(--fs-cap); }
.timer-box .timer-time { margin: 4px 0 8px; font-size: 22px; font-weight: 700; }
.timer-box.run .timer-time { color: var(--brand); }
.timer-box input { width: 72px; min-height: 34px; padding: 5px 7px; text-align: center; border: 1px solid var(--border); border-radius: var(--r-input); }
.timer-box .timer-button { min-height: 32px; padding: 0 8px; color: var(--t2); background: var(--neutral); border-radius: var(--r-tag); font-size: var(--fs-cap); }
.timer-box.run .timer-button { color: var(--brand-deep); background: var(--brand-light); }
.warning-note { margin-top: 8px; padding: 9px 10px; color: #9A3A2F; background: var(--danger-light); border-radius: var(--r-input); font-size: var(--fs-cap); line-height: 1.5; }
.radio-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.radio-button { min-height: 40px; color: var(--t2); background: var(--neutral); border-radius: var(--r-input); font-size: var(--fs-sub); }
.radio-button.on { color: var(--brand-deep); background: var(--brand-light); border: 1px solid var(--brand); font-weight: 700; }
.sheet-divider { height: 1px; margin: 14px 0; background: var(--divider); }

.setup-screen { background: var(--white); justify-content: flex-start; padding-top: 56px; }
.setup-screen h1 { margin-top: 18px; }
.setup-form .form-group { margin-top: 18px; }
.sex-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sex-button { min-height: 44px; color: var(--t2); background: var(--neutral); border-radius: var(--r-input); }
.sex-button.on { color: var(--brand-deep); background: var(--brand-light); border: 1px solid var(--brand); font-weight: 700; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  transform: translateX(-50%);
  color: var(--white);
  background: rgba(51, 51, 51, .92);
  border-radius: var(--r-pill);
  font-size: var(--fs-sub);
  text-align: center;
}
.hidden { display: none !important; }

@media (min-width: 680px) {
  body { padding: 24px 0; }
  .app-shell { min-height: calc(100vh - 48px); border-radius: 18px; box-shadow: 0 12px 40px rgba(16, 24, 40, .08); overflow: hidden; }
  .page, .auth-screen, .setup-screen, .loading-screen { min-height: calc(100vh - 48px); }
  .bottom-nav { bottom: 24px; border-radius: 0 0 18px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
.today-sleep { margin: 10px 0 0; text-align: center; font-size: 12px; color: var(--text-3, #999); }
.recent-card { margin-top: 8px; padding: 12px 16px 16px; background: var(--white); }
.recent-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.recent-table th { font-weight: 400; color: #999; padding: 4px 0 6px; font-size: 12px; }
.recent-table td { padding: 7px 0; border-top: 1px solid #f2f2f2; }
.recent-table th:first-child, .recent-table td:first-child { text-align: left; color: #666; }
