/* Hallmark · pre-emit critique: P5 H4 E5 S4 R5 V4
 * macrostructure: app-shell (masthead sidebar + fluid card grid) · scope: application
 * tone: editorial-almanac · anchor hue: clay 47 · type: Fraunces × Geist × PingFang SC
 * fixes: side-stripe removed · real type pairing · optimistic-delete · single elevation · OKLCH tokens
 */

/* ============================================================
   字体 · 本地内嵌，离线可用
   ============================================================ */
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   设计令牌 (OKLCH)
   ============================================================ */
:root {
  /* 纸张与墨色 —— 暖中性，向陶土色微偏 */
  --paper:      oklch(96.5% 0.010 78);
  --paper-2:    oklch(94.2% 0.013 74);
  --card:       oklch(99.2% 0.006 84);
  --rule:       oklch(89%   0.012 72);
  --rule-2:     oklch(83%   0.015 66);
  --neutral:    oklch(60%   0.014 58);
  --muted:      oklch(47%   0.014 54);
  --ink:        oklch(26%   0.016 52);
  --ink-strong: oklch(20%   0.018 50);

  /* 点缀色 —— 单一陶土，克制使用 */
  --accent:        oklch(57%  0.130 47);
  --accent-deep:   oklch(50%  0.138 44);
  --accent-soft:   oklch(93%  0.035 55);
  --accent-line:   oklch(72%  0.085 50);
  --gold:          oklch(70%  0.115 76);
  --success:       oklch(52%  0.080 155);
  --danger:        oklch(53%  0.150 28);

  /* 字体 */
  --display: "Fraunces", "PingFang SC", "Songti SC", Georgia, serif;
  --body:    "Geist", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;

  /* 4pt 间距阶 */
  --space-2xs: 0.25rem;
  --space-xs:  0.5rem;
  --space-sm:  0.75rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2.25rem;
  --space-2xl: 3.5rem;

  /* 字号阶 (1.25) */
  --text-xs:   0.75rem;
  --text-sm:   0.8125rem;
  --text-base: 0.9375rem;
  --text-md:   1.0625rem;
  --text-lg:   1.375rem;
  --text-xl:   1.75rem;
  --text-2xl:  2.25rem;

  --radius:    14px;
  --radius-sm: 9px;

  /* 单层高度阴影 */
  --shadow: 0 10px 30px -12px oklch(30% 0.02 50 / 0.22);
  --shadow-lg: 0 28px 60px -20px oklch(28% 0.03 50 / 0.34);

  /* 语义化（随主题切换） */
  --toast-bg: var(--ink-strong);
  --toast-fg: var(--paper);
  --scrim: oklch(28% 0.02 50 / 0.32);
  --hover: oklch(40% 0.02 60 / 0.06);

  /* 动效 */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in:  cubic-bezier(0.7, 0, 0.84, 0);
  --dur: 200ms;

  /* z 轴 */
  --z-raised: 10;
  --z-sticky: 200;
  --z-modal: 400;
  --z-toast: 500;
}

/* ---------- 暗色主题（由 JS 把 data-theme 解析为 light/dark） ---------- */
:root[data-theme="dark"] {
  --paper:      oklch(17%   0.012 64);
  --paper-2:    oklch(20%   0.013 62);
  --card:       oklch(22.5% 0.013 60);
  --rule:       oklch(30%   0.012 60);
  --rule-2:     oklch(37%   0.013 58);
  --neutral:    oklch(64%   0.012 60);
  --muted:      oklch(74%   0.012 62);
  --ink:        oklch(90%   0.010 72);
  --ink-strong: oklch(96%   0.010 78);

  --accent:        oklch(66% 0.115 50);
  --accent-deep:   oklch(74% 0.115 54);
  --accent-soft:   oklch(32% 0.045 50);
  --accent-line:   oklch(52% 0.085 50);
  --gold:          oklch(78% 0.105 80);
  --success:       oklch(64% 0.085 155);
  --danger:        oklch(66% 0.140 28);

  --shadow:    0 12px 32px -14px oklch(0% 0 0 / 0.55);
  --shadow-lg: 0 30px 64px -22px oklch(0% 0 0 / 0.65);

  --toast-bg: oklch(28% 0.012 60);
  --toast-fg: var(--ink-strong);
  --scrim: oklch(0% 0 0 / 0.55);
  --hover: oklch(100% 0 0 / 0.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* class 上的 display 会盖过 UA 的 [hidden]{display:none}，这里强制兜底 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--body);
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: oldstyle-nums;
}

button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============================================================
   骨架
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 256px 1fr;
  height: 100vh;
}

/* ---------- 侧栏：报头式 ---------- */
.sidebar {
  background: var(--paper-2);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-sm) var(--space-md);
  -webkit-app-region: drag;
}
.sidebar button, .sidebar input { -webkit-app-region: no-drag; }

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 46px var(--space-xs) var(--space-md);
  margin-bottom: var(--space-xs);
  border-bottom: 1px solid var(--rule);
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent);
  color: oklch(97% 0.02 80);
  font-family: var(--display);
  font-size: 21px;
  font-weight: 600;
  flex: none;
}
.brand-text h1 {
  font-family: var(--display);
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: 0.04em;   /* 中文用字间距更显从容 */
  color: var(--ink-strong);
}
.brand-text p {
  font-family: var(--display);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--neutral);
  margin-top: 1px;
}

.cat-nav {
  flex: 1;
  overflow-y: auto;
  margin-top: var(--space-2xs);
  padding-right: 2px;
}
.cat-nav::-webkit-scrollbar { width: 6px; }
.cat-nav::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }

.nav-label {
  font-size: var(--text-xs);
  letter-spacing: 0.16em;
  color: var(--muted);
  padding: var(--space-sm) var(--space-xs) var(--space-2xs);
}

.cat-item {
  -webkit-app-region: no-drag;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.cat-item:hover { background: var(--hover); color: var(--ink); }
.cat-item.active {
  background: var(--card);
  color: var(--ink-strong);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px var(--rule);
}
.cat-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.cat-item .cat-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count {
  font-size: var(--text-sm);
  color: var(--neutral);
  font-variant-numeric: tabular-nums;
}
.cat-item.active .cat-count { color: var(--accent-deep); }

.sidebar-footer {
  display: flex;
  gap: var(--space-xs);
  padding-top: var(--space-sm);
  margin-top: var(--space-xs);
  border-top: 1px solid var(--rule);
}
.sidebar-footer .ghost-btn { flex: 1; }
.sidebar-footer .theme-btn { flex: 0 0 auto; width: 40px; padding: 8px 0; font-size: 15px; text-align: center; }

/* ---------- 主区 ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xl) var(--space-sm);
  -webkit-app-region: drag;
}
.topbar > *, .topbar input, .topbar button, .topbar select { -webkit-app-region: no-drag; }

.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  max-width: 460px;
}
.search-icon { position: absolute; left: 13px; color: var(--neutral); pointer-events: none; }
#searchInput {
  width: 100%;
  padding: 10px 36px 10px 38px;
  border: 1px solid var(--rule-2);
  background: var(--card);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  outline: none;
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
#searchInput::placeholder { color: var(--neutral); }
#searchInput:focus-visible {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-clear {
  position: absolute;
  right: 9px;
  width: 20px; height: 20px;
  border: none; background: var(--rule);
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: grid; place-items: center;
}
.search-clear:hover { background: var(--rule-2); color: var(--ink); }

.topbar-actions { display: flex; align-items: center; gap: var(--space-xs); }

.sort-wrap { position: relative; }
#sortSelect {
  appearance: none; -webkit-appearance: none;
  padding: 9px 30px 9px 13px;
  border: 1px solid var(--rule-2);
  background: var(--card);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--muted);
  cursor: pointer;
}
#sortSelect:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; }
.sort-wrap::after {
  content: "▾";
  position: absolute; right: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--neutral); pointer-events: none; font-size: 10px;
}

/* ---------- 按钮 ---------- */
.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  background: var(--accent);
  color: oklch(98% 0.015 80);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), transform 100ms var(--ease-out);
}
.primary-btn:hover { background: var(--accent-deep); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.primary-btn .plus { font-size: 17px; line-height: 1; margin-top: -1px; }

.ghost-btn {
  padding: 8px 13px;
  border: 1px solid var(--rule-2);
  background: var(--card);
  color: var(--muted);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.ghost-btn:hover { color: var(--ink); border-color: var(--neutral); }
.ghost-btn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; }

.danger-link {
  border: none; background: none;
  color: var(--danger);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: 6px 2px;
}
.danger-link:hover { text-decoration: underline; }

.ghost-link {
  border: none; background: none;
  color: var(--neutral);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: 6px 2px;
}
.ghost-link:hover { color: var(--ink); text-decoration: underline; }
.ghost-link:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; border-radius: 4px; }

.icon-btn {
  width: 32px; height: 32px;
  border: none; background: transparent;
  color: var(--neutral);
  font-size: 22px; line-height: 1;
  border-radius: 8px; cursor: pointer;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.icon-btn:hover { background: var(--rule); color: var(--ink); }

/* ---------- 统计条 ---------- */
.stats {
  display: flex;
  align-items: stretch;
  gap: var(--space-xl);
  padding: var(--space-2xs) var(--space-xl) var(--space-md);
}
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat + .stat { padding-left: var(--space-xl); border-left: 1px solid var(--rule); }
.stat-num {
  font-family: var(--display);
  font-size: var(--text-xl);
  font-weight: 500;
  line-height: 1.05;
  color: var(--ink-strong);
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: -0.01em;
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--neutral);
  letter-spacing: 0.1em;
}

/* ---------- 卡片网格 ---------- */
.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
  gap: var(--space-md);
  padding: var(--space-2xs) var(--space-xl) var(--space-2xl);
  align-content: start;
}
.grid::-webkit-scrollbar { width: 11px; }
.grid::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 6px; border: 3px solid var(--paper); }

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--space-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-height: 170px;
  /* 仅一种悬停信号：抬升（位移+阴影作为一个动作） */
  transition: transform 220ms var(--ease-out), box-shadow 220ms var(--ease-out);
  animation: cardIn 0.34s var(--ease-out) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

.card-head { display: flex; align-items: flex-start; gap: var(--space-sm); }
/* 物品图标：细描边「印章」，而非彩色色块 */
.card-stamp {
  width: 44px; height: 44px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 23px;
  background: var(--paper);
  border: 1px solid var(--rule-2);
  flex: none;
  overflow: hidden;
}
.stamp-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-titles { flex: 1; min-width: 0; padding-top: 2px; }
.card-name {
  font-size: var(--text-md);
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-strong);
  letter-spacing: 0.005em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-cat {
  display: inline-block;
  margin-top: 5px;
  font-size: var(--text-xs);
  color: var(--cat-color, var(--accent-deep));
  letter-spacing: 0.04em;
}
.card-cat::before {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--cat-color, var(--accent));
  margin-right: 6px;
  vertical-align: 1px;
}

.fav-star {
  position: absolute;
  top: 12px; right: 12px;
  width: 26px; height: 26px;
  border: none; background: transparent;
  cursor: pointer;
  font-size: 15px; line-height: 1;
  color: var(--neutral);
  opacity: 0;
  border-radius: 6px;
  transition: opacity var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.card:hover .fav-star { opacity: 0.55; }
.fav-star:hover { opacity: 1; background: var(--rule); }
.fav-star:focus-visible { opacity: 1; outline: 2px solid var(--accent-line); }
.fav-star.on { opacity: 1; color: var(--gold); }

.card-meta {
  margin-top: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}
.meta-row { display: flex; align-items: baseline; gap: var(--space-xs); font-size: var(--text-sm); }
.meta-key { color: var(--neutral); flex: none; width: 3.2em; letter-spacing: 0.03em; }
.meta-val { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta-val strong {
  color: var(--ink); font-weight: 500;
  font-variant-numeric: lining-nums tabular-nums;
}

.card-note {
  margin-top: var(--space-sm);
  font-size: var(--text-sm);
  color: var(--neutral);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-tags {
  margin-top: var(--space-sm);
  display: flex; flex-wrap: wrap; gap: var(--space-2xs);
}
.tag {
  font-size: var(--text-xs);
  color: var(--muted);
  padding: 2px 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out), background var(--dur) var(--ease-out);
}
.tag:hover { border-color: var(--accent-line); color: var(--accent-deep); background: var(--accent-soft); }
.tag:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; }

.card-foot {
  margin-top: auto;
  padding-top: var(--space-sm);
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--text-xs);
  color: var(--neutral);
}
.card-qty-badge {
  font-family: var(--display);
  font-variant-numeric: lining-nums tabular-nums;
  font-size: var(--text-sm);
  color: var(--muted);
}

mark {
  background: var(--accent-soft);
  color: var(--accent-deep);
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------- 空状态 ---------- */
.empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: var(--space-xs);
  padding: var(--space-2xl);
  color: var(--muted);
}
.empty-art {
  font-family: var(--display);
  font-style: italic;
  font-size: var(--text-2xl);
  color: var(--rule-2);
}
.empty h2 { font-family: var(--display); font-size: var(--text-lg); color: var(--ink-strong); font-weight: 500; margin-top: var(--space-2xs); }
.empty p { font-size: var(--text-base); max-width: 30ch; line-height: 1.6; }
.empty-actions { display: flex; gap: var(--space-sm); align-items: center; margin-top: var(--space-sm); }

/* ============================================================
   弹窗
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: var(--z-modal);
  padding: var(--space-lg);
  animation: fadeIn 0.18s var(--ease-out) both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 560px; max-width: 100%; max-height: 90vh;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn 0.24s var(--ease-out) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-md) var(--space-lg) var(--space-sm);
  border-bottom: 1px solid var(--rule);
}
.modal-head h2 { font-family: var(--display); font-size: var(--text-lg); font-weight: 500; color: var(--ink-strong); }
.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-md);
}
.modal-foot {
  display: flex; align-items: center; gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  border-top: 1px solid var(--rule);
}
.modal-foot .spacer { flex: 1; }

.field-row { display: flex; gap: var(--space-md); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.grow { flex: 1; }
.field label { font-size: var(--text-sm); color: var(--muted); }
.field .req { color: var(--accent); }
.field input, .field textarea {
  padding: 9px 11px;
  border: 1px solid var(--rule-2);
  background: var(--paper);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  outline: none;
  width: 100%;
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), background var(--dur) var(--ease-out);
}
.field textarea { resize: vertical; line-height: 1.55; }
.field input:focus-visible, .field textarea:focus-visible {
  border-color: var(--accent-line);
  background: var(--card);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.emoji-field { align-items: flex-start; }
.icon-preview {
  width: 52px; height: 52px;
  border: 1px solid var(--rule-2);
  background: var(--paper);
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-size: 24px;
  overflow: hidden;
}
.icon-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.icon-actions { display: flex; gap: var(--space-sm); margin-top: 6px; }
.mini-link {
  border: none; background: none;
  color: var(--accent-deep);
  font-size: var(--text-xs);
  cursor: pointer; padding: 2px 0;
}
.mini-link:hover { text-decoration: underline; }
.mini-link:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; border-radius: 3px; }

.emoji-palette {
  display: flex; flex-wrap: wrap; gap: 3px;
  padding: var(--space-sm);
  background: var(--paper);
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule);
  max-height: 188px; overflow-y: auto;
}
.emoji-palette button {
  width: 34px; height: 34px;
  border: none; background: transparent;
  border-radius: 7px; font-size: 20px; cursor: pointer;
  transition: background 120ms var(--ease-out);
}
.emoji-palette button:hover { background: var(--card); }

/* ============================================================
   轻提示 (含撤销)
   ============================================================ */
.toast-stack {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--space-xs);
  z-index: var(--z-toast);
  align-items: center;
}
.toast {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 10px 12px 10px 16px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  border-radius: 11px;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.4s var(--ease-out) both;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.toast.out { animation: toastOut 0.3s var(--ease-in) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
.toast-action {
  border: none;
  background: oklch(100% 0 0 / 0.16);
  color: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 7px;
  cursor: pointer;
}
.toast-action:hover { background: oklch(100% 0 0 / 0.26); }

/* ---------- 分段切换 / 排序方向 ---------- */
.seg {
  display: inline-flex;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  border: none; background: transparent;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: var(--text-sm);
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active {
  background: var(--card);
  color: var(--ink-strong);
  box-shadow: 0 1px 2px oklch(30% 0.02 50 / 0.12);
}
.seg-btn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; }

.sort-dir {
  border: 1px solid var(--rule-2);
  background: var(--card);
  font-size: 15px;
  color: var(--muted);
}
.sort-dir:hover { color: var(--ink); border-color: var(--neutral); background: var(--card); }

.density-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--rule-2);
  background: var(--card);
  color: var(--muted);
}
.density-btn:hover { color: var(--ink); border-color: var(--neutral); }
.density-btn.active { color: var(--accent-deep); border-color: var(--accent-line); background: var(--accent-soft); }

/* ---------- 紧凑密度 ---------- */
:root[data-density="compact"] .grid {
  grid-template-columns: repeat(auto-fill, minmax(218px, 1fr));
  gap: var(--space-sm);
}
:root[data-density="compact"] .card { padding: var(--space-sm); min-height: 0; }
:root[data-density="compact"] .card-stamp { width: 38px; height: 38px; font-size: 20px; border-radius: 9px; }
:root[data-density="compact"] .card-meta { margin-top: var(--space-xs); gap: 3px; }
:root[data-density="compact"] .card-note { -webkit-line-clamp: 1; margin-top: var(--space-xs); }
:root[data-density="compact"] .card-tags { margin-top: var(--space-xs); }
:root[data-density="compact"] .card-foot { padding-top: var(--space-xs); }
:root[data-density="compact"] .ledger tbody td { padding: 5px var(--space-xs); }
:root[data-density="compact"] .ledger-stamp { width: 26px; height: 26px; font-size: 15px; }
:root[data-density="compact"] .stats { padding-bottom: var(--space-sm); }

/* ---------- 活动筛选条 ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0 var(--space-xl) var(--space-sm);
}
.filter-label { font-size: var(--text-xs); color: var(--neutral); letter-spacing: 0.08em; }
.filter-count { font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; margin-right: var(--space-2xs); }
.filter-count strong { color: var(--ink); font-weight: 600; }
.filter-clear {
  border: none; background: none;
  color: var(--neutral); font-size: var(--text-sm);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
  padding: 2px 4px;
}
.filter-clear:hover { color: var(--ink); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-deep);
  padding: 3px 11px;
  border-radius: 20px;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease-out);
}
.filter-chip:hover { background: oklch(90% 0.05 55); }
.filter-x { font-size: 14px; line-height: 1; }

/* ---------- 卡片数量步进 ---------- */
.card-foot { align-items: center; }
.qty-stepper { display: inline-flex; align-items: center; gap: 3px; }
.qty-btn {
  width: 22px; height: 22px;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px; line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out), background var(--dur) var(--ease-out),
              color var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.card:hover .qty-btn { opacity: 1; }
.qty-btn:hover { background: var(--accent-soft); color: var(--accent-deep); border-color: var(--accent-line); }
.qty-btn:focus-visible { opacity: 1; outline: 2px solid var(--accent-line); outline-offset: 1px; }
.qty-val {
  min-width: 1.8em; text-align: center;
  font-family: var(--display);
  font-variant-numeric: lining-nums tabular-nums;
  font-size: var(--text-sm);
  color: var(--muted);
}

/* ---------- 清单 / 台账视图 ---------- */
.ledger-wrap { flex: 1; overflow: auto; padding: var(--space-2xs) var(--space-xl) var(--space-2xl); }
.ledger-wrap::-webkit-scrollbar { width: 11px; height: 11px; }
.ledger-wrap::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 6px; border: 3px solid var(--paper); }
.ledger { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.ledger thead th {
  position: sticky; top: 0;
  background: var(--paper);
  text-align: left;
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--neutral);
  padding: var(--space-sm) var(--space-sm) var(--space-xs);
  border-bottom: 1px solid var(--rule-2);
  z-index: 1;
}
.ledger th.num, .ledger td.num { text-align: right; font-variant-numeric: lining-nums tabular-nums; }
.ledger th[data-sort] { cursor: pointer; user-select: none; transition: color var(--dur) var(--ease-out); }
.ledger th[data-sort]:hover { color: var(--ink); }
.ledger th.sorted { color: var(--accent-deep); }
.ledger th .sort-ind { margin-left: 4px; font-size: 9px; }
.ledger tbody td {
  padding: var(--space-sm);
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  vertical-align: middle;
  white-space: nowrap;
}
.ledger td.num strong { color: var(--ink); font-weight: 500; }
.ledger td.muted { color: var(--neutral); }
.ledger td.lc-loc { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.ledger-row { cursor: pointer; transition: background var(--dur) var(--ease-out); }
.ledger-row:hover { background: var(--card); }
.ledger-row:focus-visible { outline: 2px solid var(--accent-line); outline-offset: -2px; }
.ledger th.lc-item { width: 40%; }
.ledger td.lc-item { display: flex; align-items: center; gap: var(--space-sm); white-space: normal; }
.ledger-stamp {
  width: 30px; height: 30px; flex: none;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 17px;
  background: var(--paper);
  border: 1px solid var(--rule-2);
  overflow: hidden;
}
.ledger-titles { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ledger-name { color: var(--ink-strong); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger-cat { font-size: var(--text-xs); color: var(--cat-color, var(--accent-deep)); margin-top: 1px; }
.ledger-cat::before {
  content: ""; display: inline-block;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--cat-color, var(--accent)); margin-right: 5px; vertical-align: 1px;
}
.ledger-row .fav-star { position: static; width: 24px; height: 24px; flex: none; opacity: 0; }
.ledger-row:hover .fav-star { opacity: 0.5; }
.ledger-row .fav-star.on { opacity: 1; }

/* 侧栏脚注 + 移动端抽屉的基础态（桌面隐藏开关与遮罩） */
.sidebar-hint {
  font-size: var(--text-xs);
  color: var(--neutral);
  padding: var(--space-xs) var(--space-xs) var(--space-2xs);
  letter-spacing: 0.02em;
}
.menu-btn { display: none; }
.sidebar-scrim { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }

  /* 侧栏变为可滑出的抽屉 */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 264px;
    z-index: var(--z-modal);
    transform: translateX(-100%);
    transition: transform 260ms var(--ease-out);
    border-right: 1px solid var(--rule-2);
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar-scrim {
    display: block;
    position: fixed; inset: 0;
    background: var(--scrim);
    z-index: var(--z-sticky);
    animation: fadeIn 0.2s var(--ease-out) both;
  }
  .menu-btn { display: inline-flex; }

  .field-row { flex-direction: column; gap: var(--space-sm); }
  .stats { gap: var(--space-md); overflow-x: auto; }
  .stat + .stat { padding-left: var(--space-md); }
  .topbar, .stats, .grid, .ledger-wrap, .filter-bar { padding-left: var(--space-md); padding-right: var(--space-md); }
  .topbar { flex-wrap: wrap; }
  .topbar-actions { flex: 1; justify-content: flex-end; }
}

/* ---------- 打印 / 导出 PDF ---------- */
.print-header { display: none; }
@media print {
  :root {
    --paper: #fff; --card: #fff; --ink: #000; --ink-strong: #000;
    --muted: #222; --neutral: #444; --rule: #ccc; --rule-2: #999;
  }
  html, body { overflow: visible; height: auto; background: #fff; color: #000; }
  .app { display: block; height: auto; }
  .sidebar, .sidebar-scrim, .topbar, .filter-bar, .stats, .empty,
  .modal-overlay, .toast-stack, .menu-btn,
  .fav-star, .qty-stepper, .sort-ind { display: none !important; }
  .main { display: block; overflow: visible; }

  .print-header { display: block; margin-bottom: 14px; }
  .print-header h1 { font-family: var(--display); font-size: 20pt; font-weight: 600; }
  .print-header .meta { font-size: 9pt; color: #333; margin-top: 4px; }

  #listing, .ledger-wrap { display: block; overflow: visible; height: auto; padding: 0; }
  .ledger { width: 100%; font-size: 10pt; }
  .ledger thead th {
    position: static; background: #fff; color: #000;
    border-bottom: 1.5px solid #000; padding: 4px 8px;
  }
  .ledger tbody td { border-bottom: 1px solid #ccc; color: #000; padding: 6px 8px; }
  .ledger td.num strong, .ledger-name { color: #000; }
  .ledger th.sorted, .ledger-cat { color: #000; }
  .ledger-row { break-inside: avoid; }
  .ledger-stamp { border-color: #999; }
  @page { margin: 1.5cm; }
}
