/* myGrid grid-only stylesheet (이식용).
 * 기존 사이트 적용 시 이 파일만 복사: webgrid.js + tui-compat.js + webgrid.css
 * 모든 규칙이 .grid 스코프 안이라 사이트 전역 CSS와 충돌하지 않음.
 * v0.12.0
 */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d7dce2;
  --line-strong: #b7c0ca;
  --header: #eef2f5;
  --header-active: #d9eadf;
  --text: #17202a;
  --muted: #667085;
  --accent: #217346;
  --accent-soft: rgba(33, 115, 70, 0.14);
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  --row-h: 28px;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.grid,
.grid * {
  box-sizing: border-box;
}

.grid button,
.grid input {
  font: inherit;
}

.grid {
  position: relative;
  user-select: none;
  width: 100%;
  --row-h: 28px;
  /* 그리드 영역 바깥 1px 그레이 테두리 */
  border: 1px solid var(--line-strong);
  /* 오버레이 스크롤바가 행을 덮지 못하도록 궤적 상시 예약 */
  scrollbar-gutter: stable;
}

.grid .row {
  display: flex;
  height: var(--row-h);
}

/* flex 아이템의 내용물 기준 팽창/수축 차단: 셀 너비는 인라인 지정값으로 고정 */
.grid .row > * {
  flex: none;
}

/* 타이틀행 고정: 데이터 스크롤과 무관하게 상단에 유지. z-index로 데이터셀보다 위 */
.grid .header-row {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--header);
}

/* 복합(다단) 헤더 블록: 그룹+리프 행 전체가 함께 고정 */
.grid .header-block {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--header);
}

.grid .header-block .header-row {
  position: static;
}

.grid .group-header {
  cursor: default;
}

/* Feature controls are scoped; the filter popup lives in body to avoid scroll clipping. */
.grid .filter-button { position: absolute; right: 2px; width: 20px; border: 0; background: transparent; color: var(--muted); padding: 1px 5px; cursor: pointer; flex: none; }
.grid .filter-button.filtered { background: var(--accent); color: white; border-radius: 3px; }
.grid .sort-order { color: var(--accent); font-size: 10px; }
.grid .detail-toggle, .grid .group-toggle { flex: none; margin-right: 6px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--accent); width: 20px; height: 20px; padding: 0; cursor: pointer; border-radius: 3px; }
.grid .formula-cell { font-style: italic; }
.grid .formula-error { color: var(--danger); }
.grid .aggregate-row .summary-cell, .grid .aggregate-row .summary-corner { height: var(--row-h); }
.grid .group-row .summary-cell, .grid .group-row .summary-corner { background: #eef3f7; font-weight: 600; }
.grid .subtotal-row .summary-cell, .grid .subtotal-row .summary-corner { background: #f5f8f5; font-weight: 600; }
.grid .total-row .summary-cell, .grid .total-row .summary-corner { background: #dcece1; font-weight: 700; }
.grid .total-row { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -1px 0 #b7c0ca; }
.grid .aggregate-label { overflow: hidden; }
.grid .detail-row { padding: 12px 16px; background: #f3f6f9; min-height: 48px; border-bottom: 1px solid var(--line); width: 100%; position: sticky; left: 0; }
.grid .detail-grid-host { background: white; }
.grid .detail-content { width: 100%; }
.grid .tree-cell { display: flex; align-items: center; justify-content: flex-start; }
.grid .tree-toggle-spacer { display: inline-block; flex: 0 0 20px; width: 20px; height: 20px; margin-right: 6px; }
.webgrid-stats { box-sizing: border-box; width: 100%; padding: 7px 10px; background: #f4f8f5; color: #215e3b; border: 1px solid var(--line-strong, #b7c0ca); border-top: 0; font: 12px/1.5 "Segoe UI", system-ui, sans-serif; white-space: normal; }
.webgrid-filter-menu { box-sizing: border-box; position: fixed; z-index: 10000; width: 290px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; border: 1px solid #b7c0ca; background: white; color: #17202a; border-radius: 6px; box-shadow: 0 8px 30px #0003; font: 13px/1.4 "Segoe UI", system-ui, sans-serif; }
.webgrid-filter-menu * { box-sizing: border-box; }
.webgrid-filter-menu input, .webgrid-filter-menu select, .webgrid-filter-menu button { font: inherit; }
.webgrid-filter-menu > input, .webgrid-filter-menu select { width: 100%; min-height: 30px; padding: 4px 6px; border: 1px solid #b7c0ca; border-radius: 3px; }
.webgrid-filter-menu [hidden] { display: none; }
.webgrid-filter-menu label { display: flex; align-items: center; gap: 6px; }
.webgrid-filter-menu input[type=checkbox] { flex: none; accent-color: #217346; }
.webgrid-filter-menu .filter-value-list { max-height: 160px; min-height: 42px; overflow: auto; border: 1px solid #d7dce2; padding: 4px; }
.webgrid-filter-menu .filter-value-list label { padding: 3px; overflow-wrap: anywhere; }
.webgrid-filter-menu .filter-actions { display: flex; gap: 5px; }
.webgrid-filter-menu button { flex: 1; padding: 5px; border: 1px solid #b7c0ca; border-radius: 3px; background: #f6f7f9; cursor: pointer; }
.webgrid-filter-menu button.primary { background: #217346; color: white; border-color: #217346; }
.webgrid-filter-menu .filter-error { color: #b42318; }

/* 복합 헤더 하위 행의 rowspan 자리맞춤용 (상위 셀이 덮으므로 화면에 안 보임) */
.grid .header-spacer {
  height: var(--row-h);
  visibility: hidden;
}

.grid .cell,
.grid .col-header,
.grid .row-header,
.grid .corner,
.grid .summary-cell,
.grid .summary-corner {
  height: var(--row-h);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  white-space: nowrap;
}

/* 고정(frozen) 열: 좌측에 고정, 스크롤 셀이 밑으로 지나감 */
.grid .cell.frozen {
  position: sticky;
  z-index: 3;
  box-shadow: 1px 0 0 var(--line-strong);
}

.grid .col-header.frozen {
  position: sticky;
  z-index: 5;
  box-shadow: 1px 0 0 var(--line-strong);
}

/* active(z2)와 겹쳐도 frozen 고정 유지 */
.grid .cell.active.frozen {
  position: sticky;
  z-index: 3;
}

.grid .corner,
.grid .col-header,
.grid .row-header,
.grid .summary-corner {
  background: var(--header);
  color: #344054;
  font-size: 11px;
}

.grid .corner {
  width: 32px;
  min-width: 32px;
  display: grid;
  place-items: center;
  position: sticky;
  left: 0;
  top: 0;
  z-index: 5;
  border-right-color: var(--line-strong);
  border-bottom-color: var(--line-strong);
}

.grid .summary-row {
  position: sticky;
  bottom: 0;
  z-index: 6;
  background: #fff;
  box-shadow: 0 -1px 0 var(--line-strong);
}

.grid .summary-cell {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  background: #fff;
  color: var(--text);
  font-size: 11px;
  line-height: 1.25;
}

.grid .summary-corner {
  width: 32px;
  min-width: 32px;
  display: grid;
  place-items: center;
  position: sticky;
  left: 0;
  bottom: 0;
  z-index: 7;
  border-right-color: var(--line-strong);
}

.grid .col-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: sticky;
  top: 0;
  z-index: 4;
  font-weight: 600;
}

.grid .col-header.sortable {
  cursor: pointer;
}

.grid .col-header.has-filter {
  /* Reserve equal space so the filter button cannot shift the centered title. */
  padding-inline: 22px;
}

/* Shrink the title instead of centering an overflowing anonymous text box.
 * Wide headers keep their alignment; clipped titles always start at the front. */
.grid .header-title {
  display: block;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-align: left;
  text-overflow: clip;
}

/* Stack both direction arrows in one six-pixel column. */
.grid .sort-mark {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 6px;
  height: 10px;
  flex: 0 0 6px;
  font-size: 0;
  line-height: 0;
}

.grid .sort-mark i {
  display: block;
  width: 0;
  height: 0;
  font-style: normal;
  color: var(--line-strong);
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
}

.grid .sort-mark .mk-asc { border-bottom: 4px solid currentColor; }
.grid .sort-mark .mk-desc { border-top: 4px solid currentColor; }

.grid .sort-mark .on {
  color: var(--accent);
}

.grid .row-header {
  width: 32px;
  min-width: 32px;
  display: grid;
  place-items: center;
  position: sticky;
  left: 0;
  z-index: 3;
  border-right-color: var(--line-strong);
}

.grid .col-header.active,
.grid .row-header.active {
  background: var(--header-active);
  color: var(--accent);
}

.grid .corner.row-header-sequence,
.grid .row-header.row-header-sequence,
.grid .summary-corner.row-header-sequence {
  width: 48px;
  min-width: 48px;
}

.grid .corner.row-header-checkbox,
.grid .row-header.row-header-checkbox,
.grid .summary-corner.row-header-checkbox {
  width: 44px;
  min-width: 44px;
}

.grid .row-indicator-mark {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--accent);
  opacity: 0;
}

.grid .row-header.active .row-indicator-mark {
  opacity: 1;
}

.grid .row-check {
  width: 14px;
  height: 14px;
  margin: 0;
}

.grid .cell {
  display: flex;
  align-items: center;
  padding: 0 6px;
  background: var(--panel);
  outline: none;
  cursor: cell;
  font-size: 11px;
  text-overflow: ellipsis;
}

.grid .cell.readonly {
  background: #fbfbfb;
  color: #475467;
}

/* Empty block renderers (for example background-image icons) otherwise shrink
 * to zero width inside a flex cell. Inline renderer widths take precedence. */
.grid .cell.custom-renderer > div {
  width: 100%;
  min-width: 0;
}

.grid.theme-striped .row:nth-child(even) .cell {
  background: var(--stripe, #f8fbfd);
}

.grid .cell.editable {
  cursor: text;
}

.grid .cell.selected {
  background: var(--accent-soft);
}

.grid .cell.active {
  position: relative;
  z-index: 2;
  box-shadow: inset 0 0 0 2px var(--accent);
  background: #fff;
}

.grid .cell.editing {
  padding: 0;
  user-select: text;
  cursor: text;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.grid .cell-editor {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  padding: 0 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

/* 팝업/찾기 에디터: 입력칸 + 돋보기 버튼 */
.grid .cell-editor-wrap {
  display: flex;
  align-items: stretch;
  width: 100%;
  height: 100%;
}

.grid .cell-editor-wrap .cell-editor {
  flex: 1;
  min-width: 0;
}

.grid .cell-search-btn {
  flex: none;
  width: 26px;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--header);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

.grid .cell-search-btn:hover {
  background: var(--accent-soft);
}

/* 표시 모드 affordance: 찾기/날짜 열임을 편집 전에도 표시 */
.grid .cell-search-mark,
.grid .cell-date-mark {
  margin-left: auto;
  padding-left: 6px;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  flex: none;
}

.grid .cell-date-mark {
  cursor: default;
}

.grid .cell-search-mark:hover {
  color: var(--accent);
}

.grid .cell.bold {
  font-weight: 700;
}

.grid .cell.italic {
  font-style: italic;
}

.grid .cell.align-left {
  justify-content: flex-start;
  text-align: left;
}

.grid .cell.align-center,
.grid .summary-cell.align-center {
  justify-content: center;
  text-align: center;
}

.grid .cell.align-right,
.grid .summary-cell.align-right {
  justify-content: flex-end;
  text-align: right;
}

.grid .summary-cell.align-left {
  justify-content: flex-start;
  text-align: left;
}

.grid .cell.error {
  color: var(--danger);
}

.grid .resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
}

.grid .virtual-spacer {
  width: 100%;
  border: 0;
  padding: 0;
  margin: 0;
}

/* 고정/이동 팬 분리 (frozenCount>0, 단일 헤더): 좌측 고정, 우측 스크롤 */
.grid .grid-panes {
  display: flex;
  align-items: stretch;
}

.grid .grid-lside {
  flex: none;
  overflow: hidden;
}

.grid .grid-rside {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: clip;
  /* 오버레이 스크롤바(Win11 기본)가 행을 덮지 못하도록 궤적 상시 예약 */
  scrollbar-gutter: stable;
}

/* 네이티브 스크롤바 명시적 지정: 오버레이 대신 자리 차지형으로 강제 + TOAST 톤 */
.grid-lside::-webkit-scrollbar,
.grid-rside::-webkit-scrollbar,
.grid::-webkit-scrollbar,
.webgrid-viewport::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.grid-lside::-webkit-scrollbar-track,
.grid-rside::-webkit-scrollbar-track,
.grid::-webkit-scrollbar-track,
.webgrid-viewport::-webkit-scrollbar-track {
  background: #f5f5f5;
}

.grid-lside::-webkit-scrollbar-thumb,
.grid-rside::-webkit-scrollbar-thumb,
.grid::-webkit-scrollbar-thumb,
.webgrid-viewport::-webkit-scrollbar-thumb {
  background: #d9d9d9;
}

.grid-lside::-webkit-scrollbar-thumb:hover,
.grid-rside::-webkit-scrollbar-thumb:hover,
.grid::-webkit-scrollbar-thumb:hover,
.webgrid-viewport::-webkit-scrollbar-thumb:hover {
  background: #c1c1c1;
}

.grid-lside,
.grid-rside,
.grid,
.webgrid-viewport {
  scrollbar-width: thin;
  scrollbar-color: #d9d9d9 #f5f5f5;
}

/* 빈 그리드 메시지 */
.grid .grid-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  color: var(--muted);
  font-size: 13px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

/* 가로 스크롤 격리 뷰포트: 호스트 페이지에 스크롤 컨테이너가 없을 때
 * 그리드가 페이지를 넓히지 않도록 가로만 내부 스크롤.
 * (y:clip이라 세로 스크롤·sticky 헤더는 바깥 흐름 그대로 유지)
 * contain:inline-size로 flex 조상의 min-width:auto 확장까지 차단. */
.webgrid-viewport {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: clip;
  box-sizing: border-box;
  contain: inline-size;
  scrollbar-gutter: stable;
}
