:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8ef;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .05);
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: fixed;
  inset: 0 auto 0 0;
}

.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; font-size: 16px; font-weight: 600;
  padding: 6px 8px 18px;
}
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text);
  font-size: 14px;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(37,99,235,.9); color: #fff; }
.nav .nav-section { font-size: 12px; color: #64748b; padding: 14px 12px 6px; }

.sidebar-footer { margin-top: auto; padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.1); font-size: 12px; }
.sidebar-footer .who { color: #fff; font-weight: 600; }
.sidebar-footer .role { color: #94a3b8; }

.main { flex: 1; margin-left: 220px; padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ---------- 卡片与统计 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head h3 { font-size: 15px; }
.card-body { padding: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { color: var(--text-muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.5px; }
.stat .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat.accent-blue .value { color: var(--primary); }
.stat.accent-green .value { color: var(--success); }
.stat.accent-amber .value { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- 按钮与表单 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px;
  font-family: inherit; transition: all .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-muted); }
.field label .req { color: var(--danger); }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 72px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.checkbox-row input[type="radio"] { accent-color: var(--primary); }
.checkbox-row input[type="checkbox"] { accent-color: var(--primary); }
.checkbox-row label.checkbox-row { cursor: pointer; }

/* ---------- IBM 模块 ---------- */
.ibm-input-row td { padding: 6px 8px; }
.ibm-input-row input { padding: 6px 8px; font-size: 13px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0 0 14px; }
legend { padding: 0 6px; color: var(--text-muted); font-size: 13px; }
.qr-wrap { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

/* QR 控件：等宽可选中链接框 */
input[readonly] { background: var(--surface-2); color: var(--text); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; white-space: nowrap; font-size: 13px; }
tbody tr:hover { background: #fafbfd; }
td .muted { color: var(--text-muted); }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-open { background: var(--warn-soft); color: var(--warn); }
.badge-closed { background: var(--success-soft); color: var(--success); }
.badge-parts { background: var(--primary-soft); color: var(--primary); }
.badge-none { background: #f1f5f9; color: var(--text-muted); }

.pagination { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; gap: 10px; }
.empty { padding: 48px 18px; text-align: center; color: var(--text-muted); }

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 720px;
  box-shadow: 0 20px 40px rgba(16,24,40,.2);
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 提示 ---------- */
#toast { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 8px; padding: 10px 16px; box-shadow: var(--shadow); min-width: 220px; font-size: 13.5px;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* ---------- 登录页 ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #eef2ff, #f8fafc); }
.login-card { width: 380px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 32px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }

/* ---------- 图表 ---------- */
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-muted); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-item .bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar-track { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }

/* ---------- 报告（可打印） ---------- */
.report-toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 16px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; flex-wrap: wrap;
}
.report-paper {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 40px 44px; box-shadow: var(--shadow); max-width: 900px; margin: 0 auto;
}
.report-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--primary); padding-bottom: 14px; margin-bottom: 20px; }
.report-header .company { font-size: 18px; font-weight: 700; }
.report-header .meta { font-size: 12.5px; color: var(--text-muted); text-align: right; }
.report-title { text-align: center; font-size: 20px; letter-spacing: 2px; margin: 10px 0 20px; }
.report-section { margin-bottom: 22px; }
.report-section h4 { font-size: 14px; margin-bottom: 10px; padding-left: 8px; border-left: 3px solid var(--primary); }
.kv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 24px; }
.kv { display: flex; gap: 10px; font-size: 13.5px; }
.kv .k { color: var(--text-muted); min-width: 92px; }
.kv .v { flex: 1; font-weight: 500; word-break: break-all; }
.report-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--surface-2); white-space: pre-wrap; font-size: 13.5px; min-height: 60px; }
.sign-row { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; font-size: 13.5px; }
.sign-line { border-bottom: 1px solid var(--text); height: 46px; margin-bottom: 6px; }
.report-foot { margin-top: 30px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; }

@media print {
  body { background: #fff; }
  .sidebar, .report-toolbar, #toast, .page-head .actions { display: none !important; }
  .main { margin: 0; padding: 0; }
  .report-paper { border: none; box-shadow: none; padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; }
  @page { size: A4; margin: 16mm; }
}
