/* ═════════ 수업변경신청 화면 (public/change.js) ═════════ */
:root { --chg-sel: #ffe94d; --chg-green: #b5f5b5; }
@media (prefers-color-scheme: dark) { :root { --chg-sel: #6b5d00; --chg-green: #1f5a26; } }

/* ── 창이 떠 있을 때 뒤 화면 스크롤·당겨서 새로고침 막기 (app.js 가 html 에 lock 을 붙임) ── */
html.lock, html.lock body { overflow: hidden; overscroll-behavior: none; }
/* ── 창(안내·경고·신청 목록·수정될 시간 등): 버튼이 휴대폰 주소창·도구바에 가리지 않게 ──
   1) 창 높이를 "지금 보이는 화면 높이"(dvh)에 맞춤 (dvh 를 모르는 브라우저는 vh)
   2) 창을 제목 / 내용 / 버튼 세 칸으로 나눠 내용만 스크롤 → 버튼줄은 늘 창 아래에 보임 */
.modal { height: 100vh; height: 100dvh; padding: 12px; overscroll-behavior: contain; }
.modal .modal-box {
  display: flex; flex-direction: column; overflow: hidden;
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
}
.modal .modal-box > h3 { flex: none; }
.modal .modal-body, .modal .chg-dlg-body, .modal .stu-fields, .modal .stu-desc {
  flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.modal .modal-btns, #modalOk { flex: none; }
.modal .chg-dlg .modal-btns { padding-top: 10px; border-top: 1px solid var(--line); }
/* 수업변경 신청 화면: 자기 안에서만 스크롤 (끝까지 끌어도 뒤 화면·새로고침으로 넘어가지 않음) */
#chgScreen { position: fixed; inset: 0; z-index: 5; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); -webkit-overflow-scrolling: touch; }
/* 휴대폰 주소창이 나타나고 사라져도 화면 높이를 맞춤 (dvh 를 모르는 브라우저는 위 inset:0 사용) */
@supports (height: 100dvh) { #chgScreen { bottom: auto; height: 100dvh; } }
/* 제목줄(신청 목록·교사 ID·닫기)은 신청 화면 안에서 스크롤해도 늘 맨 위에 보이게 */
#chgScreen > .topbar { position: sticky; top: 0; z-index: 6; }
.chg-grid-wrap, .chg-list-wrap, .pick-list, .my-list, .finder .week, .my-detail { overscroll-behavior: contain; }

#modal { z-index: 40; }             /* 안내창은 항상 맨 위 */
.modal-top { z-index: 30; }         /* 찾기 창은 보강 창 위 */
#chgDlg { z-index: 20; }
.pre { white-space: pre-line; margin: 0; }

.chg { display: flex; flex-direction: column; min-height: 100%; }
/* 아래쪽 96px: 휴대폰 도구바·홈 표시줄이 덮어도 아래 버튼을 그 위까지 끌어올릴 수 있게 하는 여유 공간 */
.chg-body { padding: 10px 16px calc(96px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; }
.chg-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.chg-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }
.chg-inline select, .chg-form select, .chg-form input {
  height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: var(--surface); font-weight: 400;
}
.chg-legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--muted); }
.sw.sel { background: var(--chg-sel); }
.sw.green { background: var(--chg-green); }

/* 교사 시간표 (가로 스크롤, 교시 열·날짜 줄 고정) */
.chg-grid-wrap { overflow: auto; max-height: 60vh; max-height: 60dvh; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.chg-grid { border-collapse: collapse; table-layout: fixed; }
.chg-grid th, .chg-grid td { border: 1px solid var(--line); }
.chg-grid thead th { position: sticky; top: 0; z-index: 2; background: var(--bg); font-size: 12px; padding: 4px 2px; min-width: 84px; white-space: nowrap; }
.chg-grid thead th.today { background: #1f3f7a; color: #fff; }
.chg-grid thead th.wkend, .chg-grid td.wkend { min-width: 40px; max-width: 40px; color: var(--muted); }
.chg-grid .pcol { position: sticky; left: 0; z-index: 1; background: var(--bg); width: 36px; min-width: 36px; font-size: 13px; }
.chg-grid thead th.pcol { z-index: 3; }
/* touch-action: 두 번 터치해도 화면이 확대되지 않게 (두 번 누르기를 직접 셈) */
.chg-grid td.cc { touch-action: manipulation; -webkit-user-select: none; user-select: none; height: 48px; min-width: 84px; max-width: 84px; padding: 2px; font-size: 12px; text-align: center; vertical-align: middle; cursor: pointer; line-height: 1.2; overflow: hidden; }
.chg-grid td.cc .it { display: block; overflow-wrap: anywhere; }
.chg-grid td.cc .it.fx { color: var(--red); }
.chg-grid td.cc .ev { display: block; font-size: 11px; font-weight: 600; }
.chg-grid td.cc .gw { color: var(--blue); font-weight: 700; }
.chg-grid td.cc .mark { display: inline-block; font-size: 9px; padding: 0 2px; border-radius: 3px; border: 1px solid currentColor; }
.chg-grid td.cc .mark.ds { color: var(--mark-ds); }
.chg-grid td.cc .mark.bun { color: var(--mark-bun); }
.chg-grid td.cur { outline: 2px solid var(--blue); outline-offset: -2px; }
.bg-sel { background: var(--chg-sel); }
.bg-moved { background: var(--moved); }
.bg-changed { background: var(--changed); }
.bg-vacant { background: var(--vacant); }
.bg-absent { background: var(--absent); }
.bg-green { background: var(--chg-green); }

.chg-actions .btn-primary, .chg-actions .btn-ghost { padding: 8px 14px; }
.chg-help { margin: 0; font-size: 13px; color: var(--muted); }
.chg-tip { margin: 0; font-size: 13px; min-height: 1.2em; }

/* 변경 목록 */
.chg-list-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.chg-list { border-collapse: collapse; width: 100%; font-size: 12px; white-space: nowrap; }
.chg-list th, .chg-list td { border: 1px solid var(--line); padding: 3px 5px; text-align: center; }
.chg-list thead th { background: var(--bg); }
.chg-list tbody tr { cursor: pointer; }
.chg-list tbody tr.on td { background: var(--primary-soft); }
.chg-empty { margin: 0; padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

.chg-form { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.chg-form label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.chg-form .chg-grow { flex: 1; min-width: 200px; }
.chg-form .chg-grow input { flex: 1; min-width: 0; }
.chg-bottom { justify-content: flex-end; }
.chg-bottom button { padding: 8px 12px; }

/* 공용 창 */
.chg-dlg { max-width: 460px; }
.modal-box.wide { max-width: 980px; }
.chg-dlg .modal-btns { flex-wrap: wrap; }
.chg-dlg-body { font-size: 14px; }
.chg-note { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.chg-fields { display: flex; flex-direction: column; gap: 10px; }
.chg-fields label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.chg-fields input, .chg-fields select { height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--bg); font-weight: 400; }
.btn-s { padding: 2px 8px; font-size: 12px; }

/* 수정될 시간 확인창 */
.pv { display: flex; gap: 12px; flex-wrap: wrap; }
.pv h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.pv-t { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.pv-t button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 6px 8px; text-align: left; cursor: pointer; }
.pv-t button.on { background: var(--primary); color: #fff; }
.pv-tables { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; align-items: flex-start; }
.pv-arrow { align-self: center; font-size: 20px; color: var(--muted); }
.pv-grid { border-collapse: collapse; font-size: 12px; }
.pv-grid th, .pv-grid td { border: 1px solid var(--line); padding: 3px 4px; text-align: center; min-width: 80px; height: 30px; }
.pv-grid th:first-child { min-width: 30px; }
.pv-grid thead th { background: var(--bg); }
.pv-grid .it { display: block; }
.pv-grid .it.fx { color: var(--red); }
.pv-grid .note { display: block; font-size: 11px; }
.pv-grid td.red { outline: 2px solid var(--red); outline-offset: -2px; }

/* 보강/대체 창 */
.bg-tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.bg-tbl th, .bg-tbl td { padding: 4px 6px; text-align: left; }
.bg-tbl tr.sep td, .bg-tbl tr.sep th { border-top: 1px dashed var(--line); }
.bg-val { display: inline-block; min-width: 110px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); min-height: 28px; vertical-align: middle; }

/* 찾기 창 */
.finder { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.finder .week { flex: 1; overflow-x: auto; }
.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; min-width: 170px; }
.pick-list.tall { max-height: 360px; }
.pick-list button { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 6px 8px; text-align: left; cursor: pointer; }
.pick-list button:hover { background: var(--primary-soft); }
.pick-list button.on { background: var(--primary); color: #fff; }
.pick-list button.busy { color: var(--muted); }
.pick-list button small { opacity: .75; margin-left: 4px; }

/* 신청 목록 */
.my-list { max-height: 40vh; max-height: 40dvh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.my-list table { border-collapse: collapse; width: 100%; font-size: 13px; }
.my-list th, .my-list td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; white-space: nowrap; }
.my-list thead th { position: sticky; top: 0; background: var(--bg); }
.my-list tbody tr { cursor: pointer; }
.my-list tbody tr.on td { background: var(--primary-soft); }
.my-list .s1 { color: #1a7f37; font-weight: 600; }
.my-list .s3, .my-list .s0 { color: var(--red); font-weight: 600; }
.my-list .s5 { color: var(--blue); }
.my-detail { margin-top: 8px; overflow-x: auto; }

@media (max-width: 760px) {
  .chg-body { padding: 8px 10px calc(96px + env(safe-area-inset-bottom, 0px)); }
  .chg-grid-wrap { max-height: 55vh; max-height: 55dvh; }
  .chg-bottom { justify-content: stretch; }
  .chg-bottom button { flex: 1 1 30%; }
  .chg-form label { width: 100%; }
  .chg-form select, .chg-form input { flex: 1; }
  .pv-tables { flex-direction: column; }
  .pv-arrow { transform: rotate(90deg); }
}
