/* MG Agro CRM — 样式。颜色、圆角与原版保持一致（经典浅绿 / 经典深色 / 深色商务 / 浅色商务） */
:root {
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #ccfbf1;
  --primary-text: #0f766e;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --input: #ffffff;
  --hover: #f1f5f9;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --thead: #f1f5f9;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --font: 'Inter', 'Noto Sans SC', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color-scheme: light;
}
[data-theme='classic-dark'] {
  --primary: #14b8a6; --primary-hover: #2dd4bf; --primary-soft: rgba(20, 184, 166, 0.16); --primary-text: #5eead4;
  --bg: #0b1220; --card: #111827; --border: #1f2937; --border-strong: #374151; --text: #e5e7eb; --muted: #94a3b8;
  --input: #0f172a; --hover: #1e293b; --thead: #1e293b; color-scheme: dark;
}
[data-theme='business-dark'] {
  --primary: #3b82f6; --primary-hover: #60a5fa; --primary-soft: rgba(59, 130, 246, 0.16); --primary-text: #93c5fd;
  --bg: #0a0f1a; --card: #111827; --border: #1e293b; --border-strong: #334155; --text: #e2e8f0; --muted: #94a3b8;
  --input: #0f172a; --hover: #1e293b; --thead: #1e293b; color-scheme: dark;
}
[data-theme='business-light'] {
  --primary: #1d4ed8; --primary-hover: #1e40af; --primary-soft: #dbeafe; --primary-text: #1d4ed8; --bg: #f5f7fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tnum { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.span2 { grid-column: span 2; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand img { width: 36px; height: 36px; border-radius: 10px; }
.brand b { display: block; font-size: 15px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-size: 14px; opacity: 0.85; }
.nav a:hover { background: var(--hover); opacity: 1; }
.nav a.active { background: var(--primary-soft); color: var(--primary-text); opacity: 1; font-weight: 500; }
.nav svg, .ico { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.sync-state { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-height: 18px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sync-dot.busy { background: var(--warn); animation: pulse 1s infinite; }
.sync-dot.err { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }
.main { flex: 1; min-width: 0; padding: 24px; }
.topbar { display: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 24px; }
.card + .card { margin-top: 0; }
.card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card .desc { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.cols { display: grid; gap: 16px; align-items: start; }
.cols-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.cols-1-1 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.cols-list { grid-template-columns: 280px minmax(0, 1fr); }
.sticky { position: sticky; top: 16px; }

/* ---------- 表单 ---------- */
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
label.f > span { color: var(--text); }
label.f small { color: var(--muted); font-weight: 400; font-size: 12px; }
.in, select.in, textarea.in { width: 100%; border: 1px solid var(--border); background: var(--input); border-radius: 8px; padding: 9px 12px; min-height: 40px; outline: none; transition: border-color 0.15s, box-shadow 0.15s; }
textarea.in { min-height: 72px; resize: vertical; line-height: 1.45; }
.in:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.in[readonly], .in:disabled { background: var(--hover); color: var(--muted); }
.in.sm { min-height: 32px; padding: 5px 8px; font-size: 13px; }
.in.num { text-align: right; font-variant-numeric: tabular-nums; }
.searchbox { position: relative; }
.searchbox .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbox .in { padding-left: 36px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 8px; padding: 0 14px; height: 36px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn { background: #ea580c; border-color: #ea580c; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 30px; }
.btn.block { width: 100%; }
.btn-group { display: inline-flex; gap: 4px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: 8px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { background: var(--thead); text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 10px 8px; white-space: nowrap; }
.tbl td { padding: 12px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: var(--hover); }
.tbl .sub { color: var(--muted); font-size: 12px; }
.tbl .ep { color: var(--primary-text); font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--hover); border: 1px solid var(--border); white-space: nowrap; }
.badge.teal { background: var(--primary-soft); color: var(--primary-text); border-color: transparent; }
.badge.warn { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.badge.danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge.ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.badge.blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge.purple { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
[data-theme$='dark'] .badge.warn, [data-theme$='dark'] .badge.danger, [data-theme$='dark'] .badge.ok, [data-theme$='dark'] .badge.blue, [data-theme$='dark'] .badge.purple { background: transparent; }
.empty { border: 1px dashed var(--border-strong); border-radius: 10px; padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---------- 明细行编辑 ---------- */
.line { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--card); }
.line + .line { margin-top: 10px; }
.line-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.line-head b { font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.summary-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.grand { font-size: 26px; font-weight: 700; color: var(--primary-text); font-variant-numeric: tabular-nums; }
.formula { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--hover); border-radius: 8px; padding: 10px 12px; color: var(--muted); line-height: 1.6; }
.preview-box { background: var(--hover); border: 1px dashed var(--border-strong); border-radius: 10px; padding: 20px; white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; line-height: 2; min-height: 300px; }
.list-item { display: block; width: 100%; text-align: left; border: 1px solid var(--border); background: var(--card); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.list-item:hover { border-color: var(--primary); }
.list-item.active { border-color: var(--primary); background: var(--primary-soft); }
.list-item + .list-item { margin-top: 8px; }
.list-item b { display: block; font-size: 14px; }
.list-item span { font-size: 12px; color: var(--muted); }
.totalbar { position: sticky; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--primary); background: var(--card); border-radius: var(--radius); padding: 12px 20px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); }
.sig-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.sig-img { height: 110px; border-radius: 8px; background: var(--hover); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; overflow: hidden; }
.sig-img img { max-height: 100%; max-width: 100%; }
.img-slot { width: 100%; max-width: 260px; aspect-ratio: 210 / 120; border: 1px dashed var(--border-strong); border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--hover); color: var(--muted); font-size: 12px; }
.img-slot img { max-width: 100%; max-height: 100%; }
.img-slot.a4 { aspect-ratio: 210 / 297; max-width: 160px; }

/* ---------- 看板 ---------- */
.stats { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.stat .lbl { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; align-items: start; overflow-x: auto; }
.col { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); min-height: 200px; display: flex; flex-direction: column; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; font-weight: 600; }
.col-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; flex: 1; }
.col.drop .col-body { background: var(--primary-soft); }
.kcard { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--card); cursor: grab; display: flex; flex-direction: column; gap: 6px; }
.kcard:hover { border-color: var(--border-strong); box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06); }
.kcard.dragging { opacity: 0.4; }
.kcard .no { font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
.kcard .pname { font-weight: 600; font-size: 15px; }
.kcard .en { color: var(--muted); font-size: 12px; }
.kcard .meta { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }
.chip.done { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.chip.doing { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.chip.blocked { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.chip.pending { color: var(--muted); }
.progress { height: 4px; background: var(--hover); border-radius: 4px; overflow: hidden; width: 64px; }
.progress > i { display: block; height: 100%; border-radius: 4px; }
.charts { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.chart-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.chart-box h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend div { display: flex; gap: 6px; align-items: center; }
.hbar { display: grid; grid-template-columns: 120px 1fr 32px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.hbar .bar { height: 18px; border-radius: 4px; }

/* ---------- 弹窗 / 提示 ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 760px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.modal.wide { max-width: 960px; }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); max-width: 420px; animation: tin 0.2s; }
.toast.err { background: #b91c1c; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.banner { border: 1px solid #fed7aa; background: #fff7ed; color: #9a3412; border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 12px; }
[data-theme$='dark'] .banner { background: transparent; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.loading { padding: 80px; text-align: center; color: var(--muted); }

/* ---------- A4 单据 ---------- */
.doc-stage { background: #e5e7eb; border-radius: 12px; padding: 20px; overflow: auto; }
[data-theme$='dark'] .doc-stage { background: #1f2937; }
.doc-scale { transform-origin: top left; }
.page { width: 210mm; height: 297mm; background: #fff; color: #111; position: relative; overflow: hidden; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); margin: 0 auto 16px; font-family: 'Inter', 'Noto Sans SC', 'Noto Sans Thai', Arial, sans-serif; font-size: 10pt; line-height: 1.4; }
.page .lh { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; z-index: 0; }
.page .pc { position: absolute; left: 18mm; right: 18mm; top: 16mm; bottom: 14mm; z-index: 1; }
.page.with-lh .pc { top: 36mm; }
.page.serif { font-family: 'Times New Roman', Times, 'Noto Serif SC', 'Noto Serif Thai', serif; }
.page .pno { position: absolute; bottom: 7mm; right: 18mm; font-size: 8pt; color: #888; z-index: 1; }
.d-title { text-align: center; font-size: 17pt; font-weight: 700; letter-spacing: 0.12em; margin: 2mm 0 4mm; }
.d-co { text-align: center; }
.d-co b { font-size: 13pt; display: block; }
.d-co span { font-size: 8.5pt; color: #333; }
.d-meta { display: flex; justify-content: space-between; gap: 8mm; margin-bottom: 4mm; }
.d-meta .blk { font-size: 9.5pt; }
.d-meta .blk b { font-weight: 700; }
.d-kv { display: grid; grid-template-columns: auto 1fr; gap: 0.6mm 3mm; font-size: 9pt; }
.d-kv dt { font-weight: 700; white-space: nowrap; }
.d-kv dd { margin: 0; }
.d-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; margin-bottom: 4mm; }
.d-party { border: 0.3mm solid #999; padding: 2.5mm 3mm; font-size: 9pt; }
.d-party h5 { margin: 0 0 1mm; font-size: 9pt; letter-spacing: 0.04em; }
table.dt { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 9pt; }
table.dt + table.dt { margin-top: -0.3mm; }
.dt th, .dt td { border: 0.3mm solid #555; padding: 1.6mm 2mm; vertical-align: top; word-wrap: break-word; }
.dt th { background: #eef2f1; font-weight: 700; text-align: center; font-size: 8.5pt; }
.page.serif .dt th { background: #f3f4f6; }
.dt td.r { text-align: right; white-space: nowrap; }
.dt td.c { text-align: center; }
.dt .pre { white-space: pre-wrap; }
.dt tr.tot td { font-weight: 700; }
.d-sec { margin-top: 3.5mm; font-size: 9pt; }
.d-sec h5 { margin: 0 0 1mm; font-size: 9.5pt; }
.d-sec p { margin: 0.6mm 0; white-space: pre-wrap; }
.d-words { margin-top: 3mm; font-weight: 700; font-size: 9pt; }
.d-dash { border-top: 0.3mm dashed #999; margin: 3mm 0; }
.d-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 12mm; margin-top: 6mm; font-size: 9pt; }
.d-sign .s { border-top: 0.3mm solid #333; padding-top: 1.5mm; position: relative; }
.d-sign .simg { height: 22mm; display: flex; align-items: flex-end; }
.d-sign .simg img { max-height: 22mm; max-width: 60mm; }
.d-thanks { margin-top: 5mm; font-size: 9pt; color: #333; }
.d-footnote { margin-top: 4mm; font-size: 8pt; color: #555; }
.d-logo { position: absolute; top: 0; right: 0; max-height: 14mm; max-width: 40mm; }

/* ---------- 打印：只打印单据 ---------- */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  body.printing > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-root .page { margin: 0; box-shadow: none; page-break-after: always; break-after: page; }
  .print-root .page:last-child { page-break-after: auto; break-after: auto; }
}
.print-root { display: none; }

/* ---------- 手机 ---------- */
@media (max-width: 1100px) {
  .cols-2-1, .cols-1-1, .cols-list { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .charts { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 760px) {
  .app { display: block; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2); }
  .app.menu-open .sidebar { transform: none; }
  .scrim { display: none; }
  .app.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 39; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .topbar b { flex: 1; }
  .main { padding: 16px; }
  .page-head h1 { font-size: 20px; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 16px; }
  .board { grid-template-columns: repeat(4, 85vw); }
  .hbar { grid-template-columns: 90px 1fr 28px; }
  .toasts { left: 16px; right: 16px; align-items: stretch; }
}
