/* 采购智能体 · 前端样式 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb; --primary-dark: #1d4ed8; --slate: #0f172a;
  --bg: #f1f5f9; --card: #ffffff; --line: #e2e8f0;
  --text: #1e293b; --muted: #64748b;
  --red: #dc2626; --orange: #ea580c; --yellow: #ca8a04; --green: #16a34a; --blue: #2563eb;
}
html, body { height: 100%; }
body { font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 40px 36px; width: 380px; box-shadow: 0 24px 60px rgba(0,0,0,.35); text-align: center; }
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 22px; margin: 8px 0 4px; }
.login-sub { color: var(--muted); margin-bottom: 24px; }
#loginForm input { width: 100%; padding: 11px 14px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; outline: none; }
#loginForm input:focus { border-color: var(--primary); }
#loginForm button { width: 100%; padding: 11px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 15px; cursor: pointer; }
#loginForm button:hover { background: var(--primary-dark); }
.login-error { color: var(--red); margin-top: 10px; min-height: 18px; }
.login-hint { margin-top: 16px; color: var(--muted); font-size: 12px; line-height: 1.6; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 216px; background: var(--slate); color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-ico { font-size: 26px; }
.brand b { display: block; color: #fff; font-size: 15px; }
.brand small { color: #94a3b8; font-size: 11px; }
#nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; color: #cbd5e1; margin-bottom: 2px; user-select: none; }
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; }
.nav-badge { margin-left: auto; background: #ef4444; color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.side-user { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.avatar { font-size: 22px; }
.side-user-info { flex: 1; min-width: 0; }
.side-user-info b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-info small { color: #94a3b8; font-size: 11px; }
.linkbtn { background: none; border: 1px solid rgba(255,255,255,.25); color: #cbd5e1; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
.linkbtn:hover { background: rgba(255,255,255,.1); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.page-title { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.content { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }

/* ---------- 通用组件 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 12px; }
.stat-ico { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-ico.red { background: #fee2e2; } .stat-ico.orange { background: #ffedd5; } .stat-ico.blue { background: #dbeafe; } .stat-ico.green { background: #dcfce7; } .stat-ico.slate { background: #e2e8f0; }
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 12px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 18px; }
/* 面板头部（标题 + 搜索/筛选栏）滚动时冻结在内容区顶部，避免长列表里翻回顶部才能搜索 */
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
  position: sticky; top: 0; z-index: 6; background: #fff; border-radius: 12px 12px 0 0; box-shadow: 0 4px 10px -6px rgba(15,23,42,.18); }
.panel-head h3 { font-size: 15px; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 14px 18px; overflow-x: auto; }
.panel-tip { color: var(--muted); font-size: 12px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #f8fafc; position: sticky; top: 0; }
.tbl td { padding: 6px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; line-height: 1.45; }
.tbl tr:hover td { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions button { margin-left: 4px; }
/* 日期/时间/短字段：不换行，避免被挤成两行 */
.tbl td.nowrap { white-space: nowrap; }
/* 备注等长文本：单行省略，鼠标悬停看全文（保持行高紧凑） */
.tbl td.ellip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; gap: 4px; background: var(--primary); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f1f5f9; }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.badge.red { background: #fee2e2; color: var(--red); }
.badge.orange { background: #ffedd5; color: var(--orange); }
.badge.yellow { background: #fef9c3; color: var(--yellow); }
.badge.green { background: #dcfce7; color: var(--green); }
.badge.blue { background: #dbeafe; color: var(--blue); }
.badge.slate { background: #e2e8f0; color: #475569; }
.badge.gray { background: #f1f5f9; color: var(--muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input[type="text"], input[type="number"], input[type="password"], input[type="date"], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; outline: none; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
select { cursor: pointer; }

.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt8 { margin-top: 8px; } .mb8 { margin-bottom: 8px; }
.flex { display: flex; gap: 8px; align-items: center; } .flex.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* 价格走势图 */
.sparkline { display: block; }

/* 可搜索下拉框（物料/供应商等长列表） */
.ss { position: relative; }
.ss-input { width: 100%; }
.ss-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 28px rgba(15,23,42,.14); max-height: 260px; overflow-y: auto; margin-top: 4px; }
.ss-item { padding: 8px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f8fafc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-item:hover, .ss-item.active { background: #eff6ff; }
.ss-sub { color: var(--muted); font-size: 12px; margin-left: 8px; }
.ss-code { display: inline-block; background: #eef2ff; color: #4338ca; font-size: 11px; border-radius: 4px; padding: 1px 5px; margin-right: 7px; }
.ss-empty, .ss-more { padding: 8px 10px; color: var(--muted); font-size: 12px; }
/* 字段标签里的行内操作链接（如「＋新建物料」） */
.linkbtn2 { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 12px; padding: 0 0 0 6px; }
.linkbtn2:hover { text-decoration: underline; }

/* ---------- 模态框 ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 560px; max-width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: 760px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; }

/* ---------- 预警/话术 ---------- */
.alert-row td { vertical-align: top; }
.talk-card { background: linear-gradient(180deg, #f8fafc, #fff); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.talk-stage { font-weight: 700; color: var(--primary); margin-bottom: 8px; font-size: 14px; }
.talk-lines { white-space: pre-wrap; line-height: 1.9; color: var(--text); }
.talk-facts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.talk-facts .badge { background: #eef2ff; color: #4338ca; }
.tips { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 12px 14px; }
.tips h4 { color: #92400e; font-size: 13px; margin-bottom: 6px; }
.tips li { margin-left: 18px; color: #78350f; line-height: 1.9; font-size: 13px; }

/* ---------- 企微模拟对话 ---------- */
.chat-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
.chat-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; height: 62vh; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.chat-head b { font-size: 14px; }
.chat-head .badge { margin-left: auto; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; line-height: 1.7; font-size: 13px; }
.bubble.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; }
.chat-quick { padding: 0 12px 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chat-quick button { background: #f1f5f9; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer; }
.chat-quick button:hover { background: #e2e8f0; }
.setup-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.setup-card h4 { font-size: 14px; margin-bottom: 10px; }
.setup-card ol { margin-left: 18px; color: var(--muted); line-height: 2; font-size: 13px; }

/* ---------- Toast ---------- */
.toast { position: fixed; right: 24px; bottom: 24px; background: var(--slate); color: #fff; border-radius: 10px; padding: 12px 18px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13px; max-width: 360px; }
.toast.ok { background: #166534; }
.toast.err { background: #991b1b; }

/* 响应式 */
@media (max-width: 900px) {
  .chat-wrap { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .brand div, .side-user-info, .side-user .linkbtn { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item .txt { display: none; }
}

/* 筛选标签（立创自动匹配等页面） */
.chip { padding: 4px 12px; border: 1px solid var(--line); background: var(--card); border-radius: 14px; cursor: pointer; font-size: 12px; color: var(--muted); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
select.small, input.small { padding: 4px 8px; font-size: 12px; }
.warn { color: var(--orange); }

.ok { color: var(--green); }

