/**
 * JT Messenger - Facebook Messenger Theme for Osclass
 * High quality, responsive, dark & light mode compatible
 */

:root {
  --jtm-primary: #0084FF;
  --jtm-primary-hover: #0073e6;
  --jtm-gradient: linear-gradient(135deg, #0084FF 0%, #00C6FF 100%);
  --jtm-bg: #ffffff;
  --jtm-bg-secondary: #f0f2f5;
  --jtm-bg-tertiary: #e4e6eb;
  --jtm-border: #e4e6eb;
  --jtm-text-main: #050505;
  --jtm-text-muted: #65676b;
  --jtm-msg-received: #f0f2f5;
  --jtm-msg-received-text: #050505;
  --jtm-msg-sent: linear-gradient(135deg, #0084FF 0%, #00C6FF 100%);
  --jtm-msg-sent-text: #ffffff;
  --jtm-online: #31a24c;
  --jtm-shadow: 0 12px 36px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
}

.dark {
  --jtm-bg: #0f172a;
  --jtm-bg-secondary: #1e293b;
  --jtm-bg-tertiary: #334155;
  --jtm-border: #334155;
  --jtm-text-main: #f8fafc;
  --jtm-text-muted: #94a3b8;
  --jtm-msg-received: #1e293b;
  --jtm-msg-received-text: #f8fafc;
  --jtm-shadow: 0 16px 44px rgba(0, 0, 0, 0.45), 0 6px 16px rgba(0, 0, 0, 0.3);
}

/* Base Wrapper */
#jt-messenger-root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--jtm-text-main);
  box-sizing: border-box;
}
#jt-messenger-root *, #jt-messenger-root *:before, #jt-messenger-root *:after {
  box-sizing: border-box;
}

/* Floating Launcher Button - Positioned above #back-to-top */
#jt-messenger-launcher {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--jtm-gradient);
  box-shadow: 0 8px 24px rgba(0, 132, 255, 0.4), 0 2px 8px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  cursor: pointer;
  z-index: 99998;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease, bottom 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#jt-messenger-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 30px rgba(0, 132, 255, 0.55);
}
#jt-messenger-launcher:active {
  transform: scale(0.95);
}
#jt-messenger-launcher svg {
  width: 32px;
  height: 32px;
  fill: #ffffff;
  transition: transform 0.2s ease;
}
#jt-messenger-launcher .jtm-launcher-close {
  display: none;
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
}
#jt-messenger-launcher.is-open svg {
  display: none;
}
#jt-messenger-launcher.is-open .jtm-launcher-close {
  display: block;
}

/* Badge Counter */
#jt-messenger-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background-color: #FA3E3E;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  display: none;
  animation: jtm-pulse 2s infinite;
}
@keyframes jtm-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Docked Messenger Container Window */
#jt-messenger-window {
  position: fixed;
  bottom: 24px;
  right: 92px;
  width: 390px;
  height: 570px;
  max-width: calc(100vw - 110px);
  max-height: calc(100vh - 48px);
  background: var(--jtm-bg);
  border-radius: 20px;
  box-shadow: var(--jtm-shadow);
  border: 1px solid var(--jtm-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), height 0.3s ease, transform 0.2s ease, opacity 0.2s ease;
  transform-origin: bottom right;
}
#jt-messenger-window.is-visible {
  display: flex;
  animation: jtm-popin 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes jtm-popin {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Expanded/Wide Mode */
#jt-messenger-window.is-expanded {
  width: 780px;
  height: 640px;
  max-height: calc(100vh - 60px);
}

/* Messenger Header */
.jtm-header {
  padding: 12px 16px;
  background: var(--jtm-bg);
  border-bottom: 1px solid var(--jtm-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  shrink: 0;
}
.jtm-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.jtm-header-btn-back {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--jtm-bg-secondary);
  color: var(--jtm-text-main);
  cursor: pointer;
  border: 0;
  outline: none;
  font-size: 14px;
  transition: background 0.2s;
  shrink: 0;
}
.jtm-header-btn-back:hover {
  background: var(--jtm-bg-tertiary);
}
.jtm-header-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--jtm-text-main);
  letter-spacing: -0.3px;
  margin: 0;
}
.jtm-header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.jtm-avatar-wrap {
  position: relative;
  width: 38px;
  height: 38px;
  shrink: 0;
}
.jtm-avatar-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.jtm-status-dot {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--jtm-online);
  border: 2px solid var(--jtm-bg);
}
.jtm-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.jtm-header-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--jtm-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.jtm-header-sub {
  font-size: 11px;
  color: var(--jtm-text-muted);
  line-height: 1.2;
  margin-top: 2px;
}

.jtm-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  shrink: 0;
}
.jtm-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--jtm-bg-secondary);
  color: var(--jtm-text-muted);
  border: 0;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.jtm-action-btn:hover {
  background: var(--jtm-bg-tertiary);
  color: var(--jtm-text-main);
}

/* Messenger Body: Dual Pane */
.jtm-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* Inbox View / Threads List */
.jtm-threads-pane {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--jtm-bg);
  overflow: hidden;
}
#jt-messenger-window.is-expanded .jtm-threads-pane {
  width: 310px;
  border-right: 1px solid var(--jtm-border);
  shrink: 0;
}

/* Search Bar */
.jtm-search-wrap {
  padding: 10px 14px;
}
.jtm-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--jtm-bg-secondary);
  padding: 8px 12px;
  border-radius: 20px;
  color: var(--jtm-text-muted);
}
.jtm-search-box input {
  border: 0;
  outline: none;
  background: transparent;
  width: 100%;
  font-size: 13px;
  color: var(--jtm-text-main);
}
.jtm-search-box input::placeholder {
  color: var(--jtm-text-muted);
}

/* Threads List Scroll */
.jtm-threads-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.jtm-threads-list::-webkit-scrollbar {
  width: 6px;
}
.jtm-threads-list::-webkit-scrollbar-thumb {
  background: var(--jtm-bg-tertiary);
  border-radius: 3px;
}

/* Thread Item */
.jtm-thread-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  user-select: none;
}
.jtm-thread-item:hover {
  background: var(--jtm-bg-secondary);
}
.jtm-thread-item.is-active {
  background: var(--jtm-bg-secondary);
}
.jtm-thread-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  shrink: 0;
}
.jtm-thread-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.jtm-thread-avatar .jtm-status-dot {
  width: 12px;
  height: 12px;
  bottom: 1px;
  right: 1px;
}
.jtm-thread-info {
  flex: 1;
  min-width: 0;
}
.jtm-thread-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.jtm-thread-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--jtm-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.jtm-thread-time {
  font-size: 11px;
  color: var(--jtm-text-muted);
  shrink: 0;
  margin-left: 6px;
}
.jtm-thread-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.jtm-thread-snippet {
  font-size: 12.5px;
  color: var(--jtm-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.jtm-thread-item.has-unread .jtm-thread-name {
  font-weight: 800;
}
.jtm-thread-item.has-unread .jtm-thread-snippet {
  font-weight: 700;
  color: var(--jtm-text-main);
}
.jtm-unread-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--jtm-primary);
  shrink: 0;
}

/* Empty State */
.jtm-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 30px 20px;
  text-align: center;
  color: var(--jtm-text-muted);
}
.jtm-empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
  color: var(--jtm-primary);
  opacity: 0.8;
}
.jtm-empty-state h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--jtm-text-main);
  margin: 0 0 4px;
}
.jtm-empty-state p {
  font-size: 12px;
  margin: 0;
  line-height: 1.4;
}

/* Conversation / Chat Thread Pane */
.jtm-chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--jtm-bg);
  min-width: 0;
  height: 100%;
  position: relative;
}

/* Marketplace Attached Item Header */
.jtm-item-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--jtm-bg-secondary);
  border-bottom: 1px solid var(--jtm-border);
  font-size: 12px;
}
.jtm-item-banner-img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: #cbd5e1;
  shrink: 0;
}
.jtm-item-banner-info {
  flex: 1;
  min-width: 0;
}
.jtm-item-banner-title {
  font-weight: 700;
  color: var(--jtm-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  display: block;
}
.jtm-item-banner-price {
  font-weight: 800;
  color: #10b981;
  margin-top: 1px;
}
.jtm-item-banner-btn {
  padding: 4px 10px;
  border-radius: 14px;
  background: var(--jtm-primary);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  shrink: 0;
  transition: opacity 0.2s;
}
.jtm-item-banner-btn:hover {
  opacity: 0.9;
}

/* Quick Inquiry Chips */
.jtm-quick-chips {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-bottom: 1px solid var(--jtm-border);
  background: var(--jtm-bg);
  scrollbar-width: none;
}
.jtm-quick-chips::-webkit-scrollbar {
  display: none;
}
.jtm-chip {
  padding: 5px 11px;
  border-radius: 16px;
  background: var(--jtm-bg-secondary);
  color: var(--jtm-text-main);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--jtm-border);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.jtm-chip:hover {
  background: var(--jtm-primary);
  color: #ffffff;
  border-color: var(--jtm-primary);
}

/* Messages Stream */
.jtm-messages-stream {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.jtm-messages-stream::-webkit-scrollbar {
  width: 6px;
}
.jtm-messages-stream::-webkit-scrollbar-thumb {
  background: var(--jtm-bg-tertiary);
  border-radius: 3px;
}

/* Date Divider */
.jtm-date-divider {
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--jtm-text-muted);
  margin: 10px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Message Row */
.jtm-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 82%;
  margin-bottom: 2px;
  animation: jtm-fadein 0.15s ease-out;
}
@keyframes jtm-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.jtm-msg-row.is-received {
  align-self: flex-start;
}
.jtm-msg-row.is-sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.jtm-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  shrink: 0;
}

/* Message Bubble */
.jtm-bubble {
  padding: 9px 14px;
  font-size: 13.5px;
  line-height: 1.42;
  word-break: break-word;
  position: relative;
}
.jtm-msg-row.is-received .jtm-bubble {
  background: var(--jtm-msg-received);
  color: var(--jtm-msg-received-text);
  border-radius: 18px 18px 18px 4px;
}
.jtm-msg-row.is-sent .jtm-bubble {
  background: var(--jtm-msg-sent);
  color: var(--jtm-msg-sent-text);
  border-radius: 18px 18px 4px 18px;
}

/* Bubble Attachment Image */
.jtm-bubble-img {
  max-width: 220px;
  max-height: 260px;
  border-radius: 12px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  margin-bottom: 4px;
  transition: opacity 0.2s;
}
.jtm-bubble-img:hover {
  opacity: 0.95;
}

/* Message Time & Status */
.jtm-msg-meta {
  font-size: 10px;
  color: var(--jtm-text-muted);
  margin-top: 2px;
  display: none;
}
.jtm-msg-row:hover .jtm-msg-meta {
  display: block;
}
.jtm-msg-row.is-sent .jtm-msg-meta {
  text-align: right;
}

/* Typing Indicator Bubble */
.jtm-typing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  margin-top: 4px;
}
.jtm-typing-bubble {
  padding: 10px 14px;
  background: var(--jtm-msg-received);
  border-radius: 18px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.jtm-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--jtm-text-muted);
  animation: jtm-bounce 1.4s infinite ease-in-out both;
}
.jtm-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.jtm-typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes jtm-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Composer / Input Area */
.jtm-composer {
  padding: 10px 12px;
  background: var(--jtm-bg);
  border-top: 1px solid var(--jtm-border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  shrink: 0;
}
.jtm-composer-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--jtm-primary);
  border: 0;
  cursor: pointer;
  font-size: 16px;
  shrink: 0;
  transition: background 0.15s, transform 0.15s;
}
.jtm-composer-btn:hover {
  background: var(--jtm-bg-secondary);
  transform: scale(1.05);
}

.jtm-input-wrap {
  flex: 1;
  background: var(--jtm-bg-secondary);
  border-radius: 20px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  min-height: 36px;
  max-height: 100px;
}
.jtm-input-field {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--jtm-text-main);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  line-height: 1.35;
  padding: 2px 0;
  max-height: 80px;
  overflow-y: auto;
}
.jtm-input-field::placeholder {
  color: var(--jtm-text-muted);
}

/* Blue Thumbs-Up / Send Button */
.jtm-btn-send {
  color: var(--jtm-primary);
  font-size: 18px;
}
.jtm-btn-send.is-send-mode {
  transform: rotate(0deg);
}

/* Image Upload Preview in Composer */
.jtm-upload-preview {
  position: relative;
  display: none;
  margin-bottom: 6px;
  padding: 6px 12px;
  background: var(--jtm-bg-secondary);
  border-top: 1px solid var(--jtm-border);
}
.jtm-upload-preview img {
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
}
.jtm-upload-preview-remove {
  position: absolute;
  top: 2px;
  left: 60px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
}

/* Lightbox Modal for Full Image View */
#jtm-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#jtm-lightbox.is-open {
  display: flex;
}
#jtm-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
#jtm-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: #ffffff;
  font-size: 28px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
}

/* Seller Button on Listing Page */
.jt-messenger-item-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--jtm-gradient);
  color: #ffffff !important;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  border: 0;
  box-shadow: 0 4px 14px rgba(0, 132, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.jt-messenger-item-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 132, 255, 0.45);
}
.jt-messenger-item-btn svg {
  width: 20px;
  height: 20px;
  fill: #ffffff;
}

/* Mobile Screens */
@media (max-width: 640px) {
  #jt-messenger-launcher {
    bottom: 74px;
    right: 18px;
    width: 52px;
    height: 52px;
  }
  #jt-messenger-launcher svg {
    width: 28px;
    height: 28px;
  }
  #jt-messenger-window {
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
  }
}
