:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1c2430;
  --text-sub: #5b6572;
  --border: #e2e6ea;
  --accent: #2f6fed;
  --accent-soft: #eaf1ff;
  --warn-bg: #fff4e5;
  --warn-border: #f3c98b;
  --warn-text: #8a5a00;
  --danger: #d64545;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Roboto, sans-serif;
  line-height: 1.55;
  padding-bottom: 60px;
}
header {
  background: linear-gradient(135deg, #2f6fed, #5b8def);
  color: #fff;
  padding: 28px 20px 34px;
  text-align: center;
}
header h1 { margin: 0 0 6px; font-size: 22px; }
header p { margin: 0; font-size: 14px; opacity: 0.92; }

.wrap { max-width: 820px; margin: -18px auto 0; padding: 0 16px; }

.notice-box {
  background: var(--accent-soft);
  border: 1px solid #cddffb;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-sub);
  margin: 0 0 16px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 10px rgba(20, 30, 50, 0.05);
}
.card h2 {
  font-size: 16px;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}
.hidden { display: none !important; }

.hint { font-size: 12.5px; color: var(--text-sub); margin: 6px 0 12px; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: #fbfcfd;
  border-radius: 10px;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--text-sub);
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-area:hover, .upload-area.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.upload-area .icon { font-size: 34px; margin-bottom: 6px; }
.upload-area .main-text { font-size: 15px; font-weight: 600; }
.upload-area .sub-text { font-size: 13px; color: var(--text-sub); margin-top: 4px; }

textarea#pasteArea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 10px;
}

label.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 6px;
}
input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fbfcfd;
  color: var(--text);
}
input[type="file"] { font-size: 13px; }

.field-row { margin-bottom: 14px; }
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin-bottom: 14px;
}
@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
}

.btn-small {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
.primary-btn:disabled { background: #a9bde0; cursor: not-allowed; }

.error-box {
  background: #fdeceb;
  border: 1px solid #f3b9b4;
  color: var(--danger);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-top: 12px;
  white-space: pre-wrap;
}

.table-scroll { overflow-x: auto; margin-bottom: 6px; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table th, table td { border: 1px solid var(--border); padding: 6px 8px; white-space: nowrap; }

#rawPreviewWrap table tr { cursor: pointer; }
#rawPreviewWrap table tr:hover td { background: var(--accent-soft); }
#rawPreviewWrap table tr.chosen-header td { background: var(--accent); color: #fff; font-weight: 700; }
#rawPreviewWrap table tr.data-dim td { color: #b6bcc4; }

.mapping-table th { background: #fafbfc; font-size: 12.5px; color: var(--text-sub); }
.mapping-table td select { min-width: 150px; }
.mapping-table td.field-name { font-weight: 700; white-space: nowrap; }

.select-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.count-text { font-size: 13px; color: var(--text-sub); flex: 1; }

.student-list { display: flex; flex-direction: column; gap: 10px; }
.student-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
}
.student-row .s-name { font-weight: 700; min-width: 70px; }
.student-row .s-meta { color: var(--text-sub); flex: 1; }
.student-row .s-preview-btn { font-size: 12px; }

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 18px;
  padding: 0 24px;
}

/* ---------------- Certificate ---------------- */
#certRoot { display: none; }

.cert-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto 24px;
  background: #fff;
  padding: 22mm 18mm;
  box-shadow: 0 2px 14px rgba(0,0,0,0.12);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", serif;
  color: #111;
  position: relative;
}
.cert-school { text-align: center; font-size: 15px; color: #444; margin-bottom: 6px; }
.cert-title {
  text-align: center;
  font-size: 30px;
  letter-spacing: 12px;
  margin: 10px 0 40px;
  padding-left: 12px;
}
.cert-info { width: 100%; border-collapse: collapse; margin-bottom: 22px; font-size: 15px; }
.cert-info th, .cert-info td { border: 1px solid #333; padding: 10px 12px; }
.cert-info th { background: #f4f4f4; width: 15%; text-align: center; }
.cert-info td { width: 35%; }

.cert-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; font-size: 15px; }
.cert-table th, .cert-table td { border: 1px solid #333; padding: 10px; text-align: center; }
.cert-table th { background: #f4f4f4; }
.cert-table .total-row th, .cert-table .total-row td { font-weight: 700; background: #fafafa; }

.cert-days { font-size: 14px; margin-bottom: 10px; }
.cert-note { font-size: 14px; margin-bottom: 20px; color: #333; }

.cert-purpose {
  text-align: center;
  font-size: 16px;
  margin: 60px 0 30px;
  line-height: 1.9;
}
.cert-date { text-align: center; font-size: 16px; margin-bottom: 34px; }
.cert-school-name {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
  position: relative;
}
.cert-school-name .seal {
  display: inline-block;
  width: 60px;
  height: 60px;
  vertical-align: middle;
  margin-left: 6px;
  object-fit: contain;
}
.cert-teacher { text-align: right; font-size: 14px; padding-right: 10%; }

@media print {
  body * { visibility: hidden; }
  header, .wrap, .footer-note { display: none !important; }
  #certRoot, #certRoot * { visibility: visible; }
  #certRoot { display: block; position: absolute; left: 0; top: 0; width: 100%; }
  .cert-page {
    box-shadow: none;
    margin: 0;
    page-break-after: always;
  }
  .cert-page.no-print { display: none !important; }
  @page { size: A4; margin: 0; }
}
