/* Floating Messenger (glassy blue theme) */
.messenger-fab {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #007fa1, #59c6e4);
  color: #0b111a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  box-shadow: var(--shadow);
  border: none;
  cursor: pointer;
  z-index: 9999;
  position: fixed;
}

.messenger-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: #ff4d4f;
  color: #fff;
  font-size: 12px;
  border-radius: 999px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #0b111a;
}

.messenger-panel {
  position: fixed;
  left: 20px;
  bottom: 90px;
  width: 560px;
  max-height: 70vh;
  display: none;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.301);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  border: 1px solid rgba(58, 58, 58, 0.219);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 9998;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity .18s ease, transform .18s ease;
}
.messenger-panel.open { opacity: 1; transform: none; }

/* Mobile full-screen mode */
.messenger-panel.mobile {
  left: 0; right: 0; bottom: 0; top: 0;
  width: 100vw; height: 100vh; max-height: none; border-radius: 0;
}

.messenger-header {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  font-weight: 700;
}

.messenger-tabs { display:flex; gap:6px; }
.messenger-tab { padding:6px 10px; border-radius:999px; cursor:pointer; border:1px solid rgba(255,255,255,0.14); color:var(--muted); }
.messenger-tab.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color:#0b111a; border:none; }

.messenger-body {
  display: grid;
  grid-template-columns: 1.6fr 2.4fr;
  min-height: 260px;
}

/* (left-hidden/new-mode removed per design; list always visible) */

.messenger-left {
  border-right: 1px solid rgba(255,255,255,0.12);
  display: flex;
  flex-direction: column;
  transition: opacity .18s ease;
  width: 200px;
}

.messenger-search { padding: 8px 8px 4px 8px; }
.messenger-search input {
  width: 100%; padding: 10px 12px; background-color: rgb(0 0 0 / 47%);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 10px; color: var(--text);
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.messenger-search input:focus { border-color: rgba(97,218,251,0.6); box-shadow: 0 0 0 3px rgba(97,218,251,0.15); }

.left-list-header { display:flex; align-items:center; gap:8px; padding:8px 10px; color: var(--muted); }
.left-list-header .new-btn { margin-left:auto; padding:6px 10px; border-radius:8px; border:1px solid rgba(255,255,255,0.14); cursor:pointer; }
.left-list-header .new-btn:hover { filter: brightness(1.2); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
}
.conversation-item { padding: 10px 10px; border-bottom: 1px solid rgba(255,255,255,0.06); cursor: pointer; display:grid; grid-template-columns: 36px 1fr; gap:10px; align-items:center; }
.conversation-item:hover { background: rgba(255,255,255,0.06); }
.conversation-item.active { background: rgba(97,218,251,0.15); }
.conversation-title { font-weight: 700; }
.conversation-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-last { font-size: 12px; color: var(--muted); margin-top: 2px; }

.avatar { width:34px; height:34px; border-radius:50%; background: var(--surface-strong); display:flex; align-items:center; justify-content:center; color:var(--text); font-weight:700; flex-shrink:0; overflow:hidden; border:1px solid rgba(255,255,255,0.14); }
.avatar img { width:100%; height:100%; object-fit:cover; display:block; }

.messenger-right { display: flex; flex-direction: column; position: relative; padding: 0 12px 56px 12px; box-sizing: border-box; overflow: hidden; min-width: 330px;}
.chat-header { display:flex; align-items:center; gap:10px; padding:8px; border-bottom:1px solid rgba(255,255,255,0.12); }
.chat-title { font-weight:700; }
.chat-header .toggle-left { display: none; background: transparent; border: 1px solid rgba(255,255,255,0.14); color: var(--text); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  max-height: 568px;
  padding-bottom: 110px;
  width: 100%;
  min-width: 0; /* prevent horizontal overflow on small screens */
}
.messenger-panel textarea { display:block; width:100%; }
.msg { margin: 6px 0; max-width: 85%; padding: 8px 10px; border-radius: 12px; }
.msg { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg img { max-width: 100%; height: auto; display: block; }
.msg.me { margin-left: auto; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #0b111a; }
.msg.them { background: var(--surface-strong); color: var(--text); border: 1px solid rgba(255,255,255,0.12); }

.msg-row { display: flex; width: 100%; align-items: flex-end; gap: 10px; margin: 8px 0; padding: 0 6px; box-sizing: border-box; }
.msg-row.me { justify-content: flex-end; }
.msg-row.them { justify-content: flex-start; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; overflow: hidden; border: 1px solid rgba(255,255,255,0.14); background: var(--surface-strong); color: var(--text); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-bubble { display: inline-block; flex: 0 1 78%; max-width: 78%; min-width: 44px; padding: 10px 14px; border-radius: 18px; line-height: 1.45; font-size: 14px; white-space: pre-wrap; word-break: break-word; overflow-wrap: break-word; hyphens: auto; }
.msg-bubble.me { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #0b111a; }
.msg-bubble.them { background: var(--surface-strong); color: var(--text); border: 1px solid rgba(255,255,255,0.12); }
.msg-bubble img { max-width: 100%; height: auto; display: block; border-radius: 10px; }

/* Typing indicator (Google Messages style) */
.msg.typing { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-strong); border: 1px solid rgba(255,255,255,0.12); color: var(--text); }
.msg-bubble.typing { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-strong); border: 1px solid rgba(255,255,255,0.12); color: var(--text); }
.typing-dots { display: inline-flex; align-items: center; gap: 4px; }
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  opacity: 0.6;
  animation: typingBounce 1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .6; }
  40% { transform: translateY(-3px); opacity: 1; }
}

.composer {
  position: absolute; /* keep inside panel and centered */
  bottom: -10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background-color: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  z-index: 2;
  max-width: none;
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  box-sizing: border-box;
  overflow: hidden;
}
.composer input { flex: 1 1 auto; min-width: 0; height: 36px; padding: 0 12px; background-color: rgb(0 0 0 / 47%); color: var(--text); border: 1px solid rgba(255,255,255,0.18); border-radius: 999px; }
.composer button { height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.14); cursor: pointer; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #0b111a; font-weight: 700; display:inline-flex; align-items:center; }
.composer .btn-ghost { background: rgba(255,255,255,0.06); color: var(--text); }
.composer .btn-ghost { background: rgba(255,255,255,0.06); color: var(--text); }

/* Quick message suggestion chip */
#quickMsgSuggestion {
  background: rgba(255,255,255,0.06) !important;
  color: var(--text) !important;
  border: 1px solid rgba(255,255,255,0.14) !important;
  border-radius: 999px !important;
  padding: 0 10px !important;
  font-size: 12px !important;
  line-height: 36px !important;
  height: 36px;
  max-width: 45%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 45%;
  margin-right: 4px;
}
#quickMsgSuggestion:hover { filter: brightness(1.1); }

/* Blocking loader overlay */
.messenger-blocker {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 99999;
  pointer-events: all;
}
.messenger-spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.25);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
.messenger-blocker-text { color: #fff; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .messenger-panel { width: calc(100vw - 40px); left: 20px; }
  .messenger-panel.mobile { width: 100vw; left: 0; }
  .messenger-body { grid-template-columns: 1fr; height: calc(100vh - 52px); }
  .messenger-left { border-right: 0; border-bottom: 1px solid rgba(255,255,255,0.12); height: 100%; display:flex; flex-direction: column; }
  .conversation-list { flex: 1; overflow-y: auto; }

  /* Page switch behavior */
  .messenger-panel.view-list .messenger-right { display: none; }
  .messenger-panel.view-chat .messenger-left { display: none; }
  .chat-header .toggle-left { display: inline-flex; }

  /* Composer sits at bottom inside panel */
  .messenger-panel .composer { position: sticky; bottom: 0; right: auto; left: auto; max-width: none; width: calc(100% - 24px); margin: 0 12px 12px; }
  .messages { max-height: none; height: calc(100vh - 52px - 72px - 24px); padding: 12px 8px; }
}
