:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #e2e8f0;
  --ink: #1a2b4a;
  --sub: #64748b;
  --blue: #2b6cb0;
  --blue-d: #1f4e80;
  --green: #0f7b5f;
  --red: #c0392b;
  --amber: #b7791f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}
button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  transition: .15s;
}
button:hover { border-color: var(--blue); color: var(--blue); }
button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover { background: var(--blue-d); color: #fff; }
button.danger { color: var(--red); border-color: #f0c5c0; }
button.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select {
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}
input:focus, select:focus { border-color: var(--blue); }

/* ---------- 登录 ---------- */
#login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2b6cb0, #0f7b5f);
  z-index: 100;
}
#login .box {
  background: #fff; padding: 32px 28px; border-radius: 16px; width: 320px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
#login h1 { font-size: 20px; margin: 0 0 4px; }
#login .tip { color: var(--sub); font-size: 12px; margin: 0 0 18px; }
#login label { display: block; margin: 10px 0 4px; font-size: 12px; color: var(--sub); }
#login input { width: 100%; }
#login button { width: 100%; margin-top: 18px; padding: 10px; }

/* 登录验证码 */
#login .captcha-row { display: flex; gap: 10px; align-items: stretch; }
#login .captcha-row input { flex: 1; width: auto; text-transform: uppercase; letter-spacing: 2px; }
#login .captcha-img {
  height: 40px; width: 110px; border: 1px solid #ddd; border-radius: 8px;
  cursor: pointer; background: #f7f7f7; flex: none;
}
@media (max-width: 480px) {
  #login .box { width: 88%; }
}

/* ---------- 布局 ---------- */
#app { display: none; height: 100vh; flex-direction: column; }
header.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
header.topbar .logo { font-weight: 600; font-size: 16px; }
header.topbar .spacer { flex: 1; }
header.topbar .user { color: var(--sub); font-size: 13px; }
.menu-toggle { display: none; }

.body { flex: 1; display: flex; overflow: hidden; }

/* 侧栏 */
aside.sidebar {
  width: 248px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
aside.sidebar .sb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
aside.sidebar .sb-head span { font-weight: 600; font-size: 13px; }
.tree { flex: 1; overflow: auto; padding: 6px 4px; }
.tree-item { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px;
  cursor: pointer; font-size: 13px;
}
.tree-row:hover { background: #f1f5f9; }
.tree-row.active { background: #e8f1fb; color: var(--blue); }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .tw { opacity: .6; font-size: 11px; }
.tree-children { margin-left: 14px; }

/* 主区 */
main.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .crumb { font-size: 13px; color: var(--sub); margin-right: 6px; }
.toolbar input.search { width: 200px; }
.toolbar .spacer { flex: 1; }
.sel-info { font-size: 12px; color: var(--sub); margin-right: 6px; }

.grid-wrap { flex: 1; overflow: auto; padding: 16px; }
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
/* 列表预览尺寸（大图 / 中图 / 小图） */
.grid.size-large { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.size-medium { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.size-small { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.grid.size-small .card .meta .fn { font-size: 11px; }
.grid.size-small .card .meta .sub { font-size: 10px; }

/* 尺寸分段切换 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 6px 12px; background: #fff; color: var(--sub); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--blue); color: #fff; }
.seg button.active:hover { color: #fff; }
.seg button:hover { color: var(--blue); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; position: relative; transition: .15s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.card .thumb {
  width: 100%; aspect-ratio: 4/3; object-fit: scale-down; display: block;
}
.card .meta { padding: 6px 8px; }
.card .meta .fn { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta .sub { font-size: 11px; color: var(--sub); }
.card .check {
  position: absolute; top: 8px; left: 8px; width: 20px; height: 20px;
  border-radius: 6px; border: 2px solid #fff; background: rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px;
}
.card.selected { outline: 2px solid var(--blue); }
.card .dots {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px;
  border: none; border-radius: 6px; background: rgba(0,0,0,.32); color: #fff;
  font-size: 18px; line-height: 1; cursor: pointer; opacity: .85;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.card .dots:hover { background: rgba(0,0,0,.55); opacity: 1; }
.play-badge { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 42px; height: 42px; border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; pointer-events: none; }
.card-menu {
  position: fixed; z-index: 80; min-width: 150px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18); display: none;
}
.card-menu.show { display: block; }
.card-menu button {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 8px 10px; border-radius: 6px; font-size: 13px; color: #1f2937; cursor: pointer;
}
.card-menu button:hover { background: #e8f1fb; color: var(--blue); }
.empty { text-align: center; color: var(--sub); padding: 60px 0; }

.pager { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.pager .spacer { flex: 1; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px; padding: 20px; width: 460px; max-width: 92vw;
  box-shadow: 0 12px 48px rgba(0,0,0,.25); max-height: 90vh; overflow: auto;
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal .row { margin: 10px 0; }
.modal label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.del-hint { margin: 0 0 8px; font-size: 13px; color: var(--red, #c0392b); line-height: 1.5; }

/* 拖拽上传 */
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center;
  color: var(--sub); cursor: pointer; transition: .15s;
}
.dropzone.drag { border-color: var(--blue); background: #f0f6ff; color: var(--blue); }
.dropzone .big { font-size: 28px; }
.filelist { margin-top: 10px; max-height: 160px; overflow: auto; }
.filelist .f { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.progress { height: 8px; background: #eef2f7; border-radius: 6px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--blue); transition: .2s; }

/* 灯箱 */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.8); display: none;
  align-items: center; justify-content: center; z-index: 60; flex-direction: column;
}
.lightbox.show { display: flex; }
.lightbox .lb-body { display: flex; align-items: center; gap: 28px; max-width: 96vw; }
.lightbox .lb-left { flex: 0 1 auto; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 58vw; max-height: 78vh; border-radius: 8px; display: block; }
.lightbox .lb-right { flex: 1 1 320px; max-width: 440px; min-width: 280px; max-height: 82vh; overflow: auto; }
.lightbox .lb-meta {
  display: block; color: #eee; font-size: 14px; line-height: 1.5; width: 100%; box-sizing: border-box;
  background: rgba(255,255,255,.08); padding: 14px 18px; border-radius: 10px;
}
.lightbox .lb-meta .lb-row {
  display: flex; justify-content: space-between; gap: 16px; padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.lightbox .lb-meta .lb-row:last-child { border-bottom: none; }
.lightbox .lb-meta .lb-row .lb-k { color: #aab4c4; white-space: nowrap; flex: 0 0 auto; }
.lightbox .lb-meta .lb-row .lb-v { color: #fff; text-align: right; word-break: break-all; }
.lightbox .lb-bar { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
@media (max-width: 760px) {
  .lightbox .lb-body { flex-direction: column; gap: 14px; }
  .lightbox img { max-width: 92vw; max-height: 50vh; }
  .lightbox .lb-right { max-width: 92vw; width: 92vw; }
}
.lightbox .lb-pos { font-size: 13px; color: #eee; margin-right: auto; }
.lightbox .lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,.16); color: #fff; border: none;
  width: 46px; height: 64px; font-size: 34px; line-height: 1; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.lightbox .lb-nav:hover { background: rgba(255,255,255,.32); color: #fff; }
.lightbox .lb-prev { left: 18px; }
.lightbox .lb-next { right: 18px; }
.lightbox .lb-nav:disabled { opacity: .22; cursor: not-allowed; }
.lightbox .lb-close { position: absolute; top: 16px; right: 20px; color: #fff; font-size: 26px; cursor: pointer; }
/* 视频预览：动态 img/video 容器与媒体元素统一样式 */
.lb-stage { display: flex; align-items: center; justify-content: center; max-width: 58vw; max-height: 78vh; }
.lb-media { max-width: 58vw; max-height: 78vh; border-radius: 8px; display: block; background: #000; }
@media (max-width: 760px) {
  .lb-stage { max-width: 92vw; max-height: 50vh; }
  .lb-media { max-width: 92vw; max-height: 50vh; }
}

/* Toast */
#toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: #1a2b4a; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .25s; z-index: 200;
}
#toast.show { opacity: 1; }

/* 顶部导航 */
header.topbar .nav { display: flex; gap: 6px; }
header.topbar .nav button { padding: 6px 12px; }
header.topbar .nav button.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* 用户管理 */
#userview { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.utable { width: 100%; border-collapse: collapse; background: var(--panel); }
.utable th, .utable td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.utable th { color: var(--sub); font-weight: 600; background: #fafbfd; }
.utable tbody tr:hover td { background: #f8fafc; }
.utable .acts { white-space: nowrap; }
.utable .acts button { margin-right: 6px; padding: 4px 10px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.badge.green { background: #e6f6f0; color: var(--green); }
.badge.red { background: #fbeae8; color: var(--red); }

/* ---------- 响应式：手机 ---------- */
@media (max-width: 768px) {
  .menu-toggle { display: inline-block; }
  aside.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: .25s; width: 80vw; max-width: 300px;
    box-shadow: 0 0 30px rgba(0,0,0,.2);
  }
  body.sidebar-open aside.sidebar { transform: translateX(0); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .grid.size-large { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .grid.size-medium { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .grid.size-small { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .toolbar input.search { width: 130px; }
  .modal { width: 92vw; }
}

/* ---------- 属性字典管理 ---------- */
#dictview { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.dict-layout { flex: 1; display: flex; overflow: hidden; }
.dict-side {
  width: 240px; border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; overflow: auto; flex-shrink: 0;
}
.dict-side .sb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--sub);
}
.dict-side .tree { padding: 8px; }
.dict-side .tree-row .cnt { font-size: 11px; color: var(--sub); }
.dict-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.dict-main .toolbar { border-bottom: 1px solid var(--line); }
.dict-row-child td:first-child { padding-left: 28px; color: var(--sub); }

/* ---------- 编号规则管理 ---------- */
#ruleview { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.rule-tpl { font-family: Consolas, Monaco, monospace; font-size: 12px; color: var(--blue); }

/* ---------- 宽弹窗 / 宝石属性表单 ---------- */
.modal-wide { width: 680px; }
.attrs-block { margin: 12px 0; border-top: 1px dashed var(--line); padding-top: 12px; }
.attrs-title { font-size: 13px; color: var(--sub); margin-bottom: 8px; }
.gem-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.gem-form .gf-item label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 4px; }
.gem-form .gf-item input, .gem-form .gf-item select { width: 100%; }
/* 柜位三级级联：柜 → 第二级 → 第三级（同一行内紧凑排布） */
.cab-cascade { display: flex; gap: 4px; align-items: center; }
.cab-cascade select { flex: 1; min-width: 0; font-size: 13px; }
.cab-cascade select.cab-l1 { flex: 1.2; }
.cab-cascade select.cab-l3 { display: none; }
/* 可输入下拉框 combobox */
.combo { position: relative; }
.combo-input { width: 100%; box-sizing: border-box; }
.combo-pop {
  position: absolute; top: 100%; left: 0; right: 0; max-height: 220px; overflow-y: auto;
  background: #fff; border: 1px solid #c9d2dc; border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); z-index: 50; margin-top: 2px; text-align: left;
}
.combo-item { padding: 6px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-item:hover { background: #f0f5ff; }
.combo-empty { padding: 8px 10px; color: #95a0ad; font-size: 12px; }
.code-preview {
  margin-top: 10px; padding: 8px 12px; border-radius: 8px; background: #f0f6ff;
  border: 1px solid #d6e6fb; font-size: 13px; color: var(--blue);
  font-family: Consolas, Monaco, monospace;
}
.code-preview::before { content: "编号预览："; color: var(--sub); font-family: inherit; }
.ph-row { display: flex; gap: 8px; margin-top: 8px; }
.ph-row select { flex: 1; }
.ph-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ph-chip {
  padding: 3px 10px; border-radius: 20px; border: 1px solid var(--line); background: #f8fafc;
  font-size: 12px; color: var(--sub); cursor: pointer;
}
.ph-chip:hover { border-color: var(--blue); color: var(--blue); }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chk-row { display: flex; align-items: center; gap: 6px; }
.chk-row label { margin: 0 !important; }
.attr-img-name { font-size: 13px; color: var(--sub); word-break: break-all; }
/* 属性编辑：多媒体宝石的「保存将同步到同组」提示 */
.attr-sync-hint {
  margin: 2px 0 10px; padding: 8px 10px; font-size: 12px; line-height: 1.6;
  color: #8a5a00; background: #fdf6e3; border: 1px solid #f0e0b0; border-radius: 8px;
}

@media (max-width: 768px) {
  .dict-side { width: 180px; }
  .modal-wide { width: 92vw; }
  .gem-form { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 宝石分组（同宝石多图/视频） ---------- */
/* 卡片右上角分组标记：媒体数量 / 含视频 */
.card .group-badge {
  position: absolute; bottom: 6px; right: 6px; background: rgba(43,108,176,.92);
  color: #fff; font-size: 11px; line-height: 1; padding: 4px 7px; border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.card.is-group { border-color: #bcd3ec; box-shadow: 0 2px 10px rgba(43,108,176,.10); }
.card.is-group:hover { box-shadow: 0 6px 18px rgba(43,108,176,.20); }
/* 灯箱「设为封面图」按钮处于已指定状态时的高亮 */
.lb-bar button.active { background: #d69e2e; border-color: #b7791f; color: #fff; }

/* ---------- 合并到同宝石弹窗 ---------- */
.merge-search { display: flex; gap: 8px; }
.merge-search input { flex: 1; }
.merge-search button { flex: 0 0 auto; }
.merge-list { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; }
.merge-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.merge-row:last-child { border-bottom: none; }
.merge-row:hover { background: #f1f5f9; }
.merge-row input[type="checkbox"] { flex: 0 0 auto; width: 16px; height: 16px; }
.merge-thumb {
  width: 48px; height: 36px; object-fit: scale-down; border-radius: 6px;
  background: #f1f5f9; flex: 0 0 auto;
}
.merge-info { flex: 1; min-width: 0; }
.merge-info .fn { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-info .sub { font-size: 12px; color: var(--blue); }
