@font-face {
  font-family: "Pretendard Variable";
  src: url("vendor/PretendardVariable.subset.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: optional;
}

:root {
  --font: "Pretendard Variable", Pretendard, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  --radius: 14px;
  --radius-sm: 9px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="dark"] {
  --bg: #0b0f1a;
  --bg-grad-1: #131b30;
  --bg-grad-2: #0b0f1a;
  --surface: #141a29;
  --surface-2: #1a2135;
  --surface-3: #212a41;
  --line: #263049;
  --line-soft: #1d2537;
  --text: #e8ecf5;
  --text-dim: #9aa6bf;
  --text-faint: #8b96b0;
  --accent: #6c8cff;
  --accent-strong: #3f63e8;
  --accent-soft: rgba(108, 140, 255, 0.14);
  --accent-2: #38d6c4;
  --good: #3ddc97;
  --bad: #ff6b81;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
  --grid: rgba(255, 255, 255, 0.07);
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-grad-1: #ffffff;
  --bg-grad-2: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-3: #eef2fa;
  --line: #dde3ef;
  --line-soft: #e8edf6;
  --text: #161c2b;
  --text-dim: #5c6885;
  --text-faint: #626d87;
  --accent: #3f63e8;
  --accent-strong: #3f63e8;
  --accent-soft: rgba(63, 99, 232, 0.1);
  --accent-2: #12a89a;
  --good: #098262;
  --bad: #cf3656;
  --shadow: 0 10px 26px rgba(24, 39, 75, 0.09);
  --grid: rgba(0, 0, 0, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1100px 620px at 78% -8%, var(--bg-grad-1) 0%, transparent 62%),
    linear-gradient(180deg, var(--bg-grad-2), var(--bg));
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.025em; }

button, select, input { font-family: inherit; font-size: inherit; color: inherit; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-weight: 800;
  font-size: 19px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px var(--accent-soft);
}

.brand-text h1 { font-size: 17px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}

.seg button:hover { color: var(--text); }

.seg button.on {
  background: var(--accent-strong);
  color: #fff;
  box-shadow: 0 3px 10px var(--accent-soft);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 15px;
  color: var(--text-dim);
  transition: color 0.18s, border-color 0.18s, transform 0.18s var(--ease);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.icon-btn:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }

.layout {
  display: grid;
  grid-template-columns: 306px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 22px 8px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 104px);
}

.side-head { display: flex; align-items: baseline; justify-content: space-between; }
.side-head h2 { font-size: 14px; }
.counter { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.counter b { color: var(--accent); font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }

html.is-loading #yearSeg { min-width: 278px; min-height: 36px; }
html.is-loading #selChips:empty { display: block; min-height: 114px; }
html.is-loading #orgList { min-height: 421px; }
html.is-loading #overviewEmpty { display: none; }
html.is-loading #overviewCards { min-height: 594px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 6px 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-3);
  border: 1px solid var(--line);
  animation: pop 0.22s var(--ease);
}

.chip i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip button {
  min-width: 24px;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1;
}

.chip button:hover { color: var(--bad); }

@keyframes pop { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.field input,
.field-row select,
.toolbar select,
.toolbar input[type="search"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.field input:focus,
.field-row select:focus,
.toolbar select:focus,
.toolbar input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.field-row select { font-size: 12px; padding: 7px 8px; }

.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s, background 0.18s, transform 0.18s var(--ease);
}

.pill:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }
.pill.ghost { background: transparent; }

.org-list {
  flex: 1;
  min-height: 140px;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
}

.org-list::-webkit-scrollbar { width: 8px; }
.org-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.org-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.org-row:hover { background: var(--surface-2); }
.org-row.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 42%, transparent); }
.org-row.disabled,
.org-row:disabled { opacity: 0.4; cursor: not-allowed; }

.org-row i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--line); }
.org-row.on i { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

.org-row .nm {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-row .ty { font-size: 10.5px; color: var(--text-faint); flex: none; }

.side-foot { margin: 0; font-size: 11px; color: var(--text-faint); text-align: right; }

.main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.tabs {
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.tab {
  flex: 1;
  min-width: 74px;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s var(--ease), color 0.2s;
}

.tab:hover { color: var(--text); background: var(--surface-2); }

.tab.active {
  color: #fff;
  background: var(--accent-strong);
  box-shadow: 0 4px 14px var(--accent-soft);
}

.panel { display: none; flex-direction: column; gap: 14px; }
.panel.active { display: flex; animation: fade 0.28s var(--ease); }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.ctl { display: flex; flex-direction: column; gap: 4px; min-width: 168px; flex: 1 1 168px; }
.ctl > span { font-size: 11px; font-weight: 600; color: var(--text-faint); letter-spacing: 0.02em; }
.ctl-label { flex: 1; font-size: 11.5px; color: var(--text-faint); font-weight: 600; }
.toolbar input[type="search"] { flex: 1 1 168px; width: auto; }

.chk { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.chk input {
  width: 16px;
  height: 16px;
  flex: none;
  margin: 0;
  accent-color: var(--accent);
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chart-head { padding: 15px 18px 12px; border-bottom: 1px solid var(--line-soft); }
.chart-head h3 { font-size: 15px; }
.chart-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--text-faint); word-break: keep-all; }

.chart { height: 440px; padding: 6px 8px 10px; }
.chart.tall { height: 528px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 13px; }

.ocard {
  position: relative;
  padding: 15px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fade 0.3s var(--ease) backwards;
}

.ocard::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--c, var(--accent));
}

.ocard h3 { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.02em; }
.ocard .badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 7px 0 12px; }

.badge {
  padding: 2.5px 7px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-dim);
  border: 1px solid var(--line-soft);
}

.kv { display: grid; gap: 9px; }
.kv-row { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 8px; }
.kv-row .k { font-size: 11.5px; color: var(--text-faint); }
.kv-row .v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv-row .v small { font-size: 10.5px; font-weight: 600; color: var(--text-faint); margin-left: 2px; }

.delta { font-size: 10.5px; font-weight: 700; margin-left: 5px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--text-faint); }

.spark { margin-top: 11px; height: 44px; }

.empty {
  padding: 54px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.metric-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 168px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}
.scroll-hint { margin: -2px 14px 10px; color: var(--text-faint); font-size: 11px; }

.mpill {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.16s, background 0.16s, border-color 0.16s;
}

.mpill:hover { color: var(--text); border-color: var(--accent); }
.mpill.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

.table-wrap { padding: 12px 14px 16px; overflow-x: auto; overflow-y: visible; }
.rank-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 14px 14px;
  color: var(--text-faint);
  font-size: 12px;
}
.rank-more[hidden] { display: none; }
.chart-retry { display: block; margin: 18px auto; }

.tbl { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 12.5px; }

.tbl th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: right;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th.sortable { padding: 0; cursor: pointer; user-select: none; }

.sort-btn {
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: right;
  white-space: nowrap;
  cursor: pointer;
}

.tbl th:first-child .sort-btn { text-align: left; }
.sort-btn:hover { color: var(--accent); }

.tbl td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tbl td.table-empty { padding: 28px 14px; text-align: center; color: var(--text-faint); }

.tbl tbody tr { transition: background 0.14s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.hi { background: var(--accent-soft); }
.tbl tbody tr.hi td:first-child { font-weight: 700; }

.tbl .org-cell { display: flex; align-items: center; gap: 8px; }
.tbl .org-cell i { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.org-toggle {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.org-toggle:disabled { opacity: 0.45; cursor: not-allowed; }

.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar-cell .track { width: 78px; height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; flex: none; }
.bar-cell .fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.pct { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 24px 22px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.foot a { color: var(--text-dim); text-decoration: none; border-bottom: 1px solid var(--line); }
.foot a:hover { color: var(--accent); border-color: var(--accent); }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .org-list { max-height: 300px; }
  [data-panel="scatter"] .ctl { flex-basis: 220px; min-width: 220px; }
  .table-wrap::before {
    content: "← 표를 좌우로 스크롤 →";
    position: sticky;
    left: 0;
    display: block;
    width: max-content;
    margin: 0 0 8px;
    color: var(--text-faint);
    font-size: 11px;
  }
  html.is-loading #selChips:empty { min-height: 34px; }
  html.is-loading #orgList { min-height: 300px; }
  html.is-loading #overviewCards { min-height: 898px; }
}

@media (max-width: 767px) {
  :root {
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
  }

  body {
    font-size: 16px;
    background-attachment: scroll;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px;
  }

  .brand,
  .brand-text,
  .topbar-actions {
    min-width: 0;
  }

  .brand-text p { line-height: 1.35; }

  .topbar-actions {
    width: 100%;
    gap: 8px;
  }

  #yearSeg {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    gap: 10px;
  }

  html.is-loading #yearSeg { min-width: 0; min-height: 52px; }
  html.is-loading #selChips:empty { min-height: 114px; }
  html.is-loading #orgList { min-height: 260px; }
  html.is-loading #overviewCards { min-height: 1505px; }

  #yearSeg button {
    flex: 0 0 calc((100% - 30px) / 4);
    min-height: 44px;
    padding-inline: 0;
    scroll-snap-align: start;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    flex: none;
  }

  .layout {
    gap: 12px;
    padding: 12px 12px 4px;
  }

  .sidebar,
  .main,
  .chart-card,
  .table-wrap {
    min-width: 0;
    max-width: 100%;
  }

  .sidebar { padding: 14px; }
  .field-row { grid-template-columns: 1fr; }

  .field input,
  .field-row select,
  .toolbar select,
  .toolbar input[type="search"] {
    min-height: 44px;
    font-size: 16px;
  }

  .org-list { max-height: 260px; }
  .org-row { min-height: 44px; }

  .tabs {
    max-width: 100%;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    gap: 12px;
  }

  .tab {
    flex: 0 0 calc((100% - 12px) / 2);
    min-width: calc((100% - 12px) / 2);
    min-height: 44px;
    padding: 9px 10px;
    font-size: 14px;
    scroll-snap-align: start;
  }

  #yearSeg::-webkit-scrollbar,
  .tabs::-webkit-scrollbar { display: block; height: 4px; }
  #yearSeg::-webkit-scrollbar-thumb,
  .tabs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

  .toolbar {
    align-items: stretch;
    padding: 12px;
  }

  .ctl,
  .ctl-label,
  .toolbar input[type="search"] {
    min-width: 0;
    flex-basis: 100%;
    width: 100%;
  }

  .toolbar > .pill {
    width: 100%;
    min-height: 44px;
  }

  .toolbar .chk {
    width: 100%;
    min-height: 44px;
  }

  .metric-picker { max-height: 148px; }
  [data-panel="scatter"] .ctl { min-width: 0; }
  .card-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-head { padding: 14px 14px 12px; }
  .chart { height: 390px; padding-inline: 2px; }
  .chart.tall { height: 430px; }
  .table-wrap { padding-inline: 10px; }
  .foot { padding: 12px 14px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
