@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.css');

:root {
  --bar: #26374d;          /* 상단 메뉴바 */
  --bar-2: #33475f;
  --accent: #1f5fa9;       /* 링크·선택 */
  --accent-soft: #dce8f6;
  --head: #edf1f6;         /* 표 헤더 */
  --head-2: #e3eaf2;
  --line: #c9d2dc;         /* 격자선 */
  --line-2: #dde3ea;
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f7f9fb;
  --text: #1c2531;
  --muted: #6b7684;
  --pos: #0f7b4f;
  --neg: #c62828;
  --warn: #b26a00;
  --bar-fill: #a8c4e8;
  --viz-line: #2a78d6;     /* 스파크라인 — 그래픽 대비 4.4:1 */
  --viz-up: #d03b3b;       /* 원가 상승 — 본문 대비 4.8:1 */
  /* 누적 영역 계열 — 고정 순서, 검증 통과(CVD ΔE 9.1 / 인접쌍) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --font: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
          'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --bar: #16202c;  --bar-2: #223044;  --accent: #6fa8ea;  --accent-soft: #1d2b3d;
    --head: #222c38; --head-2: #27323f; --line: #39434f;   --line-2: #2c3540;
    --bg: #12181f;   --panel: #1a222c;  --panel-2: #1f2832;
    --text: #dfe5ec; --muted: #8b95a3;  --pos: #3ecf8e;    --neg: #ff7b7b;
    --warn: #e0a03a; --bar-fill: #2f4a75;
    --viz-line: #3987e5; --viz-up: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  --bar: #16202c;  --bar-2: #223044;  --accent: #6fa8ea;  --accent-soft: #1d2b3d;
  --head: #222c38; --head-2: #27323f; --line: #39434f;   --line-2: #2c3540;
  --bg: #12181f;   --panel: #1a222c;  --panel-2: #1f2832;
  --text: #dfe5ec; --muted: #8b95a3;  --pos: #3ecf8e;    --neg: #ff7b7b;
  --warn: #e0a03a; --bar-fill: #35507d;
  --viz-line: #3987e5; --viz-up: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
/* 모달이 뒤 스크롤을 잠글 때 스크롤바가 사라지며 화면이 튀지 않게 자리를 비워 둔다 */
html { scrollbar-gutter: stable; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
.num, td.num, .node-row > :not(.label) { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* ── 상단 메뉴바 ────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 0 12px; height: 42px;
  background: linear-gradient(180deg, var(--bar-2), var(--bar));
  border-bottom: 2px solid var(--accent);
  color: #fff;
}
header h1 { font-size: 14px; font-weight: 700; margin: 0; letter-spacing: -.2px; }
header .spacer { flex: 1; }
header, header * { color: #fff; }
header select { color: var(--text); }

/* ── 폼 컨트롤 ─────────────────────────────────── */
select, input[type="search"], button, label.file {
  font: 12px var(--font); color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 2px;
  padding: 3px 7px; height: 25px;
}
button, label.file { cursor: pointer; }
label.file {
  background: linear-gradient(180deg, #2f72c4, var(--accent));
  color: #fff; border-color: #17497f; font-weight: 600;
  display: inline-flex; align-items: center;
}
label.file:hover { filter: brightness(1.08); }
input[type="file"] { display: none; }
input[type="search"] { height: 25px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── 창(패널) ──────────────────────────────────── */
main { padding: 10px; display: grid; gap: 10px; }
main > *, .split > * { min-width: 0; }   /* grid 아이템이 내용 최소폭에 밀리지 않게 */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 0; padding: 0 0 9px;
}
.panel > h2 {
  margin: 0 0 9px; padding: 6px 10px;
  font-size: 12px; font-weight: 700; color: var(--text); letter-spacing: -.2px;
  background: linear-gradient(180deg, var(--panel-2), var(--head));
  border-bottom: 1px solid var(--line);
}
.panel > h2::before {
  content: ''; display: inline-block; width: 3px; height: 11px;
  background: var(--accent); margin-right: 7px; vertical-align: -1px;
}
.panel > *:not(h2) { margin-left: 10px; margin-right: 10px; }
.panel > .scroll, .panel > .mscroll { margin-left: 0; margin-right: 0; }

/* ── 요약 스트립 ───────────────────────────────── */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0; border: 1px solid var(--line); border-right: 0;
}
.card { border-right: 1px solid var(--line); padding: 6px 10px; background: var(--panel); }
.card .k { font-size: 11px; color: var(--muted); }
.card .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 1px; }

/* ── 격자 테이블 ───────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td {
  padding: 4px 7px; text-align: right; white-space: nowrap;
  border: 1px solid var(--line-2);
}
th {
  color: var(--text); font-weight: 600; font-size: 11px;
  background: var(--head); border-color: var(--line);
  position: relative;
}
.scroll th, .mscroll th { position: sticky; top: 0; z-index: 1; }
th.l, td.l { text-align: left; }
/* 정렬 가능한 헤더 — 목록·원자재·집계제외·상세모달 전부 */
th[data-sort], th[data-psort], th[data-exsort], th[data-hsort] { cursor: pointer; user-select: none; }
th[data-sort]:hover, th[data-psort]:hover,
th[data-exsort]:hover, th[data-hsort]:hover { background: var(--head-2); }
th[data-dir]:not([data-dir=""])::after {
  content: attr(data-dir); font-size: 9px; margin-left: 3px; color: var(--accent);
}
tbody tr { cursor: pointer; }
tbody tr:nth-child(even) { background: var(--panel-2); }
tbody tr:hover { background: var(--accent-soft); }
tbody tr.sel { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
td.name { overflow: hidden; text-overflow: ellipsis; }

/* 집계표는 숫자 컬럼을 고정폭으로 — 와이드 모니터에서 숫자가 흩어지지 않게 */
#summary, #groups { table-layout: fixed; }
#summary th:not(.l), #summary td:not(.l),
#groups  th:not(.l), #groups  td:not(.l) { width: 150px; }

#items { table-layout: fixed; }
#items th:nth-child(1), #items td:nth-child(1) { width: 20%; }
#items th:nth-child(2), #items td:nth-child(2) { width: 24%; }
#items th:nth-child(3), #items td:nth-child(3) { width: 10%; }
#items th:nth-child(4), #items td:nth-child(4) { width: 15%; }
#items th:nth-child(5), #items td:nth-child(5) { width: 11%; }
#items th:nth-child(6), #items td:nth-child(6) { width: 11%; }
#items th:nth-child(7), #items td:nth-child(7) { width: 9%; }
#items td { overflow: hidden; text-overflow: ellipsis; }

.rz { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 2; }
.rz::before { content: ''; position: absolute; left: 3px; top: 20%; height: 60%; width: 1px; background: var(--line); }
.rz:hover::before, .rz.drag::before { background: var(--accent); width: 2px; }
body.resizing { cursor: col-resize; user-select: none; }
.scroll { max-height: 70vh; overflow-y: auto; overflow-x: hidden; }

/* ── 탭 버튼 ───────────────────────────────────── */
.row-tools { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; margin-bottom: 7px; }
.chip {
  padding: 3px 11px; height: 25px; border-radius: 2px;
  border: 1px solid var(--line); background: linear-gradient(180deg, var(--panel), var(--head));
  cursor: pointer; font-size: 12px; color: var(--text);
}
.chip:hover { background: var(--head-2); }
.chip.on {
  background: linear-gradient(180deg, #2f72c4, var(--accent));
  color: #fff; border-color: #17497f; font-weight: 600;
}
.chip.warn { border-color: var(--warn); color: var(--warn); background: var(--panel); }
.chip.warn.on { background: var(--warn); color: #fff; border-color: #8a5200; }

/* hidden 은 언제나 이긴다 — display 를 지정한 클래스(.split 등)가 덮어쓰지 못하게. */
[hidden] { display: none !important; }

/* 부가세 기준 — 금액이 나오는 자리마다 어느 기준인지 밝힌다 */
.vat {
  display: inline-block; margin-left: 4px; padding: 0 4px; border-radius: 2px;
  font-size: 9px; font-weight: 600; line-height: 13px; letter-spacing: 0;
  color: var(--muted); border: 1px solid var(--line); background: var(--panel-2);
  vertical-align: 1px; white-space: nowrap;
}
.vat.inc { color: var(--warn); border-color: var(--warn); }
th .vat { display: block; margin: 1px 0 0; text-align: inherit; }

/* ── 라벨(배지) ────────────────────────────────── */
.badge {
  display: inline-block; padding: 0 5px; border-radius: 2px; font-size: 11px; line-height: 16px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
}
.badge.bom  { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.badge.buy  { color: var(--pos); border-color: var(--pos); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad  { color: var(--neg); border-color: var(--neg); }
.warn-dot { color: var(--neg); margin-right: 2px; }
.miss-dot { color: var(--warn); font-weight: 800; margin-right: 3px; }
.chip.miss { border-color: var(--warn); color: var(--warn); background: var(--panel); }
.chip.miss.on { background: var(--warn); color: #fff; border-color: #8a5200; }
.alert.miss { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, transparent); }

/* ── 탭 ────────────────────────────────────────── */
.panel > h2.tabs { padding: 0; gap: 0; background: var(--head); }
.tabs .tab {
  border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: transparent; color: var(--muted);
  font: 600 12px var(--font); height: 29px; padding: 0 16px; cursor: pointer; border-radius: 0;
}
.tabs .tab:hover { color: var(--text); background: var(--panel-2); }
.tabs .tab.on {
  background: var(--panel); color: var(--accent); border-bottom-color: transparent;
  box-shadow: inset 0 2px 0 var(--accent);
}
#excluded { table-layout: fixed; }
#excluded th:nth-child(1), #excluded td:nth-child(1) { width: 11%; }
#excluded th:nth-child(2), #excluded td:nth-child(2) { width: 24%; }
#excluded th:nth-child(3), #excluded td:nth-child(3) { width: 39%; }
#excluded th:nth-child(4), #excluded td:nth-child(4) { width: 11%; }
#excluded th:nth-child(5), #excluded td:nth-child(5) { width: 15%; }
#excluded td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#unpriced { table-layout: fixed; }
#unpriced th:nth-child(1), #unpriced td:nth-child(1) { width: 34%; }
#unpriced th:nth-child(2), #unpriced td:nth-child(2) { width: 50%; }
#unpriced th:nth-child(3), #unpriced td:nth-child(3) { width: 16%; }
#unpriced td { overflow: hidden; text-overflow: ellipsis; }

#parts { table-layout: fixed; }
#parts th:nth-child(1), #parts td:nth-child(1) { width: 19%; }
#parts th:nth-child(2), #parts td:nth-child(2) { width: 21%; }
#parts th:nth-child(3), #parts td:nth-child(3) { width: 10%; }
#parts th:nth-child(4), #parts td:nth-child(4) { width: 8%; }
#parts th:nth-child(5), #parts td:nth-child(5) { width: 13%; }
#parts th:nth-child(6), #parts td:nth-child(6) { width: 7%; }
#parts th:nth-child(7), #parts td:nth-child(7) { width: 8%; }
#parts th:nth-child(8), #parts td:nth-child(8) { width: 9%; }
#parts th:nth-child(9), #parts td:nth-child(9) { width: 7%; }
#parts td { overflow: hidden; text-overflow: ellipsis; }
#parts td small { font-size: 10px; }

/* ── 마스터-디테일 ─────────────────────────────── */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
@media (min-width: 1700px) { .split { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); } }
#detail { position: sticky; top: 52px; }

.item-head {
  display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: flex-end;
  padding: 8px 10px; margin: 0 0 9px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.item-head .big { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; }
.item-head .sub { font-size: 11px; color: var(--muted); }

/* ── 원가 구성 트리 ────────────────────────────── */
.tree { font-size: 12px; border: 1px solid var(--line); }
.node-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 80px 92px 100px 56px;
  gap: 6px; align-items: center; padding: 5px 7px;
  border-bottom: 1px solid var(--line-2);
}
.node-row.head {
  color: var(--text); font-size: 11px; font-weight: 600;
  background: var(--head); border-bottom: 1px solid var(--line);
}
.node-row.head small { display: block; font-size: 9px; font-weight: 400; color: var(--muted); line-height: 1.2; }
.node-row > :not(.label) { text-align: right; }

/*
 * 반제품은 머리 행부터 하위 자재·소계까지가 한 덩어리다.
 * 축(좌측 세로선)을 블록 전체에 하나만 둬서 어디서 시작해 어디서 끝나는지 보이게 한다.
 */
.node.grp { border-left: 3px solid var(--accent); }
.node.grp > .grp-head {
  background: var(--panel-2); font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.node.grp > .grp-head .txt { color: var(--accent); }

.kids {
  margin: 0; padding-left: 15px;
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
.kids > .node > .node-row { padding-left: 4px; }
/* 중첩될수록 축 색을 낮춰 깊이를 구분 */
.node.grp .node.grp { border-left-color: var(--muted); }
.node.grp .node.grp > .kids { background: color-mix(in srgb, var(--muted) 6%, transparent); }
.node.grp .node.grp .node.grp { border-left-color: var(--line); }
.kids > .node:last-of-type > .node-row { border-bottom: 1px solid var(--line-2); }

/* 하위 합계 — '자식 합 = 반제품 단가' 검산 */
/* 소계는 하위 블록의 마지막 줄 — 배경을 블록과 맞추고 윗선으로만 끊는다 */
.node-row.kid-sum {
  border-top: 1px solid var(--line); border-bottom: 0;
  background: transparent; color: var(--muted); font-weight: 600;
  padding-left: 4px;
}
.node-row.kid-sum .txt { font-size: 11px; }
.node-row.kid-sum.mismatch { color: var(--warn); }
.node-row.kid-sum.mismatch .txt { font-weight: 600; }

.label { display: flex; align-items: center; gap: 5px; min-width: 0; }
.label .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.twist { width: 15px; flex: 0 0 15px; border: 0; background: none; color: var(--muted);
         padding: 0; font-size: 12px; line-height: 1; cursor: pointer; height: auto; }
.node.grp > .grp-head .twist { color: var(--accent); }
.twist:hover { color: var(--text); }
.twist.leaf { visibility: hidden; }
.share { position: relative; }
.share i { position: absolute; inset: 0 0 0 auto; display: block; background: var(--bar-fill);
           border-radius: 1px; opacity: .5; z-index: 0; }
.share span { position: relative; z-index: 1; padding-right: 2px; }
.node-row .unit small { color: var(--muted); font-size: 10px; display: block; line-height: 1.25; }
.stale { color: var(--warn); font-weight: 600; }

/* 자재비 소계 / 외주·공통비 / 합계 */
.node-row.sub { background: var(--panel-2); color: var(--muted); border-top: 1px solid var(--line); }
.node-row.total { background: var(--head); font-weight: 700; border-top: 2px solid var(--accent); border-bottom: 0; }

.alert {
  border: 1px solid var(--warn); border-left-width: 3px;
  padding: 7px 10px; margin: 0 0 9px; font-size: 12px; line-height: 1.65;
  background: color-mix(in srgb, var(--warn) 7%, transparent);
}
.alert b { color: var(--warn); }

/* ── 월별 단가 ─────────────────────────────────── */
.mscroll { overflow-x: auto; }
table.monthly { font-size: 11px; }
table.monthly th, table.monthly td { padding: 3px 6px; }
table.monthly th:first-child, table.monthly td:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--panel);
  max-width: 300px; overflow: hidden; text-overflow: ellipsis;
}
table.monthly th:first-child { background: var(--head); z-index: 3; }
td.real { font-weight: 700; color: var(--accent); }
td.carried { color: var(--muted); }
.spark { display: inline-flex; align-items: center; gap: 6px; }
.spark svg { display: block; overflow: visible; }
.delta { font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--viz-up); }
.delta.calm { color: var(--muted); font-weight: 400; }
th.trend, td.trend { width: 172px; }
td.trend { padding-top: 2px; padding-bottom: 2px; }

/* ── 모달 ──────────────────────────────────────── */
dialog {
  padding: 0; border: 1px solid var(--line); border-radius: 0;
  background: var(--panel); color: var(--text);
  width: min(1180px, 94vw); max-height: 86vh;
  box-shadow: 0 14px 44px rgb(0 0 0 / .26);
}
dialog::backdrop { background: rgb(12 18 26 / .45); }

/* 모달이 떠 있으면 뒤로 아무것도 넘기지 않는다.
   showModal() 이 클릭·키보드·포커스는 막아 주지만 휠은 그대로 통과한다.
   - 뒤 페이지 스크롤 잠금
   - 모달 안에서 끝까지 굴렸을 때 뒤로 이어지는 스크롤 체이닝 차단 */
body:has(dialog[open]) { overflow: hidden; }
dialog, .dlg-bd, .hist-scroll { overscroll-behavior: contain; }
.dlg-hd {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; font-size: 12px; font-weight: 700;
  background: linear-gradient(180deg, var(--panel-2), var(--head));
  border-bottom: 1px solid var(--line);
}
.dlg-hd .muted { font-weight: 400; flex: 1; }
.dlg-bd { padding: 10px; overflow: auto; max-height: calc(86vh - 96px); }
.dlg-sec { font-size: 12px; font-weight: 700; margin: 0 0 6px; display: flex; gap: 8px; align-items: baseline; }
.dlg-sec .muted { font-weight: 400; font-size: 11px; }
#mats input, #rules input, #rules select, #mats select, #bomrules input {
  font: 12px var(--font); height: 22px; padding: 1px 5px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 2px;
}
#mats tr, #rules tr, #bomrules tr { cursor: default; }
#bomrules tr.off { opacity: .5; }
#bomrules td { padding: 3px 6px; }
#mats td, #rules td { padding: 3px 6px; }
td.perunit { font-weight: 600; }
.dlg-ft {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 10px; border-top: 1px solid var(--line); background: var(--panel-2);
}
.dlg-ft .muted { font-size: 11px; }

/* 제목 바 안의 버튼 */
.panel > h2 { display: flex; align-items: center; gap: 9px; }
.chip.hbtn { margin-left: auto; height: 22px; padding: 1px 9px; font-size: 11px; font-weight: 600; }

/* ── 월별 손익 ─────────────────────────────────── */
.split-m { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px); gap: 14px; align-items: start; }
@media (max-width: 1100px) { .split-m { grid-template-columns: 1fr; } }
#monthsum tr.sumrow { background: var(--head); font-weight: 700; }
#monthsum tr.sumrow td { border-top: 2px solid var(--accent); }
#monthsum tbody tr { cursor: default; }
#mchart .legend { justify-content: flex-start; }

/* ── 월별 원가 구성 차트 ───────────────────────── */
#chart { margin-top: 10px; border-top: 1px solid var(--line-2); padding-top: 10px; }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; max-width: 1180px; height: auto; }
.chart-wrap .grid line { stroke: var(--line-2); stroke-width: 1; }
.chart-wrap .grid text, .chart-wrap .xax text {
  fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums;
}
.chart-wrap .hit { cursor: crosshair; }
.chart-wrap .cross { stroke: var(--text); stroke-width: 1; stroke-dasharray: 2 2; opacity: .45; }
.chart-wrap .tip {
  position: absolute; top: 6px; left: 0;
  background: var(--panel); border: 1px solid var(--line); padding: 5px 8px;
  font-size: 11px; line-height: 1.7; pointer-events: none; white-space: nowrap;
  box-shadow: 0 3px 12px rgb(0 0 0 / .16); z-index: 3;
}
.chart-wrap .tip span { display: flex; align-items: center; gap: 5px; }
.chart-wrap .tip span b { margin-left: auto; padding-left: 12px; }
.chart-wrap .tip .tot { border-top: 1px solid var(--line-2); margin-top: 3px; padding-top: 3px; font-weight: 700; }
.chart-wrap .tip i, .legend i {
  width: 9px; height: 9px; border-radius: 1px; display: inline-block; flex: 0 0 9px;
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 11px; }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.legend .lg b { color: var(--text); font-variant-numeric: tabular-nums; }
.legend .tot { margin-left: auto; color: var(--text); font-weight: 600; }
@media (max-width: 700px) { .legend .tot { margin-left: 0; } }

#rules input[type="text"], #rules input:not([type]), #rules input[type="number"], #rules select {
  font: 12px var(--font); height: 22px; padding: 1px 5px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 2px;
}
#rules tr.off { opacity: .5; }
#rules tr { cursor: default; }
#rules td { padding: 3px 6px; }

.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 1px; vertical-align: -1px;
          border: 1px solid var(--line); }
.swatch.real { background: var(--accent); border-color: var(--accent); }
.swatch.carried { background: var(--muted); opacity: .45; }

/* ── 파일 등록 ─────────────────────────────────── */
#drop {
  border: 1px solid var(--line); padding: 34px 16px; text-align: center;
  color: var(--muted); background: var(--panel);
}
#drop.signin { padding: 48px 16px; }
#signin { display: flex; flex-direction: column; gap: 7px; max-width: 260px; margin: 18px auto 0; }
#signin input {
  font: 13px var(--font); height: 30px; padding: 4px 9px;
  border: 1px solid var(--line); border-radius: 2px; background: var(--panel); color: var(--text);
}
#signin button { height: 30px; }
#signin .err { color: var(--neg); font-size: 12px; margin: 2px 0 0; min-height: 15px; }
#who { display: flex; align-items: center; gap: 5px; }
#who .me { font-size: 12px; font-weight: 600; }
#who .badge { border-color: rgb(255 255 255 / .5); }

#drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
#drop h1 { margin: 0 0 6px; font-size: 15px; color: var(--text); }
.slots { list-style: none; margin: 16px auto 0; padding: 0; max-width: 460px; text-align: left; }
.slots li {
  display: flex; align-items: center; gap: 9px; padding: 6px 10px;
  border: 1px solid var(--line); border-bottom: 0; background: var(--panel);
}
.slots li:last-child { border-bottom: 1px solid var(--line); }
.slots li.on { background: var(--accent-soft); }
.slots .mark { color: var(--muted); font-size: 13px; width: 14px; }
.slots li.on .mark { color: var(--pos); }
.slots .t { flex: 1; min-width: 0; color: var(--text); font-weight: 600; font-size: 12px; }
.slots .t em { display: block; font-style: normal; font-weight: 400; font-size: 11px;
               color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 진행 표시 ─────────────────────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}
#loading .box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 22px 30px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 22px rgb(0 0 0 / .15);
}
#loading .msg { margin: 0; font-size: 12px; color: var(--muted); max-width: 40ch; text-align: center; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.empty { padding: 34px 8px; text-align: center; color: var(--muted); }
details summary { cursor: pointer; color: var(--accent); font-size: 12px; }

/* 집계표는 숫자 컬럼이 고정폭이라 좁은 화면에서 넘친다 — 표만 가로로 민다 */
@media (max-width: 1100px) {
  #summary, #groups { display: block; overflow-x: auto; }
}
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  #detail { position: static; }
  .node-row { grid-template-columns: minmax(0, 1fr) 64px 78px 86px 44px; font-size: 11px; }
  main { padding: 8px; }
  .cards { grid-template-columns: repeat(2, 1fr); border-bottom: 0; }
  .card { border-bottom: 1px solid var(--line); }
  header { height: auto; padding: 6px 10px; }
}

/* 원가 자료가 아예 없는 품목 — 0 원과 혼동되지 않게 글자로 세운다 */
.nodata { color: var(--warn, #b45309); font-size: 11px; white-space: nowrap; cursor: help; }

/* 탭 바에 얹은 버튼은 탭 높이에 맞추고 오른쪽 여백을 준다 */
.panel > h2.tabs .chip.hbtn { margin-right: 8px; }

/* 무상출고가 섞인 판매가 — 평균에서 뺐다는 표식 */
.free { color: var(--muted); margin-left: 2px; cursor: help; }

/* ── 상세보기 ──────────────────────────────────── */
.detail-col { width: 74px; text-align: center; padding: 0 4px !important; }
.chip.sm { height: 19px; padding: 0 7px; font-size: 11px; font-weight: 600; }
tr:hover .chip.sm { border-color: var(--accent); color: var(--accent); }

#item-dlg .cards { margin-bottom: 12px; }
#item-dlg .card .n { font-size: 10px; color: var(--muted); margin-top: 1px; }
#item-dlg .dlg-sec { margin-top: 14px; }
#item-dlg .dlg-sec:first-of-type { margin-top: 0; }
#item-dlg .dlg-ft .chip { margin-left: auto; }

/* 이력만 스크롤한다 — 카드·원가 구성·탭 바는 제자리에 둔다 */
#item-dlg[open] { display: flex; flex-direction: column; }
#item-dlg .dlg-bd { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; max-height: none; overflow: hidden; }
#item-dlg .hist-scroll { flex: 1 1 auto; min-height: 160px; overflow: auto; }

/* 모달 안 이력 탭 — 섹션 제목 자리를 탭이 대신한다 */
.dlg-sec.tabs2 { gap: 0; align-items: center; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.dlg-sec.tabs2 .tab {
  border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted);
  font: 700 12px var(--font); height: 25px; padding: 0 12px; cursor: pointer; border-radius: 0;
}
.dlg-sec.tabs2 .tab:hover { color: var(--text); }
.dlg-sec.tabs2 .tab.on { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.dlg-sec.tabs2 .muted { margin-left: 10px; }

table.mini { width: 100%; }
table.mini thead th { position: sticky; top: 0; z-index: 1; }
table.mini td { padding: 3px 6px; }
table.mini tr { cursor: default; }
table.mini tr.tot td { font-weight: 700; background: var(--panel-2); border-top: 1px solid var(--line); }

/* 이중 계상 — 덤으로 붙은 줄을 눈에 띄게 */
.alert.dup { border-color: var(--neg); background: color-mix(in srgb, var(--neg) 7%, transparent); }
.alert.dup .dup-line { margin: 7px 0 0; padding-left: 9px; border-left: 2px solid var(--neg); }
.alert.dup .dup-line > div { margin: 3px 0; }
.alert.dup .dup-what { font-size: 12px; margin-bottom: 5px; }
.alert.dup .dup-why { font-size: 11px; margin-top: 5px; }
table.dup-path { width: 100%; background: var(--panel); table-layout: fixed; }
table.dup-path th:nth-child(1), table.dup-path td:nth-child(1) { width: 140px; }
table.dup-path th:nth-child(3), table.dup-path td:nth-child(3) { width: 68px; }
table.dup-path th:nth-child(4), table.dup-path td:nth-child(4) { width: 104px; }
table.dup-path td:nth-child(2) { word-break: break-all; }
table.dup-path th { font-size: 11px; color: var(--muted); font-weight: 600; padding: 2px 6px; }
table.dup-path td { padding: 4px 6px; vertical-align: top; font-size: 12px; line-height: 1.5; }
table.dup-path tr { cursor: default; }
table.dup-path tr.dup td { background: color-mix(in srgb, var(--neg) 10%, transparent); }
table.dup-path td .muted { font-size: 11px; }
.alert.dup .dup-line b { color: var(--text); }
.alert.dup .again { color: var(--neg); }
/* 트리의 배지와 같은 모양이라 눈으로 이어진다 */
.dup-tag {
  display: inline-block; padding: 0 5px; border-radius: 2px; font-size: 11px; line-height: 16px;
  border: 1px solid; margin-right: 4px; vertical-align: 1px;
}
.dup-tag.warn { color: var(--warn); border-color: var(--warn); }
.dup-tag.bad { color: var(--neg); border-color: var(--neg); }
.alert.dup .dup-fix { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); }
.alert.dup s { color: var(--muted); }
.alert.dup > b { color: var(--neg); }
.alert.dup .dup-fix b { color: var(--pos); }
table.mini tr.free-row td { color: var(--muted); background: var(--panel-2); }
table.mini tr.neg-row td { color: var(--neg, #b3261e); }
