/* =====================================================================
   反推工坊 — 样式
   设计方向：温暖纸感底色 + 墨色文字 + 陶土色强调，克制、留白、编辑感
   ===================================================================== */

:root {
  --paper: #f6f2ea;
  --paper-2: #fffdf9;
  --paper-3: #efe9de;
  --ink: #23201c;
  --ink-2: #4a453d;
  --ink-3: #7c756a;
  --line: #ddd5c7;
  --line-soft: #e8e1d5;
  --accent: #b4553a;
  --accent-soft: #f3e3dc;
  --accent-ink: #8e3f27;
  --sage: #6f7f68;
  --sage-soft: #e6ebe2;
  --gold: #a8843f;
  --danger: #a3352b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(35, 32, 28, 0.05), 0 2px 8px rgba(35, 32, 28, 0.04);
  --shadow-md: 0 2px 6px rgba(35, 32, 28, 0.06), 0 12px 32px rgba(35, 32, 28, 0.07);
  --font: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-en: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, #fffdf8 0%, rgba(255, 253, 248, 0) 60%),
    radial-gradient(900px 500px at 100% 0%, #f2ece0 0%, rgba(242, 236, 224, 0) 55%),
    var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -0.01em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--paper-3); padding: 0.1em 0.35em; border-radius: 5px; }

/* ---------------------------------------------------------------- 布局 */

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(246, 242, 234, 0.86);
  backdrop-filter: saturate(1.2) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  background: conic-gradient(from 210deg, var(--accent), var(--gold), var(--sage), var(--accent));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5), var(--shadow-sm);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px; border-radius: 50%;
  background: var(--paper-2); box-shadow: inset 0 0 0 1px rgba(35,32,28,0.08);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: 0.02em; }
.brand-text span { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 4px; padding: 3px; background: var(--paper-3); border-radius: 999px; }
.tab {
  border: 0; background: transparent; padding: 6px 18px; border-radius: 999px;
  cursor: pointer; color: var(--ink-2); font-size: 13px; transition: all .18s ease;
}
.tab:hover { color: var(--ink); }
.tab.is-active { background: var(--paper-2); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }

.topbar-meta { display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-size: 12px; color: var(--ink-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); box-shadow: 0 0 0 3px rgba(0,0,0,0.03); }
.dot.ok { background: #5d8a4e; }
.dot.err { background: var(--danger); }

main { flex: 1; width: 100%; max-width: 1380px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 48px) 80px; }

.view { display: none; animation: fade-up .28s ease both; }
.view.is-active { display: block; }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.is-hidden { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- 步骤条 */

.steps { display: flex; gap: 8px; margin: 4px 0 20px; padding: 0; list-style: none; flex-wrap: wrap; }
.step {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 16px 8px 10px; border-radius: 999px;
  font-size: 13px; color: var(--ink-3); background: transparent;
  border: 1px solid transparent; transition: all .2s ease;
}
.step span {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600; background: var(--paper-3); color: var(--ink-3);
}
.step.is-active { background: var(--paper-2); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow-sm); font-weight: 600; }
.step.is-active span { background: var(--accent); color: #fff; }
.step.is-done { color: var(--ink-2); }
.step.is-done span { background: var(--sage-soft); color: var(--sage); }

/* ---------------------------------------------------------------- 面板 */

.panel {
  background: var(--paper-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: clamp(18px, 2.6vw, 30px);
}

.panel-head { margin-bottom: 20px; display: flex; flex-direction: column; gap: 6px; }
.panel-head.row { flex-direction: row; align-items: flex-start; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.panel-head h2 { font-size: 20px; }
.panel-head p { color: var(--ink-3); font-size: 13px; max-width: 68ch; }

.panel-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin-top: 26px; padding-top: 18px; border-top: 1px dashed var(--line);
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- 按钮 */

.btn {
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  padding: 9px 18px; border-radius: 10px; cursor: pointer; font-size: 13.5px;
  transition: all .16s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 560; }
.btn.primary:hover { background: #33302a; border-color: #33302a; }
.btn.ghost { background: transparent; }
.btn.subtle { background: var(--paper-3); border-color: transparent; width: 100%; }
.btn.subtle:hover { background: var(--line-soft); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; font-weight: 560; }
.btn.accent:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.checkbox { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-3); cursor: pointer; user-select: none; }
.checkbox input { accent-color: var(--accent); }

/* ---------------------------------------------------------------- 上传区 */

.upload-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
@media (max-width: 900px) { .upload-grid { grid-template-columns: 1fr; } }

.dropzone {
  position: relative; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background:
    linear-gradient(var(--paper-2), var(--paper-2)) padding-box,
    repeating-linear-gradient(45deg, transparent 0 8px, rgba(180,85,58,0.02) 8px 16px);
  min-height: 300px; display: grid; place-items: center; cursor: pointer;
  transition: all .2s ease; overflow: hidden;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: #fffbf7; outline: none; }
.dropzone.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 24px; }
.dz-icon {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-size: 24px; color: var(--accent); background: var(--accent-soft); margin-bottom: 4px;
}
.dz-icon.small { width: 38px; height: 38px; font-size: 19px; }
.dz-inner strong { font-size: 14.5px; }
.dz-inner span { font-size: 12px; color: var(--ink-3); }
.dropzone img { width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0; padding: 12px; background: var(--paper-2); }

.hint-card {
  border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 22px;
  background: linear-gradient(160deg, #fbf8f2, var(--paper-2));
  display: flex; flex-direction: column; gap: 10px;
}
.hint-card h3 { font-size: 14px; color: var(--ink); }
.hint-card p { font-size: 13px; color: var(--ink-2); }
.hint-card ul { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.hint-card li { position: relative; padding-left: 18px; font-size: 12.5px; color: var(--ink-3); }
.hint-card li::before { content: "—"; position: absolute; left: 0; color: var(--accent); }

/* ---------------------------------------------------------------- 分析页 */

.analysis-layout { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 980px) { .analysis-layout { grid-template-columns: 1fr; } }

.ref-preview {
  margin: 0; position: sticky; top: 84px; border: 1px solid var(--line-soft);
  border-radius: var(--radius); overflow: hidden; background: var(--paper-3);
}
.ref-preview img { width: 100%; max-height: 480px; object-fit: contain; background: var(--paper-3); }
.ref-preview figcaption { padding: 8px 12px; font-size: 11.5px; color: var(--ink-3); border-top: 1px solid var(--line-soft); background: var(--paper-2); }

.analysis-sections { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

.section-card { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--paper-2); overflow: hidden; }
.section-card > header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 14px; background: var(--paper-3); border-bottom: 1px solid var(--line-soft);
}
.section-card > header h3 { font-size: 13px; letter-spacing: 0.01em; }
.section-card > header .hint { font-size: 11px; color: var(--ink-3); font-weight: 400; }
.section-card .fields { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.section-card.filled-ok > header { background: var(--sage-soft); }
.section-card.filled-low > header { background: #f7edda; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 11.5px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.field > span .tag-muted { font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--paper-3); color: var(--ink-3); }
.field input[type="text"], .field textarea, .field select {
  width: 100%; border: 1px solid var(--line-soft); border-radius: 8px;
  padding: 7px 10px; background: var(--paper-2); font-size: 12.8px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input[type="text"]:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 54px; line-height: 1.5; }
.field input::placeholder, .field textarea::placeholder { color: #b3aa9c; }

.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  background: var(--paper-3); border: 1px solid var(--line-soft); font-size: 11.5px; color: var(--ink-2);
}
.tag button { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 0; line-height: 1; font-size: 13px; }
.tag button:hover { color: var(--danger); }

.completeness { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 10px; }
.meter { width: 120px; height: 5px; border-radius: 3px; background: var(--paper-3); overflow: hidden; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 3px; transition: width .4s ease; }

.skeleton-note { padding: 26px; color: var(--ink-3); font-size: 13px; text-align: center; }

/* ---------------------------------------------------------------- 产品页 */

.product-grid { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .product-grid { grid-template-columns: 1fr; } }

.product-uploads { display: grid; gap: 12px; }

.mini-drop {
  position: relative; border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
  min-height: 168px; display: grid; place-items: center; cursor: pointer;
  background: var(--paper-2); transition: all .18s ease; overflow: hidden;
}
.mini-drop:hover, .mini-drop:focus-visible { border-color: var(--accent); outline: none; }
.mini-drop.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.mini-drop-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 16px; }
.mini-drop-inner strong { font-size: 12.8px; }
.mini-drop-inner span { font-size: 11.5px; color: var(--ink-3); }
.mini-drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 8px; background: var(--paper-2); }

.product-form { display: flex; flex-direction: column; gap: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } }
.product-form .field input, .product-form .field textarea {
  border: 1px solid var(--line-soft); border-radius: 9px; padding: 8px 11px;
  background: var(--paper-2); font-size: 13px;
}
.product-form .field input:focus, .product-form .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.product-form .field > span { font-size: 12px; }
/* 文案提示：卖点 vs 图上文案的差别，避免用户以为卖点会上图 */
.product-form .copy-hint { margin: -6px 0 0; }

/* ---------------------------------------------------------------- 提示词页 */

.prompt-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: 22px; align-items: start; }
@media (max-width: 1060px) { .prompt-grid { grid-template-columns: 1fr; } }

.prompt-main { display: flex; flex-direction: column; gap: 16px; }
.prompt-block { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); overflow: hidden; background: var(--paper-2); }
.prompt-block header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; background: var(--paper-3); border-bottom: 1px solid var(--line-soft);
}
.prompt-block header h3 { font-size: 12.5px; color: var(--ink-2); letter-spacing: 0.02em; }
.prompt-block textarea {
  width: 100%; border: 0; border-radius: 0; padding: 14px 16px; resize: vertical;
  font-family: var(--font-en); font-size: 13px; line-height: 1.7; background: var(--paper-2);
  color: var(--ink); min-height: 120px;
}
.prompt-block textarea:focus { outline: none; background: #fffdf9; box-shadow: inset 0 0 0 2px var(--accent-soft); }

.copy-btn {
  border: 1px solid var(--line); background: var(--paper-2); border-radius: 7px;
  padding: 3px 10px; font-size: 11.5px; cursor: pointer; color: var(--ink-2); transition: all .15s ease;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.copied { background: var(--sage-soft); border-color: var(--sage); color: var(--sage); }

.segments { display: flex; flex-direction: column; border-top: 1px dashed var(--line); }
.segment {
  display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 12px;
  padding: 8px 16px; font-size: 12px; border-bottom: 1px solid #f1ebe0;
  align-items: start; transition: background .15s ease;
}
.segment:last-child { border-bottom: 0; }
.segment:hover { background: #fdfaf4; }
.segment dt { color: var(--ink-3); font-size: 11.5px; padding-top: 1px; }
.segment dd { margin: 0; color: var(--ink-2); font-family: var(--font-en); line-height: 1.55; word-break: break-word; }

.prompt-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 84px; }
.params-card { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 16px; background: var(--paper-2); }
.params-card h3 { font-size: 12.5px; color: var(--ink-2); margin-bottom: 12px; letter-spacing: 0.02em; }
.param-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line-soft); }
.param-row:last-of-type { border-bottom: 0; }
.param-row label { font-size: 12.5px; color: var(--ink-3); }
.param-row output { font-size: 12.5px; font-family: var(--mono); color: var(--ink); }
.param-row select {
  border: 1px solid var(--line-soft); background: var(--paper-2); border-radius: 7px;
  padding: 4px 8px; font-size: 12.5px; cursor: pointer;
}
.toggle-row input { accent-color: var(--accent); width: 16px; height: 16px; }
.param-row.column { flex-direction: column; align-items: stretch; gap: 6px; }
.param-row.column input {
  border: 1px solid var(--line-soft); background: var(--paper-2); border-radius: 7px;
  padding: 6px 9px; font-size: 12.5px; font-family: var(--sans); color: var(--ink);
}
.param-row.column input:focus { outline: none; border-color: var(--accent); }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type="range"] { width: 120px; accent-color: var(--accent); }
.params-card .btn { margin-top: 12px; }

.suggest-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.suggest-list li { font-size: 12px; color: var(--ink-2); padding-left: 16px; position: relative; }
.suggest-list li::before { content: "→"; position: absolute; left: 0; color: var(--sage); font-size: 11px; }
.notes-list { display: flex; flex-direction: column; gap: 7px; }
.notes-list li { font-size: 12px; color: var(--ink-3); padding: 7px 9px; background: var(--paper-3); border-radius: 7px; }
.notes-list:empty { display: none; }

.gen-status { margin-top: 10px; font-size: 12px; color: var(--ink-3); min-height: 18px; }
.gen-status.err { color: var(--danger); }
.gen-result { margin: 10px 0 0; border: 1px solid var(--line-soft); border-radius: 10px; overflow: hidden; }
.gen-result img { width: 100%; }
.gen-result figcaption { padding: 7px 10px; font-size: 11.5px; border-top: 1px solid var(--line-soft); }
.gen-result a { color: var(--accent); text-decoration: none; }
.gen-result a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- 历史 */

.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.history-card {
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm); overflow: hidden;
  background: var(--paper-2); display: flex; flex-direction: column; transition: all .18s ease;
}
.history-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.history-card .thumb { aspect-ratio: 4 / 3; background: var(--paper-3); overflow: hidden; }
.history-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-card .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.history-card h4 { font-size: 13.5px; }
.history-card .meta { font-size: 11.5px; color: var(--ink-3); }
.history-card .kw { display: flex; flex-wrap: wrap; gap: 4px; }
.history-card .kw span { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; background: var(--paper-3); color: var(--ink-3); }
.history-card footer { display: flex; gap: 8px; padding: 0 14px 12px; }
.history-card footer .btn { padding: 5px 11px; font-size: 12px; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 48px 20px; color: var(--ink-3); font-size: 13px; }

/* ---------------------------------------------------------------- Toast */

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 12.8px; opacity: 0; pointer-events: none; transition: all .25s ease;
  box-shadow: var(--shadow-md); z-index: 100; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

/* ---------------------------------------------------------------- 加载态 */

.spinner {
  display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px;
}
.btn.ghost .spinner, .btn.subtle .spinner { border-color: rgba(35,32,28,0.2); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

.pulse-note { font-size: 12px; color: var(--ink-3); }
.pulse-note::after { content: ""; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
