:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E2E6EC;
  --border-strong: #CBD2DB;
  --text: #1F2933;
  --muted: #6B7785;
  --primary: #3D63DD;
  --primary-hover: #2F50BC;
  --danger: #D64545;
  --grid-line: #EEF1F5;
  --grid-line-strong: #DDE2E9;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color: var(--text);
  font-size: 14px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- 상단 바 ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; font-size: 17px; text-decoration: none; color: var(--primary); white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 4px; overflow-x: auto; min-width: 0; }
.nav a {
  padding: 8px 12px; border-radius: 6px; text-decoration: none; color: var(--muted);
  white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: #E8EEFF; color: var(--primary); }
.nav-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex: none; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; flex: none; }
.user-name { color: var(--muted); font-weight: 500; white-space: nowrap; }

/* ---------- 로그인 ---------- */
.auth { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.auth-brand { font-weight: 800; font-size: 22px; color: var(--primary); text-align: center; }
.auth-card h1 { text-align: center; margin: 4px 0 0; }
.auth-card .sub { margin: 0 0 4px; color: var(--muted); text-align: center; line-height: 1.5; }
.auth-card .btn.primary { padding: 10px 14px; margin-top: 4px; }

/* ---------- 계정 ---------- */
.account-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 20px;
}
.account-name { font-weight: 700; font-size: 16px; margin-bottom: 2px; }
.section-head { margin-top: 32px; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12.5px; background: #F0F3F7; }
.role-badge.admin { background: #E8EEFF; color: var(--primary); font-weight: 600; }
.field .readonly-value { font-weight: 400; font-size: 14px; padding: 7px 0; }

/* ---------- 페이지 ---------- */
.view { padding: 24px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.picker { display: flex; align-items: center; gap: 8px; }
.picker select { font-size: 16px; font-weight: 600; padding: 6px 10px; min-width: 200px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

.empty {
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 48px 24px; text-align: center; color: var(--muted);
}
.empty p { margin: 0 0 16px; }

/* ---------- 버튼 / 입력 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #F0C2C2; }
.btn.danger:hover { background: #FDF1F1; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.icon-btn {
  border: none; background: none; font-size: 20px; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

input, select, textarea {
  font: inherit; color: inherit; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface);
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #BFD0FF; border-color: var(--primary); }
textarea { resize: vertical; }
.search { width: 220px; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: var(--surface); padding: 7px 12px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.active { background: var(--primary); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

/* ---------- 시간표 ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font: inherit; font-size: 13px; cursor: pointer;
}
.legend-item small { color: var(--muted); }
.legend-item.active { border-color: var(--text); font-weight: 600; }
.legend-item.dim { opacity: 0.45; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }

.tt-scroll {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.tt {
  display: grid;
  grid-template-columns: 56px repeat(var(--cols), minmax(118px, 1fr));
  grid-template-rows: 40px var(--body-h);
  min-width: fit-content;
}
.tt-corner, .tt-dayhead {
  position: sticky; top: 0; background: var(--surface); z-index: 2;
  border-bottom: 1px solid var(--border-strong);
}
.tt-dayhead {
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; border-left: 1px solid var(--border);
}
.tt-dayhead.weekend { color: #C0392B; }
.tt-dayhead.today { background: #EEF3FF; color: var(--primary); }
.tt-times { position: sticky; left: 0; z-index: 2; background: var(--surface); }
.tt-corner { left: 0; z-index: 3; }
.tt-hour {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.tt-hour:first-child { transform: none; top: 2px !important; }
.tt-col {
  position: relative; border-left: 1px solid var(--border);
  background-image:
    linear-gradient(to bottom, var(--grid-line-strong) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 100% 60px, 100% 30px;
}
.tt-col.clickable { cursor: copy; }
.tt-col.clickable:hover { background-color: #FAFBFE; }

.tt-block {
  position: absolute; padding: 0 2px; margin: 0; border: none; background: none;
  font: inherit; text-align: left; cursor: pointer; z-index: 1;
  display: flex; flex-direction: column; gap: 1px;
}
.tt-block::before {
  content: ""; position: absolute; inset: 1px 1px 1px 1px;
  background: #fff linear-gradient(var(--tint), var(--tint));
  border-left: 4px solid var(--c); border-radius: 5px;
  box-shadow: inset 0 0 0 1px var(--c);
  z-index: -1;
}
.tt-block > span { position: relative; padding-left: 9px; padding-right: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-block .tt-name { font-weight: 700; font-size: 12.5px; padding-top: 5px; }
.tt-block .tt-time { font-size: 11.5px; color: #3E4C59; font-variant-numeric: tabular-nums; }
.tt-block .tt-meta { font-size: 11.5px; color: #52606D; }
.tt-block:hover { z-index: 3; }
.tt-block:hover::before { box-shadow: inset 0 0 0 2px var(--c), 0 4px 10px rgba(16, 24, 40, 0.15); }
.tt-block.compact { flex-direction: row; align-items: center; gap: 0; }
.tt-block.compact .tt-name { padding-top: 0; }
.tt-block.compact .tt-time { padding-left: 2px; }
.tt-block.compact .tt-meta { display: none; }
.tt-block.dim { opacity: 0.25; }
.tt-now { position: absolute; left: 0; right: 0; height: 2px; background: #E5484D; z-index: 2; pointer-events: none; }
.tt-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #E5484D; }

/* ---------- 표 ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #FAFBFC; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #FAFBFE; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .name { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.table .memo { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .chips { min-width: 180px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: 4px; }
.chip {
  display: inline-block; padding: 2px 8px; margin: 2px 4px 2px 0; border-radius: 4px;
  background: #F0F3F7; font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* ---------- 다이얼로그 ---------- */
.dialog {
  border: none; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.25); color: var(--text);
}
.dialog.wide { width: min(800px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.field em { color: var(--danger); font-style: normal; }
.field input, .field select, .field textarea { font-weight: 400; font-size: 14px; }
.field-head { display: flex; justify-content: space-between; align-items: center; }
.field .hint { font-weight: 400; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.form-error {
  margin: 0; padding: 10px 12px; border-radius: 6px; background: #FDF1F1; color: #A61B1B;
  white-space: pre-line; font-size: 13px;
}

.color-field { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch-btn { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1); }
.swatch-btn.selected { border-color: var(--text); box-shadow: inset 0 0 0 2px #fff; }
.custom-color input { width: 40px; height: 30px; padding: 2px; cursor: pointer; }

.session-rows { display: flex; flex-direction: column; gap: 8px; }
.session-row {
  display: grid; align-items: center; gap: 6px;
  grid-template-columns: 84px 118px auto 118px minmax(120px, 1fr) minmax(90px, 0.8fr) auto;
}
.session-row .tilde { color: var(--muted); }
.session-row input, .session-row select { font-weight: 400; padding: 6px 8px; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1F2933; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #B42318; }
.toast.success { background: #146C43; }

/* ---------- 반응형 ---------- */
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 12px; }
  .view { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .session-row { grid-template-columns: 1fr 1fr auto 1fr; }
  .session-row [name=teacher], .session-row [name=room] { grid-column: span 2; }
  .session-row [data-remove-row] { grid-column: 4; justify-self: end; grid-row: 1; }
  .search { width: 100%; }
  .user-name { display: none; }
  .auth { min-height: auto; padding-top: 24px; }
}

/* ---------- 인쇄 ---------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; }
  .topbar, .no-print, .toast { display: none !important; }
  .view { padding: 0; max-width: none; }
  .picker select { border: none; appearance: none; padding: 0; }
  .tt-scroll { overflow: visible; box-shadow: none; }
  .tt { grid-template-columns: 40px repeat(var(--cols), 1fr); }
  .tt-block, .swatch, .tt-block::before { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tt-now { display: none; }
}
