.viz-root {
  color-scheme: light;
  --page: #f6f6f4;
  --surface-1: #ffffff;
  --border: #e4e4e0;
  --grid: #efefef;
  --text-primary: #191919;
  --text-secondary: #666666;
  --accent: #191919;
  --selected: #d6203a;          /* 선발 강조 외곽선 */
  --row-hover: #f5f7fa;
  --row-active: #fdecee;
  --muted-bar: #ececE8;
  /* 군집 색 (data viz 검증 팔레트: CVD 분리 통과) */
  --c0: #257de0;  /* 인기정거장 */
  --c1: #00b894;  /* 주말집중형 */
  --c2: #a35fd1;  /* 퇴근집중형 */
  --c3: #f2a600;  /* 출근집중형 */
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: #f6f6f4;
}
.viz-root {
  min-height: 100vh;
  background: var(--page);
  color: var(--text-primary);
  padding: 28px 32px 20px;
  max-width: 1480px;
  margin: 0 auto;
}
a { color: inherit; }

.page-header { margin-bottom: 18px; }
h1 { font-size: 24px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 4px; }
.sub, .hint { margin: 0; color: var(--text-secondary); }
.sub { font-size: 14px; }
.hint { font-size: 12.5px; }
.muted { color: var(--text-secondary); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  min-width: 0;
  display: flex; flex-direction: column;
}
.card-head { margin-bottom: 12px; }
.card-head.row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }

/* 군집 카드 */
.cluster-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.cluster-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; position: relative;
}
.cluster-card .top { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.cluster-card .name { font-weight: 700; font-size: 15px; }
.cluster-card .count { margin-left: auto; font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.cluster-card .key { font-size: 13px; color: var(--text-secondary); }
.cluster-card .key b { color: var(--text-primary); }
.cluster-card .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; font-size: 12px; }
.cluster-card .stats span { display: block; color: var(--text-secondary); }
.cluster-card .stats strong { font-variant-numeric: tabular-nums; font-size: 13px; }
.cluster-card .show { position: absolute; top: 12px; right: 14px; font-size: 12px; color: var(--text-secondary); display: none; }

/* 상단 그리드 */
.top-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; margin-bottom: 16px; }

/* 선발 조건 */
.control-card h2 { margin-bottom: 4px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 6px; }
button {
  font: inherit; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  border-radius: 8px; padding: 6px 10px;
}
button:hover { background: #f3f3f0; }
button:focus-visible, input:focus-visible, select:focus-visible, tr:focus-visible { outline: 2px solid #257de0; outline-offset: 2px; }
button.primary { background: var(--text-primary); color: #fff; border-color: var(--text-primary); padding: 9px 18px; font-weight: 600; }
button.primary:hover { background: #333; }
button.primary.pulse { box-shadow: 0 0 0 3px rgba(214, 32, 58, .25); }
button:disabled { opacity: .45; cursor: not-allowed; }

.slider { padding: 12px 0; border-bottom: 1px solid var(--grid); }
.slider:last-child { border-bottom: 0; }
.slider .lab { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 6px; }
.slider .lab .q { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-secondary); }
.slider .lab .q b { color: var(--text-primary); font-size: 14px; }
.slider .row { display: flex; align-items: center; gap: 10px; }
.slider input[type=range] { flex: 1; accent-color: var(--text-primary); }
.slider input[type=number] {
  width: 58px; font: inherit; font-size: 13px; padding: 4px 6px; text-align: right;
  border: 1px solid var(--border); border-radius: 6px; font-variant-numeric: tabular-nums;
}
.slider .warn { font-size: 12px; color: #b4541a; margin-top: 4px; }

.sum-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13.5px; margin: 10px 0 12px; flex-wrap: wrap; }
.sum-row .muted { font-size: 12px; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dirty { font-size: 12.5px; color: var(--selected); }
.dirty[hidden] { display: none; }

/* 지도 */
.map-card { min-height: 620px; }
#map.no-tiles { background: #e3eaf0; }
#map { flex: 1; min-height: 560px; border-radius: 8px; border: 1px solid var(--border); background: #eef0f2; }
.toggle { font-size: 13.5px; display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.sel-swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  border: 2.5px solid var(--selected); vertical-align: -1px; margin-right: 2px;
}
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; font-size: 13px; }
.legend label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.legend .sel { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--text-secondary); }
.legend .sel .ring { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--selected); background: #fff; }

.leaflet-popup-content { font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; margin: 12px 14px; }
.pop .t { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.pop .s { color: var(--text-secondary); font-size: 12px; margin-bottom: 8px; }
.pop .badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; margin-bottom: 6px; }
.pop .picked { color: var(--selected); font-weight: 700; margin-left: 6px; }
.pop table { font-size: 12.5px; border-collapse: collapse; }
.pop td { padding: 1px 0; }
.pop td:first-child { color: var(--text-secondary); padding-right: 14px; }
.pop td:last-child { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* 요약 */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 13px; color: var(--text-secondary); }
.kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.kpi .chips { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; }
.kpi .chips span { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }

.bottom-grid { display: grid; grid-template-columns: minmax(420px, 5fr) 8fr; gap: 16px; align-items: start; }

.table-wrap { overflow: auto; max-height: 620px; }
.table-wrap.tall { max-height: 620px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-1);
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--text-secondary);
  padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text-primary); }
thead th .arrow { font-size: 10px; margin-left: 3px; }
th.num, td.num { text-align: right; }
tbody td { padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.active { background: var(--row-active); }
tbody tr.zero td { color: var(--text-secondary); }
tfoot td { padding: 9px 8px; font-weight: 700; border-top: 1px solid var(--text-primary); position: sticky; bottom: 0; background: var(--surface-1); }
td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.bar-col { width: 34%; }
.stack { display: flex; height: 10px; gap: 2px; }
.stack i { display: block; height: 100%; }
.stack i:first-child { border-radius: 2px 0 0 2px; }
.stack i:last-child { border-radius: 0 3px 3px 0; }
.cl { display: inline-flex; align-items: center; gap: 6px; }

.table-tools { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.table-tools select { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.foot { margin-top: 18px; font-size: 12px; color: var(--text-secondary); }

@media (max-width: 1100px) {
  .top-grid, .bottom-grid { grid-template-columns: 1fr; }
  .cluster-cards, .kpis { grid-template-columns: repeat(2, 1fr); }
  .viz-root { padding: 20px 14px; }
}
