/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f4f3ef;
  --card:     #ffffff;
  --input-bg: #f0efe9;
  --primary:  #1a3a6b;
  --primary2: #2653a3;
  --text:     #1c1c1c;
  --sub:      #5c5c5c;
  --hint:     #9a9a9a;
  --border:   #e0deda;
  --border2:  #c4c0b8;
  --danger:   #b52b2b;
  --unread:   #d4470c;
  --r:        10px;
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

html, body { height: 100%; }

/* ===== LOGIN ===== */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(150deg, #dde4f0 0%, #f4f3ef 55%, #ece8e0 100%);
}

.login-wrap { width: 100%; max-width: 420px; padding: 20px; }

.login-card {
  background: var(--card);
  border-radius: 18px;
  padding: 44px 36px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.11);
  border: 1px solid var(--border);
}

.login-header { text-align: center; margin-bottom: 32px; }

.logo-mark {
  width: 52px; height: 52px;
  background: var(--primary);
  border-radius: 14px;
  margin: 0 auto 18px;
  position: relative;
}
.logo-mark::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 26px; height: 26px;
  border: 2.5px solid rgba(255,255,255,0.8);
  border-radius: 50%;
}

.login-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.login-header p  { font-size: 0.875rem; color: var(--sub); }

.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 0.82rem; font-weight: 600;
  color: var(--sub); margin-bottom: 5px;
}
.field input {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  font-size: 0.95rem; background: var(--input-bg); color: var(--text);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.field input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,58,107,0.1);
  background: #fff;
}

.btn-login {
  width: 100%; padding: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--r);
  font-size: 1rem; font-weight: 600;
  cursor: pointer; margin-top: 6px;
  transition: background 0.18s;
}
.btn-login:hover:not(:disabled) { background: var(--primary2); }
.btn-login:disabled { opacity: 0.55; cursor: not-allowed; }

.error-msg {
  background: #fef2f2; border: 1px solid #fca5a5;
  color: var(--danger); border-radius: var(--r);
  padding: 9px 13px; font-size: 0.85rem; margin-bottom: 10px;
}

.login-foot { text-align: center; font-size: 0.78rem; color: var(--hint); margin-top: 20px; }


/* ===== SHARED CHAT LAYOUT ===== */
.chat-page, .admin-page {
  height: 100vh; overflow: hidden;
  background: var(--bg);
}

/* 채팅 헤더 */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px;
  background: var(--primary);
  flex-shrink: 0;
}
.chat-header-info { display: flex; flex-direction: column; }
.chat-title { font-size: 1rem; font-weight: 700; color: #fff; }
.chat-sub   { font-size: 0.75rem; color: rgba(255,255,255,0.65); }

.btn-logout {
  padding: 5px 12px; background: rgba(255,255,255,0.15);
  color: #fff; border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px; font-size: 0.8rem; cursor: pointer;
  transition: background 0.15s; white-space: nowrap;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* 날짜 바 */
.date-bar {
  text-align: center; padding: 7px;
  font-size: 0.75rem; color: var(--hint);
  background: var(--bg); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* 메시지 영역 */
.messages {
  flex: 1; overflow-y: auto;
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg);
}
.msg-empty {
  text-align: center; color: var(--hint);
  font-size: 0.875rem; line-height: 1.8;
  margin: auto;
}

/* 메시지 행 */
.msg-row { display: flex; align-items: flex-end; gap: 8px; }
.msg-row.mine    { flex-direction: row-reverse; }
.msg-row.theirs  { flex-direction: row; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary2); color: #fff;
  font-size: 0.75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.msg-body { display: flex; flex-direction: column; max-width: 68%; }
.msg-row.mine .msg-body { align-items: flex-end; }

.msg-name {
  font-size: 0.75rem; font-weight: 600;
  color: var(--sub); margin-bottom: 3px;
}

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem; line-height: 1.55;
  word-break: break-word;
}
.msg-row.theirs .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-row.mine .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 0.7rem; color: var(--hint);
  margin-top: 4px;
}
.msg-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: 3px;
}
.msg-foot.right { flex-direction: row-reverse; }

/* 삭제 버튼 (관리자용) */
.btn-del {
  font-size: 0.7rem; padding: 1px 5px;
  background: none; border: 1px solid var(--border2);
  border-radius: 4px; color: var(--hint);
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.btn-del:hover { color: var(--danger); border-color: var(--danger); }

/* 입력 영역 */
.input-area {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.input-area textarea {
  flex: 1; padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  font-size: 0.9rem; font-family: inherit;
  resize: none; background: var(--input-bg);
  color: var(--text); line-height: 1.5;
  transition: border-color 0.18s;
  min-height: 40px;
}
.input-area textarea:focus { outline: none; border-color: var(--primary); background: #fff; }

.btn-send {
  padding: 10px 18px; height: 40px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--r);
  font-size: 0.875rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--primary2); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }


/* ===== STUDENT CHAT WRAP ===== */
.chat-wrap {
  height: 100vh;
  display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}


/* ===== ADMIN LAYOUT ===== */
.admin-wrap {
  height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

/* 사이드바 */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 56px;
  background: #1a3a1a;
  flex-shrink: 0;
}
.sidebar-title { font-weight: 700; color: #fff; font-size: 0.95rem; }

.sidebar-label {
  padding: 10px 16px 6px;
  font-size: 0.75rem; font-weight: 600;
  color: var(--hint); text-transform: uppercase; letter-spacing: 0.05em;
  flex-shrink: 0;
}

.student-list {
  list-style: none; flex: 1; overflow-y: auto;
}
.list-empty {
  padding: 16px; font-size: 0.85rem; color: var(--hint); text-align: center;
}

.student-item {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.12s;
}
.student-item:hover   { background: var(--bg); }
.student-item.active  { background: #e8edf5; border-left: 3px solid var(--primary); }
.student-item.unread .s-name::after {
  content: '';
  display: inline-block; width: 7px; height: 7px;
  background: var(--unread); border-radius: 50%;
  margin-left: 6px; vertical-align: middle;
}
.s-name { display: block; font-size: 0.9rem; font-weight: 600; }
.s-id   { display: block; font-size: 0.78rem; color: var(--sub); }
.s-last {
  display: block; font-size: 0.78rem; color: var(--hint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}

/* 관리자 채팅 패널 */
.admin-chat {
  display: flex; flex-direction: column;
  overflow: hidden;
}
.admin-chat .chat-header { background: var(--primary); }


/* 관리 도구 영역 */
.sidebar-tools {
  flex-shrink: 0;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tools-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

/* 자동 초기화 상태 */
.reset-status {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.reset-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}
.reset-key {
  font-size: 0.72rem;
  color: var(--hint);
  flex-shrink: 0;
}
.reset-val {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}

.btn-clear-all {
  width: 100%;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  text-align: left;
  background: #fff0f0;
  color: var(--danger);
  border: 1px solid #f5a0a0;
}
.btn-clear-all:hover:not(:disabled) { background: #ffd6d6; }
.btn-clear-all:disabled { opacity: 0.5; cursor: not-allowed; }

/* 자정 초기화 카운트다운 배지 (채팅 헤더 우측) */
.reset-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  margin-left: auto;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 8px;
  padding: 5px 11px;
  flex-shrink: 0;
}
.reset-badge.overdue {
  background: rgba(181,43,43,0.35);
  border-color: rgba(255,120,120,0.5);
}
.reset-badge-label {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.reset-badge-time {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.reset-badge.overdue .reset-badge-time {
  color: #ffb3b3;
}


/* 토스트 알림 */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1c1c1c;
  color: #fff;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 9999;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }


/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .login-card { padding: 32px 22px; }

  .admin-wrap { grid-template-columns: 1fr; grid-template-rows: 220px 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-header { height: 48px; }
  .student-list { display: flex; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .student-item { min-width: 130px; border-bottom: none; border-right: 1px solid var(--border); }
  .sidebar-label { display: none; }
}
