/* [style.css] 全局视觉：温暖奶油底 + 杏橙主色，卡片/底栏/表单/表格/锁屏，移动端优先 */

/* ===== 主题变量 ===== */
:root {
  --bg: #FBF6EE;            /* 奶油底 */
  --card: #FFFFFF;          /* 卡片底 */
  --primary: #F2A65A;       /* 杏橙主色 */
  --primary-deep: #D98A3B;  /* 主色加深（激活文字） */
  --primary-soft: #FBE8D3;  /* 主色浅底 */
  --green: #88B78A;         /* 达标/柔绿 */
  --green-soft: #E9F2E9;
  --red: #E57373;           /* 警示 */
  --red-soft: #FBE9E9;
  --amber: #E8B04B;         /* 边缘/琥珀 */
  --amber-soft: #FBF0DB;
  --ink: #4A3F35;           /* 深字 */
  --ink-2: #7C6F60;         /* 次级文字 */
  --line: #EDE2D2;          /* 描边/分隔 */
  --gray: #B9B0A3;          /* 未记录/灰 */
  --gray-soft: #F0ECE4;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(74, 63, 53, 0.08);
  --shadow-lg: 0 6px 24px rgba(74, 63, 53, 0.14);
}

/* ===== 基础 ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font: inherit; color: inherit; font-size: 16px; }
h1, h2, h3 { line-height: 1.3; }

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ===== 应用外壳布局 ===== */
#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(251, 246, 238, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-name { font-size: 18px; font-weight: 700; }
.topbar-sep { color: var(--ink-2); }
.topbar-age { font-size: 13px; color: var(--ink-2); }
.topbar-date { margin-left: auto; font-size: 13px; color: var(--ink-2); white-space: nowrap; }

#page {
  flex: 1;
  padding: 12px 14px 84px; /* 底部留出标签栏高度 */
}

/* ===== 底部标签栏 ===== */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink-2);
}
.tab-icon { font-size: 20px; line-height: 1.1; }
.tab-label { font-size: 11px; }
.tab.active { color: var(--primary-deep); font-weight: 700; }
.tab.active .tab-icon { transform: translateY(-1px); }

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 10px;
}
.card-title .spacer { flex: 1; }
.big-num { font-size: 30px; font-weight: 800; line-height: 1.15; }
.muted { color: var(--ink-2); font-size: 13px; }
.small { font-size: 12px; }
.empty {
  color: var(--ink-2);
  text-align: center;
  padding: 22px 12px;
  font-size: 14px;
}

/* ===== 状态色（卡片强调 / 徽章通用）===== */
/* 用法：卡片 .card.ok 左侧色条 + 浅色底；徽章 .pill.warn */
.ok   { --status: var(--green); --status-soft: var(--green-soft); --status-ink: #3E7241; }
.warn { --status: var(--amber); --status-soft: var(--amber-soft); --status-ink: #8F6414; }
.bad  { --status: var(--red);   --status-soft: var(--red-soft);   --status-ink: #B93F3F; }
.idle { --status: var(--gray);  --status-soft: var(--gray-soft);  --status-ink: #6E6254; }

.card.ok, .card.warn, .card.bad, .card.idle {
  border-left: 4px solid var(--status);
  background: linear-gradient(to right, var(--status-soft), var(--card) 42%);
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--status-soft, var(--gray-soft));
  color: var(--status-ink, var(--ink-2));
  white-space: nowrap;
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status, var(--gray));
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 18px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn-ghost {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-danger { background: var(--red); }
.btn-block { display: flex; width: 100%; }

/* ===== 分段切换 ===== */
.segment {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--gray-soft);
  border-radius: 13px;
  margin-bottom: 12px;
}
.segment button {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.segment button.active {
  background: var(--card);
  color: var(--primary-deep);
  box-shadow: var(--shadow);
}

/* ===== 表单 ===== */
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 0;
}
.form-row > label, .row-label {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 600;
}
.form-row .grow { flex: 1; min-width: 0; }

input[type="text"], input[type="number"], input[type="password"],
input[type="date"], input[type="time"], input[type="month"],
select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 76px; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; }

/* ===== 快捷芯片（常用食物等）===== */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
}
.chip {
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}
.chip:active, .chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-deep);
  font-weight: 600;
}

/* ===== Bristol 分型选择器 ===== */
.bristol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.bristol-btn {
  min-height: 66px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink-2);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
}
.bristol-btn .num { font-size: 18px; font-weight: 800; color: var(--ink); }
.bristol-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.bristol-btn.active .num { color: var(--primary-deep); }

/* ===== 进度条 ===== */
.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--gray-soft);
  overflow: hidden;
}
.progress-bar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.25s ease;
}
.progress-bar.ok { background: var(--green); }

/* ===== 参考表（横向滚动 + 首列吸附 + 当前月龄高亮）===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
table.data {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 500px;
  font-size: 13px;
}
.data th, .data td {
  padding: 9px 10px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--primary-soft);
  font-weight: 700;
}
.data th:first-child, .data td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  font-weight: 700;
  border-right: 1px solid var(--line);
}
.data thead th:first-child { z-index: 3; background: var(--primary-soft); }
.data tbody tr:last-child td { border-bottom: none; }
.data tr.row-now td {
  background: var(--amber-soft);
  font-weight: 800;
  color: var(--ink);
}

/* ===== 锁屏 ===== */
#lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #FFF8EC 0%, #FBE4C6 55%, #F5D2A2 100%);
}
.lock-card { width: 100%; max-width: 340px; text-align: center; }
.lock-logo {
  width: 86px;
  height: 86px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  background: var(--primary);
  box-shadow: var(--shadow-lg);
}
.lock-card h1 { font-size: 23px; margin: 0 0 6px; }
.lock-sub { margin: 0 0 24px; font-size: 14px; color: var(--ink-2); }
#lock-form { display: flex; flex-direction: column; gap: 12px; }
#lock-pass { text-align: center; letter-spacing: 6px; }
.lock-error {
  min-height: 20px;
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
}
.lock-tip { margin: 28px 0 0; font-size: 12px; color: var(--ink-2); }

/* ===== 轻提示 ===== */
#toast-root {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 86%;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(74, 63, 53, 0.94);
  color: #FFF9F0;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.22s ease;
}
.toast-ok, .toast-success { background: var(--green); color: #1E3A20; }
.toast-warn { background: var(--amber); color: #4A3510; }
.toast-bad, .toast-error { background: var(--red); color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ===== 深色模式（简单适配，保证对比度）===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221D18;
    --card: #2D2721;
    --ink: #F2ECE2;
    --ink-2: #BDB0A0;
    --line: #40382F;
    --gray-soft: rgba(255, 255, 255, 0.09);
    --primary-soft: rgba(242, 166, 90, 0.18);
    --green-soft: rgba(136, 183, 138, 0.18);
    --amber-soft: rgba(232, 176, 75, 0.18);
    --red-soft: rgba(229, 115, 115, 0.18);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
  .ok   { --status-ink: #A9D3AB; }
  .warn { --status-ink: #F0C878; }
  .bad  { --status-ink: #F2A3A3; }
  .idle { --status-ink: #B7AB9B; }
  #topbar { background: rgba(34, 29, 24, 0.92); }
  #tabbar { background: rgba(45, 39, 33, 0.96); }
  .segment button.active { color: var(--primary); }
  .data thead th, .data thead th:first-child { background: #3A3129; }
  #lock-screen { background: linear-gradient(160deg, #2D2721 0%, #221D18 100%); }
  .toast-ok, .toast-success { color: #142615; }
  .toast-warn { color: #3C2B0A; }
}
