:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e4e6ea;
  --text: #1f2430;
  --text-dim: #6b7280;
  --accent: #ff6b35;
  --accent-dim: #ffe4d6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  height: 60px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.save-indicator { font-size: 12px; color: var(--text-dim); }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }

.steps {
  width: 220px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.step-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 500;
}
.step-btn .num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-dim);
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.step-btn:hover { background: var(--bg); }
.step-btn.active { background: var(--accent-dim); color: var(--accent); }
.step-btn.active .num { background: var(--accent); color: #fff; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 60px;
}

.step-panel { display: none; max-width: 900px; margin: 0 auto; }
.step-panel.active { display: block; }

.panel-head h2 { margin: 0 0 6px; font-size: 20px; }
.panel-head p { margin: 0 0 20px; color: var(--text-dim); font-size: 14px; line-height: 1.5; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card-title { margin: 0 0 12px; font-size: 15px; }

/* Step 1 form */
.form-card { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); flex: 1; }
.field span { font-weight: 600; color: var(--text); }
.field input[type=text], .field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}
.field input[type=color] { width: 60px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; }
.field-row { display: flex; gap: 20px; }

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #e85f2c; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.small.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.btn.large { padding: 14px 22px; font-size: 15px; }
.btn.danger { color: #d33; border-color: #f3c9c9; }
.btn.icon-btn { padding: 6px 8px; font-size: 13px; line-height: 1; }

.step-nav { display: flex; justify-content: space-between; margin-top: 20px; }

/* Step 2 templates */
.template-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.template-card {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, transform .1s;
}
.template-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.template-card .t-icon { font-size: 22px; margin-bottom: 6px; }
.template-card .t-label { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.template-card .t-desc { font-size: 11px; color: var(--text-dim); line-height: 1.4; }

.section-order-list { display: flex; flex-direction: column; gap: 8px; }
.order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg);
}
.order-item .oi-index { font-size: 12px; color: var(--text-dim); width: 20px; }
.order-item .oi-icon { font-size: 16px; }
.order-item .oi-label { flex: 1; font-size: 13px; font-weight: 600; }
.order-item .oi-actions { display: flex; gap: 4px; }

.empty-hint { color: var(--text-dim); font-size: 13px; text-align: center; padding: 10px 0; }
.hidden { display: none !important; }

/* Step 3 editors */
.editor-list { display: flex; flex-direction: column; gap: 14px; }
.editor-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.editor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  background: #fafafa;
}
.editor-head .oi-icon { font-size: 16px; }
.editor-head .oi-label { flex: 1; font-size: 14px; font-weight: 700; }
.editor-head .chev { transition: transform .15s; color: var(--text-dim); }
.editor-card.open .editor-head .chev { transform: rotate(90deg); }
.editor-body { padding: 16px; display: none; border-top: 1px solid var(--border); }
.editor-card.open .editor-body { display: block; }

.ef-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.ef-row label { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.ef-row input[type=text], .ef-row textarea, .ef-row input[type=url] {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit;
}
.ef-row textarea { resize: vertical; min-height: 60px; }

.img-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}
.img-upload img { width: 90px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: #eee; }
.img-upload .up-info { font-size: 11px; color: var(--text-dim); }

.subitem-list { display: flex; flex-direction: column; gap: 10px; }
.subitem {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
  position: relative;
  background: #fcfcfd;
}
.subitem .subitem-remove {
  position: absolute; top: 6px; right: 6px;
  border: none; background: none; color: var(--text-dim); cursor: pointer; font-size: 13px;
}
.add-subitem-btn { margin-top: 4px; }

/* Step 4 preview */
.preview-toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.preview-frame-wrap { display: flex; justify-content: center; background: #e9eaee; border-radius: var(--radius); padding: 24px; }
.preview-frame { border: none; background: #fff; box-shadow: var(--shadow); transition: width .2s; }
.preview-frame.mobile { width: 390px; height: 720px; }
.preview-frame.desktop { width: 900px; height: 720px; }

/* Step 5 export */
.export-card { display: flex; flex-direction: column; gap: 12px; }
.code-view { margin-top: 10px; }
.code-view-toolbar { display: flex; justify-content: flex-end; margin-bottom: 6px; }
#codeArea { width: 100%; height: 320px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; padding: 12px; border-radius: 8px; border: 1px solid var(--border); }

@media (max-width: 860px) {
  .template-grid { grid-template-columns: repeat(2, 1fr); }
}
