/* 共享外壳样式与组件类。
 *
 * Tailwind 从 CDN 负责页面内部的排版，这份文件只负责两件 Tailwind 做起来
 * 会散开的事：一是外壳（侧栏 / 顶栏 / 横幅）的结构样式，二是十六个页面
 * 反复出现的卡片、表格、徽标、KPI 这几类组件。组件写成语义类而不是每页
 * 抄一串工具类，是因为深色的 BI 组要整体换一套颜色 —— 令牌换一次即可。
 */

:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --surface: #ffffff;
  --ground: #f1f5f9;
  --raise: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --primary: #3b82f6;
  --secondary: #8b5cf6;
  --tertiary: #06b6d4;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  /* 侧边栏：天蓝。压到 sky-700 这一档是为了白字还读得清——
     字面意义的天蓝（#87ceeb）配白字只有 1.74:1，这一档是 5.93:1，过 WCAG AA。
     四个令牌必须一起动：次要文字、选中态原本都是按深蓝黑底配的，
     只换 --sidebar-bg 的话它们会糊在蓝底上。 */
  --sidebar-bg: #0369a1;
  --sidebar-ink: #e0f2fe;
  --sidebar-faint: #a5d8f3;
  --sidebar-active: #075985;
}

/* BI 组沿用图 4 的深色表盘。只换令牌，组件类不动。 */
[data-theme="dark"] {
  --ink: #e2e8f0;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --faint: #64748b;
  --line: rgba(56, 189, 248, .18);
  --surface: #0f1b34;
  --ground: #060d1f;
  --raise: 0 0 0 1px rgba(56, 189, 248, .10), 0 8px 24px rgba(2, 6, 23, .55);
  --primary: #22d3ee;
  --secondary: #a855f7;
  --tertiary: #38bdf8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--ground);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------- 外壳骨架 ---------- */

.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  /* 分隔线改用白色低透明：原来的 slate 14% 是按深蓝黑底调的，压在天蓝上看不见。 */
  border-bottom: 1px solid rgba(255, 255, 255, .20);
}
/* 品牌标：SunShine 的金色 S。
   原来是个蓝紫渐变方块 + 白色线框图标，现在换成 logo 本身，所以底色与阴影都去掉了——
   金色压在深色侧边栏上本来就立得住，再垫一层色块反而像把 logo 装进了别人的容器里。
   logo 已抠成透明底（见 assets/sunshine-logo.png，由 trade/img/sunshine-logo.png 抠出），
   容器不设 background，只留一点 drop-shadow 把金属边缘从深底上托起来。 */
.app-brand-mark {
  width: 44px; height: 44px;
  flex: 0 0 44px;
  display: grid; place-items: center;
}
.app-brand-mark img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  /* 用 drop-shadow 而不是 box-shadow：后者画的是那个 44px 方框的影子，
     而这张图是不规则的 S，方框影子会露在 logo 外面。 */
  filter: drop-shadow(0 2px 5px rgba(3, 40, 62, .38));
}
.app-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.app-brand-text strong { font-size: 14.5px; color: #f8fafc; font-weight: 650; }
.app-brand-text em { font-style: normal; font-size: 11.5px; color: var(--sidebar-faint); margin-top: 1px; }

.app-nav { flex: 1; padding: 12px 10px 18px; }
.app-nav-group + .app-nav-group { margin-top: 18px; }
.app-nav-group-title {
  display: flex; align-items: baseline; gap: 7px;
  padding: 6px 9px 8px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  color: var(--sidebar-faint);
  text-transform: none;
}
.app-nav-group-title i { font-size: 10px; }
.app-nav-group-title em { font-style: normal; font-size: 9.5px; opacity: .65; margin-left: auto; }

.app-nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: 7px;
  font-size: 12.8px;
  color: var(--sidebar-ink);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.app-nav-item i { width: 15px; font-size: 12px; text-align: center; opacity: .75; }
.app-nav-item:hover { background: rgba(255, 255, 255, .13); color: #ffffff; }
.app-nav-item.is-active {
  background: var(--sidebar-active);
  color: #fff;
  /* 左侧那道条原本是 --primary（#3b82f6），压在天蓝底上会浑成一片，
     分不出选中与未选中。改用品牌标那个金色：蓝底上最跳，也和 logo 呼应。 */
  box-shadow: inset 2px 0 0 #fbbf24;
}
.app-nav-item.is-active i { opacity: 1; color: #fbbf24; }

.app-sidebar-foot {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, .20);
  font-size: 10.5px; line-height: 1.5;
  color: var(--sidebar-faint);
}
.app-sidebar-foot i { margin-top: 2px; }
/* 原来的 #93c5fd 在天蓝底上只有 3.29:1，换成 --sidebar-ink 同档并加下划线。 */
.app-sidebar-foot a { color: var(--sidebar-ink); text-decoration: underline; text-underline-offset: 2px; }

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

.app-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-topbar-title h1 { margin: 0; font-size: 19px; font-weight: 680; letter-spacing: -.01em; }
.app-topbar-title p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.app-topbar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }


.app-content { flex: 1; padding: 20px 24px 40px; }

/* ---------- 组件 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--raise);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head h3 {
  margin: 0; font-size: 13.5px; font-weight: 650; letter-spacing: -.005em;
}
.card-head p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.card-body { padding: 16px; }
.card-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

.kpi { padding: 15px 16px; }
.kpi-label { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 0; line-height: 1.1; }
.kpi-value.is-unknown { font-size: 19px; color: var(--faint); font-weight: 600; }
.kpi-note { font-size: 10.8px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

.delta { font-size: 11.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.delta-flat { color: var(--faint); }

.chart-box { position: relative; width: 100%; }
.chart-sm { height: 160px; }
.chart-md { height: 220px; }
.chart-lg { height: 300px; }

table.data { width: 100%; border-collapse: collapse; font-size: 12.2px; }
table.data th {
  text-align: left; font-weight: 600; font-size: 11px;
  color: var(--muted); letter-spacing: .02em;
  padding: 9px 12px;
  background: var(--ground);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--ground) 60%, transparent); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 10.8px; font-weight: 600; white-space: nowrap;
}
.badge-good { background: rgba(16, 185, 129, .12); color: #047857; }
.badge-warn { background: rgba(245, 158, 11, .14); color: #b45309; }
.badge-bad { background: rgba(239, 68, 68, .12); color: #b91c1c; }
.badge-info { background: rgba(59, 130, 246, .12); color: #1d4ed8; }
.badge-muted { background: rgba(100, 116, 139, .12); color: #475569; }
[data-theme="dark"] .badge-good { color: #6ee7b7; }
[data-theme="dark"] .badge-warn { color: #fcd34d; }
[data-theme="dark"] .badge-bad { color: #fca5a5; }
[data-theme="dark"] .badge-info { color: #93c5fd; }
[data-theme="dark"] .badge-muted { color: #cbd5e1; }

.app-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--line);
}
.app-chip-muted { color: var(--muted); background: var(--ground); }
.app-chip-live { color: #047857; background: rgba(16, 185, 129, .1); border-color: rgba(16, 185, 129, .25); }
/* 和上面的 badge-* 同一类问题：深绿字配浅绿底在深色卡片上读不出来。 */
[data-theme="dark"] .app-chip-live { color: #6ee7b7; background: rgba(16, 185, 129, .14); }
[data-theme="dark"] .app-chip-muted { color: var(--muted); background: rgba(148, 163, 184, .08); }

.app-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.app-btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.app-btn-ghost:hover { background: var(--ground); }
.app-btn-primary { background: var(--primary); color: #fff; }
.app-btn-primary:hover { filter: brightness(1.06); }
[data-theme="dark"] .app-btn-primary { color: #04121f; }

.app-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff; font-size: 12px;
}

/* 每页底部的数据来源块。图上每个数字都要么能说出它从哪来，
   要么明说它还没有来源 —— 这是本仓库的既有纪律，不是本页新加的。 */
.provenance {
  margin-top: 22px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 13px 16px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  font-size: 11.4px; line-height: 1.65; color: var(--muted);
}
.provenance h4 {
  margin: 0 0 7px; font-size: 11.5px; font-weight: 650; color: var(--ink-2);
  display: flex; align-items: center; gap: 6px;
}
.provenance ul { margin: 0; padding-left: 17px; }
.provenance li + li { margin-top: 3px; }
.provenance strong { color: var(--ink-2); font-weight: 620; }

.scroll-y { overflow-y: auto; }
.scroll-y::-webkit-scrollbar, .table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.scroll-y::-webkit-scrollbar-thumb, .table-wrap::-webkit-scrollbar-thumb {
  background: var(--faint); border-radius: 4px; opacity: .5;
}
.scroll-y::-webkit-scrollbar-track, .table-wrap::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .app-sidebar { width: 100%; flex: none; height: auto; position: static; }
  .app-nav { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 12px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .app-content { padding: 16px; }
  .app-topbar { padding-left: 16px; padding-right: 16px; }
}
