/* 표 머리의 정렬 단추·열 필터의 모양(ui/table-tools.mjs가 만드는 요소). 색과 간격은 화면의 변수를 쓴다: --text, --text-2,
   --muted, --line, --line-strong, --surface, --surface-2, --focus, --up(잘못 적은 입력칸), --radius, --fs-sub. 강조색은 Fixture 화면의 --blue가 있으면
   그것, 없으면 --focus다(밝은·어두운 화면은 화면이 변수로 바꾼다). */

/* 머리 칸 전체가 정렬 단추다: 칸은 제 여백·맞춤을 그대로 두고, 단추의 ::after가 칸을 덮는다. 칸의 position은 화면 것이 이긴다
   (:where로 구체성 0. Fixture의 sticky 머리도 ::after를 담는다). 머리 글 옆에는 정렬 화살표만 서고, 깔때기는 칸 안쪽에 겹쳐 선다
   (아래). 머리 묶음은 칸의 바탕색을 이어받아 깔때기에 넘긴다(깔때기가 겹친 자리의 글자를 그 색으로 가린다. 네 화면 모두 머리 칸에
   불투명한 바탕이 있다). */
:where(th.tt-th) { position: relative; }
.tt-head { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; vertical-align: middle; background-color: inherit; }
.tt-sort {
  display: inline-flex; align-items: center; gap: 4px; min-width: 0; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; text-align: inherit; white-space: inherit; cursor: pointer;
}
.tt-sort::after { content: ""; position: absolute; inset: 0; }
/* 글쇠 초점: 머리 칸 가장자리 안쪽의 2px 링(칸을 덮는 ::after에 그린다). 네 화면이 같은 모양이고, 칸 안에 그려 이웃 칸·고정 칸·
   스크롤 칸에 잘리지 않는다. 마우스로 누르면 서지 않는다(:focus-visible). 단추 자체의 링(화면의 :focus-visible, 기간 툴팁의
   .tip-head:focus-visible)은 끈다: 구체성을 그보다 높게 둔다. */
.tt-th .tt-sort:focus, .tt-th .tt-sort:focus-visible { outline: none; }
.tt-sort:focus-visible::after { outline: 2px solid var(--focus); outline-offset: -2px; }
.tt-th:hover .tt-sort { color: var(--text); }
th[aria-sort] .tt-sort { color: var(--blue, var(--focus)); }
/* 기간 툴팁(ui/period-tip.mjs)이 붙은 정렬 단추(벙커·지수 요약 표의 전주~전년 동기 대비): 화면의 .tip-head(inline-block, help 커서,
   점선 밑줄)를 단추 모양으로 되돌리고 점선 밑줄은 글자에만 둔다. */
.tt-sort.tip-head { display: inline-flex; cursor: pointer; text-decoration: none; }
.tt-sort.tip-head .tt-label { text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; }
.tt-icon { display: block; flex: none; width: 14px; height: 14px; }
/* 정렬 화살표(2026-11-11 표 머리 정리): 정렬 중인 열에만 늘 보이고 강조색이다. 정렬 안 된 열은 숨어 있다가 머리에 마우스를 올리거나
   머리 안 단추에 글쇠 초점이 있으면 흐린 위아래 화살표로 보인다. 자리(14px와 글과의 사이 4px)는 늘 둔다: 정렬을 바꿔도 머리 글이
   밀리거나 열 폭이 흔들리지 않고(정렬·쪽 넘김에 열 폭 고정, 2026-10-29), 좁은 열에서 화살표가 칸 밖으로 나가지 않는다.
   :has()를 모르는 브라우저는 그 규칙만 버리도록 따로 적는다. 정렬 중인 열의 규칙은 맨 뒤라 hover·초점보다 이긴다. */
.tt-sort-icon { color: var(--muted); opacity: 0; transition: opacity .12s ease-out; }
.tt-th:hover .tt-sort-icon { opacity: .55; }
.tt-th:has(:focus-visible) .tt-sort-icon { opacity: .55; }
.tt-th[aria-sort] .tt-sort-icon { color: inherit; opacity: 1; }

/* 깔때기: 칸 안쪽 가장자리에 겹쳐 서서(머리 글을 밀지 않는다) 칸의 바탕색으로 그 자리 글자를 가린다. 칸을 덮는 ::after 위에 서고
   세로로는 칸 가운데다(정렬 화살표와 같은 줄). 머리에 마우스를 올렸을 때, 머리 안 단추에 글쇠 초점이 있을 때, 판이 열렸을 때만
   보인다(숨어 있어도 누르고 초점을 받는다: 마우스가 오면 이미 보인다). 터치 화면(hover 없음)에서는 늘 보인다. 걸리면 채워지고
   강조색이다. 필터가 걸린 것만으로는 보이지 않는다(아래 밑줄, 2026-11-11 피드백 1). 왼쪽·가운데 맞춤 머리는 칸 오른쪽 안, 오른쪽 맞춤 숫자 머리(화면이 num을 단 칸)는 글이 오른쪽에
   붙어 있으니 빈 왼쪽 안이다. */
.tt-filter {
  position: absolute; z-index: 1; top: 0; bottom: 0; right: 3px; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; margin: auto 0; padding: 0; border: 0; border-radius: 2px; background-color: inherit;
  color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s ease-out;
}
.tt-th.num .tt-filter { right: auto; left: 3px; }
.tt-th:hover .tt-filter, .tt-filter:focus-visible, .tt-filter[aria-expanded="true"] { opacity: 1; }
.tt-th:has(:focus-visible) .tt-filter { opacity: 1; }
@media (hover: none) { .tt-filter { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tt-sort-icon, .tt-filter { transition: none; } }
/* 필터가 걸린 열(ui/table-tools.mjs가 머리 칸에 tt-filtered를 단다): 머리 칸 아래쪽 안에 강조색 밑줄 2px. 칸을 덮는 정렬 단추의 ::after에
   안쪽 그림자로 그려 머리 글을 밀지도 가리지도 않는다(칸 아래 여백 안이다). 색만으로 알리지 않게 깔때기 title이 "필터 적용됨"이다. */
.tt-th.tt-filtered .tt-sort::after { box-shadow: inset 0 -2px 0 var(--blue, var(--focus)); }
/* 좁은 열: 깔때기가 들어갈 빈자리(왼쪽·가운데 맞춤은 정렬 화살표 뒤, 숫자 머리는 머리 글 앞)가 없을 때. 가리는 차례는 흐린 힌트
   화살표, 머리 글이다. 정렬 안 된 열은 깔때기가 비어 있는 화살표 자리에 선다(머리 글은 그대로, 마우스를 올린 동안의 흐린 화살표는
   깔때기 밑이다). 정렬 중인 열은 화살표를 덮지 않고 왼쪽·가운데 맞춤은 화살표 바로 왼쪽, 숫자 머리는 칸 왼쪽 안에 서서 머리 글을
   가린다. 화살표와 머리 글을 기준점(anchor)으로 삼고, 기준점 이름은 머리 칸마다 따로다(anchor-scope).
   대체 배치(2026-11-11 피드백 1): anchor-scope를 모르는 브라우저(anchor-name만 아는 브라우저도)는 @supports에 걸리지 않아 위의 기본 자리
   그대로다. 깔때기는 제 머리 칸(position이 있는 칸) 안의 absolute이고 왼쪽·가운데 맞춤은 오른쪽 안 3px, 숫자 머리는 왼쪽 안 3px라 칸 밖으로
   나가거나 다른 칸을 덮지 않는다. 좁은 열에서는 마우스를 올린 동안 깔때기가 정렬 화살표나 머리 글 끝을 덮을 수 있다(필터가 걸린 것만으로는
   깔때기가 보이지 않으니 늘 덮지는 않는다). 문서 루트에 tt-no-anchor를 달면 이 길을 탄다(Chrome에서 대체 배치를 시험한다). */
@supports (anchor-scope: all) {
  :where(th.tt-th) { anchor-scope: --tt-arrow, --tt-label; }
  .tt-sort-icon { anchor-name: --tt-arrow; }
  .tt-th .tt-label { anchor-name: --tt-label; }
  :root:not(.tt-no-anchor) .tt-th:not(.num) .tt-filter {
    position-anchor: --tt-arrow; left: calc(anchor(right) + 2px); justify-self: end; position-try-fallbacks: --tt-before-arrow;
  }
  :root:not(.tt-no-anchor) .tt-th.num .tt-filter {
    right: calc(anchor(--tt-label left) + 2px); justify-self: start; position-try-fallbacks: --tt-cell-start;
  }
  :root:not(.tt-no-anchor) .tt-th:not([aria-sort]) .tt-filter { position-try-fallbacks: --tt-on-arrow; }
}
@position-try --tt-before-arrow { left: 3px; right: calc(anchor(--tt-arrow left) + 2px); }
@position-try --tt-cell-start { left: 3px; right: auto; }
@position-try --tt-on-arrow { left: calc(anchor(--tt-arrow center) - 10px); right: auto; }
.tt-filter:hover { color: var(--text); background: var(--surface-2); }
.tt-filter:focus { outline: none; }
.tt-filter:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.tt-filter.is-on, .tt-filter.is-on:hover { color: var(--blue, var(--focus)); }
.tt-filter.is-on path { fill: currentColor; }
.tt-filter[aria-expanded="true"] { background: var(--surface-2); }

/* 표 위 한 줄: 필터 N개 · 모두 지우기, 그리고 열마다의 칩 */
.tt-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 0 0 6px;
  color: var(--text-2); font-size: var(--fs-sub, 13px); line-height: 1.4;
}
.tt-bar[hidden] { display: none; }
.tt-count { font-weight: 600; }
.tt-dot { color: var(--muted); }
.tt-clear {
  padding: 0; border: 0; background: none; color: var(--blue, var(--focus)); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
.tt-chips { display: contents; }
.tt-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; height: 24px; padding: 0 4px 0 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius, 2px); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
}
.tt-chip:hover { border-color: var(--muted); }
.tt-chip-text { min-width: 0; max-width: 22em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-chip-icon { color: var(--muted); }
.tt-chip:hover .tt-chip-icon { color: var(--text); }

/* 필터 판: 창에 고정해 깔때기 아래(자리가 없으면 위)에 놓는다. 창보다 크지 않다. */
.tt-panel {
  position: fixed; z-index: 80; box-sizing: border-box; width: 260px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  overflow: auto; padding: 10px; border: 1px solid var(--line-strong); border-radius: var(--radius, 2px);
  background: var(--surface); color: var(--text); box-shadow: 0 6px 24px rgba(17, 24, 39, .16);
  font-size: var(--fs-sub, 13px); font-weight: 400; line-height: 1.4; text-align: left; white-space: normal;
}
.tt-panel[hidden] { display: none; }
.tt-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.tt-panel-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.tt-panel button {
  padding: 0; border: 0; background: none; color: var(--blue, var(--focus)); font: inherit; cursor: pointer;
}
.tt-panel button:disabled { color: var(--muted); cursor: default; }
.tt-panel input[type="search"], .tt-panel input[type="text"], .tt-panel input[type="date"] {
  display: block; box-sizing: border-box; width: 100%; height: 28px; margin: 0; padding: 0 8px;
  border: 1px solid var(--line-strong); border-radius: 3px; background: var(--surface); color: var(--text); font: inherit;
}
.tt-panel input[aria-invalid="true"] { border-color: var(--up); }
.tt-bulk { display: flex; gap: 6px; margin: 6px 0; }
.tt-options { max-height: 240px; margin: 0; padding: 0; overflow: auto; list-style: none; border-top: 1px solid var(--line); }
.tt-options label { display: flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 2px; cursor: pointer; }
.tt-options label:hover { background: var(--surface-2); }
.tt-options input { flex: none; margin: 0; }
.tt-opt-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-opt-n { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.tt-none { padding: 6px 2px; color: var(--muted); }
.tt-more { margin: 6px 0 0; color: var(--muted); }
.tt-more[hidden] { display: none; }
.tt-range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
/* 날짜 칸은 달력 단추까지 있어 둘을 나란히 두면 좁은 판(390px의 16px 글자)에서 넘친다: 위아래로 쌓는다. */
.tt-range.is-date { grid-template-columns: 1fr; }
.tt-range label { display: grid; gap: 4px; min-width: 0; color: var(--text-2); }
/* 좁은 화면: 입력칸 글자가 16px(1rem)보다 작으면 iOS가 확대한다. */
@media (max-width: 600px) {
  .tt-panel input[type="search"], .tt-panel input[type="text"], .tt-panel input[type="date"] { font-size: 1rem; }
}

@media print {
  .tt-sort-icon, .tt-filter, .tt-bar, .tt-panel { display: none !important; }
  /* 머리 글자는 정렬 단추 안에 있다: 인쇄에서 단추를 모두 숨기는 화면(Fixture)에서도 머리 글자는 싣는다. */
  button.tt-sort { display: inline-flex !important; }
  .tt-sort::after { content: none; }
  th[aria-sort] .tt-sort { color: inherit; }
  .tt-sort.tip-head .tt-label { text-decoration: none; }
}
