:root {
  --green: #006600;
  --line: #dfe3e8;
  --bg: #f6f7f9;
  --warn: #fff8d6;
  --err: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: #222;
  font: 14px/1.5 "Microsoft YaHei", "等线", system-ui, sans-serif;
}

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--green);
  color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 17px; font-weight: 700; }
.brand .muted { color: #bfe3bf; font-weight: 400; }
.ident { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ident label { color: #d8f0d8; }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row label { color: #555; }
.spacer { flex: 1; }
.inline { display: inline-flex; align-items: center; gap: 5px; }

input, select, button, textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid #ccd2d9;
  border-radius: 5px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid #b7dcb7; border-color: var(--green); }

button { cursor: pointer; }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:hover { background: #004c00; }
button.ghost { background: #fff; color: #333; }
button.ghost:hover { background: #eef3ee; }
button:disabled { opacity: .5; cursor: not-allowed; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px 14px;
  margin-bottom: 10px;
}
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #555; }
.grid input { width: 100%; }

.pill {
  padding: 2px 10px; border-radius: 20px; font-size: 12px;
  background: #e8f5e8; color: var(--green); border: 1px solid #bfe3bf;
}
.pill.locked { background: #fdecea; color: var(--err); border-color: #f5c6c0; }

.splitbar {
  margin-top: 10px; display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 13px; color: #444;
}
.splitbar b { color: #111; }
.splitbar .hi { color: #b8860b; }

.tablewrap { overflow: auto; max-height: 60vh; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 5px 7px; text-align: center; white-space: nowrap; }
th { background: var(--green); color: #fff; position: sticky; top: 0; }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr.needs-contract { background: var(--warn); }
tbody tr:hover { background: #eef7ee; }
td.left { text-align: left; }
tfoot td { background: #fffbe0; font-weight: 700; }

.msg { margin-top: 8px; font-size: 13px; white-space: pre-line; }
.msg.error { color: var(--err); }
.msg.warn { color: #8a6d00; }
/* 对比度：原来的 #888 在浅灰底上只有约 3.5:1，手机户外几乎看不清。
   换成 #5f6672（约 5.5:1）—— 只改颜色值，不动任何布局。 */
.muted { color: #5f6672; }
.small { font-size: 12px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 9px 16px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: 80vw;
}
.toast.show { opacity: .95; }
.toast.error { background: var(--err); }

/* 视图切换（全部 / 待下单 / 缺发票） */
.views { display: flex; gap: 6px; margin-left: 12px; flex-wrap: wrap; }
.viewbtn {
  background: #fff; border: 1px solid #ccd2d9; border-radius: 20px;
  padding: 3px 12px; font-size: 13px; color: #333;
}
.viewbtn:hover { background: #eef3ee; }
.viewbtn.active { background: var(--green); color: #fff; border-color: var(--green); }
.viewbtn b { font-weight: 700; }

/* 条目表上方那个搜索框 */
.searchinp {
  padding: 4px 8px; font-size: 13px; border: 1px solid #ccd2d9;
  border-radius: 6px; width: 200px; max-width: 44vw;
}

/* 行内小按钮 */
.mini {
  padding: 2px 7px; font-size: 12px; border-radius: 4px;
  background: #fff; border: 1px solid #ccd2d9; margin: 0 2px; color: #333;
}
.mini:hover { background: #eef3ee; }
.mini.danger { color: var(--err); border-color: #f0c8c2; }
.mini.danger:hover { background: #fdecea; }

/* 行内状态下拉 */
.cellselect { padding: 2px 4px; font-size: 12px; border-radius: 4px; }
.cellselect.done {
  background: #e8f5e8; border-color: #bfe3bf; color: #0a5a0a; font-weight: 600;
}

/* 发票文件 */
.invcell { white-space: nowrap; }
.invfile { display: inline-flex; align-items: center; gap: 3px; margin-right: 6px; }
.invfile a {
  font-size: 12px; text-decoration: none; color: var(--green);
  border: 1px solid #bfe3bf; border-radius: 4px; padding: 1px 5px;
}
.invfile a:hover { background: #eef7ee; }

/* 进度条上的提示 */
.warnpill {
  background: #fff4d6; color: #8a6d00; border: 1px solid #f0dca0;
  border-radius: 20px; padding: 1px 10px; font-size: 12px;
}
.okpill {
  background: #e8f5e8; color: var(--green); border: 1px solid #bfe3bf;
  border-radius: 20px; padding: 1px 10px; font-size: 12px;
}
/* 进度条上那种「点一下看这些行」的提示 */
.warnpill.link { cursor: pointer; text-decoration: underline dotted; }
.warnpill.link:hover { background: #ffeab0; }

/* 行内「填金额」：有发票却没实付金额，一眼就要看见 */
.mini.warnmini {
  background: #fff4d6; border-color: #f0dca0; color: #8a6d00; font-weight: 600;
}
.mini.warnmini:hover { background: #ffe9b0; }

/* 粘贴分享文案快速填入 */
.pastebar { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.pastebar textarea {
  flex: 1; min-height: 46px; resize: vertical;
  font: inherit; padding: 7px 9px;
  border: 1px solid #ccd2d9; border-radius: 5px; background: #fbfdfb;
}
.pastebar textarea:focus { outline: 2px solid #b7dcb7; border-color: var(--green); }
.pastebar button { white-space: nowrap; padding: 0 18px; }

/* 回填车队总表的行块 */
#blockText {
  width: 100%; min-height: 110px; margin-top: 8px;
  font: 12px/1.5 Consolas, "Courier New", monospace;
  padding: 8px; border: 1px solid #ccd2d9; border-radius: 5px;
  background: #fbfdfb; resize: vertical; white-space: pre; overflow: auto;
}
#blockText:focus { outline: 2px solid #b7dcb7; border-color: var(--green); }

/* 邮箱收发票 */
#mailConfigBox { margin: 8px 0; }
#mailConfigBox summary {
  cursor: pointer; font-size: 13px; color: var(--green); margin-bottom: 8px;
}
#mailPending { margin-top: 10px; }
.mailcard {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 9px 11px; margin-bottom: 8px; background: #fbfdfb;
}
.mailcard .subj { font-weight: 600; }
.mailcard .meta { color: #888; font-size: 12px; margin-top: 2px; }
.mailcard .row { margin-top: 7px; }
.sugg {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid #bfe3bf; background: #f2faf2; color: #0a5a0a;
  border-radius: 20px; padding: 2px 10px; font-size: 12px; margin: 2px 5px 2px 0;
  cursor: pointer;
}
.sugg:hover { background: #e4f5e4; }

/* 分享给组员 */
.sharebox {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-top: 10px;
}
.sharebox img {
  width: 176px; height: 176px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; padding: 4px;
}
.sharebox img[hidden] { display: none; }
.sharetext { display: flex; flex-direction: column; gap: 6px; }
.shareurl {
  font: 16px/1.4 Consolas, "Courier New", monospace;
  color: var(--green); font-weight: 700; word-break: break-all;
}

/* 两个入口：按 html 上的 mode-* 决定显示哪些区块。
   记住这只是体验层 —— 真正的拦截在服务端（没登录调采购接口一律 401）。 */
html.mode-member .purchase-only { display: none !important; }
html.mode-purchase .member-only { display: none !important; }

/* 采购入口的登录门 */
.logingate {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(18, 28, 20, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.logingate[hidden] { display: none; }
.loginbox {
  background: #fff; border-radius: 10px; padding: 26px 28px;
  width: min(380px, 100%); box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  display: flex; flex-direction: column; gap: 12px;
}
.loginbox h2 { margin: 0; font-size: 19px; }
.loginbox input {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; font-size: 15px;
}

/* 组员界面的进度数字 */
.progbar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.progbar .prog {
  flex: 1 1 130px; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; background: #fafcfa;
}
.progbar .prog b { display: block; font-size: 22px; line-height: 1.2; color: var(--green); }
.progbar .prog span { font-size: 12px; color: #667; }

/* 组员看到的只读状态（不是下拉框） */
.cellselect.readonly {
  display: inline-block; padding: 3px 8px; border-radius: 5px;
  background: #f2f5f2; color: #556; border: 1px solid var(--line);
}
.cellselect.readonly.done {
  background: #e4f5e4; color: #2c6b2c; border-color: #b6dcb6;
}

/* 已退货的行：整行压暗一点，名称划掉，旁边挂个标记 */
tr.refunded td { background: #fbf6f6; color: #8a8a8a; }
tr.refunded td:nth-child(2) { text-decoration: line-through; }
.refundtag {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  font-size: 11px; line-height: 1.5; border-radius: 4px;
  text-decoration: none;
  background: #f6e6e6; color: #a33; border: 1px solid #e3cccc;
}

/* 分享卡片里的分隔线与宽输入框 */
.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0 10px; }
.wideinp {
  flex: 1 1 260px; min-width: 200px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit;
}

/* 垫资标记：挂在「申购人」那列下面 */
.payertag {
  display: block; margin-top: 2px;
  font-size: 11px; line-height: 1.5; color: #8a6d1f;
}

/* 组员管理：新加的那一行给点提示色 */
tr.newrow td { background: #fffbe8; }
#memTable input:not([type="checkbox"]) {
  width: 100%; min-width: 5em;
  padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; font: inherit;
}
/* 当前视图合计：贴在表格下面，不跟数据行连成一片 */
.itemsum {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: baseline;
  margin-top: 8px; padding: 9px 12px;
  background: var(--warn); border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px;
}
.itemsum .sumrow { font-weight: 600; }
.itemsum .sumitem b { font-size: 15px; }
/* 没有数据时别留一条空黄带 —— `display: flex` 会盖掉 [hidden] 的 display:none */
.itemsum[hidden] { display: none; }

/* 一票多单的核对框：要能放下「明细 / 选条目 / 金额」三列 */
.widebox { width: min(680px, 100%); }
#assignTable { width: 100%; border-collapse: collapse; font-size: 13px; }
#assignTable th, #assignTable td {
  border: 1px solid var(--line); padding: 5px 7px; text-align: left;
}
#assignTable th { background: var(--green); color: #fff; }
#assignTable select, #assignTable input { width: 100%; font: inherit; }
#assignTable td:first-child { max-width: 15em; word-break: break-all; }
#assignTable td:last-child { width: 6em; }
#assignSum { margin: 8px 0 0; font-size: 13px; }
#assignSum.bad { color: #b3261e; font-weight: 600; }
#assignSum.good { color: #1b7f3b; }

/* 「网址链接/商家」列：长链接只显示短标签，列宽限死，点开是新标签页 */
#itemsTable td a { color: var(--green); text-decoration: underline; }
#itemsTable td:nth-child(12) {
  max-width: 12em; overflow: hidden; text-overflow: ellipsis;
}

/* 页面内输入框：替代 window.prompt（部分内嵌浏览器不弹它，点了像没反应） */
.askbar {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .35);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.askbar[hidden] { display: none; }
.askbox {
  background: #fff; border-radius: 10px; padding: 16px 18px;
  width: min(420px, 100%); box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}
.askbox p { margin: 0 0 10px; font-size: 14px; }
.askbox input {
  width: 100%; padding: 9px 10px; font: inherit; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 6px;
}
.askbox .row { justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* 「存/删」（成员表）和「改/删」（条目表）都钉在右边。
   手机上表格要横向滑，不钉住这一列会被挤出屏幕，人根本点不到 ——
   就会以为"填完了却存不上"。（真发生过）*/
#itemsTable td:last-child, #itemsTable th:last-child,
#memTable td:last-child, #memTable th:last-child {
  position: sticky; right: 0; z-index: 1; white-space: nowrap;
}
#itemsTable td:last-child, #memTable td:last-child { background: #fff; }
#itemsTable tbody tr:nth-child(even) td:last-child,
#memTable tbody tr:nth-child(even) td:last-child { background: #fafbfc; }
#memTable tr.newrow td:last-child { background: #fffbe8; }

/* 物料名称列横向滚动时**钉在左边**。
   19 列滑到右边后，光看「规格型号 / 数量 / 单价」根本认不出这是哪条采购，
   只能来回滑（用户报的原话）。钉住这一列就一眼看得出。
   只钉这一列、不连 # 列一起钉：钉两列必须固定列宽，列宽一变 left 值就错位、
   露出下层内容。只钉一列用 left: 0，永远准。
   border-collapse: collapse 下 sticky 单元格的右边框会被吃掉，用 box-shadow 补。*/
#itemsTable th:nth-child(2), #itemsTable td:nth-child(2) {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
  text-align: left;
}
/* 表头同时要 top:0（既有规则）和 left:0，z-index 得压过普通单元格 */
#itemsTable th:nth-child(2) { background: var(--green); z-index: 4; }
/* 斑马纹 / 高亮行 / 悬停时，钉住的单元格也要跟着变色，否则会透出下层内容 */
#itemsTable tbody tr:nth-child(even) td:nth-child(2) { background: #fafbfc; }
#itemsTable tbody tr.needs-contract td:nth-child(2) { background: var(--warn); }
#itemsTable tbody tr:hover td:nth-child(2) { background: #eef7ee; }

/* 改挂弹窗里的多选列表 */
/* 多选列表样式在文件末尾的 .picklist / .pickitem（旧的 #pickList <select> 已换成可点的标签） */

/* 合并打印的结果预览：直接嵌在卡片里看，不用另开窗口 */
.preview-box { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.preview-frame { width: 100%; height: 620px; margin-top: 8px; border: 1px solid var(--line);
  border-radius: 8px; background: #f7f7f7; }

/* 发票预览弹层：点「看发票」就地弹出来看，不用新开标签页（也就关得掉了） */
.fileviewer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(18, 28, 20, .55);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.fileviewer[hidden] { display: none; }
.fileviewer-box {
  background: #fff; border-radius: 10px; padding: 12px 14px;
  width: min(1000px, 100%); height: min(92vh, 900px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  display: flex; flex-direction: column; gap: 8px;
}
.fileviewer-frame {
  flex: 1; width: 100%; border: 1px solid var(--line);
  border-radius: 8px; background: #f7f7f7;
}

/* 待购清单：采购照着它去淘宝下单 */
.shopcard {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 9px 11px; margin-bottom: 8px; background: #fbfdfb;
}
.shopcard .subj { font-weight: 600; }
.shopcard .meta { color: #888; font-size: 12px; margin-top: 2px; }
.shopcard .row { margin-top: 7px; }

/* 填物料名称时提示「以前买过什么」，点一下带出规格/单价 */
.history-box {
  margin-top: 8px; padding: 8px 10px;
  border: 1px dashed #cfe3cf; border-radius: 6px; background: #f7fbf7;
}
.history-box .sugg { margin-top: 6px; }

/* 垫付结算：谁先掏了多少钱 */
.payertable { width: 100%; border-collapse: collapse; font-size: 13px; }
.payertable th, .payertable td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.payertable th { color: #666; font-weight: 600; background: #fafcf9; }
.payertable td:last-child, .payertable th:last-child { text-align: right; }

/* 「系统自动挂的」提示：人没点过它，得显眼一点 */
.autonote { color: #b26a00; font-weight: 600; }

/* 多选列表：点一下选中、再点一下取消 —— 手机上原生 multiple select 做不了多选 */
.picklist {
  display: flex; flex-wrap: wrap; gap: 6px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; max-height: 260px; overflow-y: auto;
  background: #fcfdfc; flex: 1 1 100%;
}
.pickitem {
  padding: 9px 13px; border: 1px solid #ccd2d9; border-radius: 18px;
  background: #fff; font-size: 13px; line-height: 1.2;
  cursor: pointer; text-align: left; min-height: 38px;
}
.pickitem.on {
  background: #eaf5ea; border-color: #7fbf7f; color: #0a5a0a; font-weight: 600;
}
.pickitem:active { transform: scale(0.98); }

/* ---------------------------------------------------------------- 分栏（Tab）

   11 个卡片全铺开来要滚很久，按「现在在干什么」分成几栏：
   填采购 / 下单 / 发票 / 结算 / 组员（组员只有「填采购」和「进度」）。
   按钮本身带 purchase-only / member-only，由 html.mode-* 那两条规则决定谁能看见。*/
.pagetabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin: 16px 0 2px; padding: 5px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
.pagetab {
  flex: 0 0 auto; padding: 9px 18px;
  border: 0; border-radius: 8px;
  background: transparent; color: #45514a;
  font-size: 14px; cursor: pointer;
}
.pagetab:hover { background: #eef7ee; }
.pagetab.on { background: var(--green); color: #fff; font-weight: 600; }

/* 不在当前栏里的卡片直接不占位置 */
.pane-off { display: none !important; }

/* 三方对账：三个总额的小药丸 + 只列问题行的小表 */
.recontotals { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 10px; }
.reconpill {
  padding: 6px 12px; border-radius: 8px;
  background: #f3f8f3; border: 1px solid var(--line);
  font-size: 13px; color: #2c4a2c;
}

/* 待购清单里「下完单当场填实付」—— 输入框别太宽 */
.shopact { gap: 8px; margin-top: 6px; }
.paidbox { width: 118px; padding: 5px 8px; font-size: 13px; }

/* 「买了但状态没同步」的提醒条 */
.taglag {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 8px 0; padding: 9px 12px;
  background: #fffbe8; border: 1px solid #e4d48a; border-radius: 8px;
  font-size: 13px; color: #6b5a13;
}

/* ---------------------------------------------------------------- 手机（≤640px）

   断点之外一条规则都不加，桌面端零影响。这里只收紧触屏上真正碍事的地方：
   输入框 16px（iOS 小于 16px 聚焦会自动放大整页）、
   行内按钮至少 44×44（手指点得中）、表格能横滑且不被长文本撑爆。 */
@media (max-width: 640px) {
  /* iOS 聚焦缩放：字号必须 ≥16px，否则一碰输入框整页就跳大。
     !important 是因为 .cellselect / .searchinp / .paidbox 这些类选择器
     把字号压到了 12–13px，元素选择器盖不过它们 —— 只在手机断点里生效。 */
  input, select, textarea { font-size: 16px !important; }

  /* 触屏点得中：行内小按钮一律 44×44 */
  .mini, .rowbtns button, td button, .shopact button, .bulkbar button,
  .viewbtn, .pagetab, .sugg, .pickitem {
    min-height: 44px; min-width: 44px;
  }
  /* 勾选框本身别撑成 44px（会把「#」列挤爆），用内边距把点按面积补够 */
  .pickbox { width: 24px; height: 24px; }
  #itemsTable td:first-child { padding-top: 11px; padding-bottom: 11px; }

  /* 表格：横向滑动 + 惯性滚动，别整页跟着一起横 */
  .tablewrap { overflow: auto; -webkit-overflow-scrolling: touch; }

  /* 顶部卡片那一行允许换行，别把按钮挤出屏幕 */
  .row, .splitbar, .topbar, .ident { flex-wrap: wrap; }

  /* 表格单元格允许换行：长规格/长链接会把整张表撑到几倍宽 */
  #itemsTable td, #memTable td { white-space: normal; word-break: break-all; }
  /* 但「改/删」那一列还是要一行放得下（它固定在右侧） */
  #itemsTable td:last-child, #memTable td:last-child { white-space: nowrap; }

  /* 弹层在窄屏上要能滚，不然核对框下半截点不到 */
  .askbox { max-height: 90vh; overflow: auto; }
}
