/* ============================================================
   藏宝阁资产估价台 — 样式
   栅格：8pt 间距基准；Web 内容区最大宽 1440，主工作区 420 + 1fr
   字体层级：20/28 · 16/24 · 14/21 · 12/18（共 4 级）
   色板：中性撑结构，主色 1 个 + 语义色 3 个
   ============================================================ */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #cfd8e6;
  --text: #101828;
  --text-2: #475467;
  --text-3: #8b97a8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff4ff;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --warn: #b45309;
  --warn-soft: #fffaeb;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; line-height: 24px; }
h3 { font-size: 14px; line-height: 21px; }
p { margin: 0; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 24px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, #60a5fa 100%);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px 9px auto auto;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: #fff;
  opacity: .92;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 16px; line-height: 24px; font-weight: 600; }
.brand-text em {
  font-style: normal;
  font-size: 12px;
  line-height: 18px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }

.env-tag {
  font-size: 12px;
  line-height: 18px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.env-tag[data-state="ok"] { color: var(--success); background: var(--success-soft); border-color: #b7e4c7; }
.env-tag[data-state="bad"] { color: var(--danger); background: var(--danger-soft); border-color: #f5c2bd; }

/* ---------------- 接口设置抽屉 ---------------- */
.config-drawer {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 16px 24px 20px;
}
.config-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
}
.config-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 12px auto 0;
}
.config-btns { display: flex; gap: 8px; }

/* ---------------- 按钮 ---------------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  line-height: 21px;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:disabled { cursor: not-allowed; opacity: .45; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-ghost {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-sm { padding: 4px 12px; font-size: 12px; line-height: 18px; }

/* ---------------- 主布局 ---------------- */
.layout {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-input { padding: 24px; position: sticky; top: 88px; }
.panel-result { padding: 24px; min-height: calc(100vh - 160px); }

.panel-head { margin-bottom: 16px; }
.panel-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-sub { margin-top: 4px; font-size: 12px; line-height: 18px; color: var(--text-3); }

.panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.panel-foot-right { justify-content: flex-end; margin-top: 16px; }
.foot-note { font-size: 12px; line-height: 18px; color: var(--text-3); }

/* ---------------- 表单 ---------------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field + .field { margin-top: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.field-row .field + .field { margin-top: 0; }

.field-label { font-size: 12px; line-height: 18px; color: var(--text-2); font-weight: 500; }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-hint { font-size: 12px; line-height: 18px; color: var(--text-3); }

input[type="text"], textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  line-height: 21px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type="text"]:hover, textarea:hover { border-color: #b6c2d4; }
input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
input[type="text"]:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }

.inline-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------------- 分段控件 ---------------- */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  border-radius: 4px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 21px;
  color: var(--text-2);
  cursor: pointer;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

/* ---------------- 提示条 ---------------- */
.alert {
  margin-top: 16px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 18px;
  border: 1px solid transparent;
}
.alert-error { color: var(--danger); background: var(--danger-soft); border-color: #f5c2bd; }
.alert-info { color: var(--warn); background: var(--warn-soft); border-color: #f3d9a8; margin-top: 0; margin-bottom: 16px; }
.alert-ok { color: var(--success); background: var(--success-soft); border-color: #b7e4c7; }

/* ---------------- 状态胶囊 ---------------- */
.state-pill {
  flex: 0 0 auto;
  font-size: 12px;
  line-height: 18px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.state-pill[data-state="loading"] { color: var(--primary); background: var(--primary-soft); border-color: #c9daff; }
.state-pill[data-state="ok"] { color: var(--success); background: var(--success-soft); border-color: #b7e4c7; }
.state-pill[data-state="bad"] { color: var(--danger); background: var(--danger-soft); border-color: #f5c2bd; }
.state-pill[data-state="warn"] { color: var(--warn); background: var(--warn-soft); border-color: #f3d9a8; }

/* ---------------- 指标区 ---------------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.metric {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.metric-label { font-size: 12px; line-height: 18px; color: var(--text-3); }
.metric-value {
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.metric-unit { font-size: 12px; line-height: 18px; color: var(--text-3); }

/* ---------------- AI 复核卡 ---------------- */
.ai-card {
  border: 1px solid #c9daff;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
}
.ai-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.ai-head h3 { color: #1e40af; }
.ai-summary { font-size: 14px; line-height: 21px; color: var(--text); }
.ai-risk { margin-top: 8px; font-size: 12px; line-height: 18px; color: var(--warn); }
.ai-raw { margin-top: 12px; }
.ai-raw summary { font-size: 12px; line-height: 18px; color: var(--text-2); cursor: pointer; }
.ai-raw pre {
  margin: 8px 0 0;
  padding: 12px;
  max-height: 220px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 18px;
  white-space: pre-wrap;
  word-break: break-all;
}

.tag {
  font-size: 12px;
  line-height: 18px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  white-space: nowrap;
}
.tag[data-tone="ok"] { color: var(--success); background: var(--success-soft); border-color: #b7e4c7; }
.tag[data-tone="warn"] { color: var(--warn); background: var(--warn-soft); border-color: #f3d9a8; }
.tag[data-tone="bad"] { color: var(--danger); background: var(--danger-soft); border-color: #f5c2bd; }

/* ---------------- 明细表 ---------------- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: calc(100vh - 420px);
  background: var(--surface);
}

.item-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  line-height: 20px;
}

.item-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-size: 12px;
  line-height: 18px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
}

.item-table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text);
}
.item-table tbody tr:last-child td { border-bottom: none; }
.item-table tbody tr:hover td { background: #fbfcfe; }

.col-no { width: 40px; }
.col-name { min-width: 160px; }
.col-type { width: 72px; }
.col-lv { width: 96px; }
.col-attr { min-width: 180px; }
.col-money { width: 92px; text-align: right !important; }
.col-verdict { width: 88px; }
.item-table td.col-money { text-align: right; font-variant-numeric: tabular-nums; }

.cell-name { font-weight: 500; }
.cell-sub { display: block; font-size: 12px; line-height: 18px; color: var(--text-3); }
.cell-muted { color: var(--text-3); }

.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-size: 12px;
  line-height: 18px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}

.money-main { font-variant-numeric: tabular-nums; }
.money-strong { font-weight: 600; }

/* 空态 */
.row-empty td { padding: 0 !important; }
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 72px 24px;
  color: var(--text-3);
  text-align: center;
}
.empty strong { font-size: 14px; line-height: 21px; color: var(--text-2); font-weight: 500; }
.empty span:last-child { font-size: 12px; line-height: 18px; }
.empty-art {
  width: 56px;
  height: 40px;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  position: relative;
  margin-bottom: 8px;
}
.empty-art::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 10px;
  width: 32px;
  height: 2px;
  background: var(--border-strong);
  box-shadow: 0 8px 0 var(--border-strong), 0 16px 0 var(--border-strong);
}

/* 加载骨架 */
.skeleton {
  display: inline-block;
  height: 12px;
  width: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #eef2f7 25%, #e3e9f2 37%, #eef2f7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: 520px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 21px;
  color: #fff;
  background: #1d2939;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .18);
}
.toast[data-tone="bad"] { background: var(--danger); }
.toast[data-tone="ok"] { background: var(--success); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1280px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .config-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .panel-input { position: static; }
  .panel-result { min-height: auto; }
  .table-wrap { max-height: none; }
  .brand-text em { display: none; }
}

@media (max-width: 720px) {
  .topbar-inner { padding: 12px 16px; }
  .config-drawer { padding: 12px 16px 16px; }
  .config-grid { grid-template-columns: minmax(0, 1fr); }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .field-row .field + .field { margin-top: 16px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-input, .panel-result { padding: 16px; }
  .panel-foot { flex-wrap: wrap; }
}
