/* ============ Procurement Copilot · ChatGPT 风(极简) ============ */
:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --border: #e5e5e5;
  --border-soft: #ececec;
  --text: #0d0d0d;
  --muted: #6f6f6f;
  --user-bubble: #f0f0f0;
  --ok-bg: #ecfdf5; --ok-fg: #047857;
  --warn-bg: #fffbeb; --warn-fg: #b45309;
  --err-bg: #fef2f2; --err-fg: #b91c1c;
  --info-bg: #f4f4f5; --info-fg: #52525b;
  --r: 14px; --r-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }

/* ---------- 控件 ---------- */
button { font-family: inherit; cursor: pointer; }
select, input, textarea { font-family: inherit; font-size: 14px; }
textarea:focus, input:focus, select:focus { outline: none; border-color: #b3b3b3; box-shadow: 0 0 0 2px rgba(13,13,13,.05); }

/* ---------- 头部(极简) ---------- */
header { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px;
  background: rgba(255,255,255,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border-soft); }
.brand { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.badge { background: var(--bg); color: var(--muted); font-size: 11px; font-weight: 600; border-radius: 20px; padding: 2px 9px; }
.lang-switch { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.lang-switch select { background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 13px; }
.lang-switch select:focus { border-color: #b3b3b3; }
.link-btn { color: var(--muted); text-decoration: none; border: 1px solid var(--border); background: #fff;
  padding: 6px 12px; border-radius: 8px; font-size: 12.5px; transition: .15s; }
.link-btn:hover { border-color: #b3b3b3; color: var(--text); }

/* ================= 对话版 ================= */
.chat-body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; background: var(--bg); }
.chat-header { flex: 0 0 auto; }
.chat-main { flex: 1 1 auto; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; width: 100%;
  padding: 0 16px; min-height: 0; }

/* 进度:一行小字 + 小圆点 */
.progress-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; padding: 14px 4px 2px; flex-wrap: wrap; }
.prog { width: 8px; height: 8px; border-radius: 50%; background: #e2e2e2; transition: .2s; }
.prog.done { background: #b9b9b9; }
.prog.active { background: var(--text); transform: scale(1.25); }
.prog:not(:last-of-type) { margin-right: 3px; }
.prog-label { font-size: 12.5px; color: var(--muted); margin-left: 8px; font-weight: 500; }
.prog-done { font-size: 12.5px; color: var(--ok-fg); font-weight: 600; }

/* 消息区 */
.chat-messages { flex: 1 1 auto; overflow-y: auto; padding: 18px 4px 10px; display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth; scrollbar-width: thin; scrollbar-color: #d4d4d4 transparent; }
.msg { display: flex; max-width: 100%; }
.msg.bot { align-self: flex-start; width: 100%; }
.msg.user { align-self: flex-end; max-width: 88%; }
.avatar { display: none; }
.bubble { line-height: 1.75; font-size: 15px; word-break: break-word; }
.msg.bot .bubble { background: transparent; border: 0; box-shadow: none; padding: 0; width: 100%; }
.msg.user .bubble { background: var(--user-bubble); border-radius: 16px; padding: 10px 15px; border-top-right-radius: 5px; }
.msg.typing .bubble { color: var(--muted); }
.msg.typing .bubble::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%;
  background: #a1a1a1; animation: blink 1.2s infinite; vertical-align: middle; }
@keyframes blink { 0%,100%{opacity:.2} 50%{opacity:1} }

/* 阶段徽章(低调) */
.phase-badge { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 2px 8px; margin-bottom: 8px; }
.phase-badge.collect { background: var(--info-bg); color: var(--info-fg); }
.phase-badge.confirm { background: var(--warn-bg); color: var(--warn-fg); }
.phase-badge.result { background: var(--ok-bg); color: var(--ok-fg); }

/* 报告:白底细边,像 markdown 正文 */
.report { margin-top: 4px; background: #fff; border: 1px solid var(--border-soft); border-radius: 12px; padding: 12px 16px; }
.md-h1 { font-size: 16px; font-weight: 700; margin: 8px 0 4px; }
.md-h2 { font-size: 14px; font-weight: 700; margin: 12px 0 5px; padding-bottom: 4px; border-bottom: 1px solid var(--border-soft); }
.md-li { padding: 1.5px 0; }
.md-p { padding: 2px 0; }

/* 快捷回复(扁平) */
.quick-replies { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 4px; min-height: 48px; }
.chip { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 999px;
  font-size: 13px; transition: .14s; }
.chip:hover { background: #f0f0f0; border-color: #d0d0d0; }

/* 输入栏(ChatGPT 风:圆角矩形 + 小圆形发送) */
.chat-input-bar { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 8px 0 14px; }
.input-shell { flex: 1; display: flex; align-items: flex-end; gap: 6px; background: #fff; border: 1px solid var(--border);
  border-radius: 24px; padding: 6px 6px 6px 16px; transition: border-color .15s, box-shadow .15s; }
.input-shell:focus-within { border-color: #b3b3b3; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
.chat-input-bar textarea { flex: 1; resize: none; border: 0; outline: 0; background: transparent; font-size: 15px; line-height: 1.6;
  min-height: 32px; max-height: 150px; overflow-y: auto; padding: 5px 0; }
.chat-input-bar textarea:focus { box-shadow: none; }
.chat-input-bar button { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--text);
  color: #fff; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center; transition: .15s; }
.chat-input-bar button:hover { background: #262626; }
.chat-input-bar button:active { transform: scale(.94); }

/* 结果区块(白底细边) */
.result-block { margin-top: 6px; background: #fff; border: 1px solid var(--border-soft); border-radius: 12px; padding: 16px; }
.result-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

/* 卡片(扁平) */
.card { border: 1px solid var(--border-soft); border-radius: 12px; margin-top: 10px; background: #fff; overflow: hidden; }
.card summary { cursor: pointer; padding: 11px 15px; font-weight: 600; font-size: 14px; user-select: none; list-style: none;
  display: flex; align-items: center; gap: 8px; }
.card summary::-webkit-details-marker { display: none; }
.card summary::before { content: "▸"; transition: .15s; color: #9a9a9a; font-size: 12px; }
.card[open] summary::before { transform: rotate(90deg); }
.card[open] summary { border-bottom: 1px solid var(--border-soft); }
.card .kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.card .kv td { padding: 7px 15px; border-bottom: 1px solid #f4f4f4; vertical-align: top; }
.card .kv tr:last-child td { border-bottom: 0; }
.card .kv tr.total td { font-weight: 700; background: #fafafa; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 询盘 / 产品 */
.inq { padding: 10px 15px; border-bottom: 1px solid #f4f4f4; }
.inq:last-child { border-bottom: 0; }
.inq pre { white-space: pre-wrap; background: #fafafa; border: 1px solid var(--border-soft); border-radius: 9px; padding: 9px; font-size: 12.5px; margin: 8px 0 0; }
.sup { padding: 10px 15px; border-bottom: 1px solid #f4f4f4; }
.sup:last-child { border-bottom: 0; }
.muted { color: var(--muted); font-size: 12.5px; }
.small { font-size: 12.5px; }
.warn { color: var(--warn-fg); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; margin-top: 6px; }
.mini { font-size: 12px; padding: 3px 10px; border-radius: 7px; border: 1px solid var(--border); background: #fff; cursor: pointer; margin-left: 6px; transition: .15s; }
.mini:hover { background: #f0f0f0; }

/* 标签 */
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; margin: 2px; }
.tag.low { background: var(--ok-bg); color: var(--ok-fg); }
.tag.mid { background: var(--warn-bg); color: var(--warn-fg); }
.tag.high { background: var(--err-bg); color: var(--err-fg); }

/* 对话过程折叠 */
.chat-log { margin-top: 14px; border: 1px dashed #d4d4d4; border-radius: 12px; background: #fbfbfb; }
.chat-log summary { cursor: pointer; padding: 9px 13px; font-size: 13px; color: var(--muted); font-weight: 600; user-select: none; list-style: none; }
.chat-log summary::-webkit-details-marker { display: none; }
.chat-log-inner { padding: 4px 13px 13px; display: flex; flex-direction: column; gap: 10px; max-height: 42vh; overflow-y: auto; }
.chat-log-inner .msg { max-width: 100%; }
.chat-log-inner .msg.user { max-width: 88%; }

/* ================= 高级版 / 后台 ================= */
nav#tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 18px; background: rgba(255,255,255,.85);
  border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px); }
.tab { border: 1px solid var(--border); background: #fff; padding: 8px 15px; border-radius: 9px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--muted); transition: .14s; }
.tab:hover { border-color: #b3b3b3; color: var(--text); }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }
main { padding: 22px; max-width: 1200px; margin: 0 auto; }
.panel { display: none; background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--r); padding: 20px; }
.panel.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h2 { margin: 0 0 6px; font-size: 16px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
textarea, input[type=text], input[type=number], select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; width: 100%; background: #fff; transition: .15s; }
textarea { width: 100%; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin: 12px 0; }
.actions button { background: var(--text); color: #fff; border: 0; padding: 9px 18px; border-radius: 9px; font-size: 14px; font-weight: 500; transition: .15s; }
.actions button:hover { background: #262626; }
.btn-primary { background: var(--text); color: #fff; border: 0; padding: 10px 20px; border-radius: 10px; font-size: 14px; font-weight: 600; transition: .15s; }
.btn-primary:hover { background: #262626; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.grid2 .full { grid-column: 1 / -1; }
.result { background: #fafafa; border: 1px solid var(--border-soft); border-radius: 9px; padding: 13px;
  overflow: auto; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.hint { color: var(--muted); font-size: 13px; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.card pre { white-space: pre-wrap; background: #fafafa; border-radius: 9px; padding: 9px; font-size: 12.5px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--border-soft); padding: 7px 9px; text-align: left; }
th { background: #f4f4f5; font-weight: 600; }
footer { text-align: center; color: #9a9a9a; font-size: 12px; padding: 16px; }

/* 响应式 */
@media (max-width: 720px) {
  header { padding: 9px 12px; }
  .chat-main { padding: 0 10px; }
  .msg.user { max-width: 92%; }
  nav#tabs { padding: 10px 10px; }
  main { padding: 12px; }
}

/* 历史面板 */
.chat-main { position: relative; }
.history-panel { position: absolute; right: 12px; top: 52px; width: 300px; max-height: 72vh; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--sh-md); z-index: 20; padding: 10px; }
.history-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 8px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.history-head b { font-size: 13.5px; }
.hist-item { padding: 9px 10px; border-radius: 9px; cursor: pointer; transition: .13s; }
.hist-item:hover { background: #f4f4f5; }
.hist-item + .hist-item { border-top: 1px solid #f4f4f4; }

/* ================= 左侧边栏(新对话 + 历史) ================= */
.chat-body { flex-direction: row; }
.sidebar { width: 264px; flex: 0 0 auto; background: #fff; border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; padding: 12px; gap: 8px; overflow-y: auto; }
.sidebar-brand { font-size: 14px; font-weight: 700; padding: 4px 6px 10px; border-bottom: 1px solid var(--border-soft); }
.new-chat { background: var(--text); color: #fff; border: 0; border-radius: 10px; padding: 10px 14px;
  font-size: 13.5px; font-weight: 600; transition: .15s; }
.new-chat:hover { background: #262626; }
.sidebar-section { font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px; }
.history-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.hist-item { display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 9px; }
.hist-item:hover { background: #f4f4f5; }
.hist-item.active { background: var(--user-bubble); }
.hist-main { flex: 1; min-width: 0; cursor: pointer; }
.hist-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-del { opacity: 0; background: none; border: 0; font-size: 12px; cursor: pointer; transition: .15s; }
.hist-item:hover .hist-del { opacity: 1; }
.hist-empty { font-size: 12.5px; color: var(--muted); padding: 8px; }
.chat-wrap { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.header-left { display: flex; align-items: center; gap: 8px; }
.sidebar-toggle { display: none; background: none; border: 0; font-size: 18px; cursor: pointer; padding: 2px 6px; }
.chat-title { font-size: 14px; font-weight: 600; }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--sh-lg); }
  .sidebar-toggle { display: block; }
}
