:root{
  --bg:#f7f6f3; --card:#fff; --line:#e3e0d9; --text:#2b2b2b; --muted:#6f6a63;
  --accent:#2f5d50; --danger:#a63b32; --ok:#2f6b4f;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{background:var(--bg);color:var(--text);
  font:14px/1.6 -apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif}

/* ---- 顶栏 ---- */
.topbar{display:flex;align-items:center;justify-content:flex-end;gap:24px;
  padding:0 20px;height:46px;background:#fff;border-bottom:1px solid var(--line)}
.who{display:flex;align-items:center;gap:10px;margin:0;font-size:13px;color:var(--muted)}
.who button{font:inherit;font-size:13px;padding:5px 11px;border:1px solid var(--line);
  background:#fff;border-radius:6px;color:var(--muted);cursor:pointer;
  display:inline-flex;align-items:center;gap:5px}
.who button:hover{background:#f4f2ed}

/* ---- 页面 ---- */
.page{max-width:1180px;margin:0 auto;padding:22px 20px 60px}
h1{font-size:18px;font-weight:600;margin:0 0 4px}
h2{font-size:15px;font-weight:600;margin:0 0 10px}
.sub{color:var(--muted);font-size:13px;margin:0 0 18px}
.card{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:18px 20px;margin-bottom:14px}

/* ---- 工具条 ---- */
.toolbar{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin-bottom:14px}
.toolbar .grow{flex:1 1 auto}
.count{color:var(--muted);font-size:13px}

/* ---- 表格 ---- */
table{width:100%;border-collapse:collapse;background:#fff;
  border:1px solid var(--line);border-radius:10px;overflow:hidden}
th,td{padding:8px 12px;text-align:left;border-bottom:1px solid #f0eee9;font-size:13.5px}
th{background:#faf9f6;color:var(--muted);font-weight:500;white-space:nowrap}
tbody tr:hover{background:#fbfaf7}
tbody tr:last-child td{border-bottom:none}
td.num,th.num{text-align:right;font-variant-numeric:tabular-nums}
td.code{font-family:ui-monospace,Menlo,monospace;font-size:13px}
.empty{text-align:center;color:var(--muted);padding:32px}

/* ---- 表单 ---- */
label{display:block;font-size:13px;color:var(--muted);margin:12px 0 5px}
input:not([type]),input[type=text],input[type=password],input[type=number],input[type=email],
input[type=date],select,textarea{
  width:100%;padding:8px 10px;border:1px solid var(--line);border-radius:7px;
  font:inherit;font-size:14px;background:#fff;color:var(--text)}
input:focus,select:focus,textarea:focus{outline:2px solid #cfdcd5;outline-offset:1px;border-color:#b9cbc2}
textarea{resize:vertical;min-height:60px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:0 16px}
button{font:inherit;font-size:13.5px;padding:8px 16px;border-radius:7px;
  border:1px solid var(--line);background:#fff;color:var(--text);cursor:pointer}
button:hover{background:#f4f2ed}
button.primary{background:var(--accent);border-color:var(--accent);color:#fff}
button.primary:hover{background:#28503f}
button.danger{color:var(--danger);border-color:#e8d3d0}
button.danger:hover{background:#fbf1f0}
button.mini{padding:4px 10px;font-size:12.5px}
.actions{display:flex;gap:8px;margin-top:18px}
.hint{color:var(--muted);font-size:12.5px;margin-top:6px}
.err{background:#fbf0ef;border:1px solid #eed6d3;color:var(--danger);
  padding:9px 12px;border-radius:7px;font-size:13px;margin:0 0 4px}
.ok{background:#eef4f0;border:1px solid #d6e5dc;color:var(--ok);
  padding:9px 12px;border-radius:7px;font-size:13px;margin:0 0 14px}

/* ---- 登录 ---- */
.login-body{min-height:100vh;display:flex;align-items:center;justify-content:center}
.login-card{width:330px;background:#fff;border:1px solid var(--line);
  border-radius:12px;padding:30px 28px 28px;box-shadow:0 1px 3px rgba(0,0,0,.03)}
.login-card label:first-of-type{margin-top:0}
.login-card button{width:100%;padding:10px;margin-top:24px;
  background:var(--accent);border-color:var(--accent);color:#fff;font-size:14px}
.login-card button:hover{background:#28503f}

/* ---- 筛选区 ---- */
.filters{display:flex;flex-wrap:wrap;gap:10px 14px;align-items:flex-end;
  background:#fff;border:1px solid var(--line);border-radius:10px;
  padding:14px 16px;margin-bottom:14px}
.fitem{display:flex;flex-direction:column;gap:4px}
.fitem label{font-size:12px;color:var(--muted);margin:0;display:block}
.fitem input,.fitem select{width:138px;padding:6px 8px;font-size:13px;border-radius:6px}
.fitem select{height:31px}

/* ---- 密集表格（列多时横向滚动） ---- */
.table-wrap{overflow-x:auto;background:#fff;border:1px solid var(--line);border-radius:10px}
.table-wrap table{border:none;border-radius:0;overflow:visible}  /* overflow:hidden 会让 sticky 列失效 */
table.dense th,table.dense td{padding:7px 9px;font-size:12.5px;white-space:nowrap}
table.dense tbody tr:hover{background:#fbfaf7}
table.dense .note{white-space:normal;max-width:220px;color:var(--muted);font-size:12px}

/* 有值高亮：还原原系统两种色（ui-state-highlight 黄 / ui-state-active 蓝）
   FX  返修 → 黄    FDH 返单 → 蓝，TH 原系统无高亮 */
.hl{background:#fdf3d8}
.hl-fx{background:#fdf3d8}
.hl-fdh{background:#e4eefa}

/* ---- 自制确认弹窗（替代原生 confirm） ---- */
.modal-mask{position:fixed;inset:0;background:rgba(43,43,43,.34);
  display:flex;align-items:center;justify-content:center;z-index:50;
  backdrop-filter:blur(1px)}
.modal-mask[hidden]{display:none}
.modal{width:372px;background:#fff;border-radius:12px;padding:24px 26px 20px;
  box-shadow:0 16px 48px rgba(0,0,0,.18);animation:pop .12s ease-out}
@keyframes pop{from{transform:scale(.97);opacity:.6}to{transform:scale(1);opacity:1}}
.modal h3{font-size:15px;font-weight:600;margin:0 0 10px}
.modal p{color:var(--muted);font-size:13px;line-height:1.75;margin:0 0 22px}
.modal-actions{display:flex;gap:10px}
.modal-actions button{flex:1;padding:9px 0;font-size:13.5px}
button.danger-solid{background:var(--danger);border-color:var(--danger);color:#fff}
button.danger-solid:hover{background:#8f322b}

/* ---- 导出弹窗（列选择） ---- */
.modal-wide{width:560px}
.cols{display:flex;gap:28px;margin:2px 0 20px}
.col{flex:1;display:flex;flex-direction:column;gap:9px}
.col label{display:flex;align-items:center;gap:7px;font-size:13.5px;
  color:var(--text);margin:0;cursor:pointer;line-height:1.5}
.col input[type=checkbox]{width:15px;height:15px;margin:0;flex:none;
  accent-color:var(--accent);cursor:pointer}

/* ---- 折扣待确认：整行淡底 + 左侧竖条 ----
   与单元格级的 .hl 黄底分层：行级提示「有事情要处理」，单元格级提示「这项有值」 */
/* 行级高亮：zk_check = 1 的行整行浅蓝 + 左侧蓝竖条
   浅底配深字，行内按钮保持原有样式不受影响 */
table.dense tbody tr.is-marked{--rb:#c2dafe;--rbh:#aacdfd;--rbar:#0d6efd}
body.list-full .table-wrap tbody tr.is-marked,
table.dense tbody tr.is-marked{background:var(--rb)}
body.list-full .table-wrap tbody tr.is-marked:hover,
table.dense tbody tr.is-marked:hover{background:var(--rbh)}
table.dense tbody tr.is-marked td:first-child{box-shadow:inset 5px 0 0 var(--rbar)}
table.dense tbody tr.is-marked td:last-child{background:var(--rb)}
table.dense tbody tr.is-marked:hover td:last-child{background:var(--rbh)}

/* 固定在左右两端的列（编辑 / 删除）背景跟随行色 */
body.list-full .table-wrap tbody tr.is-marked td:first-child{background:var(--rb)}
body.list-full .table-wrap tbody tr.is-marked:hover td:first-child{background:var(--rbh)}

/* ---- 合计行 ---- */
table.dense tfoot td{background:#f7f5f0;font-weight:600;color:var(--text);
  border-top:2px solid #ddd9d1;border-bottom:none;padding:9px}

/* ---- 操作列固定在右侧：横向滚动时删除按钮始终可见 ---- */
table.dense th:last-child,
table.dense td:last-child{
  position:sticky;
  right:0;
  background:#fff;
  box-shadow:-1px 0 0 0 var(--line);
}
table.dense thead th:last-child{background:#faf9f6;z-index:3}
table.dense tbody td:last-child{z-index:2}
table.dense tbody tr:hover td:last-child{background:#fbfaf7}
/* 待确认行的固定列跟随行底色，否则白块会切断整行高亮 */
table.dense tfoot td:last-child{background:#f7f5f0}

/* ---- 列间竖线：与横线同色，最后一列由固定列的阴影线承担边界 ---- */
table.dense th,table.dense td{border-right:1px solid #f0eee9}
table.dense th:last-child,table.dense td:last-child{border-right:none}
table.dense tfoot td{border-right:1px solid #e6e2da}
table.dense tfoot td:last-child{border-right:none}

/* ---- 添加表单：FX / FDH 输入框淡底，与列表的两种高亮色对应 ---- */
.fx-cell input{background:#fdfaf2}
.fdh-cell input{background:#f4f8fd}

/* ---- 添加弹窗（表单型） ---- */
.modal-form{width:760px;max-height:88vh;overflow-y:auto}
.modal-form h3{margin-bottom:14px}
.modal-form .grid{grid-template-columns:repeat(3,1fr);gap:0 16px;margin-bottom:2px}
.modal-form label{margin-top:6px}
.modal-form .err{margin:10px 0 0}
/* 内容高于视口时按钮吸底，不用滚到底才能保存 */
.modal-form .modal-actions{position:sticky;bottom:0;margin:16px 0 0;
  padding:14px 0;background:#fff;border-top:1px solid var(--line)}
.modal-form .modal-actions button{flex:none;min-width:96px;padding:9px 22px}

/* ---- 客户名称自动补全下拉 ---- */
.ac-list{position:absolute;top:100%;left:0;right:0;z-index:6;
  margin:2px 0 0;padding:4px;list-style:none;background:#fff;
  border:1px solid var(--line);border-radius:8px;
  box-shadow:0 8px 24px rgba(0,0,0,.12);max-height:224px;overflow-y:auto}
.ac-list li{padding:7px 10px;border-radius:5px;cursor:pointer;font-size:13.5px;
  color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ac-list li:hover,.ac-list li.on{background:#eaf0ed;color:var(--accent)}

/* 只读的计算字段 */
input[readonly]{background:#f7f5f0;color:var(--muted);cursor:default}
input[readonly]:focus{outline:none;border-color:var(--line)}

/* ---- 添加弹窗：左表单 / 右历史 ---- */
.modal-split{width:min(1180px,94vw);max-height:92vh}
.split{display:flex;gap:22px;align-items:flex-start}
.split form{flex:1;min-width:0}
.history{width:400px;flex:none;border-left:1px solid var(--line);padding-left:20px;
  max-height:68vh;overflow-y:auto}
.history h4{font-size:13px;font-weight:500;color:var(--muted);margin:0 0 10px}
/* 固定列宽：日期与金额不换行，备注占剩余宽度并两行截断 */
.hist-table{width:100%;border:none;border-radius:0;border-collapse:collapse;
  table-layout:fixed;font-size:12px}
.hist-table th{background:transparent;color:var(--muted);font-weight:500;
  padding:6px 6px;border-bottom:1px solid var(--line);border-right:none;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hist-table th:nth-child(1){width:96px}
.hist-table th:nth-child(2){width:88px;text-align:right}
.hist-table td{padding:7px 6px;border-bottom:1px solid #f2f0ec;
  border-right:none;vertical-align:top;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hist-table td.num{text-align:right}
.hist-table .note{color:var(--muted);white-space:normal;word-break:break-all;
  line-height:1.5;max-height:3em;overflow:hidden}
.hist-empty{color:var(--muted);font-size:13px;text-align:center;padding:44px 0;margin:0}

/* 编辑列在最前、删除列在最后，物理隔开防误点 */
td.ops-first{white-space:nowrap;padding-right:6px}
td.ops{white-space:nowrap;padding-right:12px}
td.ops .ops-inner{display:flex;align-items:center;justify-content:center}
/* 删除列表头居中；整列收窄到刚好放一个按钮 */
table.dense th.ops-col{text-align:center;padding-left:4px;padding-right:4px}
table.dense td.ops{padding-left:4px;padding-right:4px}
td.ops form{margin:0}

/* 编辑列固定在左侧，横向滚动时仍可点 */
body.list-full .table-wrap thead th:first-child,
body.list-full .table-wrap tbody td:first-child{
  position:sticky;left:0;z-index:3;background:#fff;
  box-shadow:1px 0 0 0 var(--line);
}
body.list-full .table-wrap thead th:first-child{background:#faf9f6;z-index:6}
body.list-full .table-wrap tbody tr:hover td:first-child{background:#fbfaf7}

/* 筛选区的提交按钮：与输入框同宽同高 */
/* 注意：这里必须用固定宽度。写 width:100% 会失效——父元素 .fitem 里
   只有 label + button 没有输入框，宽度反被按钮内容撑开，百分比就成了 67px */
.fitem button{width:138px;height:31px;padding:0 10px;
  display:flex;align-items:center;justify-content:center;gap:5px}

/* 列表底部操作按钮：与筛选区「查询」同尺寸 */
#add-open, #exp-open{width:138px;height:31px;padding:0 10px;gap:5px;
  display:inline-flex;align-items:center;justify-content:center}

/* ---- 列表页锁定视口：只有表格内部滚动，底部按钮常驻 ---- */
html{height:100%}
body.list-full{height:100%;overflow:hidden;display:flex;flex-direction:column}
body.list-full .page{flex:1 1 auto;min-height:0;display:flex;flex-direction:column;
  overflow:hidden;padding-bottom:16px}
body.list-full .page > .filters,
body.list-full .page > .toolbar,
body.list-full .page > .ok,
body.list-full .page > .err,
body.list-full .page > .count{flex:0 0 auto}
body.list-full .page > .table-wrap{flex:1 1 auto;min-height:0;overflow:auto}

/* 表头随内容滚动固定；操作列同时 sticky 右侧，层级要压过表头 */
body.list-full .table-wrap thead th{position:sticky;top:0;z-index:4;background:#faf9f6}
body.list-full .table-wrap thead th:last-child{z-index:6}
body.list-full .table-wrap tbody td:last-child{z-index:3}

/* 序号列：居中小字，弱化存在感 */
th.idx, td.idx{text-align:center;color:var(--muted);font-size:12.5px;
  font-variant-numeric:tabular-nums;padding-left:6px;padding-right:6px}

/* ---- 弹窗右上角关闭按钮 ---- */
.modal{position:relative}
.modal-x{position:absolute;top:12px;right:12px;width:28px;height:28px;
  display:flex;align-items:center;justify-content:center;padding:0;
  border:none;border-radius:6px;background:transparent;
  color:var(--muted);cursor:pointer;transition:background .12s,color .12s}
.modal-x:hover{background:#f0eee9;color:var(--text)}
.modal-x:active{background:#e8e5de}

/* 列多时按内容展开、超宽横向滚动，避免操作列被压缩到按钮换行 */
body.list-full .table-wrap table.dense{width:max-content;min-width:100%}
table.dense td.ops{width:152px;min-width:152px}

/* 列多时按内容展开、超宽横向滚动，避免操作列被压缩到按钮换行 */
body.list-full .table-wrap table.dense{width:max-content;min-width:100%}
table.dense td.ops{width:152px;min-width:152px}

/* ---- 列表页占满宽度：去掉 1180px 居中限制与两侧留白 ---- */
body.list-full .page{max-width:none;margin:0;padding:14px 8px 12px}  /* 左右各留 8px，微微离边 */
body.list-full .topbar{padding:0 14px}

/* 客户名称：限宽折行，避免长名称把整列撑宽
   （td 直接设 max-width 在表格布局里会被忽略，必须套一层 div） */
td .cname{width:220px;max-width:220px;white-space:normal;
  word-break:break-word;line-height:1.45}

/* ---- 添加/编辑弹窗：整体字号收一档，更紧凑 ---- */
.modal-form h3{font-size:14.5px;margin:0 0 10px}
.modal-form label{font-size:12px;margin-top:5px}
.modal-form input,
.modal-form select,
.modal-form textarea{font-size:12.5px;padding:6px 8px}
.modal-form .grid{gap:0 14px;margin-bottom:0}
.modal-form .modal-actions{margin:12px 0 0;padding:12px 0}
.modal-form .modal-actions button{font-size:13px;height:30px}
