:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #16202f;
  --muted: #6b7889;
  --line: #e2e7f0;
  --brand: #2f5bea;
  --brand-soft: #eaf0ff;
  --green: #12996b;
  --green-soft: #e6f7f0;
  --red: #d8453c;
  --red-soft: #fdecea;
  --amber: #b7791f;
  --amber-soft: #fdf3e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 64, .06), 0 8px 24px rgba(16, 32, 64, .06);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; }

/* ---------- 로그인 ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #eef2fb, #dfe7fa);
}
.login-card {
  background: var(--panel);
  padding: 32px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: min(360px, 92vw);
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---------- 상단바 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 16px; white-space: nowrap; }
.version { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  font-family: inherit;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.view { padding: 22px; max-width: 1400px; margin: 0 auto; }

/* ---------- 공통 요소 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 15px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.green .value { color: var(--green); }
.stat.red .value { color: var(--red); }
.stat.brand .value { color: var(--brand); }

.btn {
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.badge.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.badge.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.badge.live { color: var(--green); border-color: var(--green-soft); }
.badge.live.off { color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--bg); }
tbody tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 130px; }
.toolbar .spacer { flex: 1; }

.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- 막대 목록 ---------- */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 46px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: block; background: var(--bg); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { display: block; background: var(--brand); height: 100%; border-radius: 6px; min-width: 3px; }
.bar-fill.green { background: var(--green); }
.bar-fill.red { background: var(--red); }

/* ---------- 추이 차트 ---------- */
.trend { display: grid; grid-auto-flow: column; gap: 14px; align-items: end; min-height: 160px; padding-top: 8px; }
.trend-col { display: grid; gap: 6px; justify-items: center; }
.trend-bars { display: flex; gap: 4px; align-items: flex-end; height: 120px; }
.trend-bar { width: 16px; border-radius: 4px 4px 0 0; background: var(--green); min-height: 2px; }
.trend-bar.out { background: var(--red); }
.trend-label { font-size: 11px; color: var(--muted); }

/* ---------- 피드 ---------- */
.feed { display: grid; gap: 10px; max-height: 460px; overflow-y: auto; }
.feed-item { display: grid; gap: 3px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.feed-item .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.feed-item .detail { color: var(--muted); font-size: 12.5px; white-space: pre-wrap; }
.feed-item.new-item { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--brand-soft); } to { background: #fff; } }

/* ---------- 업로드 ---------- */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px;
  text-align: center;
  background: var(--panel);
  cursor: pointer;
  transition: .15s;
}
.dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone strong { display: block; font-size: 15px; margin-bottom: 6px; }

.plan-legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- 학생 카드 ---------- */
.card-dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(900px, 94vw);
  max-height: 92vh;
  box-shadow: 0 20px 60px rgba(16, 32, 64, .28);
}
.card-dialog::backdrop { background: rgba(16, 32, 64, .45); }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}
.card-head h2 { margin: 0; font-size: 20px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 20px 22px 24px; display: grid; gap: 18px; overflow-y: auto; }
.card-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.card-tabs button {
  border: 0; background: transparent; padding: 8px 12px; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent;
}
.card-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 18px; }
.field { display: grid; gap: 2px; }
.field .k { font-size: 11.5px; color: var(--muted); }
.field .v { font-size: 13.5px; }

.timeline { display: grid; gap: 10px; }
.timeline-item { display: grid; gap: 3px; padding: 10px 12px; border-left: 3px solid var(--brand); background: var(--bg); border-radius: 0 10px 10px 0; }
.timeline-item.note { border-left-color: var(--amber); }
.timeline-item.out { border-left-color: var(--red); }
.timeline-item.in { border-left-color: var(--green); }

.note-form { display: grid; gap: 8px; }
.note-form .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.note-form .row > * { flex: 0 0 auto; }
.note-form select, .note-form input[type=text] { width: auto; min-width: 140px; }
.checkbox { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.checkbox input { width: auto; }

/* ---------- 토스트 ---------- */
.toast-area { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 50; }
.toast {
  background: #16202f; color: #fff; padding: 11px 15px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 13px; max-width: 380px; animation: rise .2s ease-out;
}
.toast.good { background: #0f7a56; }
.toast.bad { background: #b6362e; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .view { padding: 14px; }
  .bar-row { grid-template-columns: 88px 1fr 40px; }
}
