:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #687089;
  --line: #e3e7ef;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --primary-bg: #eaf1ff;
  --accent: #f97316;
  --in: #16a34a;
  --in-bg: #e7f7ed;
  --out: #2563eb;
  --out-bg: #e8f0ff;
  --none: #8a92a6;
  --none-bg: #f0f2f6;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(20, 30, 60, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  word-break: keep-all;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }

/* ---------- 레이아웃 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.brand img { width: 34px; height: 34px; }
.brand small { display: block; font-weight: 500; font-size: .75rem; color: var(--muted); }
.topbar .spacer { flex: 1; }
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }
.narrow { max-width: 560px; }
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 1.15rem; }

/* ---------- 버튼/입력 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; min-height: 42px;
  border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-in { background: var(--in); border-color: var(--in); color: #fff; }
.btn-out { background: var(--out); border-color: var(--out); color: #fff; }
.btn-danger { color: var(--danger); border-color: #f3c4c4; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; border-radius: 10px; }
.btn-block { width: 100%; }

.input, select.input, textarea.input {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; background: #fff; color: var(--text);
}
.input:focus { outline: 2px solid var(--primary-bg); border-color: var(--primary); }
textarea.input { min-height: 120px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

/* ---------- 상태 배지 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.badge.in { background: var(--in-bg); color: var(--in); }
.badge.out { background: var(--out-bg); color: var(--out); }
.badge.none { background: var(--none-bg); color: var(--none); }
.tag { background: #fff1e6; color: var(--accent); border-radius: 6px; padding: 1px 6px; font-size: .75rem; font-weight: 700; }

/* ---------- 홈 ---------- */
.hero {
  background: linear-gradient(135deg, #2563eb, #4f46e5 60%, #7c3aed);
  color: #fff; border-radius: 24px; padding: 32px 24px; margin-bottom: 20px;
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px;
  width: 220px; height: 220px; border-radius: 50%; background: rgba(255, 255, 255, .1);
}
.hero h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); margin-bottom: 6px; }
.hero p { margin: 0; opacity: .9; }
.hero .today { display: inline-block; margin-top: 14px; background: rgba(255, 255, 255, .18); padding: 4px 12px; border-radius: 999px; font-size: .9rem; }
.menu-card { display: block; color: var(--text); transition: transform .15s, box-shadow .15s; }
.menu-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(20, 30, 60, .1); }
.menu-card .ico { font-size: 2rem; }
.menu-card h3 { margin: 8px 0 4px; }
.menu-card p { margin: 0; color: var(--muted); font-size: .92rem; }

/* ---------- 공지 ---------- */
.notice { border: 1px solid var(--line); border-radius: 12px; padding: 0; margin-bottom: 10px; background: #fff; }
.notice.pinned { border-color: #fed7aa; background: #fffaf5; }
.notice summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.notice summary::-webkit-details-marker { display: none; }
.notice-title { font-weight: 700; flex: 1; min-width: 160px; }
.notice-date { color: var(--muted); font-size: .8rem; }
.notice-body { padding: 0 16px 16px; white-space: pre-wrap; color: #3a4256; }
.media { padding: 0 16px 16px; display: grid; gap: 10px; }
.media-grid { display: grid; gap: 6px; grid-template-columns: repeat(3, 1fr); }
.media-grid.n1 { grid-template-columns: 1fr; }
.media-grid.n2 { grid-template-columns: 1fr 1fr; }
.media-grid a { display: block; border-radius: 10px; overflow: hidden; background: var(--none-bg); aspect-ratio: 4 / 3; }
.media-grid.n1 a { aspect-ratio: auto; }
.media-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid.n1 img { height: auto; max-height: 520px; object-fit: contain; }
.media-video { width: 100%; max-height: 520px; border-radius: 10px; background: #000; }
.media-embed { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: #000; }
.media-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.media-tag { background: var(--primary-bg); color: var(--primary); }
.media-edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 8px; }
.media-edit .mi { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--none-bg); display: grid; place-items: center; font-size: .75rem; color: var(--muted); text-align: center; }
.media-edit .mi img, .media-edit .mi video { width: 100%; height: 100%; object-fit: cover; }
.media-edit .mi .kind { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px; padding: 0 6px; font-size: .7rem; }
.media-edit .mi button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; }
.upload-btn { position: relative; overflow: hidden; }
.upload-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--in); font-weight: 600; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--in); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- 학부모 ---------- */
.child-card { position: relative; }
.child-status {
  display: flex; align-items: center; gap: 14px;
  padding: 18px; border-radius: 14px; margin: 12px 0;
}
.child-status.in { background: var(--in-bg); }
.child-status.out { background: var(--out-bg); }
.child-status.none { background: var(--none-bg); }
.child-status .big { font-size: 2.4rem; line-height: 1; }
.child-status .st { font-size: 1.25rem; font-weight: 800; }
.child-status.in .st { color: var(--in); }
.child-status.out .st { color: var(--out); }
.child-status.none .st { color: var(--none); }
.times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.times div { background: #f8f9fc; border-radius: 12px; padding: 10px 12px; }
.times b { display: block; font-size: 1.2rem; }
.log-list { list-style: none; margin: 12px 0 0; padding: 0; }
.log-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.log-day { font-size: .8rem; color: var(--muted); font-weight: 700; margin-top: 12px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; padding: 10px 0 12px;
  font: inherit; font-size: .8rem; color: var(--muted); cursor: pointer; position: relative;
}
.tabbar button .i { display: block; font-size: 1.35rem; }
.tabbar button.active { color: var(--primary); font-weight: 700; }
.dot-badge { position: absolute; top: 6px; left: 55%; background: var(--danger); color: #fff; border-radius: 999px; font-size: .65rem; padding: 0 5px; }

/* ---------- 관리자 ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs button {
  border: 0; background: none; padding: 12px 16px; font: inherit; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.stat b { display: block; font-size: 1.9rem; line-height: 1.1; }
.stat.in b { color: var(--in); }
.stat.out b { color: var(--out); }
.stat.none b { color: var(--none); }
.stu {
  border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #fff;
  border-left: 5px solid var(--none);
}
.stu.in { border-left-color: var(--in); }
.stu.out { border-left-color: var(--out); }
.stu .name { font-weight: 800; font-size: 1.05rem; }
.stu .meta { font-size: .8rem; color: var(--muted); margin: 2px 0 8px; }
.stu .actions { display: flex; gap: 6px; margin-top: 10px; }
.stu .actions .btn { flex: 1; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto; }
.feed li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.feed time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 46px; }
.dash { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .dash { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
td code { background: var(--primary-bg); color: var(--primary-d); padding: 2px 6px; border-radius: 6px; font-weight: 700; letter-spacing: .5px; }

dialog { border: 0; border-radius: 18px; padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(15, 20, 35, .45); }
.qr-box { display: flex; justify-content: center; margin: 12px 0; }
.qr-box img, .qr-box canvas { max-width: 220px; }

/* ---------- 로그인 ---------- */
.login-wrap { min-height: 80vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); }
.login-card h1 { font-size: 1.4rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

/* ---------- 키오스크 ---------- */
.kiosk-body { background: #0f172a; color: #e2e8f0; }
.kiosk-body .topbar { background: rgba(15, 23, 42, .9); border-color: #1e293b; }
.kiosk-body .brand { color: #fff; }
.kiosk-body .card { background: #111c33; border-color: #1e2a44; box-shadow: none; color: #e2e8f0; }
.kiosk-body .input { background: #0b1324; border-color: #26334f; color: #fff; }
.kiosk-body .btn:not(.btn-primary):not(.btn-in):not(.btn-out) { background: #18233d; border-color: #26334f; color: #e2e8f0; }
.kiosk-body .muted { color: #94a3b8; }
.kiosk { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 860px) { .kiosk { grid-template-columns: 1fr; } }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.modes .btn.active { outline: 3px solid #fff; }
#reader { width: 100%; border-radius: 14px; overflow: hidden; background: #000; min-height: 260px; }
#reader video { border-radius: 14px; }
.kstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.kstats div { background: #0b1324; border-radius: 12px; padding: 12px; text-align: center; }
.kstats b { display: block; font-size: 1.8rem; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; padding: 10px 4px; border-bottom: 1px solid #1e2a44; }
.result {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(2, 6, 23, .82); animation: fade .15s;
}
.result-inner { text-align: center; padding: 40px 48px; border-radius: 28px; color: #fff; min-width: min(420px, 90vw); }
.result-inner.in { background: var(--in); }
.result-inner.out { background: var(--out); }
.result-inner.err { background: var(--danger); }
.result-inner.warn { background: #b45309; }
.result-inner .r-icon { font-size: 4rem; line-height: 1; }
.result-inner .r-name { font-size: clamp(2rem, 6vw, 3.2rem); font-weight: 900; margin: 10px 0 4px; }
.result-inner .r-msg { font-size: 1.4rem; font-weight: 700; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 공통 알림 ---------- */
.setup-banner { background: #fff7e6; color: #8a4b00; border-bottom: 1px solid #fde1b0; padding: 12px 16px; font-size: .92rem; text-align: center; }
#toast-box { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toast { background: #1c2333; color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); transition: opacity .3s; font-size: .92rem; }
.toast.ok { background: var(--in); }
.toast.err { background: var(--danger); }
.toast.hide { opacity: 0; }
footer.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px 16px 40px; }

/* ---------- 인쇄 (QR 카드 / 학부모 안내문) ---------- */
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; }
  body.printing { background: #fff; }
  .print-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8mm; }
  .print-grid.slips { grid-template-columns: repeat(2, 1fr); }
  .pcard { border: 1.5px dashed #999; border-radius: 4mm; padding: 5mm; text-align: center; break-inside: avoid; }
  .pcard .qr { display: flex; justify-content: center; margin: 3mm 0; }
  .pcard .qr img, .pcard .qr canvas { width: 38mm; height: 38mm; }
  .pcard .pname { font-size: 15pt; font-weight: 800; }
  .pcard .pcenter { font-size: 8pt; color: #555; }
  .pcard .pcode { font-size: 16pt; font-weight: 800; letter-spacing: 1px; margin: 2mm 0; }
  .pcard .pnote { font-size: 8.5pt; color: #333; text-align: left; line-height: 1.5; }
}
