/* 쪽지시험 관리 사이트 공통 스타일
   교사 화면(넓은 모니터)과 학생 화면(휴대폰)이 같은 토큰을 쓴다. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dde3ec;
  --border-strong: #c3ccd9;
  --text: #1a2233;
  --text-muted: #5b6779;
  --text-faint: #8a95a6;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #e8f0fe;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #b91c1c;
  --danger-soft: #fdeaea;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --font: "Pretendard", "맑은 고딕", "Malgun Gothic", -apple-system,
          BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.35; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }

a { color: var(--brand); }

/* ---------- 레이아웃 ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.topbar .who { color: var(--text-muted); font-size: .88rem; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 18px; }
.wrap-narrow { max-width: 560px; margin: 0 auto; padding: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2, .card-head h3 { margin: 0; margin-right: auto; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-tight { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.spacer { margin-left: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .wrap { padding: 12px; }
}

/* ---------- 탭 ---------- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tabs button {
  flex: none;
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* ---------- 폼 ---------- */

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { color: var(--text-muted); font-size: .84rem; margin-top: 4px; }

input[type="text"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  font-family: inherit;
  /* 16px 미만이면 아이폰이 입력할 때 화면을 멋대로 확대해 레이아웃이 깨진다.
     user-scalable=no 로 막는 것은 저시력 학생을 배제하므로 쓰지 않는다. */
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 42px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
input[type="checkbox"], input[type="radio"] {
  width: 20px; height: 20px; margin: 0; accent-color: var(--brand); flex: none;
}
.inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.inline label { margin: 0; }
.w-auto { width: auto; }
.w-sm { width: 110px; }
.w-md { width: 190px; }
/* flex 줄 안에서는 폭이 눌려 글자가 잘린다. 줄어들지 않게 고정한다. */
.w-xl { width: 380px; max-width: 100%; flex: 0 0 auto; }

/* ---------- 버튼 ---------- */

.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 4px 10px; min-height: 32px; font-size: .86rem; }
.btn-lg { padding: 14px 24px; min-height: 54px; font-size: 1.05rem; width: 100%; }

/* ---------- 표 ---------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  white-space: nowrap;
}
table.data th, table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.data th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); }

/* ---------- 상태 표시 ---------- */

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag-brand { background: var(--brand-soft); color: var(--brand-dark); border-color: transparent; }

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat .k { font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.stat .v { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--text-faint); }

.notice {
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  margin-bottom: 12px;
  font-size: .9rem;
  border: 1px solid transparent;
}
.notice-info { background: var(--brand-soft); color: #1e3a8a; }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }

.empty {
  text-align: center;
  color: var(--text-faint);
  padding: 34px 16px;
  font-size: .93rem;
}

.mono {
  font-family: "Consolas", "D2Coding", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}
.code-big {
  font-family: "Consolas", "D2Coding", ui-monospace, monospace;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--brand-dark);
}

/* ---------- 알림 토스트 ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(14px);
  background: #1f2937;
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: .92rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ---------- 모달 ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

[hidden] { display: none !important; }

/* ---------- 인쇄 ---------- */

@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; }
  body { background: #fff; font-size: 10pt; color: #000; }
  .topbar, .tabs, .btn, .no-print, #toast, .modal-back { display: none !important; }
  .card {
    border: 0;
    box-shadow: none;
    padding: 0;
    margin-bottom: 14px;
    break-inside: avoid;
  }
  .wrap, .wrap-narrow { max-width: none; padding: 0; }
  .table-scroll { overflow: visible; }

  table.data { font-size: 9.5pt; white-space: normal; }
  table.data th {
    /* 화면에서는 머리글을 고정해 두는데, 인쇄할 때 그대로 두면 자리가 어긋난다. */
    position: static;
    background: #eee !important;
  }
  /* 표가 여러 장에 걸치면 장마다 머리글을 다시 찍는다. */
  table.data thead { display: table-header-group; }
  table.data tfoot { display: table-footer-group; }
  table.data tr { break-inside: avoid; }

  /* 막대그래프와 음영이 인쇄에서 사라지지 않게 한다. */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  a[href]::after { content: none; }

  .page-break { break-after: page; page-break-after: always; }
  /* 마지막 장 뒤에 빈 종이 한 장이 따라 나오는 것을 막는다. */
  .page-break:last-child { break-after: auto; page-break-after: auto; }

  @page { size: A4; margin: 14mm; }
}

/* 졸업생 안내 */
.notice-brand { background: var(--brand-soft); color: var(--brand-dark); }
.badge-quiet { background: var(--surface-2); color: var(--text-muted); }
