:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-bg: #eef2ff;
  --dark: #1e293b;
  --gray: #64748b;
  --light-gray: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12), 0 8px 32px rgba(0,0,0,.06);
}
* { margin:0; padding:0; box-sizing:border-box; }
html { overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--dark); min-height: 100vh;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
img { max-width: 100%; height: auto; }
input, textarea, select { max-width: 100%; box-sizing: border-box; }

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff; padding: 16px 32px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 12px rgba(79,70,229,.3);
  position: sticky; top: 0; z-index: 100;
}
.header .logo { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.header .logo a { color: inherit; text-decoration: none; }
.header .logo .icon { width: 36px; height: 36px; background: rgba(255,255,255,.2); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.header nav a { color: rgba(255,255,255,.85); text-decoration: none; margin-left: 24px; font-size: 14px; transition: color .2s; }
.header nav a:hover { color: #fff; }

/* Layout */
.container { max-width: 1400px; margin: 24px auto; padding: 0 24px; display: grid; grid-template-columns: 1fr 420px; gap: 24px; }

/* Card */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.card-title .dot { width: 8px; height: 8px; background: var(--primary); border-radius: 50%; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--gray); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--light-gray);
  border-radius: 8px; font-size: 14px; transition: border-color .2s; outline: none; font-family: inherit;
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }

/* Color */
.color-row { display: flex; gap: 12px; align-items: center; }
.color-item { flex: 1; display: flex; align-items: center; gap: 8px; }
.color-item label { font-size: 13px; color: var(--gray); white-space: nowrap; }
.color-input { width: 44px; height: 36px; border: 2px solid var(--light-gray); border-radius: 8px; cursor: pointer; padding: 2px; }

/* Range */
.range-wrap { display: flex; align-items: center; gap: 12px; }
.range-wrap input[type=range] { flex: 1; accent-color: var(--primary); }
.range-val { min-width: 44px; text-align: center; font-size: 13px; font-weight: 600; color: var(--primary); background: var(--primary-bg); padding: 4px 8px; border-radius: 6px; }

/* Radio group */
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-btn { padding: 8px 16px; border: 1.5px solid var(--light-gray); border-radius: 8px; cursor: pointer; font-size: 13px; transition: all .2s; background: #fff; user-select: none; }
.radio-btn:hover { border-color: var(--primary-light); }
.radio-btn.active { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); font-weight: 500; }

/* Preview */
.preview-panel { position: sticky; top: 90px; }
.preview-box {
  background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
  border-radius: var(--radius); padding: 32px; text-align: center;
  min-height: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--light-gray); transition: border-color .3s;
}
.preview-box:hover { border-color: var(--primary-light); }
.qr-canvas-wrap {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 16px;
  position: relative;
  max-width: 100%;
  box-sizing: border-box;
}
.qr-canvas-wrap canvas {
  display: block;
  border-radius: 8px;
  max-width: 100%;
  height: auto !important;
}
.placeholder-text { color: var(--gray); font-size: 14px; }
.placeholder-text .big-icon { font-size: 48px; margin-bottom: 12px; opacity: .3; }

/* Buttons */
.btn { padding: 10px 20px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; transition: all .2s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338ca; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,70,229,.35); }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-bg); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-group { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

/* Preset colors */
.preset-colors { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.preset-color { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--light-gray); transition: transform .15s; }
.preset-color:hover { transform: scale(1.15); }

/* Style presets */
.preset-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.preset-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background .15s;
  position: relative;
  min-width: 56px;
}
.preset-item:hover {
  background: var(--primary-bg);
}
.preset-swatch {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
  border: 2px solid #fff;
}
.preset-label {
  font-size: 11px;
  color: var(--gray);
  white-space: nowrap;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-del {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  line-height: 14px;
  text-align: center;
  display: none;
  cursor: pointer;
}
.preset-item:hover .preset-del {
  display: block;
}

/* Logo */
.logo-upload { display: flex; align-items: center; gap: 12px; }
.logo-drop {
  width: 72px; height: 72px; border: 2px dashed var(--light-gray); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 24px; color: var(--gray); overflow: hidden; transition: all .2s; position: relative;
}
.logo-drop:hover { border-color: var(--primary); color: var(--primary); }
.logo-drop.dragover { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }
.logo-drop img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.logo-drop .remove-logo {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  background: var(--danger); color: #fff; border-radius: 50%;
  display: none; align-items: center; justify-content: center; font-size: 12px; cursor: pointer;
}
.logo-drop.has-logo .remove-logo { display: flex; }

/* Batch */
.batch-area { width: 100%; min-height: 120px; border: 2px dashed var(--light-gray); border-radius: 10px; padding: 16px; font-size: 13px; resize: vertical; }
.batch-tips { font-size: 12px; color: var(--gray); margin-top: 6px; line-height: 1.6; }

/* Toast */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--dark); color: #fff; padding: 12px 24px; border-radius: 8px;
  font-size: 14px; z-index: 999; opacity: 0; transition: all .3s; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* History */
.history-list { max-height: 200px; overflow-y: auto; }
.history-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; cursor: pointer; transition: background .15s; font-size: 13px; }
.history-item:hover { background: var(--bg); }
.history-item .h-qr { width: 32px; height: 32px; border-radius: 4px; flex-shrink: 0; }
.history-item .h-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--gray); }
.history-item .h-time { font-size: 11px; color: #94a3b8; }

/* Switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.switch-row label { font-size: 13px; color: var(--gray); }
.switch { position: relative; width: 44px; height: 24px; background: var(--light-gray); border-radius: 12px; cursor: pointer; transition: background .2s; }
.switch.on { background: var(--primary); }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on::after { transform: translateX(20px); }

/* Download menu */
.dl-wrap { position: relative; display: inline-block; }
.dl-menu { display: none; position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); background: #fff; border-radius: 8px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 10; min-width: 140px; }
.dl-menu.show { display: block; }
.dl-menu button { display: block; width: 100%; padding: 8px 14px; border: none; background: transparent; text-align: left; cursor: pointer; border-radius: 6px; font-size: 13px; color: var(--dark); }
.dl-menu button:hover { background: var(--primary-bg); color: var(--primary); }

.error-banner { background: #fef2f2; border: 1.5px solid #fecaca; color: #991b1b; padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: none; }
.error-banner.show { display: block; }

/* Footer */
.footer {
  text-align: center;
  padding: 24px 16px 32px;
  color: var(--gray);
  font-size: 12px;
  opacity: 0.8;
}
.footer p { margin: 0; line-height: 1.6; }
.footer a:hover { text-decoration: underline !important; }

/* 移动端生成按钮 - 仅移动端显示 */
.mobile-generate-btn {
  display: none;
  width: 100%;
  justify-content: center;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 8px;
}

/* 全屏二维码预览 */
.qr-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.qr-fullscreen.show {
  display: flex;
}
.qr-fullscreen .fs-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.qr-fullscreen .fs-close:hover {
  background: rgba(255, 255, 255, 0.25);
}
.qr-fullscreen .fs-title {
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 20px;
  text-align: center;
  word-break: break-all;
  max-width: 90%;
  opacity: 0.9;
}
.qr-fullscreen .fs-canvas-wrap {
  background: #fff;
  padding: 12px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: min(80vw, 80vh);
  max-height: 75vh;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-fullscreen .fs-canvas-wrap canvas {
  display: block;
  max-width: 100% !important;
  max-height: calc(75vh - 24px) !important;
  width: auto !important;
  height: auto !important;
  border-radius: 8px;
}
.qr-fullscreen .fs-tip {
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  margin-top: 16px;
  text-align: center;
}
.qr-fullscreen .fs-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
  justify-content: center;
}
.qr-fullscreen .fs-actions .btn {
  padding: 12px 20px;
  font-size: 14px;
  min-width: 100px;
  justify-content: center;
}
.qr-fullscreen .fs-actions .btn-primary {
  background: #fff;
  color: var(--primary);
}
.qr-fullscreen .fs-actions .btn-primary:hover {
  background: #f1f5f9;
  color: var(--primary);
}
.qr-fullscreen .fs-actions .btn-outline {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}
.qr-fullscreen .fs-actions .btn-outline:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; padding: 0 12px; max-width: 100%; }
  .preview-panel { position: static; }
  .header { padding: 14px 16px; }
  .header nav { display: none; }
}

@media (max-width: 600px) {
  .container { margin: 12px auto; padding: 0 10px; }
  .card { padding: 16px; margin-bottom: 12px; max-width: 100%; }
  .card-title { font-size: 15px; margin-bottom: 12px; }
  .preview-box { min-height: 320px; padding: 16px; max-width: 100%; box-sizing: border-box; }
  .qr-canvas-wrap { padding: 10px; }
  .color-row { flex-wrap: wrap; }
  .color-item { min-width: 45%; }
  .mobile-generate-btn { display: inline-flex; }
  .qr-fullscreen .fs-actions .btn {
    flex: 1;
    min-width: 45%;
  }
  .header { padding: 12px 14px; }
  .header .logo { font-size: 18px; }
  .header .logo .icon { width: 30px; height: 30px; font-size: 16px; }
}

@media (max-width: 400px) {
  .container { padding: 0 8px; }
  .card { padding: 12px; }
  .radio-btn { padding: 6px 10px; font-size: 12px; }
  .form-textarea { min-height: 80px; }
  .preview-box { min-height: 260px; padding: 12px; }
  .qr-canvas-wrap { padding: 8px; border-radius: 8px; }
  .btn { padding: 8px 12px; font-size: 13px; }
  .mobile-generate-btn { padding: 12px 16px; font-size: 15px; }
}

/* ========== 标签打印 ========== */
.label-print-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
.label-print-modal.show { display: flex; }
.lp-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}
.lp-dialog {
  position: relative;
  background: #fff;
  border-radius: 12px;
  width: 95%;
  max-width: 900px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
  overflow: hidden;
}
.lp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--light-gray);
}
.lp-title { font-size: 16px; font-weight: 600; color: var(--dark); }
.lp-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--gray);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.lp-close:hover { background: var(--primary-bg); color: var(--dark); }

.lp-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--light-gray);
  flex-wrap: wrap;
  background: #fafafa;
}
.lp-tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lp-label { font-size: 13px; color: var(--gray); white-space: nowrap; }
.lp-tool-group select {
  padding: 6px 10px;
  border: 1px solid var(--light-gray);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}
.lp-radio-group {
  display: flex;
  border: 1px solid var(--light-gray);
  border-radius: 6px;
  overflow: hidden;
}
.lp-radio {
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  color: var(--gray);
  transition: all .15s;
}
.lp-radio.active {
  background: var(--primary);
  color: #fff;
}
.lp-radio:not(.active):hover { background: var(--primary-bg); }

.lp-info {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--gray);
  background: #f0f9ff;
  border-bottom: 1px solid #e0f2fe;
}

.lp-preview-wrap {
  flex: 1;
  overflow: auto;
  padding: 20px;
  background: #f5f5f5;
  display: flex;
  justify-content: center;
}
.lp-preview {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
  padding: 5mm;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 2mm;
  transform-origin: top center;
}
.lp-preview.landscape {
  width: 297mm;
  min-height: 210mm;
}
.lp-tag {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
  border: 0.5px dashed #ddd;
  position: relative;
}
.lp-tag canvas { display: block; }

/* 打印样式 */
@media print {
  body * { visibility: hidden; }
  .label-print-modal,
  .label-print-modal * { visibility: visible; }
  .label-print-modal {
    position: static;
    display: block;
  }
  .lp-overlay,
  .lp-header,
  .lp-toolbar,
  .lp-info,
  .lp-preview-wrap { display: none !important; }
  .lp-dialog {
    position: static;
    background: none;
    border-radius: 0;
    width: auto;
    max-width: none;
    max-height: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
  .lp-preview {
    display: flex !important;
    box-shadow: none;
    padding: 5mm;
    margin: 0 auto;
  }
  .lp-tag { border: none; }
  @page {
    size: A4 portrait;
    margin: 0;
  }
  @page :first { margin: 0; }
}

@media (max-width: 600px) {
  .lp-dialog { width: 100%; max-height: 100vh; border-radius: 0; }
  .lp-toolbar { padding: 10px 12px; gap: 10px; }
  .lp-header { padding: 12px 14px; }
  .lp-preview-wrap { padding: 10px; }
  .lp-info { padding: 6px 12px; }
}
