* { box-sizing: border-box; }
:root {
  --red: #b0242a;
  --red-dark: #8f1d22;
  --gold: #c19a3d;
  --gold-dark: #a9852c;
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #2b2f36;
  --muted: #6b7280;
  --faint: #9aa0a6;
  --line: #e9ebef;
  --line-soft: #f1f3f5;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.05);
}
body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* 顶栏 */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 100;
}
.brand { font-size: 18px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 9px; }
.brand::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: var(--red); box-shadow: 0 0 0 4px rgba(176,36,42,.12);
}
.btn-link {
  text-decoration: none; font-size: 13px; color: var(--muted);
  border: 1px solid var(--line); padding: 6px 14px; border-radius: 8px;
  transition: all .2s;
}
.btn-link:hover { color: var(--red); border-color: var(--red); }

.banner {
  margin: 16px 28px 0; padding: 12px 16px; background: #fff7e6;
  border: 1px solid #ffe2a8; border-radius: 10px; color: #8a5a00; font-size: 14px;
}
.banner a { color: var(--red); font-weight: 600; }

.layout {
  display: flex; gap: 24px; padding: 24px 28px; align-items: flex-start;
}
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; box-shadow: var(--shadow);
}
.panel h2 {
  margin: 0 0 18px; font-size: 16px; color: var(--ink);
  border-left: 4px solid var(--gold); padding-left: 10px;
}

/* 模板管理 */
.tpl-panel { margin: 24px 28px 0; }
.tpl-head {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.tpl-head h2 { margin: 0; }
.tpl-toggle { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; transition: transform .3s ease; }
.tpl-toggle::before {
  content: ""; width: 9px; height: 9px;
  border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint);
  transform: rotate(45deg) translate(-2px, -2px);
}
.tpl-panel.collapsed .tpl-toggle { transform: rotate(180deg); }
.tpl-body { margin-top: 16px; }
.tpl-panel.collapsed .tpl-body { display: none; }

.tpl-hint { margin: 0 0 16px; font-size: 12px; color: var(--faint); line-height: 1.6; }
.tpl-toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px;
}
.tpl-toolbar label { font-size: 13px; color: var(--muted); }
.tpl-toolbar select {
  padding: 8px 12px; font-size: 14px; border: 1px solid var(--line);
  border-radius: 10px; outline: none; min-width: 200px; background: #fff; color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
.tpl-toolbar select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(193,154,61,.12); }
.chk { display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; font-size: 13px; color: var(--muted); }
.chk input { accent-color: var(--red); }
.tpl-msg { font-size: 13px; color: #27ae60; margin-left: auto; }
.tpl-msg.dirty { color: #e67e22; }
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.tpl-grid .field { margin-bottom: 0; }
.field-full { grid-column: 1 / -1; }

/* 字段编辑器 */
.fields-editor-head {
  display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px;
}
.fe-title { font-size: 13px; color: var(--muted); }
.fields-editor { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.field-row {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft); background: #fafbfc;
  transition: background .15s;
}
.field-row:hover { background: #fff; }
.field-row:last-child { border-bottom: none; }
.field-row input[type=text] {
  padding: 7px 10px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; outline: none;
  transition: border-color .2s;
}
.field-row input[type=text]:focus { border-color: var(--gold); }
.field-row .f-label { flex: 1; }
.field-row .f-value { width: 200px; }
.f-show { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.f-show input { margin: 0; accent-color: var(--red); }
.f-up, .f-down, .f-del {
  width: 28px; height: 28px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1;
  transition: all .15s;
}
.f-up:hover, .f-down:hover { border-color: var(--gold); color: var(--gold-dark); }
.f-del { color: #c0392b; }
.f-del:disabled { color: #ccc; cursor: not-allowed; }
.f-value-placeholder { width: 200px; font-size: 12px; color: var(--faint); text-align: center; }

.form-panel { width: 380px; flex-shrink: 0; }
.preview-panel { flex: 1; }
.records-panel { margin: 0 28px 40px; }

.form-hint { margin: -8px 0 16px; font-size: 12px; color: var(--faint); line-height: 1.6; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field .req { color: #c0392b; }
.field input[type=text], .field input[type=date], .field select, .field textarea {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { min-height: 120px; resize: vertical; font-family: inherit; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--gold); box-shadow: 0 0 0 3px rgba(193,154,61,.12);
}
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.inline-qty { display: flex; gap: 8px; }
.inline-qty input { flex: 1; }
.inline-qty select { flex: 0 0 auto; width: 72px; padding: 0 6px; }

.mini {
  white-space: nowrap; font-size: 12px; color: var(--muted); height: 34px; line-height: 32px;
  border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 0 12px; cursor: pointer;
  transition: all .2s;
}
.mini:hover { border-color: var(--gold); color: var(--gold-dark); }
.mini.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.mini.primary:hover { background: var(--gold-dark); border-color: var(--gold-dark); color: #fff; }
.mini.danger { color: #c0392b; }
.mini.danger:hover { border-color: #c0392b; color: #c0392b; }

.actions { display: flex; gap: 12px; margin-top: 20px; }
.btn {
  flex: 1; padding: 11px 14px; font-size: 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  transition: all .2s;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.result { margin-top: 12px; font-size: 14px; color: #27ae60; }
.result a { color: var(--red); }

.preview-wrap { display: flex; justify-content: center; background: #fafbfc; border-radius: 12px; padding: 16px; }
#preview { width: 340px; height: auto; border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.14); }

.records { width: 100%; border-collapse: collapse; font-size: 13px; }
.records th, .records td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.records th { background: #fafbfc; color: var(--muted); font-weight: 600; }
.records tbody tr { transition: background .15s; }
.records tbody tr:hover { background: #fafbfc; }
.records tbody tr:nth-child(even) { background: #fcfcfd; }
.thumb { width: 56px; height: 74px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; }
.ops a { color: var(--red); margin-right: 8px; text-decoration: none; }
.ops a.del { color: var(--faint); }
.ops a:hover { text-decoration: underline; }
.empty { text-align: center; color: var(--faint); padding: 24px !important; }

.f-tag { flex: 0 0 auto; font-size: 11px; color: var(--faint); border: 1px solid #e0e0e0; border-radius: 4px; padding: 2px 6px; background: #fff; white-space: nowrap; }
.f-tag.custom { color: var(--red); border-color: #f0c6c7; background: #fdf1f1; }

/* 自定义弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal-mask.show { display: flex; }
.modal-box {
  width: 360px; max-width: 90vw; background: #fff; border-radius: 16px;
  padding: 24px; box-shadow: 0 24px 64px rgba(0,0,0,.2);
  animation: modal-pop .2s ease;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 12px; }
.modal-text { font-size: 14px; color: var(--muted); line-height: 1.7; margin-bottom: 24px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; }
.modal-actions .btn { flex: 0 0 auto; min-width: 88px; }
@keyframes modal-pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Toast */
.toast-box {
  position: fixed; right: 24px; bottom: 24px; z-index: 1100;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  min-width: 220px; max-width: 320px; padding: 12px 16px; border-radius: 10px;
  background: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.12); font-size: 13px; color: var(--ink);
  border-left: 3px solid var(--gold); opacity: 0; transform: translateY(10px); transition: all .3s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left-color: #27ae60; }
.toast.warn { border-left-color: #e67e22; }
.toast.error { border-left-color: #c0392b; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .form-panel { width: 100%; }
  .tpl-grid { grid-template-columns: 1fr; }
  .field-row { flex-wrap: wrap; }
  .field-row .f-value, .f-value-placeholder { width: 100%; }
  #preview { width: 260px; }
}
