/* ============================================================================
   CHAT STYLES - Professional light theme (KM-CHAT redesign)
   Palette: #f0f2f5 bg, #3E6B47 accent, #ffffff surfaces
   ============================================================================ */

#page-chat {
  background: #f0f2f5;
  padding: 0 !important;
}

#chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-container {
  max-width: 800px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.chat-header {
  display: flex;
  flex-direction: column;
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e0e4ea;
  flex-shrink: 0;
}

.chat-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-participants {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 40px;
  font-size: 0.82rem;
  color: #65737e;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 6px;
  margin-top: 2px;
}

.chat-header-participants:hover {
  background: #f0f2f5;
  color: #3E6B47;
}

.chat-header-participants span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-title {
  color: #1a2a1e;
  font-size: 1.3rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-new-btn {
  background: #3E6B47;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chat-new-btn:hover {
  background: #5B7B5E;
}

.chat-back-btn {
  background: none;
  color: #3E6B47;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-back-btn:hover {
  color: #1a2a1e;
}

.chat-conv-title {
  color: #1a2a1e;
  font-size: 1.1rem;
  font-weight: bold;
  margin-left: 12px;
}

/* ---- Body ---- */
.chat-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- Empty state ---- */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #8696a0;
}

.chat-empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.chat-empty-title {
  font-size: 1.3rem;
  color: #1a2a1e;
  font-weight: bold;
  margin-bottom: 8px;
}

.chat-empty-sub {
  font-size: 0.9rem;
}

.chat-loading {
  text-align: center;
  padding: 40px;
  color: #8696a0;
}

/* ---- Conversation list ---- */
.chat-conv-list {
  padding: 0;
}

.chat-conv-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid #e0e4ea;
  cursor: pointer;
  transition: background 0.2s;
  background: #ffffff;
}

.chat-conv-item:hover {
  background: #f5f6fa;
}

.chat-conv-unread {
  background: #f0f7f1;
}

.chat-conv-unread .chat-conv-name,
.chat-conv-unread .chat-conv-preview {
  font-weight: bold;
  color: #1a2a1e;
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
  font-weight: bold;
  margin-right: 14px;
  flex-shrink: 0;
}

.chat-avatar svg {
  width: 24px;
  height: 24px;
}

.chat-avatar-sm {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  margin-right: 12px;
  flex-shrink: 0;
}

.chat-conv-info {
  flex: 1;
  min-width: 0;
}

.chat-conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.chat-conv-name {
  color: #1a2a1e;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conv-time {
  color: #8696a0;
  font-size: 0.8rem;
  margin-left: 8px;
  flex-shrink: 0;
}

.chat-conv-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-conv-preview {
  color: #65737e;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-unread-badge {
  background: #3E6B47;
  color: #fff;
  border-radius: 12px;
  min-width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 0 6px;
  margin-left: 8px;
}

.chat-conv-role {
  font-size: 0.75rem;
  color: #8696a0;
  margin-top: 2px;
}

/* ---- Type badges for groups ---- */
.chat-conv-type-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.chat-type-badge {
  font-size: 0.7rem;
  padding: 1px 8px;
  border-radius: 8px;
  font-weight: 600;
  color: #fff;
}

.chat-type-family_group { background: #2ecc71; }
.chat-type-parents_group { background: #3498db; }
.chat-type-students_group { background: #e67e22; }
.chat-type-room { background: #9b59b6; }

.chat-member-count {
  font-size: 0.75rem;
  color: #8696a0;
}

/* ---- Tab bar ---- */
.chat-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid #e0e4ea;
  background: #ffffff;
  flex-shrink: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  gap: 2px;
  padding: 0 8px;
}

.chat-tabs::-webkit-scrollbar { display: none; }

.chat-tab {
  padding: 10px 14px;
  color: #65737e;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chat-tab svg {
  width: 16px;
  height: 16px;
}

.chat-tab:hover { color: #3E6B47; }

.chat-tab.chat-tab-active {
  color: #3E6B47;
  font-weight: 600;
  border-bottom-color: #3E6B47;
}

.chat-tab-badge {
  background: #3E6B47;
  color: #fff;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: bold;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  margin-left: 5px;
  vertical-align: middle;
}

/* ---- Messages view ---- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #f0f2f5;
}

.chat-empty-conv {
  text-align: center;
  color: #8696a0;
  padding: 40px 20px;
}

.chat-date-sep {
  text-align: center;
  margin: 16px 0;
  color: #8696a0;
  font-size: 0.8rem;
}

.chat-date-sep::before,
.chat-date-sep::after {
  content: '';
}

/* ---- Bubbles ---- */
.chat-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 18px;
  margin-bottom: 6px;
  word-wrap: break-word;
}

.chat-bubble-me {
  background: #3E6B47;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-bubble-other {
  background: #ffffff;
  color: #1a2a1e;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid #e0e4ea;
}

.chat-bubble-text {
  font-size: 0.95rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.chat-bubble-time {
  font-size: 0.7rem;
  margin-top: 4px;
  opacity: 0.6;
  text-align: right;
}

.chat-bubble-other .chat-bubble-time {
  color: #8696a0;
  opacity: 1;
}

/* ---- Bubble wrap & actions ---- */
.chat-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin-bottom: 6px;
}

.chat-bubble-wrap-me {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.chat-bubble-wrap-other {
  align-self: flex-start;
}

.chat-bubble-wrap .chat-bubble {
  margin-bottom: 0;
}

.chat-bubble-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  position: relative;
}

.chat-bubble-wrap:hover .chat-bubble-actions {
  opacity: 1;
}

.chat-reply-btn {
  background: none;
  border: none;
  color: #8696a0;
  cursor: pointer;
  padding: 3px 5px;
  opacity: 0;
  transition: opacity 0.2s;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-reply-btn svg {
  width: 16px;
  height: 16px;
}

.chat-bubble-wrap:hover .chat-reply-btn {
  opacity: 1;
}

.chat-reply-btn:hover {
  color: #3E6B47;
}

.chat-delete-btn:hover {
  color: #e74c3c !important;
}

/* ---- Reactions (bigger) ---- */
.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
  margin-bottom: 4px;
  padding: 0 4px;
}

.chat-bubble-wrap-me + .chat-reactions {
  justify-content: flex-end;
}

.chat-reaction-chip {
  background: #e8ecf0;
  border: 1px solid #d0d5dc;
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 1rem;
  cursor: pointer;
  color: #1a2a1e;
  transition: background 0.2s;
  position: relative;
}

.chat-reaction-chip:hover {
  background: #d0d5dc;
}

.chat-reaction-mine {
  background: #d4e8d9;
  border-color: #3E6B47;
}

/* ---- Reaction details popup ---- */
.chat-reaction-details {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  border: 1px solid #e0e4ea;
  border-radius: 10px;
  padding: 10px 14px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 160px;
  max-width: 280px;
  white-space: normal;
}

.chat-reaction-details::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #e0e4ea;
}

.chat-reaction-details-title {
  font-size: 1.1rem;
  margin-bottom: 6px;
  text-align: center;
}

.chat-reaction-details-list {
  font-size: 0.8rem;
  color: #65737e;
  line-height: 1.5;
  margin-bottom: 8px;
}

.chat-reaction-details-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.chat-reaction-details-btn {
  background: #3E6B47;
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 4px 14px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-reaction-details-btn:hover {
  background: #5B7B5E;
}

.chat-reaction-details-btn.remove {
  background: #e74c3c;
}

.chat-reaction-details-btn.remove:hover {
  background: #c0392b;
}

.chat-reaction-details-close {
  background: #e0e4ea;
  color: #65737e;
}

/* ---- Reaction picker (bigger) ---- */
.chat-reaction-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
  display: flex;
  gap: 2px;
  background: #ffffff;
  border: 1px solid #e0e4ea;
  border-radius: 20px;
  padding: 4px 6px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.chat-reaction-picker-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.chat-reaction-picker-btn:hover {
  background: #f0f2f5;
}

/* ---- Reply block inside bubble ---- */
.chat-reply-block {
  background: rgba(62,107,71,0.08);
  border-left: 3px solid #3E6B47;
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 6px;
  max-width: 100%;
  overflow: hidden;
}

.chat-bubble-me .chat-reply-block {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.5);
}

.chat-reply-block-sender {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: #3E6B47;
}

.chat-bubble-me .chat-reply-block-sender {
  color: rgba(255,255,255,0.85);
}

.chat-reply-block-text {
  display: block;
  font-size: 0.8rem;
  color: #65737e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-bubble-me .chat-reply-block-text {
  color: rgba(255,255,255,0.7);
}

/* ---- Reply preview above input ---- */
.chat-reply-preview {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #f5f7fa;
  border-top: 1px solid #e0e4ea;
  border-left: 3px solid #3E6B47;
  flex-shrink: 0;
}

.chat-reply-preview-body {
  flex: 1;
  min-width: 0;
}

.chat-reply-preview-sender {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #3E6B47;
}

.chat-reply-preview-text {
  display: block;
  font-size: 0.85rem;
  color: #65737e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-reply-cancel {
  background: none;
  border: none;
  color: #8696a0;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: 8px;
  flex-shrink: 0;
}

.chat-reply-cancel:hover {
  color: #1a2a1e;
}

/* ---- Quiet hours banner ---- */
.chat-quiet-banner {
  background: #fff8e1;
  color: #f57f17;
  padding: 10px 20px;
  font-size: 0.85rem;
  border-bottom: 1px solid #ffe082;
  text-align: center;
  flex-shrink: 0;
}

/* ---- Input bar ---- */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  padding: 10px 16px;
  border-top: 1px solid #e0e4ea;
  background: #ffffff;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: #f0f2f5;
  border: 1px solid #e0e4ea;
  border-radius: 20px;
  padding: 10px 16px;
  color: #1a2a1e;
  font-size: 0.95rem;
  resize: none;
  max-height: 120px;
  outline: none;
  font-family: inherit;
  margin-right: 8px;
}

.chat-input:focus {
  border-color: #3E6B47;
}

.chat-input::placeholder {
  color: #8696a0;
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #3E6B47;
  color: #fff;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.chat-send-btn svg {
  width: 20px;
  height: 20px;
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-send-btn:not(:disabled):hover {
  background: #5B7B5E;
}

/* ---- Search bar ---- */
.chat-search-bar {
  padding: 12px 16px;
  border-bottom: 1px solid #e0e4ea;
  background: #ffffff;
}

.chat-search-input {
  width: 100%;
  background: #f0f2f5;
  border: 1px solid #e0e4ea;
  border-radius: 20px;
  padding: 10px 16px;
  color: #1a2a1e;
  font-size: 0.95rem;
  outline: none;
  box-sizing: border-box;
}

.chat-search-input:focus {
  border-color: #3E6B47;
}

.chat-search-input::placeholder {
  color: #8696a0;
}

/* ---- Contact list ---- */
.chat-contact-list {
  padding: 0;
}

.chat-contact-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #e0e4ea;
  cursor: pointer;
  transition: background 0.2s;
  background: #ffffff;
}

.chat-contact-item:hover {
  background: #f5f6fa;
}

.chat-contact-info {
  flex: 1;
}

.chat-contact-name {
  color: #1a2a1e;
  font-size: 1rem;
  font-weight: 500;
}

.chat-contact-role {
  color: #8696a0;
  font-size: 0.8rem;
  margin-top: 2px;
}

/* ---- Header actions ---- */
.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-new-room-btn {
  background: #3498db !important;
}

.chat-new-room-btn:hover {
  background: #5dade2 !important;
}

/* ---- Sender name in group bubbles ---- */
.chat-bubble-sender {
  font-size: 0.75rem;
  color: #3E6B47;
  font-weight: 600;
  margin-bottom: 2px;
}

.chat-bubble-me .chat-bubble-sender {
  color: rgba(255,255,255,0.85);
}

/* ---- Member list modal ---- */
.chat-members-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.chat-members-modal {
  background: #ffffff;
  border: 1px solid #e0e4ea;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
}

.chat-members-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-members-header h3 {
  color: #1a2a1e;
  margin: 0;
  font-size: 1.1rem;
}

.chat-members-close {
  color: #8696a0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
}

.chat-members-close:hover {
  color: #1a2a1e;
}

.chat-members-desc {
  color: #65737e;
  font-size: 0.85rem;
  margin-top: 6px;
}

.chat-members-count {
  color: #3E6B47;
  font-size: 0.85rem;
  margin: 10px 0;
  font-weight: 600;
}

.chat-members-list {
  display: flex;
  flex-direction: column;
}

.chat-member-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f0f2f5;
}

.chat-member-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.chat-member-name {
  color: #1a2a1e;
  font-size: 0.95rem;
}

.chat-member-role {
  font-size: 0.7rem;
  padding: 1px 8px;
  border-radius: 8px;
  font-weight: 600;
  color: #fff;
}

.chat-role-parent { background: #3498db; }
.chat-role-student { background: #2ecc71; }
.chat-role-teacher { background: #f39c12; }
.chat-role-admin { background: #9b59b6; }

/* ---- Room creation form ---- */
.chat-room-form {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-room-name-bar {
  padding: 12px 16px;
  border-bottom: 1px solid #e0e4ea;
  background: #ffffff;
}

.chat-room-create-bar {
  padding: 12px 16px;
  border-top: 1px solid #e0e4ea;
  background: #ffffff;
  display: flex;
  justify-content: flex-end;
}

.chat-room-contact-label {
  cursor: pointer;
}

.chat-room-contact-label input[type="checkbox"] {
  accent-color: #3E6B47;
}

/* ---- Lucide icon alignment helpers ---- */
.chat-icon-inline {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.chat-icon-inline svg {
  width: 16px;
  height: 16px;
}
