:root {
  --bg: #f3f4f6; --panel: #ffffff; --panel-2: #f7f8fa; --ink: #1b1e26; --muted: #5c6472; --faint: #8b93a2;
  --line: #e3e5ea; --line-strong: #d1d4dc; --accent: #3d5a9c; --accent-ink: #294f96; --accent-soft: #eef1f8;
  --ok: #2f7a57; --ok-soft: #e6f2ec; --warn: #9a6516; --warn-soft: #f6eede; --bad: #a8433a; --bad-soft: #f6e5e3;
  --on-accent: #ffffff;
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(20,24,35,.06), 0 8px 24px rgba(20,24,35,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --panel: #171a21; --panel-2: #1c1f28; --ink: #e7e8ec; --muted: #9aa1af; --faint: #6b7280;
    --line: #282c37; --line-strong: #363b48; --accent: #8aa4de; --accent-ink: #a9bdea; --accent-soft: #1c2334;
    --ok: #5fb58c; --ok-soft: #12291f; --warn: #cf9a4e; --warn-soft: #2a2113; --bad: #d97a6e; --bad-soft: #2c1a17;
    --on-accent: #0f1117;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.55; }
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
h2 { margin: 0; font-size: 17px; }
.hint { font-size: 12px; color: var(--faint); margin: 6px 0; }
.empty { text-align: center; color: var(--faint); font-size: 14px; padding: 32px 0; }
.pre { white-space: pre-line; }

/* 로그인 */
.gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); }
.gate .card { width: min(400px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 30px; box-shadow: var(--shadow); text-align: center; transform: translateY(-7vh); }
.gate h1 { font-size: 20px; margin: 10px 0 6px; }
.gate p { color: var(--muted); font-size: 14px; margin: 6px 0 16px; }
.schoolmark { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--accent-ink); }
.schoolmark.center { justify-content: center; }
.schoolmark::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); flex: 0 0 auto; }

/* 버튼 */
.btn-primary { width: 100%; height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 15px; }
.btn-ghost { height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--muted); padding: 0 14px; font-size: 13px; font-weight: 600; }
.btn-ghost.wide { width: 100%; margin-top: 12px; }

/* 앱 틀 */
.app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(80px + env(safe-area-inset-bottom)); }
header.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; margin: 0 -16px 14px; }
.hleft { display: grid; gap: 2px; }
.hleft .title { font-size: 15px; }
.hright { display: flex; gap: 8px; align-items: center; }
.pc-pill { font-size: 11px; font-family: var(--mono); border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px 8px; }
.pc-pill.on { color: var(--ok); }
.pc-pill.off { color: var(--faint); }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 0 0 auto; height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--muted); font-weight: 600; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

/* 날짜 줄 · 요약 */
.datebar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.nav-btn { width: 40px; height: 40px; flex: 0 0 auto; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 18px; }
.datelabel, .datepick { flex: 1; height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel);
  display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 500; position: relative; }
.datepick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.summary { display: flex; gap: 14px; margin-bottom: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.summary b { font-family: var(--mono); color: var(--ink); }

/* 학생 줄 */
.row { width: 100%; display: grid; grid-template-columns: 2.6ch minmax(4em, 1fr) minmax(0, auto); gap: 10px; align-items: center; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; font-size: 15px; }
button.row:hover { border-color: var(--line-strong); }
.row .tag { white-space: normal; }
.row .no { font-family: var(--mono); color: var(--faint); font-size: 13px; text-align: right; }
.row .nm { font-weight: 600; }
.row .nm small { font-weight: 400; color: var(--faint); margin-left: 4px; }
.row .st { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.row .mini { height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 600; }
.tag { font-size: 11.5px; font-weight: 700; font-family: var(--mono); padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.tag.ok { color: var(--ok); background: var(--ok-soft); }
.tag.warn { color: var(--warn); background: var(--warn-soft); }
.tag.bad { color: var(--bad); background: var(--bad-soft); }
.tag.none { color: var(--faint); background: var(--panel-2); }

/* 기록 카드 · 묶음 */
.grp { margin-bottom: 16px; }
.grp > h3 { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
.g-sum { font-family: var(--mono); font-size: 12px; color: var(--faint); font-weight: 400; }
.crow { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; display: grid; gap: 6px; overflow-wrap: anywhere; }
.c-who { font-weight: 600; }
.c-who small { font-weight: 400; color: var(--faint); }
.c-meta { font-size: 12px; color: var(--faint); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.c-acts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.c-acts button { height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 600; }
.c-acts button.p { color: var(--accent-ink); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.c-acts button.del { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

/* 반영 배너 */
.banner { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.banner .state { font-size: 13px; color: var(--muted); }
.banner .state b { color: var(--ink); }
.banner .hint { margin: 0; }

/* 설정 */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; display: grid; gap: 10px; }
.panel h3 { margin: 0; font-size: 14px; color: var(--muted); }
.panel, .field { grid-template-columns: minmax(0, 1fr); }   /* 긴 프린터 이름이 화면 밖으로 밀지 않게 */
.field select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.panel input[type="file"] { max-width: 100%; }
#roster-list, #roster-preview { overflow-x: auto; }
.field { display: grid; gap: 6px; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input[type="text"], .field input[type="number"], .field input[type="time"], .field select, .field textarea, .dates input {
  height: 44px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel-2); color: var(--ink); font-size: 14px; padding: 0 12px; }
.field textarea { height: auto; padding: 10px 12px; resize: vertical; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.toggle input { width: 20px; height: 20px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
th { background: var(--panel-2); font-weight: 600; color: var(--muted); font-size: 12px; }

/* 세그먼트 · 칩 */
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; height: 40px; border: 0; border-right: 1px solid var(--line); background: var(--panel); color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel); color: var(--muted); font-weight: 600; font-size: 13px; }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* 시트 */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: end center; background: rgba(10,13,18,.4); }
.sheet { width: min(480px, 100vw); background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 14px; box-shadow: var(--shadow); max-height: 90vh; max-height: 90dvh; overscroll-behavior: contain; overflow-y: auto; }
@media (min-width: 560px) { .modal { place-items: center; } .sheet { border-radius: 18px; } }
.sheet .sub { font-size: 13px; color: var(--muted); }
.sheet details summary { font-size: 13px; color: var(--muted); font-weight: 600; cursor: pointer; }
.sheet details[open] { display: grid; gap: 10px; }
.dates { display: flex; gap: 6px; align-items: center; }
.dates input { flex: 1; min-width: 0; font-family: var(--mono); }
.prev { background: var(--accent-soft); color: var(--accent-ink); border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 14px; }
.err { border: 1px solid var(--bad); background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; white-space: pre-line; }
.add { height: 44px; border: 1px dashed var(--line-strong); border-radius: 12px; background: transparent; color: var(--accent-ink); font-weight: 700; font-size: 14px; }
.actions { display: flex; gap: 8px; }
.actions button { flex: 1; height: 46px; border-radius: 12px; font-weight: 700; font-size: 14px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink); }
.actions button.save { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* 알림 */
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  font-size: 13px; padding: 10px 16px; border-radius: 10px; max-width: 90vw; z-index: 40; box-shadow: var(--shadow); }

/* 통계 */
#tab-stats > .seg { margin-bottom: 10px; }
.statbar { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; margin-bottom: 10px; }
.statbar .datebar { margin: 0; }
.statbar #st-term-ctl .hint { margin: 6px 0 0; }
.statbar #st-export { height: 40px; color: var(--accent-ink); }
.alert { border: 1px solid var(--bad); background: var(--bad-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 4px; font-size: 13px; }
.alert .a-head { font-weight: 700; color: var(--bad); }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.cards .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; text-align: center; }
.cards .card b { display: block; font-family: var(--mono); font-size: 18px; }
.cards .card span { font-size: 11px; color: var(--muted); }
#st-filter { margin-bottom: 10px; }
.twrap { border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; background: var(--panel); }
#st-table th, #st-table td { text-align: center; padding: 7px 6px; white-space: nowrap; }
#st-table th.l, #st-table td.l { text-align: left; font-weight: 600; }
#st-table td:first-child { font-family: var(--mono); color: var(--faint); }
#st-table td small { display: block; font-size: 10px; color: var(--faint); font-family: var(--mono); line-height: 1.1; }
#st-table td .z { color: var(--line-strong); }
#st-table tbody tr { cursor: pointer; }
#st-table tr.flag td { background: var(--bad-soft); }
