:root {
  --bg: #f4f6f8;
  --panel: #fff;
  --line: #dde3e9;
  --line-strong: #c3ccd6;
  --text: #1d2733;
  --muted: #6b7885;
  --brand: #2f7a4d;
  --brand-dark: #245f3c;
  --danger: #c0392b;
  --warn: #b8860b;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.55 "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 顶栏 ---------------- */
header.topbar {
  background: var(--brand);
  color: #fff;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
header.topbar .brand {
  font-size: 16px; font-weight: 700; margin-right: 14px; padding: 11px 0;
  color: #fff; white-space: nowrap;
}
header.topbar .brand:hover { text-decoration: none; }
header.topbar nav a {
  color: #e8f3ec; padding: 11px 12px; display: inline-block; border-bottom: 3px solid transparent;
}
header.topbar nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
header.topbar nav a.active { color: #fff; font-weight: 600; border-bottom-color: #ffd479; }
header.topbar .spacer { flex: 1; }
header.topbar .right a { color: #dcefe3; font-size: 13px; padding: 11px 8px; display: inline-block; }

/* ---------------- 布局 ---------------- */
main { max-width: 1360px; margin: 0 auto; padding: 16px; }

.page-head {
  display: flex; align-items: center; gap: 12px; margin: 0 0 14px;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 19px; margin: 0; font-weight: 600; }
.page-head .spacer { flex: 1; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
}
.panel > h2 {
  font-size: 15px; margin: -2px 0 12px; font-weight: 600;
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.panel.tight { padding: 0; }
.panel.tight > h2 { margin: 0; padding: 12px 16px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: 1fr 1fr; }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 980px) { .grid.c2, .grid.c3 { grid-template-columns: 1fr; } }

/* ---------------- 表格 ---------------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left;
  vertical-align: middle;
}
table.data thead th {
  background: #eef2f5; font-weight: 600; color: #445; white-space: nowrap;
  border-bottom: 1px solid var(--line-strong); position: sticky; top: 0; z-index: 1;
}
table.data tbody tr:hover { background: #f7fafb; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.mid, table.data th.mid { text-align: center; }
table.data tfoot td { font-weight: 600; background: #f3f6f8; border-top: 2px solid var(--line-strong); }
.table-wrap { overflow-x: auto; }

.empty { padding: 26px; text-align: center; color: var(--muted); }

/* ---------------- 表单 ---------------- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input:not([type]), input[type=text], input[type=password], input[type=date], input[type=month], input[type=number], input[type=email],
input[type=search], select, textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line-strong);
  border-radius: 4px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(47,122,77,.12);
}
input[readonly] { background: #f2f4f6; color: var(--muted); }

/* 日期框：文本框 + 右边一个小日历按钮（JS 把 type=date 换成这个） */
.date-wrap { position: relative; display: block; }
.date-wrap > input { padding-right: 26px; }
.date-wrap > .cal {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; cursor: pointer; padding: 2px 4px;
  font-size: 14px; line-height: 1; opacity: .5;
}
.date-wrap > .cal:hover { opacity: 1; }
input.date-in.bad { border-color: #c0392b; background: #fff6f5; }
textarea { min-height: 70px; resize: vertical; font-size: 13px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(4, 1fr); }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: span 3; }
.form-grid .span4 { grid-column: span 4; }
@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid .span3, .form-grid .span4 { grid-column: span 2; }
}
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.check input { width: auto; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-block; padding: 6px 13px; border-radius: 4px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--text); cursor: pointer; font: inherit; white-space: nowrap;
}
.btn:hover { background: #f0f3f5; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #e6b8b2; }
.btn.danger:hover { background: #fdf1f0; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------- 提示 ---------------- */
.flash { padding: 9px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.flash.ok  { background: #e8f5ec; border: 1px solid #b9dfc7; color: #1e6b3a; }
.flash.err { background: #fdecea; border: 1px solid #f2c2bc; color: #a02b1d; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px;
  background: #eceff2; color: #5a6672; white-space: nowrap;
}
.tag.green { background: #e3f3e9; color: #1e6b3a; }
.tag.amber { background: #fdf2dd; color: #8a6415; }
.tag.red   { background: #fbe6e3; color: #a02b1d; }
.tag.blue  { background: #e5eefb; color: #1f4f8f; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 进度条 */
.bar { height: 6px; background: #e6eaee; border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.bar > i.full { background: #2f7a4d; }
.bar > i.part { background: #d9a441; }

/* 看板数字 */
.kpi { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.kpi .box {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; min-width: 132px; flex: 1;
}
.kpi .box .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .box .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .box.warn .v { color: var(--warn); }
.kpi .box.danger .v { color: var(--danger); }

/* ---------------- 明细行编辑器 ---------------- */
/* 明细表：列宽照表头写的来（table-layout:fixed），输入框撑满格子。
   不这么写的话，浏览器按内容排，数量/金额这种窄列里的数字会被裁掉看不见。 */
table.items { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
table.items th {
  position: relative;
  background: #eef2f5; font-size: 12px; font-weight: 600; color: #445;
  padding: 6px 5px; border: 1px solid var(--line); white-space: nowrap;
}
table.items td { border: 1px solid var(--line); padding: 2px; }
table.items input, table.items select {
  border: none; border-radius: 0; padding: 5px 6px; background: transparent;
  width: 100%; box-sizing: border-box; min-width: 0;
}
table.items input[type=checkbox] { width: auto; }
table.items input:focus, table.items select:focus { box-shadow: inset 0 0 0 2px rgba(47,122,77,.2); }
table.items td.amt { text-align: right; padding: 5px 8px; font-variant-numeric: tabular-nums;
                     background: #f7f9fa; white-space: nowrap; }
table.items td.seq { text-align: center; color: var(--muted); width: 30px; font-size: 12px; }
table.items td.op { width: 34px; text-align: center; }
table.items .rm {
  border: none; background: none; color: var(--danger); cursor: pointer; font-size: 15px;
  line-height: 1; padding: 3px 6px;
}
table.items tfoot td { background: #f3f6f8; font-weight: 600; }

.linked { background: #f0f6f1 !important; }
.linked-mark { color: var(--brand); font-size: 11px; }

.sticky-actions {
  position: sticky; bottom: 0; background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line); padding: 10px 16px; margin: 14px -16px -14px;
  display: flex; gap: 8px; align-items: center;
  backdrop-filter: blur(4px);
}

@media print {
  header.topbar, .no-print, .sticky-actions { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
}

/* ---------------- 登录页 ---------------- */
.login-page { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #eef1f3; margin: 0; }
.login-box { width: 320px; background: #fff; padding: 26px 24px 24px;
  border: 1px solid var(--line-strong); border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.login-box h1 { margin: 0 0 16px; font-size: 20px; text-align: center; }

/* 产品缩略图（档案列表、报价单明细行、产品表单） */
.thumb { width: 40px; height: 40px; object-fit: contain; border: 1px solid var(--line);
         background: #fff; border-radius: 3px; vertical-align: middle; }
.thumb.lg { width: 120px; height: 120px; }
.thumb[hidden] { display: none; }
.thumb-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }

/* 下拉旁边带一个小按钮（报价单页的「＋新客户」「＋联系人」） */
.with-btn { display: flex; gap: 6px; align-items: center; }
.with-btn select { flex: 1; min-width: 0; }
/* 弹窗（原生 <dialog>） */
dialog.dlg { border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px;
             width: min(560px, 92vw); box-shadow: 0 8px 30px rgba(0,0,0,.18); }
dialog.dlg::backdrop { background: rgba(0, 0, 0, .35); }
dialog.dlg h2 { margin: 0 0 12px; font-size: 16px; }
dialog.dlg .form-grid { grid-template-columns: repeat(2, 1fr); }
dialog.dlg .form-grid .span2 { grid-column: span 2; }
.dlg-err { color: var(--danger); min-height: 18px; margin: 4px 0 8px; }

/* 外销版报价单（style=export）明细行：参考价小字 + 表格里的多行描述框 */
.ref-price { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
input::placeholder { color: #a7b0ad; }
table.items textarea { width: 100%; box-sizing: border-box; min-height: 40px; height: 40px; font-size: 13px; resize: vertical; overflow: hidden; }
table.items textarea[data-f="note"], table.items textarea[data-f="color"] { min-height: 30px; height: 30px; }   /* 备注：一行起步，字多了自动长高、不截断 */

/* 提示字调浅：浏览器默认灰太深，跟填好的值分不清（HanLing 更新 C2，2026-09-16 米萝实测也撞上） */
::placeholder { color: #b8c0c8; opacity: 1; }

/* Delivery Date：月份 + 上中下旬 + 生成的英文，三格一行，高度和其他输入框一致 */
.date-parts { display: grid; grid-template-columns: 170px 150px 1fr; gap: 8px; align-items: center; }
@media (max-width: 760px) { .date-parts { grid-template-columns: 1fr 1fr; } .date-parts > :last-child { grid-column: span 2; } }

/* 兜底：原生 hidden 属性本来就该整个不显示，防止某个更具体的 display 规则把它盖掉 */
[hidden] { display: none !important; }

/* ---------------- 分页签（通用：.tabs 容器 + .tab 按钮 + [data-tab-panel] 面板） ----------------
   当前签下面一条主题色线；.tab-badge 是灰色小字「（2 箱）」——10-14 用户：绿圈数字像「还有几件事没办」。 */
.tabs {
  display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 14px;
  border-bottom: 1px solid var(--line-strong);
}
.tab {
  border: none; background: none; cursor: pointer; font: inherit; color: var(--muted);
  padding: 9px 14px 8px; margin-bottom: -1px; border-bottom: 3px solid transparent;
  display: inline-flex; align-items: center; gap: 6px; border-radius: 4px 4px 0 0;
}
.tab:hover { color: var(--text); background: #f0f3f5; }
.tab.active { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }
.tab-badge { color: var(--muted); font-size: 12px; font-weight: 400; }

/* 产品多图：档案页的图片格子、明细行上的「选图」按钮、选图弹窗 */
.img-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.img-card { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; }
.row-thumbs { display: inline-flex; flex-wrap: wrap; gap: 2px; justify-content: center; align-items: center;
              min-width: 44px; min-height: 40px; padding: 1px; border: 1px dashed var(--line); border-radius: 3px;
              background: none; cursor: pointer; font-size: 12px; color: #8a949c; }
.row-thumbs:hover, .row-thumbs:focus-visible { border-color: var(--brand); outline: none; }
.row-thumbs .thumb { width: 38px; height: 38px; }
.row-thumbs.multi .thumb { width: 26px; height: 26px; }
.pick-grid { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.pick-card { position: relative; border: 2px solid var(--line); border-radius: 5px; padding: 3px; background: #fff; cursor: pointer; }
.pick-card.on { border-color: var(--brand); }
.pick-card .ord { position: absolute; top: 2px; left: 2px; min-width: 18px; height: 18px; border-radius: 9px;
                  background: var(--brand); color: #fff; font-size: 12px; line-height: 18px; text-align: center; }
.pick-card:not(.on) .ord { display: none; }

/* 账号：右上角「谁登录着」、权限表 */
.topbar .who { font-weight: 600; }
.topbar .who small { font-weight: 400; margin-left: 4px; padding: 0 5px; border-radius: 3px;
                     background: rgba(255,255,255,.18); font-size: 11px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px;
        background: #eef1f4; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #e3f1e8; color: var(--brand-dark); }
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child { text-align: left; }
/* 只读角色（财务看销售单据）：改/删/新建/转单这些会写库的按钮不显示 */
main.ro form[method="post" i]:not(.keep), main.ro a[href*="/new"], main.ro a[href*="/edit"] { display: none !important; }

/* ── 从工厂报价单导入：核对页 ── */
.imp-stat { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; flex-wrap: wrap; }
.imp-stat kbd { border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; background: #fff; }
.pill.warn { background: #fdf3e3; color: #a2670a; }
.pill.bad { background: #fdecea; color: var(--danger); }
.ok-txt { color: var(--brand-dark); } .bad-txt { color: var(--danger); font-weight: 600; }

.imp-wrap { display: grid; grid-template-columns: minmax(0, 42%) minmax(0, 58%); gap: 12px; align-items: start; }
@media (max-width: 980px) { .imp-wrap { grid-template-columns: 1fr; } }

.imp-sheet { max-height: 70vh; overflow: auto; border-top: 1px solid var(--line); }
table.xl { border-collapse: collapse; font-size: 12px; white-space: nowrap; }
table.xl td, table.xl th { border: 1px solid #e6eaee; padding: 2px 6px; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; }
table.xl th.rn { background: #f4f6f8; color: var(--muted); position: sticky; left: 0; font-weight: 400; }
table.xl tr.hdr td { background: #eef3f7; font-weight: 600; }
table.xl tr.on td { background: #fff6d8; }           /* 点右边的行，这行亮起来 */

.imp-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 8px 0; }
.imp-rows { display: flex; flex-direction: column; gap: 8px; max-height: 62vh; overflow: auto; padding-right: 4px; }
.imp-row { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 6px;
  padding: 8px 10px; background: #fff; }
.imp-row.lv-ok { border-left-color: #3f7d55; }
.imp-row.lv-maybe { border-left-color: #d79a2b; background: #fffdf7; }
.imp-row.lv-none { border-left-color: var(--danger); background: #fffafa; }
.imp-row.on { box-shadow: 0 0 0 2px rgba(47,122,77,.25); }
.ir-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ir-seq { width: 22px; height: 22px; border-radius: 11px; background: #eef1f4; color: var(--muted);
  text-align: center; line-height: 22px; font-size: 12px; flex: none; }
.ir-src { font-weight: 600; }
.ir-img { width: 34px; height: 34px; object-fit: contain; border: 1px solid var(--line);
  border-radius: 3px; background: #fff; }
.ir-body { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.ir-f { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
.ir-f input { min-width: 230px; }
.ir-f.sm input { min-width: 70px; width: 80px; }
.ir-f input[data-need] { border-color: #d79a2b; background: #fffdf5; }
.ir-drop { color: var(--muted); }
.ir-note { margin-top: 4px; }
.imp-extras, .imp-total { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
tr.dif-diff td { background: #fffaf3; } tr.dif-extra td { background: #fdecea; }
tr.dif-missing td { background: #f4f6f8; }
.pill.ai { background: #ece7fb; color: #5b3fb5; font-weight: 600; }
.ir-why .pill { white-space: normal; }            /* AI 的理由可能长，允许换行 */

/* 核对回签单：有差异的那几格要一眼看到 */
tr.dif-diff td:last-child, tr.dif-extra td:last-child { color: var(--danger); font-weight: 600; }

/* 上传处理中（app.js） */
.btn.busy { cursor: progress; opacity: .85; }
.btn .spin { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: btnspin .8s linear infinite; }
@keyframes btnspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn .spin { animation: none; } }

/* 明细表拖列宽（app.js） */
table.items th .col-rs { position: absolute; top: 0; right: -4px; bottom: 0; width: 8px; cursor: col-resize; z-index: 2; }
table.items th .col-rs:hover, table.items th .col-rs.on { background: rgba(47,122,77,.28); }
body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-select: none !important; }

/* 文件块（单据下载）：点了下载，按住能拖出去（app.js 设 DownloadURL） */
.file-groups { display: grid; gap: 8px; margin-bottom: 8px; }
.file-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.file-group .fg-label { min-width: 52px; font-weight: 600; color: #445; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: #233; text-decoration: none; font-size: 13px; cursor: grab; }
.file-chip:hover { border-color: #2f7a4d; background: #f3f8f5; text-decoration: none; }
.file-chip:active { cursor: grabbing; }
.file-chip .ext { font-size: 10px; font-weight: 700; padding: 1px 4px; border-radius: 3px; color: #fff; }
.file-chip .ext.pdf { background: #c0392b; }
.file-chip .ext.xls { background: #1e7a46; }
.file-group .fg-print { color: var(--muted); }

/* 应收页顶上的外贸/内贸概览框：整框可点，当前签那个描主题色边 */
a.box.rcv-box { color: inherit; text-decoration: none; }
a.box.rcv-box:hover { border-color: var(--line-strong); }
a.box.rcv-box.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.kpi .box .v.danger-text { color: var(--danger); font-size: 20px; }
.rcv-split { font-size: 15px; color: var(--text); margin-top: 4px; font-variant-numeric: tabular-nums; }
.rcv-split b { font-weight: 600; }
.rcv-split .n { color: var(--muted); font-size: 13px; }
.rcv-split .plus { color: var(--muted); margin: 0 8px; }

/* 滚动条位置一直留着：内容变长变短（筛选、展开收起）时滚动条出现/消失，整页会左右跳一下（10-15 用户：页面抖动） */
html { scrollbar-gutter: stable; }
