/* WebAnaly 看板样式 —— 浅色为主，窄屏自适应，零外部字体依赖 */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e4e9f0;
  --text: #1f2937;
  --text-2: #5b6779;
  --muted: #8b96a8;
  --accent: #2f6fed;
  --accent-soft: #ebf1ff;
  --up: #d64545;      /* 涨：红 */
  --down: #2f9e44;    /* 跌：绿 */
  --warn: #d98613;
  --danger: #d64545;
  --ok: #2f9e44;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --border: #2b313b;
    --text: #e8ecf2;
    --text-2: #a9b3c1;
    --muted: #7f8b9c;
    --accent: #6b9bff;
    --accent-soft: #1e2a44;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
  .grid { stroke: #2b313b; }
  .chart-svg .axis { fill: #7f8b9c; }
  .pie-total { fill: #e8ecf2; }
  .pie-sub { fill: #7f8b9c; }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

/* ---------- 布局 ---------- */
.shell { display: flex; min-height: 100vh; }

.side {
  width: 208px;
  flex: 0 0 208px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  padding: 18px 18px 14px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.nav { padding: 4px 10px; overflow-y: auto; flex: 1; }
.nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13.5px;
  margin-bottom: 2px;
}
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-foot { padding: 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.topbar h2 { font-size: 16px; }
.topbar .spacer { flex: 1; }

.wrap { padding: 18px 22px 48px; }

/* ---------- 通用控件 ---------- */
select, input[type=text], input[type=password], input[type=number], input[type=date], textarea {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  max-width: 100%;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff;
  border: 1px solid transparent; border-radius: 8px;
  padding: 7px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: var(--panel); color: var(--text-2); border-color: var(--border); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card > h3 { font-size: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card > h3 .hint { font-weight: 400; font-size: 12px; color: var(--muted); }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.metric .k { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.metric .v { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.metric .d { font-size: 12px; color: var(--muted); margin-top: 4px; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .two-col, .three-col { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .side { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .18s; }
  .side.open { transform: none; }
  .shell { display: block; }
  .wrap, .topbar { padding-left: 14px; padding-right: 14px; }
  #menu-btn { display: inline-flex !important; }
  .grid-cards { grid-template-columns: 1fr 1fr; }
}

/* ---------- 表格 ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.path { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.tbl .rank { color: var(--muted); width: 28px; font-variant-numeric: tabular-nums; }

/* 榜单条：数值占比的直观呈现 */
.bar-track { position: relative; height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 3px; }

/* 升降榜的双向条：中线为 0，向右为涨（红）、向左为跌（绿） */
.dbar {
  position: relative; height: 8px; min-width: 90px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px; overflow: hidden;
}
.dbar::before {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--border);
}
.dfill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }

/* ---------- 图表 ---------- */
.chart-svg { width: 100%; height: 280px; display: block; }
.chart-svg.chart-pie { height: 240px; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-svg .axis { font-size: 11px; fill: var(--muted); }
.chart-svg .axis-y { text-anchor: end; }
.chart-svg .axis-x { text-anchor: middle; }
/* 柱状图色：走 CSS 变量而不是硬编码色值，才能在深色主题下自动跟随 */
.chart-svg .bar { fill: var(--accent); }
.chart-svg .bar-prev { fill: var(--muted); opacity: .45; }
.pie-total { font-size: 22px; font-weight: 700; text-anchor: middle; fill: var(--text); }
.pie-sub { font-size: 11px; text-anchor: middle; fill: var(--muted); }
.spark { width: 100%; height: 28px; display: block; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

.empty { color: var(--muted); font-size: 13px; padding: 28px 0; text-align: center; }
.error-box {
  background: #fdecec; color: #a12a2a; border: 1px solid #f6c9c9;
  border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px;
}
.alert { border-radius: 8px; padding: 9px 14px; font-size: 13px; margin-bottom: 10px; }
.alert.danger { background: #fdecec; color: #a12a2a; border: 1px solid #f6c9c9; }
.alert.warn { background: #fdf6e6; color: #8a5b00; border: 1px solid #f3e0b3; }
.alert.ok { background: #eaf7ee; color: #22683a; border: 1px solid #c7e6d1; }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.note strong { color: var(--text-2); }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 11.5px; background: var(--accent-soft); color: var(--accent);
}
.badge.grey { background: var(--bg); color: var(--muted); }
.badge.ok { background: #eaf7ee; color: var(--ok); }
.badge.bad { background: #fdecec; color: var(--danger); }

.site-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel);
}
.site-pill select { border: none; padding: 0; background: transparent; font-size: 13px; }

code, pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
pre.snippet {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; white-space: pre; margin: 0 0 10px;
  user-select: all;
}

.kv { display: grid; grid-template-columns: 168px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- Markdown 报告渲染 ---------- */
.md { font-size: 14px; line-height: 1.85; color: var(--text-2); }
.md h2 {
  font-size: 15px; margin: 24px 0 8px; color: var(--text);
  padding-bottom: 7px; border-bottom: 1px solid var(--border);
}
.md h2:first-child { margin-top: 6px; }
.md h3 { font-size: 14px; margin: 18px 0 6px; color: var(--text); }
.md p { margin: 9px 0; }
.md ul { margin: 8px 0 8px 22px; }
.md li { margin: 5px 0; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.md pre { background: var(--bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }
.md strong { color: var(--text); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.md blockquote {
  margin: 12px 0; padding: 10px 16px; border-left: 3px solid var(--accent-soft);
  background: var(--bg); border-radius: 0 8px 8px 0; color: var(--muted); font-size: 13px;
}
.md table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.md th, .md td { border-bottom: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.md table tr:first-child td { color: var(--muted); font-weight: 600; background: var(--bg); }

/* ---------- AI 任务进度条（不确定进度） ---------- */
.progress { height: 5px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; margin: 0 0 8px; }
.progress > i {
  display: block; height: 100%; width: 34%; background: var(--accent);
  animation: wa-slide 1.2s ease-in-out infinite;
}
@keyframes wa-slide {
  0%   { margin-left: -34%; }
  100% { margin-left: 100%; }
}

/* ---------- AI 可见度评分与问题项 ---------- */
.score-big { font-size: 38px; font-weight: 700; letter-spacing: -1px; line-height: 1.2; }
.score-ok { color: var(--ok); }
.score-warn { color: var(--warn); }
.score-bad { color: var(--danger); }

.issue { border-left: 3px solid var(--border); padding: 4px 0 4px 13px; margin: 12px 0; }
.issue.danger { border-color: var(--danger); }
.issue.warn { border-color: var(--warn); }
.issue.info { border-color: var(--accent); }
.issue .t { font-weight: 600; font-size: 13.5px; color: var(--text); }
.issue .d { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.75; }
.issue .f { font-size: 12.5px; color: var(--accent); margin-top: 5px; line-height: 1.75; }

/* ---------- 折叠块 ---------- */
details.acc { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
details.acc > summary { cursor: pointer; padding: 10px 14px; font-size: 13px; line-height: 1.7; }
details.acc > summary:hover { background: var(--bg); }
details.acc[open] > summary { border-bottom: 1px solid var(--border); }
details.acc > div { padding: 12px 14px; font-size: 13px; }

@media (max-width: 760px) {
  .score-big { font-size: 30px; }
  .md table { font-size: 12px; }
}
