/* ── Chat Modal (Student) ────────────────────────────────────────────────── */
.chat-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(20,20,20,.5); z-index: 400; backdrop-filter: blur(4px);
}
.chat-modal-overlay.open { display: flex; align-items: center; justify-content: center; }

.chat-modal {
  background: #fff; border-radius: 16px; border: 1px solid #e4e4e7;
  width: min(560px, 95vw); height: min(620px, 90vh);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.125rem 1.5rem; border-bottom: 1px solid #e4e4e7; flex-shrink: 0;
}
.chat-modal-header h2 { font-size: 1rem; font-weight: 800; }
.chat-modal-close {
  background: none; border: 1px solid #e4e4e7; border-radius: .5rem;
  width: 2rem; height: 2rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center; color: #141414; transition: .15s;
}
.chat-modal-close:hover { opacity: .6; }

/* Application selector */
.chat-app-select {
  padding: .875rem 1.25rem; border-bottom: 1px solid #e4e4e7; flex-shrink: 0;
  display: flex; flex-direction: column; gap: .5rem;
}
.chat-app-select-label { font-size: .75rem; font-weight: 700; color: #71717a; text-transform: uppercase; letter-spacing: .06em; }
.chat-app-list { display: flex; flex-direction: column; gap: .375rem; }
.chat-app-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .625rem .875rem; border-radius: .625rem; border: 1.5px solid #e4e4e7;
  cursor: pointer; transition: .15s; font-size: .875rem; font-weight: 600; background: #fff;
  text-align: left; width: 100%;
}
.chat-app-item:hover { border-color: #141414; }
.chat-app-item.active { border-color: #141414; background: #f9f9f9; }
.chat-app-item-date { font-size: .75rem; color: #71717a; font-weight: 500; }
.chat-app-unread {
  background: #e04f2d; color: #fff; font-size: .6875rem; font-weight: 800;
  padding: .15rem .5rem; border-radius: 999px; min-width: 1.25rem; text-align: center;
}

/* Messages area */
.chat-messages-wrap { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.chat-empty { color: #a1a1aa; font-size: .875rem; text-align: center; padding: 2rem 0; }

/* Bubbles */
.chat-msg { display: flex; flex-direction: column; max-width: 72%; }
.chat-msg--mine   { align-self: flex-end;   align-items: flex-end;   margin-left: auto; }
.chat-msg--theirs { align-self: flex-start; align-items: flex-start; margin-right: auto; }

.chat-msg-name {
  font-size: .6875rem; font-weight: 700; color: #71717a;
  margin-bottom: .25rem; padding: 0 .25rem;
}
.chat-msg-text {
  padding: .625rem .875rem; border-radius: 12px;
  font-size: .9rem; line-height: 1.55;
}
.chat-msg--mine  .chat-msg-text { background: #141414; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg--theirs .chat-msg-text { background: #f4f4f5; color: #141414; border-bottom-left-radius: 4px; }

.chat-msg-img {
  max-width: 220px; max-height: 220px; border-radius: 10px;
  object-fit: cover; cursor: pointer; display: block;
}
.chat-msg-time {
  font-size: .6875rem; color: #a1a1aa; margin-top: .25rem; padding: 0 .25rem;
}

/* Input bar */
.chat-input-bar {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem 1rem; border-top: 1px solid #e4e4e7; flex-shrink: 0;
}
.chat-input-bar textarea {
  flex: 1; font-family: inherit; font-size: .9rem; resize: none;
  border: 1.5px solid #e4e4e7; border-radius: .75rem; padding: .625rem .875rem;
  outline: none; line-height: 1.5; max-height: 120px; min-height: 40px;
  transition: border-color .2s;
}
.chat-input-bar textarea:focus { border-color: #141414; }
.chat-icon-btn {
  width: 2.25rem; height: 2.25rem; border-radius: .625rem;
  border: 1.5px solid #e4e4e7; background: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: #71717a; transition: .15s; flex-shrink: 0;
}
.chat-icon-btn:hover { border-color: #141414; color: #141414; }
.chat-send-btn {
  width: 2.25rem; height: 2.25rem; border-radius: .625rem;
  border: none; background: #141414; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; transition: .15s; flex-shrink: 0;
}
.chat-send-btn:hover { opacity: .75; }
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }
.chat-send-btn--sending { opacity: .5; pointer-events: none; }
.chat-send-btn--sending svg { animation: chatSendPulse .5s ease-in-out infinite alternate; }
@keyframes chatSendPulse { from { transform: scale(1) rotate(0deg); opacity: 1; } to { transform: scale(.75) rotate(15deg); opacity: .5; } }

/* Image overlay */
.chat-img-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,.85); align-items: center; justify-content: center;
  cursor: zoom-out;
}
.chat-img-overlay img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }

/* Student nav badge */
.chat-nav-badge {
  display: none; background: #e04f2d; color: #fff;
  font-size: .6875rem; font-weight: 800; padding: .1rem .45rem;
  border-radius: 999px; min-width: 1.25rem; text-align: center;
  margin-left: auto;
}
.chat-nav-badge.visible { display: inline-block; }

/* ── Admin Chat Section ───────────────────────────────────────────────────── */
.admin-chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 0; height: calc(100vh - 7rem); border: 1px solid #e4e4e7; border-radius: 14px; overflow: hidden; }

.chat-candidates-panel { border-right: 1px solid #e4e4e7; display: flex; flex-direction: column; background: #fff; min-height: 0; overflow: hidden; }
.chat-candidates-panel-header { padding: 1rem 1.25rem; border-bottom: 1px solid #e4e4e7; font-size: .875rem; font-weight: 700; }
.chat-candidates-list { flex: 1; overflow-y: auto; }
.chat-candidate-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1.25rem; cursor: pointer; border-bottom: 1px solid #f4f4f5;
  transition: background .15s;
}
.chat-candidate-item:hover { background: #fafafa; }
.chat-candidate-item.active { background: #f4f4f5; }
.chat-candidate-avatar {
  width: 2.25rem; height: 2.25rem; border-radius: 50%; background: #141414;
  color: #c1f11d; display: flex; align-items: center; justify-content: center;
  font-size: .875rem; font-weight: 800; flex-shrink: 0;
}
.chat-candidate-info { flex: 1; min-width: 0; }
.chat-candidate-name { font-size: .875rem; font-weight: 700; truncate; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-candidate-email { font-size: .75rem; color: #71717a; }
.chat-candidate-unread {
  background: #e04f2d; color: #fff; font-size: .6875rem; font-weight: 800;
  padding: .15rem .45rem; border-radius: 999px; flex-shrink: 0;
}
.chat-no-candidates { padding: 2rem; text-align: center; color: #a1a1aa; font-size: .875rem; }

.chat-panel { display: flex; flex-direction: column; background: #fafafa; min-height: 0; overflow: hidden; }
.chat-panel-header {
  padding: 1rem 1.5rem; border-bottom: 1px solid #e4e4e7;
  background: #fff; display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
}
.chat-panel-header-info { flex: 1; }
.chat-panel-name { font-size: .9375rem; font-weight: 800; }
.chat-panel-email { font-size: .8125rem; color: #71717a; }
.chat-panel-placeholder {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #a1a1aa; font-size: .9375rem;
}
.chat-admin-messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 1.25rem 1.5rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.chat-admin-input-bar {
  display: flex; align-items: center; gap: .625rem;
  padding: 1rem 1.5rem; border-top: 1px solid #e4e4e7; background: #fff; flex-shrink: 0;
}
.chat-admin-input-bar textarea {
  flex: 1; font-family: inherit; font-size: .9rem; resize: none;
  border: 1.5px solid #e4e4e7; border-radius: .75rem; padding: .625rem .875rem;
  outline: none; line-height: 1.5; max-height: 120px; min-height: 40px; transition: border-color .2s;
}
.chat-admin-input-bar textarea:focus { border-color: #141414; }

/* Write-to-student modal */
.chat-write-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(20,20,20,.5); z-index: 400; backdrop-filter: blur(4px);
}
.chat-write-modal-overlay.open { display: flex; align-items: center; justify-content: center; }
.chat-write-modal {
  background: #fff; border-radius: 16px; border: 1px solid #e4e4e7;
  width: min(480px, 94vw); padding: 1.75rem; display: flex; flex-direction: column; gap: 1rem;
}
.chat-write-modal h3 { font-size: 1.125rem; font-weight: 800; margin: 0; }
.chat-write-search {
  width: 100%; font-family: inherit; font-size: .9rem; padding: .625rem .875rem;
  border: 1.5px solid #e4e4e7; border-radius: .75rem; outline: none; transition: border-color .2s;
}
.chat-write-search:focus { border-color: #141414; }
.chat-write-list { display: flex; flex-direction: column; gap: .375rem; max-height: 260px; overflow-y: auto; }
.chat-write-item {
  display: flex; align-items: center; gap: .75rem; padding: .75rem .875rem;
  border-radius: .625rem; border: 1.5px solid #e4e4e7; cursor: pointer; transition: .15s;
}
.chat-write-item:hover { border-color: #141414; background: #f9f9f9; }
.chat-write-item-name { font-size: .875rem; font-weight: 700; }
.chat-write-item-meta { font-size: .75rem; color: #71717a; }

@media (max-width: 760px) {
  .admin-chat-layout { grid-template-columns: 1fr; }
  .chat-candidates-panel { max-height: 220px; }
}
