:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17201e;
  --text-2: #5d6b68;
  --line: #dde4e2;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --red: #c2410c;
  --red-soft: #fde8de;
  --amber: #b45309;
  --amber-soft: #fdf1d8;
  --gray-soft: #e9ecec;
  --child: #7c3aed;
  --child-soft: #ede5fd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #182120;
    --surface-2: #1f2a28;
    --text: #e6eeec;
    --text-2: #9aaba7;
    --line: #2a3634;
    --accent: #2dd4bf;
    --accent-soft: #123a36;
    --red: #fb923c;
    --red-soft: #3b2216;
    --amber: #fbbf24;
    --amber-soft: #382d12;
    --gray-soft: #26302e;
    --child: #a78bfa;
    --child-soft: #2a2140;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 0; text-align: center; color: var(--text-2); }
.page { max-width: 720px; margin: 0 auto; padding: 0 16px 96px; }

/* 顶栏 */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  margin: 0 -16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 搜索 */
.search { display: flex; gap: 8px; margin-bottom: 14px; }
.search input { flex: 1; }

/* 提醒区 */
.alerts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.alert {
  border-radius: var(--radius); padding: 12px; background: var(--surface); box-shadow: var(--shadow);
  border: 1px solid var(--line); min-height: 78px; display: flex; flex-direction: column; justify-content: space-between;
}
.alert b { font-size: 26px; line-height: 1; font-weight: 700; }
.alert span { font-size: 13px; color: var(--text-2); }
.alert.expired.on { background: var(--red-soft); border-color: transparent; }
.alert.expired.on b { color: var(--red); }
.alert.soon.on { background: var(--amber-soft); border-color: transparent; }
.alert.soon.on b { color: var(--amber); }
.alert.low.on { background: var(--gray-soft); border-color: transparent; }

/* 大入口 */
.entries { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.entry {
  border-radius: 18px; padding: 18px 16px; min-height: 120px; display: flex; flex-direction: column; justify-content: flex-end;
  background: var(--accent-soft); color: var(--text);
}
.entry.child { background: var(--child-soft); }
.entry .t { font-size: 20px; font-weight: 700; }
.entry .n { font-size: 13px; color: var(--text-2); }



.section-title { font-size: 14px; color: var(--text-2); margin: 18px 2px 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }

/* 卡片 */
.cards { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; gap: 12px; padding: 10px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); align-items: center;
}
.card img, .card .noimg {
  width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2);
}
.card .noimg { display: grid; place-items: center; font-size: 12px; color: var(--text-2); }
.cbody { flex: 1; min-width: 0; }
.cname { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.csub { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cexp { font-size: 13px; margin-top: 2px; }
.cexp.expired { color: var(--red); font-weight: 650; }
.cexp.soon { color: var(--amber); font-weight: 650; }
.cexp.ok { color: var(--text-2); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; font-weight: 600; }
.tag.child { background: var(--child-soft); color: var(--child); }

.bar { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.bar .track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 3px; }
.bar .fill.l1, .bar .fill.l0 { background: var(--red); }
.bar .fill.l2 { background: var(--amber); }
.bar .txt { font-size: 12px; color: var(--text-2); white-space: nowrap; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) { .chip.on { color: #06201d; } }

.empty { text-align: center; color: var(--text-2); padding: 36px 12px; }

/* 悬浮按钮 */
.fab {
  position: fixed; right: max(18px, calc(50vw - 342px)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  box-shadow: 0 6px 18px rgba(15,118,110,.35); display: grid; place-items: center; cursor: pointer; z-index: 20;
}
@media (prefers-color-scheme: dark) { .fab { color: #06201d; } }
.fab svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; }

/* 表单 */
.form { display: flex; flex-direction: column; gap: 14px; }
.field label, .lbl { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; font-weight: 550; }
.field label .req { color: var(--red); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; outline: none; min-height: 44px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filled { border-color: var(--amber) !important; background: var(--amber-soft) !important; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hint { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 0; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button.on[data-v=child] { color: var(--child); }
.seg button.on[data-v=adult] { color: var(--accent); }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06201d; } }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }

/* 照片 */
.photos { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.photos .ph { position: relative; flex: none; }
.photos .ph img { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; display: block; }
.photos .ph .x {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.7); color: #fff; font-size: 14px; line-height: 24px; cursor: pointer;
}
.photos .ph .first { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 0 5px; border-radius: 5px; }
.photos .add {
  flex: none; width: 84px; height: 84px; border-radius: 12px; border: 1.5px dashed var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--text-2); font-size: 12px; text-align: center; padding: 6px;
}
.photos .add.busy { opacity: .6; }
.recog { margin-top: 8px; }

/* 详情 */
.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px 14px; padding: 0 16px; }
.gallery a { flex: none; scroll-snap-align: start; }
.gallery img { height: 220px; max-width: 80vw; border-radius: 14px; object-fit: cover; display: block; }
.dname { font-size: 22px; font-weight: 700; margin: 0 0 2px; }
.dsub { color: var(--text-2); margin-bottom: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.kv { margin: 0; display: grid; grid-template-columns: 96px 1fr; gap: 8px 10px; font-size: 14.5px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-all; }
.big-exp { font-size: 17px; font-weight: 700; }
.big-exp.expired { color: var(--red); } .big-exp.soon { color: var(--amber); }
.qty { display: flex; align-items: center; gap: 12px; }
.qty .num { font-size: 22px; font-weight: 700; }
.qty .bar { flex: 1; }
.qty .bar .track { height: 10px; border-radius: 5px; }
.actions { display: flex; gap: 10px; }
.actions > * { flex: 1; }

/* 设置 */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .meta { font-size: 12px; color: var(--text-2); }
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 13px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

/* 登录 */
.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 20px; }
.auth h1 { font-size: 24px; margin: 0 0 6px; }
.auth p { color: var(--text-2); margin: 0 0 22px; }
.logo { width: 56px; height: 56px; margin-bottom: 14px; }

/* 扫码层 */
.scanner { position: fixed; inset: 0; background: #000; z-index: 100; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .frame { position: absolute; left: 50%; top: 40%; width: 74vw; max-width: 340px; height: 180px; transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,.85); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.scanner .msg { position: absolute; left: 0; right: 0; top: calc(40% + 110px); text-align: center; color: #fff; font-size: 14px; padding: 0 20px; }
.scanner .bottom { background: #111; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.scanner .bottom input { flex: 1; background: #222; border-color: #333; color: #fff; }
.scanner .bottom .btn { background: #222; border-color: #333; color: #fff; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: rgba(20,24,23,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 200; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
