/* ===== 主题系统 =====
 * 默认主题: Obsidian
 * 切换方法: 修改 <html data-theme="xxx"> 的值
 * 可选: dark-roast / frost / obsidian / blaze
 * 自定义: 复制任意一套，改 data-theme 名称和色值即可
 */

/* --- Obsidian: 深蓝灰/极客科技 --- */
[data-theme="obsidian"] {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #242833; --surface3: #2e323f;
  --border: #363b4a; --border-light: #434959;
  --text: #e4e6ed; --text-muted: #8b90a0; --text-dim: #5c6173;
  --accent: #818cf8; --accent-glow: #a5b4fc;
  --green: #4ade80; --blue: #60a5fa; --purple: #c084fc;
  --red: #f87171; --orange: #fb923c; --yellow: #fbbf24;
  --font-display: 'JetBrains Mono', 'SF Mono', monospace;
  --font-body: 'Noto Sans SC', -apple-system, sans-serif;
}
/* --- Dark Roast: 深色暖褐/品质感 --- */
[data-theme="dark-roast"] {
  --bg: #1a1412; --surface: #231e1a; --surface2: #2c2520; --surface3: #362e28;
  --border: #3d3430; --border-light: #4a3f39;
  --text: #f0e8e0; --text-muted: #a89888; --text-dim: #7a6b5e;
  --accent: #d4a574; --accent-glow: #e8b888;
  --green: #6db87a; --blue: #7aa3c8; --purple: #9b82c4;
  --red: #c47a6d; --orange: #d4956a; --yellow: #d4b86a;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Noto Sans SC', -apple-system, sans-serif;
}
/* --- Frost: 浅色简约/清爽效率 --- */
[data-theme="frost"] {
  --bg: #f5f6f8; --surface: #ffffff; --surface2: #eef0f4; --surface3: #e4e7ed;
  --border: #d8dce6; --border-light: #c8cdd8;
  --text: #1c1f26; --text-muted: #5c6070; --text-dim: #8b90a0;
  --accent: #2d6be6; --accent-glow: #5b8ff7;
  --green: #16a34a; --blue: #2563eb; --purple: #7c3aed;
  --red: #dc2626; --orange: #ea580c; --yellow: #ca8a04;
  --font-display: 'Inter Tight', -apple-system, sans-serif;
  --font-body: 'Noto Sans SC', -apple-system, sans-serif;
}
/* --- Blaze: 深色玫红/激励感 --- */
[data-theme="blaze"] {
  --bg: #1a0a14; --surface: #261520; --surface2: #321e2c; --surface3: #3e2838;
  --border: #4a3344; --border-light: #5c4055;
  --text: #f5e8f0; --text-muted: #b89aad; --text-dim: #8a6e80;
  --accent: #f43f7a; --accent-glow: #ff6b9d;
  --green: #4ade80; --blue: #60a5fa; --purple: #c084fc;
  --red: #f87171; --orange: #fb923c; --yellow: #fbbf24;
  --font-display: 'Bebas Neue', Impact, sans-serif;
  --font-body: 'Noto Sans SC', -apple-system, sans-serif;
}

:root {
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font-body);
  font-weight: 300;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ===== Top Bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--bg) 60%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 24px; }
.topbar h1 {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.topbar-right { display: flex; align-items: center; gap: 12px; position: relative; }
.count {
  font-family: var(--font-display);
  font-size: 13px; color: var(--text-dim);
  letter-spacing: 0.02em;
}
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-muted); font-size: 18px; padding: 4px 10px;
  cursor: pointer; transition: all .2s;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.menu-dropdown {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; min-width: 160px;
  z-index: 20; box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.menu-dropdown.open { display: block; }
.menu-dropdown button, .menu-dropdown .menu-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 14px; background: none; border: none;
  color: var(--text); font-size: 14px; cursor: pointer;
  font-family: var(--font-body); transition: background .15s;
}
.menu-dropdown button:hover, .menu-dropdown .menu-item:hover { background: var(--surface3); }

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: 20px; z-index: 20;
  display: grid; place-items: center;
  width: 56px; height: 56px;
  background: var(--accent);
  border: none; border-radius: 50%;
  color: var(--bg); cursor: pointer;
  font-size: 24px; font-weight: 300;
  box-shadow: 0 4px 20px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: all .2s;
}
.fab:hover { background: var(--accent-glow); transform: scale(1.05); }
.fab:active { transform: scale(.95); }

/* ===== Filters ===== */
.filters {
  position: sticky; top: 54px; z-index: 9;
  padding: 8px 20px 12px; background: var(--bg);
  display: flex; flex-direction: column; gap: 10px;
}
.search-wrap { position: relative; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); pointer-events: none;
}
.filters input {
  width: 100%; padding: 10px 12px 10px 36px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px;
  font-family: var(--font-body); transition: border-color .2s;
}
.filters input:focus { outline: none; border-color: var(--accent); }
.filters input::placeholder { color: var(--text-dim); }
.chips {
  display: flex; gap: 6px; overflow-x: auto;
  scrollbar-width: none; -ms-overflow-style: none; padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 5px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; color: var(--text-muted);
  font-size: 13px; font-family: var(--font-body); font-weight: 400;
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.chip:hover { border-color: var(--border-light); color: var(--text); }
.chip.active {
  background: var(--accent); border-color: var(--accent);
  color: var(--bg); font-weight: 500;
}

/* ===== Sort Bar ===== */
.sort-bar {
  display: flex; gap: 8px; padding: 4px 16px 8px; background: var(--bg);
}
.sort-btn {
  font-size: 13px; padding: 5px 14px; border-radius: 14px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); font-family: inherit;
  cursor: pointer; transition: all 0.2s;
}
.sort-btn.active {
  background: var(--accent); color: var(--bg); border-color: var(--accent);
}

/* ===== Cards ===== */
.cards { padding: 6px 16px 120px; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; transition: all .25s ease;
  position: relative; overflow: hidden;
}
.card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; border-radius: 3px 0 0 3px;
}
.card.s-在用::before { background: var(--green); }
.card.s-库存::before { background: var(--blue); }
.card.s-用完::before { background: var(--text-dim); }
.card:active { transform: scale(.985); }
@media (hover: hover) {
  .card:hover { border-color: var(--border-light); background: var(--surface2); }
}

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-name {
  font-family: var(--font-display);
  font-size: 17px; font-weight: 600;
  color: var(--accent-glow); line-height: 1.3;
  letter-spacing: 0.02em;
}
.card-status {
  flex-shrink: 0; font-size: 11px; padding: 3px 10px;
  border-radius: 999px; font-weight: 500; white-space: nowrap;
}
.card-status.s-在用 { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.card-status.s-库存 { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.card-status.s-用完 { background: var(--surface3); color: var(--text-dim); }

.card-meta {
  margin-top: 6px; font-size: 13px; color: var(--text-muted);
  display: flex; flex-wrap: wrap; gap: 4px 0;
  font-family: var(--font-display); letter-spacing: 0.01em;
}
.card-meta .sep { margin: 0 6px; opacity: .4; }

/* Remaining bar */
.remain-bar-wrap {
  margin-top: 10px; display: flex; align-items: center; gap: 8px;
}
.remain-bar {
  flex: 1; height: 6px; background: var(--surface3);
  border-radius: 3px; overflow: hidden;
}
.remain-bar-fill {
  height: 100%; border-radius: 3px;
  transition: width .3s ease;
}
.remain-bar-fill.high { background: var(--green); }
.remain-bar-fill.mid { background: var(--yellow); }
.remain-bar-fill.low { background: var(--red); }
.remain-pct {
  font-family: var(--font-display);
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  min-width: 36px; text-align: right;
  letter-spacing: 0.02em;
}

.card-tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  font-size: 11px; padding: 2px 8px;
  background: var(--surface3); border-radius: 6px; color: var(--text-muted);
}

.card-note {
  margin-top: 8px; font-size: 13px; line-height: 1.5;
  color: var(--text-muted); font-style: italic;
}
.card-footer {
  margin-top: 8px; display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-dim);
  font-family: var(--font-display); letter-spacing: 0.01em;
}

/* ===== Empty State ===== */
.empty { text-align: center; padding: 80px 20px; color: var(--text-dim); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== Editor Dialog ===== */
dialog {
  border: none; border-radius: 16px;
  max-width: 520px; width: 94vw;
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  padding: 0; margin: auto; inset: 0;
  max-height: 90vh; overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,.65); }
.editor-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px 0;
}
.editor-header h3 {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 600; color: var(--accent);
  letter-spacing: 0.03em;
}
.close-btn {
  background: none; border: none;
  color: var(--text-dim); font-size: 18px; cursor: pointer; padding: 4px 8px;
}
.editor-body {
  padding: 16px 20px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  max-height: 60vh; overflow-y: auto;
}
.editor-body label { display: flex; flex-direction: column; gap: 4px; }
.editor-body label.full { grid-column: 1 / -1; }
.editor-body span { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.editor-body input, .editor-body select, .editor-body textarea {
  padding: 9px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-family: var(--font-body);
  transition: border-color .2s;
}
.editor-body input:focus, .editor-body select:focus, .editor-body textarea:focus {
  outline: none; border-color: var(--accent);
}
.editor-body textarea { resize: vertical; }
.editor-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px 18px; border-top: 1px solid var(--border);
}
.spacer { flex: 1; }
.ghost-btn {
  padding: 8px 18px; background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted); font-size: 14px;
  cursor: pointer; transition: all .2s;
}
.ghost-btn:hover { border-color: var(--text-muted); color: var(--text); }
.primary-btn {
  padding: 8px 22px; background: var(--accent);
  border: none; border-radius: var(--radius-sm);
  color: var(--bg); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all .2s;
}
.primary-btn:hover { background: var(--accent-glow); }
.danger-btn {
  padding: 8px 16px; background: none; border: 1px solid var(--red);
  border-radius: var(--radius-sm); color: var(--red); font-size: 13px;
  cursor: pointer; transition: all .2s;
}
.danger-btn:hover { background: color-mix(in srgb, var(--red) 12%, transparent); }

/* Smart Select */
.smart-select-wrap { display: flex; gap: 6px; align-items: center; }
.smart-select-wrap select { flex: 1; min-width: 0; }
.smart-manage-btn {
  flex-shrink: 0; width: 36px; height: 36px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text-dim);
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.smart-manage-btn:hover { background: var(--surface3); color: var(--text); }
.smart-manager-body { padding: 12px 16px; max-height: 50vh; overflow-y: auto; }
.smart-manager-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.smart-manager-item:last-child { border-bottom: none; }
.smart-manager-name {
  flex: 1; font-size: 15px; color: var(--text);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.smart-manager-count { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.smart-manager-actions { display: flex; gap: 4px; flex-shrink: 0; }
.smart-manager-action {
  width: 32px; height: 32px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); cursor: pointer;
  font-size: 14px; display: flex; align-items: center; justify-content: center;
  transition: all .15s; color: var(--text-muted);
}
.smart-manager-action:hover { background: var(--surface2); }
.smart-manager-action.danger:hover {
  background: color-mix(in srgb, var(--red) 12%, transparent);
  color: var(--red); border-color: var(--red);
}
.smart-manager-empty { text-align: center; color: var(--text-dim); padding: 24px 0; font-size: 14px; }
/* Auto-calc field */
.auto-calc {
  background: var(--surface3) !important;
  color: var(--accent) !important;
  font-family: var(--font-display) !important;
  font-weight: 600 !important;
  letter-spacing: 0.02em;
  cursor: default;
}

.smart-input {
  margin-top: 6px; padding: 9px 12px;
  background: var(--surface2); border: 1px solid var(--accent);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
  font-family: var(--font-body); width: 100%;
}

/* ===== Animations ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeUp .35s ease both; }
.cards .card:nth-child(1) { animation-delay: 0s; }
.cards .card:nth-child(2) { animation-delay: .03s; }
.cards .card:nth-child(3) { animation-delay: .06s; }
.cards .card:nth-child(4) { animation-delay: .09s; }
.cards .card:nth-child(5) { animation-delay: .12s; }

/* ===== Responsive ===== */
@media (max-width: 520px) {
  .editor-body { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .filters { padding: 6px 16px 10px; }
  .topbar h1 { font-size: 20px; }
}
@media (display-mode: standalone) {
  .topbar { padding-top: 56px; }
  .editor-header { padding-top: 56px; }
}
