* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", sans-serif;
  margin: 0; background: #f6f7f9; color: #1c2230;
}
header {
  background: #1c2230; color: #fff; padding: 14px 24px;
  display: flex; align-items: center; gap: 20px;
}
header h1 { font-size: 17px; margin: 0; font-weight: 600; }
header nav a { color: #cdd5e0; text-decoration: none; margin-right: 16px; font-size: 14px; }
header nav a.active, header nav a:hover { color: #fff; }
#config { margin-left: auto; font-size: 12px; color: #9aa7b8; }
main { max-width: 1560px; margin: 24px auto; padding: 0 24px; }
.card { background: #fff; border: 1px solid #e3e7ec; border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.card h2 { font-size: 15px; margin: 0 0 14px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
input[type=text], textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cfd6df; border-radius: 7px; font-size: 14px; font-family: inherit;
}
textarea { min-height: 150px; resize: vertical; }
.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
button {
  background: #2f6df6; color: #fff; border: 0; border-radius: 7px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
}
button.secondary { background: #5a667a; }
button:disabled { opacity: .5; cursor: default; }
.filters { margin-bottom: 14px; }
.pager { margin-top: 14px; gap: 6px; justify-content: center; }
.pager .page-btn {
  background: #fff; color: #2f3a4d; border: 1px solid #cfd6df;
  padding: 7px 12px; font-size: 13px; font-weight: 600; border-radius: 6px;
}
.pager .page-btn.active { background: #2f6df6; color: #fff; border-color: #2f6df6; }
.pager .page-btn:disabled { opacity: .4; }
.pager .page-gap { padding: 0 4px; color: #8a94a3; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.TRADE_DOCS { background: #e1f0ff; color: #1559b0; }
.chip.TARIFF { background: #fff0d9; color: #aa6a00; }
.chip.ORDER { background: #e7f7e7; color: #277a2c; }
.chip.GENERAL { background: #ececf1; color: #4a4f5c; }
.status-ok { color: #277a2c; } .status-error { color: #c0392b; } .status-unsupported { color: #aa6a00; }
pre.json {
  background: #0f1626; color: #d6e2f5; padding: 14px; border-radius: 8px;
  overflow: auto; font-size: 12px; line-height: 1.5; max-height: 360px;
  white-space: pre-wrap; word-break: break-word;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #eceff3; }
th { color: #6b7585; font-weight: 600; }
tr.clickable:hover { background: #f3f6fb; cursor: pointer; }
.cost { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; }
.cost b { font-size: 18px; display: block; }
.muted { color: #8a93a3; font-size: 12px; }
.dl-link { float: right; font-size: 12px; font-weight: 600; color: #2f6df6; text-decoration: none; }
.dl-link:hover { text-decoration: underline; }
.att { border: 1px solid #e3e7ec; border-radius: 8px; padding: 14px; margin-top: 12px; }
.att h3 { font-size: 14px; margin: 0 0 8px; }
/* 접이식 추출 카드(②: 본문 문서·첨부 추출) — 기본 접힘, summary 가 제목 */
details.att-toggle > summary {
  cursor: pointer; list-style: none; font-size: 14px; font-weight: 600; color: #1c2230;
  user-select: none;
}
details.att-toggle > summary::-webkit-details-marker { display: none; }
details.att-toggle > summary::before {
  content: "▶"; color: #2f6df6; font-size: 11px; margin-right: 9px;
  display: inline-block; transition: transform .15s; vertical-align: middle;
}
details.att-toggle[open] > summary::before { transform: rotate(90deg); }
details.att-toggle[open] > summary { margin-bottom: 10px; }

/* ── history 상세 2단 레이아웃 ── */
.detail-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
/* 좌우 패널을 각각 독립 스크롤(뷰포트 높이 고정) — 필드 클릭 시 좌측 미리보기만 스크롤 이동되고
   화면 전체/우측 목록은 움직이지 않게 한다. */
.detail-grid > div {
  min-width: 0;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  position: sticky;
  top: 14px;
}
@media (max-width: 1000px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid > div { max-height: none; overflow: visible; position: static; }
}
.detail-grid .subj { font-size: 15px; margin: 10px 0; }
.detail-grid pre.body {
  background: #f8fafc; color: #28303d; border: 1px solid #e3e7ec; border-radius: 8px;
  padding: 16px; white-space: pre-wrap; word-break: break-word; max-height: 720px; overflow: auto;
  font-size: 14px; line-height: 1.7;
}
/* 본문 HTML 렌더(표 보존) */
.detail-grid .body-html {
  background: #fff; color: #28303d; border: 1px solid #e3e7ec; border-radius: 8px;
  padding: 16px; max-height: 760px; overflow: auto; font-size: 13px; line-height: 1.6;
  word-break: break-word;
}
.detail-grid .body-html table { border-collapse: collapse; margin: 8px 0; font-size: 11.5px; }
.detail-grid .body-html td, .detail-grid .body-html th { border: 1px solid #cfd6df; padding: 3px 6px; vertical-align: top; }
.detail-grid .body-html p { margin: 4px 0; }
.detail-grid .body-html a { color: #2f6df6; }
/* 이전 메시지 이력 토글(기본 닫힘) */
.detail-grid .body-html details.thread-history { margin-top: 14px; border-top: 1px dashed #cfd6df; padding-top: 10px; }
.detail-grid .body-html details.thread-history > summary { cursor: pointer; color: #6b7585; font-size: 12px; font-weight: 700; user-select: none; list-style: none; }
.detail-grid .body-html details.thread-history > summary::-webkit-details-marker { display: none; }
.detail-grid .body-html details.thread-history > summary::before { content: "▶ "; color: #8a93a3; }
.detail-grid .body-html details.thread-history[open] > summary::before { content: "▼ "; }
.detail-grid .body-html .thread-old { margin-top: 10px; opacity: .82; }
.preview { width: 100%; height: 900px; border: 1px solid #e3e7ec; border-radius: 8px; background: #fff; }
img.preview { object-fit: contain; }
.nopreview { padding: 16px; background: #f8fafc; border: 1px dashed #cfd6df; border-radius: 8px; font-size: 13px; }
.reason {
  background: #f1f6ff; border-left: 3px solid #2f6df6; border-radius: 6px;
  padding: 14px 16px; margin-bottom: 14px; font-size: 13.5px; line-height: 1.8;
  word-break: keep-all;
}
.reason br { content: ""; display: block; margin-bottom: 7px; }
.reason-label { font-weight: 700; color: #1559b0; margin-bottom: 8px; font-size: 13px; }

/* ── 추출 결과: 값+신뢰도 통합 표 ── */
table.kv { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
table.kv th { color: #6b7585; font-weight: 600; font-size: 12px; border-bottom: 1px solid #e3e7ec; padding: 6px 8px; }
table.kv th.c, table.kv td.c { width: 60px; text-align: right; }
table.kv td { padding: 7px 8px; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
table.kv td.k { color: #6b7585; font-weight: 600; width: 40%; word-break: break-all; }
table.kv td.v { color: #1c2230; word-break: break-word; }
table.kv .sep { color: #c4ccd6; padding: 0 2px; }
.conf { display: inline-block; min-width: 34px; text-align: center; border-radius: 5px; padding: 1px 6px; font-size: 11px; font-weight: 700; }
.conf.hi { background: #e7f7e7; color: #277a2c; }
.conf.mid { background: #fff0d9; color: #aa6a00; }
.conf.lo { background: #f0f0f3; color: #9aa1ad; }
details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: #2f6df6; font-size: 12px; user-select: none; }
.empty-list { margin-top: 6px; line-height: 1.6; }

/* ── 추출 결과: 라벨 → 값 → 신뢰도 블록 ── */
.fields { margin-top: 8px; }
.field { padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.field:last-child { border-bottom: 0; }
.field-title { font-size: 12px; color: #6b7585; font-weight: 600; }
.field-title .field-key { color: #b6bdc8; font-weight: 400; font-size: 11px; margin-left: 6px; }
.field-value { font-size: 14.5px; color: #1c2230; margin-top: 3px; word-break: break-word; line-height: 1.5; }
.field-value .sep { color: #c4ccd6; padding: 0 3px; }
/* ① FSK 키 미추출 노티 */
.field.missing { opacity: .8; }
.field-value.noti { display: inline-block; font-size: 12.5px; font-weight: 600; color: #b1473f;
  background: #fdecea; padding: 2px 9px; border-radius: 5px; }
/* ① 추출 집계 배지 */
.fsk-tally { font-size: 12.5px; font-weight: 600; padding: 6px 10px; border-radius: 7px; margin-bottom: 4px; }
.fsk-tally.full { background: #e7f7e7; color: #277a2c; }
.fsk-tally.partial { background: #fff5e6; color: #99641a; }
.fsk-card.primary { border-left: 4px solid #2f6df6; }
/* ② 추출 실패 사유 */
.att.fail { background: #fcf6f5; border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.extract-fail { font-size: 13px; color: #9a4a43; margin-top: 4px; }
.extract-fail.muted { color: #8a94a3; }
/* 검증 신뢰도 배지 */
.conf { display: inline-block; margin-left: 7px; font-size: 10.5px; font-weight: 700;
  padding: 1px 7px; border-radius: 5px; vertical-align: middle; white-space: nowrap; }
.conf.hi  { background: #e7f7e7; color: #277a2c; }
.conf.mid { background: #fff3da; color: #946400; }
.conf.lo  { background: #ffe7d4; color: #b3540a; }
.conf.vlo { background: #fdecea; color: #c0392b; }
.conf.review { box-shadow: 0 0 0 1px currentColor inset; }
/* 검토 필요 필드 강조 */
.field.review { background: #fffaf2; border-left: 3px solid #f0a500; padding-left: 9px; border-radius: 0 6px 6px 0; }
.review-sum { display: inline-block; font-size: 12px; font-weight: 700; color: #b3540a;
  background: #fff3da; padding: 2px 9px; border-radius: 6px; }
/* 분류결과 카드 — FSK 요청 키값 요약 표 */
.fsk-summary-wrap { margin: 14px 0; }
.cs-head { font-size: 13px; font-weight: 700; color: #2f3a4d; margin-bottom: 6px; }
.cs-head .muted { font-weight: 500; margin-left: 6px; }
.cs-table { width: 100%; border-collapse: collapse; font-size: 13px; border-radius: 8px; overflow: hidden; }
.cs-table td { padding: 6px 11px; border-bottom: 1px solid #fff; vertical-align: top; }
.cs-key { width: 30%; color: #4a5564; font-weight: 600; }
.cs-val { color: #1c2230; word-break: break-word; }
.cs-score { width: 64px; text-align: right; font-weight: 800; white-space: nowrap; }
.cs-row.hi  { background: #eef9ee; } .cs-row.hi  .cs-score { color: #277a2c; }
.cs-row.mid { background: #fff8ea; } .cs-row.mid .cs-score { color: #946400; }
.cs-row.lo  { background: #fff0e4; } .cs-row.lo  .cs-score { color: #b3540a; }
.cs-row.vlo { background: #fdeeec; } .cs-row.vlo .cs-score { color: #c0392b; }
.cs-row.miss { background: #fbeaea; } .cs-row.miss .cs-val { color: #c0392b; font-style: italic; }
.cs-row.low { box-shadow: inset 3px 0 0 #e8a33d; }
.cs-legend { margin-top: 7px; font-size: 11px; color: #8a94a3; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cs-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 3px; vertical-align: middle; }
.cs-dot.hi { background: #cdeccd; } .cs-dot.mid { background: #ffe7b3; } .cs-dot.lo { background: #ffd3b0; }
.cs-dot.vlo { background: #f6c3bd; } .cs-dot.miss { background: #f0b3b3; }
/* 목록 FSK 추출 셀 */
.fsk-cell { font-weight: 700; white-space: nowrap; }
.fsk-cell.ok { color: #277a2c; }
.fsk-cell.flag { color: #b3540a; }
.fsk-flag { display: inline-block; font-size: 11px; font-weight: 700; background: #fff3da;
  color: #b3540a; padding: 1px 7px; border-radius: 5px; margin-left: 4px; }
.field-conf { display: inline-block; margin-top: 5px; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 5px; }
.field-conf.hi { background: #e7f7e7; color: #277a2c; }
.field-conf.mid { background: #fff0d9; color: #aa6a00; }
.field-conf.lo { background: #f0f0f3; color: #9aa1ad; }

/* ── 첨부 미리보기 오버레이 + 하이라이트 ── */
.page-wrap { position: relative; margin-bottom: 12px; }
.page-img { width: 100%; display: block; border: 1px solid #e3e7ec; border-radius: 8px; }
.ocr-layer { position: absolute; inset: 0; pointer-events: none; }
.ocr-box { position: absolute; border-radius: 2px; }
.ocr-box.hl { background: rgba(47,109,246,0.22); outline: 2px solid #2f6df6; }
/* 라인박스에서 값 부분만 좁혀 강조: 전체 박스 점등 끄고 내부 구간만 표시 */
.ocr-box.hl.partial { background: transparent; outline: none; }
.ocr-sub-hl { position: absolute; top: 0; height: 100%; background: rgba(47,109,246,0.28); outline: 2px solid #2f6df6; border-radius: 2px; }
mark.hl { background: #ffe27a; color: inherit; border-radius: 2px; padding: 0 1px; }
td.hl-cell, th.hl-cell { background: #ffe27a !important; }
.field.clickable { cursor: pointer; border-radius: 6px; transition: background .1s; }
.field.clickable:hover { background: #f3f6fb; }
.field.active { background: #eaf1ff; box-shadow: inset 3px 0 0 #2f6df6; padding-left: 8px; }

/* ── 분류 요약 밴드(전체폭) + 추출 패널 헤더 ── */
.detail-summary { border-left: 4px solid #2f6df6; }
.detail-summary h2 { font-size: 16px; }
.pane-h { font-size: 14px; margin: 0 0 12px; color: #1c2230; }

/* ── 본문 매칭 실패 안내 토스트 ── */
#flash-note {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2230; color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: all .2s; z-index: 1000;
}
#flash-note.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── GENERAL 추출: 요약 줄 + 종류 부제 ── */
.doc-kind { font-size: 12px; color: #8a93a3; margin: -4px 0 8px; }
.doc-summary {
  display: flex; gap: 8px; align-items: flex-start;
  background: #fbf6e9; border: 1px solid #f0e3c0; border-radius: 8px;
  padding: 11px 13px; margin: 8px 0 4px; font-size: 13.5px; line-height: 1.65; color: #5a4a1f;
}
.doc-summary .ds-label {
  flex: 0 0 auto; background: #e9c46a; color: #5a4a1f; font-weight: 700;
  font-size: 11px; padding: 2px 8px; border-radius: 5px;
}
.doc-actions {
  background: #eef5ff; border: 1px solid #d3e3fb; border-radius: 8px;
  padding: 10px 13px; margin: 8px 0 4px;
}
.doc-actions .da-label { font-size: 11px; font-weight: 700; color: #1559b0; margin-bottom: 5px; }
.doc-actions ul { margin: 0; padding-left: 18px; }
.doc-actions li { font-size: 13.5px; line-height: 1.7; color: #1c3a66; }

/* ── chip 기본(FSK 한글 타입명) + FSK 카드 강조 ── */
.chip { background: #e6ebf2; color: #39506b; }
.fsk-card { border: 2px solid #2f6df6; }
.fsk-card > h2 { color: #1559b0; }

/* ── 추출 근거(맥락상 추론한 값) ── */
.field-evidence {
  margin-top: 5px; font-size: 11.5px; color: #6b6150; line-height: 1.5;
  background: #fbf7ee; border-left: 2px solid #e0b85c; border-radius: 4px; padding: 4px 8px;
}

/* 첨부 출처 표시 (xlsx 등) */
.field-evidence.src { background: #eef3fb; border-left-color: #5a8fd6; color: #2c4a73; }
