/* AIFID V1 极简前端样式 */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1e8e3e;
  --primary-light: #e6f4ea;
  --primary-dark: #186d2f;
  --warn: #f9ab00;
  --error: #d93025;
  --text: #202124;
  --text-secondary: #5f6368;
  --bg: #fafafa;
  --bg-card: #fff;
  --border: #dadce0;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== 顶栏 ===== */
.header {
  background: linear-gradient(135deg, #1e8e3e 0%, #34a853 100%);
  color: #fff;
  padding: 16px 24px;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 28px; }
.logo-text { font-size: 22px; font-weight: 700; }
.logo-sub { font-size: 13px; opacity: 0.85; margin-left: 8px; }

.header-right { display: flex; gap: 12px; align-items: center; font-size: 12px; }
.env-badge, .llm-badge {
  background: rgba(255,255,255,0.2);
  padding: 4px 10px;
  border-radius: 12px;
  font-family: ui-monospace, monospace;
}
.env-badge.production { background: rgba(255,255,255,0.25); }
.env-badge.staging { background: rgba(249,171,0,0.5); }
.llm-badge.ready { background: rgba(52,168,83,0.5); }
.llm-badge.fallback { background: rgba(217,48,37,0.5); }
.version { opacity: 0.7; font-family: ui-monospace, monospace; }

/* ===== 主区 ===== */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  width: 100%;
}

/* ===== 侧栏 ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  transition: all 0.15s;
}
.nav-item:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}
.nav-item.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

/* ===== 内容区 ===== */
.content {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px 32px;
  box-shadow: var(--shadow);
  min-height: 600px;
}

.tab { display: none; }
.tab.active { display: block; }

h2 { color: var(--primary-dark); margin-bottom: 8px; font-size: 22px; }
h3 { color: var(--text); margin: 20px 0 8px; font-size: 16px; }
.tab-desc { color: var(--text-secondary); margin-bottom: 24px; }

/* ===== 表单 ===== */
.form { background: var(--bg); padding: 20px; border-radius: 8px; margin-bottom: 20px; }
.form-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.form-row label { min-width: 80px; font-weight: 500; color: var(--text-secondary); }
.form-row input[type=text], .form-row select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  flex: 1;
  max-width: 300px;
}
.form-row input[type=text]:focus, .form-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30,142,62,0.1);
}
.checkbox-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
}
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  font-size: 13px;
  min-width: auto;
}
.checkbox-group label:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 500;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.btn-login {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn-login:hover { background: rgba(255,255,255,0.3); }
.btn-login.logged {
  background: rgba(255,255,255,0.3);
  border-color: rgba(255,255,255,0.5);
}

.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 28px 32px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.modal-content h3 { color: var(--primary-dark); margin-bottom: 8px; }
.modal-content code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ===== 结果区 ===== */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.alert-warning {
  background: #fef7e0;
  color: #7c5800;
  border-left: 4px solid var(--warn);
}
.alert-success {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-left: 4px solid var(--primary);
}
.alert-info {
  background: #e8f0fe;
  color: #1967d2;
  border-left: 4px solid #1967d2;
}

.tier-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  border-left: 4px solid var(--primary);
}
.tier-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.tier-name { font-size: 18px; font-weight: 700; color: var(--primary-dark); }
.tier-cost { font-size: 16px; font-weight: 600; color: var(--text); }
.tier-cost small { color: var(--text-secondary); font-weight: 400; }
.tag-llm {
  font-size: 11px;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}
.tag-fallback {
  font-size: 11px;
  background: var(--warn);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}

.ing-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ing-table th, .ing-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.ing-table th { color: var(--text-secondary); font-weight: 500; background: var(--bg); }
.ing-table tr:hover { background: var(--primary-light); }
.ing-table .price { font-weight: 600; color: var(--primary-dark); }

.conf-high { color: var(--primary); }
.conf-medium { color: var(--warn); }
.conf-low, .conf-unclear, .conf-missing { color: var(--error); }

.narrative {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-top: 16px;
  white-space: pre-wrap;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.8;
  max-height: 500px;
  overflow-y: auto;
}

/* ===== 成分库列表 ===== */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.count-badge {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.ing-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  max-height: 600px;
  overflow-y: auto;
}
.ing-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  transition: all 0.15s;
}
.ing-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.ing-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.ing-id { font-size: 11px; color: var(--text-secondary); font-family: ui-monospace, monospace; }
.ing-func { font-size: 12px; color: var(--primary); margin-top: 4px; }
.ing-mech { font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.5; }
.ing-price { font-size: 14px; font-weight: 600; color: var(--primary-dark); margin-top: 6px; }

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { color: var(--text); margin-bottom: 12px; }
.empty-state .hint { font-size: 12px; color: var(--text-secondary); margin-top: 12px; opacity: 0.7; }

/* ===== 底栏 ===== */
.footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 24px;
}

.loading { text-align: center; padding: 40px; color: var(--text-secondary); }
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* RAG 参考案例 */
.ref-cases {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.ref-case {
  background: linear-gradient(135deg, #f0f7ff 0%, #e8f4f8 100%);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 13px;
}
.ref-case-name {
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 4px;
}
.ref-case-source {
  color: #666;
  font-size: 11px;
  margin-bottom: 6px;
  font-style: italic;
}
.ref-case-effect {
  color: var(--text);
  line-height: 1.5;
}

/* ============================================
   V1.2: Knowledge Mining Pipeline 样式
   ============================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.stat-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary-dark, #166534);
  line-height: 1.2;
}
.stat-label {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}
.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
}
.action-row label {
  margin-right: 8px;
  font-size: 13px;
  color: #555;
}
.action-row select {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}
.action-left, .action-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.candidate-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  transition: all 0.2s;
}
.candidate-card:hover {
  border-color: var(--primary, #16a34a);
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.1);
}
.cand-header {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}
.cand-check {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  cursor: pointer;
}
.cand-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.cand-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary-dark, #166534);
}
.conf-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}
.conf-high { background: #dcfce7; color: #166534; }
.conf-med { background: #fef3c7; color: #92400e; }
.conf-low { background: #fee2e2; color: #991b1b; }
.src-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #dbeafe;
  color: #1e40af;
}
.meta-tag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f3f4f6;
  color: #4b5563;
}
.cand-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  line-height: 1.6;
}
.cand-section h5 {
  font-size: 12px;
  color: #6b7280;
  text-transform: uppercase;
  margin: 0 0 4px 0;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.cand-section p {
  margin: 0;
  color: #374151;
}
.cand-section .evidence {
  font-style: italic;
  background: #fef9c3;
  padding: 8px 10px;
  border-left: 3px solid #facc15;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
}
.cand-section .meta {
  font-size: 11px;
  color: #9ca3af;
  font-family: monospace;
  word-break: break-all;
}
.cand-section a {
  color: #1d4ed8;
  text-decoration: none;
}
.cand-section a:hover {
  text-decoration: underline;
}
.cand-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}
.empty {
  text-align: center;
  color: #9ca3af;
  padding: 40px;
  font-size: 14px;
}
.empty.err {
  color: #dc2626;
}

/* ============================================ */
/* V1.3 Price Research 样式                       */
/* ============================================ */
.pr-card {
  border-left: 4px solid #6366f1;
}
.pr-comparison {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  background: #f9fafb;
  border-radius: 6px;
}
.pr-col {
  flex: 1;
  min-width: 0;
}
.pr-col.pr-decision {
  flex: 1.5;
  background: #fff;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #e5e7eb;
}
.pr-label {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 4px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.pr-value {
  font-size: 18px;
  font-weight: 700;
  color: #111827;
  font-family: 'SF Mono', Consolas, monospace;
}
.pr-arrow {
  align-self: center;
  color: #9ca3af;
  font-size: 20px;
}
.pr-input, .pr-conf, .pr-source {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 13px;
  margin-top: 4px;
}
.pr-input { font-family: 'SF Mono', Consolas, monospace; }
.pr-source { font-size: 12px; }
.pr-reasoning {
  font-size: 13px;
  color: #4b5563;
  background: #fef3c7;
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 3px solid #f59e0b;
  margin-top: 8px;
  line-height: 1.5;
}
.pr-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}
.pr-source-note {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
  word-break: break-all;
}

.verdict-low {
  background: #fecaca;
  color: #991b1b;
}
.verdict-high {
  background: #fde68a;
  color: #92400e;
}
.verdict-ok {
  background: #d1fae5;
  color: #065f46;
}
.verdict-unk {
  background: #e5e7eb;
  color: #4b5563;
}
