/* ================================================================
   Reset & Base
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  background: #f0f0f2;
  color: #111827;
}
body { overflow: hidden; }

/* ================================================================
   App Layout: toolbar (fixed height) + workspace (fill rest)
   ================================================================ */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================================================================
   Brand Bar (row 0)
   ================================================================ */
.tb-row-brand {
  height: 36px;
  background: #111827;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.brand-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  height: 20px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-name {
  font-size: 13px;
  font-weight: 600;
  color: #f9fafb;
  letter-spacing: 0.2px;
}

.brand-version {
  font-size: 10px;
  color: #6b7280;
  background: #374151;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 500;
}

.brand-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-support {
  font-size: 11px;
  color: #9ca3af;
}

.brand-email {
  font-size: 11px;
  color: #818cf8;
  text-decoration: none;
}
.brand-email:hover { color: #a5b4fc; text-decoration: underline; }

/* ================================================================
   Toolbar
   ================================================================ */
.toolbar {
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.tb-row {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tb-row::-webkit-scrollbar { display: none; }

.tb-row-global {
  height: 46px;
  border-bottom: 1px solid #f3f4f6;
}

.tb-row-props {
  height: 42px;
  background: #fafafa;
}

.tb-sep {
  width: 1px;
  height: 24px;
  background: #e5e7eb;
  margin: 0 8px;
  flex-shrink: 0;
}

/* Edit groups container — disabling is done via JS (opacity + pointer-events) */
.tb-edit-groups {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}


.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.tb-group-label {
  font-size: 11px;
  font-weight: 600;
  color: #9ca3af;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-right: 2px;
}

/* Toolbar buttons */
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s;
  outline: none;
  flex-shrink: 0;
}
.tb-btn svg { width: 12px; height: 12px; flex-shrink: 0; }
.tb-btn:hover { background: #f9fafb; border-color: #9ca3af; }
.tb-btn:active { background: #f3f4f6; }

.tb-btn-primary {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}
.tb-btn-primary:hover { background: #5254cc; border-color: #5254cc; }

.tb-btn-dark {
  background: #111827;
  border-color: #111827;
  color: #fff;
}
.tb-btn-dark svg { stroke: #fff; }
.tb-btn-dark:hover { background: #374151; border-color: #374151; }

.tb-btn-danger {
  border-color: #ef4444;
  color: #ef4444;
}
.tb-btn-danger:hover { background: #fef2f2; }

/* View switcher */
.tb-view-btn {
  height: 28px;
  padding: 0 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  outline: none;
  flex-shrink: 0;
}
.tb-view-btn.active {
  background: #111827;
  border-color: #111827;
  color: #fff;
}
.tb-view-btn:hover:not(.active) { background: #f9fafb; }

/* Field chips */
.field-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.field-chip {
  height: 26px;
  padding: 0 10px;
  border-radius: 13px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid #d1d5db;
  background: #fff;
  color: #374151;
  transition: all 0.12s;
  outline: none;
  white-space: nowrap;
}
.field-chip:hover { border-color: #6366f1; color: #6366f1; }
.field-chip.active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}

/* Props panels */
.props-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #9ca3af;
  padding: 0 4px;
  flex-shrink: 0;
}
.props-panel {
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
  flex-shrink: 0;
}
.props-panel.hidden { display: none !important; }

/* Range in toolbar */
.tb-range {
  width: 100px;
  height: 4px;
  cursor: pointer;
  accent-color: #6366f1;
  flex-shrink: 0;
}
.tb-range-val {
  font-size: 11px;
  color: #374151;
  min-width: 36px;
  font-weight: 500;
  flex-shrink: 0;
}

/* Small input in toolbar */
.tb-input-sm {
  height: 28px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0 8px;
  font-size: 12px;
  color: #111827;
  outline: none;
  background: #fff;
  flex-shrink: 0;
}
.tb-input-sm:focus { border-color: #6366f1; }

/* Select in toolbar */
.tb-select {
  height: 28px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0 8px;
  font-size: 12px;
  color: #111827;
  background: #fff;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
  max-width: 110px;
}
.tb-select:focus { border-color: #6366f1; }


.tb-input-sz {
  width: 52px;
  text-align: center;
  padding: 0 4px;
}

/* Number/text input companion (fallback, kept for reference) */
.tb-input-num {
  width: 48px;
  text-align: center;
  padding: 0 4px;
  -moz-appearance: textfield;
}
.tb-input-num::-webkit-outer-spin-button,
.tb-input-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Unit label next to inputs */
.tb-unit {
  font-size: 11px;
  color: #6b7280;
  flex-shrink: 0;
  margin-left: -2px;
}

/* Color in toolbar */
.tb-color {
  height: 28px;
  width: 44px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 2px 3px;
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
}

/* Style buttons B/I/U in toolbar */
.style-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #374151;
  transition: all 0.12s;
  outline: none;
  flex-shrink: 0;
}
.style-btn:hover { background: #f9fafb; }
.style-btn.active { background: #111827; color: #fff; border-color: #111827; }

/* ================================================================
   Workspace
   ================================================================ */
.workspace {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view-panel {
  display: none;
  width: 100%;
  height: 100%;
}
.view-panel.view-active { display: flex; flex-direction: column; }

/* ================================================================
   Design View
   ================================================================ */
.design-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #f0f0f2;
}

.design-canvas {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* ================================================================
   Preview Box (794 x 378 = 210mm x 100mm @ 96dpi)
   ================================================================ */
.preview-box {
  position: relative;
  width: 794px;
  height: 378px;
  background: #fff;
  border: 2px solid #d1d5db;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
}

.bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

/* ================================================================
   Layers
   ================================================================ */
.layer {
  position: absolute;
  cursor: move;
  user-select: none;
}
.layer.hidden { display: none !important; }

/* Selection highlight - thin dashed blue */
.layer.selected::before {
  content: '';
  position: absolute;
  inset: -3px;
  border: 1.5px dashed #6366f1;
  border-radius: 2px;
  pointer-events: none;
  z-index: 1000;
}

/* Multi-select highlight - amber dashed */
.layer.multi-selected::before {
  content: '';
  position: absolute;
  inset: -3px;
  border: 1.5px dashed #f59e0b;
  border-radius: 2px;
  pointer-events: none;
  z-index: 1000;
}

.text-layer .text-el {
  margin: 0;
  padding: 0;
  white-space: nowrap;
  line-height: 1.2;
  display: block;
  cursor: move;
}

.logo-layer { /* position set by JS */ }
.logo-img {
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #6366f1;
  border: 2px solid #fff;
  border-radius: 2px;
  bottom: -6px;
  right: -6px;
  cursor: nwse-resize;
  z-index: 1001;
  display: none;
}
.layer.selected .resize-handle { display: block; }

.layer-delete {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: none;
  z-index: 1002;
  padding: 0;
  outline: none;
}
.layer.selected .layer-delete { display: block; }

/* ================================================================
   Batch View
   ================================================================ */
.batch-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  gap: 10px;
  overflow: hidden;
}

.batch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}
.batch-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.batch-hint {
  font-size: 12px;
  color: #6b7280;
}

.batch-textarea {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.7;
  background: #fff;
}
.batch-textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }

.batch-progress { flex-shrink: 0; }
.progress-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: #6366f1;
  border-radius: 4px;
  transition: width 0.2s;
  width: 0;
}
.progress-text {
  font-size: 12px;
  color: #6b7280;
  margin-top: 6px;
}

/* ================================================================
   Utilities
   ================================================================ */
.hidden { display: none !important; }
.text-muted { color: #9ca3af; font-size: 12px; }

/* ================================================================
   Icon buttons in toolbar (SVG icon only, square)
   ================================================================ */
.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: #374151;
  transition: all 0.12s;
  outline: none;
  flex-shrink: 0;
  position: relative;
}
.icon-btn svg { width: 16px; height: 16px; display: block; }
.icon-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.icon-btn:active { background: #e5e7eb; }

/* Disabled state for undo/redo */
.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Tooltip for icon buttons */
.icon-btn::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  padding: 3px 7px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 9999;
}
.icon-btn:hover::after { opacity: 1; }

/* ================================================================
   Preview View
   ================================================================ */
.preview-view-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f0f0f2;
  position: relative;
}

.preview-view-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

.preview-canvas {
  box-shadow: 0 4px 24px rgba(0,0,0,0.2);
  border-radius: 2px;
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* Floating action bar: top-right corner of each view */
.view-action-bar {
  position: absolute;
  top: 10px;
  right: 14px;
  display: flex;
  gap: 6px;
  z-index: 20;
  align-items: center;
}

/* ================================================================
   Modal: Add Field Dialog
   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none !important; }

.modal-box {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 360px;
  padding: 0;
  overflow: hidden;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: #111827;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #f3f4f6;
}

.modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.modal-field label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
}
.modal-input {
  height: 36px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  color: #111827;
  outline: none;
  width: 100%;
  transition: border-color 0.12s;
  font-family: inherit;
}
.modal-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }

.modal-footer {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid #f3f4f6;
}

/* ================================================================
   Indigo button variant (image field)
   ================================================================ */
.tb-btn-indigo {
  background: #818cf8;
  border-color: #818cf8;
  color: #fff;
}
.tb-btn-indigo:hover { background: #6366f1; border-color: #6366f1; }

/* ================================================================
   Zoom Control Bar (inside design view)
   ================================================================ */
/* zoom-bar: 嵌在工具栏同行的内联缩放控件 */
.zoom-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
/* zoom-inline alias */
.zoom-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
/* 缩放控件与视图按钮之间的分隔线 */
.zoom-sep {
  color: #d1d5db;
  font-size: 16px;
  padding: 0 2px;
  user-select: none;
  line-height: 1;
}
.zoom-btn {
  width: 26px;
  height: 26px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #374151;
  transition: all 0.12s;
  outline: none;
  flex-shrink: 0;
}
.zoom-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.zoom-label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  min-width: 38px;
  text-align: center;
  flex-shrink: 0;
}

/* ================================================================
   Design view: scrollable when zoomed
   ================================================================ */
.design-wrap {
  overflow: auto !important;
}

/* ================================================================
   Image field layer
   ================================================================ */
.img-field-layer {
  /* position set by JS */
}
.img-field-inner {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}
.img-field-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  border: 1.5px dashed #d1d5db;
  border-radius: 4px;
  color: #9ca3af;
  font-size: 11px;
  pointer-events: none;
  flex-direction: column;
  gap: 4px;
}

/* ================================================================
   Batch image note
   ================================================================ */
.batch-img-note {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12px;
  color: #1d4ed8;
  flex-shrink: 0;
}
.batch-img-note.hidden { display: none !important; }
