:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --line: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --primary: #e23b3b;
  --primary-d: #c22f2f;
  --gold: #d8b46a;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: rgba(15,17,21,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #ff7a45);
  color: #fff; font-weight: 700; font-size: 18px;
}
.brand-text h1 { font-size: 16px; font-weight: 700; }
.brand-text p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.search-wrap { margin-left: auto; flex: 1; max-width: 360px; }
#search {
  width: 100%; height: 38px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 20px; color: var(--text); font-size: 14px; outline: none;
}
#search:focus { border-color: var(--primary); }

/* 布局 */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: 60px;
  width: 180px; flex: 0 0 180px;
  padding: 14px 10px;
  display: flex; flex-direction: column; gap: 6px;
  max-height: calc(100vh - 60px); overflow-y: auto;
}
.cat-chip {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 10px;
  background: transparent; border: 1px solid transparent;
  color: var(--muted); font-size: 14px; text-align: left; cursor: pointer;
  transition: .15s;
}
.cat-chip em { font-style: normal; font-size: 12px; color: var(--muted); }
.cat-chip:hover { background: var(--surface); color: var(--text); }
.cat-chip.active { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.cat-chip.active em { color: var(--gold); }

.content { flex: 1; padding: 14px; min-width: 0; }

/* 网格 */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.card {
  position: relative; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: .15s;
}
.card:hover { border-color: #3a4150; transform: translateY(-2px); }
.card img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; }
.card .meta {
  padding: 7px 9px; font-size: 12px; color: var(--muted);
  display: flex; justify-content: space-between; gap: 6px;
}
.card .meta .code { color: var(--gold); font-weight: 600; white-space: nowrap; }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(226,59,59,.35); }
.card .pick {
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 16px; line-height: 1;
  background: rgba(0,0,0,.45); color: #fff;
  display: grid; place-items: center; backdrop-filter: blur(2px);
}
.card.selected .pick { background: var(--primary); }
.card .pickbadge {
  position: absolute; top: 8px; left: 8px;
  background: var(--primary); color: #fff; font-size: 11px;
  padding: 2px 7px; border-radius: 10px; display: none;
}
.card.selected .pickbadge { display: block; }

.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* 底部选图浮条 */
.pickbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 12px;
  background: rgba(23,26,33,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  transform: translateY(110%); transition: transform .25s;
}
.pickbar.show { transform: translateY(0); }
.pick-count { font-size: 14px; }
.pick-count strong { color: var(--gold); font-size: 18px; }
.pick-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); padding: 9px 16px; border-radius: 20px;
  font-size: 14px; cursor: pointer; transition: .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: transparent; }

/* hidden 属性优先级最高：保证弹层/提示默认隐藏（修复 display:flex 覆盖 hidden 的 bug） */
[hidden] { display: none !important; }

/* 弹层 */
.modal, .lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%; max-width: 520px; max-height: 86vh;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 12px 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal-foot .btn { flex: 1; }
.hint { font-size: 12px; color: var(--muted); padding: 0 16px 14px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--surface-2); color: var(--text); font-size: 22px; cursor: pointer;
}
.icon-btn:hover { background: #2a2f3a; }

/* 清单项 */
.list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.list-item img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.list-item .li-info { flex: 1; min-width: 0; }
.list-item .li-code { color: var(--gold); font-weight: 600; font-size: 14px; }
.list-item .li-name { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-del { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.list-item .li-del:hover { color: var(--primary); }

/* 大图 */
.lightbox { flex-direction: column; background: rgba(0,0,0,.92); }
#lbImg { max-width: 92vw; max-height: 76vh; object-fit: contain; border-radius: 8px; }
.lb-close { position: fixed; top: 16px; right: 16px; }
.lb-nav {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.12); color: #fff; font-size: 30px; cursor: pointer;
}
.lb-nav.prev { left: 16px; } .lb-nav.next { right: 16px; }
.lb-bar {
  position: fixed; bottom: 24px; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; gap: 16px;
}
.lb-bar span { color: #fff; font-size: 14px; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #000; color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 14px; z-index: 80; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: .92; }

/* 移动端 */
@media (max-width: 720px) {
  .sidebar {
    position: sticky; top: 59px; width: 100%; flex: none;
    flex-direction: row; overflow-x: auto; padding: 8px 10px;
    max-height: none; border-bottom: 1px solid var(--line); background: var(--bg);
  }
  .cat-chip { flex: 0 0 auto; white-space: nowrap; }
  .layout { flex-direction: column; }
  .content { padding: 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
  .search-wrap { max-width: none; }
  .brand-text p { display: none; }
}
