:root {
  --blue: #2563eb;
  --orange: #f59e0b;
  --line: #e2e8f0;
  --ink: #1e293b;
  --muted: #64748b;
  --bg: #f1f5f9;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
}
header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 20px 32px;
}
header h1 { margin: 0; font-size: 20px; font-weight: 700; }
header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
main { max-width: 1400px; margin: 0 auto; padding: 24px 32px 64px; }
section {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 22px 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
section h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 700;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--ink);
  display: flex; align-items: center; gap: 8px;
}
section h2 .badge {
  background: var(--ink); color: #fff; font-size: 11px;
  border-radius: 5px; padding: 2px 8px; font-weight: 600;
}
.chart-wrap { position: relative; height: 340px; margin-bottom: 8px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: right;
  white-space: nowrap;
}
thead th {
  background: #f8fafc;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  position: sticky; top: 0;
}
/* 첫 컬럼 고정 — 가로 스크롤 시 채널명/지표명이 따라온다(섹션 1~5).
   매트릭스 섹션(8~11)의 .rowhead와 같은 정책. */
th.metric, td.metric {
  text-align: left; font-weight: 600; background: #f8fafc;
  position: sticky; left: 0; z-index: 1;
}
thead th.metric { z-index: 2; }               /* 헤더 행의 첫 칸은 세로·가로 양쪽 고정이라 더 위 */

/* 그룹 헤더(공식몰·쿠팡·오픈마켓·기타)는 colspan 셀이라 셀 자체엔 sticky가 안 먹는다
   (표 폭 전체를 차지해 고정할 여지가 없음) → 안쪽 <span>을 고정해 라벨만 붙들어 둔다. */
tr.group-head td > span {
  position: sticky; left: 10px;   /* = 셀 좌측 패딩(th,td: 7px 10px). td.metric의 글자와 세로로 정렬된다 */
  display: inline-block; padding-right: 8px;
}
.rate { color: #dc2626; font-weight: 600; }

/* 이익률 히트맵(섹션 5) — 배경이 신호를 담당하므로 글씨는 검정 일반.
   .rate(빨간 볼드)를 덮어쓴다. 발산형: 0% 기준 음수=빨강, 양수=초록. */
td.rate-heat { color: #0f172a; font-weight: 400; position: relative; }
tr.total-row td.rate-heat { font-weight: 700; }
/* 섹션 2/3 그룹 헤더 */
tr.group-head td {
  background: #eef2ff; font-weight: 700; text-align: left; color: #3730a3;
}
tr.total-row td { background: #fef9c3; font-weight: 700; }
tr.total-row td.metric { background: #fde68a; }
tbody tr:hover td:not(.metric) { background: #f8fafc; }
tr.total-row:hover td { background: #fef08a; }

/* KPI 스트립 */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.kpi .k-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .k-value { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.kpi .k-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* 매트릭스: 좌측 상품명 고정 + 히트맵 셀 */
table.matrix td.rowhead, table.matrix th.rowhead {
  text-align: left; font-weight: 600; background: #f8fafc;
  position: sticky; left: 0; z-index: 1; min-width: 170px; max-width: 170px;
  overflow: hidden; text-overflow: ellipsis;
}
table.matrix thead th.rowhead { z-index: 2; }
.heat { position: relative; }
.muted-zero { color: #cbd5e1; }

/* 섹션 1 요약표 — 금액/비율 덩어리와 수량 덩어리를 시각적으로 가른다.
   (판매총액~ROAS = 손익 지표 / 옵션주문수량~상품 1개당 판매액 = 수량 지표) */
tr.group-sep td { border-top: 2px solid #cbd5e1; }
/* 섹션 4 미니바 */
.barcell { position: relative; min-width: 150px; }
.barcell .bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(37,99,235,.12); border-right: 2px solid rgba(37,99,235,.4);
}
.barcell .bar-val { position: relative; padding-right: 4px; }
td.pos { color: #16a34a; } td.neg { color: #dc2626; }
.legend { font-size: 11px; color: var(--muted); margin: 0 0 12px; display: flex; gap: 6px; align-items: center; }
.legend .swatch { width: 70px; height: 12px; border-radius: 3px; border: 1px solid var(--line); }

/* 필터 바 (대·중분류) */
.filter-bar{display:flex;gap:8px;margin:12px 0}
.filter-bar a{padding:6px 14px;border:1px solid var(--line,#ddd);border-radius:6px;text-decoration:none;color:inherit}
.filter-bar a.on{background:#2563eb;color:#fff;border-color:#2563eb}
.filter-bar.sub a{font-size:13px;padding:4px 10px}
.warn{background:#fef3c7;border:1px solid #f59e0b;padding:10px;border-radius:6px}
.empty{padding:40px;text-align:center;color:var(--muted,#888)}

/* 음수 금액(적자·환불) 강조 — 채널표(섹션 2~4) 셀. 히트맵 적자색(#dc2626)과 동일 계열. */
td.neg { color: #dc2626; }
