:root {
  --primary: #C0271A;        /* KIBOKO红 */
  --primary-dark: #7A1508;   /* 印章红 */
  --primary-light: #F7E8E4;  /* 红的浅暖底 */
  --danger: #C0271A;
  --success: #2e9e5b;
  --warning: #e6a23c;
  --text: #2E1B14;
  --text-light: #8a6f66;
  --border: #e6d8d0;
  --bg: #FAF5EF;             /* 暖米白 */
  --sidebar-bg: #ffffff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "Segoe UI", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

/* ---------- 登录页 ---------- */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #FAF5EF 0%, #F1E3DB 55%, #EAD3C8 100%);
}
#login-screen::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px;
  background: linear-gradient(90deg, #7A1508, #C0271A, #7A1508);
}
.login-box {
  background: #fff; border-radius: 10px; padding: 34px 40px; width: 380px;
  box-shadow: 0 18px 50px rgba(122, 21, 8, .16);
  border-top: 4px solid #C0271A;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-box h1 { font-size: 19px; text-align: center; margin-bottom: 6px; letter-spacing: 2px; color: var(--text); }
.login-box .sub { text-align: center; color: var(--text-light); margin-bottom: 26px; }
.login-box .field { margin-bottom: 16px; }
.login-box label { display: block; margin-bottom: 6px; color: var(--text-light); }
.login-box input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 12px; min-height: 16px; margin-bottom: 8px; }
.login-tip { margin-top: 18px; font-size: 11px; color: var(--text-light); text-align: center; }

/* ---------- 主框架 ---------- */
#app { display: none; height: 100vh; flex-direction: column; }
#app.show { display: flex; }
.topbar {
  height: 54px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 18px; gap: 12px; flex-shrink: 0;
}
.topbar .logo { display: flex; align-items: center; gap: 10px; }
.topbar .logo .logo-img { display: block; filter: drop-shadow(0 1px 0 rgba(122,21,8,.05)); }
.topbar .logo .sys-name { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: 1px; padding-left: 10px; border-left: 2px solid var(--border); }
.login-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-logo img { height: 56px; width: auto; }
.topbar .logo .mark {
  width: 28px; height: 28px; border-radius: 6px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;
}
.topbar .spacer { flex: 1; }
.topbar .user-info { color: var(--text-light); display: flex; align-items: center; gap: 10px; }
.topbar .user-info .role-tag {
  background: var(--primary-light); color: var(--primary); padding: 2px 8px; border-radius: 10px; font-size: 11px;
}
.layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 208px; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 10px 0 40px; flex-shrink: 0;
  transition: width .18s ease; overflow-x: hidden;
}
.sidebar .nav-group { margin-bottom: 2px; }
.sidebar .group-title {
  padding: 12px 16px 5px; font-size: 11px; color: var(--text-light); letter-spacing: 1px;
  display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none;
}
.sidebar .group-title:hover { color: var(--primary); }
.sidebar .gt-arrow { font-size: 9px; width: 10px; text-align: center; transition: transform .15s ease; opacity: .7; }
.sidebar .nav-group.collapsed .gt-arrow { transform: rotate(-90deg); }
.sidebar .gt-txt { white-space: nowrap; }
.sidebar .gt-badge {
  margin-left: auto; font-size: 10px; line-height: 1; padding: 2px 6px; border-radius: 8px;
  background: var(--primary-light); color: var(--primary); opacity: .85;
}
.sidebar .gt-bar { display: none; }
.sidebar .nav-group.collapsed .group-items { display: none; }
.sidebar a {
  display: flex; align-items: center; gap: 8px; padding: 9px 15px; color: var(--text);
  text-decoration: none; border-left: 3px solid transparent; cursor: pointer;
  white-space: nowrap; overflow: hidden;
}
.sidebar a:hover { background: var(--primary-light); }
.sidebar a.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.sidebar a .ic { width: 16px; text-align: center; opacity: .75; flex-shrink: 0; }
.sidebar a .t { overflow: hidden; text-overflow: ellipsis; }

/* ---- 迷你模式（往左收窄：仅显示图标） ---- */
.sidebar.mini { width: 52px; }
.sidebar.mini .gt-arrow, .sidebar.mini .gt-txt, .sidebar.mini .gt-badge { display: none; }
.sidebar.mini .gt-bar { display: block; width: 18px; height: 2px; border-radius: 1px; background: var(--border); margin: 0 auto; }
.sidebar.mini .group-title { padding: 10px 0 4px; justify-content: center; }
.sidebar.mini .nav-group.collapsed .group-items { display: block; }
.sidebar.mini a { justify-content: center; padding: 9px 0; gap: 0; border-left-width: 3px; }
.sidebar.mini a .t { display: none; }
.sidebar.mini a .ic { width: auto; font-size: 15px; }

/* ---- 侧栏展开/收窄切换按钮 ---- */
.sidebar-toggle {
  position: absolute; z-index: 30; top: 50%; transform: translateY(-50%); left: 208px;
  width: 18px; height: 52px; padding: 0;
  border: 1px solid var(--border); border-left: none; border-radius: 0 12px 12px 0;
  background: #fff; color: var(--primary); font-weight: 700;
  font-size: 13px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 2px 0 8px rgba(122,21,8,.12);
  transition: left .18s ease, background .15s ease, color .15s ease;
}
.sidebar-toggle:hover { background: var(--primary-light); color: var(--primary-dark); box-shadow: 2px 0 10px rgba(122,21,8,.18); }
#sidebar.mini + .sidebar-toggle { left: 52px; }
.main { flex: 1; overflow-y: auto; padding: 18px 22px; min-width: 0; }

/* ---------- 通用组件 ---------- */
.page-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.page-title .desc { font-size: 12px; color: var(--text-light); font-weight: 400; }
.card {
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px;
}
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; }
input.ipt, select.ipt {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
  background: #fff; color: var(--text); min-width: 0;
}
input.ipt:focus, select.ipt:focus { outline: none; border-color: var(--primary); }
button.btn {
  padding: 7px 16px; border: none; border-radius: 6px; font-size: 13px; cursor: pointer;
  background: var(--primary); color: #fff; display: inline-flex; align-items: center; gap: 5px;
}
button.btn:hover { background: var(--primary-dark); }
button.btn.gray { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.btn.gray:hover { background: var(--bg); }
button.btn.danger { background: var(--danger); }
button.btn.danger:hover { background: #b53a36; }
button.btn.sm { padding: 4px 10px; font-size: 12px; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
table.tbl th, table.tbl td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap;
}
table.tbl th { background: #F4EAE2; color: #7a5c52; font-weight: 600; font-size: 12px; }
table.tbl tr:hover td { background: #FBF4EE; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .pos { color: var(--success); }
table.tbl .neg { color: var(--danger); }
.empty-tip { text-align: center; color: var(--text-light); padding: 40px 0; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.tag.ok { background: #e8f7ee; color: var(--success); }
.tag.warn { background: #fdf3e3; color: var(--warning); }
.tag.bad { background: #fdecec; color: var(--danger); }
.tag.danger { background: #fdecec; color: var(--danger); }
.tag.blue { background: var(--primary-light); color: var(--primary); }
/* 技能选择芯片 */
.sk-chip {
  display: inline-block; padding: 4px 12px; border-radius: 14px; font-size: 12px; cursor: pointer;
  border: 1px solid var(--border); color: var(--text-light); background: #fff; user-select: none;
}
.sk-chip:hover { border-color: var(--primary); color: var(--primary); }
.sk-chip.on { background: var(--primary-light); border-color: var(--primary); color: var(--primary); font-weight: 600; }
/* BOM 材料标签 */
.bom-mat {
  display: inline-block; background: var(--primary-light); color: #8a3a30; font-size: 11px;
  padding: 2px 8px; border-radius: 10px; margin: 2px 4px 2px 0; white-space: nowrap;
}

/* 首页四大版块卡片 */

/* ---- PLM 相关 ---- */
.tag.gray { background: #f0ede8; color: #8a7d72; }
.ver { display: inline-block; font-size: 11px; color: var(--text-light); margin-left: 4px; }
.lv { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 20px;
  border-radius: 10px; font-size: 12px; font-weight: 600; }
.lv1 { background: var(--primary-light); color: var(--primary); }
.lv2 { background: #fdf3e3; color: var(--warning); }
.lv3, .lv4, .lv5 { background: #f0ede8; color: #8a7d72; }
.ecn-detail > div { margin-bottom: 12px; }
.ecn-detail label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 3px; }
.ecn-detail { font-size: 13px; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 18px; }
.module-card {
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px 14px;
}
.module-card.plm { border-top: 3px solid #C0271A; }
.module-card.erp { border-top: 3px solid #7A1508; }
.module-card.mes { border-top: 3px solid #d98e3a; }
.module-card.wms { border-top: 3px solid #2e9e5b; }
.module-card .m-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.module-card .m-code {
  font-family: "Arial Black", Arial, sans-serif; font-weight: 900; font-size: 21px; color: var(--text);
}
.module-card.plm .m-code { color: #C0271A; }
.module-card.erp .m-code { color: #7A1508; }
.module-card.mes .m-code { color: #b06f22; }
.module-card.wms .m-code { color: #218049; }
.module-card .m-name { font-size: 12px; color: var(--text-light); }
.module-card .m-stat { font-size: 12px; color: var(--text-light); margin-bottom: 8px; }
.module-card .m-stat b { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }
.module-card .m-desc { font-size: 12px; color: var(--text-light); line-height: 1.6; margin-bottom: 12px; min-height: 38px; }
.module-card .m-links { display: flex; flex-wrap: wrap; gap: 6px; }
.module-card .m-links a {
  font-size: 12px; color: var(--primary); background: var(--primary-light); padding: 3px 11px;
  border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.module-card .m-links a:hover { background: var(--primary); color: #fff; }

/* 仪表盘 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px;
}
.stat-card .label { color: var(--text-light); font-size: 12px; margin-bottom: 8px; }
.stat-card .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .foot { margin-top: 6px; font-size: 11px; color: var(--text-light); }
.stat-card.blue { border-top: 3px solid var(--primary); }
.stat-card.green { border-top: 3px solid var(--success); }
.stat-card.orange { border-top: 3px solid var(--warning); }
.stat-card.red { border-top: 3px solid var(--danger); }
.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .dash-cols { grid-template-columns: 1fr; } }

/* 模态框 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 30, 50, .45); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-mask.layer2 { z-index: 150; }   /* 第二层弹窗（如工商检索叠加在编辑弹窗之上） */
.modal {
  background: #fff; border-radius: 10px; width: 640px; max-width: 96vw; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 20, 50, .3);
}
.modal.wide { width: 960px; }
.modal .m-head {
  padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; font-size: 15px; font-weight: 700;
}
.modal .m-head .close { cursor: pointer; color: var(--text-light); font-size: 18px; }
.modal .m-body { padding: 18px 20px; overflow-y: auto; }
.modal .m-foot {
  padding: 12px 20px; border-top: 1px solid var(--border); display: flex;
  justify-content: flex-end; gap: 10px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 18px; }
.form-grid .f-full { grid-column: 1 / -1; }
.form-item label { display: block; margin-bottom: 5px; color: var(--text-light); font-size: 12px; }
.form-item input.ipt, .form-item select.ipt { width: 100%; }
.form-error { color: var(--danger); margin-top: 10px; font-size: 12px; min-height: 15px; }

/* 单据录入 */
.doc-head-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; margin-bottom: 14px; }
@media (max-width: 1000px) { .doc-head-fields { grid-template-columns: repeat(2, 1fr); } }
.doc-total-bar {
  display: flex; justify-content: flex-end; align-items: center; gap: 20px; padding: 12px 4px;
  font-size: 14px;
}
.doc-total-bar b { font-size: 18px; color: var(--danger); font-variant-numeric: tabular-nums; }
table.tbl input.ipt, table.tbl select.ipt { width: 100%; padding: 5px 6px; }
table.tbl td .cell-ctrl { min-width: 90px; }
table.doc-edit td { padding: 4px 6px; }
/* 报价单数量/单价数字输入框：去掉上下箭头，避免遮挡点击；兼容中文输入法输入 */
.i-qty, .i-price, .i-tax {
  -moz-appearance: textfield;
}
.i-qty::-webkit-outer-spin-button,
.i-qty::-webkit-inner-spin-button,
.i-price::-webkit-outer-spin-button,
.i-price::-webkit-inner-spin-button,
.i-tax::-webkit-outer-spin-button,
.i-tax::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.i-qty, .i-price, .i-tax { padding-right: 8px; }
.table-note { color: var(--text-light); font-size: 12px; margin: 8px 0; }
.muted { color: var(--text-light); font-size: 12px; }
.ipt.err { border-color: var(--danger); background: #fff6f5; }

/* 报价单状态流程条 */
.qt-flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.qt-step { padding: 3px 12px; border-radius: 12px; font-size: 12px; background: #f3ece9; color: var(--text-light); }
.qt-step.done { background: #e8f7ee; color: var(--success); }
.qt-step.cur { background: var(--primary); color: #fff; font-weight: 600; }
.qt-step.bad { background: #fdecec; color: var(--danger); }
.qt-arrow { color: var(--text-light); font-size: 12px; }

/* 简易条形图 */
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar-row .bl { width: 84px; color: var(--text-light); font-size: 12px; text-align: right; flex-shrink: 0; }
.bar-row .btrack { flex: 1; background: #F1E3DB; height: 16px; border-radius: 3px; overflow: hidden; }
.bar-row .bfill { height: 100%; background: linear-gradient(90deg, #7A1508, #C0271A); border-radius: 3px; }
.bar-row .bv { width: 110px; font-size: 12px; font-variant-numeric: tabular-nums; }

/* 工单进度条 */
.prog { display: inline-block; width: 100%; min-width: 80px; background: #F1E3DB; height: 12px; border-radius: 3px; overflow: hidden; vertical-align: middle; }
.prog .prog-fill { height: 100%; background: linear-gradient(90deg, #7A1508, #C0271A); border-radius: 3px; }
.tag.warn { background: #FBEEDC; color: #9A5B00; }

.toast {
  position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: #4a2a22; color: #fff; padding: 10px 22px; border-radius: 6px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: fadein .2s;
}
.toast.err { background: var(--danger); }
@keyframes fadein { from { opacity: 0; top: 50px; } to { opacity: 1; top: 66px; } }
.section-h { font-size: 14px; font-weight: 700; margin: 4px 0 12px; padding-left: 8px; border-left: 3px solid var(--primary); }

/* ============ 系统管理 ============ */
.two-col { display: grid; grid-template-columns: 1fr 1.6fr; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.perm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 10px; margin-top: 6px; }
.perm-item { display: flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.perm-item:hover { background: var(--bg-soft, #faf5ef); }
.perm-item input { accent-color: var(--primary); }
.active-row td { background: rgba(192, 39, 26, 0.06); }

/* ============ CRM 版块 ============ */
.module-card.crm { border-top: 3px solid #B8862F; }
.module-card.crm .m-code { color: #96702a; }

/* ============ 首页图表 ============ */
.chart-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.chart-grid .span-2 { grid-column: span 2; }
@media (max-width: 1100px) { .chart-grid { grid-template-columns: 1fr; } .chart-grid .span-2 { grid-column: span 1; } }
.chart-card { padding: 14px 16px; }
.chart-card .section-h .desc { font-weight: 400; font-size: 11px; color: var(--text-light); margin-left: 6px; }
.chart-empty { padding: 40px 0; text-align: center; color: var(--text-light); font-size: 12px; }
.pie-wrap { display: flex; align-items: center; gap: 14px; padding: 4px 0; }
.pie-wrap svg { flex-shrink: 0; }
.lg-list { flex: 1; min-width: 0; }
.lg-row { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 0; }
.lg-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.lg-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.lg-val { color: var(--text-light); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.bar-legend { display: flex; gap: 14px; margin-bottom: 4px; padding-left: 6px; }
.hb-list { padding: 6px 0; display: flex; flex-direction: column; gap: 8px; }
.hb-row { display: grid; grid-template-columns: 110px 1fr 64px; align-items: center; gap: 8px; font-size: 12px; }
.hb-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); text-align: right; }
.hb-track { background: #f3ebe4; border-radius: 5px; height: 14px; overflow: hidden; }
.hb-fill { height: 100%; border-radius: 5px; min-width: 2px; transition: width .5s ease; }
.hb-val { color: var(--text-light); font-variant-numeric: tabular-nums; }

/* WMS 库位 */
.tabs { display: inline-flex; gap: 4px; margin-bottom: 12px; background: var(--bg-soft, #f5f0ea); padding: 3px; border-radius: 8px; }
.tab { border: none; background: transparent; padding: 6px 18px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text-light); }
.tab.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.code-chip { display: inline-block; padding: 1px 8px; border-radius: 5px; background: #f3ebe4; border: 1px dashed #d9c9b8; font-family: Consolas, monospace; font-size: 12px; color: var(--text); }
.wh-type-grid { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.wh-type-card { flex: 1; min-width: 150px; padding: 10px 14px; border: 1px solid var(--line, #e6ddd2); border-radius: 8px; background: #fff; }
.wh-type-card b { display: block; font-size: 13px; margin-bottom: 2px; }
.wh-type-card span { font-size: 11px; color: var(--text-light); }

/* 消息中心 */
.bell-btn { position: relative; }
.bell-ic { font-size: 16px; line-height: 1; }
.msg-badge { position: absolute; top: -6px; right: -8px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--danger, #C0271A); color: #fff; font-size: 10px; font-weight: 700;
  align-items: center; justify-content: center; box-shadow: 0 0 0 2px #fff; }
.msg-unread { background: #fdf3ee; }
.msg-unread td:first-child { box-shadow: inset 3px 0 0 var(--primary, #C0271A); }

/* 工单问题行高亮 */
.row-warn { background: #fff6f4 !important; }
.row-warn:hover td { background: #fff0ec !important; }
.issue-card { background: var(--card, #fff); }
