/* K-Defense 관리자 — 색은 역할 이름(토큰)으로만 쓴다. 차트 색은 dataviz 기본 팔레트(검증 통과). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --neg: #e34948;
  --gray: #b9b8b0;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;
  --radius: 10px;
  --font: 'Pretendard Variable', Pretendard, system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --neg: #e66767;
    --gray: #5c5b56;
    --good-ink: #0ca30c;
    --seq-1: #104281;
    --seq-2: #184f95;
    --seq-3: #1c5cab;
    --seq-4: #256abf;
    --seq-5: #3987e5;
    --seq-6: #6da7ec;
    --seq-7: #9ec5f4;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --ring: rgba(255, 255, 255, 0.1);
  --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --neg: #e66767;
  --gray: #5c5b56;
  --good-ink: #0ca30c;
  --seq-1: #104281;
  --seq-2: #184f95;
  --seq-3: #1c5cab;
  --seq-4: #256abf;
  --seq-5: #3987e5;
  --seq-6: #6da7ec;
  --seq-7: #9ec5f4;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  font-feature-settings: 'ss06';
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── 머리줄 ───────────────────────────────────────────── */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--ring);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; }
.brand b { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  border: 1px solid var(--ring);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}
.controls { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0;
  background: none;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring), 0 1px 2px rgba(0, 0, 0, 0.06); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 32px; height: 18px; border-radius: 999px; background: var(--baseline); position: relative; margin: 0; cursor: pointer; transition: background 0.15s; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.btn {
  border: 1px solid var(--ring);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.ghost { border-color: transparent; background: none; color: var(--ink-2); }
.updated { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── 본문 배치 ───────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 188px minmax(0, 1fr); gap: 28px; padding: 20px 24px 64px; max-width: 1560px; margin: 0 auto; }
.nav { position: sticky; top: 72px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; font-size: 13px; font-weight: 500; text-decoration: none; }
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a[aria-current='true'] { background: var(--surface-2); color: var(--ink); font-weight: 650; }
.nav .src { margin-top: 14px; padding: 10px; font-size: 11.5px; color: var(--muted); line-height: 1.55; border-top: 1px solid var(--ring); }
main { min-width: 0; }
section { scroll-margin-top: 72px; margin-bottom: 36px; }
section > header { display: flex; align-items: baseline; gap: 12px; margin: 0 0 12px; flex-wrap: wrap; }
section > header h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.015em; margin: 0; }
section > header p { margin: 0; color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* ── 카드 ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--ring);
  padding: 14px 16px 14px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.card-h { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-h h3 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: -0.005em; }
.card-h .sub { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.card-h .tools { margin-left: auto; display: flex; gap: 4px; flex: none; }
.chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--ring);
  border-radius: 6px;
  padding: 1px 7px;
  background: none;
  cursor: pointer;
}
.chip[aria-pressed='true'] { color: var(--ink); background: var(--surface-2); }
.card-b { position: relative; min-height: 40px; flex: 1; }
.card-f { margin-top: 10px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.card.loading .card-b { opacity: 0.45; transition: opacity 0.2s; }
.empty { color: var(--muted); font-size: 13px; padding: 18px 0; text-align: center; }
.err { color: var(--critical); font-size: 12.5px; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--critical) 8%, transparent); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin: -2px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* 색 열쇠(줄·네모) */
.key { display: inline-block; flex: none; }
.key-line { width: 14px; height: 2px; border-radius: 2px; background: currentColor; }
.key-box { width: 10px; height: 10px; border-radius: 3px; background: currentColor; }
.c-s1 { color: var(--s1); } .c-s2 { color: var(--s2); } .c-s3 { color: var(--s3); } .c-neg { color: var(--neg); } .c-gray { color: var(--gray); }

/* ── 숫자 칸(KPI) ───────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--ring); padding: 12px 14px 10px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; display: flex; gap: 6px; align-items: center; }
.kpi .label .tag { margin-left: auto; font-size: 10.5px; color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
.kpi .value { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.25; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-left: 2px; }
.kpi .delta { font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .spark { margin-top: 4px; height: 28px; }
.up-good, .down-good { color: var(--good-ink); font-weight: 650; }
.up-bad, .down-bad { color: var(--critical); font-weight: 650; }
.flat { color: var(--muted); }
.hero { grid-column: span 2; background: var(--surface); }
.hero .value { font-size: 52px; letter-spacing: -0.035em; line-height: 1.1; }
.hero .spark { height: 44px; }

/* ── 차트 공통 ───────────────────────────────────────── */
svg.chart { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
svg.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.grid-l { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.base-l { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.endlabel { fill: var(--ink); font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.annot { fill: var(--ink-2); font-size: 11.5px; font-weight: 600; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { opacity: 0.1; }
.dot { stroke: var(--surface); stroke-width: 2; }
.cross { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.band-hover { fill: var(--hover); }
.k-s1 { stroke: var(--s1); } .k-s2 { stroke: var(--s2); } .k-s3 { stroke: var(--s3); } .k-neg { stroke: var(--neg); } .k-gray { stroke: var(--gray); }
.f-s1 { fill: var(--s1); } .f-s2 { fill: var(--s2); } .f-s3 { fill: var(--s3); } .f-neg { fill: var(--neg); } .f-gray { fill: var(--gray); }
.bar:hover, .bar.on { filter: brightness(1.12); }

/* 가로 막대 목록 */
.hb { display: flex; flex-direction: column; gap: 7px; }
.hb-row { display: grid; grid-template-columns: minmax(70px, 38%) minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 13px; }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.hb-label small { color: var(--muted); margin-left: 4px; }
.hb-track { height: 10px; position: relative; }
.hb-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; min-width: 2px; }
.hb-val { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 600; font-size: 12.5px; text-align: right; min-width: 3.5em; }
.hb-val small { color: var(--muted); font-weight: 500; margin-left: 4px; }

/* 히트맵 */
.heat { display: grid; gap: 2px; font-size: 11px; }
.heat .cell { border-radius: 3px; min-height: 18px; background: var(--surface-2); }
.heat .rl, .heat .cl { color: var(--muted); font-variant-numeric: tabular-nums; display: flex; align-items: center; }
.heat .cl { justify-content: center; }
.scale { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 8px; }
.scale i { width: 18px; height: 8px; border-radius: 2px; display: inline-block; }
.q0 { background: var(--surface-2) !important; } .q1 { background: var(--seq-1) !important; } .q2 { background: var(--seq-2) !important; }
.q3 { background: var(--seq-3) !important; } .q4 { background: var(--seq-4) !important; } .q5 { background: var(--seq-5) !important; }
.q6 { background: var(--seq-6) !important; } .q7 { background: var(--seq-7) !important; }
.q5, .q6, .q7 { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .q1, :root:not([data-theme='light']) .q2, :root:not([data-theme='light']) .q3, :root:not([data-theme='light']) .q4 { color: #fff; } :root:not([data-theme='light']) .q5, :root:not([data-theme='light']) .q6, :root:not([data-theme='light']) .q7 { color: #0b0b0b; } }
:root[data-theme='dark'] .q1, :root[data-theme='dark'] .q2, :root[data-theme='dark'] .q3, :root[data-theme='dark'] .q4 { color: #fff; }
:root[data-theme='dark'] .q5, :root[data-theme='dark'] .q6, :root[data-theme='dark'] .q7 { color: #0b0b0b; }

/* 표 */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tbody tr:hover td { background: var(--hover); }
.tbl .dim { color: var(--muted); }
.tbl-scroll { max-height: 420px; overflow: auto; }
.cohort td.c { text-align: center; font-variant-numeric: tabular-nums; border-radius: 3px; border: 2px solid var(--surface); padding: 4px 2px; min-width: 40px; }
.cohort td.c.none { background: none; color: transparent; }
.minibar { display: inline-block; height: 6px; border-radius: 0 3px 3px 0; background: var(--s1); vertical-align: middle; margin-right: 6px; }

/* 상태 표시(아이콘 + 글) */
.st { display: inline-flex; align-items: center; gap: 6px; }
.st::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.st.good::before { background: var(--good); }
.st.warning::before { background: var(--warning); }
.st.critical::before { background: var(--critical); }
.st.neutral::before { background: var(--gray); }

/* 숫자 목록(작은 통계 묶음) */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px 16px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 680; letter-spacing: -0.015em; }
.stat .v small { font-size: 12px; color: var(--ink-2); font-weight: 600; margin-left: 2px; }

/* 리뷰 */
.reviews { display: flex; flex-direction: column; gap: 10px; max-height: 330px; overflow: auto; }
.review { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.review .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.review .stars { color: var(--ink); font-weight: 700; letter-spacing: 1px; }
.review p { margin: 0; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

.note { font-size: 12.5px; color: var(--ink-2); line-height: 1.6; }
.note b { color: var(--ink); }
.pill { display: inline-block; font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }

/* 툴팁 */
.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--ring), 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 8px 10px;
  font-size: 12px;
  min-width: 120px;
  max-width: 280px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.08s, transform 0.08s;
}
.tip.on { opacity: 1; transform: none; }
.tip-t { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.tip-r { display: flex; align-items: center; gap: 7px; line-height: 1.7; }
.tip-r b { font-variant-numeric: tabular-nums; font-weight: 700; }
.tip-r .n { color: var(--ink-2); }

/* 로그인 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border-radius: 14px; box-shadow: 0 0 0 1px var(--ring), 0 16px 40px rgba(0, 0, 0, 0.08); padding: 28px 26px 24px; }
.login h1 { font-size: 20px; margin: 14px 0 4px; letter-spacing: -0.02em; }
.login p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 12px 0 6px; }
.login input { width: 100%; border: 1px solid var(--baseline); background: var(--page); border-radius: 8px; padding: 10px 12px; font-size: 15px; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login button { width: 100%; margin-top: 20px; border: 0; border-radius: 8px; padding: 11px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer; }
.login .msg { margin-top: 14px; color: var(--critical); font-size: 13px; }

/* ── 좁은 화면 ───────────────────────────────────────── */
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 48px; gap: 12px; }
  .nav { position: sticky; top: 58px; z-index: 10; flex-direction: row; overflow-x: auto; background: var(--page); padding: 6px 0; margin: 0 -16px; padding-left: 16px; scrollbar-width: none; }
  .nav a { white-space: nowrap; }
  .nav .src { display: none; }
  .span-3, .span-4, .span-5 { grid-column: span 6; }
  .span-7, .span-8 { grid-column: span 12; }
}
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .top { padding: 8px 16px; flex-wrap: wrap; gap: 8px; }
  .controls { margin-left: 0; width: 100%; justify-content: flex-start; }
  .badge, .updated { display: none; }
  .grid { gap: 10px; }
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
  .hero { grid-column: 1 / -1; }
  .hero .value { font-size: 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 22px; }
  .nav { top: 92px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .top, .nav { display: none; } .layout { display: block; } .card, .kpi { break-inside: avoid; } }
