:root {
  --bg: #f5f6fa;
  --side-bg: #1f2937;
  --side-fg: #cbd5e1;
  --side-active: #2563eb;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --tag-hw: #3b82f6;
  --tag-sw: #8b5cf6;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

/* ========== Login ========== */
.login-page { display:flex; align-items:center; justify-content:center; min-height: 100vh;
  background: linear-gradient(135deg,#2563eb 0%,#1e40af 100%); }
.login-card { background: #fff; padding: 36px 32px; border-radius: 10px; width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15); text-align:center; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .subtitle { color: var(--muted); margin: 0 0 24px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 15px; margin-bottom: 12px; }
.login-card button { width:100%; padding:10px; background: var(--primary); color:#fff;
  border: none; border-radius: 6px; font-size: 15px; cursor:pointer; }
.login-card button:hover { background: var(--primary-hover); }
.login-card .err { color: var(--danger); min-height: 20px; margin-top: 8px; font-size: 13px; }
.login-card .hint { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ========== App Layout ========== */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 220px; background: var(--side-bg); color: var(--side-fg);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar .logo { padding: 18px 20px; font-size: 18px; font-weight: 600; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar nav a {
  display: block; padding: 10px 20px; color: var(--side-fg);
  cursor: pointer; text-decoration: none; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar nav a.active { background: rgba(37,99,235,.15); color: #fff; border-left-color: var(--side-active); }
.side-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.btn-link { background: none; border: none; color: var(--side-fg); cursor: pointer; padding: 0; font-size: 13px; }
.btn-link:hover { color: #fff; }

.main { flex: 1; overflow-y: auto; padding: 24px 32px; }
.main .loading { color: var(--muted); padding: 40px; text-align: center; }

/* ========== Common ========== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { margin: 0; font-size: 20px; }
.page-header .actions { display: flex; gap: 8px; }

.card { background: var(--card); border-radius: 8px; box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 16px; font-size: 16px; }

button, .btn {
  padding: 6px 14px; border: 1px solid var(--border); background: #fff;
  border-radius: 5px; cursor: pointer; font-size: 13px; color: var(--text);
  transition: all .15s;
}
button:hover, .btn:hover { background: #f9fafb; }
button.primary, .btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover, .btn.primary:hover { background: var(--primary-hover); }
button.danger, .btn.danger { color: var(--danger); border-color: #fecaca; }
button.danger:hover, .btn.danger:hover { background: #fef2f2; }
button.sm { padding: 3px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }

.form-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table th { background: #f9fafb; font-weight: 600; color: #374151; }
table tbody tr:hover { background: #fafbff; }
table tbody tr.revoked td { color: #9ca3af; text-decoration: line-through; text-decoration-color: #d1d5db; }
table tbody tr.revoked td .tag { text-decoration: none; }
table td .row-actions { display: flex; gap: 6px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px;
  background: #e5e7eb; color: #374151; }
.tag.hw { background: #dbeafe; color: var(--tag-hw); }
.tag.sw { background: #ede9fe; color: var(--tag-sw); }
.tag.success { background: #d1fae5; color: #065f46; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.danger { background: #fee2e2; color: #991b1b; }
.tag.info { background: #dbeafe; color: #1e40af; }
.tag.muted { background: #f3f4f6; color: #6b7280; }

.stock-ok { color: var(--success); font-weight: 600; }
.stock-warn { color: var(--warn); font-weight: 600; }
.stock-none { color: var(--danger); font-weight: 600; }

/* Dashboard cards */
.dash-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 10px; }
.dash-card { background: var(--card); padding: 20px; border-radius: 8px; box-shadow: var(--shadow); }
.dash-card .label { color: var(--muted); font-size: 13px; }
.dash-card .value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.dash-card.red .value { color: var(--danger); }
.dash-grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 16px; }
.dash-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.chart-tabs { display: flex; gap: 4px; }
.chart-tabs button {
  padding: 4px 14px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--muted); font-size: 12px; cursor: pointer;
}
.chart-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal { background: #fff; border-radius: 8px; box-shadow: 0 20px 50px rgba(0,0,0,.2);
  min-width: 480px; max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { min-width: 780px; }
.modal-head { padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1500; display: flex; flex-direction: column; gap: 8px; }
.toast-item { padding: 10px 18px; border-radius: 6px; color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.15);
  animation: slideUp .25s ease; }
.toast-item.success { background: var(--success); }
.toast-item.error { background: var(--danger); }
.toast-item.info { background: var(--primary); }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* BOM Editor */
.bom-editor table { margin-bottom: 10px; }
.bom-editor td input, .bom-editor td select { width: 100%; }
.bom-editor .add-row { color: var(--primary); cursor: pointer; font-size: 13px; }

/* Shipment steps */
.ship-step { margin-bottom: 18px; }
.ship-step .step-title { font-weight: 600; margin-bottom: 10px; color: #374151; }
.ship-bom-table input[type=number] { width: 80px; }

/* Searchable combobox */
.combo { position: relative; max-width: 520px; }
.combo input { width: 100%; padding-right: 30px; }
.combo-arrow {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 4px 8px; font-size: 12px;
}
.combo-arrow:hover { color: var(--text); background: transparent; }
.combo-list {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 5px;
  max-height: 260px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.08);
  z-index: 50;
}
.combo-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  display: flex; gap: 10px; align-items: center;
}
.combo-item:hover { background: #f3f4f6; }
.combo-item .code { color: var(--muted); font-family: monospace; font-size: 12px; min-width: 110px; }
.combo-item .name { color: var(--text); }
.combo-item.temp { color: var(--primary); border-top: 1px dashed var(--border); }
.combo-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

/* Detail page */
.detail-meta { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-bottom: 16px; }
.detail-meta .item { background: #f9fafb; padding: 10px 14px; border-radius: 6px; }
.detail-meta .item .lbl { font-size: 12px; color: var(--muted); }
.detail-meta .item .val { font-weight: 600; margin-top: 2px; }

.search-box { display: flex; gap: 8px; margin-bottom: 12px; }
.search-box input { flex: 1; }

.flex { display: flex; gap: 8px; align-items: center; }
.flex-end { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }

/* Project detail shipments subtable */
.sub-table { background: #fafbff; padding: 12px; border-radius: 6px; margin-top: 8px; }
.sub-table th { background: transparent; font-size: 12px; color: var(--muted); }

/* Manual page */
.manual-steps { display: flex; flex-direction: column; gap: 12px; }
.step { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.step-body { line-height: 1.6; font-size: 13px; }
details { margin-bottom: 8px; }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: 6px 0; }
details p { margin: 4px 0 8px 16px; font-size: 13px; color: #555; line-height: 1.6; }

/* Activity */
.log-type { font-weight: 600; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.log-type.入库 { background: #dbeafe; color: #1e40af; }
.log-type.出货 { background: #d1fae5; color: #065f46; }
.log-type.签收 { background: #e0e7ff; color: #3730a3; }
.log-type.产品 { background: #f3e8ff; color: #6b21a8; }
.log-type.项目 { background: #fef3c7; color: #92400e; }
.log-type.PDF { background: #fce7f3; color: #9d174d; }

.sign-photo-thumb { max-width: 120px; max-height: 90px; border-radius: 4px; cursor: pointer; border: 1px solid var(--border); }

/* Responsive */
@media (max-width: 960px) {
  .sidebar { width: 180px; }
  .dash-grid { grid-template-columns: repeat(3,1fr); }
  .dash-grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-meta { grid-template-columns: 1fr; }
}
