/* =========================
   QQ Bracelet Designer - FINAL CLEAN CSS
   可直接完整替换 app.css
   兼容当前 PHP / JS 结构
   ========================= */

/* =========================
   Base reset
   ========================= */
.qqbd [hidden] {
  display: none !important;
}

.qqbd,
.qqbd * {
  box-sizing: border-box;
}

.qqbd button,
.qqbd input,
.qqbd textarea {
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.qqbd img {
  -webkit-user-drag: none;
  user-drag: none;
}

/* =========================
   Root
   ========================= */
.qqbd {
  --qqbd-h: 760px;

  --bg: #ffffff;
  --line: #eef0f3;
  --text: #111827;
  --muted: #6b7280;
  --primary: #ef4444;
  --primary2: #111827;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.08);

  --qqbd-thumb: 46px;

  width: min(420px, 100%);
  height: var(--qqbd-h);
  margin: 0 auto;

  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  position: relative;

  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Microsoft Yahei", Arial, sans-serif;

  display: flex;
  flex-direction: column;
  color: var(--text);
}

/* =========================
   Stage
   ========================= */
.qqbd-stagewrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 260px;
  min-width: 0;
  background: #fff;
  overflow: hidden;
}

#qqbd-stage,
[id^="qqbd-stage"],
.qqbd-stage {
  width: 100%;
  height: 100%;
}

/* watermark */
.qqbd-watermark {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: rgba(17, 24, 39, 0.2);
  z-index: 2;
  pointer-events: none;
}

.qqbd-wm-title {
  font-weight: 700;
  font-size: 14px;
}

.qqbd-wm-sub {
  font-size: 11px;
  margin-top: 4px;
}

/* =========================
   Top strip
   ========================= */
.qqbd-strip {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  z-index: 5;

  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;

  pointer-events: none;
  flex-wrap: nowrap;
}

.qqbd-strip > * {
  pointer-events: auto;
}

.qqbd-badge {
  flex: 0 0 auto;
  white-space: nowrap;

  background: #ffe4e6;
  color: #be123c;
  border: 1px solid #fecdd3;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.qqbd-strip-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
  flex-wrap: nowrap;
}

.qqbd-chip {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(229, 231, 235, 0.95);
  color: #374151;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  white-space: nowrap;
}

.qqbd-chip[data-qqbd-size],
.qqbd-chip[data-qqbd-price] {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================
   Actions
   ========================= */
.qqbd-actions {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;

  padding: 10px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex: 0 0 auto;
}

.qqbd-btn {
  height: 40px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #fff;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.qqbd-btn-ghost {
  width: 52px;
}

.qqbd-btn-primary {
  flex: 1;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.qqbd-btn-primary2 {
  flex: 1.2;
  background: var(--primary2);
  border-color: var(--primary2);
  color: #fff;
}

/* =========================
   Panel
   ========================= */
.qqbd-panel {
  height: 300px;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 0 0 auto;
}

/* 隐藏“已选中” */
.qqbd-pill[data-qqbd-using] {
  display: none !important;
}

/* panel top 只留搜索 */
.qqbd-panel-top {
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.qqbd-search,
.qqbd-panel-top .qqbd-search {
  width: 100%;
  min-width: 0;
  height: 34px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  padding: 0 12px;
  outline: none;
  font-size: 12px;
  background: #fff;
}

.qqbd-panel-body {
  display: grid;
  grid-template-columns: 96px 1fr;
  flex: 1 1 auto;
  min-height: 0;
}

/* =========================
   Left rail (tabs + categories)
   ========================= */
.qqbd-cats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 6px;
  border-right: 1px solid var(--line);
  background: #fafafa;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* JS 当前会生成 class="qqbd-tabs qqbd-tabs-rail" */
.qqbd-tabs {
  position: sticky;
  top: 0;
  z-index: 5;

  display: flex;
  gap: 6px;
  padding: 6px;
  margin: 0;

  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}

.qqbd-tabs-rail .qqbd-tab,
.qqbd-tabs .qqbd-tab {
  flex: 1 1 0;
  height: 34px;

  border: 1px solid transparent;
  border-radius: 10px;
  background: #f9fafb;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 0;
  cursor: pointer;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.12s ease;
  box-shadow: none;
}

.qqbd-tabs-rail .qqbd-tab:hover,
.qqbd-tabs .qqbd-tab:hover {
  transform: none;
  background: #fff;
  border-color: #e5e7eb;
}

.qqbd-tabs-rail .qqbd-tab.is-active,
.qqbd-tabs .qqbd-tab.is-active {
  background: #fff1f2;
  border-color: #fecdd3;
  box-shadow: none;
}

.qqbd-tabs-rail .qqbd-tab img,
.qqbd-tabs .qqbd-tab img {
  width: 15px;
  height: 15px;
  display: block;
  object-fit: contain;
  margin: 0 auto;
  opacity: 0.85;
}

.qqbd-tabs-rail .qqbd-tab.is-active img,
.qqbd-tabs .qqbd-tab.is-active img {
  opacity: 1;
}

.qqbd-catslist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 4px;
}

.qqbd-cat {
  width: 100%;
  text-align: center;
  border: 1px solid transparent;
  background: transparent;
  padding: 10px 6px;
  border-radius: 12px;
  cursor: pointer;
  color: #111827;
  font-size: 13px !important;
  line-height: 1.15;
  white-space: normal;
  word-break: break-word;
}

.qqbd-cat:hover {
  background: #fff;
}

.qqbd-cat.is-active {
  background: #fff1f2;
  color: #be123c;
  border-color: #fecdd3;
}

/* =========================
   Grid + cards
   ========================= */
.qqbd-grid {
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  align-content: start;
  align-items: start;
  grid-auto-rows: min-content;

  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.qqbd-card {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 10px 8px;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.05);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
  min-width: 0;
}

.qqbd-card:hover {
  transform: translateY(-1px);
}

.qqbd-beadimg {
  width: min(var(--qqbd-thumb), 100%);
  aspect-ratio: 1 / 1;
  height: auto;
  margin: 0 auto 6px;
  overflow: hidden;

  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: radial-gradient(circle at 30% 30%, #fff, #cfd3da 55%, #9aa3af);

  display: flex;
  align-items: center;
  justify-content: center;
}

.qqbd-beadimg img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
  border-radius: inherit;
  pointer-events: none;
}

.qqbd-card[data-type="spacer"] .qqbd-beadimg,
.qqbd-card[data-type="runring"] .qqbd-beadimg,
.qqbd-card[data-type="irregular"] .qqbd-beadimg {
  border-radius: 12px;
  border: 0;
  background: #fff;
}

.qqbd-card[data-type="spacer"] .qqbd-beadimg img,
.qqbd-card[data-type="runring"] .qqbd-beadimg img,
.qqbd-card[data-type="irregular"] .qqbd-beadimg img {
  border-radius: 12px;
  object-fit: contain;
}

.qqbd-beadimg:has(img) {
  border: 0 !important;
  background: transparent !important;
}

.qqbd-cardname {
  font-size: 12px;
  text-align: center;
  color: #111827;
  line-height: 1.2;
  min-height: 28px;
  min-width: 0;
}

.qqbd-cardmeta {
  font-size: 11px;
  text-align: center;
  color: #6b7280;
  margin-top: 6px;
}

/* =========================
   Panel foot
   ========================= */
.qqbd-panel-foot {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  flex: 0 0 auto;
}

.qqbd-tip {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.2;
}

/* =========================
   Modal
   ========================= */
.qqbd-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 50;
}

.qqbd-modal-card {
  width: min(520px, 96%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.qqbd-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
}

.qqbd-modal-title {
  font-weight: 700;
}

.qqbd-modal-body {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.qqbd-modal-foot {
  padding: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.qqbd-preview {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.qqbd-json {
  width: 100%;
  height: 160px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  padding: 10px;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 11px;
}

/* =========================
   Toast
   ========================= */
.qqbd-toast {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;

  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px;

  font-size: 13px;
  font-weight: 600;
  line-height: 1;

  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  white-space: nowrap;
}

.qqbd-toast.is-warn {
  background: #ef4444;
}

/* =========================
   Interaction fixes
   ========================= */
.qqbd-stagewrap,
.qqbd-stagewrap canvas,
.qqbd-stagewrap .konvajs-content {
  touch-action: none;
}

.qqbd-stagewrap {
  -webkit-tap-highlight-color: transparent;
}

.qqbd-stagewrap,
.qqbd-actions,
.qqbd-panel,
.qqbd-card,
.qqbd-cat {
  user-select: none;
  -webkit-user-select: none;
}

/* =========================
   Small generic screen
   ========================= */
@media (max-width: 480px) {
  .qqbd-strip {
    left: 10px;
    right: 10px;
    top: 10px;
    gap: 6px;
  }

  .qqbd-badge,
  .qqbd-chip {
    padding: 5px 8px;
    font-size: 11px;
  }

  .qqbd-strip-right {
    gap: 6px;
  }
}

/* =========================
   Desktop
   ========================= */
@media (min-width: 1024px) {
  .qqbd {
    width: min(1200px, 100%);
    height: min(860px, 90vh);
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    grid-template-rows: 1fr auto;
    border-radius: 22px;
    --qqbd-thumb: clamp(40px, 4vw, 54px);
  }

  .qqbd-stagewrap {
    grid-column: 1;
    grid-row: 1 / span 2;
    min-height: 0;
    border-right: 1px solid var(--line);
  }

  .qqbd-panel {
    grid-column: 2;
    grid-row: 1;
    height: 100%;
  }

  .qqbd-actions {
    grid-column: 2;
    grid-row: 2;
    border-top: 1px solid var(--line);
    border-bottom: 0;
  }

  .qqbd-panel-body {
    grid-template-columns: 112px 1fr;
  }

  .qqbd-cats {
    padding: 10px 8px;
  }

  .qqbd-cat {
    font-size: 13px !important;
    padding: 11px 6px;
  }

  .qqbd-chip[data-qqbd-size] {
    max-width: 160px;
  }

  .qqbd-chip[data-qqbd-price] {
    max-width: 180px;
  }
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 767px) {
  .qqbd {
    --qqbd-thumb: 34px;
  }

  /* top strip */
  .qqbd-strip {
    left: 10px;
    right: 10px;
    top: 10px;
    gap: 6px;
  }

  .qqbd-badge {
    padding: 6px 10px;
    font-size: 12px;
  }

  .qqbd-strip-right {
    gap: 6px;
  }

  .qqbd-chip {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* action buttons */
  .qqbd-actions {
    height: auto;
    min-height: 0;
    padding: 4px 6px;
    gap: 4px;
    align-items: center;
  }

  .qqbd-btn {
    height: 26px;
    min-height: 26px;
    line-height: 26px;
    padding: 0 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    box-shadow: none;
  }

  .qqbd-btn-ghost {
    flex: 0 0 28px;
    width: 28px;
    min-width: 28px;
    max-width: 28px;
    padding: 0;
    font-size: 12px;
  }

  .qqbd-btn-primary {
    flex: 0 0 auto;
    min-width: 54px;
    padding: 0 8px;
  }

  .qqbd-btn-primary2 {
    flex: 0 0 auto;
    min-width: 78px;
    padding: 0 10px;
    margin-left: auto;
  }

  /* make stage area visually larger by shrinking lower area */
  .qqbd-panel {
    height: 228px;
  }

  .qqbd-panel-top {
    padding: 4px 6px;
  }

  .qqbd-panel-top .qqbd-search {
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
  }

  .qqbd-panel-body {
    grid-template-columns: 50px 1fr;
  }

  /* left rail tighter */
  .qqbd-cats {
    gap: 2px;
    padding: 2px;
  }

  .qqbd-tabs {
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    box-shadow: none;
  }

  .qqbd-tabs-rail .qqbd-tab,
  .qqbd-tabs .qqbd-tab {
    height: 20px;
    min-height: 20px;
    border-radius: 6px;
  }

  .qqbd-tabs-rail .qqbd-tab img,
  .qqbd-tabs .qqbd-tab img {
    width: 10px;
    height: 10px;
  }

  .qqbd-catslist {
    gap: 2px;
    padding-bottom: 0;
  }

  .qqbd-cat {
    padding: 4px 0;
    border-radius: 6px;
    font-size: 10px !important;
    line-height: 1;
    min-height: 20px;
  }

  .qqbd-cat.is-active {
    padding: 4px 0;
  }

  /* right side 3 columns */
  .qqbd-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 5px;
  }

  .qqbd-card {
    padding: 5px 3px;
    border-radius: 10px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.04);
  }

  .qqbd-beadimg {
    width: min(var(--qqbd-thumb), 100%);
    margin: 0 auto 4px;
  }

  .qqbd-card[data-type="spacer"] .qqbd-beadimg,
  .qqbd-card[data-type="runring"] .qqbd-beadimg,
  .qqbd-card[data-type="irregular"] .qqbd-beadimg {
    border-radius: 8px;
  }

  .qqbd-card[data-type="spacer"] .qqbd-beadimg img,
  .qqbd-card[data-type="runring"] .qqbd-beadimg img,
  .qqbd-card[data-type="irregular"] .qqbd-beadimg img {
    border-radius: 8px;
  }

  .qqbd-cardname {
    font-size: 10px;
    line-height: 1.1;
    min-height: 20px;
  }

  .qqbd-cardmeta {
    margin-top: 2px;
    font-size: 9px;
    line-height: 1.05;
  }

  .qqbd-panel-foot {
    padding: 4px 6px;
  }

  .qqbd-tip {
    font-size: 10px;
    line-height: 1.1;
  }
}
/* 搜索时：左侧分类区淡化，不显示当前高亮 */
.qqbd-cats.is-searching .qqbd-cat {
  opacity: 0.55;
}

.qqbd-cats.is-searching .qqbd-cat.is-active {
  opacity: 0.55;
  background: transparent;
  color: #111827;
  border-color: transparent;
}

.qqbd-cats.is-searching .qqbd-tabs,
.qqbd-cats.is-searching .qqbd-tabs-rail {
  opacity: 0.7;
}
/* =========================
   panel-top 内联布局
   按钮和搜索框同一行
   ========================= */
.qqbd-panel-top.qqbd-panel-top-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.qqbd-panel-top.qqbd-panel-top-inline .qqbd-actions.qqbd-actions-inline {
  flex: 0 0 auto;
  width: auto;
  height: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

.qqbd-panel-top.qqbd-panel-top-inline .qqbd-search {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}

/* 让按钮不要继承原来那种独立横条的表现 */
.qqbd-actions.qqbd-actions-inline .qqbd-btn-primary2 {
  margin-left: 0;
}

/* 手机端 */
@media (max-width: 767px) {
  .qqbd-panel-top.qqbd-panel-top-inline {
    gap: 6px;
    padding: 4px 6px;
  }

  .qqbd-panel-top.qqbd-panel-top-inline .qqbd-actions.qqbd-actions-inline {
    gap: 4px;
  }

  .qqbd-panel-top.qqbd-panel-top-inline .qqbd-search {
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
    border-radius: 999px;
  }

  .qqbd-actions.qqbd-actions-inline .qqbd-btn {
    height: 26px;
    min-height: 26px;
    line-height: 26px;
    padding: 0 8px;
    border-radius: 8px;
    font-size: 11px;
    box-shadow: none;
  }

  .qqbd-actions.qqbd-actions-inline .qqbd-btn-ghost {
    flex: 0 0 28px;
    width: 28px;
    min-width: 28px;
    max-width: 28px;
    padding: 0;
    font-size: 12px;
  }

  .qqbd-actions.qqbd-actions-inline .qqbd-btn-primary {
    flex: 0 0 auto;
    min-width: 54px;
    padding: 0 8px;
  }

  .qqbd-actions.qqbd-actions-inline .qqbd-btn-primary2 {
    flex: 0 0 auto;
    min-width: 78px;
    padding: 0 10px;
  }
}
@media (min-width: 1024px) {
  .qqbd-actions.qqbd-actions-inline .qqbd-btn,
  .qqbd-panel-top.qqbd-panel-top-inline .qqbd-btn {
    white-space: nowrap;
    word-break: keep-all;
    flex-shrink: 0;
  }

  .qqbd-actions.qqbd-actions-inline .qqbd-btn-primary,
  .qqbd-panel-top.qqbd-panel-top-inline .qqbd-btn-primary {
    min-width: 68px;
  }

  .qqbd-actions.qqbd-actions-inline .qqbd-btn-primary2,
  .qqbd-panel-top.qqbd-panel-top-inline .qqbd-btn-primary2 {
    min-width: 96px;
    padding: 0 16px;
  }
}