:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e7e9ee;
  --accent: #d92b2b;
  --accent-soft: #fdecec;
  --blue: #2563eb;
  --green: #0f9d58;
  --amber: #d97706;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 8px 24px -12px rgba(17, 24, 39, .18);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

.app { min-height: 100dvh; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 800;
}
.topbar .spacer { flex: 1; }
.topbar-inner { width: 100%; max-width: 1360px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer; color: var(--text);
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 21px; height: 21px; }

/* ---------- layout ---------- */
.page { max-width: 1360px; margin: 0 auto; padding: 16px 16px calc(92px + var(--safe-bottom)); }
.page.narrow { max-width: 820px; }
.page.form { max-width: 680px; }
.page.no-tabs { padding-bottom: 32px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar-inner { display: flex; width: 100%; max-width: 760px; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; font-size: 11px; color: var(--faint); border: 0; background: none; cursor: pointer;
}
.tab.active { color: var(--accent); font-weight: 600; }
.tab svg { width: 22px; height: 22px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 15px; cursor: pointer;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:disabled { opacity: .55; }
.btn-ghost { background: transparent; }
.btn-danger { color: #b91c1c; border-color: #f3cfcf; background: #fff7f7; }
.btn-block { width: 100%; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }

/* ---------- form ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--faint); margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); padding: 11px 12px; font-size: 15px; color: var(--text);
  outline: none; appearance: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 88px; resize: vertical; }
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.form-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.form-section h3 { margin: 0 0 14px; font-size: 14px; color: var(--muted); font-weight: 600; }
.form-actions { position: sticky; bottom: calc(10px + var(--safe-bottom)); display: flex; gap: 10px; padding-top: 6px; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--text); border-color: var(--text); color: #fff; font-weight: 600; }

/* ---------- search ---------- */
.search { position: relative; }
.search input {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 14px 0 40px; font-size: 15px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { position: absolute; left: 13px; top: 12px; width: 20px; height: 20px; color: var(--faint); }

/* ---------- kit cards ---------- */
.kit-list { display: flex; flex-direction: column; gap: 10px; }
.kit-card {
  display: flex; gap: 12px; padding: 10px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.thumb {
  width: 100px; height: 100px; flex: 0 0 100px; border-radius: 14px; overflow: hidden;
  background: linear-gradient(145deg, #eef1f5, #e2e6ec); position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.empty::after {
  content: ""; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cg fill='none' stroke='%23aab1bd' stroke-width='2'%3E%3Cpath d='M10 16l14-7 14 7v16l-14 7-14-7z'/%3E%3Cpath d='M10 16l14 7 14-7M24 23v16'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 34px; background-repeat: no-repeat; background-position: center;
}
.kit-main { min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.kit-name { font-weight: 700; font-size: 17px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kit-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kit-grade { font-weight: 600; color: #374151; }
.kit-tags { color: var(--faint); }
.kit-foot { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.backlog { background: #fff4e5; color: #b45309; }
.badge.building { background: #e8f0ff; color: #1d4ed8; }
.badge.done { background: #e7f7ee; color: #047857; }
.badge.out { background: #f1f2f5; color: #6b7280; }
.kit-qty { font-size: 12px; color: var(--faint); }
.kit-price { margin-left: auto; font-size: 13px; font-weight: 650; color: var(--text); }

/* ---------- stat strip ---------- */
.stat-strip {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px;
}
.stat .n { font-size: 19px; font-weight: 750; letter-spacing: -.4px; }
.stat .l { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

/* ---------- detail ---------- */
.detail-hero {
  border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--line);
  margin-bottom: 14px;
}
.detail-hero img { width: 100%; max-height: 360px; object-fit: cover; }
.detail-title { padding: 16px; }
.detail-title h1 { margin: 0 0 6px; font-size: 21px; line-height: 1.25; letter-spacing: -.3px; }
.detail-title .sub { color: var(--muted); font-size: 13.5px; }
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

.info-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.info-row { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.info-row:last-child { border-bottom: 0; }
.info-row .k { color: var(--muted); flex: 0 0 84px; }
.info-row .v { flex: 1; word-break: break-word; }
.info-row .v.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.section-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 4px 8px; }

.action-row { display: flex; gap: 8px; margin-top: 16px; }
.action-row .btn { flex: 1; }

/* ---------- movements ---------- */
.mov { display: flex; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.mov + .mov { margin-top: 8px; }
.mov-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 15px; flex: 0 0 34px; }
.mov-in { background: #e7f7ee; color: #047857; }
.mov-out { background: #fdecec; color: #b91c1c; }
.mov-adjust { background: #eef2ff; color: #4338ca; }
.mov-main { flex: 1; min-width: 0; }
.mov-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov-note { font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov-side { text-align: right; }
.mov-qty { font-weight: 700; font-size: 14px; }
.mov-qty.plus { color: var(--green); }
.mov-qty.minus { color: var(--accent); }
.mov-time { font-size: 11.5px; color: var(--faint); }

/* ---------- stats ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 13px; }
.bar-row .label { flex: 0 0 76px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { flex: 1; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bar-row .num { flex: 0 0 42px; text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ---------- empty / loading ---------- */
.empty { text-align: center; padding: 56px 16px; color: var(--faint); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty p { margin: 6px 0 18px; font-size: 14px; }
.loading { text-align: center; padding: 28px; color: var(--faint); font-size: 13px; }
.skeleton { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, #eceef2 25%, #f5f6f8 37%, #eceef2 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; margin-bottom: 10px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 28px 22px; box-shadow: var(--shadow); }
.auth-logo { width: 54px; height: 54px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; margin-bottom: 18px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.4px; }
.auth-card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.auth-error { background: var(--accent-soft); color: #b91c1c; border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---------- modal ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 60; background: rgba(17, 24, 39, .42);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .16s ease;
}
.modal {
  width: 100%; max-width: 480px; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom)); animation: slideup .2s ease;
  max-height: 88dvh; overflow-y: auto;
}
@media (min-width: 560px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: 20px; padding-bottom: 20px; }
}
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } }

/* ---------- toast ---------- */
.toast-root { position: fixed; left: 0; right: 0; bottom: calc(84px + var(--safe-bottom)); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(17, 24, 39, .92); color: #fff; font-size: 13.5px; padding: 9px 16px;
  border-radius: 999px; animation: fade .18s ease; max-width: 86vw;
}

/* ---------- photo picker ---------- */
.photo-pick {
  width: 100%; aspect-ratio: 4 / 3; border-radius: 14px; border: 1.5px dashed #cbd2dc;
  background: var(--surface-2); display: grid; place-items: center; cursor: pointer; overflow: hidden;
  position: relative; color: var(--faint); font-size: 13px;
}
.photo-pick img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick .ph { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.photo-pick .ph svg { width: 30px; height: 30px; }

/* ---------- misc ---------- */
.share-banner {
  background: #fff8e6; border: 1px solid #f3e0b0; color: #8a6116; border-radius: 12px;
  padding: 9px 12px; font-size: 12.5px; margin-bottom: 12px;
}
.dup-warn { background: #fff8e6; border: 1px solid #f3e0b0; color: #8a6116; border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-top: 8px; }
.dup-warn b { color: #7a5200; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { font-size: 12.5px; color: var(--muted); }
.hr { height: 1px; background: var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb8 { margin-bottom: 8px; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.scan-box { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 4/3; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; }
.scan-reticle { position: absolute; inset: 18%; border: 2px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.28); }

/* ---------- new: quick actions & tags ---------- */
.kit-actions { margin-left: auto; display: flex; gap: 6px; }
.mini-btn {
  width: 34px; height: 28px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; font-size: 12.5px; font-weight: 600; color: var(--faint); cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.mini-btn:active { background: var(--bg); color: var(--text); }
.mini-btn.plus { background: transparent; border-color: var(--line); color: var(--faint); }
.ver-badge {
  font-size: 11px; padding: 2px 7px; border-radius: 6px; background: #eef2ff; color: #4338ca; font-weight: 650;
}
.special-tag {
  display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  background: #f3f0ff; color: #6d28d9; margin-right: 4px; margin-bottom: 4px;
}
.seg { display: flex; gap: 6px; }
.seg-item {
  flex: 1; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-weight: 650; cursor: pointer;
}
.seg-item.active { background: var(--text); color: #fff; border-color: var(--text); }
.tag-select { display: flex; flex-wrap: wrap; gap: 8px; max-height: 190px; overflow-y: auto; padding: 2px; }
.tag {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 11px; font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.tag.active { background: var(--accent-soft); border-color: #f3b4b4; color: #b91c1c; font-weight: 600; }
details.form-section summary {
  cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 600; list-style: none;
}
details.form-section summary::-webkit-details-marker { display: none; }
details.form-section summary::after { content: "展开"; float: right; font-size: 12px; color: var(--faint); }
details.form-section[open] summary::after { content: "收起"; }
.kit-card { align-items: center; }
.thumb { display: block; }

/* ---------- refinements ---------- */
.photo-pick { height: 200px; aspect-ratio: auto; }
.bar-row .label { flex: 0 0 104px; }
#kitForm { padding-bottom: 12px; }
@media (min-width: 720px) {
  .kit-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
  .kit-card { margin: 0; }
  .chips { flex-wrap: wrap; overflow: visible; }
  .page { padding: 22px 24px calc(96px + var(--safe-bottom)); }
  .topbar-inner { padding: 0 24px; }
}

.grade-cascade { display: flex; flex-direction: column; gap: 8px; }

/* ---------- grouped by grade ---------- */
.grade-group {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 10px; overflow: hidden;
}
.grade-group summary {
  list-style: none; display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; cursor: pointer; font-weight: 650; font-size: 14.5px;
}
.grade-group summary::-webkit-details-marker { display: none; }
.g-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-count {
  flex: 0 0 auto; font-size: 12px; color: var(--muted); background: var(--bg);
  padding: 2px 9px; border-radius: 999px; font-weight: 600;
}
.g-chev {
  width: 8px; height: 8px; border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint);
  transform: rotate(45deg); transition: transform .15s ease; flex: 0 0 auto; margin-left: 2px;
}
.grade-group[open] .g-chev { transform: rotate(-135deg); }
.grade-group[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.grade-group .kit-list { padding: 0 10px 10px; }

.group-tools { display: flex; justify-content: flex-end; margin-bottom: 8px; }

.link-btn { border: 0; background: none; color: var(--accent); font-size: 12.5px; font-weight: 600; margin-left: 8px; padding: 0; cursor: pointer; }

/* ---------- multi-select dropdown ---------- */
.ms { position: relative; }
.ms-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  text-align: left; cursor: pointer; background: var(--surface);
}
.ms-toggle #msLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-panel {
  position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 40px -18px rgba(17, 24, 39, .35); padding: 10px;
}
.ms-search { height: 36px; padding: 0 10px; font-size: 13.5px; }
.ms-list { max-height: 230px; overflow-y: auto; margin-top: 8px; }
.ms-item { display: flex; gap: 8px; align-items: flex-start; padding: 7px 6px; border-radius: 8px; font-size: 13.5px; cursor: pointer; }
.ms-item:active { background: var(--bg); }
.ms-item input { margin-top: 3px; }
.ms-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }

/* ---------- special tag toggle ---------- */
.tag-toggle {
  border: 1px solid var(--line); background: transparent; color: var(--faint);
  font-size: 11.5px; padding: 1px 8px; border-radius: 999px; margin-left: 6px; cursor: pointer;
}
.tag-toggle[aria-expanded="true"] { color: var(--text); background: var(--bg); }
.kit-tags-row { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 5px; }
.kit-tags-row[hidden] { display: none; }
