:root {
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --border: #e6e5e0;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a8985;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --up: #0ca30c;
  --down: #e34948;
  --grid: #e6e5e0;
  --tab-active: #0b0b0b;
  --chip-normal: #52514e;
  --chip-opportunity: #2a78d6;
  --chip-warning: #eb6834;
  --radius: 12px;
  --font: "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --surface: #1a1a19;
    --border: #2c2c2a;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8a8985;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --grid: #2c2c2a;
    --tab-active: #ffffff;
    --chip-normal: #c3c2b7;
    --chip-opportunity: #3987e5;
    --chip-warning: #d95926;
  }
}
:root[data-theme="dark"] {
  --bg: #121211;
  --surface: #1a1a19;
  --border: #2c2c2a;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #8a8985;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --grid: #2c2c2a;
  --tab-active: #ffffff;
  --chip-normal: #c3c2b7;
  --chip-opportunity: #3987e5;
  --chip-warning: #d95926;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  padding: 0 16px 40px;
}

.header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }
.controls { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; }
select, button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--text-3); }

main { max-width: 1200px; margin: 0 auto; }

/* 테마 전환 */
.theme { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.theme button { border: 0; border-radius: 0; background: transparent; color: var(--text-2); font-size: 13px; padding: 6px 12px; }
.theme button + button { border-left: 1px solid var(--border); }
.theme button:hover { color: var(--text); }
.theme button[aria-pressed="true"] { color: var(--text); font-weight: 700; background: color-mix(in srgb, var(--text) 10%, var(--surface)); }
.theme button:focus-visible { outline: 2px solid var(--s1); outline-offset: -2px; }

/* 알림 배너 */
.alerts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.alerts:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%;
  padding: 8px 12px; border-radius: 999px; font-size: 13px; line-height: 1.3;
  border: 1px solid var(--chip-normal);
  background: color-mix(in srgb, var(--chip-normal) 10%, var(--surface));
}
.chip-opportunity { border-color: var(--chip-opportunity); background: color-mix(in srgb, var(--chip-opportunity) 10%, var(--surface)); }
.chip-warning { border-color: var(--chip-warning); background: color-mix(in srgb, var(--chip-warning) 10%, var(--surface)); }
.chip-icon {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--surface); background: var(--chip-normal);
}
.chip-opportunity .chip-icon { background: var(--chip-opportunity); }
.chip-warning .chip-icon { background: var(--chip-warning); }
.chip-body { display: flex; flex-direction: column; min-width: 0; color: var(--text); }
.chip-body b { font-weight: 700; }
.chip-body span { color: var(--text-2); }
.chip-link { flex: 0 0 auto; border: 0; border-radius: 0; background: transparent; padding: 0 2px; color: var(--text); font-size: 13px; font-weight: 700; text-decoration: underline; cursor: pointer; }
.chip-link:hover { color: var(--text-2); }
.chip-link:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }
.chip-basis { flex: 0 0 auto; color: var(--text-3); font-size: 12px; margin-left: 4px; }

/* 요약 줄, 보조 제목, 범례 */
.sum-line { margin: 0 0 12px; color: var(--text-2); font-size: 14px; }
.sub-h { margin: 12px 0 2px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.chart.chart-sm { height: 170px; }
.chart.chart-xs { height: 84px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { display: inline-block; }

.chart.chart-md { height: 200px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.grid3 .card.wide { grid-column: 1 / -1; }

/* 코호트 히트맵: 셀 배경은 --s1 한 색의 농도 5단계 */
.heatmap { border-collapse: separate; border-spacing: 2px; font-size: 13px; }
.heatmap th, .heatmap td { border-bottom: 0; padding: 7px 8px; text-align: center; min-width: 52px; }
.heatmap th.row-head, .heatmap td.row-head { text-align: left; font-weight: 600; color: var(--text); white-space: nowrap; }
.heatmap td.num { color: var(--text-2); }
.heatmap td.heat { color: var(--text); background: color-mix(in srgb, var(--s1) var(--p), var(--surface)); border-radius: 4px; font-variant-numeric: tabular-nums; }
.heatmap td.base { color: var(--text-2); background: transparent; border: 1px solid var(--border); border-radius: 4px; }
.heatmap td.empty { background: var(--surface); }
.heatmap .h1 { --p: 10%; } .heatmap .h2 { --p: 24%; } .heatmap .h3 { --p: 40%; } .heatmap .h4 { --p: 58%; } .heatmap .h5 { --p: 76%; }
.heatmap tr.boundary td { color: var(--text-3); }
.heatmap tr.boundary td.heat { background: color-mix(in srgb, var(--s1) calc(var(--p) * 0.5), var(--surface)); }
.heatmap .badge { margin-left: 6px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-3); }
.heat-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.heat-legend .sw { display: inline-flex; align-items: center; gap: 6px; }
.heat-legend .box { width: 18px; height: 14px; border-radius: 3px; background: color-mix(in srgb, var(--s1) var(--p), var(--surface)); display: inline-block; }
.heat-legend .note { color: var(--text-3); }

/* 목표 계산기 */
.calc { display: grid; gap: 8px; margin: 4px 0 12px; }
.calc label { font-size: 14px; color: var(--text-2); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.calc output { font-size: 20px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.calc input[type="range"] { width: 100%; accent-color: var(--s1); }
.calc-result { margin: 0; font-size: 15px; color: var(--text); }
.calc-result b { font-variant-numeric: tabular-nums; }

.bar-table td.wrap { white-space: normal; text-align: left; min-width: 260px; color: var(--text-2); font-size: 13px; }

/* 판정 표시: 색이 아니라 글자와 테두리로 구분 */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--text-3); font-size: 12px; font-weight: 700; color: var(--text); white-space: nowrap; }
.pill.rejected { border-style: dashed; color: var(--text-2); }
.pill.likely { border-width: 2px; }
.bar-table td.wrap.strong { color: var(--text); }

/* 셀 안 막대 표 */
.bar-table td.name, .bar-table th.name { text-align: left; }
.bcell { position: relative; display: flex; align-items: center; justify-content: flex-end; min-width: 110px; height: 26px; }
.bcell .fill { position: absolute; left: 0; top: 2px; bottom: 2px; border-radius: 3px; background: color-mix(in srgb, var(--s1) 30%, var(--surface)); }
.bcell .v { position: relative; padding: 0 6px; color: var(--text); font-variant-numeric: tabular-nums; }
.bar-table td.rank { text-align: center; color: var(--text-3); width: 44px; }

/* 월별 차트 필터 */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 4px 0 12px; }
.filters label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.filters select { font-size: 13px; padding: 6px 8px; }
.filters-note { margin: 0; font-size: 13px; color: var(--text-3); flex: 1 1 260px; }
.tag {
  display: inline-block; vertical-align: 2px; margin-left: 6px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  background: color-mix(in srgb, var(--s1) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--s1) 30%, var(--border));
}
.tag-fixed { background: transparent; border-color: var(--border); color: var(--text-3); }

/* 탭 */
.tabs {
  display: flex; gap: 4px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: 0; border-radius: 0; background: transparent;
  padding: 10px 14px; font-size: 14px; font-weight: 600; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); border-color: transparent; }
.tab[aria-selected="true"] { color: var(--tab-active); border-bottom-color: var(--tab-active); }
.tab:focus-visible { outline: 2px solid var(--s1); outline-offset: -2px; }
.panel[hidden] { display: none; }
.placeholder { padding: 32px 18px; }

.kpis { display: grid; gap: 12px; margin-bottom: 12px; }
.kpis-main { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis-lead { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.kpi .label { color: var(--text-2); font-size: 13px; margin: 0 0 6px; }
.kpi .value { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .delta { margin: 6px 0 0; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi .delta b { font-weight: 600; }
.kpi .delta.up b { color: var(--up); }
.kpi .delta.down b { color: var(--down); }
.kpi .delta.flat b { color: var(--text-2); }
.kpi .spark { display: block; width: 100%; height: 28px; margin-top: 8px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card h2 { font-size: 16px; margin: 0; font-weight: 700; }
.hint { margin: 2px 0 10px; color: var(--text-3); font-size: 13px; }
.chart { position: relative; height: 240px; }
.card.wide .chart { height: 260px; }

.table-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-2); font-weight: 600; font-size: 13px; }
tbody tr:hover { background: color-mix(in srgb, var(--s1) 8%, transparent); }
td.muted { color: var(--text-3); }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }

/* 기간 비교 */
.compare { margin-bottom: 12px; }
.compare-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px; font-size: 13px;
  color: var(--text-2); background: var(--surface); border: 1px solid var(--border);
}
.toggle[aria-pressed="true"] { color: var(--text); border-color: var(--text-3); background: color-mix(in srgb, var(--text) 5%, var(--surface)); }
.toggle[aria-pressed="false"] { opacity: 0.6; }
.toggle[aria-pressed="false"] .dot { background: var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.p12 { background: var(--s1); }
.dot.p6 { background: var(--s2); }
.dot.p3 { background: var(--s3); }
.compare-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.compare-item { min-width: 0; }
.compare-item h3 { font-size: 13px; color: var(--text-2); font-weight: 600; margin: 0 0 4px; }
.compare-item .chart { height: 190px; }
.compare-empty { color: var(--text-3); font-size: 14px; padding: 24px 0; text-align: center; grid-column: 1 / -1; }

.foot { color: var(--text-3); font-size: 12px; margin-top: 16px; }
.foot p { margin: 4px 0; }

@media (max-width: 900px) {
  .kpis-main, .kpis-lead { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .kpis-main, .kpis-lead { grid-template-columns: 1fr; }
  .chip { border-radius: 14px; flex-wrap: wrap; }
  .compare-grid { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
}
