:root {
  --brand: #1462b0;
  --brand-deep: #0d4583;
  --brand-soft: #e6eff9;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --line: #d7dde6;
  --text: #1c2430;
  --muted: #5d6878;
  --danger: #b23a3a;
  --hint-fill: #eef4fc;
  --desk: #e4e8ee;
  --shadow: 0 1px 2px rgb(15 30 60 / 8%), 0 6px 18px rgb(15 30 60 / 8%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #5a9de3;
    --brand-deep: #8dbcf0;
    --brand-soft: #1b2b40;
    --bg: #11161d;
    --surface: #1a2029;
    --line: #2e3744;
    --text: #e6ebf2;
    --muted: #9aa6b6;
    --danger: #e07a7a;
    --desk: #0c1016;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #5a9de3;
  --brand-deep: #8dbcf0;
  --brand-soft: #1b2b40;
  --bg: #11161d;
  --surface: #1a2029;
  --line: #2e3744;
  --text: #e6ebf2;
  --muted: #9aa6b6;
  --danger: #e07a7a;
  --desk: #0c1016;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 35%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  background: var(--brand);
  color: #fff;
}
:root[data-theme="dark"] .topbar { background: #12355e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .topbar { background: #12355e; }
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 16px 10px;
}
.mark {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgb(255 255 255 / 85%);
}
.eyebrow { margin: 0; font-size: 13px; opacity: .85; letter-spacing: .04em; }
h1 { margin: 0; font-size: 23px; letter-spacing: -.01em; }
.tools {
  display: flex;
  gap: 6px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
  overflow-x: auto;
}
.tool-tab {
  border: 0;
  border-radius: 10px 10px 0 0;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
  background: rgb(255 255 255 / 14%);
}
.tool-tab.is-active { background: var(--bg); color: var(--brand-deep); }
.tool-tab.is-soon { font-weight: 500; opacity: .7; border: 1px dashed rgb(255 255 255 / 50%); border-bottom: 0; background: none; }
.tool-num {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
}

/* ---------- layout ---------- */
.evidence {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
.side { display: flex; flex-direction: column; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.hint.small { margin: 8px 0 0; font-size: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #0b1a2b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0b1a2b; } }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 12px; }
.file-btn { position: relative; }
.new-row { display: flex; flex-wrap: wrap; gap: 8px; }
.new-row .btn { flex: 1 1 auto; }
button:focus-visible, .file-btn:focus-within, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- page list ---------- */
.page-list { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.page-list:empty { display: none; }
.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.group-head input { margin: 0; }
.page-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
}
.page-item.is-current { background: var(--brand-soft); border-color: var(--brand); }
.page-item input { margin: 0; flex: none; width: 16px; height: 16px; }
.page-item button {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 2px 0;
  color: inherit;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.page-item .num { font-weight: 700; color: var(--brand-deep); margin-right: 6px; }
.page-item .label { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-item .meta { display: block; font-size: 12px; color: var(--muted); }

/* ---------- workspace ---------- */
.workspace { min-width: 0; }
.page-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.page-bar.is-hidden { display: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0;
  padding: 5px 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.is-on { background: var(--brand); color: #fff; font-weight: 700; }
.status { margin-left: auto; font-size: 13px; color: var(--muted); }
.status.is-error { color: var(--danger); font-weight: 700; }

.paper-wrap {
  background: var(--desk);
  border-radius: 12px;
  padding: 24px;
  overflow: hidden;
}
.paper-zoom { width: 210mm; margin: 0 auto; }
.empty-state { text-align: center; padding: 60px 16px; }
.empty-state img { width: 72px; height: 72px; border-radius: 50%; background: #fff; opacity: .9; }
.empty-state p { margin: 10px 0 0; }
.empty-state.is-hidden { display: none; }

/* ---------- the paper (always black on white, like the printed form) ---------- */
.sheet {
  position: relative;
  width: 210mm;
  height: 297mm;
  background: #fff;
  color: #000;
  box-shadow: var(--shadow);
  font-family: "HCR Batang", "함초롬바탕", "Batang", "바탕", "Noto Serif KR", serif;
}
.frame {
  position: absolute;
  left: 10.5mm;
  top: 21mm;
  width: 190mm;
  height: 254.5mm;
  border: 1px solid #000;
  display: grid;
  grid-template-rows: 14.5mm 14.5mm minmax(0, 1fr);
}
.f-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 6mm;
  font-family: "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif;
  font-weight: 700;
}
.f-year, .f-month { font-size: 11pt; font-weight: 700; }
.f-name { font-size: 16pt; letter-spacing: .04em; white-space: pre; }
.f-month-wrap { justify-self: end; font-size: 11pt; white-space: pre; }
.f-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid #000;
  min-height: 0;
}
.frame.one .f-row { grid-template-columns: minmax(0, 1fr); }
.f-row > * + * { border-left: 1px solid #000; }
.f-title {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3mm;
  font-size: 11.5pt;
  font-weight: 700;
  text-align: center;
  letter-spacing: .02em;
  overflow: hidden;
}
.f-title > * { width: 100%; }
.f-body {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 3mm;
}
.f-text {
  margin: 0 0 2mm;
  padding: 0 1mm;
  font-family: inherit;
  font-size: 10pt;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
  color: #000;
}
.f-text:empty { display: none; }
.f-imgs {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 2mm;
}
.f-imgs:empty { display: none; }
.f-img { position: relative; min-width: 0; min-height: 0; }
.f-img img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 0;
}

/* paper inputs (screen editing) */
.sheet input, .sheet textarea {
  border: 0;
  border-radius: 3px;
  background: var(--hint-fill);
  color: #000;
  font: inherit;
  text-align: inherit;
  letter-spacing: inherit;
}
.sheet input { padding: 1px 2px; }
.sheet input:focus, .sheet textarea:focus { outline: 2px solid #1462b0; outline-offset: 0; background: #fff; }
.f-year input { width: 4.6ch; font-weight: 700; }
.f-month input { width: 2.6ch; text-align: center; font-weight: 700; }
.f-title input { font-weight: 700; padding: 4px 2px; }
.sheet textarea.f-text {
  display: block;
  width: 100%;
  resize: none;
  overflow: hidden;
  min-height: 2.2em;
  text-align: left;
  letter-spacing: normal;
}
.sheet input::placeholder, .sheet textarea::placeholder { color: #8a96a8; font-weight: 400; }

/* cell helpers (screen only) */
.cell-empty {
  position: absolute;
  inset: 3mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed #b8c7da;
  border-radius: 8px;
  color: #4b5a6e;
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 13px;
  text-align: center;
}
.cell-empty .btn { background: #fff; color: #1c2430; border-color: #c8d3e0; }
.cell-empty .btn.primary { background: #1462b0; color: #fff; border-color: #1462b0; }
.cell-tools {
  position: absolute;
  right: 2mm;
  bottom: 2mm;
  z-index: 2;
  display: flex;
  gap: 4px;
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
}
.cell-tools .btn, .img-tools button {
  min-height: 28px;
  padding: 2px 8px;
  font-size: 12px;
  background: rgb(255 255 255 / 94%);
  color: #1c2430;
  border-color: #b8c7da;
  box-shadow: 0 1px 3px rgb(0 0 0 / 15%);
}
.f-body.is-drop { outline: 3px solid #1462b0; outline-offset: -3px; background: #eef4fc; }
.f-body.is-busy::after {
  content: "넣는 중…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(255 255 255 / 75%);
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 14px;
  color: #1462b0;
}
.img-tools {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
  opacity: 0;
  transition: opacity .15s;
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
}
.img-tools button { border: 1px solid #b8c7da; border-radius: 6px; cursor: pointer; }
.img-tools button.del { color: #b23a3a; }
.f-img:hover .img-tools, .f-img:focus-within .img-tools { opacity: 1; }
.f-img:hover { outline: 1px dashed #1462b0; }
@media (hover: none) { .img-tools { opacity: 1; } }

/* ---------- 등록부 paper ---------- */
.reg-pages { display: flex; flex-direction: column; gap: 24px; }
.sheet.reg { font-family: "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif; }
.r-box { position: absolute; left: 19mm; top: 23mm; width: 170mm; }
.r-sub { text-align: center; font-size: 13pt; font-weight: 700; height: 9mm; }
.r-sub input { width: 100%; font-weight: 700; text-align: center; }
.r-band { margin-top: 1mm; }
.r-bar { height: 1.3mm; }
.r-bar.top { background: linear-gradient(90deg, #00a0e9 50%, #ffc000 50%); }
.r-bar.bottom { background: linear-gradient(90deg, #339a1c 50%, #ff3c00 50%); }
.r-title {
  display: flex;
  align-items: center;
  height: 12.5mm;
  background: #dfe4f6;
  font-size: 20pt;
  font-weight: 700;
  text-align: center;
  letter-spacing: .02em;
}
.r-title input { width: 100%; background: transparent; font-weight: 700; }
.sheet .r-title input:not(:focus) { background: transparent; box-shadow: inset 0 -2px 0 #b9c7e6; }
.r-date {
  display: block;
  margin: 3mm 1.5mm 0 auto;
  padding: 1px 4px;
  border: 0;
  border-radius: 3px;
  background: var(--hint-fill);
  color: #000;
  font: inherit;
  font-size: 12pt;
  font-weight: 700;
  cursor: pointer;
}
.r-table {
  width: 166.5mm;
  margin: 5mm 0 0 3.4mm;
  border-collapse: collapse;
  table-layout: fixed;
  border: 0.6mm solid #000;
  font-size: 12pt;
  text-align: center;
}
.r-c-no { width: 17.1mm; }
.r-c-school { width: 39mm; }
.r-c-name { width: 34mm; }
.r-c-sign { width: 44.6mm; }
.r-c-note { width: 31.8mm; }
.r-table th {
  height: 16mm;
  background: #c5cff0;
  font-size: 12.5pt;
  font-weight: 700;
  border: 1px solid #000;
  border-bottom: 0.6mm solid #000;
}
.r-table td { height: 12.1mm; padding: 0 1mm; border: 1px solid #000; }
.r-table input { width: 100%; padding: 4px 1px; text-align: center; }
.r-school input { font-weight: 700; }
.r-name input { font-size: 13pt; }
.r-note { position: relative; }
.r-note input { font-size: 9.5pt; }
.r-tools {
  position: absolute;
  top: 50%;
  left: calc(100% + 1.5mm);
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
}
.r-tools button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid #b8c7da;
  border-radius: 5px;
  background: #fff;
  color: #1c2430;
  font-size: 12px;
  cursor: pointer;
}
.r-tools button.del { color: #b23a3a; }
.r-table tr:hover .r-tools, .r-table tr:focus-within .r-tools { opacity: 1; }
.drop-hint {
  margin: 0 0 10px;
  padding: 10px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
/* while a file is dragged over the 등록부 tab: a frame over the visible window with a label in the middle */
#tool-register.is-dropping::before,
#tool-register.is-dropping::after {
  position: fixed;
  z-index: 20;
  pointer-events: none;
}
#tool-register.is-dropping::before {
  content: "";
  inset: 12px;
  border: 3px dashed var(--brand);
  border-radius: 16px;
  background: color-mix(in srgb, var(--brand-soft) 80%, transparent);
}
#tool-register.is-dropping::after {
  content: "여기에 놓으면 명단을 채워요";
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 24px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.date-field { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; }
.date-field input { font: inherit; font-weight: 400; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); }

/* print area is laid out off screen so photos can be measured */
#print-area { position: absolute; left: -10000px; top: 0; }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .evidence { grid-template-columns: minmax(0, 1fr); padding-top: 14px; }
  .paper-wrap { padding: 12px; }
  .page-bar { position: static; }
  .status { flex-basis: 100%; margin-left: 0; }
  h1 { font-size: 20px; }
  .mark { width: 44px; height: 44px; }
}

/* ---------- print ---------- */
@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff !important; }
  body > * { display: none !important; }
  body:not(.printing) > main[data-tool-panel="evidence"]:not([hidden]),
  body:not(.printing) > main[data-tool-panel="register"]:not([hidden]) { display: block !important; padding: 0; margin: 0; }
  body:not(.printing) .side,
  body:not(.printing) .page-bar,
  body:not(.printing) .empty-state { display: none !important; }
  body:not(.printing) .workspace, body:not(.printing) .paper-wrap { display: block; padding: 0; margin: 0; background: none; border-radius: 0; }
  .reg-pages { display: block; }
  .sheet.is-blank-page { display: none; }
  .reg-pages .sheet { break-after: auto; page-break-after: auto; }
  .reg-pages .sheet + .sheet { break-before: page; page-break-before: always; }
  .r-tools { display: none !important; }
  .r-date { background: none !important; }
  .sheet .r-title input { box-shadow: none !important; }
  body.printing > #print-area { display: block !important; position: static; }
  .paper-zoom { zoom: 1 !important; width: auto; margin: 0; }
  .sheet { box-shadow: none; break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .cell-empty, .cell-tools, .img-tools { display: none !important; }
  .f-img:hover { outline: none; }
  .sheet input, .sheet textarea { background: none !important; outline: none !important; }
  .sheet input::placeholder, .sheet textarea::placeholder { color: transparent; }
  .sheet textarea.f-text.is-blank { display: none; }
}
