:root {
  --brand: #b45309;
  --brand-700: #92400e;
  --brand-50: #fffbeb;
  --bg: #fafafa;
  --surface: #ffffff;
  --line: #e5e5e5;
  --line-soft: #f5f5f5;
  --txt: #171717;
  --txt-secondary: #525252;
  --txt-tertiary: #737373;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--txt);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--txt);
  transition: background-color 120ms ease, border-color 120ms ease;
}
button:hover {
  background: var(--line-soft);
  border-color: #d4d4d4;
}
button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
button.primary:hover {
  background: var(--brand-700);
  border-color: var(--brand-700);
}
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--txt-secondary);
}
button.ghost:hover {
  background: var(--brand-50);
  color: var(--brand);
}
button:disabled { opacity: .45; cursor: default; }

input, select, textarea {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--txt);
  background: var(--surface);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-50);
}
input::placeholder { color: var(--txt-tertiary); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}
th {
  color: var(--txt-tertiary);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.03em;
  background: var(--line-soft);
}
tr:last-child td { border-bottom: none; }
td.wrap { white-space: normal; min-width: 200px; }
div.wrap { white-space: normal; max-width: 420px; }

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card h1 {
  font-size: 22px;
  margin: 0;
  text-align: center;
  color: var(--txt);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-card .subtitle {
  text-align: center;
  color: var(--txt-tertiary);
  font-size: 13px;
  margin-top: -8px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--txt-secondary); font-weight: 500; }
.login-card button.primary { padding: 11px; font-size: 14px; margin-top: 4px; }
.err { color: #dc2626; font-size: 12px; min-height: 16px; font-weight: 500; }

header {
  display: flex;
  flex-direction: column; /* 2026-10-17 两行结构：上=品牌+平台切换，下=主导航 */
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-top {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 52px;
}
.logo {
  font-weight: 650;
  font-size: 17px;
  color: var(--txt);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.logo::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--brand);
}
/* 平台切换按钮组（2026-10-17）：品牌名右侧，未接入平台作占位入口 */
.platform-tabs {
  display: flex;
  gap: 6px;
  flex: 1;
  align-items: center;
}
.ptab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--txt-secondary);
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.ptab:hover { border-color: var(--brand); color: var(--brand); }
.ptab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
nav { display: flex; gap: 4px; height: 44px; align-items: center; border-top: 1px solid var(--line); }
/* header 右上角商户名称（2026-10-16）：退出按钮左侧、nav 弹性占位后自然右靠 */
.tenant-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--txt-secondary);
  padding: 5px 12px;
  background: var(--brand-50);
  border-radius: 14px;
  white-space: nowrap;
}
nav a {
  color: var(--txt-secondary);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: background-color 120ms ease, color 120ms ease;
}
nav a:hover { background: var(--line-soft); color: var(--txt); }
nav a.active { background: var(--brand-50); color: var(--brand); }
main { padding: 28px; max-width: 1280px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}
.card h2 { font-size: 15px; margin: 0 0 16px; font-weight: 600; color: var(--txt); letter-spacing: -0.01em; }
.card h3 { font-size: 13px; margin: 20px 0 10px; color: var(--txt-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tier-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.tier-card:hover {
  border-color: #d4d4d4;
  background: var(--line-soft);
}
.tier-card .label { font-weight: 600; font-size: 15px; color: var(--txt); }
.tier-card .range { color: var(--txt-tertiary); font-size: 12px; margin-bottom: 12px; }
.tier-card .metrics { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--txt-secondary); }
.tier-card .metrics b { color: var(--txt); font-weight: 600; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.kv .item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.kv .item .k { font-size: 12px; color: var(--txt-tertiary); font-weight: 500; margin-bottom: 4px; }
.kv .item .v { font-size: 22px; font-weight: 600; color: var(--txt); letter-spacing: -0.01em; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: var(--line-soft);
  color: var(--txt-secondary);
  margin-right: 6px;
}
.badge.ad { background: #fff7ed; color: #9a3412; }
.badge.hit { background: #f0fdf4; color: #166534; }
.badge::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}
.matched { color: #166534; font-weight: 600; }
.skipped { color: var(--txt-tertiary); }
.muted { color: var(--txt-tertiary); font-size: 12px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.pct::after { content: "%"; }

/* ---------- 首页仪表盘（P1 店铺诊断 v1） ---------- */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.dash-grid .card { margin-bottom: 0; }

.health-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.score-circle {
  width: 96px; height: 96px; border-radius: 50%;
  border: 6px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.score-circle span { font-size: 30px; font-weight: 700; }
.dims { display: flex; flex-wrap: wrap; gap: 8px; }
.dim-chip {
  display: inline-flex; flex-direction: column; align-items: center;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--line-soft); min-width: 68px;
}
.dim-chip .dim-label { font-size: 12px; color: var(--txt-tertiary); }
.dim-chip .dim-score { font-size: 16px; font-weight: 600; }
.dim-chip.dim-off { opacity: .45; }

.funnel-row {
  display: grid; grid-template-columns: 52px 1fr 90px 56px;
  gap: 10px; align-items: center; margin-bottom: 12px;
}
.funnel-label { font-size: 13px; color: var(--txt-secondary); }
.funnel-bar-wrap { background: var(--line-soft); border-radius: 4px; height: 18px; }
.funnel-bar {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, #64748b, #2563eb);
}
.funnel-bar.funnel-off { background: var(--line); }
.funnel-value { font-size: 13px; font-weight: 600; text-align: right; }
.funnel-rate { text-align: right; }

.trend-wrap {
  display: flex; align-items: flex-end; gap: 2px;
  height: 56px; padding-top: 4px;
}
.trend-col { flex: 1; display: flex; align-items: flex-end; height: 100%; }
.trend-bar {
  width: 100%; border-radius: 2px 2px 0 0;
  background: #93c5fd; min-height: 2px;
}
.trend-col:hover .trend-bar { background: #2563eb; }

.alert-row {
  padding: 8px 12px; border-radius: 6px; margin-bottom: 8px;
  font-size: 13px;
}
.alert-row.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-row.danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-row.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.dash-alerts { grid-column: 1 / -1; }

/* 单品诊断表 */
.diag-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.diag-table th {
  text-align: right; padding: 6px 8px; color: var(--txt-tertiary);
  font-weight: 500; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.diag-table th:nth-child(1), .diag-table th:nth-child(2) { text-align: left; }
.diag-table td {
  padding: 8px; text-align: right; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.diag-table td:nth-child(1), .diag-table td:nth-child(2) { text-align: left; }
.diag-table tbody tr { cursor: pointer; }
.diag-table tbody tr:hover { background: var(--line-soft); }
.diag-title { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }

/* 通用表格（d4 分析页：人群/地域排行、流量渠道；前两列左对齐） */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: right; padding: 6px 8px; color: var(--txt-tertiary);
  font-weight: 500; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td {
  padding: 8px; text-align: right;
  border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
.tbl th:nth-child(1), .tbl th:nth-child(2),
.tbl td:nth-child(1), .tbl td:nth-child(2) { text-align: left; }

.lc {
  display: inline-flex; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.lc-new { background: #eff6ff; color: #1d4ed8; }
.lc-growing { background: #f0fdf4; color: #15803d; }
.lc-mature { background: #f5f5f4; color: #44403c; }
.lc-declining { background: #fff7ed; color: #c2410c; }
.lc-idle { background: #fafafa; color: var(--txt-tertiary); }

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--txt-tertiary);
}

@media (max-width: 768px) {
  header { gap: 12px; padding: 0 16px; height: auto; min-height: 56px; flex-wrap: wrap; }
  nav { order: 3; width: 100%; padding-bottom: 8px; }
  main { padding: 16px; }
  .tier-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}

/* ---------- AI 运营顾问对话页 ---------- */
.ai-msg { display: flex; flex-direction: column; max-width: 86%; }
.ai-msg-user { align-self: flex-end; align-items: flex-end; }
.ai-msg-ai { align-self: flex-start; }
.ai-bubble {
  padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
  line-height: 1.7; word-break: break-word;
}
.ai-msg-user .ai-bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 2px; }
.ai-msg-ai .ai-bubble { background: var(--line-soft); border: 1px solid var(--line); border-bottom-left-radius: 2px; }
.ai-skill-tag {
  font-size: 11px; color: var(--txt-tertiary); margin: 0 0 3px 4px;
}
/* P1-1.3 回复反馈按钮（赞/踩/重新生成） */
.ai-fb-row { display: flex; gap: 6px; margin-top: 5px; padding-left: 4px; }
.ai-fb-btn {
  font-size: 11px; color: var(--txt-tertiary); background: none;
  border: 1px solid transparent; border-radius: 6px; padding: 2px 8px;
  cursor: pointer; line-height: 1.6;
}
.ai-fb-btn:hover { color: var(--txt); border-color: var(--line); background: var(--line-soft); }
.ai-fb-btn.on { color: var(--brand); border-color: var(--brand); background: rgba(46,125,50,.08); }
/* P3-1.2 AI 建议卡片（Agent 创建的待审批任务，气泡下方逐张渲染） */
.ai-sugg-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; padding-left: 4px; }
.ai-sugg-card {
  display: flex; flex-direction: column; gap: 6px; max-width: 440px;
  padding: 10px 12px; border: 1px solid var(--brand); border-radius: 8px;
  background: rgba(46,125,50,.05);
}
.ai-sugg-top { display: flex; justify-content: space-between; align-items: center; }
.ai-sugg-badge {
  font-size: 11px; color: #fff; background: var(--brand);
  padding: 2px 10px; border-radius: 999px;
}
.ai-sugg-status { font-size: 11px; color: #d97706; font-weight: 600; }
.ai-sugg-summary { font-size: 13px; line-height: 1.6; }
.ai-sugg-foot { display: flex; align-items: center; gap: 8px; }
.ai-sugg-go {
  font-size: 12px; color: var(--brand); background: none;
  border: 1px solid var(--brand); border-radius: 6px;
  padding: 4px 14px; cursor: pointer; line-height: 1.5;
}
.ai-sugg-go:hover { background: var(--brand); color: #fff; }
.md-body p { margin: 0 0 8px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body ul, .md-body ol { margin: 4px 0 10px; padding-left: 20px; }
.md-body li { margin: 3px 0; }
.md-body h3, .md-body h4, .md-body h5, .md-body h6 {
  margin: 12px 0 6px; font-weight: 600; color: var(--txt);
}
.md-body h3 { font-size: 15px; }
.md-body h4 { font-size: 13px; }
.md-body h5, .md-body h6 { font-size: 12px; }
.md-body blockquote {
  margin: 6px 0; padding: 4px 10px; border-left: 3px solid var(--brand);
  background: rgba(180, 83, 9, 0.06); border-radius: 0 6px 6px 0;
}
.md-body code {
  background: rgba(0,0,0,.07); padding: 1px 5px; border-radius: 4px;
  font-size: 12px; font-family: Consolas, monospace;
}
.md-body hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.md-table-wrap { overflow-x: auto; margin: 8px 0; }
.md-body table { border-collapse: collapse; font-size: 12px; width: 100%; }
.md-body th, .md-body td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: left; white-space: normal;
}
.md-body th { background: var(--line-soft); font-weight: 600; color: var(--txt); }
.md-body tbody tr:nth-child(even) { background: rgba(0,0,0,.02); }

