/* ===== Chat Wrapper ===== */
main {
  display: flex;
  justify-content: center;  /* center horizontally */
  align-items: flex-start;  /* align top */
  width: 100%;
  padding: 0;               /* remove Bootstrap mt-5 / pt-4 */
  margin: 0;
}
.chat-wrapper {
  flex: 1 0 auto;
  display: flex;
  justify-content: center;  /* horizontal center */
  align-items: flex-start;  /* top aligned */
  /* padding: 20px; */
  padding-bottom: 30px;
  width: 100%;
  max-width: 1000px; /* wide wrapper on large screens */
  box-sizing: border-box;
} 

/* ===== Chat Card ===== */
.chat-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 750px;   /* wider chat card */
  height: calc(100vh - 80px); /* fill viewport minus navbar */
  background: rgba(42, 42, 59, 0.95);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  overflow: hidden;
}

/* ===== Chat Header ===== */
.chat-header {
  background: #3a3a55;
  color: #fff;
  padding: 14px 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Chat Box ===== */
.chat-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 auto;
  min-height: 100px;
  overflow-y: auto;
  padding: 12px;
  background: rgba(91, 91, 131, 0.3);
  scrollbar-width: thin;
  scrollbar-color: #777 transparent;
  scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar {
  width: 6px;
}
.chat-box::-webkit-scrollbar-thumb {
  background: #777;
  border-radius: 10px;
}

/* ===== Messages ===== */
.message {
  display: block;
  max-width: 75%;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.95rem;
  word-wrap: break-word;
  box-sizing: border-box;
  margin-bottom: 4px; /* reduced spacing */
}

.message.self {
  background: rgba(108, 157, 230, 0.85);
  color: #fff;
  margin-left: auto;
  text-align: right;
  border-bottom-right-radius: 6px;
  animation-name: fadeInRight;
}

.message.other {
  background: rgba(244, 245, 248, 0.85);
  color: #000;
  margin-right: auto;
  text-align: left;
  border-bottom-left-radius: 6px;
  animation-name: fadeInLeft;
}

.message.system {
  background: transparent;
  color: #bbb;
  text-align: center;
  font-size: 0.85rem;
  margin: 2px auto;
  max-width: 100%;
  display: block;
  animation-name: fadeIn;
  opacity: 0.8;
}

.message:last-child {
  margin-bottom: 0;
}

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity:0; transform:translateY(10px);} to {opacity:1; transform:translateY(0);} }
@keyframes fadeInRight { from {opacity:0; transform:translateX(20px);} to {opacity:1; transform:translateX(0);} }
@keyframes fadeInLeft { from {opacity:0; transform:translateX(-20px);} to {opacity:1; transform:translateX(0);} }

/* ===== Chat Input Area ===== */
.chat-input {
  flex-shrink: 0; /* always visible */
  display: flex;
  flex-direction: column; /* input on top, secondary buttons below */
  gap: 6px;
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
  background: #2a2a3b;
  border-radius: 0 0 20px 20px;
}

/* Input row: message + send button */
.chat-input .input-row {
  display: flex;
  gap: 6px;
  width: 100%;
}
.chat-input .input-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  border: none;
  outline: none;
  background: #1e1e2f;
  color: #fff;
  font-size: 0.95rem;
}
.chat-input .input-row #sendBtn {
  border-radius: 6px;
  padding: 8px 18px;
  font-weight: 600;
  font-size: 1rem;
  background: #28a745;
  color: #fff;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chat-input .input-row #sendBtn:hover {
  background: #218838;
  transform: scale(1.05);
}

/* Secondary buttons row below input */
.chat-input .secondary-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-start;
}
#stopSearchBtn, #disconnetBtn, #nextBtn {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
  background-color: #6c757d;
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}
#stopSearchBtn:hover, #disconnetBtn:hover, #nextBtn:hover {
  background-color: #5a6268;
  transform: scale(1.02);
}

/* ===== Preference Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top:0; left:0;
  width:100%; height:100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index:2000;
}
.modal-box {
  background: #2a2a3b;
  color: white;
  padding: 20px;
  border-radius: 12px;
  width: 350px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  animation: fadeInScale 0.3s ease;
}
.modal-box h3 { margin-bottom:16px; text-align:center; }
.form-group { margin-bottom:12px; display:flex; flex-direction:column; }
.form-group label { margin-bottom:6px; font-size:0.9rem; color:#ddd; }
.form-group input, .form-group select { padding:8px; border-radius:6px; border:none; background:#1e1e2f; color:white; }
.modal-actions { display:flex; justify-content:space-between; margin-top:16px; }
.modal-actions .btn { padding:8px 14px; font-weight:600; border:none; border-radius:6px; cursor:pointer; }
.btn-primary { background:#28a745; color:white; } .btn-primary:hover { background:#218838; }
.btn-secondary { background:#6c757d; color:white; } .btn-secondary:hover { background:#5a6268; }
@keyframes fadeInScale { from { opacity:0; transform:scale(0.9); } to { opacity:1; transform:scale(1); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .chat-card { max-width: 100%; height: 85vh; }
  .chat-box { min-height: 200px; padding: 12px; }
  .chat-input .input-row input { font-size: 0.9rem; padding: 8px 10px; }
  .chat-input .input-row #sendBtn { font-size: 0.95rem; padding: 8px 14px; }
  .chat-input .secondary-buttons button { font-size: 0.75rem; padding: 5px 10px; }
  .chat-wrapper { padding-top: 8px; padding-bottom: 10px; }
}
@media (max-width: 576px) {
  .chat-card { max-width: 100%; height: 80vh; }
  .chat-box { min-height: 180px; }
  .chat-input .input-row input { font-size: 0.85rem; }
  .chat-input .input-row #sendBtn { font-size: 0.9rem; padding: 6px 12px; }
  .chat-input .secondary-buttons button { font-size: 0.7rem; padding: 4px 8px; }
}
