:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e6e8eb;
  --text: #1f2329;
  --muted: #8a9099;
  --primary: #2f6df6;
  --warn-bg: #fff7e6;
  --warn-line: #ffd591;
  --bad-bg: #fff1f0;
  --bad-line: #ffa39e;
  --ok: #389e0d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  /* 滚动时锁定在顶部；z-index 低于模态(50)/toast，避免遮挡弹层 */
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .04);
}
.topbar h1 { font-size: 18px; margin: 0; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav-toggle { display: none; } /* 桌面端隐藏汉堡，仅移动端出现 */
.nav-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
}
.nav-link:hover { background: #f0f2f5; color: var(--text); }
.nav-link.active { background: #eaf1ff; color: var(--primary); font-weight: 600; }
.badge {
  font-size: 12px;
  color: var(--muted);
  background: #f0f2f5;
  padding: 4px 10px;
  border-radius: 999px;
  margin-left: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  padding: 16px 24px;
  align-items: start;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

/* 移动端顶栏：标题 + 汉堡按钮一行，点击展开下拉抽屉式菜单 */
@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 16px;
  }
  .topbar h1 { font-size: 15px; line-height: 1.3; flex: 1; min-width: 0; }

  /* 汉堡按钮 */
  .nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 36px;
    padding: 8px 9px;
    background: #f0f2f5;
    border-radius: 9px;
  }
  .nav-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text);
    border-radius: 2px;
    transition: transform .22s ease, opacity .22s ease;
  }
  .topbar.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .topbar.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
  .topbar.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* 抽屉：默认收起，展开时整行铺开为竖直列表 */
  .nav {
    order: 3;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    overflow: hidden;
    max-height: 0;
    margin-top: 0;
    opacity: 0;
    transition: max-height .25s ease, opacity .2s ease, margin-top .25s ease;
  }
  .topbar.nav-open .nav {
    max-height: 70vh;
    opacity: 1;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    overflow-y: auto;
  }
  .nav-link { width: 100%; padding: 11px 12px; font-size: 14px; border-radius: 8px; }
  .nav-account {
    width: 100%;
    margin: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
  }
  .nav-logout { width: 100%; text-align: left; padding: 11px 12px; }
  .badge { align-self: flex-start; margin: 6px 0 2px; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}
.panel h2 { font-size: 15px; margin: 0 0 14px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions select, .actions input[type="text"] {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px;
}
.chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
button.mini { font-size: 12px; padding: 6px 12px; background: #f0f2f5; color: var(--text); }
button.mini:disabled { opacity: .5; cursor: not-allowed; }

.prompt-main { padding: 16px 24px; max-width: 900px; }

button.mini.save { background: var(--primary); color: #fff; }
button.mini.danger { background: #fff1f0; color: #cf1322; }
button.mini.danger:hover { background: #ffe7e5; }
.sub-label { font-size: 13px; margin: 6px 0 10px; color: var(--text); }
.sub-label-row { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 10px; }
.sub-label-row .sub-label { margin: 0; font-weight: 600; }
.field code {
  background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12px;
}

.scenario-list { display: flex; flex-direction: column; gap: 12px; }
.scenario {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fafbfc;
}
.scenario-head { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.scenario-head input {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px;
}
.scenario-head .sc-key { width: 160px; font-family: ui-monospace, monospace; }
.scenario-head .sc-label { flex: 1; min-width: 120px; }
.scenario .sc-row { display: flex; gap: 8px; margin-bottom: 6px; }
.scenario .sc-row > label { flex: 1; font-size: 12px; color: var(--muted); }
.scenario textarea {
  width: 100%; margin-top: 3px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 7px; font-size: 13px;
  font-family: inherit; resize: vertical;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
}
.toggle-text { display: flex; flex-direction: column; gap: 2px; }
.toggle-text strong { font-size: 13px; font-weight: 600; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #c9ced6;
  border-radius: 999px;
  transition: background .2s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:disabled + .switch-slider { opacity: .6; cursor: progress; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; margin-bottom: 6px; }
.field small { color: var(--muted); font-weight: normal; margin-left: 4px; }
.field .req {
  font-style: normal; font-size: 11px; color: #cf1322;
  background: #fff1f0; border-radius: 4px; padding: 1px 6px; margin-left: 6px;
}
.field input.invalid, .field textarea.invalid {
  border-color: #e23b3b; box-shadow: 0 0 0 3px rgba(226, 59, 59, .15);
}
.field-err { display: block; color: #cf1322; font-size: 12px; margin-top: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { resize: vertical; }

/* 生成页：只读展示当前方案绑定的产品 */
.product-view {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  padding: 10px 12px;
}
.product-view.invalid {
  border-color: #e23b3b; box-shadow: 0 0 0 3px rgba(226, 59, 59, .15);
}
.product-view.empty {
  color: var(--muted); font-size: 13px; background: #fff7e6; border-color: var(--warn-line);
}
.product-view .pv-name { font-size: 14px; font-weight: 600; color: var(--text); }
.product-view .pv-facts {
  margin-top: 6px; font-size: 13px; color: var(--muted);
  white-space: pre-wrap; line-height: 1.5;
}

button {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
}
button.primary { background: var(--primary); color: #fff; }
button.primary:disabled { opacity: .6; cursor: progress; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); margin-left: 8px; }

.hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 14px; }
.space-info { font-size: 12px; color: var(--muted); margin-top: 8px; }

.status { font-size: 12px; color: var(--muted); font-weight: normal; }

.warning {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.debug-prompt {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: #fafbfc;
}
.debug-prompt summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}
.debug-call {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.debug-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.debug-role {
  display: inline-block;
  font-size: 11px;
  color: var(--primary);
  background: #eaf1ff;
  border-radius: 999px;
  padding: 2px 8px;
  margin: 8px 0 6px;
}
.debug-prompt pre {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.55;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* 顶栏账号区 */
.nav-account { display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; }
.nav-logout {
  font-size: 12px; padding: 5px 10px; background: #fff1f0; color: #cf1322;
  border-radius: 8px;
}

/* 登录页 */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card { width: 100%; max-width: 360px; }
.login-title { font-size: 20px; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.login-btn { width: 100%; margin-top: 4px; }
.login-err { color: #cf1322; font-size: 13px; min-height: 18px; margin-top: 10px; }

/* 账号管理 */
.admin-create { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.admin-inp {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
.admin-inp:nth-child(1) { width: 200px; font-family: ui-monospace, monospace; }
.admin-inp:nth-child(2) { width: 160px; }
.admin-inp:nth-child(3) { width: 160px; }
/* ===== 提示词管理：方案标签 ===== */
.profile-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.ptab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; cursor: pointer; font-size: 13px; color: var(--text);
  user-select: none;
}
.ptab:hover { background: #f5f7fa; }
.ptab.active { border-color: var(--primary); background: #eaf1ff; color: var(--primary); font-weight: 600; }
.ptab-star { display: inline-flex; color: #c9ced6; cursor: pointer; border-radius: 4px; }
.ptab-star:hover { color: #f5a623; }
.ptab-star svg { width: 15px; height: 15px; display: block; }
.ptab-star.is-default { color: #f5a623; }
.ptab-star.is-default svg { fill: currentColor; }
.ptab-add { border-style: dashed; color: var(--muted); font-weight: normal; }
.ptab-add:hover { color: var(--primary); border-color: var(--primary); background: #fff; }
.ptab-add svg { width: 14px; height: 14px; }

/* ===== 图标按钮 ===== */
.icon-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 7px 11px; border-radius: 8px;
  background: #f0f2f5; color: var(--text); border: 1px solid transparent;
  cursor: pointer; line-height: 1;
}
.icon-btn:hover { background: #e6e9ef; }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn svg { width: 14px; height: 14px; flex: none; }
.icon-btn.primary { background: var(--primary); color: #fff; }
.icon-btn.primary:hover { background: #245fe0; }
.icon-btn.danger { color: #cf1322; }
.icon-btn.danger:hover { background: #ffe7e5; }

/* ===== 场景卡片（带字段标签）===== */
.scenario-no {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  font-size: 12px; font-weight: 600; color: var(--primary);
  background: #eaf1ff; border-radius: 6px; flex: none;
}
.sc-del.icon-btn { padding: 6px; margin-left: auto; }
.sc-field { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.sc-field-label { font-size: 11px; color: var(--muted); }

/* ===== 全局：聚焦态 / 过渡 / 减弱动效（惠及所有页面）===== */
button, input, select, textarea, .nav-link, .icon-btn {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 109, 246, .15);
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ===== 模态对话框 ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 41, .42);
  opacity: 0; transition: opacity .16s ease;
}
.modal-backdrop.show { opacity: 1; }
.modal-card {
  width: 100%; max-width: 360px; background: var(--panel);
  border-radius: 14px; padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  transform: translateY(8px) scale(.98); transition: transform .16s ease;
}
.modal-backdrop.show .modal-card { transform: none; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.modal-msg { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }
.modal-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; font-size: 14px; margin-bottom: 16px; font-family: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-btn {
  padding: 8px 16px; border-radius: 9px; font-size: 13px;
  cursor: pointer; border: 1px solid transparent;
}
.modal-btn.ghost { background: #f0f2f5; color: var(--text); }
.modal-btn.ghost:hover { background: #e6e9ef; }
.modal-btn.primary { background: var(--primary); color: #fff; }
.modal-btn.primary:hover { background: #245fe0; }
.modal-btn.danger { background: #e23b3b; color: #fff; }
.modal-btn.danger:hover { background: #c92f2f; }

/* ===== Toast 轻提示 ===== */
.toast-wrap {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 16px; border-radius: 10px; font-size: 13px;
  background: #1f2329; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  opacity: 0; transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #cf1322; }
.toast.success { background: #389e0d; }

.account-list { display: flex; flex-direction: column; gap: 8px; }
.account-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fafbfc;
  flex-wrap: wrap;
}
.account-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.account-id { font-family: ui-monospace, monospace; font-weight: 600; font-size: 13px; }
.account-name { font-size: 13px; color: var(--muted); }
.account-when { font-size: 12px; color: var(--muted); }
.account-ops { display: flex; gap: 6px; }
.reset-btn { background: #f0f2f5; }
.del-btn { background: #fff1f0; color: #cf1322; }

/* ===== 生成按钮 loading 态 + 取消 ===== */
.gen-actions { display: flex; align-items: center; }
button.primary.loading { position: relative; padding-left: 34px; cursor: progress; }
button.primary.loading::before {
  content: ''; position: absolute; left: 14px; top: 50%; width: 14px; height: 14px;
  margin-top: -7px; border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 等待骨架屏 ===== */
.results-skeleton { display: flex; flex-direction: column; gap: 12px; }
.skeleton-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.sk-line {
  height: 12px; border-radius: 6px; margin: 9px 0;
  background: linear-gradient(90deg, #eef0f2 25%, #f7f8fa 37%, #eef0f2 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}
.sk-line.sk-head { width: 38%; height: 14px; margin: 2px 0 14px; }
.sk-line.short { width: 55%; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.results { display: flex; flex-direction: column; gap: 12px; }

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.card.bad { background: var(--bad-bg); border-color: var(--bad-line); }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); }

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.card-idx { font-weight: 600; font-size: 13px; }
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f0f2f5;
  color: var(--muted);
}
.tag.ok { background: #f6ffed; color: var(--ok); }
.tag.bad { background: #fff1f0; color: #cf1322; }
.tag.warn { background: #fff7e6; color: #d46b08; }

.card-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.card-foot { margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.copy-btn { font-size: 12px; padding: 4px 10px; background: #f0f2f5; color: var(--text); }
.hits { font-size: 12px; color: #cf1322; }
.empty { color: var(--muted); font-size: 14px; }
