/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: #f0f2f5;
  color: #333;
  line-height: 1.6;
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
table { border-collapse: collapse; width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ========== Layout ========== */
#app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}
.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-icon { font-size: 32px; }
.logo-text h1 { font-size: 16px; font-weight: 600; }
.logo-text span { font-size: 12px; color: rgba(255,255,255,0.5); }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  font-size: 14px;
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.12); color: #fff; border-left-color: #409EFF; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.role-selector { margin-bottom: 8px; }
.role-selector label { font-size: 12px; color: rgba(255,255,255,0.5); display: block; margin-bottom: 4px; }
.role-selector select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 13px;
  outline: none;
}
.role-selector select option { background: #1a1a2e; color: #fff; }
.user-info { font-size: 12px; color: rgba(255,255,255,0.4); }

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 24px 32px;
  min-height: 100vh;
}
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 22px; font-weight: 600; color: #1a1a2e; }
.page-time { font-size: 13px; color: #909399; }
.role-badge {
  background: #409EFF;
  color: #fff;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 13px;
}

/* ========== Cards ========== */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-badge {
  font-size: 12px;
  color: #909399;
  background: #f5f7fa;
  padding: 3px 10px;
  border-radius: 10px;
}
.card-body { padding: 20px; }

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: all 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.stat-card .stat-label { font-size: 13px; color: #909399; }
.stat-card .stat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

/* ========== Table ========== */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar .input { flex: 1; min-width: 200px; }
.table-container { background: #fff; border-radius: 10px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); overflow: auto; }
.data-table { font-size: 14px; }
.data-table thead { background: #f5f7fa; }
.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: #606266;
  white-space: nowrap;
  border-bottom: 2px solid #e4e7ed;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #ebeef5;
  color: #333;
}
.data-table tbody tr:hover { background: #f5f7fa; }

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 18px;
  border-radius: 6px;
  border: 1px solid #dcdfe6;
  background: #fff;
  color: #606266;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:hover { color: #409EFF; border-color: #c6e2ff; background: #ecf5ff; }
.btn-primary { background: #409EFF; color: #fff; border-color: #409EFF; }
.btn-primary:hover { background: #3a8ee6; border-color: #3a8ee6; color: #fff; }
.btn-success { background: #67C23A; color: #fff; border-color: #67C23A; }
.btn-success:hover { background: #5daf34; border-color: #5daf34; }
.btn-warning { background: #E6A23C; color: #fff; border-color: #E6A23C; }
.btn-warning:hover { background: #cf9236; }
.btn-danger { background: #F56C6C; color: #fff; border-color: #F56C6C; }
.btn-danger:hover { background: #e04949; }
.btn-outline { background: transparent; color: #409EFF; border-color: #409EFF; }
.btn-outline:hover { background: #ecf5ff; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 4px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 3px; }
.btn-default { background: #f5f7fa; border-color: #dcdfe6; color: #606266; }

/* ========== Form ========== */
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-group { margin-bottom: 16px; flex: 1; min-width: 200px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; color: #606266; }
.required { color: #F56C6C; }
.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  font-size: 14px;
  color: #333;
  transition: border-color 0.2s;
  outline: none;
}
.input:focus { border-color: #409EFF; box-shadow: 0 0 0 2px rgba(64,158,255,0.15); }
.input-sm { padding: 6px 8px; font-size: 13px; }
textarea.input { resize: vertical; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid #ebeef5; margin-top: 8px; }
.items-table-wrapper { overflow-x: auto; }
.items-table-wrapper table { min-width: 1100px; }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: 500px;
  max-width: 90vw;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-lg { width: 900px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid #ebeef5;
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close {
  background: none; border: none;
  font-size: 20px; color: #909399; cursor: pointer;
  padding: 4px 8px; border-radius: 4px;
}
.modal-close:hover { background: #f5f7fa; color: #333; }
.modal-body { padding: 24px; }

/* ========== Timeline ========== */
.timeline { position: relative; padding-left: 30px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 10px; top: 0; bottom: 0;
  width: 2px;
  background: #e4e7ed;
}
.timeline-item {
  position: relative;
  padding-bottom: 24px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  left: -24px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #409EFF;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px #409EFF;
}
.timeline-dot.start { background: #67C23A; box-shadow: 0 0 0 2px #67C23A; }
.timeline-dot.end { background: #E6A23C; box-shadow: 0 0 0 2px #E6A23C; }
.timeline-content { }
.timeline-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.timeline-meta { font-size: 12px; color: #909399; }
.timeline-notes { font-size: 13px; color: #606266; margin-top: 4px; padding: 6px 10px; background: #f5f7fa; border-radius: 4px; }

/* ========== Detail Panel ========== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-item { }
.detail-item label { font-size: 12px; color: #909399; display: block; margin-bottom: 2px; }
.detail-item .detail-value { font-size: 14px; font-weight: 500; }
.detail-grid.edit-mode .detail-item { display: flex; flex-direction: column; gap: 4px; }
.detail-grid.edit-mode .detail-item label { margin-bottom: 0; }
.detail-section { margin-top: 24px; }
.detail-section h4 { font-size: 15px; font-weight: 600; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid #ebeef5; }
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ========== Flow Diagram ========== */
.flow-diagram { padding: 24px 0; }
.flow-steps { display: flex; flex-wrap: wrap; gap: 0; align-items: flex-start; }
.flow-step {
  flex: 1;
  min-width: 140px;
  text-align: center;
  position: relative;
}
.flow-step:not(:last-child)::after {
  content: '→';
  position: absolute;
  right: -8px;
  top: 30px;
  font-size: 24px;
  color: #c0c4cc;
  z-index: 1;
}
.flow-step-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #e4e7ed;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 8px;
  transition: all 0.3s;
}
.flow-step.active .flow-step-icon {
  border-color: #409EFF;
  box-shadow: 0 0 0 6px rgba(64,158,255,0.12);
}
.flow-step.done .flow-step-icon {
  border-color: #67C23A;
  background: #f0f9eb;
}
.flow-step-title { font-size: 13px; font-weight: 600; color: #333; }
.flow-step-dept { font-size: 11px; color: #909399; }

/* ========== Email Preview ========== */
.email-preview {
  background: #fdf6ec;
  border: 1px solid #faecd8;
  border-radius: 8px;
  padding: 16px;
  margin-top: 12px;
  font-size: 13px;
}
.email-preview h5 { color: #E6A23C; margin-bottom: 8px; }
.email-preview pre { white-space: pre-wrap; font-family: inherit; color: #606266; }

/* ========== Toast ========== */
.toast-container {
  position: fixed; top: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}
.toast.success { background: #67C23A; }
.toast.error { background: #F56C6C; }
.toast.info { background: #409EFF; }
.toast.warning { background: #E6A23C; }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* ========== Pagination ========== */
.pagination { display: flex; gap: 8px; justify-content: center; padding: 20px 0; }
.pagination button {
  padding: 6px 14px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:hover { color: #409EFF; border-color: #409EFF; }
.pagination button.active { background: #409EFF; color: #fff; border-color: #409EFF; }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== Loading ========== */
.loading { text-align: center; padding: 40px; color: #909399; font-size: 14px; }

/* ========== Inspection Select ========== */
.item-inspection-select.pass { color: #67C23A; border-color: #67C23A; font-weight: 600; }
.item-inspection-select.fail { color: #F56C6C; border-color: #F56C6C; font-weight: 600; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; padding: 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .flow-steps { flex-direction: column; }
  .flow-step:not(:last-child)::after { content: '↓'; right: 50%; top: auto; bottom: -12px; transform: translateX(50%); }
}

/* ========== Supplier Search Dropdown ========== */
.supplier-search-wrapper {
  position: relative;
}
.supplier-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #dcdfe6;
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  z-index: 500;
  max-height: 240px;
  overflow-y: auto;
}
.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #333;
  transition: background 0.15s;
  border-bottom: 1px solid #f5f5f5;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: #ecf5ff; color: #409EFF; }

/* ========== Supplier Add Bar ========== */
.supplier-add-bar {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ========== Batch Import ========== */
#batchImportText {
  width: 100%;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  min-height: 200px;
}

/* ========== Detail-only mode (new window) ========== */
body.detail-mode .sidebar { display: none; }
body.detail-mode .main-content { margin-left: 0; padding: 24px 40px; }
body.detail-mode .view { display: none; }
body.detail-mode #view-detail { display: block; }

/* ========== Material Toggle Buttons ========== */
.btn-toggle-active {
  border-color: #409EFF !important;
  color: #409EFF !important;
  background: #ecf5ff !important;
}
.btn-toggle-inactive {
  border-color: #dcdfe6 !important;
  color: #606266 !important;
  background: #fff !important;
}

/* Print styles */
@media print {
  .sidebar, .toast-container, .btn, .modal-overlay { display: none !important; }
  .main-content { margin-left: 0; }
}
