﻿/* ===== 基础重置 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ===== 滚动条样式 ===== */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg2);
}

::-webkit-scrollbar-thumb {
  background: var(--bg4);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted2);
}

/* ===== 通用按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg3);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg4);
  border-color: var(--rule2);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: var(--accent2);
  color: #fff;
  border-color: var(--accent2);
}

.btn-danger:hover {
  background: #c0392b;
  border-color: #c0392b;
}

.btn-success {
  background: var(--accent3);
  color: #fff;
  border-color: var(--accent3);
}

.btn-success:hover {
  background: #1e8449;
  border-color: #1e8449;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline:hover {
  background: var(--accent);
  color: #fff;
}

.btn-export {
  background: var(--accent4);
  color: #fff;
  border-color: var(--accent4);
}

.btn-export:hover {
  background: #d68910;
  border-color: #d68910;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 16px;
}

/* ===== 通用输入框 ===== */
input,
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg2);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ===== 表单组 ===== */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===== 通用卡片 ===== */
.card {
  background: var(--bg2);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--rule);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ===== 表格样式 ===== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table th {
  background: var(--bg3);
  padding: 10px 12px;
  text-align: left;
  color: var(--ink);
  border-bottom: 2px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 1;
}

table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink2);
}

table tr:hover td {
  background: rgba(30, 136, 229, 0.05);
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 600px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  margin: 12px 0;
}

/* ===== 标签样式系统 ===== */
.tag {
  display: inline-block;
  min-width: 52px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}

.tag.blue {
  background: rgba(30, 136, 229, 0.2);
  color: var(--accent-hover);
}

.tag.red {
  background: rgba(231, 76, 60, 0.2);
  color: var(--accent2);
}

.tag.green {
  background: rgba(39, 174, 96, 0.2);
  color: var(--accent3);
}

.tag.orange {
  background: rgba(243, 156, 18, 0.2);
  color: var(--accent4);
}

.tag.gray {
  background: rgba(136, 136, 136, 0.2);
  color: var(--muted);
}

/* ===== 徽章样式 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent2);
  color: #fff;
}

.badge.blue {
  background: var(--accent);
}

.badge.green {
  background: var(--accent3);
}

.badge.orange {
  background: var(--accent4);
}

.badge.gray {
  background: var(--muted2);
}

/* ===== 空状态 ===== */
.empty {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

/* ===== Toast 提示 ===== */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: var(--accent3);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

.toast.show {
  opacity: 1;
}

/* ===== 模态框 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg2);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.modal-header h3 {
  font-size: 18px;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.modal-close:hover {
  color: var(--accent2);
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

/* ===== 关联库存 ===== */
.stock-link-section {
  margin-top: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.stock-link-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg2);
  cursor: pointer;
  user-select: none;
  gap: 8px;
}
.stock-link-header:hover {
  background: var(--bg3);
}
.stock-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--muted2);
  border-radius: 999px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.stock-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.stock-toggle.on {
  background: var(--accent3);
}
.stock-toggle.on::after {
  transform: translateX(16px);
}
.stock-link-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 12px;
}
.stock-link-body.open {
  max-height: 400px;
  padding: 12px;
}
.stock-link-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stock-info-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--ink);
}

/* ===== 统计卡片网格 ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.stat-card {
  background: var(--bg2);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--rule);
  text-align: center;
}

.stat-card .stat-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .stat-num.red {
  color: var(--accent2);
}

.stat-card .stat-num.green {
  color: var(--accent3);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.stat-card .stat-change {
  font-size: 11px;
  margin-top: 6px;
}

.stat-card .stat-change.up {
  color: var(--accent3);
}

.stat-card .stat-change.down {
  color: var(--accent2);
}

/* ===== 加载状态 ===== */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.loading::after {
  content: '...';
  display: inline-block;
  animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
  0%, 20% {
    content: '.';
  }
  40% {
    content: '..';
  }
  60%, 100% {
    content: '...';
  }
}

/* ===== 进度条 ===== */
.progress {
  height: 8px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s;
}

.progress-bar.green {
  background: var(--accent3);
}

.progress-bar.red {
  background: var(--accent2);
}

.progress-bar.orange {
  background: var(--accent4);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal {
    width: 95%;
    max-height: 90vh;
  }
}

/* 修复 #27：checkbox 样式统一 */
input[type="checkbox"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--rule2, #555);
  border-radius: 4px;
  background: var(--bg, #1a1a1a);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  transition: all 0.2s;
  flex-shrink: 0;
}
input[type="checkbox"]:hover {
  border-color: var(--accent, #1e88e5);
}
input[type="checkbox"]:checked {
  background: var(--accent, #1e88e5);
  border-color: var(--accent, #1e88e5);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"]:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(30, 136, 229, 0.3);
}

input[type="radio"] {
  width: auto;
  padding: 0;
  border: none;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 修复 #33：键盘可访问性 focus-visible 样式 */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 鼠标点击不显示 outline（仅键盘导航时显示） */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

/* 修复 #32：select 下拉箭头 + option 暗色样式 */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
select option {
  background-color: var(--bg2);
  color: var(--ink);
}
select option:checked {
  background-color: var(--accent);
  color: #fff;
}

/* 修复 #32：range 滑块暗色样式 */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg4);
  border-radius: 3px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  transition: var(--transition);
}
input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent-hover);
  transform: scale(1.15);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
}

/* 修复 #32：number 输入框去除默认 spinner */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* ===== 导出展示页弹窗 ===== */
.export-desc {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--ink2);
  line-height: 1.6;
  border-left: 3px solid var(--accent);
  background: var(--bg3);
}

.export-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--rule);
}

.export-count {
  font-size: 13px;
  color: var(--muted);
}

.export-cat-list {
  padding: 8px 12px 12px;
}

.export-cat-group {
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 6px;
  transition: var(--transition);
}

.export-cat-group:hover {
  border-color: var(--rule2);
}

.export-cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  background: var(--bg3);
  transition: var(--transition);
  user-select: none;
}

.export-cat-header:hover {
  background: var(--bg4);
}

.export-cat-header input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.export-cat-count {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg4);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: auto;
}

.export-cat-arrow {
  color: var(--muted);
  font-size: 11px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.export-cat-products {
  display: none;
  padding: 4px 8px 6px 36px;
  background: var(--bg2);
}

.export-prod-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.export-prod-row:hover {
  background: var(--bg3);
}

.export-prod-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.export-prod-name {
  font-size: 13px;
  color: var(--ink);
  flex: 1;
}

.export-prod-price {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.export-prod-empty {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--muted);
}