:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #d9dee7;
  --border-strong: #b6bfcd;
  --text: #1b2330;
  --muted: #5d6879;
  --accent: #1f5faa;
  --accent-soft: #e8f0fb;
  --danger: #b4231f;
  --warn-bg: #fff6e3;
  --warn-border: #e8c479;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 18px rgba(20, 30, 50, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "맑은 고딕", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0; font-weight: 700; }

/* ── 헤더 ─────────────────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 26px; }
.brand h1 { font-size: 17px; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.save-state { font-size: 12.5px; color: var(--muted); }

.steps {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.step-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.step-btn:hover { border-color: var(--border-strong); }
.step-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.step-btn .step-num { opacity: .7; margin-right: 5px; }

/* ── 패널 ─────────────────────────────────────────────────────────────── */

.panel { max-width: 1180px; margin: 0 auto; padding: 22px 20px 80px; }
.loading { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card > h2 { font-size: 15.5px; margin-bottom: 4px; }
.card > .card-desc { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.grid { display: grid; gap: 12px 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field > span { font-weight: 600; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; line-height: 1.5; }

.btn {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  padding: 7px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1a5296; }
.btn.ghost { border-color: var(--border); color: var(--muted); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger-ghost { color: var(--danger); border-color: #e3bcbb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.notice strong { font-weight: 700; }
.notice.info { background: var(--accent-soft); border-color: #bcd3f0; }

.badge {
  display: inline-block;
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef1f6;
  color: var(--muted);
  margin-left: 6px;
}
.badge.check { background: #fdf0d8; color: #8a5a11; }
.badge.rank { background: var(--accent); color: #fff; }

/* ── 데이터 표 ────────────────────────────────────────────────────────── */

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { border: 1px solid var(--border); padding: 5px 7px; text-align: center; }
.data-table th { background: #f2f5f9; font-weight: 600; color: var(--muted); font-size: 12.5px; }
.data-table td.left, .data-table th.left { text-align: left; }
.data-table input { border: 1px solid transparent; background: transparent; padding: 3px 5px; }
.data-table input:hover { border-color: var(--border); }
.data-table input.score { text-align: center; width: 100%; min-width: 44px; }
.data-table tr.total-row td { background: #f7f9fc; font-weight: 700; }
.data-table tr.rank-1 td { background: #eef6ff; }

.table-scroll { overflow-x: auto; }

.subject-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: #fff;
}
.subject-item.included { border-color: var(--accent); background: #fbfdff; }
.subject-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.subject-head label { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.subject-meta { color: var(--muted); font-size: 12.5px; }
.subject-body { margin-top: 12px; }

.rank-picker { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.rank-picker .field { min-width: 210px; }

.llm-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.llm-hint { font-size: 12px; color: var(--muted); }

.doc-list { display: flex; flex-direction: column; gap: 6px; }
.doc-list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13.5px;
}

.verify-list { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13px; }
.verify-list li { padding: 3px 0; }
.verify-ok { color: #1a7a3c; font-weight: 600; }
.verify-fail { color: var(--danger); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: #1b2330; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.dialog { border: none; border-radius: 12px; padding: 22px 24px; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(10, 20, 40, .25); }
.dialog::backdrop { background: rgba(15, 22, 35, .45); }
.dialog h2 { font-size: 17px; margin-bottom: 14px; }
.dialog-section { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.dialog-section h3 { font-size: 14px; margin-bottom: 6px; }
.dialog-section .field + .field { margin-top: 10px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.dialog-footer { display: flex; justify-content: flex-end; margin-top: 18px; }

/* ── 문서 미리보기 (A4) ───────────────────────────────────────────────── */

#preview { margin-top: 18px; }
.doc-wrap { margin-bottom: 26px; overflow-x: auto; }

/* 창이 좁을 때는 A4 미리보기를 축소해 가로 스크롤을 줄인다(인쇄에는 영향 없음). */
@media screen and (max-width: 1000px) {
  .page { zoom: .78; }
}
@media screen and (max-width: 820px) {
  .page { zoom: .62; }
}
.doc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.doc-head-title { font-size: 13px; font-weight: 600; color: var(--muted); }

.page {
  width: 210mm;
  min-height: 297mm;
  padding: 20mm 17mm;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-family: "함초롬바탕", "맑은 고딕", "Malgun Gothic", serif;
  font-size: 11pt;
  color: #000;
  line-height: 1.6;
}

.doc-title { font-size: 15pt; font-weight: 700; text-align: center; margin: 4pt 0 10pt; letter-spacing: -.3pt; }
.doc-p { margin: 0 0 2pt; white-space: pre-wrap; }
.doc-p.align-left { text-align: left; }
.doc-p.align-center { text-align: center; }
.doc-p.align-right { text-align: right; }
.doc-p.align-justify { text-align: justify; }
.doc-p.bold { font-weight: 700; }
.doc-p.small { font-size: 9.5pt; color: #333; }
.doc-spacer { height: 10pt; }
.doc-pagebreak { break-after: page; height: 0; }

.doc-table { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 4pt 0 6pt; }
.doc-table th, .doc-table td {
  border: .4pt solid #000;
  padding: 3pt 4pt;
  vertical-align: middle;
  word-break: break-word;
  font-weight: 400;
  font-size: 10.5pt;
}
.doc-table th { background: #f1f1f1; font-weight: 700; text-align: center; }
.doc-table.small th, .doc-table.small td { font-size: 9pt; padding: 2pt 2pt; }

@media print {
  .app-header, .panel > .card, .toast, .dialog { display: none !important; }
  .panel { padding: 0; max-width: none; }
  #preview { margin: 0; display: block !important; }
  .doc-head { display: none; }
  body { background: #fff; }
  .page {
    width: auto; min-height: auto; margin: 0; padding: 0;
    border: none; box-shadow: none;
    break-after: page;
  }
  .doc-wrap { margin: 0; }
  .doc-wrap:last-child .page { break-after: auto; }
}

@page { size: A4 portrait; margin: 20mm 17mm; }

.sub-head { font-size: 14px; margin-bottom: 4px; }
.sample-select { max-width: 340px; font-size: 12.5px; padding: 4px 6px; }
.rank-block { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.rank-block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.rank-block-head .badge.rank { margin-left: 0; }

/* 5단계 문서 범위 고르기 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none; font: inherit; font-size: 13.5px; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 999px; padding: 6px 12px; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip-count {
  font-size: 11.5px; background: #eef1f6; color: var(--muted);
  border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center;
}
.chip.active .chip-count { background: rgba(255, 255, 255, .25); color: #fff; }

/* ── 왼쪽 사이드바: 저장 / 불러오기 ─────────────────────────────────────── */

.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
.layout-main { min-width: 0; }

.sidebar {
  position: sticky;
  top: 108px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.side-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.side-block h3 { font-size: 13.5px; margin-bottom: 6px; }
.side-hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; line-height: 1.5; }
.side-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.side-actions .btn { flex: 1 1 auto; }

.save-row {
  display: flex; align-items: stretch; gap: 4px;
  border: 1px solid var(--border); border-radius: 8px;
  margin-top: 6px; overflow: hidden;
}
.save-row.active { border-color: var(--accent); background: var(--accent-soft); }
.save-open {
  flex: 1; text-align: left; background: none; border: none; cursor: pointer;
  font: inherit; padding: 7px 9px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.save-open:hover { background: #f4f7fb; }
.save-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-meta { font-size: 11.5px; color: var(--muted); }
.save-tools { display: flex; flex-direction: column; }
.icon-btn {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 13px; line-height: 1; padding: 4px 7px;
}
.icon-btn:hover { background: #eef1f6; color: var(--text); }
.icon-btn.danger:hover { background: #fdeceb; color: var(--danger); }

/* ── 과목별 심사위원 ─────────────────────────────────────────────────────── */

.member-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: 14px;
  background: #fbfcfe;
}
.member-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.member-head .btn { margin-left: auto; }
.member-box .data-table { background: #fff; }

@media screen and (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; flex-wrap: wrap; }
  .side-block { flex: 1 1 260px; }
}

@media print {
  .layout { display: block; }
  .sidebar { display: none !important; }
}

/* ── 단계 이동 ──────────────────────────────────────────────────────────── */

.step-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 40px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.step-nav .btn { min-width: 120px; }
.step-nav .btn.primary { min-width: 160px; }
.step-nav-mid { font-size: 12.5px; color: var(--muted); }

@media print { .step-nav { display: none !important; } }

.step-nav-mid { white-space: nowrap; }
@media screen and (max-width: 520px) {
  .step-nav-mid { display: none; }
  .step-nav .btn, .step-nav .btn.primary { min-width: 0; flex: 1 1 auto; }
}

/* 오프라인판 내려받기 버튼(헤더 오른쪽) */
#btnOffline { text-decoration: none; display: inline-flex; align-items: center; }
@media screen and (max-width: 640px) { #btnOffline { display: none; } }
@media print { #btnOffline { display: none !important; } }

/* 가로 용지로 내는 서식(서식1)의 미리보기 */
.page.landscape { width: 297mm; min-height: 210mm; padding: 15mm 17mm; }
@media screen and (max-width: 1250px) { .page.landscape { zoom: .68; } }
@media print { .page.landscape { width: auto; min-height: auto; } }

/* ── 만든이 (왼쪽 메뉴 제일 아래) ───────────────────────────────────────── */

.side-maker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 8px;
}

.maker-face {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex: none;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.maker-text { min-width: 0; }
.maker-name { margin: 0; font-size: 13.5px; font-weight: 700; color: var(--text); }
.maker-sub { margin: 1px 0 0; font-size: 11.5px; line-height: 1.35; color: var(--muted); }

@media print { .side-maker { display: none !important; } }

/* 검정도서 / 인정도서 구분 — 1단계 과목 목록 */
.badge.book-certified { background: #e4efe3; color: #2f6b2a; }
.badge.book-approved { background: #e8eefb; color: #2b4f93; }

/* 좁은 화면에서는 머리글을 눌러 두지 않는다.
   "자동 저장" 표시는 세로로 찌그러지기 쉬워 숨기고, 안내 문구만 남긴다. */
@media screen and (max-width: 720px) {
  .save-state { display: none; }
  .brand-sub { font-size: 12px; line-height: 1.4; }
}

/* 순위에 넣지 않은 후보 안내 */
.notice.warn { background: var(--warn-bg); border-color: var(--warn-border); margin-top: 12px; }
.notice.warn .btn { margin-left: 4px; vertical-align: baseline; }
.badge.group { background: #f1ecf7; color: #5b4380; }
.data-table td.nowrap { white-space: nowrap; }
.data-table textarea { width: 100%; min-width: 220px; resize: vertical; font: inherit; }
