/* ====== Reset & Base ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: #FFF5F5;
  color: #2D3436;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea {
  font-family: inherit;
  outline: none;
  border: 1.5px solid #E0E0E0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  width: 100%;
  background: #FAFAFA;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: #FF6B6B;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
  background: #FFF;
}
textarea { resize: vertical; min-height: 80px; }
select { appearance: auto; }

/* ====== Splash ====== */
.splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #FFF5F5 0%, #FFE0E0 100%);
  z-index: 9999;
  transition: opacity 0.4s, visibility 0.4s;
}
.splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-icon { font-size: 72px; margin-bottom: 16px; animation: splashBounce 1s ease infinite; }
@keyframes splashBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
.splash-text { font-size: 24px; font-weight: 700; color: #FF6B6B; margin-bottom: 24px; }
.spinner { width: 32px; height: 32px; border: 3px solid #FFD0D0; border-top-color: #FF6B6B; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== Setup Warning ====== */
.setup-warning {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #FFF5F5; z-index: 100;
  padding: 24px;
}
.setup-card {
  background: #FFF;
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}
.setup-icon { font-size: 64px; margin-bottom: 16px; }
.setup-card h2 { font-size: 22px; margin-bottom: 8px; color: #2D3436; }
.setup-card p { font-size: 15px; color: #636E72; margin-bottom: 24px; }

/* ====== App Shell ====== */
.app { display: flex; flex-direction: column; min-height: 100vh; max-width: 480px; margin: 0 auto; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
  color: #FFF;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 12px rgba(255, 107, 107, 0.3);
}
.header-left { display: flex; flex-direction: column; gap: 2px; }
.header-baby-name { font-size: 18px; font-weight: 700; }
.header-date { font-size: 12px; opacity: 0.85; }
.header-btn {
  background: rgba(255,255,255,0.2);
  color: #FFF;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.35); }

/* Content */
.app-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 80px;
  overflow-y: auto;
}

/* Bottom Nav */
.app-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: #FFF;
  border-top: 1px solid #F0F0F0;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.05);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  background: transparent;
  color: #B2BEC3;
  font-size: 11px;
  transition: color 0.2s;
}
.nav-item.active { color: #FF6B6B; }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 500; }

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-primary {
  background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
  color: #FFF;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(255, 107, 107, 0.4); }
.btn-secondary {
  background: #F0F0F0;
  color: #636E72;
}
.btn-secondary:hover { background: #E0E0E0; }
.btn-success {
  background: linear-gradient(135deg, #00B894, #00CEC9);
  color: #FFF;
  box-shadow: 0 4px 12px rgba(0, 184, 148, 0.3);
}
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 8px; }
.btn-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  padding: 0;
  font-size: 18px;
}

/* ====== Cards ====== */
.card {
  background: #FFF;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  margin-bottom: 12px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: #636E72;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-value {
  font-size: 28px;
  font-weight: 700;
  color: #2D3436;
}

/* ====== Dashboard ====== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat-card {
  background: #FFF;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  text-align: center;
}
.stat-card.full { grid-column: 1 / -1; }
.stat-icon { font-size: 32px; margin-bottom: 6px; }
.stat-label { font-size: 13px; color: #636E72; margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; color: #2D3436; }
.stat-sub { font-size: 12px; color: #B2BEC3; margin-top: 2px; }
.stat-card .status-ok { color: #00B894; }
.stat-card .status-warn { color: #FDCB6E; }
.stat-card .status-miss { color: #D63031; }

/* Vitamin pill */
.vitamin-pill {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
}
.vitamin-ad { background: #FFEAA7; color: #6C5B00; }
.vitamin-d3 { background: #DFE6E9; color: #2D3436; }

/* Quick actions */
.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 4px 0;
}
.quick-actions .btn {
  flex: 1;
  min-width: 72px;
  font-size: 13px;
  padding: 10px 8px;
  border-radius: 12px;
}

/* ====== Records Page ====== */
.record-tabs {
  display: flex;
  gap: 4px;
  background: #F0F0F0;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.record-tab {
  flex: 1;
  padding: 8px 4px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: #636E72;
  background: transparent;
  transition: all 0.2s;
  text-align: center;
}
.record-tab.active {
  background: #FFF;
  color: #FF6B6B;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.record-form { display: none; }
.record-form.active { display: block; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #636E72;
  margin-bottom: 6px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* Button group (radio-like) */
.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.btn-group .btn-option {
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  background: #F0F0F0;
  color: #636E72;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.btn-group .btn-option.selected {
  background: #FFF0F0;
  color: #FF6B6B;
  border-color: #FF6B6B;
}

/* ====== History ====== */
.history-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.history-filters .btn {
  flex-shrink: 0;
  font-size: 13px;
  padding: 8px 16px;
}
.history-list .record-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #F0F0F0;
}
.record-item:last-child { border-bottom: none; }
.record-item-icon { font-size: 24px; flex-shrink: 0; }
.record-item-info { flex: 1; }
.record-item-title { font-size: 14px; font-weight: 600; }
.record-item-meta { font-size: 12px; color: #B2BEC3; margin-top: 2px; }
.record-item-action { font-size: 18px; color: #D63031; background: transparent; padding: 4px; }

/* ====== Chat ====== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  max-height: calc(100vh - 140px);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
}
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.bot { align-self: flex-start; }
.chat-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.chat-msg.user .chat-avatar { background: #FF6B6B; }
.chat-msg.bot .chat-avatar { background: #DFE6E9; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}
.chat-msg.user .chat-bubble {
  background: #FF6B6B;
  color: #FFF;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot .chat-bubble {
  background: #FFF;
  color: #2D3436;
  border: 1px solid #F0F0F0;
  border-bottom-left-radius: 4px;
}
.chat-bubble p { margin-bottom: 8px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { padding-left: 18px; margin-bottom: 8px; }
.chat-bubble li { margin-bottom: 4px; }

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  background: #FFF5F5;
  border-top: 1px solid #F0F0F0;
}
.chat-input-area input {
  flex: 1;
  border-radius: 24px;
  padding: 10px 16px;
}
.chat-input-area .btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  flex-shrink: 0;
}
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}
.chat-typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #B2BEC3;
  animation: typing 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Chat data cards */
.chat-data-card {
  background: #F8F9FA;
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0;
  border-left: 3px solid #FF6B6B;
}
.chat-data-card .data-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.chat-data-card .data-row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }

/* ====== Settings ====== */
.settings-section {
  margin-bottom: 24px;
}
.settings-section h3 {
  font-size: 16px;
  font-weight: 700;
  color: #2D3436;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #FFE0E0;
}
.settings-section .note {
  font-size: 12px;
  color: #B2BEC3;
  margin-top: 4px;
}
.setting-input-group { margin-bottom: 12px; }
.setting-input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #636E72;
  margin-bottom: 4px;
}
.setting-input-group input, .setting-input-group select {
  font-size: 14px;
}
.setting-input-group .hint {
  font-size: 12px;
  color: #B2BEC3;
  margin-top: 4px;
}

/* ====== Chart Container ====== */
.chart-container {
  background: #FFF;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  margin-bottom: 12px;
}
.chart-container canvas { max-height: 220px; }

/* ====== Emergency record button (floating) ====== */
.fab {
  position: fixed;
  bottom: 80px;
  right: max(16px, calc((100vw - 480px) / 2 + 16px));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
  color: #FFF;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(255, 107, 107, 0.4);
  z-index: 40;
  transition: transform 0.2s;
}
.fab:hover { transform: scale(1.1); }

/* ====== Utilities ====== */
.text-center { text-align: center; }
.text-muted { color: #B2BEC3; }
.mt-8 { margin-top: 8px; }
.mb-8 { margin-bottom: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }

/* Delete confirm */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 24px;
}
.confirm-dialog {
  background: #FFF;
  border-radius: 20px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}
.confirm-dialog h3 { margin-bottom: 8px; }
.confirm-dialog p { font-size: 14px; color: #636E72; margin-bottom: 20px; }
.confirm-dialog .form-actions { margin-top: 0; }

/* Quick insert button at bottom of records */
.quick-preset {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.quick-preset .btn {
  font-size: 20px;
  padding: 14px 8px;
  background: #F8F9FA;
  border: 1.5px solid #F0F0F0;
  color: #636E72;
}
.quick-preset .btn:hover { border-color: #FF6B6B; color: #FF6B6B; }

/* ====== Empty state ====== */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: #B2BEC3;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ====== Responsive ====== */
@media (min-width: 480px) {
  .app-content { padding: 20px; padding-bottom: 84px; }
}
