/* ───────── 학교 시간표 웹앱 스타일 ───────── */

/* 색상 (밝은 화면) */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7584;
  --line: #dde2ea;
  --primary: #1f4e8c;
  --primary-soft: #e6eef9;
  --blue: #1d5fd1;   /* 담당교사 없음, 행사(수업안함/시험) */
  --red: #d22f2f;    /* 고정수업, 방학/휴업 */
  --moved: #c9f1fb;  /* 이동 (델파이 하늘색) */
  --changed: #c6f5e6;/* 교체·보강 (델파이 연녹색) */
  --vacant: #fff6b0; /* 옮겨간 원래 자리 (델파이 노란색) */
  --absent: #ffd2d2; /* 보강으로 결강된 자리, 장소변경으로 빈 자리 (델파이 분홍색) */
  --mark-ds: #7b3fc4;  /* 동시수업 표시 */
  --mark-bun: #0f7c6b; /* 분반 표시 */
  --holiday: #fdf0f0;/* 휴업일 열 */
  --today: #fff8e1;  /* 오늘 열 머리 */
  --radius: 10px;
}

/* 색상 (어두운 화면) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6eaf0;
    --muted: #97a1af;
    --line: #2c3440;
    --primary: #7fb0ff;
    --primary-soft: #1f2d42;
    --blue: #7fb0ff;
    --red: #ff7b7b;
    --moved: #12414d;
    --changed: #134235;
    --vacant: #4a4416;
    --absent: #4f2328;
    --mark-ds: #c49bff;
    --mark-bun: #5fd3bf;
    --holiday: #2a1c1e;
    --today: #33301c;
  }
}

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

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }

/* 버튼 */
.btn-primary {
  background: var(--primary); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 18px; font-weight: 600; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn-primary { color: #0d1420; } }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
.btn-ghost:hover, .btn-icon:hover { background: var(--primary-soft); }
.btn-icon {
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-size: 22px; line-height: 1; cursor: pointer;
}

/* ───────── 첫 연결 화면 ───────── */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 24px; color: var(--primary); }
.login-desc { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.login-card .opt { font-weight: 400; color: var(--muted); }
.login-card input {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  background: var(--bg); font-weight: 400;
}
.login-card input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.login-msg { margin: 0; min-height: 1.2em; color: var(--red); font-size: 14px; }
.login-btns { display: flex; justify-content: flex-end; gap: 8px; }
.login-btns .btn-primary { min-width: 96px; }

/* ───────── 조회 화면 ───────── */
.app { display: flex; flex-direction: column; min-height: 100%; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--primary); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #16243a; } }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); }
.school { display: flex; align-items: center; gap: 8px; min-width: 0; }
.school-name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 99px;
  background: rgba(255,255,255,.2); white-space: nowrap;
}

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 7px;
  cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.datebar { display: flex; align-items: center; gap: 6px; }
.datebar input {
  height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: var(--surface);
}

.content { flex: 1; display: flex; min-height: 0; }

/* 왼쪽 목록 */
.side {
  width: 220px; flex-shrink: 0; border-right: 1px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column;
}
.search { margin: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.list { overflow-y: auto; padding: 6px 10px 16px; flex: 1; max-height: calc(100vh - 120px); }
.list h4 { margin: 12px 4px 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.list .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 4px; }
.list.wide .items { grid-template-columns: 1fr; }
.list button {
  border: 1px solid transparent; background: transparent; border-radius: 7px;
  padding: 6px 8px; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list button:hover { background: var(--primary-soft); }
.list button.on { background: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .list button.on { color: #0d1420; } }
.list button small { color: var(--muted); margin-left: 4px; font-size: 12px; }
.list button.on small { color: inherit; opacity: .8; }

/* 오른쪽 시간표 */
.main { flex: 1; min-width: 0; padding: 14px 16px 24px; }
.list-select { display: none; }
.tt-title { margin: 0 0 10px; font-size: 18px; }
.tt-title small { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 6px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tt { border-collapse: collapse; width: 100%; min-width: 560px; table-layout: fixed; }
.tt th, .tt td { border: 1px solid var(--line); }
.tt tr:first-child th { border-top: 0; }
.tt tr > :first-child { border-left: 0; }
.tt tr > :last-child { border-right: 0; }
.tt tr:last-child td, .tt tr:last-child th { border-bottom: 0; }

.tt thead th { padding: 8px 4px; font-size: 14px; background: var(--bg); vertical-align: top; }
.tt thead th.today { background: var(--today); }
.tt thead th .ev { display: block; font-size: 12px; font-weight: 600; margin-top: 2px; }
.tt .pcol { width: 64px; }
.tt tbody th { background: var(--bg); font-size: 13px; padding: 4px; }
.tt tbody th b { display: block; font-size: 16px; }
.tt tbody th span { color: var(--muted); font-size: 11px; display: block; }

.tt td { height: 64px; padding: 4px 5px; text-align: center; vertical-align: middle; font-size: 14px; }
.tt td.holiday { background: var(--holiday); }
.tt td.moved { background: var(--moved); }
.tt td.changed { background: var(--changed); }
.tt td.vacant { background: var(--vacant); }
.tt td.absent { background: var(--absent); }
/* 동시수업/분반 표시: 칸 왼쪽 위 작은 글자 (델파이 아이콘 위치) */
.tt td { position: relative; }
.tt .mark {
  position: absolute; top: 2px; left: 2px;
  font-size: 10px; line-height: 1; font-weight: 700;
  padding: 2px 3px; border-radius: 3px; border: 1px solid currentColor;
}
.tt td.has-mark { padding-top: 16px; }
.tt .mark.ds { color: var(--mark-ds); }
.tt .mark.bun { color: var(--mark-bun); }
.tt td.clickable { cursor: pointer; }
.tt td.fixed .subj { color: var(--red); }
.tt .gw { color: var(--blue); font-weight: 700; margin-right: 2px; }
.tt .subj { font-weight: 600; display: block; word-break: keep-all; }
.tt .subj.warn { color: var(--blue); }
.tt .sub { display: block; font-size: 12px; color: var(--muted); word-break: keep-all; }
.tt .part + .part { border-top: 1px dashed var(--line); margin-top: 3px; padding-top: 3px; }
.tt .note { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tt td.vacant .note, .tt td.absent .note { color: var(--text); opacity: .75; }

/* 행사 색 (델파이 HENSAKINDCOLOR: 1 검정, 2·3 파랑, 4·5 빨강) */
.ev.k1 { color: var(--text); }
.ev.k2, .ev.k3 { color: var(--blue); }
.ev.k4, .ev.k5 { color: var(--red); }
.tt td .ev { display: block; font-size: 12px; font-weight: 600; }

/* 학년 일일 시간표: 가로로 밀어도 교시 열은 왼쪽에 고정 */
.tt.grade tr > :first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--bg);
  box-shadow: 1px 0 0 var(--line);
}
.tt.grade thead th { white-space: nowrap; }
/* 학년 표는 칸이 좁으므로: 긴 과목명은 칸 안에서 줄바꿈, 글자 조금 작게,
   동시/분반 표시는 글자를 가리지 않게 맨 위에 놓고, 교사·장소는 한 줄씩 */
.tt.grade td { font-size: 13px; padding: 3px 2px; line-height: 1.25; }
.tt.grade td.has-mark { padding-top: 3px; }
.tt.grade .mark { position: static; display: inline-block; margin-bottom: 1px; }
.tt.grade .subj, .tt.grade .sub, .tt.grade td .ev { overflow-wrap: anywhere; word-break: normal; }
.tt.grade .sub .sp { display: block; }
.tt.grade .sub .dot { display: none; }
.tt.grade .note { display: none; }
.tt-title .ev { font-size: 14px; margin-left: 8px; }

.tt-empty { color: var(--muted); padding: 24px 4px; text-align: center; }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; padding: 0; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 5px; }
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); display: inline-block; }
.sw.moved { background: var(--moved); }
.sw.changed { background: var(--changed); }
.sw.vacant { background: var(--vacant); }
.sw.absent { background: var(--absent); }
.updated { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ───────── 안내창 ───────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: grid; place-items: center; padding: 16px; z-index: 10;
}
.modal-box {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 14px;
  padding: 22px 20px 18px; display: flex; flex-direction: column; gap: 12px;
}
.modal-box h3 { margin: 0; font-size: 17px; }
.modal-body { font-size: 15px; white-space: pre-line; }
.modal-box .btn-primary { align-self: flex-end; }

/* 상단 버튼 묶음 (학생설정, 학교 변경) */
.top-btns { display: flex; gap: 6px; flex-shrink: 0; }

/* 학생설정 창 */
.stu-desc { margin: 0; color: var(--muted); font-size: 14px; }
.stu-fields { display: flex; gap: 10px; }
.stu-fields label { flex: 1; display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.stu-fields select {
  height: 42px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px;
  background: var(--bg); font-weight: 400;
}
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }

/* 학생시간표: 수업하러 가는 교실(이동반) */
.tt .where {
  display: inline-block; margin-top: 2px; padding: 0 5px; border-radius: 99px;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--primary);
}
@media (prefers-color-scheme: dark) { .tt .where { color: #0d1420; } }
.tt-info { color: var(--muted); font-size: 13px; margin: -4px 0 8px; }

/* 학생시간표 탭의 왼쪽 목록 자리: 설정 내용 */
.stu-card { padding: 12px 6px; display: flex; flex-direction: column; gap: 8px; }
.stu-card b { font-size: 17px; }

/* ───────── 좁은 화면 (휴대폰) ───────── */
@media (max-width: 760px) {
  .side { display: none; }
  .list-select {
    display: block; width: 100%; margin-bottom: 10px; height: 42px;
    border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--surface);
  }
  .toolbar { padding: 8px 16px; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; padding: 7px 4px; }
  .datebar { width: 100%; }
  .datebar input { flex: 1; min-width: 0; }
  .main { padding: 12px 10px 24px; }

  /* 화면 전체 글자: 화면 너비에 따라 13~15px */
  body { font-size: clamp(13px, 3.6vw, 15px); }
  .tabs button { font-size: clamp(12px, 3.5vw, 15px); }
  .tt-title { font-size: clamp(15px, 4.4vw, 18px); }

  /* 표: 주간 표는 가로를 화면 너비에 맞춤(가로 스크롤 없음), 세로는 페이지 스크롤
     학년 표는 학급이 많아 app.js 에서 최소 너비를 주므로 그때만 가로로 밀어서 봄 */
  .tt { min-width: 0; }
  .tt .pcol { width: clamp(30px, 9vw, 46px); }

  /* 머리줄: 날짜와 요일을 두 줄로 */
  .tt thead th { font-size: clamp(10px, 3vw, 14px); padding: 4px 1px; line-height: 1.25; }
  .tt thead th .dw { display: block; }
  .tt thead th .ev { font-size: clamp(8px, 2.4vw, 12px); overflow-wrap: anywhere; }

  /* 교시 칸 */
  .tt tbody th { padding: 3px 1px; }
  .tt tbody th b { font-size: clamp(12px, 3.8vw, 16px); }
  .tt tbody th span { font-size: clamp(7px, 2.2vw, 11px); }

  /* 수업 칸: 글자 크기는 화면 너비에 비례, 긴 과목명은 줄바꿈 */
  .tt td { height: clamp(46px, 13vw, 64px); padding: 3px 1px; font-size: clamp(9px, 3vw, 13px); line-height: 1.25; }
  .tt .subj { overflow-wrap: anywhere; word-break: normal; }
  .tt .sub { font-size: clamp(8px, 2.5vw, 12px); overflow-wrap: anywhere; word-break: normal; }
  .tt .sub .sp { display: block; }   /* 교사, 장소를 한 줄씩 */
  .tt .sub .dot { display: none; }
  .tt td .ev { font-size: clamp(8px, 2.5vw, 12px); overflow-wrap: anywhere; }
  .tt .part + .part { margin-top: 2px; padding-top: 2px; }
  /* 칸 안의 변경 설명은 숨기고, 칸을 누르면 안내창으로 보여줌 */
  .tt .note { display: none; }

  /* 동시/분반 표시: 좁은 칸에서는 글자 위에 겹치지 않게 맨 위에 작게 */
  .tt td.has-mark { padding-top: 3px; }
  .tt .mark { position: static; display: inline-block; font-size: clamp(7px, 2.1vw, 10px); padding: 1px 2px; margin-bottom: 1px; }

  .legend { gap: 10px; font-size: clamp(11px, 3.2vw, 13px); }
  .tt .where { font-size: clamp(9px, 2.7vw, 11px); padding: 0 4px; }
  .top-btns .btn-ghost { padding: 6px 9px; font-size: clamp(12px, 3.5vw, 15px); }
}
