:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  /* 文字色都按 WCAG AA（≥ 4.5:1）在白底 / 浅灰底 / 对应浅色底上校验过 */
  --muted: #646468;
  --line: rgba(60, 60, 67, .14);
  --fill: rgba(118, 118, 128, .12);
  --accent: #0059c1;
  --accent-bg: #0059c1;
  --on-accent: #ffffff;
  --accent-soft: rgba(0, 122, 255, .12);
  --star: #ffb300;
  --star-soft: rgba(255, 179, 0, .16);
  --star-text: #855800;
  --danger: #d1001c;
  --danger-soft: rgba(255, 59, 48, .12);
  --warn: #a64b00;
  --warn-soft: rgba(255, 149, 0, .15);
  --ok: #1d7a33;
  --ok-bg: #1d7a33;
  --on-ok: #ffffff;
  --ok-soft: rgba(52, 199, 89, .15);
  --purple: #8228b5;
  --purple-soft: rgba(175, 82, 222, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 10px rgba(0, 0, 0, .04);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #a8a8ae;
    --line: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24);
    --accent: #409cff;
    --accent-bg: #0a6fd6;
    --on-accent: #ffffff;
    --accent-soft: rgba(10, 132, 255, .2);
    --star: #ffd60a;
    --star-soft: rgba(255, 214, 10, .16);
    --star-text: #ffd60a;
    --danger: #ff6961;
    --danger-soft: rgba(255, 69, 58, .18);
    --warn: #ffb340;
    --warn-soft: rgba(255, 159, 10, .18);
    --ok: #30d158;
    --ok-bg: #30d158;
    --on-ok: #000000;
    --ok-soft: rgba(48, 209, 88, .18);
    --purple: #d08cff;
    --purple-soft: rgba(191, 90, 242, .2);
    --shadow: none;
  }
}

[hidden] { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- 键盘焦点 ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card :focus-visible, .segmented :focus-visible, .alert-btns :focus-visible, .menu-item:focus-visible { outline-offset: -3px; }
[role="dialog"]:focus, [role="alertdialog"]:focus { outline: none; }
/* 这些输入框自身去掉了描边，用外层容器显示焦点 */
.search:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.field:focus-within { box-shadow: inset 3px 0 0 var(--accent); }
.field [aria-invalid="true"] { color: var(--danger); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
body { min-height: 100vh; padding-bottom: calc(110px + var(--safe-b)); }
html.locked, html.locked body { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input, textarea { font: inherit; font-size: 16px; color: inherit; }
.ic { width: 20px; height: 20px; flex: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  padding: calc(var(--safe-t) + 10px) 16px 8px;
  border-bottom: .5px solid var(--line);
}
.title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: .3px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--fill); color: var(--accent);
}
.search {
  position: relative; margin-top: 8px;
  display: flex; align-items: center;
  background: var(--fill); border-radius: 11px; height: 38px; padding: 0 8px;
}
.search-ic { color: var(--muted); display: grid; place-items: center; }
.search-ic .ic { width: 17px; height: 17px; }
.search input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  padding: 0 6px; height: 100%; -webkit-appearance: none; appearance: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.clear-btn {
  width: 24px; height: 24px; border-radius: 50%; background: var(--muted); color: var(--card);
  font-size: 16px; line-height: 24px; text-align: center;
}

.tabs {
  display: flex; gap: 4px; margin: 10px -16px 0; padding: 0 16px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .cats::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  height: 34px; padding: 0 6px; border-radius: 10px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.tab .count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  font-size: 11.5px; line-height: 18px; text-align: center;
  background: var(--fill); color: var(--muted); font-variant-numeric: tabular-nums;
}
/* 标签放不下时（英文/法文）先收紧，仍放不下就横向滚动并在被遮挡一侧渐隐 */
.tabs.compact .tab { padding: 0 4px; font-size: 12.5px; gap: 2px; }
.tabs.compact .tab .count { padding: 0 4px; min-width: 16px; }
.tabs.fade-r { -webkit-mask-image: linear-gradient(to right, #000 82%, transparent); mask-image: linear-gradient(to right, #000 82%, transparent); }
.tabs.fade-l { -webkit-mask-image: linear-gradient(to left, #000 82%, transparent); mask-image: linear-gradient(to left, #000 82%, transparent); }
.tabs.fade-l.fade-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent); mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent); }
.tab.t-starred .count.has { background: var(--star-soft); color: var(--star-text); }
.tab.t-low .count.has { background: var(--warn-soft); color: var(--warn); }
.tab.t-expired .count.has { background: var(--danger-soft); color: var(--danger); }
.tab.t-ordered .count.has { background: var(--purple-soft); color: var(--purple); }
.tab.active { background: var(--accent-bg); color: var(--on-accent); box-shadow: none; }
.tab.active .count, .tab.active .count.has { background: rgba(255, 255, 255, .22); color: var(--on-accent); }

.cats, .chips {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.cats { margin: 8px -16px 0; padding: 0 16px 2px; }
.chip {
  flex: none; height: 30px; padding: 0 12px; border-radius: 15px;
  border: 1px solid var(--line); background: transparent;
  font-size: 13px; color: var(--text); white-space: nowrap;
}
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- 列表 ---------- */
.list { list-style: none; padding: 12px 16px 0; max-width: 720px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 60px 32px; line-height: 1.7; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

.row {
  position: relative; margin-bottom: 10px; border-radius: var(--radius);
  transition: height .22s ease, margin .22s ease, opacity .22s ease;
}
.row.removing { overflow: hidden; margin-bottom: 0; opacity: 0; }
.row-delete {
  position: absolute; top: 0; right: 0; bottom: 0; width: 50%;
  border-radius: var(--radius); background: var(--danger); color: #fff;
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
  padding-right: 22px; gap: 2px; font-size: 13px; font-weight: 600;
  opacity: 0; transition: width .2s ease;
}
.row-delete span { width: 44px; text-align: center; }
.row-delete .ic { width: 22px; height: 22px; margin-right: 11px; }
.row.revealed .row-delete { opacity: 1; }
.row.full .row-delete { width: 100%; }

.card {
  position: relative; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  transition: transform .25s ease;
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  cursor: pointer;
}
.card.dragging { transition: none; }
.card.starred::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--star);
}
.card-main { display: flex; gap: 12px; padding: 12px 6px 8px 12px; }
.thumb {
  width: 60px; height: 60px; border-radius: 12px; flex: none; object-fit: cover;
  background: var(--fill); display: grid; place-items: center;
  color: #fff; font-size: 24px; font-weight: 700;
}
.info { flex: 1; min-width: 0; }
.name { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.4; }
.name-btn {
  display: block; max-width: 100%; text-align: left; font-weight: inherit; line-height: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px;
}
.meta { font-size: 13px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note {
  font-size: 13px; line-height: 1.4; color: var(--text); opacity: .72; margin-top: 3px;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; word-break: break-word;
}
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badges:empty { display: none; }
.badge { font-size: 12px; line-height: 18px; padding: 0 7px; border-radius: 9px; font-weight: 600; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.soon { background: var(--warn-soft); color: var(--warn); font-weight: 500; }
.badge.purple { background: var(--purple-soft); color: var(--purple); }

.star-btn {
  width: 44px; height: 44px; margin-top: -8px; flex: none;
  display: grid; place-items: center; color: var(--muted);
}
.star-btn .ic { width: 26px; height: 26px; stroke-width: 1.8; }
.star-btn.on { color: var(--star); }
.star-btn.on .ic, .star-toggle.on .ic { fill: currentColor; }

.card-actions { display: flex; align-items: center; gap: 8px; padding: 0 12px 12px; }
.spacer { flex: 1; }
.stepper { display: flex; align-items: center; background: var(--fill); border-radius: 10px; }
.stepper button { width: 38px; height: 34px; font-size: 22px; line-height: 1; color: var(--accent); }
.stepper button:active { opacity: .5; }
.stepper .qty {
  min-width: 34px; text-align: center; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums;
}
.stepper .qty.low { color: var(--warn); }
.stepper .qty.zero { color: var(--danger); }
.pill {
  height: 34px; padding: 0 12px; border-radius: 10px;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.pill .ic { width: 17px; height: 17px; }
.pill.order { background: var(--accent-soft); color: var(--accent); }
.pill.arrive { background: var(--ok-bg); color: var(--on-ok); }
.pill:active { opacity: .6; }

.fab {
  position: fixed; right: 20px; bottom: calc(22px + var(--safe-b)); z-index: 20;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent-bg); color: var(--on-accent); font-size: 34px; font-weight: 300; line-height: 58px;
  box-shadow: 0 6px 18px rgba(0, 122, 255, .35);
}
.fab:active { transform: scale(.94); }

/* ---------- 弹层 ---------- */
.layer { position: fixed; inset: 0; z-index: 100; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .25s ease; }
.layer.open .backdrop { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 0 16px calc(16px + var(--safe-b));
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.layer.open .sheet { transform: translateY(0); }
.sheet-full {
  display: flex; flex-direction: column; padding: 0;
  height: calc(100vh - 20px - var(--safe-t)); height: calc(100dvh - 20px - var(--safe-t));
  max-height: none; overflow: hidden;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: .5px solid var(--line); flex: none;
}
.sheet-head h2 { font-size: 17px; margin: 0; }
.text-btn { color: var(--accent); font-size: 17px; padding: 4px 2px; }
.text-btn.strong { font-weight: 700; }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px calc(32px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 6px; }
.sheet-title { font-size: 20px; margin: 12px 4px 8px; }
.sheet-sub { color: var(--muted); font-size: 14px; margin: 0 4px 12px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 8px 4px 4px; }

.photo-row { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.photo {
  width: 104px; height: 104px; border-radius: 18px; background: var(--card); flex: none;
  display: grid; place-items: center; overflow: hidden; cursor: pointer; color: var(--muted);
  border: 1px dashed var(--line);
}
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo-ph { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; }
.photo-ph .ic { width: 28px; height: 28px; stroke-width: 1.6; }
.photo-side { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.star-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px;
  border-radius: 20px; background: var(--card); font-weight: 600; color: var(--muted);
  border: 1px solid var(--line);
}
.star-toggle .ic { width: 20px; height: 20px; }
.star-toggle.on { background: var(--star-soft); color: var(--star-text); border-color: transparent; }
.link-btn { color: var(--accent); font-size: 15px; padding: 2px 0; }
.link-btn.danger { color: var(--danger); }

.group { background: var(--card); border-radius: 14px; margin-bottom: 16px; overflow: hidden; }
.field {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 8px 14px; border-bottom: .5px solid var(--line);
}
.group > .field:last-child, .group > :last-child { border-bottom: 0; }
.field > span { flex: 0 1 auto; min-width: 0; font-weight: 500; max-width: 55%; }
.field > .stepper, .field > .date-row { flex: none; }
.field > span small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; line-height: 1.35; margin-top: 2px; }
.field > input[type="text"] {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; text-align: right; padding: 6px 0;
}
.field.col { flex-direction: column; align-items: stretch; gap: 6px; padding-top: 12px; }
.field.col textarea { width: 100%; border: 0; background: none; outline: none; resize: vertical; padding: 0; line-height: 1.5; }
.field.invalid > span { color: var(--danger); }
.group .chips { padding: 2px 14px 12px; border-bottom: 0; }
.field-btn { padding: 0 14px 14px; }
.field-btn:has(> [hidden]) { display: none; }

.stepper.big input, .stepper.huge input {
  width: 64px; border: 0; background: none; outline: none; text-align: center;
  font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; padding: 0;
}
.stepper.big input::placeholder { font-weight: 400; font-size: 14px; color: var(--muted); }
.stepper.huge { border-radius: 14px; background: var(--card); }
.stepper.huge button { width: 54px; height: 50px; font-size: 28px; }
.stepper.huge input { width: 90px; font-size: 26px; }
.flash { animation: flash .9s ease; }
@keyframes flash { 0%, 100% { background: transparent; } 30% { background: var(--ok-soft); } }

.date-row { display: flex; align-items: center; gap: 10px; }
.date-wrap { position: relative; }
.date-wrap input {
  -webkit-appearance: none; appearance: none; border: 0; outline: none;
  background: var(--fill); border-radius: 8px; padding: 0 10px; height: 36px; min-width: 132px;
  font-size: 16px; text-align: center; color: var(--text);
}
.date-wrap input::-webkit-date-and-time-value { text-align: center; }
.date-wrap.empty input { color: transparent; }
.date-wrap.empty::after {
  content: attr(data-ph); position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); pointer-events: none; font-size: 15px;
}

.wide-btn {
  display: block; width: 100%; height: 50px; border-radius: 14px;
  font-size: 17px; font-weight: 600; text-align: center;
}
.wide-btn.primary { background: var(--accent-bg); color: var(--on-accent); }
.wide-btn.ok { background: var(--ok-bg); color: var(--on-ok); }
.wide-btn.plain { background: var(--card); }
.wide-btn.danger { color: var(--danger); }
.wide-btn.danger-soft { background: var(--card); color: var(--danger); margin-top: 8px; }
.wide-btn:active { opacity: .7; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.order-qty { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 4px; }
.order-qty > span { font-weight: 600; }

.segmented { display: flex; background: var(--fill); border-radius: 10px; padding: 2px; }
.segmented button { flex: 1; height: 34px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.segmented button.active { background: var(--card); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); font-weight: 600; }
.menu-list { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 10px; }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 12px 16px; border-bottom: .5px solid var(--line);
}
.menu-item:last-child { border-bottom: 0; }
.menu-item span { display: block; color: var(--accent); font-size: 17px; }
.menu-item small { display: block; color: var(--muted); font-size: 13px; }
.menu-item:active { background: var(--fill); }

.layer.center { display: grid; place-items: center; }
.alert {
  position: relative; width: min(300px, 86vw); background: var(--card); border-radius: 16px;
  text-align: center; overflow: hidden;
  opacity: 0; transform: scale(1.08); transition: opacity .2s ease, transform .2s ease;
}
.layer.open .alert { opacity: 1; transform: scale(1); }
.alert h2 { font-size: 17px; margin: 20px 16px 4px; }
.alert p { font-size: 14px; color: var(--muted); margin: 0 16px 18px; white-space: pre-line; line-height: 1.5; }
.alert-btns { display: flex; border-top: .5px solid var(--line); }
.alert-btns button { flex: 1; height: 46px; font-size: 17px; color: var(--accent); }
.alert-btns button + button { border-left: .5px solid var(--line); }
.alert-btns.stack { flex-direction: column; }
.alert-btns.stack button + button { border-left: 0; border-top: .5px solid var(--line); }
.alert-btns button.primary { font-weight: 700; }
.alert-btns button.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); z-index: 200;
  transform: translate(-50%, 20px); opacity: 0; transition: opacity .2s ease, transform .2s ease;
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100% - 32px); width: max-content;
  background: rgba(36, 36, 38, .95); color: #fff; border-radius: 12px; padding: 11px 16px;
  font-size: 15px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast button { color: #64d2ff; font-weight: 700; flex: none; }

@media (hover: hover) {
  .card:hover { box-shadow: 0 2px 14px rgba(0, 0, 0, .08); }
}

/* 系统开启「减弱动态效果」时去掉滑动、缩放和闪烁动画 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* Windows 高对比度等强制配色模式：保证选中状态和焦点仍然可见 */
@media (forced-colors: active) {
  .tab.active, .chip.active, .segmented button.active { outline: 2px solid Highlight; }
  .star-btn.on .ic, .star-toggle.on .ic { fill: Highlight; }
}
