:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d9dee7;
  --primary: #2457c5;
  --ok: #10834d;
  --bad: #c53434;
  --warn: #b86610;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: 212px;
  padding: 20px 14px;
  background: #202734;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.nav strong { font-size: 18px; margin: 2px 8px 12px; }
.nav a, .nav button {
  color: #fff;
  text-decoration: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.nav a:hover, .nav button:hover { background: rgba(255,255,255,.12); }
.nav form { margin-top: auto; }

.content { margin-left: 212px; padding: 28px; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; }

h1 { margin: 0 0 20px; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 18px; }
section, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; background: transparent; border: 0; padding: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.stats b { display: block; font-size: 28px; }
.stats span { color: var(--muted); font-size: 13px; }

form { margin: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.toolbar label {
  min-width: 180px;
  margin: 0;
}
.toolbar label.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
}
.toolbar label.month-field {
  display: inline-grid;
  grid-template-columns: max-content 110px;
  align-items: center;
  column-gap: 8px;
  min-width: max-content;
  white-space: nowrap;
  word-break: keep-all;
}
.toolbar label.month-field span {
  display: inline-block;
  white-space: nowrap;
  word-break: keep-all;
}
.toolbar label.month-field input {
  width: 110px;
  min-width: 110px;
}
.toolbar label.inline-field select {
  width: auto;
  min-width: 140px;
}
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}
.tabs a:hover {
  color: var(--ink);
  background: #eef1f6;
}
.tabs a.active {
  color: var(--primary);
  background: var(--panel);
  border-color: var(--line);
  font-weight: 700;
}
label { display: grid; gap: 6px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.check { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 8px; margin: 0; }
.toolbar label.compact-check {
  min-width: 0;
  width: auto;
  gap: 4px;
  white-space: nowrap;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.toolbar.date-lookup-toolbar {
  display: inline-flex;
  flex-wrap: nowrap;
  width: max-content;
  max-width: 100%;
}
.toolbar.date-lookup-toolbar > input.date-lookup-input {
  flex: 0 0 150px;
  width: 150px;
  min-width: 150px;
  max-width: 150px;
}
.toolbar.date-lookup-toolbar > select.class-lookup-select {
  flex: 0 0 190px;
  width: 190px;
  min-width: 190px;
  max-width: 190px;
}
.toolbar.date-lookup-toolbar > input.student-lookup-input {
  flex: 0 0 220px;
  width: 220px;
  min-width: 220px;
  max-width: 220px;
}
.toolbar.date-lookup-toolbar > select.student-status-filter {
  flex: 0 0 100px;
  width: 100px;
  min-width: 100px;
  max-width: 100px;
}
textarea { resize: vertical; }
button {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
button:disabled {
  cursor: not-allowed;
  opacity: .55;
}
button.ghost { background: transparent; }
button.secondary { background: #4b5563; }
button.ghost-light { background: #e5e7eb; color: var(--ink); }
button.icon-button { background: transparent; color: var(--muted); padding: 6px 8px; }
.error { color: var(--bad); }
.ok { color: var(--ok); }
.warn { color: var(--warn); font-weight: 700; }
.hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }
.checkbox-grid { flex-basis: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.muted { color: var(--muted); }
.message-preview {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}
.message-result-list {
  display: grid;
  gap: 4px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.message-result-list span {
  white-space: nowrap;
}
.table-scroll-hint {
  display: none;
}
.message-history-scroll {
  overflow-x: auto;
}
.attendance-table-scroll {
  overflow-x: auto;
}
.message-targets {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px 10px;
  width: max-content;
  max-width: 100%;
  margin-bottom: 10px;
  overflow-x: auto;
}
.message-targets label {
  display: inline-grid;
  grid-template-columns: max-content max-content;
  align-items: center;
  flex: none;
  width: auto;
  min-width: max-content;
  margin: 0;
  white-space: nowrap;
  word-break: keep-all;
}
.message-targets label span {
  display: inline-block;
  white-space: nowrap;
  word-break: keep-all;
}
.message-targets input[type="radio"] {
  flex: none;
  width: auto;
  min-width: 0;
}
.message-targets select {
  flex: none;
  width: auto;
  min-width: 160px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.student-list td { white-space: nowrap; }
.list-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 12px;
}
.assignment-board {
  table-layout: fixed;
}
.assignment-help {
  margin: -4px 0 12px;
}
.assignment-board th:first-child {
  width: 130px;
}
.assignment-cell {
  min-width: 150px;
  min-height: 82px;
  height: 82px;
  background: #fff;
  transition: background .15s ease, outline-color .15s ease;
}
.assignment-cell.empty {
  background: #f1f3f7;
}
.assignment-cell.drag-over {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
  background: #eef4ff;
}
.assignment-cell.drop-eligible {
  outline: 2px dashed var(--primary);
  outline-offset: -3px;
  cursor: pointer;
}
.assigned-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 30px;
  align-items: flex-start;
}
.student-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f1ff;
  color: #17448d;
  font-size: 13px;
  overflow-wrap: anywhere;
  cursor: grab;
  user-select: none;
}
.student-chip:active,
.student-card:active {
  cursor: grabbing;
}
.student-chip.dragging,
.student-card.dragging {
  opacity: .55;
}
.student-chip.selected-source,
.student-card.selected-source {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.assignment-cell small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}
.student-card-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.student-card {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}
.student-card:active {
  cursor: grabbing;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}
th { background: #edf0f5; color: #374151; }
td form { display: flex; gap: 6px; align-items: center; }
.badge { display: inline-block; min-width: 44px; text-align: center; padding: 4px 8px; border-radius: 999px; font-size: 12px; color: #fff; }
.badge.출석, .badge.보강 { background: var(--ok); }
.badge.결석 { background: var(--bad); }

.kiosk-shell {
  width: 100%;
  height: 100dvh;
  padding: clamp(20px, 3vw, 48px);
  overflow: hidden;
}
.kiosk {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(480px, 6fr);
  gap: clamp(24px, 4vw, 64px);
  width: 100%;
  height: 100%;
  margin: 0;
  padding: clamp(24px, 4vw, 64px);
  text-align: center;
  background: var(--panel);
}
.kiosk-status {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.kiosk-label {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: clamp(12px, 1.1vw, 18px);
  font-weight: 700;
  letter-spacing: .16em;
}
.kiosk h1 {
  margin: 0 0 8px;
  font-size: clamp(36px, 4.2vw, 68px);
  line-height: 1.1;
}
.kiosk time {
  margin: 0 0 clamp(24px, 4vh, 48px);
  color: var(--muted);
  font-size: clamp(15px, 1.4vw, 22px);
  font-weight: 600;
  line-height: 1.4;
  word-break: keep-all;
}
.kiosk output {
  display: block;
  min-height: 1.4em;
  color: var(--ink);
  font-size: clamp(26px, 3vw, 48px);
  font-weight: 700;
  line-height: 1.4;
  word-break: keep-all;
}
#digits {
  min-height: 1.4em;
  margin-top: 12px;
  color: var(--primary);
  font-size: clamp(40px, 5vw, 76px);
  font-weight: 700;
  letter-spacing: .18em;
  line-height: 1.4;
}
.kiosk-help {
  margin: clamp(16px, 3vh, 32px) 0 0;
  color: var(--muted);
  font-size: clamp(14px, 1.35vw, 20px);
  word-break: keep-all;
}
.keypad {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(10px, 1.4vw, 20px);
}
.keypad button {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 8px;
  font-size: clamp(28px, 3vw, 48px);
  background: #202734;
  transition: background .15s ease, transform .15s ease;
}
.keypad button:hover { background: var(--primary); }
.keypad button:active { transform: scale(.98); }
.keypad button:focus-visible { outline: 4px solid var(--primary); outline-offset: 3px; }

dialog.modal {
  width: min(760px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
}
dialog.modal::backdrop { background: rgba(17, 24, 39, .52); }
.modal-panel { display: block; padding: 0; }
.modal-panel header, .modal-panel footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-panel footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}
.modal-panel h2 { margin: 0; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
  padding: 18px;
}
.attendance-no-feedback { display: block; padding: 0 18px 14px; }

@media (max-width: 820px) {
  .nav {
    position: fixed;
    inset: auto 0 0 0;
    width: auto;
    height: 64px;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
    z-index: 10;
  }
  .nav strong, .nav form { display: none; }
  .nav a {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .content { margin: 0 0 64px; padding: 16px; }
  .split { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
  .attendance-table-scroll table {
    display: table;
    overflow: visible;
  }
  .attendance-table-scroll th,
  .attendance-table-scroll td {
    white-space: nowrap;
    word-break: keep-all;
  }
  .attendance-status-table { min-width: 820px; }
  .makeup-status-table { min-width: 560px; }
  .attendance-table-scroll .teacher-attendance-table { min-width: 760px; }
  .table-scroll-hint {
    display: block;
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 13px;
  }
  .message-history-scroll table {
    display: table;
    min-width: 900px;
    overflow: visible;
  }
}

@media (min-width: 521px) and (max-width: 820px) {
  .kiosk {
    grid-template-columns: minmax(200px, 1fr) minmax(0, 2.2fr);
    gap: 16px;
    padding: 30px;
  }
  .kiosk h1, .kiosk output { white-space: nowrap; }
}

@media (max-width: 520px) {
  .toolbar.student-search-toolbar {
    width: 100%;
    flex-wrap: wrap;
  }
  .toolbar.student-search-toolbar > input.student-lookup-input {
    flex: 1 0 100%;
    width: 100%;
    max-width: none;
  }
  .kiosk-shell {
    height: auto;
    min-height: 100dvh;
    padding: 12px;
    overflow: auto;
  }
  .kiosk {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr);
    gap: 16px;
    height: auto;
    min-height: calc(100dvh - 24px);
    padding: 16px;
  }
  .kiosk-label { margin-bottom: 4px; }
  .kiosk h1 { font-size: 36px; }
  .kiosk time { margin-bottom: 12px; }
  .kiosk output { font-size: 24px; }
  #digits {
    margin-top: 4px;
    font-size: 40px;
  }
  .kiosk-help { margin-top: 8px; }
}

.message-compose { display: grid; gap: 12px; }
.message-compose .check { display: flex; justify-content: flex-start; }
.message-compose input[type="checkbox"] { width: auto; flex: 0 0 auto; margin: 0; }
.message-compose .check span { min-width: 0; }
.message-student-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.message-student-list label { padding: 6px 0; overflow-wrap: anywhere; }
#message-variables { display: grid; gap: 12px; }
#message-preview { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 12px; margin: 0; }
.message-error { color: var(--bad); }
