/*!
 * 生鲜采购统计系统 · 全局样式 assets/app.css
 * 版本：v1.5.0 ｜ 最后修改：2026-11-03
 * 用途：移动优先布局、卡片式表单、费用差异黄色提示、toast、模态框、表格样式。
 * 本版（批A）：顶部导航白字可见性/对比度达标（--primary-strong）、触控目标≥44px、
 *       数字等宽、弹窗内滚动+粘性表头、照片控件隐藏+label 按钮、safe-area、
 *       focus-visible、prefers-reduced-motion、表格斑马纹/悬停、桌面提报三列。
 * 说明：零外部依赖，全部本地样式。
 */

:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-strong: #15803d;   /* 承载白字的深主色（白字对比 5.02:1，WCAG AA） */
  --primary-light: #dcfce7;
  --warn-bg: #fefce8;
  --warn-border: #eab308;
  --warn-text: #854d0e;
  --danger: #dc2626;
  --danger-text: #b91c1c;      /* 压 #fee2e2 = 5.30:1 */
  --danger-bg: #fee2e2;
  --text: #1f2937;
  --muted: #4b5563;            /* 白底≈8:1，灰底 6.87:1 */
  --border: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55;
}
a { color: var(--primary-dark); }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* ===== 顶部栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(90deg, #15803d, #166534); /* 白字 5.02–7.13:1 */
  color: #fff; padding: 8px 14px; min-height: 48px;
}
.topbar .title {
  flex: 1; font-size: 17px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .back { color: #fff; text-decoration: none; font-size: 15px; white-space: nowrap; }
.topbar .spacer { width: 44px; }
.topbar .btn-mini { background: rgba(0,0,0,.25); color: #fff; border-color: rgba(255,255,255,.5); }
.topbar .nav { flex: 1; }

/* 管理台顶部导航：白字 + 横向可滚动 + 选中态（P0-1） */
.topbar .nav { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; }
.topbar .nav::-webkit-scrollbar { height: 0; }
.topbar .nav-item {
  color: #fff; text-decoration: none; opacity: .92;
  font-size: 14px; line-height: 1.2; white-space: nowrap;
  padding: 8px 10px; border-radius: 6px;
}
.topbar .nav-item:hover { background: rgba(255,255,255,.14); opacity: 1; }
.topbar .nav-item.active { background: rgba(255,255,255,.22); opacity: 1; font-weight: 600; }
@media (max-width: 900px) { .topbar .nav-item { padding: 8px; font-size: 13px; } }

/* ===== 页面容器 ===== */
.page { max-width: 560px; margin: 0 auto; padding: 12px; }
.page-wide { max-width: 1280px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .fld { margin-bottom: 0; }
.spacer-flex { flex: 1; }

/* ===== 卡片 ===== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card h2, .modal h2 {
  font-size: 16px; color: var(--primary-dark);
  border-left: 3px solid var(--primary); padding-left: 8px;
}
.card h2 { margin: 0 0 10px; }
.modal h2 { margin: 14px 0 10px; }
.modal h2:first-child { margin-top: 0; }

/* ===== 表单 ===== */
label.fld { display: block; margin-bottom: 8px; }
label.fld > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
label.fld > span em { color: var(--danger); font-style: normal; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=tel], select, textarea {
  width: 100%; padding: 8px 10px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22,163,74,.12); }
input:disabled { background: #f9fafb; color: var(--muted); cursor: not-allowed; }
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); column-gap: 10px; }
.grid-2 label.fld, .grid-3 label.fld { min-width: 0; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; font-size: 15px; cursor: pointer; text-decoration: none;
  background: #e5e7eb; color: var(--text); line-height: 1.2; white-space: nowrap;
  min-height: 44px; /* 触控目标 */
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary-strong); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-mini {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
  min-height: 36px;
}
.btn-mini.danger { color: var(--danger); border-color: #fecaca; }
.form-err {
  background: var(--danger-bg); color: var(--danger-text); border: 1px solid #fecaca;
  border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13px;
}

/* ===== 徽标 ===== */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 1.6; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-submitted { background: var(--primary-light); color: var(--primary-dark); }
.badge-voided { background: #e5e7eb; color: #374151; }

/* ===== 明细行 ===== */
.item-row {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 10px; margin-bottom: 10px; background: #fafafa;
}
.item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.item-no { font-weight: 600; font-size: 14px; color: var(--primary-dark); }
.item-calc {
  margin-top: 8px; font-size: 13px; color: var(--muted);
  border-top: 1px dashed var(--border); padding-top: 6px; line-height: 1.9;
}
.item-calc .num { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 差异提示：黄色（毛皮净不一致 / 实付与金额差异） */
.warn-chip {
  display: inline-block; background: var(--warn-bg); border: 1px solid var(--warn-border);
  color: var(--warn-text); padding: 0 8px; border-radius: 999px; font-size: 12px;
}
.err-chip {
  display: inline-block; background: var(--danger-bg); border: 1px solid #fecaca;
  color: var(--danger-text); padding: 0 8px; border-radius: 999px; font-size: 12px;
}

/* ===== 汇总预览 ===== */
.sum-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.sum-cell { background: var(--primary-light); border-radius: 8px; padding: 8px 10px; }
.sum-cell .k { font-size: 12px; color: var(--primary-dark); }
.sum-cell .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; word-break: break-word; }

/* ===== 底部操作条 ===== */
.actions { display: flex; gap: 10px; padding: 10px 0 16px; }
.actions .btn { flex: 1; }
.actions.sticky {
  position: sticky; bottom: 0;
  background: linear-gradient(0deg, var(--bg) 82%, rgba(243,244,246,0));
  margin-top: -4px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* iPhone 安全区 */
}

/* ===== 照片 ===== */
/* 原生 file 控件隐藏，用 label 按钮触发（P2-3） */
#photo-input { position: absolute; width: 0; height: 0; opacity: 0; overflow: hidden; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.photo-item {
  position: relative; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; background: #fff; text-decoration: none; color: var(--text);
}
.photo-item img { width: 100%; height: 84px; object-fit: cover; display: block; }
.photo-item .photo-name {
  display: block; font-size: 12px; color: var(--muted); padding: 2px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo-item .photo-del {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,.2); background: rgba(0,0,0,.55); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.photo-pending { outline: 2px dashed var(--primary); }

/* ===== 列表项 ===== */
.list-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 10px; cursor: pointer;
}
.list-item:hover { background: #f9fafb; border-color: #d1d5db; }
.list-item .row1 { display: flex; align-items: center; gap: 8px; }
.list-item .row1 .no { font-weight: 600; }
.list-item .row2 { display: flex; gap: 16px; margin-top: 6px; color: var(--muted); font-size: 13px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.list-item .row3 { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.list-item .btn-mini { padding: 8px 12px; min-height: 44px; } /* 手机主操作区 */

/* ===== toast ===== */
.toast-box {
  position: fixed; top: 58px; left: 50%; transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(92vw, 480px);
}
.toast {
  background: rgba(17,24,39,.92); color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 14px; max-width: 100%; box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: toast-in .25s ease;
}
.toast-success { background: rgba(21,128,61,.97); } /* 白字 ≈5.0:1 */
.toast-error   { background: rgba(185,28,28,.97); } /* 白字 ≈6.5:1 */
.toast-warn    { background: rgba(180,83,9,.95); }
.toast-out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
table.data th, table.data td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap; }
table.data th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: 13px; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:nth-child(even) { background: #f9fafb; }
table.data tbody tr:hover { background: #f0fdf4; }

/* ===== Tabulator 适配（admin.html 中 vendor 先加载、app.css 后加载，覆盖生效） ===== */
.tabulator { font-size: 14px; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.tabulator .tabulator-header { background: #f9fafb; color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 600; }
.tabulator .tabulator-header .tabulator-col { background: #f9fafb; border-right: 1px solid var(--border); }
.tabulator .tabulator-row { min-height: 34px; }
.tabulator .tabulator-row.tabulator-row-even { background: #f9fafb; }
.tabulator .tabulator-row:hover { background: #f0fdf4; }
.tabulator .tabulator-cell { font-variant-numeric: tabular-nums; }
.batch-link { color: var(--primary-dark); cursor: pointer; text-decoration: underline; }

/* ===== 合计行 ===== */
.totals-bar {
  display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px;
  background: var(--primary-light); border-radius: 8px; padding: 8px 12px; font-size: 13px;
}
.totals-bar .totals-item { color: var(--primary-dark); }
.totals-bar b { font-variant-numeric: tabular-nums; }

/* ===== 三态（加载/错误/空） ===== */
.state-loading::before {
  content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 8px;
  vertical-align: -3px; border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: sx-spin .8s linear infinite;
}
@keyframes sx-spin { to { transform: rotate(360deg); } }
.state-error { color: var(--danger-text); }

/* ===== 统计卡片 ===== */
.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat-card .k { font-size: 12px; color: var(--muted); }
.stat-card .v { font-size: 20px; font-weight: 700; color: var(--primary-dark); margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; word-break: break-word; }

/* ===== 分段切换 ===== */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: none; background: #fff; padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--muted); min-height: 40px; }
.seg button.active { background: var(--primary-strong); color: #fff; }

/* ===== 模态框 ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,.5); z-index: 150;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; max-width: 860px; width: 100%;
  padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  max-height: calc(100dvh - 48px); overflow-y: auto; /* 弹窗内滚动 */
}
.modal .modal-head {
  position: sticky; top: -16px; z-index: 2; background: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0 8px; margin-bottom: 10px;
}
.modal .modal-head h3 { margin: 0; font-size: 16px; }
/* 批次/详情等宽表弹窗在宽屏放大（仅限这两个业务弹窗，改密码等小弹窗保持 860） */
#batch-modal .modal, #detail-modal .modal { max-width: min(1500px, 96vw); }
@media (max-width: 480px) { .modal { max-height: calc(100dvh - 24px); } }

/* ===== 登录页 ===== */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: linear-gradient(160deg, #ecfdf5, #dcfce7 40%, #f0fdf4);
}
.login-card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login-card h1 { margin: 0; text-align: center; font-size: 24px; color: var(--primary-dark); }
.login-card .sub { text-align: center; color: var(--muted); margin: 6px 0 20px; }
.login-card label.fld { margin-bottom: 14px; }
.login-card label.fld > span { color: var(--text); font-size: 14px; }
.login-tip { text-align: center; color: var(--muted); font-size: 12px; margin-top: 12px; }

/* ===== 键盘焦点可见性（P2-9） ===== */
a:focus-visible, button:focus-visible, .list-item:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

/* ===== 减少动效偏好（P2-10） ===== */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ===== 手机端适配 ===== */
@media (max-width: 480px) {
  /* 防 iOS Safari 聚焦 <16px 输入框自动放大页面 */
  input[type=text], input[type=password], input[type=date], input[type=number],
  input[type=tel], select, textarea { font-size: 16px; }
  /* 宽字段占整行，短字段保持两列 */
  .grid-2 > label.fld.wide { grid-column: 1 / -1; }
}

/* ===== 桌面端适配 ===== */
@media (min-width: 768px) {
  .page { max-width: 720px; }
  .photo-item img { height: 120px; }
}
@media (min-width: 1024px) {
  .page { max-width: 900px; }
  .page-wide { max-width: 1080px; }               /* 电脑端提报页紧凑版心 */
  .page-wide .grid-2 { grid-template-columns: repeat(3, 1fr); } /* 三列网格 */
  .page-wide .grid-2 > label.fld.wide { grid-column: span 2; }
  .page-wide .sum-grid { grid-template-columns: repeat(4, 1fr); }
  .photo-grid { grid-template-columns: repeat(5, 1fr); }
}

/* ===== 管理台全屏自适应（v1.4：表格铺满可用屏幕，随窗口缩放） ===== */
.page-full { max-width: none !important; padding: 12px 16px; }
.page-full .card { margin-bottom: 12px; }
