/* ============ 报价单系统 - 移动端优先自适应 ============ */
:root {
  --primary: #1a6fb5;
  --primary-dark: #145a94;
  --danger: #d64545;
  --bg: #f2f5f8;
  --card: #ffffff;
  --text: #232a33;
  --muted: #7a8694;
  --line: #e3e8ee;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(20, 40, 60, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  box-shadow: var(--shadow);
}
.brand {
  font-size: 17px; font-weight: 700; color: var(--primary);
  text-decoration: none; margin-right: 8px;
}
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a {
  color: var(--text); text-decoration: none;
  padding: 6px 12px; border-radius: 999px; font-size: 14px;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--primary); color: #fff; }

/* 导航下拉菜单 */
.nav-dropdown { position: relative; display: inline-flex; align-items: center; }
.nav-dropdown-toggle { cursor: pointer; }
.nav-dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0; z-index: 60;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 120px; padding: 4px 0;
}
.nav-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 4px;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block; padding: 8px 16px; border-radius: 0; font-size: 14px; white-space: nowrap;
}
.nav-dropdown-menu a:hover { background: var(--bg); }
.nav-dropdown-menu a.active { background: var(--primary); color: #fff; }

/* 浮动保存按钮（编辑页topbar内，主保存按钮滚出视口+有脏修改时显示） */
.float-save-btn {
  margin-left: auto;
  animation: floatSaveIn .2s ease;
  white-space: nowrap;
}
.float-save-btn.float-save-show {
  display: inline-flex !important;
}
@keyframes floatSaveIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 布局 ---------- */
.container { max-width: 1550px; margin: 0 auto; padding: 16px; }
.container.wide { max-width: 1680px; }
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px; margin-bottom: 10px;
}
.card-head h2 { margin-bottom: 0; }

/* ---------- 表单 ---------- */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.form-row .field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.field.grow { flex: 1; min-width: 220px; }
.field.align-end { justify-content: flex-end; }
label { font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; font-family: inherit; color: var(--text);
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 111, 181, .12);
}
textarea { resize: vertical; }
input[type="file"] { padding: 8px; }
input[type="search"] { max-width: 260px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline select { flex: 1; }

/* ---------- 首页：新建报价单 ---------- */
.gen-card h2 { margin-bottom: 4px; }
.gen-card > p.muted { margin-bottom: 12px; }
.gen-input-box {
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; margin-bottom: 12px; background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.gen-input-box.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,111,181,.12);
}
.gen-input-box textarea {
  border: none; border-radius: 0; resize: vertical;
}
.gen-input-box textarea:focus {
  box-shadow: inset 0 0 0 2px rgba(26,111,181,.15);
}
.gen-upload-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-top: 1px dashed var(--line); background: var(--bg);
}
.gen-input-box .img-previews {
  padding: 0 12px 8px; background: var(--bg);
}
.gen-action-row {
  display: flex; align-items: flex-end; gap: 12px;
}
.gen-model-field { flex: 0 1 300px; margin-bottom: 0; }
.gen-model-field .inline select { min-width: 0; }
.gen-btn {
  padding: 11px 32px; font-size: 15px; font-weight: 600;
  white-space: nowrap;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: 14px; cursor: pointer;
  text-decoration: none; transition: all .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: #f0c8c8; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 表格（小屏横向滚动） ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px;
  padding: 0 16px; }
.table { width: 100%; min-width: 860px; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  border-bottom: 1px solid var(--line); padding: 9px 10px;
  text-align: left; vertical-align: middle; white-space: nowrap;
}
.table th { color: var(--muted); font-weight: 600; font-size: 13px;
  background: var(--bg); }
.table tr:hover td { background: #f7fafc; }
.th-ops { width: 250px; text-align: right; }
.td-ops { text-align: right; white-space: nowrap; }
.td-ops .btn { margin-left: 4px; padding: 4px 8px; font-size: 12px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: #eef3f8; color: var(--primary);
}
.badge.warn { background: #fdf3e0; color: #b07814; }
.badge.done { background: #e5f6ec; color: #1c8a4d; }
.badge.ai { background: #efe8fc; color: #6a3fc9; }

/* ---------- 编辑页：网点页签 ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  padding: 7px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.panel { display: none; }
.panel.active { display: block; }
.sheet-note { margin-bottom: 12px; }

/* 明细编辑表 */
.panel .table-wrap { margin: 0; padding: 0; }
.edit-table { width: 100%; min-width: 1562px; border-collapse: collapse; font-size: 13px;
  table-layout: fixed; }
.edit-table th {
  background: var(--bg); color: var(--muted); font-weight: 600;
  padding: 7px 6px; border: 1px solid var(--line); text-align: center;
  position: sticky; top: 0;
}
.edit-table td { border: 1px solid var(--line); padding: 4px; }
.edit-table input {
  border: 1px solid transparent; border-radius: 6px; padding: 6px 8px;
  font-size: 13px; background: transparent; min-width: 0; width: 100%;
  box-sizing: border-box;
}
.edit-table input:hover { border-color: var(--line); }
.edit-table input:focus { background: #fff; border-color: var(--primary); }
.col-idx { width: 42px; text-align: center; color: var(--muted); }
.col-area { width: 84px; text-align: center; color: var(--primary); font-weight: 600; }
.col-sum { width: 108px; text-align: right; padding-right: 10px; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.grand-total {
  background: var(--primary); color: #fff; border-radius: 999px;
  padding: 5px 14px; font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.row-ops { width: 88px; text-align: center; white-space: nowrap; }
.row-ops button {
  border: none; background: none; color: var(--primary); cursor: pointer;
  font-size: 13px; padding: 2px 5px;
}
.row-ops button.del { color: var(--danger); }
/* 单价单元格：输入框 + "智能计算"复选框（勾选后单价锁定，改价须经遮罩层） */
.up-cell { display: flex; flex-direction: column; gap: 1px; }
.up-cell > input[data-f="unit_price"] { flex: 1; min-width: 0; }
/* 智能计算中：单价只读锁定，点击重新打开「智能计算单价」弹窗 */
.edit-table input.calc-locked {
  background: #edf4fc; border-color: var(--primary);
  color: var(--primary); font-weight: 600; cursor: pointer;
}
.edit-table input.calc-locked:hover { background: #e0edfb; }
.edit-table input.calc-locked:focus {
  outline: none; box-shadow: 0 0 0 2px rgba(26, 111, 181, .15);
}
.up-cell .calc-chk {
  display: inline-flex; align-items: center; gap: 3px; flex: none;
  white-space: nowrap; font-size: 10px; color: var(--primary);
  cursor: pointer; user-select: none; padding: 0 2px; align-self: flex-start;
}
.edit-table .up-cell .calc-chk input[type="checkbox"] {
  width: 12px; height: 12px; min-width: 12px; max-width: 12px;
  margin: 0; padding: 0; flex: none; accent-color: var(--primary);
  background: transparent; border: none; box-shadow: none;
}
/* 智能计算遮罩层：换算过程预览 */
.calc-pv {
  background: #fafbfc; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 8px 0 4px; font-size: 13px; line-height: 1.9;
}
.calc-pv .pv-line { color: var(--muted); }
.calc-pv .pv-final { font-weight: 600; color: var(--text); }
.calc-pv .pv-final b { color: var(--primary); font-size: 15px; }
.chk-line { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.chk-line input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--primary); }
.chk-line b { color: var(--primary); font-weight: 600; }
/* 订单AI预览计划行：可勾选执行项 */
.ai-plan-row {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px;
  background: #f7f9fb; border: 1px solid #eef1f5; border-radius: 8px;
  margin-bottom: 6px; cursor: pointer; font-size: 13px; line-height: 1.6;
}
.ai-plan-row input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--primary); margin-top: 2px; }
.ai-plan-row b { color: var(--primary); font-weight: 600; }
.ai-plan-row.muted { background: #fdfdfd; border-style: dashed; }
.ai-plan-row.muted input[type="checkbox"] { accent-color: #9aa4af; }
.ai-plan-row .ai-tag {
  flex: none; font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: #e8eef6; color: #4a6fa5; font-weight: 600; margin-right: 2px;
}
.ai-plan-row.muted .ai-tag { background: #f0f1f3; color: #8a94a0; }
/* 订单AI执行结果行 */
.ai-res {
  font-size: 13px; line-height: 1.7; padding: 6px 10px; border-radius: 6px;
  margin-bottom: 5px; background: #f7f9fb;
}
.ai-res.ok { background: #f0f8f1; color: #247a34; }
.ai-res.err { background: #fdf2f2; color: #b34242; }
/* 编辑页弹窗：附带捆绑商品说明块 */
.bundle-tip {
  background: #fafbfc; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 4px 0 8px; font-size: 13px;
  line-height: 1.8; color: var(--text);
}
/* 列宽分配（fixed 布局只认表头行）：全部列显式定宽，避免无宽列被挤压不可见；
   序号/宽/高/数量/面积/单位/单价/合计/操作固定，名称/型号/备注留足输入空间 */
.edit-table th:nth-child(1), .edit-table td:nth-child(1) { width: 40px; }
.edit-table th:nth-child(2), .edit-table td:nth-child(2) { width: 220px; }
.edit-table th:nth-child(3), .edit-table td:nth-child(3) { width: 300px; }
.edit-table th:nth-child(4), .edit-table td:nth-child(4),
.edit-table th:nth-child(5), .edit-table td:nth-child(5) { width: 86px; }
.edit-table th:nth-child(6), .edit-table td:nth-child(6) { width: 80px; }
.edit-table th:nth-child(7), .edit-table td:nth-child(7) { width: 92px; }
.edit-table th:nth-child(8), .edit-table td:nth-child(8) { width: 118px; }
.edit-table th:nth-child(9), .edit-table td:nth-child(9) { width: 148px; }
.edit-table th:nth-child(10), .edit-table td:nth-child(10) { width: 112px; }
.edit-table th:nth-child(11), .edit-table td:nth-child(11) { width: 180px; }
.edit-table th:nth-child(12), .edit-table td:nth-child(12) { width: 100px; }

/* ---------- 产品库 / 备注 ---------- */
.note-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px; background: #fff;
}
.note-card textarea { font-size: 14px; min-height: 72px; }
.note-card .note-title {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.model-list {
  background: var(--bg); border-radius: 8px; padding: 10px 12px;
  font-size: 13px; color: var(--muted); margin-top: 8px;
  max-height: 160px; overflow-y: auto;
}
#ai-table input {
  width: 100%; min-width: 120px; box-sizing: border-box;
  font-size: 13px; padding: 4px 6px;
}
#ai-table .row-no { text-align: center; color: var(--muted); }

/* ---------- 设置页：指定模型多选下拉 ---------- */
[hidden] { display: none !important; }
.ms { position: relative; }
.ms .ms-box {
  display: flex; align-items: center; gap: 2px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 2px 6px; cursor: pointer; min-height: 28px;
}
.ms .ms-box:focus-within {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26, 111, 181, .12);
}
.ms-chips {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  max-height: 76px; overflow-y: auto; flex: 1 1 0%; min-width: 0;
  scrollbar-width: thin;
}
.ms-chip {
  display: inline-flex; align-items: center; gap: 2px;
  max-width: 180px; background: #e8f0f8; color: var(--primary-dark);
  border-radius: 999px; padding: 1px 6px 1px 2px; font-size: 12px;
  white-space: nowrap; cursor: grab; user-select: none;
}
.ms-chip-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ms-chip-v { cursor: pointer; font-size: 12px; padding: 0 1px; opacity: .35; user-select: none; flex-shrink: 0; }
.ms-chip-v:hover { opacity: 1; }
.ms-chip-vision { background: #e0f5e8; }
.ms-chip-vision .ms-chip-v { opacity: 1; }
.ms-x { cursor: pointer; font-weight: 700; color: var(--muted); padding: 0 2px; flex-shrink: 0; }
.ms-x:hover { color: var(--danger); }
.ms-chip.dragging { opacity: .35; }
.ms-chip.drag-over-left { box-shadow: -2px 0 0 var(--primary); }
.ms-chip.drag-over-right { box-shadow: 2px 0 0 var(--primary); }
i.muted { font-style: normal; color: var(--muted); font-size: 11px; }
#ai-table .ms-search {
  flex: 0 0 auto; width: auto; min-width: 50px; max-width: 80px;
  border: none !important; box-shadow: none !important; outline: none;
  background: transparent; padding: 4px 2px; font-size: 13px; cursor: text;
}
.ms-caret { color: var(--muted); font-size: 11px; padding: 0 2px; flex-shrink: 0; }
.ms-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 9999;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 40, 60, .18); padding: 6px;
}
.ms-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.ms-tools .btn { padding: 2px 8px; font-size: 12px; }
.ms-tools a { font-size: 12px; color: var(--primary); cursor: pointer; text-decoration: none; }
.ms-tools a:hover { text-decoration: underline; }
.ms-filter {
  flex: 1; min-width: 80px; border: 1px solid var(--line); border-radius: 4px;
  padding: 2px 6px; font-size: 12px; outline: none; background: #fff;
}
.ms-filter:focus { border-color: var(--primary); }
.ms-opts { max-height: 240px; overflow-y: auto; }
.ms-opt-row {
  display: flex; align-items: center; gap: 4px; padding: 3px 4px;
  border-radius: 6px; font-size: 13px; cursor: grab;
}
.ms-opt-row:hover { background: rgba(0,0,0,.04); }
.ms-opt-row.dragging { opacity: .3; }
.ms-opt-row.drag-over { border-top: 2px solid var(--primary); }
.ms-opt-drag { color: var(--muted); font-size: 14px; opacity: .3; cursor: grab; user-select: none; flex-shrink: 0; letter-spacing: -1px; }
.ms-opt-row:hover .ms-opt-drag { opacity: .7; }
.ms-opt { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; cursor: pointer; font-weight: 400; }
.ms-opt span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#ai-table .ms-opt input { width: auto; min-width: 0; flex: 0 0 auto; accent-color: var(--primary); margin: 0; }
.ms-opt-vision { cursor: pointer; font-size: 14px; opacity: .25; user-select: none; padding: 0 2px; flex-shrink: 0; }
.ms-opt-vision:hover { opacity: .7; }
.ms-opt-vision-on { opacity: 1; color: #2e7d32; }
.ms-empty { font-size: 12px; color: var(--muted); padding: 6px; }
.img-previews { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.img-preview-item {
  position: relative; display: inline-block;
}
.img-preview-item img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line);
}
.img-del {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 13px; line-height: 18px;
  text-align: center; cursor: pointer; display: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.img-preview-item:hover .img-del { display: block; }
.img-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.7); display: flex;
  align-items: center; justify-content: center; cursor: zoom-out;
}
.img-overlay img {
  max-width: 90vw; max-height: 90vh; border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}
.doc-previews { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.doc-preview-item {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #f8f9fa; max-width: 280px;
}
.doc-preview-item .doc-icon { font-size: 20px; }
.doc-preview-item .doc-name {
  font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px;
}
.doc-preview-item .doc-size { font-size: 11px; }
.doc-preview-item:hover .img-del { display: block; }

/* ---------- 提示 / 弹窗 ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.flash.error { background: #fdecec; color: var(--danger); border: 1px solid #f5c6c6; }
.flash.success { background: #e5f6ec; color: #1c8a4d; border: 1px solid #bce8cd; }
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: rgba(30, 40, 50, .92); color: #fff; padding: 10px 20px;
  border-radius: 999px; font-size: 14px; z-index: 200;
  opacity: 0; pointer-events: none; transition: all .25s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 30, 40, .45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; max-width: 1080px; width: 100%;
  max-height: 88vh; overflow-y: auto; padding: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal h3 { font-size: 16px; margin-bottom: 6px; }
.modal .q-item { margin-bottom: 14px; }
.modal .q-item label { display: block; margin-bottom: 4px; white-space: pre-wrap; }
.modal .q-item textarea { min-height: 56px; }
.modal .cb-title { position: relative; padding-right: 28px; }
.modal-x {
  position: absolute; top: -2px; right: -2px; border: none; background: transparent;
  color: #8a94a0; font-size: 20px; line-height: 1; padding: 3px 7px 5px;
  border-radius: 6px; cursor: pointer;
}
.modal-x:hover { color: #222; background: rgba(0, 0, 0, .06); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.loading-line { color: var(--muted); font-size: 14px; padding: 10px 0; }

/* ---------- 登录 ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(160deg, #eaf2fa, #f5f8fb);
  padding: 16px;
}
.login-card {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  padding: 32px 28px; width: 100%; max-width: 380px;
}
.login-card h1 { font-size: 22px; text-align: center; color: var(--primary); margin-bottom: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-card p.muted { text-align: center; }

/* ---------- 通用 ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.wrap { flex-wrap: wrap; }
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 6px;
}
/* 表格加载中提示（深色版 spinner） */
.table-loading {
  text-align: center; padding: 40px 0; color: var(--muted); font-size: 14px;
}
.table-loading .spinner {
  border-color: rgba(59,172,237,.25); border-top-color: #3baced;
  width: 22px; height: 22px; vertical-align: -6px; margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .container { padding: 12px; }
  .card { padding: 14px; border-radius: 12px; }
  .form-row { gap: 10px; }
  .field.grow { min-width: 100%; }
  .btn-lg { width: 100%; }
  .card-head .btn-group { width: 100%; }
  .brand { font-size: 16px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .tab { flex-shrink: 0; }
}

/* ---------- 大升级：状态徽章 / 时间线 / 文件 / 订单 ---------- */
.badge.primary { background: #e3f0fd; color: #1c6fd0; }
.badge.muted { background: #eef1f4; color: #8a94a0; }
.badge.danger { background: #fde8e8; color: #c03a2f; }

.input-sm { padding: 6px 10px; font-size: 13px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--text); }
.input-sm.grow { flex: 1; min-width: 0; }

.link { color: var(--primary); text-decoration: none; }
.link:hover { text-decoration: underline; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
/* 子列可收缩：内部长表格（文件库等）走 .table-wrap 横向滚动，避免内容把页面撑宽 */
.two-col > * { min-width: 0; }
.two-col .table-wrap { margin: 0; padding: 0; }
.two-col .table { min-width: 0; }
.two-col h3 { margin: 6px 0 10px; font-size: 15px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* 时间线 */
.tl { border-left: 2px solid var(--line); margin: 4px 0 4px 6px; padding-left: 16px; }
.tl-item { position: relative; padding-bottom: 14px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { position: absolute; left: -21px; top: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--primary); }
.tl-head { display: flex; gap: 8px; align-items: baseline; }
.tl-head b { font-size: 14px; font-weight: 600; }
.tl-note { margin-top: 3px; font-size: 13px; color: var(--muted);
  background: #f7fafc; border-radius: 8px; padding: 6px 10px; white-space: pre-wrap; }

/* 文件库 */
.file-upload { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.file-upload input[type=file] { max-width: 260px; font-size: 13px; }
.file-upload .f-cat { flex: 0 0 auto; }
.file-upload .f-remark { flex: 1; min-width: 140px; }
.f-table th, .f-table td { font-size: 13px; }

.file-preview { margin-top: 12px; height: 62vh; }
.file-preview iframe { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* 订单状态按钮组 */
.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.st-btn { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px; color: var(--text); }
.st-btn:hover { border-color: var(--primary); color: var(--primary); }
.st-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 代办列表 */
.todo-list { list-style: none; margin: 6px 0 0; padding: 0; }
.todo-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--line); }
.todo-list li:last-child { border-bottom: none; }
.todo-item { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; cursor: pointer; }
.todo-item input { flex: 0 0 auto; width: auto; min-width: 0; max-width: 16px; padding: 0;
  margin: 0; border: none; }
.todo-item span { flex: 1; min-width: 0; word-break: break-all; }
.todo-list li.done .todo-item span { text-decoration: line-through; color: var(--muted); }

/* 订单列表 - 待办列高亮 + 展开行 */
.todo-td { cursor: pointer; white-space: nowrap; }
.todo-td.expanded { background: #e3f0fd; }
.todo-count { font-weight: 600; }
.todo-count.todo-pending { color: #c03a2f; }
.todo-count.todo-done { color: #1c8a4d; }
.todo-badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px; margin-left: 4px; font-weight: 600; }
.todo-badge.warn { background: #fdf3e0; color: #b07814; }
tr.todo-row > td { padding: 0 !important; background: #f8fafc; }
.todo-expand { padding: 12px 16px; border-top: 2px solid var(--primary); }
.todo-expand-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.todo-expand-head b { font-size: 14px; color: var(--primary-dark); }
.todo-expand-list { list-style: none; margin: 0; padding: 0; }
.todo-expand-item { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.todo-expand-item:last-child { border-bottom: none; }
.todo-expand-item.done .todo-item span { text-decoration: line-through; color: var(--muted); }
.todo-expand-item .badge.small { font-size: 11px; padding: 1px 6px; }

/* ============ 二轮升级：剩余天数 / 分组时间线 / 富文本 / 代办增强 ============ */
/* 剩余天数彩色 */
.badge.ok { background: #e5f6ec; color: #1c8a4d; }
.badge.overdue { background: #7a1f1a; color: #fff; }

/* 时间线分组段头 */
.tl-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #f2f6fa; border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 6px 10px; margin: 2px 0 10px; font-size: 13px; }
.tl-group .tl-g-label { font-weight: 700; color: var(--text); }
.tl-group .tl-g-marker { margin-left: auto; font-size: 12px; color: var(--muted); }
.tl-g-items { padding-left: 2px; }
.tl-group.flash { animation: tlflash 1.2s ease 2; }
@keyframes tlflash {
  0%, 100% { background: #f2f6fa; }
  50% { background: #fdeaa8; border-left-color: #e0a800; }
}

/* 富文本执行记录 */
.tl-html { margin-top: 6px; font-size: 13px; line-height: 1.7; color: var(--text);
  background: #fbfcfd; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  max-width: 720px; word-break: break-word; }
.tl-html img { max-width: 100%; height: auto; border-radius: 6px; }
.tl-html a { color: var(--primary); }
.tl-ops { margin-left: auto; display: inline-flex; gap: 6px; }
.tl-ops .btn { padding: 2px 10px; font-size: 12px; }

/* 时间线贴图缩略图 */
.tl-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tl-thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); cursor: zoom-in; transition: transform .15s; }
.tl-thumb:hover { transform: scale(1.06); box-shadow: 0 2px 8px rgba(0,0,0,.18); }

/* 图片放大 */
.lightbox { display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 90vw; max-height: 85vh; border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,.4); }

/* 中等宽弹窗（产品编辑等字段较多的表单） */
.modal.med { width: min(960px, 94vw); max-height: 90vh; overflow-y: auto; }

/* 宽弹窗（富文本编辑器 / 文件预览） */
.modal.wide { width: min(960px, 94vw); max-height: 94vh; overflow-y: auto; }
/* 文件预览专用：弹窗不滚动，由 iframe 内部适配 */
.modal.wide.pv-modal { overflow: hidden; padding-bottom: 12px; }
.we-wrap { border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: #fff; margin-top: 10px; }
.we-wrap .w-e-toolbar { border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.we-wrap .w-e-text-container { height: 320px !important; min-height: 200px; }
.we-wrap .w-e-text-container [data-slate-editor] { padding: 10px 14px; font-size: 14px; }

/* 代办分组与日期 */
.todo-group { display: flex; align-items: center; gap: 8px; padding: 10px 4px 6px !important;
  border-bottom: none !important; }
.todo-range { flex: 0 0 auto; font-size: 12px; color: var(--muted);
  background: #f2f6fa; border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.todo-range.warn { background: #fdf3e0; color: #b07814; }
.todo-range.over { background: #fde8e8; color: #c03a2f; font-weight: 600; }

/* ---------- 订单进度：垂直环节时间线 ---------- */
.step-tip { display: inline-block; padding: 0 8px; border-radius: 999px;
  font-size: 12px; background: #e5f6ec; color: #1c8a4d; }
.step-tip.cur { background: #e6f1fe; color: #1f5fa8; }
.step-tip.todo { background: #f5f6f7; color: #9aa1a9; }

.env-tl { margin-top: 12px; }
.env-item { position: relative; padding-left: 30px; }
.env-item::before { content: ''; position: absolute; left: 11px; top: 30px; bottom: -2px;
  width: 2px; background: var(--line); }
.env-item:last-child::before { display: none; }
.env-dot { position: absolute; left: 3px; top: 14px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; border: 4px solid #cfd6dd; }
.env-item.done .env-dot { border-color: #1a9c5c; }
.env-item.cur .env-dot { border-color: var(--primary); box-shadow: 0 0 0 5px rgba(26, 111, 181, .15); }
.env-item.todo .env-dot { border-color: #cfd6dd; background: #f5f6f7; }
.env-item.hist .env-dot { border-color: #cfd6dd; background: #fff; }

.env-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin: 4px 0; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; transition: all .15s; }
.env-head:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.env-item.done .env-head { background: #f5fbf7; }
.env-item.cur .env-head { background: #eef5fc; border-color: #b0d0f2; }
.env-item.todo .env-head { background: #fafbfc; }
.env-item.hist .env-head { background: #fafbfc; }
.env-item.active .env-head { outline: 2px solid var(--primary); outline-offset: 1px; }
.env-name { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 150px; }
.env-item.todo .env-name b { color: #9aa1a9; }
.env-time-wrap { display: flex; align-items: center; gap: 6px; }
.env-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.env-time-edit { padding: 1px 8px; font-size: 12px; }
.env-meta { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.env-switch { flex: 0 0 auto; }

.env-body { margin: 6px 0 14px 0; }
.env-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
@media (max-width: 980px) { .env-grid { grid-template-columns: 1fr; } }
.env-note, .env-todo { background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-width: 0; }
.env-pane-head { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px; }
.env-pane-head h4 { margin: 0; font-size: 14px; color: var(--text); }

/* 内嵌富文本编辑器 */
.rec-editor { margin-top: 12px; }
.rec-editor-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.rec-editor .we-wrap { margin-top: 0; }
.rec-editor .w-e-text-container { height: 240px !important; min-height: 150px; }
#rec-ops { margin-top: 10px; }

/* ---------- 记账 / 收款进度 ---------- */
.ledger-overview { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 4px; }
@media (max-width: 1100px) { .ledger-overview { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .ledger-overview { grid-template-columns: repeat(2, 1fr); } }
.lv-item { background: #f7fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.lv-label { font-size: 12px; color: var(--muted); }
.lv-num { font-size: 18px; font-weight: 700; color: var(--text); }
.lv-num.in { color: #1a9c5c; }
.lv-num.out { color: #c03a2f; }
.lv-num.over { color: #b00020; text-decoration: line-through; }
.lv-item .btn { align-self: flex-start; }

/* 进度条（详情页） */
.pay-progress { margin-top: 12px; }
.pp-bar { height: 10px; border-radius: 999px; background: #e8edf2; overflow: hidden; }
.pp-fill { height: 100%; border-radius: 999px; background: var(--primary);
  transition: width .4s ease; min-width: 0; }
.pp-fill.full { background: #1a9c5c; }
.pp-label { display: flex; align-items: baseline; gap: 10px; margin-top: 6px; }
.pp-pct { font-size: 16px; font-weight: 700; color: var(--primary); }
.pp-pct.full { color: #1a9c5c; }

/* 记账记录列表 */
.ledger-list { list-style: none; margin: 8px 0 0; padding: 0; }
.ledger-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ledger-list li:last-child { border-bottom: none; }
.ld-date { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.ld-cat { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.ld-amount { font-weight: 700; font-size: 14px; flex: 0 0 auto; }
.ld-amount.in { color: #1a9c5c; }
.ld-amount.out { color: #c03a2f; }
.ld-note { flex: 1; min-width: 120px; font-size: 13px; color: var(--muted); word-break: break-all; }
.ledger-list .btn { flex: 0 0 auto; }

/* 列表页收款进度 */
.pay-cell { display: flex; align-items: center; gap: 6px; min-width: 140px; }
.pay-mini { flex: 1; height: 22px; border-radius: 999px; background: #e8edf2;
  overflow: hidden; position: relative; }
.pay-mini-fill { height: 100%; border-radius: 999px; background: #3baced; transition: width .3s; }
.pay-mini-fill.full { background: #1a9c5c; }
.pay-mini-pct { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  color: #232a33; text-shadow: 0 0 3px rgba(255,255,255,.8); pointer-events: none; }
.pay-mini-pct.ok { color: #1a9c5c; }
.pay-ratio { font-size: 12px; font-weight: 600; color: var(--primary); white-space: nowrap; flex-shrink: 0; }
.pay-ratio.ok { color: #1a9c5c; }

/* ---------- 三合一：状态/时间线/代办 ---------- */
#st-current { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#st-current .badge { font-size: 13px; padding: 4px 10px; }
.tl-todos { background: #f7fafc; border: 1px dashed var(--line); border-radius: 10px;
  padding: 6px 12px; margin: 4px 0 8px; }
.tl-todos.empty { background: transparent; border-style: dashed; padding: 2px 12px; }
.tl-todos-head { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.tl-todos-head .badge { font-size: 12px; }
.tl-todo-add { margin-left: auto; padding: 2px 10px; font-size: 12px; white-space: nowrap; }
.tl-todos .todo-list { margin: 4px 0 0; }
.tl-todos .todo-list li { padding: 5px 2px; }
.tl-g-items { margin-bottom: 4px; }

/* 附带捆绑选择（产品库） */
.bundle-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; background: #fafbfc;
  display: flex; flex-direction: column; gap: 4px; }
.bundle-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 5px 8px; border-radius: 6px; background: #fff;
  border: 1px solid var(--line); }
.bundle-line:hover { border-color: var(--primary); }
.bundle-line input[type="checkbox"] { width: 16px; height: 16px;
  min-width: 16px; max-width: 16px; margin: 0; padding: 0;
  accent-color: var(--primary); box-shadow: none; }
.bundle-name { font-weight: 600; color: var(--text); font-size: 14px; white-space: nowrap; }
.bundle-meta { flex: 1; min-width: 0; }
.bundle-qty { width: 100px; min-width: 100px; padding: 5px 8px; font-size: 13px;
  text-align: center; }
.bundle-price { width: 210px; min-width: 210px; padding: 5px 8px; font-size: 13px; }

/* ---------- 订单一级阶段（2026-09：阶段+二级状态） ---------- */
.badge.stage { background: #eef1f5; color: #4a5568; border: 1px solid #d5dbe3; font-weight: 600; }
.env-chain-wrap { flex: 1 1 auto; min-width: 0; }
.env-subchain { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.env-subchip { font-size: 12px; line-height: 1; padding: 4px 10px; border-radius: 999px;
  background: #f2f6fa; color: #66707a; border: 1px solid #dfe5ec; white-space: nowrap; }
.env-item.todo .env-subchip { background: #f5f6f7; color: #9aa1a9; }
.env-subchip.cur { background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 600; }

.env-subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.sub-chip { padding: 5px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: #4a5568; font-size: 13px; cursor: pointer; transition: all .15s; }
.sub-chip:hover { border-color: var(--primary); color: var(--primary); }
.sub-chip.active { background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 600; }
/* 真实当前状态的 chip（仅当查看目标不是它时可见差异；切换查看不改变订单状态） */
.sub-chip.curst:not(.active) { background: #f0f6fc; border-color: var(--primary); color: var(--primary); }
.cur-tag { font-style: normal; font-size: 10px; background: var(--primary); color: #fff;
  border-radius: 999px; padding: 1px 6px; margin-left: 5px; vertical-align: 1px; }

/* 切换状态弹窗（阶段 → 二级 chips） */
.sw-picker { display: grid; gap: 10px; margin: 12px 0 4px; max-height: 46vh; overflow-y: auto; }
.sw-block { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fafbfc; }
.sw-block-name { font-weight: 600; font-size: 13px; color: #4a5568; margin-bottom: 8px; }
.sw-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sw-chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: #3d4650; font-size: 13px; cursor: pointer; transition: all .12s; }
.sw-chip:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.sw-chip.sel { background: #8bc34a; border-color: #8bc34a;
  color: #fff; font-weight: 600; }
.sw-chip.cur { background: #e6f1fe; border-color: #b0d0f2; color: var(--primary);
  font-weight: 600; cursor: pointer; }

/* 富文本笔记：拖拽文件到编辑区时的落点提示 */
.we-content.pd-over { outline: 2px dashed var(--primary);
  outline-offset: -2px; border-radius: 4px; }

/* ============ AI智能助手 - 聊天页面 ============ */
.chat-page { max-width: 100% !important; padding: 0 !important; }
.chat-layout { display: flex; height: calc(100vh - 52px); overflow: hidden; position: relative; }

/* 左侧会话列表 */
.chat-sidebar { width: 240px; min-width: 240px; background: #f7f8fa;
  border-right: 1px solid #e3e8ee; display: flex; flex-direction: column; overflow: hidden; }
.chat-sidebar.sidebar-hidden { display: none; }
.sidebar-header { padding: 12px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #e3e8ee; }
.sidebar-header h3 { margin: 0; font-size: 14px; }
.sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item { padding: 10px 12px; border-radius: 8px; cursor: pointer;
  margin-bottom: 4px; position: relative; transition: background .15s; }
.session-item:hover { background: #edf0f5; }
.session-item.active { background: #e6f1fe; }
.session-title { font-size: 13px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.session-meta { font-size: 11px; color: #8896a7; margin-top: 2px; }
.session-actions { position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: none; gap: 4px; }
.session-item:hover .session-actions { display: flex; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 2px 4px;
  font-size: 14px; border-radius: 4px; }
.btn-icon:hover { background: #ddd; }

/* 主聊天区 */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.chat-toolbar { padding: 6px 12px; border-bottom: 1px solid #e3e8ee;
  display: flex; align-items: center; gap: 6px; background: #fff; flex-shrink: 0; }
.chat-toolbar #chatTitle { flex: 1; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chat-model-select { padding: 3px 6px; border: 1px solid #d0d7de; border-radius: 4px;
  font-size: 12px; max-width: 140px; flex-shrink: 0; }
.chat-toolbar .btn-sm { flex-shrink: 0; white-space: nowrap; }

/* 消息区 */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 20px; background: #fafbfc; }
.chat-welcome { text-align: center; padding: 60px 20px; color: #57606a; }
.chat-welcome h2 { font-size: 24px; margin-bottom: 8px; }
.chat-welcome p { color: #8896a7; margin-bottom: 20px; }
.chat-quick-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* 消息气泡 */
.chat-msg { display: flex; gap: 10px; margin-bottom: 16px; max-width: 85%; }
.chat-msg-user { margin-left: auto; flex-direction: row-reverse; }
.chat-msg-avatar { width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; background: #f0f2f5; }
.chat-msg-body { flex: 1; min-width: 0; }
.chat-msg-user .chat-msg-body { align-items: flex-end; }
.chat-msg-text { background: #fff; padding: 10px 14px; border-radius: 12px;
  font-size: 14px; line-height: 1.6; word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.chat-msg-user .chat-msg-text { background: #e6f1fe; }
.chat-msg-images { margin-bottom: 6px; }
.chat-msg-img { max-width: 200px; max-height: 150px; border-radius: 8px; cursor: pointer;
  margin-right: 4px; }
.chat-msg-text a { color: var(--primary); text-decoration: underline; }

/* Markdown 渲染样式 */
.chat-msg-text h1,.chat-msg-text h2,.chat-msg-text h3,.chat-msg-text h4,
.chat-msg-text h5,.chat-msg-text h6 { margin: 10px 0 6px; font-weight: 600; line-height: 1.3; }
.chat-msg-text h1 { font-size: 1.4em; }
.chat-msg-text h2 { font-size: 1.25em; }
.chat-msg-text h3 { font-size: 1.1em; }
.chat-msg-text p { margin: 6px 0; }
.chat-msg-text ul,.chat-msg-text ol { margin: 6px 0; padding-left: 22px; }
.chat-msg-text li { margin: 3px 0; }
.chat-msg-text blockquote { border-left: 3px solid #d0d7de; padding: 4px 12px; margin: 8px 0;
  color: #57606a; background: #f6f8fa; border-radius: 0 6px 6px 0; }
.chat-msg-text hr { border: none; border-top: 1px solid #d0d7de; margin: 10px 0; }
.chat-msg-text table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.chat-msg-text th,.chat-msg-text td { border: 1px solid #d0d7de; padding: 6px 10px; text-align: left; }
.chat-msg-text th { background: #f6f8fa; font-weight: 600; }
.chat-msg-text tr:nth-child(even) { background: #f6f8fa; }
.chat-msg-text img { max-width: 100%; border-radius: 6px; }
.chat-msg-text strong { font-weight: 600; }
.chat-msg-text em { font-style: italic; }
.chat-msg-text del { text-decoration: line-through; color: #57606a; }

/* 代码块 */
.chat-msg-text pre { background: #1e1e2e; color: #cdd6f4; padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: 13px; margin: 8px 0; }
.chat-msg-text pre code { background: none; padding: 0; border-radius: 0; color: inherit; font-size: inherit; }
.chat-msg-text code { background: #f0f2f5; padding: 2px 6px; border-radius: 4px;
  font-size: 13px; color: #d73a49; }
.chat-code-block { background: #1e1e2e; color: #cdd6f4; padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: 13px; margin: 8px 0; }
.chat-code-inline { background: #f0f2f5; padding: 2px 6px; border-radius: 4px;
  font-size: 13px; color: #d73a49; }

/* 输入区 */
.chat-input-area { padding: 12px 16px; border-top: 1px solid #e3e8ee; background: #f8f9fa; }
.chat-images-preview { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.chat-img-preview { position: relative; }
.chat-img-preview img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid #e3e8ee; }
.chat-img-remove { position: absolute; top: -4px; right: -4px; background: #e74c3c; color: #fff;
  border: none; border-radius: 50%; width: 18px; height: 18px; font-size: 10px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; }
.chat-input-row { display: flex; align-items: center; background: #fff;
  border: 1px solid #d0d7de; border-radius: 12px; padding: 4px 6px 4px 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); transition: border-color .2s, box-shadow .2s; }
.chat-input-row:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(9,105,218,.12); }
.chat-img-btn { cursor: pointer; font-size: 18px; padding: 6px; border-radius: 6px;
  user-select: none; color: #666; line-height: 1; }
.chat-img-btn:hover { background: #f0f2f5; color: #333; }
#chatInput { flex: 1; border: none; padding: 8px 8px; font-size: 14px; resize: none;
  min-height: 36px; max-height: 120px; font-family: inherit; line-height: 1.5;
  background: transparent; }
#chatInput:focus { outline: none; box-shadow: none; }
#chatSendBtn { flex-shrink: 0; border-radius: 8px; padding: 6px 16px; font-size: 13px;
  white-space: nowrap; }

/* ============ 右下角智能客服浮窗 ============ */
#chat-widget-btn { position: fixed; bottom: 24px; right: 24px; width: 52px; height: 52px;
  border-radius: 50%; background: var(--primary); color: #fff; font-size: 24px;
  border: none; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.2);
  z-index: 9999; display: flex; align-items: center; justify-content: center;
  transition: transform .2s; }
#chat-widget-btn:hover { transform: scale(1.1); }
#chat-widget-panel { position: fixed; bottom: 24px; right: 24px; width: 420px; height: 560px;
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.18); z-index: 10000;
  display: flex; flex-direction: column; overflow: hidden; background: #fff; }
.chat-widget-hidden { display: none !important; }
.chat-widget-header { padding: 10px 16px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.chat-widget-header button { background: none; border: none; color: #fff;
  font-size: 18px; cursor: pointer; }
.chat-widget-actions { display: flex; gap: 4px; }
.chat-widget-actions button { background: none; border: none; color: #fff;
  font-size: 16px; cursor: pointer; padding: 2px 4px; border-radius: 3px; }
.chat-widget-actions button:hover { background: rgba(255,255,255,.2); }
#chat-widget-panel.chat-widget-fullscreen {
  width: 100vw !important; height: 100vh !important;
  bottom: 0 !important; right: 0 !important; border-radius: 0; }
.chat-widget-body { flex: 1; overflow: hidden; }

/* 移动端适配 */
@media (max-width: 768px) {
  .chat-sidebar { display: none; }
  .chat-sidebar.sidebar-mobile-open { display: flex; position: absolute; left: 0; top: 0; bottom: 0; z-index: 1001; width: 280px; box-shadow: 2px 0 12px rgba(0,0,0,.18); background: #f7f8fa; }
  .chat-sidebar.sidebar-hidden { display: none; }
  .sidebar-overlay { position: absolute; inset: 0; z-index: 1000; background: rgba(0,0,0,.35); }
  .chat-layout { height: calc(100vh - 52px); }
  .chat-msg { max-width: 95%; }
  #chat-widget-panel { width: calc(100vw - 16px); height: calc(100vh - 80px);
    right: 8px; bottom: 8px; border-radius: 8px; }
  .chat-toolbar { flex-wrap: wrap; gap: 4px; padding: 4px 8px; }
  .chat-toolbar #chatTitle { min-width: 60px; font-size: 13px; }
  .chat-model-select { max-width: 100px; font-size: 11px; }
}

/* ===== embed模式：iframe嵌入时隐藏导航栏和浮窗 ===== */
html.chat-embed .topbar,
html.chat-embed #chat-widget-btn,
html.chat-embed #chat-widget-panel { display: none !important; }
html.chat-embed body { margin: 0; padding: 0; }
html.chat-embed .container { padding-top: 0 !important; height: 100vh; overflow: hidden; }
html.chat-embed .chat-layout { height: 100vh; }
html.chat-embed .chat-toolbar { padding: 4px 8px; gap: 4px; }
html.chat-embed .chat-toolbar #chatTitle { font-size: 13px; }
html.chat-embed .chat-model-select { max-width: 90px; font-size: 11px; padding: 2px 4px; }
html.chat-embed .chat-toolbar .btn-sm { font-size: 11px; padding: 2px 6px; }
html.chat-embed .chat-input-area { padding: 8px 10px; }
html.chat-embed .chat-input-row { border-radius: 8px; padding: 3px 3px 3px 6px; }
html.chat-embed #chatInput { font-size: 13px; min-height: 32px; padding: 6px 6px; }
html.chat-embed #chatSendBtn { font-size: 12px; padding: 5px 12px; }
