/* ============ 沐瀚成长日记 · 奶呼呼育儿本 ============ */
:root {
  --bg: #FFF3EA;
  --card: #FFFDF9;
  --side: #FFE8DC;
  --side-hover: #FFDCCB;
  --primary: #E7A48B;
  --primary-dark: #D48971;
  --accent: #F2B8A8;
  --accent-dark: #E39A88;
  --blue: #B7D5E4;
  --brown: #E8C9A4;
  --purple: #D7C4E6;
  --text: #6A5348;
  --text-light: #A18478;
  --line: #F3D8C8;
  --danger: #E08B86;
  --radius: 24px;
  --shadow: 0 10px 28px rgba(212, 137, 113, 0.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Songti SC", serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12px 12px, rgba(242, 184, 168, .28) 1.6px, transparent 2px),
    radial-gradient(ellipse at 88% -8%, rgba(255, 214, 170, .55), transparent 46%),
    radial-gradient(ellipse at 0% 100%, rgba(183, 213, 228, .38), transparent 42%);
  background-size: 28px 28px, auto, auto;
  color: var(--text);
  font-size: 14.5px;
  letter-spacing: .02em;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 232px;
  background: var(--side);
  display: flex;
  flex-direction: column;
  transition: width .25s ease;
  flex-shrink: 0;
  position: relative;
  border-right: 1px solid var(--line);
}
#sidebar.collapsed { width: 68px; }
#sidebar.collapsed .logo-text, #sidebar.collapsed .nav-label { display: none; }
#sidebar.collapsed .logo-chip { margin: 0 auto; }

.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
}
.logo-chip {
  width: 42px; height: 42px; flex-shrink: 0;
  background: linear-gradient(160deg, #FFE7C2, #F2B8A8);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: 0 4px 12px rgba(227, 154, 136, .35);
}
.logo-title { font-size: 15px; font-weight: 600; letter-spacing: .5px; }
.logo-sub { font-size: 11px; color: var(--text-light); }

#nav { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
#nav::-webkit-scrollbar { width: 4px; }
#nav::-webkit-scrollbar-thumb { background: #D5CCC0; border-radius: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 3px;
  border-radius: 18px; cursor: pointer;
  color: var(--text); text-decoration: none;
  transition: background .15s;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: var(--side-hover); }
.nav-item.active {
  background: linear-gradient(135deg, #FFD9C8, #F2B8A8);
  box-shadow: 0 4px 12px rgba(227,154,136,.28);
}
.nav-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff;
}
.nav-label { font-size: 13.5px; }
.nav-item .badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 10px; border-radius: 8px; padding: 1px 6px;
}
#sidebar.collapsed .nav-item .badge { display: none; }

.toggle-btn {
  align-self: center; margin-bottom: 14px;
  width: 36px; height: 26px; border-radius: 999px; border: none;
  background: #FFE1D1; color: var(--text-light); cursor: pointer;
  font-size: 12px;
}
.toggle-btn:hover { background: #FFD3BE; }

/* ---------- 主区域 ---------- */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#topbar {
  height: 58px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; background: rgba(255, 253, 249, .82);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
  flex-shrink: 0;
}
#page-title { font-size: 17px; font-weight: 600; }
.baby-badge {
  background: linear-gradient(135deg, #FFE7C2, #F2B8A8);
  padding: 6px 14px; border-radius: 999px; font-size: 12.5px; color: #9A5D4C;
}
#page { flex: 1; overflow-y: auto; padding: 24px 28px; }
#page::-webkit-scrollbar { width: 6px; }
#page::-webkit-scrollbar-thumb { background: #D5CCC0; border-radius: 3px; }
.footer-note { text-align: center; padding: 12px; color: #B7B0A6; font-size: 12px; flex-shrink: 0; }

/* ---------- 卡片 ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  border: 1px solid rgba(243, 216, 200, .7);
}
.card-title { font-size: 14.5px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.stat-num { font-size: 30px; font-weight: 700; color: var(--primary-dark); }
.stat-num small { font-size: 13px; font-weight: 400; color: var(--text-light); margin-left: 4px; }
.stat-label { font-size: 12.5px; color: var(--text-light); margin-top: 6px; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 50%; font-size: 21px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.clickable { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(90,80,70,.13); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-light); font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #F0EBE3; white-space: nowrap; }
tr:hover td { background: #FAF7F2; }
.row-actions button {
  background: none; border: none; cursor: pointer; font-size: 15px; padding: 2px 4px; opacity: .6;
}
.row-actions button:hover { opacity: 1; }
.empty {
  text-align: center; color: #BCB4A8; padding: 40px 0; font-size: 13px;
}
.empty .empty-emoji { font-size: 34px; display: block; margin-bottom: 10px; }

/* ---------- 按钮 / 表单 ---------- */
.btn {
  border: none; border-radius: 999px; padding: 9px 18px; font-size: 13.5px;
  cursor: pointer; font-family: inherit; transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, #F2B8A8, #E7A48B); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: #FFE8DC; color: var(--text); }
.btn.ghost:hover { background: #FFDCCB; }
.btn.danger { background: #FAD7D4; color: #B45A56; }
.btn.small { padding: 5px 12px; font-size: 12.5px; border-radius: 999px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-light); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 16px;
  padding: 10px 14px; font-size: 14px; font-family: inherit;
  background: #FFF8F3; color: var(--text); outline: none;
  transition: border .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 弹窗 ---------- */
#modal-mask {
  position: fixed; inset: 0; background: rgba(80, 72, 64, .35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(3px);
}
#modal-mask.hidden, .hidden { display: none !important; }
#modal {
  background: var(--card); border-radius: 28px; padding: 24px;
  width: min(520px, 92vw); max-height: 86vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(212, 137, 113, .22);
}
#modal-title { font-size: 16px; font-weight: 600; margin-bottom: 18px; }
#modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%);
  background: #57534C; color: #fff; padding: 10px 22px; border-radius: 12px;
  font-size: 13.5px; z-index: 200; box-shadow: 0 8px 30px rgba(0,0,0,.2);
  animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ---------- 标签 / 状态 ---------- */
.tag {
  display: inline-block; padding: 3px 10px; border-radius: 8px;
  font-size: 12px; background: #EDE9E1; color: var(--text-light);
}
.tag.green { background: #DCE7D8; color: #6E8566; }
.tag.orange { background: #F0E2CB; color: #A5814B; }
.tag.red { background: #EBD2CF; color: #A05A55; }
.tag.blue { background: #DCE4EA; color: #6E8298; }
.tag.purple { background: #E4DFF0; color: #85799F; }

.section-gap { margin-top: 20px; }
.muted { color: var(--text-light); font-size: 12.5px; }
.formula-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #EFE7DC; color: #9A8267; border-radius: 10px;
  padding: 5px 12px; font-size: 12.5px; margin: 3px 4px 3px 0;
}
.subtabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.subtab {
  border: none; background: #FFE8DC; color: var(--text);
  padding: 7px 16px; border-radius: 999px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.subtab.active { background: linear-gradient(135deg, #F2B8A8, #E7A48B); color: #fff; }

/* 分享链接框 */
.share-link-box {
  display: flex; gap: 8px; align-items: center;
  background: #F6F3EE; border: 1px dashed #CFC6B8; border-radius: 12px;
  padding: 12px 14px; font-size: 13px; color: #7A736A; word-break: break-all;
}
.toggle-switch {
  width: 44px; height: 24px; border-radius: 12px; background: #D9D2C7;
  position: relative; cursor: pointer; transition: background .2s; flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle-switch.on { background: var(--primary); }
.toggle-switch.on::after { left: 22px; }

/* 生长曲线 */
.chart-box { position: relative; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-light); margin-top: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }

/* 只读模式提示 */
.readonly-banner {
  background: #FFE7C2; color: #9A5D4C; text-align: center;
  padding: 8px; font-size: 13px; border-radius: 0 0 16px 16px;
}

/* ---------- 密码门锁 ---------- */
#gate { display: none; }
body.locked #app { display: none; }
body.locked #gate {
  display: flex; position: fixed; inset: 0; z-index: 400;
  align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 214, 170, .7), transparent 46%),
    radial-gradient(ellipse at 90% 100%, rgba(183, 213, 228, .5), transparent 42%),
    #FFF3EA;
}
.gate-sky { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.gate-star { position: absolute; color: #E7A48B; opacity: .55; font-size: 18px; }
.gate-star.s1 { top: 12%; left: 14%; }
.gate-star.s2 { top: 22%; right: 18%; font-size: 14px; }
.gate-star.s3 { bottom: 18%; left: 22%; }
.gate-cloud {
  position: absolute; width: 120px; height: 42px; border-radius: 999px;
  background: rgba(255,255,255,.55);
}
.gate-cloud::before, .gate-cloud::after {
  content: ''; position: absolute; background: inherit; border-radius: 50%;
}
.gate-cloud::before { width: 52px; height: 52px; top: -22px; left: 18px; }
.gate-cloud::after { width: 38px; height: 38px; top: -14px; right: 22px; }
.gate-cloud.c1 { top: 16%; right: 10%; }
.gate-cloud.c2 { bottom: 14%; left: 8%; width: 90px; }
.gate-card {
  position: relative; width: min(400px, 100%);
  background: #FFFDF9; border-radius: 32px; padding: 36px 28px 28px;
  box-shadow: 0 18px 50px rgba(212, 137, 113, .18);
  border: 1px solid rgba(243, 216, 200, .8);
  text-align: center;
}
.gate-chip {
  width: 72px; height: 72px; margin: 0 auto 14px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 38px; background: linear-gradient(160deg, #FFE7C2, #F2B8A8);
  box-shadow: 0 8px 20px rgba(227, 154, 136, .3);
}
.gate-kicker {
  font-size: 11px; letter-spacing: .28em; color: #E7A48B; margin-bottom: 8px;
}
.gate-card h1 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.gate-copy { color: var(--text-light); margin-bottom: 22px; line-height: 1.7; }
.gate-card .field { text-align: left; }
.gate-btn { width: 100%; padding: 12px 18px; font-size: 15px; }
.gate-error { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* ===================================================
 * 移动端适配（≤ 768px）
 * - 侧边栏改为抽屉式
 * - 顶栏增加汉堡菜单
 * - 页面 padding 收紧
 * - 表格、表单、弹窗适配
 * =================================================== */
@media (max-width: 768px) {
  /* 抽屉遮罩 */
  #sidebar-mask {
    position: fixed; inset: 0; background: rgba(80,72,64,.35);
    z-index: 90; backdrop-filter: blur(2px);
  }
  #sidebar-mask:not(.hidden) { display: block; }

  /* 侧边栏改抽屉 */
  #sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    z-index: 95; box-shadow: 4px 0 24px rgba(80,72,64,.25);
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 248px !important;
  }
  #sidebar.mobile-open { transform: translateX(0); }
  /* 抽屉模式下隐藏 PC 的折叠按钮 */
  #sidebar .toggle-btn { display: none; }
  /* 抽屉展开时不裁切文字 */
  #sidebar .logo-text, #sidebar .nav-label { display: block !important; }
  #sidebar .logo-chip { margin: 0 !important; }

  /* 主区域铺满 */
  #main { width: 100%; }
  #topbar { padding: 0 14px !important; height: 52px !important; }
  #page-title { font-size: 15px !important; }
  #baby-badge { font-size: 11.5px !important; padding: 4px 10px !important; }
  #page { padding: 14px 14px 24px !important; }
  .footer-note { font-size: 11px !important; padding: 10px !important; }

  /* 显示汉堡菜单 */
  .menu-btn {
    display: inline-flex !important;
    align-items: center; justify-content: center;
    width: 36px; height: 36px; border: none; background: transparent;
    color: var(--text); font-size: 20px; cursor: pointer;
    border-radius: 10px; margin-right: 8px;
  }
  .menu-btn:hover { background: var(--side-hover); }

  /* 顶栏在窄屏允许 badge 截断 */
  #topbar-right { min-width: 0; }
  #baby-badge { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }

  /* 卡片更紧凑 */
  .card { padding: 14px !important; border-radius: 14px !important; }
  .card-title { font-size: 13.5px !important; margin-bottom: 10px !important; }
  .stat-num { font-size: 22px !important; }
  .stat-num small { font-size: 11px !important; }
  .stat-label { font-size: 11.5px !important; }
  .stat-icon { width: 36px !important; height: 36px !important; font-size: 18px !important; margin-bottom: 8px !important; }

  /* 网格在移动端全部单列 */
  .grid { gap: 12px !important; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr 1fr !important; }

  /* 表格：横向滚动 */
  .table-wrap { margin: 0 -14px; padding: 0 14px; }

  /* 按钮大一点，方便点 */
  .btn { padding: 10px 16px !important; font-size: 14px !important; }
  .btn.small { padding: 7px 12px !important; font-size: 13px !important; }

  /* 表单更紧凑 */
  .field { margin-bottom: 12px !important; }
  .field input, .field select, .field textarea { font-size: 16px !important; padding: 11px 12px !important; }  /* 16px 防止 iOS 放大 */
  .field-row { grid-template-columns: 1fr !important; gap: 0 !important; }

  /* 弹窗占满屏幕底部 */
  #modal {
    width: 100vw !important; max-width: 100vw !important;
    height: auto; max-height: 92vh;
    border-radius: 18px 18px 0 0 !important;
    padding: 18px 16px 20px !important;
    margin-top: auto;
  }
  #modal-mask { align-items: flex-end !important; }
  #modal-title { font-size: 15px !important; margin-bottom: 14px !important; }
  #modal-actions .btn { flex: 1; padding: 12px !important; }

  /* toast 不挡顶栏 */
  #toast { top: 60px !important; font-size: 13px !important; padding: 8px 18px !important; }

  /* 子 tabs 可滚动 */
  .subtabs { overflow-x: auto; flex-wrap: nowrap !important; padding-bottom: 4px; }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtab { flex-shrink: 0; padding: 7px 14px !important; }

  /* 分享链接框 */
  .share-link-box { font-size: 12px !important; padding: 10px !important; }
  .formula-chip { font-size: 11.5px !important; padding: 4px 10px !important; }

  /* 喂奶过滤区按钮可换行 */
  .row { flex-wrap: wrap; gap: 6px !important; }

  /* chart 容器自适应 */
  .chart-box { overflow-x: auto; }
  .chart-box svg { max-width: 100%; height: auto; }
}

/* 极小屏（≤ 380px）单列 */
@media (max-width: 380px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr !important; }
}

/* 防止 input 在 iOS 缩放（input font-size >= 16px 已在上面处理） */
@supports (-webkit-touch-callout: none) {
  .field input, .field select, .field textarea { font-size: 16px !important; }
}
