/* ============================================================
   采购自动化平台 — 现代亮色商务风（全视觉重设计）
   布局：左侧导航 + 主内容区；杜绝任何横向滚动条
   ============================================================ */
:root {
  --primary: #4f46e5;          /* 靛蓝主色 */
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --err: #dc2626;
  --err-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --violet: #7c3aed;
  --violet-soft: #f5f3ff;
  --text: #0f172a;
  --text-2: #475569;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --bg: #f6f7fb;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .05), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-hover: 0 8px 24px rgba(79, 70, 229, .14);
  --sidebar-w: 220px;
  --sidebar-w-min: 64px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { overflow-x: hidden; max-width: 100vw; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}

/* ============ 左侧导航 ============ */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; z-index: 50;
  transition: width .2s ease;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; padding: 4px 10px 20px;
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  display: flex; align-items: center; justify-content: center; font-size: 17px;
  box-shadow: 0 4px 10px rgba(79, 70, 229, .3);
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; border: none; background: none;
  font-size: 14px; color: var(--text-2); cursor: pointer; text-align: left;
  transition: all .15s ease; white-space: nowrap;
}
.nav-item .ico { font-size: 16px; width: 22px; text-align: center; flex: none; }
.nav-item:hover { background: var(--border-light); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);
}
.conn-status {
  padding: 10px 12px; font-size: 12px; color: var(--text-light);
  border-top: 1px solid var(--border-light); white-space: nowrap;
}
.conn-status .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e; margin-right: 6px; vertical-align: 1px;
}
.conn-status.running .dot { background: #f59e0b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ============ 主内容区 ============ */
.main { margin-left: var(--sidebar-w); padding: 26px 30px 40px; min-width: 0; }
.page { display: none; animation: fadein .25s ease; }
.page.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 18px; letter-spacing: .5px; }
.page-sub { font-size: 13px; color: var(--text-light); font-weight: 400; margin-left: 10px; }

/* ============ 卡片 ============ */
.panel {
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px;
}

/* ============ 数据总览：板块卡片 ============ */
.board-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.board-card {
  position: relative; overflow: hidden; cursor: pointer;
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px 16px; transition: all .18s ease;
}
.board-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
}
.board-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.board-card .bc-num { font-size: 32px; font-weight: 800; line-height: 1.1; }
.board-card .bc-label { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.board-card .bc-go { font-size: 12px; color: var(--text-light); margin-top: 10px; }
.board-card.b-pending::before { background: #f59e0b; } .board-card.b-pending .bc-num { color: #b45309; }
.board-card.b-ordered::before { background: #3b82f6; } .board-card.b-ordered .bc-num { color: #1d4ed8; }
.board-card.b-payable::before { background: #10b981; } .board-card.b-payable .bc-num { color: #047857; }
.board-card.b-paid::before { background: #8b5cf6; } .board-card.b-paid .bc-num { color: #6d28d9; }

/* 任务进度 */
.task-box {
  padding: 12px 16px; border-radius: 10px; font-size: 14px; margin: 14px 0 10px;
}
.task-box.idle { background: var(--border-light); color: var(--text-light); }
.task-box.running { background: var(--warn-soft); color: #92400e; font-weight: 500; }
.progress-wrap {
  height: 8px; background: var(--border-light); border-radius: 99px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, #6366f1, #4f46e5);
  transition: width .4s ease;
}
.hint { font-size: 12px; color: var(--text-light); margin-top: 12px; }

/* ============ 采购列表 ============ */
.list-topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.list-topbar .spacer { flex: 1; }
.select-wrap { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.select-wrap select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); font-size: 13px; color: var(--text); cursor: pointer; outline: none;
}
.select-wrap select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.selected-info { font-size: 13px; color: var(--text-light); }
.selected-info b { color: var(--primary); font-size: 15px; }

/* 板块子页签 */
.board-tabs {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px;
}
.board-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); font-size: 13.5px; color: var(--text-2);
  cursor: pointer; transition: all .15s ease; white-space: nowrap;
}
.board-tab .cnt {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; background: var(--border-light); color: var(--text-2);
}
.board-tab:hover { border-color: var(--primary); color: var(--primary); }
.board-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.board-tab.active .cnt { background: rgba(255,255,255,.25); color: #fff; }
.board-tab[data-board="pending"] .cnt { background: var(--warn-soft); color: #b45309; }
.board-tab[data-board="ordered"] .cnt { background: var(--info-soft); color: #1d4ed8; }
.board-tab[data-board="payable"] .cnt { background: var(--ok-soft); color: #047857; }
.board-tab[data-board="paid"] .cnt { background: var(--violet-soft); color: #6d28d9; }
.board-tab.active[data-board] .cnt { background: rgba(255,255,255,.25); color: #fff; }

/* 板块操作条 */
.board-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

/* ============ 表格 ============ */
.table-panel { padding: 6px 6px 2px; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.data-table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-light);
  padding: 11px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; text-transform: uppercase; letter-spacing: .4px;
}
.data-table td {
  padding: 11px 12px; border-bottom: 1px solid var(--border-light);
  font-size: 13.5px; vertical-align: middle;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: #f8fafc; }
tr.row-error td { background: var(--err-soft); }
tr.row-error:hover td { background: #fee2e2; }
tr.row-ok td { background: #fbfdff; }
td.col-check { width: 36px; text-align: center; }
td.col-qty { text-align: center; }
th.col-qty { text-align: center; }
.col-check input[type="checkbox"] { cursor: pointer; accent-color: var(--primary); }

/* 状态徽章 */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-pending { background: var(--warn-soft); color: #b45309; }
.badge-ok { background: var(--ok-soft); color: #047857; }
.badge-err { background: var(--err-soft); color: #b91c1c; }
.badge-info { background: var(--info-soft); color: #1d4ed8; }
.badge-muted { background: var(--border-light); color: var(--text-2); }
.badge-violet { background: var(--violet-soft); color: #6d28d9; }

.err-text { color: var(--err); font-size: 12.5px; }
.ok-text { color: var(--ok); }
.ww-sub { display: block; font-size: 11px; color: var(--text-light); margin-top: 2px; }
.empty { text-align: center; color: var(--text-light); padding: 34px 0 !important; }
.order-no-cell { font-family: Consolas, Menlo, monospace; font-size: 12.5px; cursor: pointer; }
.order-no-cell:hover { color: var(--primary); text-decoration: underline; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-2); font-size: 13.5px;
  cursor: pointer; transition: all .15s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); box-shadow: var(--shadow); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.primary {
  background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .3);
}
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.warn { background: var(--warn-soft); border-color: #fcd34d; color: #b45309; }
.btn.warn:hover { border-color: var(--warn); color: var(--warn); }
.btn.danger { background: var(--err-soft); border-color: #fecaca; color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.pay { background: var(--ok-soft); border-color: #a7f3d0; color: #047857; }
.btn.pay:hover { border-color: var(--ok); color: var(--ok); box-shadow: var(--shadow); }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 8px; }

/* ============ AI判读弹窗 ============ */
.judge-tip {
  font-size: 13px; line-height: 1.6; color: #64748b;
  padding: 8px 10px; border-radius: 8px; background: #f1f5f9; min-height: 18px;
}
.judge-tip.judge-ok { color: #047857; background: #ecfdf5; }
.judge-tip.judge-err { color: #b91c1c; background: #fef2f2; }

/* ============ 日志 ============ */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer, .toolbar .log-count { flex: 1; font-size: 13px; color: var(--text-light); }
.log-panel {
  max-height: 560px; overflow-y: auto; padding: 14px 18px;
  font-family: Consolas, Menlo, monospace; font-size: 12.5px; line-height: 1.9;
}
.log-line { white-space: pre-wrap; word-break: break-all; }
.log-time { color: var(--text-light); margin-right: 8px; }
.log-step { color: var(--primary); margin-right: 6px; }
.log-op { color: #7c3aed; font-size: 11px; margin-right: 6px; font-weight: 600; }

/* token 到期预警横幅 */
.token-banner { display: flex; align-items: center; gap: 8px; margin: 0 0 14px;
                padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.token-banner.err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.token-banner.warn { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.log-error { color: var(--err); }
.log-success { color: var(--ok); }
.log-info { color: var(--text-2); }
.log-empty { text-align: center; color: var(--text-light); padding: 40px 0; }

/* ============ 配置表单 ============ */
form.panel h3 {
  font-size: 15px; margin: 26px 0 14px; padding-left: 10px;
  border-left: 3px solid var(--primary); color: var(--text);
}
form.panel h3:first-child { margin-top: 0; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px 18px; margin-bottom: 14px;
}
.form-grid label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--text-2); font-weight: 500; min-width: 0;
}
.form-grid input, .form-grid textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13.5px; outline: none; transition: all .15s ease; width: 100%;
  font-family: inherit;
}
.form-grid input:focus, .form-grid textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.checkbox-line { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-line input { width: auto !important; accent-color: var(--primary); }
.test-result { margin: 12px 0 4px; font-size: 13px; min-height: 20px; word-break: break-all; }
.form-actions { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border-light); }

/* ============ Toast ============ */
.toast {
  position: fixed; top: 22px; left: 50%; transform: translateX(-50%) translateY(-80px);
  background: var(--text); color: #fff; padding: 11px 22px; border-radius: 12px;
  font-size: 13.5px; box-shadow: 0 8px 30px rgba(15, 23, 42, .25);
  opacity: 0; transition: all .3s ease; z-index: 999; max-width: 80vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

/* ============ 响应式（窄屏收起侧栏文字，绝不出现横向滚动条） ============ */
@media (max-width: 1100px) {
  .sidebar { width: var(--sidebar-w-min); padding: 18px 8px; }
  .brand { padding: 4px 4px 18px; }
  .brand .txt { display: none; }
  .nav-item { justify-content: center; padding: 11px 8px; }
  .nav-item .txt { display: none; }
  .conn-status { text-align: center; padding: 10px 2px; font-size: 0; }
  .main { margin-left: var(--sidebar-w-min); padding: 20px 16px 32px; }
  .data-table td { max-width: 160px; }
}
@media (max-width: 720px) {
  .data-table td, .data-table th { padding: 8px 6px; font-size: 12.5px; }
  .hide-sm { display: none; }
}
