/* ===================================
   Collab Toast Notification
   =================================== */

/* Appears bottom-right; slides up on enter, fades out on leave */
.collab-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.collab-toast i {
  color: var(--primary, #2dd4bf);
  font-size: 1rem;
  flex-shrink: 0;
}

.collab-toast--visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 480px) {
  .collab-toast {
    bottom: 16px;
    right: 16px;
    left: 16px;
    justify-content: center;
  }
}

/* ===================================
   Trip Chat Sidebar
   =================================== */

/* Backdrop overlay */
.chat-sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1003;
}

/* Sidebar panel */
.chat-sidebar {
  position: fixed;
  top: 0;
  right: -400px;
  width: 380px;
  max-width: 90vw;
  height: 100vh;
  background: white;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  z-index: 1004;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
}

.chat-sidebar-open {
  right: 0;
}

/* Header */
.chat-sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-sidebar-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-sidebar-header h3 i {
  color: var(--primary, #2dd4bf);
}

.chat-sidebar-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #767676;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.chat-sidebar-close:hover {
  background: #f3f4f6;
  color: #333;
}

/* Messages area — scoped to .chat-sidebar to override global .chat-messages
   from trip-builder styles (height: 0, visibility: hidden) */
.chat-sidebar .chat-messages {
  flex: 1;
  height: auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  visibility: visible;
  margin: 0;
}

/* Individual message */
.chat-sidebar .chat-message {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 85%;
}

.chat-message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  margin-bottom: 3px;
}

.chat-message-author {
  font-weight: 600;
  color: #333;
}

.chat-message-time {
  color: #999;
}

.chat-message-content {
  background: #f3f4f6;
  padding: 8px 12px;
  border-radius: 12px;
  border-top-left-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #333;
  word-break: break-word;
}

/* Own messages align right */
.chat-message-own {
  align-self: flex-end;
}

.chat-message-own .chat-message-meta {
  flex-direction: row-reverse;
}

.chat-message-own .chat-message-content {
  background: var(--primary, #2dd4bf);
  color: white;
  border-radius: 12px;
  border-top-right-radius: 4px;
  border-top-left-radius: 12px;
}

/* Empty state */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #999;
  text-align: center;
  padding: 2rem;
}

.chat-empty-state i {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.3;
}

.chat-empty-state p {
  margin: 0;
  font-size: 0.95rem;
}

/* Input form */
.chat-input-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
  background: white;
}

.chat-input-form input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input-form input[type="text"]:focus {
  border-color: var(--primary, #2dd4bf);
}

.chat-input-form .btn {
  border-radius: 50%;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-sidebar {
    width: 100%;
    max-width: 100vw;
  }
}

/* ===================================
   Per-Itinerary-Item Chat Popup
   =================================== */

/* Wrapper that holds reactions + chat button side by side */
.reactions-and-chat {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 0.5rem;
  justify-content: flex-end;
}

/* Chat bubble button on each itinerary item — matches reaction-btn sizing */
.item-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem 0.5rem 0.55rem;
  border: 1.5px solid rgba(13, 148, 136, 0.3);
  border-radius: 2rem;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(4px);
  font-size: 0.9rem;
  color: var(--primary, #0d9488);
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
}

.item-chat-btn i {
  font-size: 1.1rem;
  color: var(--primary, #0d9488);
  transition: transform 0.18s ease;
}

.item-chat-btn:hover {
  border-color: var(--primary, #0d9488);
  background: var(--teal-50, #f0fdfa);
  box-shadow: 0 3px 10px rgba(13, 148, 136, 0.18);
  transform: translateY(-1px);
}

.item-chat-btn:hover i {
  transform: scale(1.15);
}

.item-chat-btn:active {
  transform: translateY(0) scale(0.98);
}

.item-chat-btn.item-chat-active {
  border-color: var(--primary, #0d9488);
  background: var(--teal-50, #f0fdfa);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.22);
}

/* Red dot shown when unread messages exist and the popup is closed.
   Cleared automatically when the popup is opened (chat.js). */
.item-chat-btn.has-unread::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 9px;
  height: 9px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
  pointer-events: none;
}

.item-chat-count-badge {
  background: var(--primary, #0d9488);
  color: white;
  border-radius: 10px;
  padding: 0 5px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
}

/* Container is a fixed-position overlay. JS positions it exclusively via
   transform: translate(x, y) — a GPU-composited operation that never
   triggers layout or paint, giving smooth jitter-free tracking on scroll. */
.item-chat-container {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  width: 440px;
  max-width: calc(100vw - 24px);
  pointer-events: auto;
  will-change: transform;
}

/* The popup card itself — owns its own height constraint so the flex chain works */
.item-chat-popup {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  animation: itemChatSlideIn 0.15s ease;
  display: flex;
  flex-direction: column;
  max-height: min(380px, 60vh);
}

@keyframes itemChatSlideIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.item-chat-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  flex-shrink: 0;
}

.item-chat-popup-header i {
  color: var(--primary, #0d9488);
  margin-right: 4px;
}

.item-chat-close {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  line-height: 1;
  transition: all 0.15s ease;
}

.item-chat-close:hover {
  background: #e5e7eb;
  color: #374151;
}

/* Messages area — flex: 1 so it fills remaining space inside the capped popup */
.item-chat-messages-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-chat-message {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 82%;
}

.item-chat-message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  margin-bottom: 3px;
}

.item-chat-message-author {
  font-weight: 600;
  color: #374151;
}

.item-chat-message-time {
  color: #9ca3af;
}

.item-chat-message-content {
  background: #f3f4f6;
  padding: 6px 10px;
  border-radius: 10px;
  border-top-left-radius: 3px;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #1f2937;
  word-break: break-word;
}

.item-chat-message-own {
  align-self: flex-end;
}

.item-chat-message-own .item-chat-message-meta {
  flex-direction: row-reverse;
}

.item-chat-message-own .item-chat-message-content {
  background: var(--primary, #0d9488);
  color: white;
  border-radius: 10px;
  border-top-right-radius: 3px;
  border-top-left-radius: 10px;
}

.item-chat-empty {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #9ca3af;
  font-size: 0.8rem;
  padding: 4px 0;
}

.item-chat-empty i {
  opacity: 0.4;
}

/* Per-message reaction buttons — overlaps bottom of message bubble */
.item-chat-message-reactions {
  display: flex;
  gap: 2px;
  position: relative;
  margin-top: -7px;
  margin-bottom: 4px;
  padding-left: 6px;
  z-index: 1;
}

.item-chat-message-own .item-chat-message-reactions {
  justify-content: flex-end;
  padding-left: 0;
  padding-right: 6px;
}

/* Add bottom padding to message content so reactions don't obscure text */
.item-chat-message-content:has(
  + .item-chat-message-reactions .msg-reaction-btn.msg-reaction-active
),
.item-chat-message-content {
  padding-bottom: 10px;
}

/* Wrapper needed to anchor the tooltip */
.msg-reaction-wrap {
  position: relative;
  display: inline-flex;
}

.msg-reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 4px;
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  font-size: 0.72rem;
  color: #c4c9d4;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.4;
}

.msg-reaction-btn:hover {
  color: #6b7280;
}

.msg-reaction-btn-up:hover,
.msg-reaction-btn-up.msg-reaction-active {
  color: var(--primary, #0d9488);
  background: var(--teal-50, #f0fdfa);
  border-color: rgba(13, 148, 136, 0.3);
}

.msg-reaction-btn-down:hover,
.msg-reaction-btn-down.msg-reaction-active {
  color: #ef4444;
  background: #fef2f2;
  border-color: rgba(239, 68, 68, 0.2);
}

/* Hover tooltip listing who reacted — matches .auth-wall-tooltip style */
.msg-reaction-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 120px;
  max-width: 180px;
}

.msg-reaction-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(20, 20, 20, 0.92);
}

.msg-reaction-tooltip-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.msg-reaction-tooltip-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
}

.msg-reaction-tooltip-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
}

.msg-reaction-tooltip-initials-up {
  background: var(--primary, #0d9488);
}

.msg-reaction-tooltip-initials-down {
  background: #ef4444;
}

.msg-reaction-tooltip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.msg-reaction-wrap:hover .msg-reaction-tooltip {
  opacity: 1;
}

/* Input form — flex-shrink: 0 keeps it pinned to the bottom of the popup */
.item-chat-form {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}

.item-chat-form input[type="text"] {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 16px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.item-chat-form input[type="text"]:focus {
  border-color: var(--primary, #0d9488);
}

.item-chat-form button[type="submit"] {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary, #0d9488);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.item-chat-form button[type="submit"]:hover {
  opacity: 0.85;
}
