:root {
  --bg: #0b1220;
  --bg-2: #101a2e;
  --card: #151f35;
  --card-2: #1b2740;
  --border: #253355;
  --text: #e8edf7;
  --text-2: #8b98b8;
  --accent: #3d7eff;
  --accent-2: #00d4ff;
  --warn: #ff9f43;
  --danger: #ff5b5b;
  --success: #2ecc71;
  --gold: #f5b942;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.app { display: flex; min-height: 100vh; }

/* ── 侧边栏 ── */
.sidebar {
  width: 250px;
  background: linear-gradient(180deg, #0d1830 0%, #0a1222 100%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
}
.logo { padding: 26px 22px 20px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.logo-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; box-shadow: 0 4px 16px rgba(61,126,255,.4);
}
.logo-text h1 { font-size: 15px; font-weight: 600; line-height: 1.35; }
.logo-text p { font-size: 11px; color: var(--text-2); margin-top: 2px; letter-spacing: .5px; }
.nav { flex: 1; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 10px;
  color: var(--text-2); text-decoration: none; font-size: 14px;
  transition: all .2s; border: 1px solid transparent;
}
.nav-item:hover { color: var(--text); background: rgba(61,126,255,.08); }
.nav-item.active {
  color: #fff; background: linear-gradient(90deg, rgba(61,126,255,.25), rgba(0,212,255,.12));
  border-color: rgba(61,126,255,.4);
}
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px 22px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 12px; line-height: 1.8; }

/* ── 主区 ── */
.main { flex: 1; min-width: 0; margin-left: 250px; padding: 28px 34px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .3s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; font-weight: 600; background: linear-gradient(90deg, #fff, #9db8ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.page-head .sub { color: var(--text-2); font-size: 13px; margin-bottom: 3px; }
.head-actions { margin-left: auto; }

/* ── 卡片 ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; margin-bottom: 16px; color: var(--text); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { text-align: center; padding: 24px 16px; }
.stat-num { font-size: 36px; font-weight: 700; background: linear-gradient(135deg, var(--accent-2), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.warn .stat-num { background: linear-gradient(135deg, var(--warn), var(--danger)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-label { color: var(--text-2); margin-top: 6px; font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-card { overflow: hidden; }
.chart { height: 300px; width: 100%; }

/* ── 表格 ── */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; padding: 11px 12px; font-size: 12px; color: var(--text-2);
  border-bottom: 1px solid var(--border); font-weight: 500; white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid rgba(37,51,85,.5); font-size: 13.5px; vertical-align: middle; }
.table tr:hover td { background: rgba(61,126,255,.05); }

/* 星级 */
.stars { color: var(--gold); font-size: 14px; letter-spacing: 1px; white-space: nowrap; }
.stars.red { color: var(--danger); font-weight: 700; }
.stars.low { color: var(--warn); }

/* 徽章 */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; }
.badge-ok { background: rgba(46,204,113,.15); color: var(--success); }
.badge-warn { background: rgba(255,159,67,.15); color: var(--warn); }
.badge-danger { background: rgba(255,91,91,.15); color: var(--danger); }
.badge-blue { background: rgba(61,126,255,.15); color: var(--accent-2); }

/* ── 按钮 ── */
.btn {
  padding: 9px 20px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--card-2); color: var(--text); cursor: pointer; font-size: 13.5px;
  transition: all .2s;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff; font-weight: 600;
  box-shadow: 0 4px 16px rgba(61,126,255,.35);
}
.btn.primary:hover { filter: brightness(1.15); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn.danger { background: rgba(255,91,91,.15); color: var(--danger); border-color: rgba(255,91,91,.3); }
.btn.danger:hover { background: var(--danger); color: #fff; }

/* ── 筛选区 ── */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input, .field input, .field select {
  padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 13px; outline: none;
}
.filters select:focus, .filters input:focus, .field input:focus, .field select:focus { border-color: var(--accent); }
.filters input[type="text"] { width: 220px; }

/* ── 分页 ── */
.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 14px; color: var(--text-2); font-size: 13px; }

/* ── 表单 ── */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--text-2); }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.selected-tip { color: var(--accent-2); font-size: 13px; }

/* 上传 */
.upload-row { display: flex; flex-direction: column; gap: 10px; }
.image-preview { display: flex; gap: 10px; flex-wrap: wrap; }
.image-preview img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* ── 弹窗 ── */
.modal-mask {
  position: fixed; inset: 0; background: rgba(5,10,20,.7); backdrop-filter: blur(4px);
  z-index: 300; display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  width: 640px; max-width: 92vw; max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal.wide { width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-head h3 { margin: 0; font-size: 16px; }
.close { background: none; border: none; color: var(--text-2); font-size: 22px; cursor: pointer; }
.close:hover { color: #fff; }
.modal-body { padding: 22px 24px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }
.star-preview { margin-top: 14px; padding: 12px 16px; border-radius: 10px; background: var(--bg-2); color: var(--gold); font-size: 15px; }

/* 详情 */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.detail-item { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px dashed rgba(37,51,85,.6); }
.detail-item .k { color: var(--text-2); min-width: 90px; }
.detail-item .v { color: var(--text); }
.detail-section { margin-top: 18px; }
.detail-section h4 { color: var(--accent-2); font-size: 14px; margin-bottom: 10px; }
.detail-img { width: 100px; height: 100px; object-fit: cover; border-radius: 8px; margin-right: 8px; border: 1px solid var(--border); }

/* 导入 */
.center-card { text-align: center; }
.center-card h3 { margin-bottom: 8px; }
.center-card p { color: var(--text-2); font-size: 13px; margin-bottom: 16px; }
.center-card .btn { margin-top: 6px; }
.import-result { margin-top: 16px; text-align: left; font-size: 13px; line-height: 1.9; }
.import-result .ok { color: var(--success); }
.import-result .err { color: var(--danger); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}

/* ═══════════ 移动端响应式 (≤768px) ═══════════ */
.mobile-nav { display: none; }

@media (max-width: 768px) {
  body { font-size: 13px; }

  /* 兜底：禁止页面级横向滚动（表格内部滚动保留在 .card 内） */
  html, body { max-width: 100%; overflow-x: hidden; }

  /* 侧边栏隐藏，底部导航显示 */
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 14px 12px 76px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
    /* 纯色背景，不用 backdrop-filter——部分安卓WebView(微信X5)会让fixed失效 */
    background: #0d1830;
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  .mnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; color: var(--text-2); text-decoration: none; font-size: 11px;
    border-radius: 8px;
  }
  .mnav-item .mnav-icon { font-size: 18px; line-height: 1; }
  .mnav-item.active { color: #fff; background: rgba(61,126,255,.2); }
  .mnav-item.active .mnav-icon { color: var(--accent-2); }

  /* 页头 */
  .page-head { margin-bottom: 14px; gap: 6px; }
  .page-head h2 { font-size: 18px; }
  .page-head .sub { font-size: 12px; width: 100%; }
  .head-actions { margin-left: 0; width: 100%; }
  .head-actions .btn { width: 100%; padding: 11px; }

  /* 统计卡片 2列 */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 16px 8px; }
  .stat-num { font-size: 28px; }
  .stat-label { font-size: 11.5px; }

  /* 图表 */
  .grid-2 { grid-template-columns: 1fr; gap: 12px; }
  .chart { height: 230px; }
  .card { padding: 14px 12px; margin-bottom: 12px; border-radius: 12px; }
  .card h3 { font-size: 14px; margin-bottom: 10px; }

  /* 表格：关键列保留，次要列隐藏；超宽横向滚动 */
  .card { overflow-x: auto; }
  .table th, .table td { padding: 9px 8px; font-size: 12px; white-space: nowrap; }
  /* 台账表：隐藏 批次(4) 修复次数(6) */
  #bearing-tbody td:nth-child(4),
  #view-bearings thead th:nth-child(4),
  #bearing-tbody td:nth-child(6),
  #view-bearings thead th:nth-child(6) { display: none; }
  /* 装配履历表：隐藏 名称(3) 部门(4) 运行状态(7) */
  #assembly-tbody td:nth-child(3), #assembly-tbody td:nth-child(4), #assembly-tbody td:nth-child(7),
  #view-assembly thead th:nth-child(3), #view-assembly thead th:nth-child(4), #view-assembly thead th:nth-child(7) { display: none; }
  /* 报废表：隐藏 详细说明(6) */
  #scrap-tbody td:nth-child(6),
  #view-scraps thead th:nth-child(6) { display: none; }
  /* 看板最近装配：隐藏 名称(3) 部门(4) */
  #recent-assembly td:nth-child(3), #recent-assembly td:nth-child(4),
  #view-dashboard thead th:nth-child(3), #view-dashboard thead th:nth-child(4) { display: none; }

  /* 筛选区全宽 */
  .filters { gap: 8px; }
  .filters select { flex: 1; min-width: calc(50% - 8px); }
  .filters input[type="text"] { width: 100%; flex-basis: 100%; }
  .filters .btn { flex: 1; }

  /* 分页 */
  .pager { justify-content: space-between; }
  .pager .btn { flex: 1; }

  /* 表单单列 */
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; padding: 11px; }

  /* 表单控件防溢出 */
  .field input, .field select, .filters select, .filters input, input[type="file"] {
    max-width: 100%;
  }

  /* 弹窗：居中显示，不与底部导航重叠（底部弹出会和固定导航抢地盘） */
  .modal { width: 100%; max-width: 100%; max-height: 84vh; border-radius: 14px; }
  .modal-mask { align-items: center; padding: 0 8px; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; padding: 11px; }

  /* 详情单列 */
  .detail-grid { grid-template-columns: 1fr; }
  .detail-item .k { min-width: 76px; }

  /* 导入按钮 */
  .center-card .btn { width: 100%; padding: 11px; }
  #import-file { width: 100%; margin-bottom: 10px; }

  /* 上传预览 */
  .image-preview img { width: 72px; height: 72px; }

  /* 表格操作按钮 */
  .table .btn { padding: 5px 9px; font-size: 11.5px; }
}
