:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  --critical: #d03b3b;
  --warning-ink: #9a6400;
  --other: #b4b2a9;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;

  --seq-0: #f0efec;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;

  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --critical: #e66767;
    --warning-ink: #fab219;
    --other: #5f5e59;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --seq-0: #232322;
    --seq-1: #104281;
    --seq-2: #184f95;
    --seq-3: #1c5cab;
    --seq-4: #256abf;
    --seq-5: #2a78d6;
    --seq-6: #5598e7;
    --seq-7: #86b6ef;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5;
  --good: #0ca30c;
  --bad: #e66767;
  --critical: #e66767;
  --warning-ink: #fab219;
  --other: #5f5e59;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --seq-0: #232322;
  --seq-1: #104281;
  --seq-2: #184f95;
  --seq-3: #1c5cab;
  --seq-4: #256abf;
  --seq-5: #2a78d6;
  --seq-6: #5598e7;
  --seq-7: #86b6ef;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 18px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }

/* ---------- 상단 ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--page);
}

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 2px; }
.field span { font-size: 12px; color: var(--muted); }

select, input[type="date"], .btn {
  font: inherit;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.btn { cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn-sm { height: 28px; font-size: 12px; padding: 0 10px; }

/* ---------- 탭 ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}

.tab {
  flex: none;
  font: inherit;
  padding: 12px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); font-weight: 650; border-bottom-color: var(--accent); }

/* ---------- 본문 ---------- */

.content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: opacity .15s;
}

.content.loading { opacity: .45; pointer-events: none; }

.status { color: var(--text-2); padding: 40px 0; text-align: center; }

.error-box {
  padding: 16px 18px;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  background: var(--surface);
}
.error-box strong { color: var(--bad); }
.error-box p { margin: 6px 0 0; color: var(--text-2); }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}
.page-head .sub { color: var(--text-2); font-size: 13px; }
.page-head .sub a { margin-left: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 12px;
}
.card-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.foot { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- KPI ---------- */

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi .label { font-size: 13px; color: var(--text-2); }
.kpi .value { font-size: 26px; font-weight: 650; margin: 2px 0; letter-spacing: -0.01em; }
.kpi .cmp { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; }

.delta { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.delta.flat { color: var(--muted); font-weight: 400; }

.kpis.secondary { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpis.secondary .kpi { padding: 10px 14px; }
.kpis.secondary .value { font-size: 18px; }
.kpi .label[data-tip] { cursor: help; text-decoration: underline dotted var(--axis); text-underline-offset: 3px; }
.kpi .note { font-size: 12px; color: var(--muted); }

/* ---------- 상태 표시 (아이콘 + 라벨, 색만으로 구분하지 않음) ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 10px;
  line-height: 16px;
  font-weight: 600;
  white-space: nowrap;
  background: color-mix(in srgb, currentColor 10%, transparent);
  vertical-align: 1px;
  margin-left: 2px;
}
.chip::before { font-size: 7px; }
.chip-critical { color: var(--critical); }
.chip-critical::before { content: "■"; }
.chip-warning { color: var(--warning-ink); }
.chip-warning::before { content: "▲"; }
.chip-info { color: var(--text-2); }
.chip-info::before { content: "●"; }
.chip-ok { color: var(--good); }
.chip-ok::before { content: "✓"; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.checks li { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 2px 8px; align-items: baseline; }
.checks .why { grid-column: 2; }
.checks .site { font-weight: 600; }
.checks .why { color: var(--text-2); font-size: 13px; }

.notice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.notice div { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.notice p { margin: 0; color: var(--text-2); font-size: 13px; flex: 1 1 300px; }

/* ---------- 세그먼트 컨트롤 ---------- */

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border: 0;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--hover); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--surface); }
.seg button:disabled { color: var(--muted); opacity: .5; cursor: not-allowed; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; }

.chart-box { position: relative; height: 300px; }

/* ---------- 표 ---------- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: middle; }
th { font-weight: 600; font-size: 12px; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--hover); }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 650; border-bottom: 0; }

.cell-main { max-width: 420px; }
.cell-main .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-main .s { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rank { color: var(--muted); width: 28px; font-variant-numeric: tabular-nums; }

.barcell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; min-width: 140px; }
.barcell .bar { flex: 1; height: 8px; border-radius: 0 4px 4px 0; background: var(--grid); overflow: hidden; max-width: 120px; }
.barcell .bar i { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.err { color: var(--bad); font-size: 12px; }

/* ---------- 100% 누적 막대 ---------- */

.stack-block + .stack-block { margin-top: 18px; }
.stack-title { font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

.stack { display: flex; gap: 2px; height: 22px; }
.stack span { min-width: 2px; height: 100%; }
.stack span:first-child { border-radius: 4px 0 0 4px; }
.stack span:last-child { border-radius: 0 4px 4px 0; }
.stack span:only-child { border-radius: 4px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 12px; color: var(--text-2); }
.legend b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.stack-rows { display: grid; grid-template-columns: minmax(90px, 160px) 1fr; gap: 10px 12px; align-items: center; }
.stack-rows .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 히트맵 ---------- */

.heatmap { display: grid; grid-template-columns: 28px repeat(24, minmax(14px, 1fr)); gap: 2px; min-width: 520px; }
.heatmap .hl { font-size: 11px; color: var(--muted); text-align: center; }
.heatmap .dl { font-size: 12px; color: var(--text-2); display: flex; align-items: center; }
.heatmap .c { aspect-ratio: 1.6; border-radius: 3px; background: var(--seq-0); }

.ramp { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.ramp i { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- 툴팁 ---------- */

.tip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-line;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}

/* ---------- 로그인 ---------- */

.login { max-width: 360px; width: 100%; margin: 40px auto; display: flex; flex-direction: column; gap: 12px; }
.login .field input { width: 100%; font: inherit; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.btn.primary { background: var(--text); color: var(--surface); border-color: var(--text); height: 38px; }
.btn.primary:hover { opacity: .9; background: var(--text); }
.btn:disabled { opacity: .5; cursor: wait; }

/* ---------- 반응형 ---------- */

@media (max-width: 1000px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .tabs { padding: 0 8px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 21px; }
  .filters { width: 100%; }
  .field { flex: 1 1 40%; }
  .field select, .field input { width: 100%; }
  .chart-box { height: 240px; }
  .stack-rows { grid-template-columns: 80px 1fr; }
  .checks li { grid-template-columns: minmax(0, 1fr); }
  .checks .why { grid-column: 1; }
}
