/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-surface-hover: #1c2128;
  --bg-input: #0d1117;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #7d8590;
  --accent: #2f81f7;
  --accent-hover: #4493f8;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --purple: #a371f7;
  --radius: 10px;
  --sidebar-w: 260px;
}
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* ===== 侧边栏 ===== */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 24px; }
.sidebar-header .title { font-size: 15px; font-weight: 600; }

.sidebar-section { padding: 16px; }
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.sidebar-btn {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.sidebar-btn:hover { background: var(--bg-surface-hover); border-color: var(--accent); }

.status-panel { font-size: 12px; }
.status-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.status-item:last-child { border-bottom: none; }
.status-key { color: var(--text-dim); }
.status-val { color: var(--text); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.version { font-size: 11px; color: var(--text-dim); }

/* ===== 主区域 ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.header-title { font-size: 16px; font-weight: 600; }
.header-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ===== 聊天区 ===== */
#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}
#messages { max-width: 800px; margin: 0 auto; }

.msg {
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--accent); color: #fff; }
.msg.bot .msg-avatar { background: var(--bg-surface-hover); border: 1px solid var(--border); }

.msg-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .msg-bubble { background: var(--accent); color: #fff; }
.msg.bot .msg-bubble { background: var(--bg-surface); border: 1px solid var(--border); }

/* ===== 扫描结果卡片 ===== */
.scan-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
  max-width: 70%;
}
.scan-card .card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.scan-card .card-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.scan-card .card-row .key { color: var(--text-dim); }
.scan-card .image-list { margin-top: 8px; }
.scan-card .image-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
}
.scan-card .image-item .badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}
.badge.data { background: rgba(63,185,80,0.15); color: var(--green); }
.badge.ref { background: rgba(125,133,144,0.15); color: var(--text-dim); }

/* ===== 模式选择卡片 ===== */
.mode-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
  max-width: 70%;
}
.mode-card .mode-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.mode-options { display: flex; flex-direction: column; gap: 10px; }
.mode-option {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-option:hover { border-color: var(--accent); background: var(--bg-surface-hover); }
.mode-option.selected { border-color: var(--accent); background: rgba(47,129,247,0.08); }
.mode-option .opt-header { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.mode-option .opt-desc { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.mode-option input {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.mode-option input:focus { outline: none; border-color: var(--accent); }
.mode-option select {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.mode-option select:focus { outline: none; border-color: var(--accent); }

.run-btn {
  margin-top: 12px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.run-btn:hover { background: var(--accent-hover); }
.run-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.secondary-btn:hover { border-color: var(--accent); color: var(--text); background: var(--bg-surface-hover); }

.cost-table-card input,
.cost-table-card select {
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.cost-table-card input:focus,
.cost-table-card select:focus { outline: none; border-color: var(--accent); }

/* ===== 进度区 ===== */
#progress-area { padding: 0 24px 12px; max-width: 800px; margin: 0 auto; width: 100%; }
.progress-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.progress-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.stop-btn {
  padding: 4px 12px;
  font-size: 12px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}
.stop-btn:hover { background: #c0392b; }
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#progress-text { font-size: 14px; font-weight: 500; }

.progress-bar-container {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.progress-log {
  margin-top: 10px;
  max-height: 120px;
  overflow-y: auto;
  font-size: 12px;
  font-family: "Cascadia Code", "Fira Code", monospace;
  color: var(--text-dim);
  line-height: 1.5;
}
.log-line { padding: 2px 0; }
.log-line.info { color: var(--text); }
.log-line.warn { color: var(--yellow); }
.log-line.error { color: var(--red); }
.log-line.success { color: var(--green); }

/* ===== 结果卡片 ===== */
.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 8px;
  max-width: 70%;
}
.result-card .result-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-value.cost { color: var(--green); }
.stat-value.batch { color: var(--accent); }

.result-section { margin-top: 16px; }
.result-section .section-h { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text-dim); }
.formula-table, .supplier-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.formula-table th, .formula-table td,
.supplier-table th, .supplier-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.formula-table th, .supplier-table th { color: var(--text-dim); font-weight: 600; }
.warning-row { color: var(--yellow); }

.download-buttons { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.download-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.download-btn:hover { border-color: var(--accent); background: var(--bg-surface-hover); }

/* ===== 输入区 ===== */
#input-area {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}
.input-wrapper { display: flex; gap: 10px; max-width: 800px; margin: 0 auto; }
#input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
#input:focus { border-color: var(--accent); }
#send-btn {
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.upload-btn {
  padding: 12px 16px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.upload-btn:hover { border-color: var(--accent); color: var(--accent); }
.input-hint { text-align: center; font-size: 11px; color: var(--text-dim); margin-top: 6px; }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  #sidebar { display: none; }
  .msg-bubble, .scan-card, .mode-card, .result-card { max-width: 90%; }
}

/* ===== Excel 预览对话框 ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  width: 90%;
  max-width: 1200px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s;
}
.modal-close:hover {
  color: var(--text);
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
