:root {
  --bg: #f4f6f7;
  --card: #ffffff;
  --line: #e3e7ea;
  --line-soft: #eef1f3;
  --text: #1a2226;
  --dim: #6a757e;
  --faint: #949ea7;
  --accent: #0d6e74;
  --accent-soft: #e7f2f2;
  --narrow: #14714a;
  --narrow-bg: #e3f3ea;
  --wide: #a1470f;
  --wide-bg: #fbeade;
  --mid: #5d6871;
  --mid-bg: #eef1f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161a;
    --card: #1a1f24;
    --line: #2a3138;
    --line-soft: #232930;
    --text: #e5e9ec;
    --dim: #8e99a3;
    --faint: #6f7a84;
    --accent: #4ec3ca;
    --accent-soft: #14312f;
    --narrow: #5ad19b;
    --narrow-bg: #16311f;
    --wide: #e8a06a;
    --wide-bg: #34220f;
    --mid: #9aa4ae;
    --mid-bg: #242a30;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 20px 32px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Pretendard", system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
}

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

.logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--dim);
}

.btn-primary {
  padding: 8px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.boot {
  margin: 40px 0;
  text-align: center;
  color: var(--dim);
}

.boot.error {
  color: #c0392b;
}

/* ---------- 레이아웃 ---------- */

/* 세로 스크롤은 표 카드 안쪽 하나뿐이다. 나머지는 전부 페이지 스크롤을 따른다. */
.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.main {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.content:has(.detail:not([hidden])) {
  grid-template-columns: minmax(0, 1fr) 330px;
}

@media (max-width: 1180px) {
  .layout,
  .content,
  .content:has(.detail:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- 필터 ---------- */

.filters {
  padding: 16px 14px;
}

.panel-title {
  margin: 0 0 14px;
  padding-left: 8px;
  border-left: 3px solid var(--accent);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}

.group {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.group:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.group-label {
  display: block;
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.note {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--faint);
}

.filters input,
.filters select,
.searchbar input,
.searchbar select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font: inherit;
}

.filters input:focus,
.filters select:focus,
.searchbar input:focus,
.searchbar select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.check-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.check-list label:hover {
  background: var(--mid-bg);
}

.check-list input {
  width: 14px;
  height: 14px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
}

.check-list .name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-list .tally {
  flex: none;
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.check-list .all-row {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line-soft);
}

.check-list label:has(input:checked) {
  background: var(--accent-soft);
}

.check-list label:has(input:checked) .name {
  font-weight: 600;
  color: var(--accent);
}

/* ---------- 검색 바 ---------- */

.searchbar {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1.1fr;
  gap: 12px;
  padding: 12px 14px;
}

@media (max-width: 780px) {
  .searchbar {
    grid-template-columns: 1fr 1fr;
  }
}

.sfield label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
}

/* ---------- 결과 ---------- */

/* 표 카드를 화면 높이에 맞춰 잘라 페이저가 항상 첫 화면에 보이게 한다.
   빼는 값은 상단 바 + 검색 바 + 간격의 합이다. */
.results {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: calc(100vh - 200px);
  overflow: hidden;
}

.summary {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}

.summary .stat b {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary .stat span {
  margin-left: 5px;
  font-size: 12px;
  color: var(--dim);
}

.summary .stat + .stat {
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

/* 페이지 안에서 세로로 스크롤되는 유일한 영역. 페이저는 이 바깥에 있어
   80행짜리 목록에서도 '다음' 버튼이 항상 보인다. */
.table-scroll {
  flex: 1;
  min-height: 260px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}

thead th span {
  display: block;
  font-weight: 400;
  color: var(--faint);
  font-size: 10px;
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--mid-bg);
}

tbody tr.selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.empty td {
  padding: 40px 12px;
  text-align: center;
  color: var(--dim);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.uni {
  font-weight: 600;
}

.sub {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--faint);
}

.cut-main {
  font-size: 14px;
  font-weight: 700;
}

.cut-hist {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--faint);
}

.track {
  display: inline-block;
  margin-right: 5px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--mid-bg);
  color: var(--mid);
  font-size: 10px;
  font-weight: 600;
  vertical-align: 1px;
}

.track.comprehensive {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- 분포 폭 ---------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--mid-bg);
  color: var(--mid);
  font-size: 11px;
  font-weight: 600;
}

.badge.narrow {
  background: var(--narrow-bg);
  color: var(--narrow);
}

.badge.wide {
  background: var(--wide-bg);
  color: var(--wide);
}

.badge.insufficient,
.badge.none {
  padding-left: 0;
  background: transparent;
  color: var(--faint);
  font-weight: 400;
}

.spread-num {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- 페이저 ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.pager-buttons {
  display: flex;
  gap: 8px;
}

.pager button {
  padding: 6px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.pager button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- 상세 ---------- */

.detail {
  position: sticky;
  top: 14px;
  padding: 16px;
}

.detail h2 {
  margin: 0 26px 3px 0;
  font-size: 16px;
  line-height: 1.35;
}

.detail h3 {
  margin: 18px 0 7px;
  padding-left: 7px;
  border-left: 3px solid var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.detail p {
  margin: 7px 0;
  font-size: 13px;
  line-height: 1.6;
}

.detail-sub {
  margin: 0 0 4px !important;
  color: var(--dim);
  font-size: 12px !important;
}

.detail-scroll {
  overflow-x: auto;
}

.detail-table {
  font-size: 12px;
}

.detail-table th,
.detail-table td {
  padding: 6px 7px;
  white-space: nowrap;
}

.detail-table thead th {
  position: static;
  padding: 6px 7px;
  background: var(--mid-bg);
}

.detail-table th[scope="row"] {
  text-align: left;
  font-weight: 600;
}

.detail-table .strong {
  font-weight: 700;
}

.detail .dim {
  color: var(--dim);
}

.detail .small {
  font-size: 11px !important;
  line-height: 1.5;
}

.detail .close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.detail .close:hover {
  background: var(--mid-bg);
}
