:root {
  --brand: #1657d6;
  --brand-dark: #0f3fa6;
  --brand-soft: #e8f0ff;
  --ink: #17202e;
  --ink-2: #46536a;
  --ink-3: #74829a;
  --line: #e3e8f0;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ok: #12855b;
  --ok-soft: #e6f6ef;
  --warn: #b4711a;
  --warn-soft: #fdf3e3;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --info-soft: #eaf1ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 64, .06), 0 8px 24px rgba(16, 32, 64, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Source Han Sans SC", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr;
  background: linear-gradient(135deg, #0b2a63 0%, #1657d6 55%, #2a7de1 100%);
}
.login-brand { color: #fff; padding: 64px 72px; display: flex; flex-direction: column; justify-content: center; }
.login-brand .logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 40px; }
.login-brand .logo-mark {
  width: 46px; height: 46px; border-radius: 12px; background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.35); display: grid; place-items: center; font-weight: 700; letter-spacing: 1px;
}
.login-brand h1 { font-size: 30px; line-height: 1.35; margin-bottom: 16px; }
.login-brand p { color: rgba(255,255,255,.82); line-height: 1.9; max-width: 520px; margin: 0 0 10px; }
.login-brand .facts { display: flex; gap: 36px; margin-top: 44px; }
.login-brand .facts b { display: block; font-size: 24px; }
.login-brand .facts span { color: rgba(255,255,255,.7); font-size: 13px; }
.login-panel { background: #fff; display: grid; place-items: center; padding: 40px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 22px; margin-bottom: 6px; }
.login-card .sub { color: var(--ink-3); margin-bottom: 28px; }
.login-card .tip { margin-top: 18px; font-size: 12px; color: var(--ink-3); line-height: 1.9; background: var(--bg); padding: 12px 14px; border-radius: 8px; }
.login-card .tip b { color: var(--ink-2); }

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: #0e1c33; color: #c9d4e6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 18px 20px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.07); }
.sidebar .brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.sidebar .brand div small { display: block; font-size: 11px; color: #7d8ba3; margin-top: 2px; }
.nav { flex: 1; overflow-y: auto; padding: 10px 0 24px; }
.nav .group { padding: 14px 20px 6px; font-size: 11px; letter-spacing: .08em; color: #61708a; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 20px; color: #c2cee1; font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.055); color: #fff; }
.nav a.active { background: rgba(22,87,214,.22); color: #fff; border-left-color: #4c86f5; font-weight: 600; }
.nav a .ico { width: 16px; text-align: center; opacity: .8; }
.sidebar .foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; color: #7d8ba3; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 58px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { color: var(--ink-3); font-size: 13px; }
.topbar .crumb b { color: var(--ink); font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 16px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-chip .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 600; }
.user-chip small { color: var(--ink-3); }
.content { padding: 20px 24px 40px; }

/* ---------- 通用组件 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; gap: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 19px; }
.page-head .desc { color: var(--ink-3); font-size: 13px; margin-top: 6px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-head h3 { font-size: 15px; }
.panel-body { padding: 16px 18px; }
.panel-body.tight { padding: 0; }

.btn {
  height: 34px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--line); background: #fff;
  color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: #c3cfe3; color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f0c6c1; background: var(--danger-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: 9px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--ink-3); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.5px; }
.kpi .hint { font-size: 12px; color: var(--ink-3); }
.kpi.accent { border-left: 3px solid var(--brand); }
.kpi.warn { border-left: 3px solid #e8a33d; }
.kpi.danger { border-left: 3px solid #d9534f; }
.kpi.ok { border-left: 3px solid #199e6f; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; padding: 10px 12px; background: #f7f9fc; color: var(--ink-2); font-weight: 600;
  border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0;
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
table.grid tbody tr:hover { background: #f8fafd; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.mono, .mono { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12.5px; }
.table-wrap { overflow: auto; max-height: calc(100vh - 300px); }
.muted { color: var(--ink-3); }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--info-soft); color: var(--brand); white-space: nowrap; }
.badge.gray { background: #eef1f6; color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.solid { background: var(--brand); color: #fff; }

.grade { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; }
.grade.S { background: #d4372f; }
.grade.A { background: #e08a1e; }
.grade.B { background: #2b74d6; }
.grade.C { background: #8695ac; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  height: 34px; padding: 0 10px; border: 1px solid #d6dded; border-radius: 7px; background: #fff; color: var(--ink); outline: none; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; line-height: 1.7; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22,87,214,.12); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
label.field > span .req { color: var(--danger); margin-left: 2px; }
label.field input, label.field select, label.field textarea { width: 100%; }
label.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-row.three { grid-template-columns: repeat(3, 1fr); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 18px; }
.tabs button {
  background: none; border: 0; padding: 12px 14px; color: var(--ink-3); cursor: pointer; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); cursor: pointer; font-size: 12.5px; }
.pill.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(11,22,44,.45); display: grid; place-items: center; z-index: 100; padding: 24px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(10,20,40,.28); }
.modal.wide { max-width: 980px; }
.modal.narrow { max-width: 460px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { font-size: 16px; }
.modal header .x { background: none; border: 0; font-size: 20px; color: var(--ink-3); cursor: pointer; line-height: 1; }
.modal .body { padding: 18px 20px; overflow: auto; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toast-wrap { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 8px; background: #17202e; color: #fff; font-size: 13px; box-shadow: var(--shadow); max-width: 70vw; }
.toast.error { background: #b3271e; }
.toast.ok { background: #10744f; }
.toast.warn { background: #9a6112; }

/* 时间轴 */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: #e3e9f3; }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px #eef3ff; }
.tl-item.warn::before { background: #d99a2b; box-shadow: 0 0 0 3px #fdf3e3; }
.tl-item.danger::before { background: #c0392b; box-shadow: 0 0 0 3px #fdecea; }
.tl-item .tl-title { font-weight: 600; font-size: 13.5px; }
.tl-item .tl-time { font-size: 12px; color: var(--ink-3); margin: 2px 0 8px; }
.tl-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); background: #f8fafd; border-radius: 8px; padding: 10px 12px; }
.tl-fields b { color: var(--ink-3); font-weight: 400; margin-right: 4px; }

/* 详情抽屉式布局 */
.detail-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.info-list { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; font-size: 13px; }
.info-list dt { color: var(--ink-3); }
.info-list dd { margin: 0; }

/* 工位机 */
.wb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.wb-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.wb-card .top { display: flex; justify-content: space-between; align-items: flex-start; }
.wb-card .pname { font-size: 17px; font-weight: 700; }
.wb-card .proc { font-size: 13px; color: var(--brand); margin-top: 4px; }
.wb-card .meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-3); margin: 12px 0; flex-wrap: wrap; }
.wb-card .ops { display: flex; gap: 10px; }
.wb-card .ops .btn { flex: 1; height: 48px; font-size: 15px; }

.bar-row { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.bar { height: 10px; border-radius: 6px; background: #eef1f6; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.bar.over > i { background: #d9534f; }

.qr-box { background: #fff; border: 1px dashed #cdd7e8; border-radius: 10px; padding: 16px; text-align: center; }
.qr-box img { width: 160px; height: 160px; }

.stat-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #eef1f6; font-size: 13px; }
.stat-line:last-child { border-bottom: 0; }

.warn-box { background: var(--warn-soft); border: 1px solid #f3ddb6; color: #7b4d0c; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.8; margin-bottom: 14px; }
.danger-box { background: var(--danger-soft); border: 1px solid #f4cbc6; color: #8f2a1e; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.8; margin-bottom: 14px; }
.info-box { background: var(--info-soft); border: 1px solid #cfe0ff; color: #17458f; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.8; margin-bottom: 14px; }

@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 14px; }
}

/* ---------- 图表组件（charts.js） ---------- */
.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.chart-card > h4 { font-size: 13.5px; margin-bottom: 12px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.chart-card > h4 .muted { font-weight: 400; font-size: 12px; }
.chart-grid { display: grid; gap: 14px; margin-bottom: 16px; }
.chart-grid.two { grid-template-columns: 1fr 1fr; }
.chart-grid.three { grid-template-columns: repeat(3, 1fr); }
.chart-grid.donut-row { grid-template-columns: 168px 1fr; align-items: center; }
.chart-grid.wide-left { grid-template-columns: 2fr 1fr; }

.chart-bar { display: grid; grid-template-columns: 118px 1fr 78px; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.chart-bar:last-child { margin-bottom: 0; }
.chart-bar-label { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar-track { height: 12px; border-radius: 6px; background: #eef1f6; overflow: hidden; display: block; }
.chart-bar-track > i { display: block; height: 100%; border-radius: 6px; transition: width .5s ease; min-width: 2px; }
.chart-bar-value { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.chart-ratio { display: grid; grid-template-columns: 108px 1fr 62px; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.chart-ratio-track { position: relative; height: 16px; border-radius: 8px; background: #eef1f6; overflow: hidden; display: block; }
.chart-ratio-track > i { display: block; height: 100%; border-radius: 8px; transition: width .5s ease; min-width: 2px; }
.chart-ratio-track > b { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); font-size: 11px; font-weight: 600; color: var(--ink-3); }
.chart-note { font-size: 11.5px; color: var(--ink-3); margin-top: 10px; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-legend b { color: var(--ink); font-variant-numeric: tabular-nums; }

.chart-donut { display: block; }
.chart-line { display: block; width: 100%; height: auto; overflow: visible; }

.chart-mini { display: inline-block; width: 54px; height: 7px; border-radius: 4px; background: #eef1f6; overflow: hidden; vertical-align: middle; }
.chart-mini > i { display: block; height: 100%; border-radius: 4px; }

.chart-empty { padding: 30px; text-align: center; color: var(--ink-3); font-size: 12.5px; }

@media (max-width: 1100px) {
  .chart-grid.two, .chart-grid.three, .chart-grid.wide-left { grid-template-columns: 1fr; }
  .chart-grid.donut-row { grid-template-columns: 1fr; justify-items: center; }
}
