/* 검산 MVP 0.2 — 새 컨트롤(검사 기준, 여러 파일, 미리보기, PDF 확인, 검토 상태, 근거표)
   기준 문서: /DESIGN.md 「인감과 장부」 · 9. 설정과 여러 파일 컨트롤
   토큰만 쓴다. 새 색·그림자·장식은 만들지 않는다. */

/* ---------- 공통: 서식 안의 기입란 ---------- */
/* styles.css의 결과 필터용 고정 폭(.field input 200px, .field select 230px)이 새 컨트롤로 새지 않게 막는다 */
.sheet .field, .business-options .field { width: auto; display: grid; gap: var(--s-1); min-width: 0; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
.sheet .field input, .sheet .field select, .sheet .field textarea { width: 100%; min-width: 0; font-weight: 400; }
.sheet input[type="text"], .sheet input:not([type]), .review-cell input[type="text"] { width: 100%; min-width: 0; min-height: var(--control); padding: 8px 12px; background: var(--sheet); color: var(--ink); border: 1px solid var(--form-line); border-bottom: 1.5px solid var(--form); border-radius: var(--r-1); font-size: var(--fs-md); }
.sheet input[type="text"]:hover, .sheet input:not([type]):hover, .review-cell input[type="text"]:hover { border-color: var(--form); }
.sheet input[type="text"]:focus-visible, .sheet input:not([type]):focus-visible, .review-cell input[type="text"]:focus-visible, .sheet textarea:focus-visible { outline: none; border-color: var(--form); box-shadow: 0 0 0 3px rgba(30, 90, 63, .28); background: #fff; }

/* 체크 칸: 서식의 네모 칸에 녹색 체크 */
.check-field { display: flex; align-items: center; gap: var(--s-3); min-height: var(--control); padding: 6px 0; font-size: .9375rem; font-weight: 600; color: var(--ink); cursor: pointer; }
.check-field input { width: 22px; height: 22px; flex: none; margin: 0; accent-color: var(--form); cursor: pointer; }

/* ---------- 검사 기준 (처음엔 접힘) ---------- */
.business-options { border-top: 2px solid var(--form); background: var(--sheet); }
.business-options > summary {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2px var(--s-3);
  min-height: 64px; padding: var(--s-3) 24px; cursor: pointer; list-style: none; background: var(--sheet-tint);
  transition: background-color var(--t-fast) var(--ease-out);
}
.business-options > summary::-webkit-details-marker { display: none; }
.business-options > summary::before { content: "+"; grid-row: 1 / 3; display: grid; place-items: center; width: 24px; height: 24px; border: 1.5px solid var(--form); border-radius: 50%; color: var(--form); font-weight: 600; line-height: 1; transition: transform var(--t-base) var(--ease-out); }
.business-options[open] > summary::before { transform: rotate(45deg); }
.business-options > summary:hover { background: #e6efe9; }
.options-title { font-size: var(--fs-lg); font-weight: 800; color: var(--form); }
.options-hint { grid-column: 2; font-size: var(--fs-sm); color: var(--ink-2); }
.business-options[open] > summary { border-bottom: 1px solid var(--form-line); }
.business-options[open] .business-options-body { animation: fade-up var(--t-base) var(--ease-out) both; }
.business-options-body { display: grid; padding: 0 24px; }

.option-group { display: grid; grid-template-columns: 11em minmax(0, 1fr); gap: var(--s-3) var(--s-6); padding-block: var(--s-5); }
.option-group + .option-group { border-top: 1px solid var(--form-line); }
.option-group h3 { grid-row: 1 / 3; font-family: var(--serif); font-size: var(--fs-lg); font-weight: 700; line-height: 1.35; color: var(--ink); }
.option-group > :not(h3) { grid-column: 2; min-width: 0; }
.option-group .mapping-help { margin: 0; max-width: var(--measure); }

.rule-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); align-items: end; }
.rule-fields .check-field { grid-column: span 3; padding-block: 0; }
.rule-fields .check-field + .check-field { margin-top: calc(-1 * var(--s-3)); }

/* 두 파일의 금액 기준: 파일 칸과 같은 항목명 띠 */
.tax-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.tax-fields fieldset { min-width: 0; margin: 0; padding: 0; border: 1.5px solid var(--form); border-radius: var(--r-1); background: var(--sheet); }
.tax-fields legend { float: left; width: 100%; padding: 8px var(--s-4); background: var(--sheet-tint); border-bottom: 1px solid var(--form-line); font-size: .9375rem; font-weight: 800; color: var(--form); }
.tax-fields fieldset > div { clear: both; display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, .8fr); gap: var(--s-3); padding: var(--s-4); }
.tax-fields fieldset > div > .field:first-child { grid-column: 1 / -1; }

/* 양식 저장 */
.profile-bar { display: grid; gap: var(--s-3); }
.profile-row { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s-2) var(--s-3); }
.profile-row .field { flex: 1 1 240px; }
.profile-row .button { flex: none; }

/* ---------- 파일 칸: 여러 파일 ---------- */
.files-grid .file-card { padding-bottom: var(--s-5); }
.drop-area { flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-height: 96px; font-size: var(--fs-md); font-weight: 700; color: var(--ink); }
.drop-area small { font-weight: 400; }
.drop-area::before { /* 올리기 표시 — 마크업 없이 */
  content: "↑"; position: absolute; right: 18px; top: 50%; display: grid; place-items: center; width: 40px; height: 40px; margin-top: -20px;
  border-radius: 50%; border: 1px solid var(--form-line); background: var(--sheet-tint); color: var(--form); font-weight: 700; font-size: 1.125rem;
  transition: transform var(--t-base) var(--ease-press);
}
.drop-area { padding-right: 72px; }
.drop-area:hover::before, .drop-area.dragging::before { transform: translateY(-3px); }
.file-card:has(.file-list-bar) .drop-area { min-height: 64px; border-style: dashed; background: transparent; font-size: .9375rem; }

.file-list-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-2); align-items: center; margin-top: var(--s-4); padding: var(--s-2); border: 1px solid var(--form-line); border-radius: var(--r-1); background: var(--sheet-tint); }
.file-list-bar select { width: 100%; min-width: 0; font-weight: 700; }
.file-list-bar .button { min-height: var(--control); padding-inline: 14px; font-size: .9375rem; color: var(--ink-2); }
.file-list-bar .button:hover { color: var(--seal); }

.file-settings { grid-template-columns: minmax(0, 1fr) 120px; }
.file-card > .field { margin-top: var(--s-4); }
.mapping summary { padding-right: 2px; }

/* 읽은 표 미리보기 · PDF 추출 표 */
.file-card > details.rules { margin-top: var(--s-3); }
.file-card > details.rules > p { margin-block: var(--s-1) var(--s-3); font-size: var(--fs-sm); color: var(--ink-3); }
.file-card > details[open] > .key-scroll { animation: fade-up var(--t-base) var(--ease-out) both; }
.preview table { min-width: 100%; width: max-content; font-size: var(--fs-sm); white-space: nowrap; }
.preview th, .preview td { padding: 8px 12px; border-bottom: 1px solid var(--form-line); text-align: left; }
.preview th { background: var(--sheet-tint); color: var(--form); }
.preview td:first-child { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.preview tr:last-child td { border-bottom: 0; }
.file-card textarea {
  display: block; width: 100%; min-height: 168px; padding: var(--s-3); resize: vertical;
  border: 1px solid var(--form-line); border-bottom: 1.5px solid var(--form); border-radius: var(--r-1); background: var(--sheet); color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: var(--fs-sm); line-height: 1.6; tab-size: 12; white-space: pre; overflow: auto;
}
.file-card > details.rules .button { margin-top: var(--s-3); }
/* PDF 확인: 확인 전에는 인주색 테두리로 해야 할 일을 알린다 */
.file-card > .check-field { margin-top: var(--s-3); padding: 10px var(--s-3); border: 1.5px solid var(--seal); border-radius: var(--r-1); background: var(--seal-tint); color: var(--seal); }
.file-card > .check-field:has(input:checked) { border-color: var(--form-line); background: var(--sheet-tint); color: var(--ok); }

/* ---------- 결과 표: 원본 위치, 기준값·입력값, 확인 상태와 메모 ---------- */
/* 넓은 표가 장부 테두리를 밀어내지 않게: 격자 자식은 내용 폭보다 줄어들 수 있어야 한다 */
.stack > *, .results > *, .ledger, .rules, .key-scroll, .table-scroll { min-width: 0; }
.table-scroll, .key-scroll { max-width: 100%; }
.table-scroll table { min-width: 1040px; }
/* 표가 칸보다 넓어지면 확인 상태·메모 열은 오른쪽에 붙여 둔다 */
.table-scroll th:last-child, .table-scroll td.review-cell { position: sticky; right: 0; z-index: 1; background: var(--sheet); box-shadow: -1px 0 0 var(--form-line); }
.table-scroll th:last-child { background: var(--sheet-tint); }
.type-cell { color: var(--seal); font-weight: 700; white-space: nowrap; }
.where { min-width: 150px; max-width: 200px; white-space: normal; overflow-wrap: anywhere; color: var(--ink); }
.explanation { min-width: 190px; max-width: 290px; }
.observed { color: var(--seal); font-weight: 800; }
.review-cell { min-width: 176px; }
.review-cell select, .review-cell input { display: block; width: 100%; min-width: 0; min-height: var(--control); font-size: .9375rem; }
.review-cell input { margin-top: var(--s-2); }
/* 담당자가 고른 상태를 줄 전체에 표시한다 (글자 상태는 셀 안에 그대로 남음) */
#issue-rows tr:has(.review-cell option[value="수정 필요"]:checked) td { background: var(--seal-tint); }
#issue-rows tr:has(.review-cell option[value="확인 완료"]:checked) td { background: var(--sheet-tint); color: var(--ink-3); }
#issue-rows tr:has(.review-cell option[value="확인 완료"]:checked) .type-cell,
#issue-rows tr:has(.review-cell option[value="확인 완료"]:checked) .observed { color: var(--ink-3); }

/* 품목별 대조 · 제외한 행 */
.audit .key-scroll { margin-block: var(--s-2) var(--s-4); }
.audit-table { min-width: 860px; font-size: .9375rem; font-variant-numeric: tabular-nums; }
.audit-table th, .audit-table td { padding: 10px 14px; border-bottom: 1px solid var(--form-line); }
.audit-table th { background: var(--sheet-tint); color: var(--form); font-size: var(--fs-sm); white-space: nowrap; }
.audit-table td:first-child { color: var(--ink); font-weight: 700; }
.audit-table td:nth-child(n+3) { text-align: right; }
.audit-table tbody tr:last-child td { border-bottom: 0; }
.audit h3 { font-family: var(--serif); font-size: var(--fs-lg); font-weight: 700; margin-block: var(--s-4) var(--s-2); }
.audit ul { list-style: none; display: grid; margin: 0 0 var(--s-4); padding: 0; border-top: 1px solid var(--form-line); font-size: .9375rem; color: var(--ink-2); }
.audit li { padding: 10px 0 10px var(--s-4); border-bottom: 1px solid var(--form-line); position: relative; overflow-wrap: anywhere; }
.audit li::before { content: ""; position: absolute; left: 2px; top: 1.15em; width: 6px; height: 6px; border-radius: 50%; background: var(--form-line); }
.audit[open] > .key-scroll { animation: fade-up var(--t-base) var(--ease-out) both; }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 1000px) {
  .option-group { grid-template-columns: 1fr; gap: var(--s-3); }
  .option-group h3 { grid-row: auto; }
  .option-group > :not(h3) { grid-column: 1; }
  .rule-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rule-fields .check-field { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .business-options > summary { padding: var(--s-3) var(--s-4); }
  .business-options-body { padding: 0 var(--s-4); }
  .rule-fields, .tax-fields { grid-template-columns: 1fr; }
  .tax-fields fieldset > div { grid-template-columns: 1fr; }
  .profile-row .field { flex-basis: 100%; }
  .profile-row .button { flex: 1 1 auto; }
  .file-settings { grid-template-columns: minmax(0, 1fr) 104px; }

  /* 미리보기·근거표는 표 모양을 지키고 칸 안에서만 가로로 넘긴다 */
  .key-scroll table { display: table; }
  .key-scroll thead { position: static; width: auto; height: auto; clip-path: none; overflow: visible; display: table-header-group; }
  .key-scroll tbody { display: table-row-group; }
  .key-scroll tr, .key-scroll tbody tr { display: table-row; padding: 0; }
  .key-scroll th, .key-scroll td, .key-scroll td + td { display: table-cell; padding: 8px 10px; border-bottom: 1px solid var(--form-line); }
  .key-scroll td::before { content: none; }
  .key-scroll .num { text-align: right; }
  .audit-table { min-width: 720px; }

  /* 결과 장부: 한 항목씩 세로 서식. 확인 상태·메모는 맨 아래 한 줄 전체 */
  .table-scroll table { min-width: 0; }
  .where, .explanation, .review-cell { min-width: 0; max-width: none; }
  .table-scroll td.review-cell { position: static; box-shadow: none; background: transparent; }
  td.where, td.review-cell { grid-column: 1 / -1; }
  .review-cell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--s-2); padding-top: var(--s-2); border-top: 1px dashed var(--form-line); }
  .review-cell::before { grid-column: 1 / -1; }
  .review-cell input { margin-top: 0; }
  /* 상태 바탕은 칸마다가 아니라 항목 전체에 한 번 */
  #issue-rows tr:has(.review-cell option[value="수정 필요"]:checked) { background: var(--seal-tint); box-shadow: inset 3px 0 0 var(--seal); }
  #issue-rows tr:has(.review-cell option[value="확인 완료"]:checked) { background: var(--sheet-tint); box-shadow: inset 3px 0 0 var(--ok); }
  #issue-rows tr:has(.review-cell option:checked) td { background: transparent; }
}
@media (max-width: 400px) {
  .review-cell { grid-template-columns: 1fr; }
  .file-list-bar { grid-template-columns: 1fr; }
}
