/**
 * Nhà Ở Việt (NÓV) — In-App Chat Stylesheet
 * Floating Chat Button, Responsive Modal, Multi-Channel Direct Messaging & Quick Replies
 */

#chat-dialog {
  width: min(840px, calc(100vw - 32px));
  max-width: 840px;
  height: 600px;
  max-height: 86vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  background: #fff;
}

#chat-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.chat-popup-container {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100%;
  width: 100%;
  background: #fff;
  overflow: hidden;
}

/* Chat Sidebar (Conversation List) */
.chat-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  height: 100%;
  overflow: hidden;
}

.chat-sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  flex-shrink: 0;
}

.chat-conversations {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.chat-conv-item {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.chat-conv-item:hover, .chat-conv-item.active {
  background: var(--surface-blue);
}

.chat-conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, #004dc9 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 2px 5px rgba(21, 94, 239, 0.25);
}

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

.chat-conv-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.chat-conv-time {
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
}

.chat-conv-prop {
  font-size: 11px;
  color: var(--brand);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  font-weight: 600;
}

.chat-conv-last {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat Main View (Active Message Thread) */
.chat-main {
  display: flex;
  flex-direction: column;
  background: #fff;
  height: 100%;
  overflow: hidden;
}

.chat-main-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  flex-shrink: 0;
  gap: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
  -webkit-overflow-scrolling: touch;
}

.chat-bubble-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-bubble-row.me {
  flex-direction: row-reverse;
}

.chat-bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  word-break: break-word;
}

.chat-bubble.me {
  background: linear-gradient(135deg, var(--brand) 0%, #175cd3 100%);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-bubble.other {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.chat-bubble-time {
  font-size: 10px;
  opacity: 0.75;
  margin-top: 4px;
  text-align: right;
}

.chat-quick-replies {
  padding: 6px 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chat-quick-replies::-webkit-scrollbar {
  display: none;
}

.chat-quick-pill {
  font-size: 11px;
  padding: 5px 12px;
  background: var(--surface-blue);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--brand);
  cursor: pointer;
  flex-shrink: 0;
  font-weight: 600;
  transition: all 0.15s ease;
}
.chat-quick-pill:hover {
  background: var(--brand);
  color: #fff;
}

.chat-composer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: #fff;
  flex-shrink: 0;
}

.chat-composer input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  outline: none;
  font-size: 13px;
  background: #f8fafc;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.chat-composer input:focus {
  border-color: var(--brand);
  background: #fff;
}

/* Floating Action Button (FAB) */
.chat-floating-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, #004ec4 100%);
  color: #fff;
  border: none;
  box-shadow: 0 6px 20px rgba(21, 94, 239, 0.4);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 24px;
  z-index: 25;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
}
.chat-floating-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 24px rgba(21, 94, 239, 0.5);
}

.chat-floating-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Responsive Chat for Tablets & Mobile */
@media (min-width: 741px) {
  .mobile-back-btn {
    display: none !important;
  }
}

@media (max-width: 740px) {
  #chat-dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: 0 !important;
    inset: 0 !important;
    position: fixed !important;
  }
  .chat-popup-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
  }
  #chat-dialog.show-list .chat-main {
    display: none !important;
  }
  #chat-dialog.show-list .chat-sidebar {
    display: flex !important;
    width: 100% !important;
    flex: 1 !important;
    border-right: 0 !important;
  }
  #chat-dialog.show-messages .chat-sidebar {
    display: none !important;
  }
  #chat-dialog.show-messages .chat-main {
    display: flex !important;
    width: 100% !important;
    flex: 1 !important;
    height: 100% !important;
  }
  .chat-floating-btn {
    bottom: calc(64px + env(safe-area-inset-bottom, 8px));
    right: 14px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}
