:root {
  --bg: #FAF7F2;
  --ink: #2E2A26;
  --ink-soft: #6B6459;
  --line: #E7E0D4;
  --card: #FFFFFF;
  --brand: #4A3A6E;
  --brand-soft: #EFE9F5;
  --danger: #C5533F;
  --warn: #E3A93C;
  --present: #6FA671;
  --late: #E3A93C;
  --absent: #C5533F;
  --g1: #4E8FC4;
  --g1-soft: #E7F0F8;
  --g2: #6B5B95;
  --g2-soft: #EFEAF5;
  --g3: #A9743C;
  --g3-soft: #F5EEE2;
  --new: #4C9A6B;
  --new-soft: #E6F3EB;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body { min-height: 100dvh; padding-bottom: calc(24px + var(--safe-bottom)); }

button { font-family: inherit; cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: rgba(250,247,242,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  font-size: 18px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  flex: 1;
  text-align: center;
}

.back-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hidden { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}

/* ---------- Home ---------- */
.home-intro { padding: 4px 2px 18px; }
.home-intro .eyebrow {
  font-size: 12px; font-weight: 700; color: var(--brand);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.home-intro h2 { font-size: 21px; margin: 6px 0 4px; letter-spacing: -0.02em; }
.home-intro p { margin: 0; color: var(--ink-soft); font-size: 13.5px; line-height: 1.5; }

.grade-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.grade-card {
  position: relative;
  border: none;
  border-radius: var(--radius);
  padding: 18px 18px;
  text-align: left;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 14px;
}
.grade-card::before {
  content: ""; position: absolute; inset: 0; opacity: 0.10; background: var(--accent);
}
.grade-card .mark {
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; flex-shrink: 0; position: relative;
}
.grade-card .info { position: relative; flex: 1; }
.grade-card .name { font-weight: 800; font-size: 16.5px; }
.grade-card .count { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.grade-card .chev { color: var(--ink-soft); font-size: 16px; position: relative; }

.section-label {
  font-size: 12px; font-weight: 700; color: var(--ink-soft);
  margin: 18px 2px 8px; text-transform: uppercase; letter-spacing: 0.03em;
  display: flex; align-items: center; justify-content: space-between;
}

.list-card { background: var(--card); border-radius: 16px; border: 1px solid var(--line); overflow: hidden; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px;
  border-bottom: 1px solid var(--line); width: 100%; border-left: none; border-right: none; border-top: none;
  background: transparent; text-align: left;
}
.list-row:last-child { border-bottom: none; }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .row-title { font-weight: 700; font-size: 15px; }
.list-row .row-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.chev { color: var(--ink-soft); font-size: 15px; }

.fab-row { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  border: none; border-radius: 14px; padding: 13px 16px; font-weight: 700;
  font-size: 14.5px; background: var(--brand); color: #fff; flex: 1;
}
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.outline { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-small { border: none; border-radius: 10px; padding: 7px 12px; font-size: 12.5px; font-weight: 700; background: var(--brand); color: #fff; }
.btn-small.ghost { background: transparent; color: var(--ink-soft); }

/* ---------- Class / roster ---------- */
.grade-banner {
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  background: var(--accent); color: #fff; display: flex; align-items: center; gap: 12px;
}
.grade-banner .mark {
  width: 42px; height: 42px; border-radius: 12px; background: rgba(255,255,255,0.22);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px; flex-shrink: 0;
}
.grade-banner .title { font-weight: 800; font-size: 16.5px; }
.grade-banner .sub { font-size: 12px; opacity: 0.88; margin-top: 2px; }

.newcomer-row .row-title::after {
  content: "새가족"; margin-left: 6px; font-size: 10.5px; font-weight: 800; color: #fff;
  background: var(--new); padding: 2px 7px; border-radius: 999px; vertical-align: middle;
}

.date-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.date-bar input[type="date"] {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13.5px; background: #fff; color: var(--ink);
}
.stat-pill { font-size: 12px; font-weight: 700; color: var(--ink-soft); }

.student-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.student-row:last-child { border-bottom: none; }
.student-row .name-block { flex: 1; min-width: 0; }
.student-row .s-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.student-row .s-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.streak-badge {
  font-size: 10.5px; font-weight: 800; color: #fff; background: var(--danger); padding: 2px 7px; border-radius: 999px;
}
.flag-badge {
  font-size: 10.5px; font-weight: 800; color: #fff; padding: 2px 7px; border-radius: 999px;
}
.flag-badge.urgent { background: var(--danger); }
.flag-badge.caution { background: var(--warn); }
.nb-badge {
  font-size: 10.5px; font-weight: 800; color: var(--new); background: var(--new-soft); padding: 2px 7px; border-radius: 999px;
}
.att-toggle {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 12.5px; font-weight: 800;
  background: #fff; color: var(--ink-soft); min-width: 56px; text-align: center; flex-shrink: 0;
}
.att-toggle[data-status="present"] { background: var(--present); border-color: var(--present); color: #fff; }
.att-toggle[data-status="late"] { background: var(--late); border-color: var(--late); color: #fff; }
.att-toggle[data-status="absent"] { background: var(--absent); border-color: var(--absent); color: #fff; }

.milestone-row { display: flex; gap: 6px; margin-top: 6px; }
.milestone-btn {
  border: 1.5px solid var(--line); border-radius: 999px; padding: 4px 9px; font-size: 10.5px; font-weight: 700;
  background: #fff; color: var(--ink-soft);
}
.milestone-btn.done { background: var(--new-soft); border-color: var(--new); color: var(--new); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: #fff;
  color: var(--ink-soft); font-size: 14px; flex-shrink: 0;
}
.icon-btn.has-mark { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty-state .mark { font-size: 32px; margin-bottom: 10px; }
.empty-state p { font-size: 13.5px; line-height: 1.5; margin: 0 0 14px; }

/* ---------- Care list (심방 우선순위) ---------- */
.care-card {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--danger);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; width: 100%; text-align: left;
}
.care-card .c-name { font-weight: 800; font-size: 14.5px; }
.care-card .c-info { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }

/* ---------- Student detail ---------- */
.student-banner {
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px; background: var(--brand-soft);
}
.student-banner .name { font-size: 19px; font-weight: 800; }
.student-banner .meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; line-height: 1.7; }
.student-banner .meta div { display: flex; gap: 6px; }
.student-banner .meta b { color: var(--ink); font-weight: 700; min-width: 62px; flex-shrink: 0; }

.visit-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.visit-card .v-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.visit-card .v-date { font-weight: 800; font-size: 13.5px; }
.visit-card .v-teacher { font-size: 12px; color: var(--ink-soft); }
.visit-card .v-q { font-size: 13px; margin-top: 6px; line-height: 1.5; }
.visit-card .v-q b { color: var(--brand); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(30,25,20,0.4); display: flex; align-items: flex-end; z-index: 50; }
.modal-sheet {
  background: #fff; width: 100%; max-width: 560px; margin: 0 auto; border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom)); max-height: 88vh; overflow-y: auto;
}
.modal-sheet h3 { margin: 0 0 14px; font-size: 17px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); margin-bottom: 6px; }
.field input[type="text"], .field input[type="tel"], .field input[type="date"], .field input[type="number"],
.field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 14.5px;
  font-family: inherit; background: #FBF9F5; color: var(--ink);
}
.field textarea { min-height: 60px; resize: vertical; }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 700;
  background: #fff; color: var(--ink-soft);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.flag-group { display: flex; gap: 8px; }
.flag-group .chip { flex: 1; text-align: center; }
.flag-group .chip[data-flag="주의"].on { background: var(--warn); border-color: var(--warn); }
.flag-group .chip[data-flag="긴급"].on { background: var(--danger); border-color: var(--danger); }

.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn.danger-text { background: #fff; color: var(--danger); border: 1px solid var(--line); flex: 0 0 auto; }

.toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: #2E2A26; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 60;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2); max-width: 88vw; text-align: center;
}

.install-banner {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; background: var(--brand); color: #fff; padding: 10px 14px; font-size: 12.5px;
  padding-top: calc(10px + var(--safe-top));
}
.install-banner-actions { display: flex; gap: 6px; flex-shrink: 0; }
.install-banner .btn-small { background: #fff; color: var(--brand); }
.install-banner .btn-small.ghost { background: transparent; color: rgba(255,255,255,0.85); }

.sync-banner {
  position: sticky; top: 0; z-index: 25; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; background: #FBE8C8; color: #7A4A0B; padding: 9px 14px; font-size: 12px; font-weight: 600;
}
.sync-banner .btn-small { background: #7A4A0B; color: #fff; flex-shrink: 0; }

.sync-status-line { font-size: 12px; color: var(--ink-soft); margin: 8px 0 0; }

/* ---------- 반별 출석 비교표 ---------- */
.report-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 420px; }
.report-table th {
  text-align: left; font-size: 10.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase;
  padding: 6px 8px; border-bottom: 1.5px solid var(--line); position: sticky; top: 0; background: var(--bg);
}
.report-table th.num, .report-table td.num { text-align: right; }
.report-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); background: var(--card); }
.report-table tr:hover td { background: var(--brand-soft); cursor: pointer; }
.report-grade-head td {
  background: var(--brand); color: #fff; font-weight: 800; font-size: 11.5px; padding: 6px 8px; cursor: default;
}
.report-grade-head:hover td { background: var(--brand); }
.report-total-row td { background: var(--brand-soft); font-size: 13px; cursor: default; }
.report-total-row:hover td { background: var(--brand-soft); }

/* ---------- 출석 빠른 수정 시트 ---------- */
.att-sheet h3 { text-align: center; }
.att-picker { display: flex; gap: 10px; margin: 6px 0 14px; }
.att-pick {
  flex: 1; border: 1.5px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink-soft);
  padding: 16px 8px; font-size: 13px; font-weight: 700; line-height: 1.6; text-align: center;
}
.att-pick[data-status="present"].active,
.att-pick[data-status="present"]:active { background: var(--present); border-color: var(--present); color: #fff; }
.att-pick[data-status="late"].active,
.att-pick[data-status="late"]:active { background: var(--late); border-color: var(--late); color: #fff; }
.att-pick[data-status="absent"].active,
.att-pick[data-status="absent"]:active { background: var(--absent); border-color: var(--absent); color: #fff; }
.att-clear-btn { width: 100%; color: var(--ink-soft); }
