/* 新家采购清单
   只用四种颜色：黑、灰、白、橙。颜色全部走下面的变量。
   橙色只给：主按钮、选中的勾、需要提醒的字。圆角一律 2px，不用阴影，靠细线和灰底分层。 */
:root {
  --bg: #ffffff;          /* 底 */
  --fg: #111111;          /* 正文 */
  --grey1: #5c5c5c;       /* 次要文字、已买 */
  --grey2: #767676;       /* 更浅的灰：不需要 */
  --line: #d4d4d4;        /* 分隔线 */
  --fill: #f2f2f2;        /* 灰底（分组标题、选中行） */
  --orange: #ff6a00;      /* 主按钮底色、选中 */
  --on-orange: #111111;   /* 橙底上的字（黑字 6.6:1） */
  --orange-text: #b84a00; /* 白底上的橙色字（5.2:1；#ff6a00 直接当字只有 2.9:1，不够） */
  --toast-bg: #111111;
  --toast-fg: #ffffff;
  --toast-line: #111111;
  --r: 2px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --padl: max(12px, var(--sal));
  --padr: max(12px, var(--sar));
  --top-h: 92px;          /* 顶栏实际高度，由脚本量出来写回这里 */
  --nav-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0e;
    --fg: #ffffff;
    --grey1: #b0b0b0;
    --grey2: #8c8c8c;
    --line: #3a3a3a;
    --fill: #1c1c1c;
    --orange-text: #ff6a00; /* 近黑底上同一个橙色当字有 6.7:1 */
    --toast-bg: #2a2a2a;
    --toast-fg: #ffffff;
    --toast-line: #5c5c5c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.lock { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", sans-serif;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; border-radius: var(--r); }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.sm { font-size: 15px; color: var(--grey1); }
.err { font-size: 15px; font-weight: 600; color: var(--orange-text); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- 按钮和输入 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--fg); background: var(--bg); color: var(--fg);
  font-size: 16px; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--orange); border-color: var(--orange); color: var(--on-orange); }
.btn.big { min-height: 52px; width: 100%; font-size: 17px; }
.btn:disabled { background: var(--fill); border-color: var(--line); color: var(--grey1); cursor: default; }
/* 文字按钮：次要操作 */
.tbtn {
  min-height: 44px; padding: 0 2px; border: 0; background: none; color: var(--fg);
  font-size: 15px; text-decoration: underline; text-underline-offset: 4px; white-space: nowrap;
}
.fld { display: block; margin-top: 12px; }
.lab { display: block; font-size: 15px; color: var(--grey1); margin-bottom: 4px; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--grey1); background: var(--bg); color: var(--fg);
  font-size: 17px; /* 不小于 16px，iPhone 点进去才不会自动放大 */
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 80px; resize: vertical; display: block; }
select {
  width: auto; max-width: 60%; min-height: 44px; padding: 6px 30px 6px 10px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ---------- 登录 ---------- */
#login { padding: calc(var(--sat) + 14vh) max(20px, var(--sar)) 40px max(20px, var(--sal)); }
.login-card { max-width: 420px; margin: 0 auto; }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card .btn { margin-top: 16px; }
.login-card .err { margin-top: 10px; }

/* ---------- 顶栏：一行（谁、进度、刷新）+ 一排跳转标签 ---------- */
#app { max-width: 720px; margin: 0 auto; }
#top {
  position: sticky; top: 0; z-index: 10;
  padding-top: var(--sat);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 var(--padr) 0 var(--padl); }
.who { flex: 0 1 auto; max-width: 40%; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog { flex: 1 1 0; min-width: 0; font-size: 15px; line-height: 20px; white-space: nowrap; }
.prog .bar { height: 3px; background: var(--line); margin-top: 3px; }
.prog .bar i { display: block; height: 100%; width: 0; background: var(--fg); }
.sync { flex: none; min-height: 44px; padding: 0; border: 0; background: none; font-size: 15px; color: var(--grey1); white-space: nowrap; }
.sync.bad { color: var(--orange-text); font-weight: 600; }
.jump { display: flex; overflow-x: auto; scrollbar-width: none; padding: 0 calc(var(--padr) - 10px) 0 calc(var(--padl) - 10px); border-top: 1px solid var(--line); }
.jump::-webkit-scrollbar { display: none; }
.jump button {
  flex: none; height: 44px; padding: 0 10px; border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  background: none; font-size: 15px; color: var(--grey1); white-space: nowrap;
}
.jump button.on { color: var(--fg); font-weight: 700; border-bottom-color: var(--fg); }

/* ---------- 清单 ---------- */
main { padding-bottom: calc(var(--nav-h) + var(--sab) + 28px); }
body.has-act main { padding-bottom: calc(var(--nav-h) + var(--sab) + 100px); }
.controls { display: flex; justify-content: space-between; gap: 12px; padding: 2px var(--padr) 2px var(--padl); }
.grp { scroll-margin-top: var(--top-h); }
.grp > h2 {
  position: sticky; top: var(--top-h); z-index: 2;
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 7px var(--padr) 7px var(--padl);
  background: var(--fill); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 16px; font-weight: 700;
}
.grp > h2 span { font-size: 15px; font-weight: 400; color: var(--grey1); white-space: nowrap; }
.it { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; padding-left: calc(var(--padl) - 3px); }
.it-main { flex: 1 1 0; min-width: 0; display: flex; gap: 10px; padding: 11px 0; min-height: 50px; }
.it.pick .it-main { cursor: pointer; }
.box { flex: none; width: 26px; height: 26px; border: 2px solid var(--fg); border-radius: var(--r); display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; line-height: 1; }
.box.off { border-color: transparent; color: var(--grey1); }
.it.sel { border-left-color: var(--orange); background: var(--fill); }
.it.sel .box { background: var(--orange); border-color: var(--orange); color: var(--on-orange); }
.it-txt { flex: 1 1 0; min-width: 0; }
.it-l1 { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.nm { font-weight: 600; }
.qty { flex: none; max-width: 46%; font-weight: 700; text-align: right; }
.st { font-size: 15px; font-weight: 600; }
.it-acts { flex: none; display: flex; align-items: center; gap: 2px; padding: 0 calc(var(--padr) - 6px) 0 8px; }
.it-acts .btn { font-size: 15px; padding: 0 10px; }
.more { width: 44px; height: 44px; padding: 0 0 10px; border: 0; background: none; font-size: 24px; font-weight: 700; line-height: 1; }
.it-main + .it-pad { flex: none; width: var(--padr); }
/* 状态不靠新颜色：待买 = 正常黑白；已买 = 灰 + 「✓ 已买」；不需要 = 浅灰 + 删除线 + 「不需要」 */
.it.s-done, .it.s-done .sm { color: var(--grey1); }
.it.s-skip, .it.s-skip .sm { color: var(--grey2); }
.it.s-skip .nm { text-decoration: line-through; }
.it.s-done .nm, .it.s-skip .nm, .it.s-done .qty, .it.s-skip .qty { font-weight: 400; }
.list-end { padding: 4px var(--padr) 0 var(--padl); }
.empty { padding: 28px var(--padr) 28px var(--padl); color: var(--grey1); }

/* ---------- 底部：操作栏（勾选后才出现）和三个标签 ---------- */
#actbar {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--sab));
  display: flex; align-items: center; gap: 12px;
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 8px var(--padr) 8px var(--padl);
  background: var(--bg); border-top: 1px solid var(--fg);
}
#actbar .tbtn { flex: none; }
#tabs {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  display: flex; width: 100%; max-width: 720px; margin: 0 auto;
  height: calc(var(--nav-h) + var(--sab)); padding: 0 var(--sar) var(--sab) var(--sal);
  background: var(--bg); border-top: 1px solid var(--line);
}
#tabs button { flex: 1 1 0; border: 0; border-top: 3px solid transparent; border-radius: 0; background: none; font-size: 15px; color: var(--grey1); }
#tabs button.on { color: var(--fg); font-weight: 700; border-top-color: var(--fg); }

/* ---------- 短暂提示（带「撤销」） ---------- */
#toast {
  position: fixed; inset: auto 12px calc(var(--nav-h) + var(--sab) + 12px) 12px;
  margin: 0 auto; width: auto; max-width: 480px; min-height: 48px; padding: 6px 6px 6px 14px;
  display: none; align-items: center; gap: 8px;
  background: var(--toast-bg); color: var(--toast-fg); border: 1px solid var(--toast-line); border-radius: var(--r);
  font-size: 15px; overflow: visible;
}
#toast.show { display: flex; }
body.has-act #toast { bottom: calc(var(--nav-h) + var(--sab) + 84px); }
#toast button { flex: none; margin-left: auto; min-height: 44px; padding: 0 12px; border: 0; background: none; color: var(--orange); font-size: 15px; font-weight: 700; }

/* ---------- 从底部弹起的面板 ---------- */
dialog { color: var(--fg); }
dialog.sheet:focus { outline: none; }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto;
  width: 100%; max-width: 560px; max-height: calc(100dvh - var(--sat) - 24px);
  padding: 0; border: 0; border-top: 2px solid var(--fg); border-radius: 0;
  background: var(--bg); overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: up 0.16s ease-out; }
@keyframes up { from { transform: translateY(28px); opacity: 0.5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }
.sh-h { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px max(4px, var(--sar)) 4px max(14px, var(--sal)); border-bottom: 1px solid var(--line); }
.sh-h h2 { font-size: 17px; min-width: 0; }
.x { flex: none; width: 44px; height: 44px; padding: 0; border: 0; background: none; font-size: 20px; }
.sh-b { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px max(14px, var(--sar)) 14px max(14px, var(--sal)); }
.sh-f { flex: none; padding: 10px max(14px, var(--sar)) calc(10px + var(--sab)) max(14px, var(--sal)); border-top: 1px solid var(--line); }
.sh-f .tbtn { display: block; margin: 4px auto 0; }
.step h3 { font-size: 16px; margin: 14px 0 8px; }
.step h3 small { font-size: 15px; font-weight: 400; color: var(--grey1); }
/* 拍照按钮：大，但不是橙色（面板里只有「提交」是橙色） */
.shoot { display: flex; align-items: center; justify-content: center; min-height: 64px; border: 2px solid var(--fg); border-radius: var(--r); font-size: 18px; font-weight: 700; cursor: pointer; }
.shoot:focus-within { outline: 2px solid var(--orange); outline-offset: 1px; }
.pgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.pgrid:empty { display: none; }
.ph { position: relative; aspect-ratio: 1; background: var(--fill); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.ph img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ph button { position: absolute; top: 0; right: 0; width: 44px; height: 44px; padding: 0; border: 0; background: none; display: flex; align-items: flex-start; justify-content: flex-end; }
.ph button span { width: 26px; height: 26px; background: #111111; color: #ffffff; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.ph.busy { display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--grey1); }
#ps-status { margin-top: 12px; }
.upbar { height: 6px; background: var(--line); margin-bottom: 6px; }
.upbar i { display: block; height: 100%; width: 0; background: var(--fg); }

/* ---------- 购买记录 ---------- */
.sum { padding: 12px var(--padr) 12px var(--padl); background: var(--fill); border-bottom: 1px solid var(--line); }
.sum b { display: block; font-size: 26px; line-height: 1.25; }
.buys-bar { display: flex; justify-content: flex-end; padding: 0 var(--padr) 0 var(--padl); border-bottom: 1px solid var(--line); }
.buy { padding: 12px var(--padr) 6px var(--padl); border-bottom: 1px solid var(--line); }
.buy-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.buy-h b { font-size: 16px; }
.buy-amt { flex: none; font-weight: 700; }
.buy-amt.wait { color: var(--orange-text); }
.buy.off, .buy.off .sm, .buy.off .buy-amt { color: var(--grey2); }
.buy.off .buy-items { text-decoration: line-through; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.th { position: relative; width: 76px; height: 76px; padding: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--fill); overflow: hidden; }
.th img { display: block; width: 100%; height: 100%; object-fit: cover; }
.th span { position: absolute; left: 0; bottom: 0; padding: 0 4px; background: #111111; color: #ffffff; font-size: 15px; line-height: 20px; }
.buy-acts { display: flex; gap: 20px; min-height: 6px; }

/* ---------- 更多：说明、操作记录、退出 ---------- */
.info { border-bottom: 1px solid var(--line); }
.info summary { min-height: 52px; display: flex; align-items: center; padding: 6px var(--padr) 6px var(--padl); font-weight: 600; cursor: pointer; }
.info-b { padding: 0 var(--padr) 14px var(--padl); font-size: 16px; }
.info-b h3 { font-size: 16px; margin: 12px 0 6px; }
.info-b ol, .info-b ul { padding-left: 22px; }
.info-b ol { list-style: decimal; }
.info-b ul { list-style: disc; }
.info-b li { margin: 4px 0; }
.log-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px var(--padr) 0 var(--padl); }
.log-h h2 { font-size: 17px; }
.log-tip { padding: 2px var(--padr) 8px var(--padl); border-bottom: 1px solid var(--line); }
.logs li { padding: 9px var(--padr) 9px var(--padl); border-bottom: 1px solid var(--line); }
.lg1 { display: flex; flex-wrap: wrap; gap: 0 10px; font-size: 15px; }
.lg1 .lg-t { color: var(--grey1); font-variant-numeric: tabular-nums; }
#logMore { display: block; margin: 0 auto; }
.foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px var(--padr) 0 var(--padl); }

/* ---------- 全屏看照片：左右滑，点「关闭」或照片外面关掉 ---------- */
dialog.viewer { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000000; color: #ffffff; overflow: hidden; }
.vw-track { display: flex; width: 100%; height: 100%; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior: contain; }
.vw-track::-webkit-scrollbar { display: none; }
.vw-slide { flex: 0 0 100%; height: 100%; display: flex; align-items: center; justify-content: center; scroll-snap-align: center; scroll-snap-stop: always; }
.vw-slide img { display: block; max-width: 100%; max-height: 100%; }
.vw-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: calc(var(--sat) + 6px) max(8px, var(--sar)) 6px max(14px, var(--sal)); background: rgba(0, 0, 0, 0.7); font-size: 15px; }
.vw-x { min-height: 44px; padding: 0 16px; border: 1px solid #ffffff; background: #000000; color: #ffffff; font-size: 16px; }
.vw-nav { position: absolute; top: 50%; width: 44px; height: 64px; margin-top: -32px; padding: 0; border: 0; border-radius: 0; background: rgba(0, 0, 0, 0.7); color: #ffffff; font-size: 28px; }
.vw-prev { left: 0; }
.vw-next { right: 0; }
.vw-nav:disabled { visibility: hidden; }
