/* ============================================================
   GLOBAL RESET & VARIABLES
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface2: #f8f9fc;
  --border: #e2e6ef;
  --primary: #5b6af5;
  --primary-dark: #4253e8;
  --primary-light: #eef0fe;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(91,106,245,.10);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.06);
}

/* ============================================================
   LAYOUT
   ============================================================ */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 0 0 60px;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  border-radius: 9px;
  display: grid;
  place-items: center;
}
.logo-icon svg { width: 20px; height: 20px; fill: white; }

header h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.5px; }
header h1 span { color: var(--primary); }

.header-badge {
  margin-left: auto;
  font-size: .72rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 40px 24px 0;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 28px;
  align-items: start;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .container { padding: 20px 12px 0; }
  header { padding: 14px 16px; }
  .card-body { padding: 14px; }
  /* 格式网格响应式 */
  .format-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}
@media (max-width: 600px) {
  .container { padding: 14px 10px 0; }
  .mode-tab { font-size: .76rem; padding: 8px 4px; }
  .format-grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 5px; }
}

.grid-left {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ============================================================
   CARD
   ============================================================ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: visible;          /* ← 关键：允许格式条等子元素溢出显示 */
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-header .icon {
  width: 28px; height: 28px;
  background: var(--primary-light);
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.card-header .icon svg {
  width: 15px; height: 15px;
  stroke: var(--primary);
  fill: none;
  stroke-width: 2;
}
.card-header h2 { font-size: .9rem; font-weight: 700; }

.card-body { padding: 20px; min-width: 0; overflow: hidden; }

/* ============================================================
   MODE TABS (主面板切换)
   ============================================================ */
.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: 10px;
  padding: 4px;
}
.mode-tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.mode-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.mode-tab:hover:not(.active) {
  color: var(--text);
  background: rgba(91,106,245,.05);
}

/* ============================================================
   MODE PANELS (面板容器)
   ============================================================ */
.mode-panel { display: none; overflow: hidden; max-width: 100%; }
.mode-panel.active { display: flex; flex-direction: column; gap: 22px; }

/* ============================================================
   FORMATS BAR (格式选择条：QR / 条码 / Data Matrix 通用)
   ============================================================ */
.formats-bar {
  display: block;
  overflow: hidden;
  max-width: 100%;
}
.formats-bar::-webkit-scrollbar { display: none; }

/* ============================================================
   FORMATS TAB (单个格式按钮)
   ============================================================ */
.formats-tab {
  padding: 8px 18px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all .18s;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
  letter-spacing: .2px;
}
.formats-tab:hover {
  color: var(--primary);
  background: rgba(91,106,245,.08);
}
.formats-tab.active {
  color: var(--primary);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(91,106,245,.18);
}

/* ============================================================
   BARCODE GROUP TABS (条码分组横向 Tab)
   ============================================================ */
.bc-tabs {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 5px;
  padding: 12px 20px;
  background: var(--surface2);
  scrollbar-width: none;
  min-width: 0;
  width: 100%;
}
.bc-tabs::-webkit-scrollbar { display: none; }

.bc-tab {
  padding: 8px 18px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all .18s;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
  letter-spacing: .2px;
}
.bc-tab:hover {
  color: var(--primary);
  background: rgba(91,106,245,.08);
}
.bc-tab.active {
  color: var(--primary);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(91,106,245,.18);
}

/* 条码分组内容区 */
.bc-content-body {
  padding: 14px 20px;
  border-top: 1.5px solid var(--border);
  width: 100%;               /* 占满父容器宽度 */
  min-width: 0;
  overflow: hidden;           /* 关键：隐藏超出部分 */
  max-width: 100%;           /* 限制最大宽度 */
}

/* ============================================================
   FORMAT GRID (格式按钮网格) - 修复溢出
   ============================================================ */
.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
  gap: 6px;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  box-sizing: border-box;
  padding: 4px;
}

/* ============================================================
   FORMAT BUTTON
   ============================================================ */
.format-btn {
  padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  flex-shrink: 1;
  min-width: 0;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
}
.format-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.format-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.format-btn .fname { font-size: .72rem; font-weight: 700; }
.format-btn .fdesc {
  font-size: .65rem;
  opacity: 0.7;
  line-height: 1.3;
}
.format-btn.active .fdesc { opacity: 0.85; }

.goto-btn { border-style: dashed; border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.goto-btn:hover { background: var(--primary); color: white; }

/* ============================================================
   CONTENT TABS (二维码内容类型)
   ============================================================ */
.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  min-width: 0;                  /* 防止撑出父容器 */
  width: 100%;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 4px 8px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface2);
  color: var(--text-muted);
  transition: all .18s;
  line-height: 1.2;
  text-align: center;
  min-width: 0;                  /* 允许收缩 */
  overflow: hidden;
}
.tab .tab-icon { font-size: 1.3rem; line-height: 1; flex-shrink: 0; }
.tab .tab-label { font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.tab.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(91,106,245,.15);
}
.tab-panel { display: none; min-width: 0; }
.tab-panel.active { display: block; }

/* 响应式：QR 内容 tab 断点 */
@media (max-width: 700px) {
  .tabs { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 520px) {
  .tabs { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 380px) {
  .tabs { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   FORM FIELDS
   ============================================================ */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.field input[type="text"],
.field input[type="url"],
.field input[type="email"],
.field textarea,
.field select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .88rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .2s;
  resize: vertical;
}
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--primary); }
.field textarea { min-height: 72px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.color-wrap { display: flex; align-items: center; gap: 10px; }
.color-wrap input[type="color"] {
  width: 40px; height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 2px;
}
.color-wrap input[type="text"] { flex: 1; }

.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.range-row .val {
  font-size: .82rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 42px;
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.toggle-row label { font-size: .85rem; font-weight: 500; }

.toggle { position: relative; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider-toggle {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--border);
  border-radius: 22px;
  transition: .2s;
}
.slider-toggle::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  bottom: 3px; left: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle input:checked + .slider-toggle { background: var(--primary); }
.toggle input:checked + .slider-toggle::before { transform: translateX(18px); }

/* ============================================================
   UPLOAD AREA
   ============================================================ */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}
.upload-area:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-area input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.upload-area p { font-size: .8rem; color: var(--text-muted); }
.upload-preview { max-height: 50px; max-width: 100%; border-radius: 5px; margin-top: 6px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-generate {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity .2s, transform .1s;
  box-shadow: 0 4px 16px rgba(91,106,245,.35);
  margin-top: 4px;
}
.btn-generate:hover { opacity: .92; }
.btn-generate:active { transform: scale(.98); }

/* ============================================================
   PREVIEW
   ============================================================ */
.preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px;
  background: linear-gradient(160deg, #f8f9ff 0%, #eef0fe 100%);
  min-height: 380px;
  justify-content: center;
}

.preview-canvas-container {
  position: relative;
  display: inline-block;
  overflow: visible;
}

/* QR */
#qr-canvas-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(91,106,245,.18);
  background: white;
  display: none;
  max-width: 100%;
  overflow: visible;
}
#qr-canvas-wrap.show { display: inline-block; max-width: 100%; overflow: visible; }
#qr-canvas-wrap canvas,
#qr-canvas-wrap svg {
  max-width: 400px;
  max-width: min(400px, 100%);
  height: auto;
  display: block;
}

#qr-logo-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#qr-logo-overlay.show { display: flex; }
#qr-logo-img {
  width: 22%; height: 22%;
  object-fit: contain;
  border-radius: 8px;
  background: white;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

/* Barcode */
#barcode-canvas-wrap {
  position: relative;
  border-radius: 10px;
  box-shadow: var(--shadow);
  background: white;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  display: none;
}
#barcode-canvas-wrap.show { display: block; max-width: 100%; overflow: hidden; }
#barcode-canvas {
  display: block;
  max-width: 400px;
  width: 100%;
  height: auto;
}

/* Data Matrix */
#data2d-canvas-wrap {
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(91,106,245,.18);
  background: white;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  display: none;
}
#data2d-canvas-wrap.show { display: inline-block; }
#data2d-canvas {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
}

.preview-label {
  margin-top: 12px;
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 260px;
  word-break: break-all;
}
.preview-meta {
  margin-top: 4px;
  font-size: .72rem;
  color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   DOWNLOAD
   ============================================================ */
.download-row { display: flex; gap: 8px; margin-top: 16px; width: 100%; }

.btn-dl {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--surface);
  color: var(--text);
  transition: all .2s;
}
.btn-dl:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.btn-dl.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-dl.primary:hover { background: var(--primary-dark); }

/* ============================================================
   FORMAT INFO
   ============================================================ */
.format-info {
  background: linear-gradient(135deg, var(--primary-light), #f0f1ff);
  border: 1px solid rgba(91,106,245,.2);
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 14px;
  font-size: .78rem;
}
.format-info .info-title { font-weight: 700; color: var(--primary); margin-bottom: 3px; }
.format-info .info-desc { color: var(--text-muted); line-height: 1.5; }
.format-info .info-example {
  font-family: 'Courier New', monospace;
  background: white;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 4px;
  display: inline-block;
  font-size: .75rem;
}

/* ============================================================
   SECTION DIVIDER
   ============================================================ */
.section-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 12px;
}
.section-divider span {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ============================================================
   PRESET BUTTONS
   ============================================================ */
.preset-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.preset-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: all .2s;
}
.preset-btn:hover,
.preset-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* ============================================================
   HISTORY
   ============================================================ */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}
.history-item {
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  transition: background .15s;
}
.history-item:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}
.hist-type {
  font-size: .68rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 1px 5px;
  border-radius: 10px;
  white-space: nowrap;
}
.hist-val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-empty { font-size: .8rem; color: var(--text-muted); text-align: center; padding: 12px 0; }

/* ============================================================
   INPUT HINT
   ============================================================ */
.input-hint { font-size: .72rem; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.input-hint.error { color: var(--danger); }

/* ============================================================
   TOAST
   ============================================================ */
#err-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1d2e;
  color: white;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 999;
  transition: transform .3s ease, opacity .3s ease;
  opacity: 0;
  pointer-events: none;
}
#err-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ============================================================
   RIGHT COLUMN (预览面板 sticky)
   ============================================================ */
.right-column {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.right-column .card {
  position: sticky;
  top: 78px;
}
