:root {
  color-scheme: light;
  --page: #f3f7f6;
  --paper: #fff;
  --wash: #f6f9f8;
  --ink: #172d2b;
  --muted: #526863;
  --line: #dce7e3;
  --edge: #bdcfca;
  --accent: #006c61;
  --accent-dark: #00564f;
  --accent-soft: #e5f3ee;
  --royal: #4d438d;
  --diamond: #08756a;
  --gold: #9a5812;
  --general: #546573;
  --corner: 16px;
  --gutter: clamp(14px, 2.2vw, 28px);
  --shadow: 0 4px 8px #183f3510, 0 1px 2px #183f3506;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font-size: 1rem; }
button, input, select, summary { font: inherit; }
button, input, select { color: inherit; }
button, select, summary { cursor: pointer; }
button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
[hidden] { display: none !important; }
.wrap { width: min(1400px, calc(100% - 64px)); margin-inline: auto; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.18; letter-spacing: -.047em; }
h2 { font-size: 1.2rem; letter-spacing: -.03em; }
h3 { font-size: 1.02rem; letter-spacing: -.02em; }

.top { background: var(--paper); border-bottom: 1px solid var(--line); }
.top-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 66px;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: .95rem; font-weight: 750; white-space: nowrap; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-dark);
  color: white;
  font-weight: 800;
  letter-spacing: -.04em;
}
.workspace-tabs { display: flex; align-items: center; gap: 6px; }
.workspace-tabs button {
  min-height: 36px;
  padding: 6px 13px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 650;
  white-space: nowrap;
}
.workspace-tabs button:hover { background: var(--wash); color: var(--ink); }
.workspace-tabs button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-dark); }
.intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px 24px;
  margin: 24px 0 18px;
  padding: 24px var(--gutter);
  border: 1px solid #d5e7df;
  border-radius: var(--corner);
  background: linear-gradient(110deg, #e5f2ed, #f1f7f2 70%, #f9fbf9);
}
#sources {
  padding: 6px 10px;
  border: 1px solid #d5e7df;
  border-radius: 7px;
  background: #fafdface;
  color: var(--accent-dark);
  font-size: .85rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
#sources:empty { display: none; }

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--corner);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.dashboard-layout {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}
.report-content { min-width: 0; }
.report-sidebar {
  position: sticky;
  top: 14px;
  z-index: 2;
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--corner);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.report-sidebar summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 5px;
  border-radius: 6px;
  font-weight: 750;
  list-style: none;
}
.report-sidebar summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 3px;
  transform: rotate(45deg) translateY(-2px);
  border-right: 1.5px solid;
  border-bottom: 1.5px solid;
  color: var(--accent);
}
.report-sidebar details[open] summary::after { transform: rotate(225deg) translate(-1px, -1px); }
.sidebar-controls { padding: 12px 0 3px; }
.sidebar-controls h3 { margin: 0 0 7px; color: var(--muted); font-size: .875rem; font-weight: 700; }
#jump-to-table {
  display: block;
  margin-top: 10px;
  padding: 8px 9px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: .875rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
#jump-to-table:hover { background: #d6ece5; }
.section-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 18px var(--gutter) 14px;
}
.section-top p { margin-top: 5px; color: var(--muted); font-size: .875rem; line-height: 1.5; }
.field { display: grid; gap: 6px; font-size: .875rem; font-weight: 650; }
input:not([type=checkbox]), select {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--paper);
  font-size: .875rem;
  font-weight: 500;
}
input[type=checkbox] { accent-color: var(--accent); }
.plain {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent-dark);
  font-size: .875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.primary, .upload > summary {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  background: var(--accent-dark);
  color: white;
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
}
.primary:hover, .upload > summary:hover { background: var(--accent); border-color: var(--accent); }
.primary:disabled { opacity: .5; cursor: default; }
.status { margin-top: 12px; color: var(--muted); font-size: .875rem; line-height: 1.55; }

.upload { position: relative; justify-self: end; }
.upload > summary, .notes > summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
.upload > summary { display: flex; align-items: center; gap: 10px; }
.upload > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 2px;
  transform: rotate(45deg) translateY(-2px);
  border-right: 1.5px solid;
  border-bottom: 1.5px solid;
}
.upload[open] > summary::after { transform: rotate(225deg) translate(-1px, -1px); }
.upload-panel {
  position: absolute;
  z-index: 5;
  top: calc(100% + 10px);
  right: 0;
  width: min(360px, calc(100vw - 28px));
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 12px 32px #173f3526;
}
.upload-panel label { display: grid; gap: 5px; margin-top: 12px; font-size: .875rem; font-weight: 650; }
.upload-panel p { margin-top: 9px; color: var(--muted); font-size: .875rem; line-height: 1.5; overflow-wrap: anywhere; }
.upload-panel input::file-selector-button {
  margin-right: 8px;
  padding: 3px 7px;
  border: 0;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font: inherit;
}
.templates { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 5px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: .875rem; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { flex: none; width: 9px; height: 9px; border-radius: 3px; }
.grade-0 { background: var(--royal); }
.grade-1 { background: var(--diamond); }
.grade-2 { background: var(--gold); }
.grade-3 { background: var(--general); }

#chart { padding: 0 var(--gutter) 18px; }
.chart-scroll { max-height: 420px; overflow: auto; }
.chart-row, .chart-axis {
  display: grid;
  grid-template-columns: minmax(90px, 132px) minmax(0, 1fr) 85px;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  font-size: .875rem;
}
.chart-row > span:first-child { font-weight: 650; overflow-wrap: anywhere; }
.chart-axis { padding-bottom: 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
.ticks { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.chart-value { text-align: right; font-variant-numeric: tabular-nums; }
.chart-row .chart-value { font-weight: 700; }
.track { display: flex; min-height: 22px; overflow: hidden; border-radius: 5px; background: #edf2f0; }
.segment {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  color: white;
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
}

.table-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 9px 14px; }
.period-row { display: grid; gap: 8px; }
.period-row p { color: var(--muted); font-size: .825rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
.period-form { display: grid; gap: 8px; margin-top: 10px; }
.detail-date { display: grid; gap: 3px; color: var(--muted); font-size: .875rem; font-weight: 650; }
.table-view { display: inline-flex; gap: 3px; padding: 3px; border-radius: 9px; background: #edf3f0; }
.table-view button {
  min-height: 32px;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
}
.table-view button[aria-pressed=true] { border-color: var(--line); background: var(--paper); color: var(--accent-dark); }
.scope-row { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.scope-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.scope-button {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  font-size: .875rem;
  white-space: nowrap;
}
.scope-button:hover { border-color: var(--accent); color: var(--accent-dark); }
.scope-button[aria-pressed=true] { border-color: var(--accent-dark); background: var(--accent-dark); color: white; font-weight: 650; }

.detail-trend .section-top { padding-top: 17px; padding-bottom: 10px; }
#trend { padding: 0 var(--gutter) 10px; }
.trend-scroll { overflow-x: auto; }
.trend-plot { display: block; width: 100%; min-width: 500px; }
.trend-plot text { fill: var(--muted); font-size: 13px; }
.trend-grid { stroke: var(--line); vector-effect: non-scaling-stroke; }
.trend-guide { stroke: #809f97; stroke-dasharray: 3 4; pointer-events: none; vector-effect: non-scaling-stroke; }
.series-0 { --series: var(--royal); }
.series-1 { --series: var(--diamond); }
.series-2 { --series: var(--gold); }
.series-3 { --series: var(--general); }
.trend-series {
  fill: none;
  stroke: var(--series);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.trend-dot { fill: var(--series); stroke: #fff; stroke-width: 1; vector-effect: non-scaling-stroke; }
.trend-hit { fill: transparent; }
.trend-point { cursor: pointer; }
.trend-point:focus-visible { outline: none; }
.trend-point:focus-visible .trend-hit { stroke: var(--accent); stroke-width: 1; vector-effect: non-scaling-stroke; }
.trend-readout {
  align-items: center;
  gap: 8px 15px;
  margin-bottom: 7px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}
.trend-readout strong, .trend-readout small { color: var(--ink); font-size: inherit; font-variant-numeric: tabular-nums; }
.trend-readout small { font-weight: 700; }

.table-scroll { overflow: auto; max-height: 680px; border-top: 1px solid var(--line); border-radius: 0 0 var(--corner) var(--corner); }
#detail-table { scroll-margin-top: 16px; }
#detail-table:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .875rem; white-space: nowrap; }
th, td { padding: 10px 12px; border-bottom: 1px solid #eaf0ed; text-align: left; }
th:first-child, td:first-child { padding-left: var(--gutter); }
th:last-child, td:last-child { padding-right: var(--gutter); }
thead { position: sticky; top: 0; z-index: 1; }
thead th { background: #edf4f1; color: #294641; }
thead tr:first-child th:not([rowspan]) { background: #e6f0eb; text-align: center; }
thead th[scope=colgroup], thead th:has([data-column="share-0"]), thead th:has([data-column="count-0"]) {
  border-left: 1px solid var(--line);
}
thead tr:nth-child(2) th { padding-inline: 12px; }
.column-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  font-weight: 700;
  white-space: nowrap;
}
.column-toggle:hover, .column-toggle.filtered { border-color: var(--edge); background: var(--accent-soft); color: var(--accent-dark); }
.column-indicator { min-width: .75em; color: var(--accent-dark); text-align: center; font-size: .8em; }
tbody tr:nth-child(even) { background: #f7faf8; }
tbody tr:hover { background: #edf6f2; }
tbody tr.focused-date { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }
tfoot { position: sticky; bottom: 0; z-index: 1; }
tfoot th, tfoot td { border-top: 1px solid var(--edge); border-bottom: 0; background: var(--accent-soft); font-weight: 750; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.campaign { max-width: 250px; overflow: hidden; text-overflow: ellipsis; }
.neg { color: #9c2626; }
.empty {
  padding: 21px 14px;
  border: 1px dashed var(--edge);
  border-radius: 8px;
  background: var(--wash);
  color: var(--muted);
  text-align: center;
  font-size: .9rem;
  line-height: 1.6;
}
#table-empty { margin: 12px var(--gutter) 18px; }

#column-menu {
  width: min(410px, calc(100vw - 28px));
  max-height: calc(100dvh - 26px);
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px #142f2a44;
}
#column-menu::backdrop { background: #142f2a66; }
.column-menu-top, .column-menu-footer, .column-actions { display: flex; align-items: center; gap: 10px; }
.column-menu-top, .column-menu-footer { justify-content: space-between; }
.column-menu-footer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.column-actions { margin: 10px 0; }
.column-actions button:not(.plain) {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-size: .875rem;
}
.column-actions button[aria-pressed=true]:not(.plain) { border-color: var(--edge); background: var(--accent-soft); color: var(--accent-dark); }
#column-options {
  max-height: min(260px, 36vh);
  overflow: auto;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--wash);
}
#column-options label { display: flex; align-items: center; gap: 9px; min-height: 32px; font-size: .875rem; overflow-wrap: anywhere; }
#column-options .status { margin: 7px 0; }
#column-menu button:disabled { opacity: .5; cursor: default; }

.notes { margin: 16px 0 34px; color: var(--muted); font-size: .875rem; line-height: 1.65; }
.notes summary { display: inline-block; color: var(--accent-dark); font-weight: 700; }
.notes summary::after { content: " +"; }
.notes[open] summary::after { content: " −"; }
.notes ul { margin-top: 8px; padding-left: 20px; }
.code-panel { padding-bottom: 20px; }
.code-form { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; padding: 0 var(--gutter); }
.code-form .field:first-child { width: min(150px, 100%); }
.code-form .field:nth-child(2) { width: min(260px, 100%); }
#code-status { margin: 10px var(--gutter); }
.code-list { display: grid; gap: 7px; max-width: 790px; padding: 0 var(--gutter); }
.code-item {
  display: grid;
  grid-template-columns: minmax(55px, 90px) minmax(0, 1fr) 114px;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  overflow-wrap: anywhere;
}
.code-actions { display: flex; align-items: center; gap: 8px; }
.code-save, .code-remove {
  padding: 6px 5px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: var(--paper);
  color: var(--accent-dark);
  font-size: .875rem;
  font-weight: 650;
}
.code-save { min-width: 56px; }
.code-save:hover { background: var(--accent-soft); border-color: var(--accent); }
.code-remove { min-width: 45px; color: #982d36; }
.code-remove:hover { border-color: #bf7a80; background: #fff3f3; }

@media (max-width: 850px) {
  .dashboard-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .report-sidebar { top: 8px; max-height: 52dvh; padding: 9px 12px; }
  .report-sidebar:not(:has(details[open])) { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .report-sidebar summary { gap: 12px; }
  .report-sidebar:not(:has(details[open])) #jump-to-table { margin-top: 0; }
  .period-form { grid-template-columns: repeat(auto-fit, minmax(122px, 1fr)); align-items: end; }
  #detail-table { scroll-margin-top: 78px; }
}
@media (max-width: 760px) {
  .wrap { width: calc(100% - 28px); }
  .top-inner { grid-template-columns: 1fr auto; gap: 8px 10px; padding: 9px 0; }
  .workspace-tabs { grid-column: 1 / -1; grid-row: 2; }
  .upload { grid-column: 2; grid-row: 1; }
  .intro { flex-wrap: wrap; margin-top: 15px; padding-block: 17px; }
  .chart-row, .chart-axis { grid-template-columns: minmax(57px, 82px) minmax(0, 1fr) 49px; gap: 7px; }
}
@media (max-width: 480px) {
  .brand { gap: 7px; font-size: .875rem; }
  .upload > summary { gap: 7px; padding-inline: 9px; }
  .scope-button { padding-inline: 7px; }
  .table-controls { gap: 8px; }
  .code-item { grid-template-columns: 40px minmax(0, 1fr) auto; padding-inline: 7px; }
}
