/* ============================================
   客户标签模版管理系统 - 样式表
   面向企业微信 H5，Mobile-First
   ============================================ */

:root {
  --primary: #1677ff;
  --primary-light: #e6f4ff;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ff4d4f;
  --text: #1f1f1f;
  --text-secondary: #666;
  --text-hint: #999;
  --bg: #f5f5f5;
  --bg-white: #fff;
  --border: #e8e8e8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ---- Header ---- */
.header {
  background: var(--bg-white);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-back {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none; font-size: 20px; cursor: pointer;
  color: var(--text);
}
.header-title {
  font-size: 17px; font-weight: 600;
  flex: 1;
}
.header-action {
  padding: 6px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.header-action.header-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* ---- Search Bar ---- */
.search-bar {
  padding: 12px 16px;
  background: var(--bg-white);
  position: sticky;
  top: 56px;
  z-index: 99;
  border-bottom: 1px solid var(--border);
}
.search-input-wrap {
  display: flex; align-items: center;
  background: var(--bg);
  border-radius: 20px;
  padding: 8px 14px;
  gap: 8px;
}
.search-input-wrap .icon { font-size: 16px; color: var(--text-hint); }
.search-input-wrap input {
  flex: 1; border: none; background: transparent;
  outline: none; font-size: 15px; color: var(--text);
}
.search-input-wrap input::placeholder { color: var(--text-hint); }
.search-input-wrap .clear-btn {
  width: 20px; height: 20px;
  border: none; background: var(--text-hint); color: #fff;
  border-radius: 50%; font-size: 12px; cursor: pointer;
  display: none;
}

/* ---- Templates List ---- */
.container {
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  padding-bottom: 80px;
}

.template-card {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex; gap: 12px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.template-card:active { transform: scale(0.98); box-shadow: var(--shadow-lg); }

.card-image {
  width: 80px; height: 80px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.card-body { flex: 1; min-width: 0; }
.card-customer {
  font-size: 16px; font-weight: 600;
  color: var(--text); margin-bottom: 2px;
}
.card-name {
  font-size: 13px; color: var(--text-secondary);
  margin-bottom: 6px;
}
.card-meta {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.card-tag {
  font-size: 12px; padding: 2px 8px;
  border-radius: 10px; background: var(--primary-light);
  color: var(--primary);
}
.card-tag.size { background: #f0f5ff; color: #2f54eb; }
.card-tag.ribbon { background: #fff7e6; color: #d46b08; }
.card-tag.inner { background: #e6fffb; color: #08979c; }
.card-tag.outer { background: #fff0f6; color: #c41d7f; }
.card-time {
  font-size: 12px; color: var(--text-hint);
  margin-top: 6px;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-hint);
}
.empty-state .emoji { font-size: 64px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ---- Detail Page ---- */
.detail-container {
  padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
.detail-images {
  display: flex; gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.detail-images {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px;
}
.detail-images .img-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer;
}
.detail-images .img-card img {
  width: 260px; height: 200px;
  object-fit: contain;
  border-radius: var(--radius-lg);
  background: var(--bg);
  border: 1px solid var(--border);
}
.detail-images .img-label {
  font-size: 12px; color: var(--text-hint);
  background: var(--bg); padding: 2px 10px; border-radius: 10px;
}

.info-section {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.info-section .section-title {
  font-size: 15px; font-weight: 600;
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.info-row {
  display: flex; padding: 6px 0; font-size: 14px;
}
.info-label {
  width: 80px; color: var(--text-hint); flex-shrink: 0;
}
.info-value { flex: 1; color: var(--text); }

.remarks-box {
  background: #fffbe6;
  border: 1px solid #ffe58f;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
  white-space: pre-line;
  color: #5c4600;
  line-height: 1.6;
}

/* ---- Form Page ---- */
.form-section-label {
  font-size: 15px; font-weight: 700;
  color: var(--text);
  padding: 8px 0 0 0;
  margin-top: 4px;
  border-bottom: 2px solid var(--primary);
}
.form-container {
  padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 14px; font-weight: 500; color: var(--text);
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px; outline: none; transition: border-color 0.2s;
  font-family: var(--font);
}
.form-input:focus { border-color: var(--primary); }
.form-textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px; outline: none; min-height: 100px;
  resize: vertical; font-family: var(--font);
}
.form-textarea:focus { border-color: var(--primary); }

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}
.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.img-delete-btn {
  margin-top: 4px;
  padding: 2px 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: #fff;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
}
.upload-area .upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-area .upload-text { font-size: 14px; color: var(--text-hint); }
.upload-area .upload-hint { font-size: 12px; color: var(--text-hint); margin-top: 4px; }
.upload-area img {
  max-width: 100%; max-height: 200px;
  border-radius: var(--radius);
  object-fit: contain;
}
.upload-area input[type="file"] {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
}

/* ---- Tab Navigation ---- */
.tab-nav {
  display: flex;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 99;
}
.tab-btn {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: none;
  font-size: 15px;
  color: var(--text-hint);
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  font-family: var(--font);
}
.tab-btn.active {
  color: var(--primary);
  font-weight: 600;
}
.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--primary);
  border-radius: 2px;
}
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ---- Checkbox Label ---- */
.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; color: var(--text); cursor: pointer;
  padding: 8px 0;
}
.checkbox-label input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer;
}

/* ---- Preset Chips ---- */
.preset-chips {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px;
}
.preset-chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  white-space: nowrap;
}
.preset-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.preset-chip.active {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.submit-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 12px 16px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  display: flex; gap: 12px;
  z-index: 100;
}
.btn {
  flex: 1; padding: 12px; border-radius: var(--radius);
  font-size: 16px; font-weight: 500; cursor: pointer;
  border: none; transition: opacity 0.2s;
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }

/* ---- Toast ---- */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 20px;
  font-size: 14px; color: #fff; z-index: 9999;
  animation: toastIn 0.3s ease;
  white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.success { background: #52c41a; }
.toast.error { background: #ff4d4f; }
.toast.info { background: #1677ff; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Image Viewer Modal ---- */
.image-viewer {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.image-viewer img {
  max-width: 95vw; max-height: 90vh;
  object-fit: contain;
}
.image-viewer .close-hint {
  position: absolute; top: 20px; right: 20px;
  color: #fff; font-size: 24px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
}

/* ---- Loading ---- */
.loading {
  text-align: center; padding: 40px; color: var(--text-hint);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Responsive (Desktop widen) ---- */
@media (min-width: 768px) {
  .container {
    max-width: 600px; margin: 0 auto;
  }
  .detail-container {
    max-width: 600px; margin: 0 auto;
  }
  .form-container {
    max-width: 600px; margin: 0 auto;
  }
  .submit-bar {
    max-width: 600px; left: 50%; transform: translateX(-50%);
  }
}
