/* 定义全局CSS变量 */
:root {
  --primary-color: #2c3e50; /* 主色调 */
  --secondary-color: #3498db; /* 次要色调 */
  --accent-color: #e67e22; /* 强调色 */
  --dark-bg: #1a2330; /* 深色背景 */
  --bg-color: #f8f9fa; /* 页面背景色 */
  --icon-size: 24px; /* 图标基准尺寸 */
  --nested-indent: 25px; /* 嵌套缩进 */
  --border-radius: 8px; /* 通用圆角 */
  --box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* 通用阴影 */
}

/* 基础页面布局 */
body {
  display: flex;
  margin: 0;
  font-family: "Microsoft YaHei", sans-serif;
  background-color: var(--bg-color);
  gap: 20px;
}

/* 深色左侧导航 */
.nav-container {
  width: 320px;
  height: 100vh;
  overflow-y: auto;
  background: var(--primary-color);
  color: white;
  padding: 0 20px 20px; /* 移除顶部内边距，让搜索框背景延伸到顶部 */
  display: block !important;
  z-index: 20;
}

/* 顶部固定区域 */
.fixed-header {
  position: relative;
  top: auto;
  z-index: 20;
  background: var(--primary-color);
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* 搜索框样式 */
.search-box {
  padding: 20px 12px 12px; /* 增加顶部内边距，使背景增高到顶部 */
  margin-bottom: 15px;
  position: sticky;
  top: 0;
  background: var(--primary-color);
  z-index: 2;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* 添加底部边框分隔 */
}

/* 收起按钮样式 */
.collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  margin-top: 10px;
  cursor: pointer;
  border-radius: var(--border-radius);
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s;
  font-size: 14px;
}

.collapse-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}


/* 确保收藏目录有正确间距 */
#favoriteCategory {
  margin-top: 10px;
}

/* 导航栏搜索输入框 */
#navSearch {
  width: 100%;
  max-width: 260px;
  padding: 10px 15px;
  border: 2px solid #34495e;
  border-radius: var(--border-radius);
  font-size: 14px;
  transition: all 0.3s;
  background: #2c3e50;
  color: white;
}

#navSearch:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 8px rgba(52, 152, 219, 0.2);
}

.category-toggle {
  gap: 16px;
  display: flex;
  align-items: center;
  padding: 10px;
  margin: 4px 0;
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.05);
}

.category-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(3px);
}

.sub-category {
  margin-left: var(--nested-indent);
  border-left: 2px solid #2c3e50;
  padding-left: 12px;
  display: none; /* 添加默认隐藏 */
}

.products-container {
  display: none;
  margin-left: calc(var(--nested-indent) - 10px);
}

.product-card {
  display: flex;
  align-items: flex-start;
  padding: 12px;
  margin: 6px 0;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius);
  cursor: pointer;
  gap: 10px; /* 收藏 */
  transition: all 0.2s;
  align-items: center; /* 收藏 */
}

.product-card:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(5px);
}

.product-info {
  flex: 1;
  flex-direction: column;
}

.product-path {
  display: block;
  white-space: normal;
  font-size: 12px;
  color: #95a5a6;
  margin-top: 4px;
}

/* 右侧主内容区 */
.main-content {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr; /* 材料成本占2份，其他各占1份 */
  gap: 10px;
  box-sizing: border-box;
  align-content: start; /* 顶部对齐 */
}

.input-group {
  width: 100%;
  padding: 15px;
  box-sizing: border-box;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  min-height: 120px;
  display: flex;
  flex-direction: column;
}

/* 材料成本区域 - 更宽 */
#materialInputs {
  width: 100%;
  min-height: 200px; /* 增加最小高度以容纳更多材料 */
}

/* 制造设置和成品售价区域 - 更窄 */
.input-group:nth-child(2), /* 制造设置 */
.input-group:nth-child(3) { /* 成品售价 */
  min-height: 150px; /* 稍微减少高度 */
}

/* 收益计算和注意事项占满全宽 */
.input-group[style*="grid-column: 1/-1"] {
  grid-column: 1 / -1;
}

.input-group h3 {
  margin: 0 0 20px;
  color: var(--primary-color);
  border-bottom: 2px solid var(--secondary-color);
  padding-bottom: 10px;
}

#currentProduct {
  grid-column: 1 / -1; /* 跨所有列 */
  width: 100%; /* 使用100%宽度 */
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  margin-bottom: 0px; /* 添加底部间距 */
}

/* 确保产品信息布局 */
#currentProduct {
  grid-column: 1 / -1;
  width: 100%;
  padding: 12px 20px; /* 调整内边距 */
  box-sizing: border-box;
  display: flex;
  align-items: center;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  margin-bottom: 0px;
  height: 80px; /* 固定高度 */
  flex-shrink: 0; /* 防止被压缩 */
}

/* 确保产品图标大小固定 */
#currentProduct img {
  width: 60px; /* 固定图标大小 */
  height: 60px;
  margin-right: 20px;
  flex-shrink: 0;
}

/* 产品信息区域 */
#currentProduct > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  flex: 1;
}

#currentProduct h2 {
  font-size: 1.5rem;
  margin: 0 0 5px 0;
  line-height: 1.2;
}

#currentProduct p {
  font-size: 0.9rem;
  margin: 0;
  color: #555;
  line-height: 1.2;
}

input[type="number"] {
  padding: 8px 12px;
  border: 2px solid #e9ecef;
  border-radius: var(--border-radius);
  width: 120px;
  transition: all 0.3s;
}

input[type="number"]:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 8px rgba(52, 152, 219, 0.2);
}

#salePrice {
  width: 120px; /* 固定宽度 */
}

.highlight {
  color: var(--accent-color);
  font-weight: 600;
}

.highlight-match {
  background-color: rgba(255, 215, 0, 0.3);
  color: #ffd700;
  padding: 2px 4px;
  border-radius: 3px;
}

.notes-box {
  background: #fff9e6;
  border-left: 4px solid #ffe066;
}

.notes-box li {
  margin: 8px 0;
  color: #666;
}

/* 箭头动画 */
.arrow {
  transition: transform 0.2s;
  margin-right: 8px;
}

.arrow.expanded {
  transform: rotate(90deg);
}

/* 在原有样式基础上添加收藏按钮样式 */
.favorite-star {
  width: 20px;
  height: 20px;
  cursor: pointer;
  transition: transform 0.2s;
  margin-left: auto;
}

#favoriteItems .product-card {
  background: rgba(255, 223, 0, 0.1) !important;
  border: 1px solid rgba(255, 223, 0, 0.3);
}

#favoriteItems .product-path {
  color: #ffd700 !important;
}

#favoriteCategory .category-icon {
  width: 20px !important;
  height: 20px !important;
}

/* 确保卡片布局一致 */
.products-container {
  display: none;
  gap: 8px;
}

/* 添加下拉框样式 */
.recipe-selector {
  width: 200px;
  padding: 8px 12px;
  margin-bottom: 15px;
  border: 2px solid #e9ecef;
  border-radius: var(--border-radius);
  background: white;
  font-size: 14px;
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%232c3e50"><path d="M7 10l5 5 5-5z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
}

.recipe-selector:focus {
  border-color: var(--secondary-color);
  outline: none;
  box-shadow: 0 0 8px rgba(52, 152, 219, 0.2);
}

/* 添加排序状态提示 */
#favoriteCategory::after {
  content: "※ 收藏目录按净利润自动排序";
  display: block;
  color: #95a5a6;
  font-size: 12px;
  margin-top: 8px;
  padding-left: 10px;
}

/* 版权信息 */
.footer {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0; /* 左侧导航宽度 */
  text-align: center;
  padding: 12px 20px;
  font-size: 13px;
  color:var(--primary-color);
  z-index: 100;
  pointer-events: none; /* 防止阻挡交互 */
}

table {
  border-collapse: separate;
  border-spacing: 20px 20px; /* 水平间距 垂直间距 */
}

td,
th {
  border: none;
  width: 200px;
}

@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  
  .input-group {
    min-height: auto; /* 自动高度 */
  }
}

/* 成品售价输入容器 */
.sale-input-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.sale-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start; /* 左对齐 */
}

.sale-input-row label {
  width: 140px; /* 稍微减少标签宽度 */
  text-align: left;
  font-size: 14px;
}

.sale-input-row input {
  width: 120px; /* 减少输入框宽度 */
  padding: 6px 8px;
}

/* 导入导出功能区样式 */
.import-export-group {
  background: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  padding: 6px 12px;
  margin-bottom: 0px;
  height: 40px; /* 固定高度 */
  display: flex;
  align-items: center;
  flex-shrink: 0; /* 防止被压缩 */
}

.import-export-controls {
  width: 100%;
}

.button-group {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 100%; /* 确保填满父容器 */
}

.data-btn {
  padding: 3px 6px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 10px;
  min-width: 55px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.data-btn:hover {
  background: #34495e;
  transform: translateY(-1px);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.data-info {
  color: #666;
  font-size: 10px;
  margin: 0;
  line-height: 1.2;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.import-export-group {
  grid-column: 1 / -1;
}

/* 材料输入行布局 */
.material-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
}

.material-selector-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.material-row {
  display: grid;
  grid-template-columns: 1fr 100px 40px; /* 三列：材料信息、输入框、银两标签 */
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: var(--border-radius);
  gap: 10px;
}

/* 材料信息区域 - 左侧 */
.material-info {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  gap: 8px;
}

.material-info span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  font-size: 14px;
  color: #666;
}

.material-selector {
  width: 200px;
  max-width: 250px;
  padding: 6px 10px;
  border: 2px solid #e9ecef;
  border-radius: var(--border-radius);
  background: white;
  font-size: 13px;
  height: 36px;
  line-height: 1.5;
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg fill="%23333" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}

/* 银两单位样式优化 */
.material-inputs span {
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 5px;
  width: 40px; /* 固定银两文字宽度 */
  text-align: left;
}

.material-selector:focus {
  border-color: var(--secondary-color);
  outline: none;
  box-shadow: 0 0 8px rgba(52, 152, 219, 0.2);
}

.material-selector option {
  font-size: 14px;
  padding: 8px;
}

.material-details {
  display: flex;
  flex-direction: column;
  margin-left: 5px;
}

.material-ratio-info {
  font-size: 11px;
  color: #aaa;
  font-style: italic;
  margin-top: 2px;
  white-space: nowrap;
}

.material-input {
  width: 100px;
  padding: 6px 8px;
  border: 2px solid #e9ecef;
  border-radius: var(--border-radius);
  font-size: 13px;
  text-align: right;
  box-sizing: border-box;
}

.material-inputs {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.composite-inputs-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 6px;
}

/* 复合材料输入框布局 */
.composite-material {
  display: flex;
  align-items: center;
  justify-content: flex-end; /* 右对齐 */
  width: 100%;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: nowrap;
}

.composite-material span {
  font-size: 13px;
  color: #666;
  min-width: 80px;
  text-align: right;
  white-space: nowrap;
}

.composite-material input {
  width: 100px;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  flex-shrink: 0;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .material-row {
    flex-direction: column;
  }
  
  .material-info {
    min-width: 100%;
    margin-bottom: 15px;
  }
  
  .material-inputs {
    min-width: 100%;
    align-items: flex-start;
  }
  
  .composite-material {
    justify-content: space-between;
  }
}

/* 制造设置区域布局优化 */
.vitality-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vitality-inputs > div {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vitality-inputs label {
  font-size: 14px;
  margin-bottom: 5px;
}

.vitality-inputs input {
  width: 120px; /* 减少输入框宽度 */
  padding: 6px 8px;
}

.vitality-inputs p {
  margin: 5px 0;
  font-size: 13px;
}

/* 复合材料行 */
.composite-material-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  gap: 6px;
}

.composite-material-row span {
  font-size: 12px;
  color: #666;
  min-width: 60px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composite-material-row input {
  width: 100px;
  max-width: 80px;
  padding: 4px 6px;
  border: 2px solid #e9ecef;
  border-radius: var(--border-radius);
  font-size: 12px;
  text-align: right;
  box-sizing: border-box;
}

/* 银两标签 - 第三列 */
.material-unit {
  font-size: 13px;
  color: #666;
  text-align: center;
  white-space: nowrap;
  padding-left: 5px;
}


.material-list-page {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  padding: 20px;
  margin-bottom: 20px;
  min-height: 600px;
}

.material-list-header {
  margin-bottom: 30px;
  border-bottom: 2px solid var(--secondary-color);
  padding-bottom: 15px;
}

.material-list-header h2 {
  color: var(--primary-color);
  margin: 0 0 10px 0;
}

.material-list-header p {
  color: #666;
  margin: 0;
  font-size: 14px;
}

/* 材料分类容器 */
.material-categories-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  width: 100%;
}

/* 确保最小2列，最大6列，并且总是双数列 */
@media (max-width: 767px) {
  .material-categories-container {
    grid-template-columns: repeat(2, 1fr); /* 小屏幕显示2列 */
  }
}

@media (min-width: 768px) and (max-width: 1199px) {
  .material-categories-container {
    grid-template-columns: repeat(4, 1fr); /* 中等屏幕显示4列 */
  }
}

@media (min-width: 1200px) {
  .material-categories-container {
    grid-template-columns: repeat(6, 1fr); /* 大屏幕显示6列 */
  }
}

/* 材料分类盒子样式保持不变，确保适应网格布局 */
.material-category {
  background: #f8f9fa;
  border-radius: var(--border-radius);
  padding: 20px;
  border-left: 4px solid var(--secondary-color);
  min-height: 200px;
  break-inside: avoid; /* 防止内容被分割 */
  box-sizing: border-box;
}

/* 材料项样式保持不变 */
.material-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

.material-item:last-child {
  border-bottom: none;
}

.material-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.material-name span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.material-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  justify-content: flex-end;
}

.material-input-container input {
  width: 100px;
  padding: 6px 8px;
  border: 2px solid #e9ecef;
  border-radius: var(--border-radius);
  font-size: 13px;
  text-align: right;
}

.material-input-container span {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
}

/* 超小屏幕单列显示 */
@media (max-width: 479px) {
  .material-categories-container {
    grid-template-columns: 1fr; /* 超小屏幕单列显示 */
  }
}