/* ============================================================
   Proforma Invoice 生成器 - 样式
   ============================================================ */
:root {
  --primary: #1a56db;
  --primary-dark: #1e40af;
  --primary-light: #eff6ff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --danger: #ef4444;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* 顶部导航 */
.topbar { background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { color: var(--primary); font-size: 22px; }
.brand h1 { font-size: 18px; font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab-btn { border: none; background: transparent; padding: 8px 16px; font-size: 14px; color: var(--text-muted); cursor: pointer; border-radius: 8px; font-weight: 500; transition: all .15s; }
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--primary-light); color: var(--primary); }
.topbar-actions { display: flex; gap: 8px; }

/* 按钮 */
.btn { border: none; padding: 8px 18px; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }

/* 容器 */
.container { max-width: 1100px; margin: 24px auto; padding: 0 24px 60px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.panel-head h2 { font-size: 16px; font-weight: 600; }
.panel-actions { display: flex; align-items: center; gap: 10px; }

.hint { font-size: 12px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.mono { font-family: "JetBrains Mono", "Consolas", monospace; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.center { text-align: center; }
.hidden { display: none !important; }

/* 公司名称大字输入 */
.company-name-input {
  text-align: center;
  font-size: 20px !important;
  font-weight: 700 !important;
  border: 1px dashed var(--border) !important;
  background: #fafbfc !important;
}
.company-name-input:focus { border-color: var(--primary) !important; }

/* 双栏布局 */
.dual-col { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 16px; }
.dual-col .col { display: flex; flex-direction: column; gap: 10px; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.field input, .field textarea, .field select, .add-row input, .search-row input, .cell-carton, .cell-price {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field select:focus, .add-row input:focus, .search-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.field input[readonly] {
  background: #f8fafc;
  color: var(--text);
  cursor: default;
}
.readonly-text {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #f8fafc;
  min-height: 36px;
  line-height: 1.5;
  word-break: break-all;
}

/* Invoice 行 */
.invoice-row { display: flex; gap: 24px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.invoice-row .field { flex: 1; max-width: 300px; }

/* 添加行 */
.add-row { display: flex; gap: 12px; align-items: flex-start; }
.add-row .autocomplete-wrap { flex: 1; position: relative; }
.add-row #cartonInput { width: 110px; flex: none; }
.cap-select { width: 130px; flex: none; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; color: var(--text); background: #fff; outline: none; cursor: pointer; }
.cap-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
.cap-select option:first-child { color: var(--text-muted); }
.msg { font-size: 13px; min-height: 18px; margin-top: 10px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* 联想下拉 */
.suggest-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); list-style: none; z-index: 50;
  max-height: 320px; overflow-y: auto; margin-top: 4px;
}
.suggest-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--bg); font-size: 13px; }
.suggest-list li:last-child { border-bottom: none; }
.suggest-list li:hover, .suggest-list li.active { background: var(--primary-light); }
.suggest-list li .num { margin-left: auto; color: var(--primary); font-weight: 600; }

/* 数据表 */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; background: #f8fafc; color: var(--text-muted); font-weight: 600; padding: 10px 8px; border-bottom: 2px solid var(--border); white-space: nowrap; font-size: 12px; }
.data-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: #fafbfc; }
.empty-row td { text-align: center; color: var(--text-muted); padding: 28px; }
.cell-carton, .cell-price { padding: 5px 8px; font-size: 13px; width: 70px; }
.cell-price { width: 90px; }
.price-cell-wrap { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.price-toggle {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}
.price-toggle:hover { opacity: 0.8; }
.toggle-icon {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform .2s;
}
.price-toggle:hover .toggle-icon { transform: rotate(180deg); color: var(--primary); }
.btn-del { border: none; background: #fef2f2; color: var(--danger); width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1; transition: background .15s; }
.btn-del:hover { background: #fee2e2; }

/* 箱数编辑高亮动画 */
@keyframes carton-flash {
  0% { background-color: #fef3c7; transform: scale(1.05); box-shadow: 0 0 0 3px rgba(26,86,219,.2); }
  25% { background-color: #fde68a; transform: scale(1.1); box-shadow: 0 0 0 4px rgba(26,86,219,.35); }
  50% { background-color: #fef3c7; transform: scale(1.05); box-shadow: 0 0 0 3px rgba(26,86,219,.2); }
  75% { background-color: #fef9c3; transform: scale(1.02); box-shadow: 0 0 0 2px rgba(26,86,219,.1); }
  100% { background-color: #fff; transform: scale(1); box-shadow: none; }
}
.cell-carton.highlight {
  animation: carton-flash 1.2s ease-in-out;
  border-color: var(--primary) !important;
}

/* 搜索 */
.search-row { margin-bottom: 14px; }
.search-row input { max-width: 320px; }

/* 金额汇总 */
.summary-row { margin-top: 8px; }
.sum-item { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 14px 20px; display: flex; flex-direction: column; gap: 4px; }
.sum-item span { font-size: 13px; color: var(--text-muted); }
.sum-item b { font-size: 22px; font-weight: 700; }
.sum-item.total { background: var(--primary); border-color: var(--primary); flex-direction: row; align-items: center; justify-content: space-between; }
.sum-item.total span { color: rgba(255,255,255,.85); font-size: 15px; }
.sum-item.total b { color: #fff; font-size: 24px; }

/* ============================================================
   预览弹窗
   ============================================================ */
.preview-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  z-index: 300;
}
.preview-toolbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.preview-title { font-size: 16px; font-weight: 600; }
.preview-toolbar-actions { display: flex; gap: 8px; }
.preview-body {
  flex: 1;
  overflow: auto;
  padding: 40px 24px;
  display: flex;
  justify-content: center;
}
.preview-doc {
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  padding: 32px 40px;
  min-height: 600px;
  width: 820px;
  max-width: 100%;
}
.preview-doc .doc {
  max-width: 100%;
  padding: 0;
  margin: 0;
  font-family: "Times New Roman", "Noto Sans CJK SC", serif;
  font-size: 12px;
  color: #000;
}
.preview-doc .pi-grid { width: 100%; }
.preview-doc .pi-grid td { border: 1px solid #000; padding: 2px 4px; vertical-align: middle; word-wrap: break-word; }
.preview-doc .pi-grid .hdr { background: #B4C7E7; font-weight: bold; font-size: 12px; text-align: center; vertical-align: middle; padding: 4px 2px; }
.preview-doc .pi-grid .lbl { font-weight: bold; font-size: 12px; text-align: center; white-space: nowrap; }
.preview-doc .pi-grid .val { font-size: 10px; text-align: left; }
.preview-doc .pi-grid .c { text-align: center; }
.preview-doc .pi-grid .total-lbl { font-weight: bold; font-size: 12px; text-align: center; }
.preview-doc .pi-grid .total-val { font-weight: bold; font-size: 12px; text-align: center; }
.preview-doc .pi-title { text-align: center; font-size: 16px; font-weight: bold; padding: 4px; }
.preview-doc .pi-spacer { border: none !important; padding: 0 !important; height: 8px; font-size: 1px; }
.preview-doc .doc-header { position: relative; text-align: center; margin-bottom: 2px; min-height: 90px; }
.preview-doc .doc-logo { position: absolute; left: 0; top: 0; width: 150px; height: auto; max-height: 90px; }
.preview-doc .doc-co-name { font-size: 20px; font-weight: bold; text-align: center; line-height: 40px; padding-top: 10px; }
.preview-doc .doc-addr { margin-top: 14px; font-size: 12px; }
.preview-doc .doc-addr-lbl { font-weight: bold; margin-bottom: 2px; }
.preview-doc .doc-addr-val { white-space: pre-line; line-height: 1.6; }
.preview-doc .doc-bank { margin-top: 10px; font-size: 12px; }
.preview-doc .doc-bank-lbl { font-weight: bold; margin-bottom: 2px; }
.preview-doc .doc-bank div { line-height: 1.6; }

/* ============================================================
   容量选择弹窗
   ============================================================ */
.capacity-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.capacity-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 580px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.capacity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.capacity-title { font-size: 16px; font-weight: 600; }
.capacity-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 100px;
}
.capacity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.capacity-table th { text-align: left; background: #f8fafc; color: var(--text-muted); font-weight: 600; padding: 8px; border-bottom: 2px solid var(--border); font-size: 12px; }
.capacity-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.cap-row { cursor: pointer; transition: background .1s; }
.cap-row:hover { background: #f1f5f9; }
.cap-row.selected { background: var(--primary-light); }
.cap-row.selected td { border-bottom-color: #bfdbfe; }
.cap-price-cell { text-align: right; white-space: nowrap; }
.cap-std-price { font-weight: 600; color: var(--text); }
.cap-agent-price { color: #b45309; }
.capacity-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  gap: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.cap-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.cap-right { display: flex; align-items: center; gap: 8px; }
.cap-qty { display: flex; align-items: center; gap: 8px; }
.cap-qty label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.cap-qty input { width: 80px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 14px; text-align: center; outline: none; }
.cap-qty input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
.cap-price-type { display: flex; align-items: center; gap: 8px; }
.cap-price-type label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

/* 打印文档样式 - 完全匹配 Excel 模板 */
.doc {
  font-family: "Times New Roman", "Noto Sans CJK SC", serif;
  font-size: 12px;
  color: #000;
  padding: 8px;
  max-width: 820px;
  margin: 0 auto;
}

/* 头部:logo + 公司名称 */
.doc-header {
  position: relative;
  text-align: center;
  margin-bottom: 2px;
  min-height: 90px;
}
.doc-logo {
  position: absolute;
  left: 0;
  top: 0;
  width: 150px;
  height: auto;
  max-height: 90px;
}
.doc-co-name {
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  line-height: 40px;
  padding-top: 10px;
}

/* 10列网格表 - 匹配 Excel A-J 列 */
.pi-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  table-layout: fixed;
}
.pi-grid td {
  border: 1px solid #000;
  padding: 2px 4px;
  vertical-align: middle;
  word-wrap: break-word;
}

/* 间隔行 */
.pi-spacer {
  border: none !important;
  padding: 0 !important;
  height: 8px;
  font-size: 1px;
  line-height: 1px;
}

/* 标签和值 */
.pi-grid .lbl {
  font-weight: bold;
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
}
.pi-grid .val {
  font-size: 10px;
  text-align: left;
}
.pi-grid .cell-b {
  font-size: 10px;
}

/* Proforma Invoice 标题行 */
.pi-title {
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  padding: 4px;
}

/* 表头 */
.pi-grid .hdr {
  background: #B4C7E7;
  font-weight: bold;
  font-size: 12px;
  text-align: center;
  vertical-align: middle;
  padding: 4px 2px;
  line-height: 1.3;
}

/* 数据行 */
.pi-grid .c { text-align: center; }
.pi-grid .empty { color: #999; padding: 20px; }

/* 合计行 */
.pi-grid .total-lbl {
  background: #fff;
  font-weight: bold;
  font-size: 12px;
  text-align: center;
}
.pi-grid .total-val {
  background: #fff;
  font-weight: bold;
  font-size: 12px;
  text-align: center;
}
.pi-grid .total-e {
  background: #fff;
}

/* 地址 */
.doc-addr {
  margin-top: 14px;
  font-size: 12px;
}
.doc-addr-lbl {
  font-weight: bold;
  margin-bottom: 2px;
}
.doc-addr-val {
  white-space: pre-line;
  line-height: 1.6;
}

/* 银行信息 */
.doc-bank {
  margin-top: 10px;
  font-size: 12px;
}
.doc-bank-lbl {
  font-weight: bold;
  margin-bottom: 2px;
}
.doc-bank div {
  line-height: 1.6;
}

/* ---- 代理价格标记 ---- */
.badge-agent {
  display: inline-block;
  background: #fef3c7;
  color: #b45309;
  font-size: 11px;
  font-weight: 700;
  padding: 0 6px;
  border-radius: 4px;
  line-height: 1.8;
  letter-spacing: 0.5px;
}
.badge-sm {
  font-size: 10px;
  padding: 1px 5px;
  line-height: 1.5;
  vertical-align: middle;
  margin-left: 4px;
}
.row-agent {
  background: #fffbeb !important;
}
.row-agent:hover {
  background: #fef3c7 !important;
}
/* ---- 配置文件标记 ---- */
.cfg-badge {
  display: inline-block;
  background: #fef3c7;
  color: #b45309;
  font-size: 10px;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 3px;
  line-height: 1.6;
  vertical-align: middle;
  margin-left: 3px;
  letter-spacing: 0.3px;
}
.cfg-hint {
  display: block;
  font-size: 11px;
  color: #b45309;
  margin-top: 2px;
}

/* 价格切换 radio 按钮组 */
.price-radio-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.price-radio {
  border: none;
  background: #fff;
  color: var(--text-muted);
  font-size: 13px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  font-weight: 500;
  white-space: nowrap;
}
.price-radio:not(:last-child) {
  border-right: 1px solid var(--border);
}
.price-radio.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.price-radio.active[data-type="agent"] {
  background: #f59e0b;
  color: #fff;
}