/* ---- Chat Panel ---- */

.chat-panel {
  position: relative;
  width: 560px;
  min-width: 280px;
  max-width: 800px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ---- Resize handle (left edge of chat panel) ---- */
.chat-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 10;
  transition: background 0.15s;
}

.chat-resize-handle:hover,
.chat-resize-handle.dragging {
  background: var(--primary);
  opacity: 0.35;
}

.chat-header {
  padding: 14px 20px;
  font-weight: 700;
  color: var(--text-bright);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 12px;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-msg {
  background: var(--bg-sunken);
  border-radius: 8px;
  padding: 10px 12px;
  max-width: 100%;
}

.chat-msg-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 3px;
}

.chat-msg-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

/* ---- Clickable Links ---- */
.chat-link {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-color: var(--primary);
  text-underline-offset: 2px;
  word-break: break-all;
  transition: opacity 0.15s;
}
.chat-link:hover {
  opacity: 0.8;
}

.chat-msg-img {
  max-width: 100%;
  border-radius: 6px;
  margin-top: 6px;
  cursor: pointer;
}

.chat-msg-time {
  font-size: 10px;
  color: var(--text-ghost);
  margin-top: 4px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  align-items: center;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 14px;
  outline: none;
  min-width: 0;
}

#chat-input:focus {
  border-color: var(--primary);
}

.chat-img-btn {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  user-select: none;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
}

.chat-img-btn:hover {
  background: var(--bg-elevated-hover);
  color: var(--text);
}

#chat-send-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: var(--text-bright);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

#chat-send-btn:hover {
  background: var(--primary-hover);
}

.image-preview {
  padding: 8px 16px;
  position: relative;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.image-preview img {
  max-width: 100%;
  max-height: 120px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

#image-preview-remove {
  position: absolute;
  top: 4px;
  right: 12px;
  background: var(--danger);
  color: var(--text-bright);
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

/* ---- Link Embeds ---- */
.chat-embed {
  margin-top: 8px;
  padding: 10px 12px;
  border-left: 3px solid var(--primary);
  background: var(--bg-elevated, rgba(255,255,255,0.04));
  border-radius: 0 6px 6px 0;
  position: relative;
  overflow: hidden;
}
.chat-embed.collapsed > *:not(.chat-embed-toggle) {
  display: none;
}
.chat-embed-toggle {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1;
}
.chat-embed-toggle:hover {
  background: var(--bg-sunken);
  color: var(--text);
}
.chat-embed-site {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.chat-embed-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 4px;
  word-break: break-word;
}
.chat-embed-title:hover {
  text-decoration: underline;
}
.chat-embed-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
}
.chat-embed-img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 4px;
  margin-top: 4px;
}

/* YouTube embed */
.chat-embed-yt-thumb {
  position: relative;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}
.chat-embed-yt-thumb img {
  width: 100%;
  display: block;
  border-radius: 6px;
}
.chat-embed-yt-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: rgba(0,0,0,0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  transition: background 0.2s;
}
.chat-embed-yt-thumb:hover .chat-embed-yt-play {
  background: rgba(255,0,0,0.85);
}
.chat-embed-yt-iframe {
  width: 100%;
  aspect-ratio: 16/9;
  border: none;
  border-radius: 6px;
}

/* ---- Search ---- */
.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-search-bar input[type="text"] {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 12px;
  outline: none;
  min-width: 0;
}
.chat-search-bar input[type="text"]:focus {
  border-color: var(--primary);
}
.chat-search-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
.chat-search-clear:hover {
  color: var(--text);
  background: var(--bg-elevated);
}
.chat-msg.search-dim {
  opacity: 0.15;
}
.chat-msg.search-match {
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

/* ---- GIF in chat ---- */
.chat-msg-gif {
  max-width: 100%;
  max-height: 250px;
  border-radius: 6px;
  margin-top: 6px;
  cursor: pointer;
}

/* ---- Custom Emoji inline ---- */
.chat-custom-emoji {
  display: inline;
  width: 32px;
  height: 32px;
  vertical-align: middle;
  margin: 0 1px;
}

/* ---- GIF Picker ---- */
.gif-picker {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  flex-shrink: 0;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gif-search-input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 12px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.gif-search-input:focus {
  border-color: var(--primary);
}

.gif-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.gif-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.gif-thumb:hover {
  opacity: 0.8;
}

.gif-attr {
  font-size: 10px;
  color: var(--text-ghost);
  text-align: right;
  flex-shrink: 0;
}

.chat-gif-btn {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
.chat-gif-btn:hover,
.chat-gif-btn.active {
  background: var(--bg-elevated-hover);
  color: var(--text);
}

/* ---- Emoji Picker ---- */
.emoji-picker {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  flex-shrink: 0;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.emoji-tabs {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.emoji-tab {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.emoji-tab.active {
  background: var(--primary);
  color: var(--text-bright);
  border-color: var(--primary);
}

.emoji-tab-content {
  display: none;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}
.emoji-tab-content.active {
  display: flex;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  font-size: 22px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
  border: none;
  background: none;
  padding: 0;
}
.emoji-item:hover {
  background: var(--bg-elevated);
}

.emoji-item img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.emoji-upload-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.emoji-upload-row input[type="text"] {
  flex: 1;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 11px;
  outline: none;
  min-width: 0;
}
.emoji-upload-row input[type="text"]:focus {
  border-color: var(--primary);
}

.emoji-upload-btn {
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.emoji-upload-btn:hover {
  background: var(--bg-elevated-hover);
  color: var(--text);
}

.chat-emoji-btn {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.2s;
}
.chat-emoji-btn:hover,
.chat-emoji-btn.active {
  background: var(--bg-elevated-hover);
}

/* ---- Chat Video ---- */
.chat-msg-video {
  max-width: 100%;
  max-height: 300px;
  border-radius: 6px;
  margin-top: 6px;
  display: block;
}

/* ---- Video Preview ---- */
#video-preview-el {
  display: none;
  max-width: 100%;
  max-height: 120px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* ---- Lazy-load media placeholder ---- */
.chat-media-load-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chat-media-load-btn:hover:not(:disabled) {
  background: var(--bg-elevated-hover);
  color: var(--text);
}
.chat-media-load-btn:disabled {
  cursor: default;
  opacity: 0.6;
}

/* ---- Image Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  background: var(--overlay-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}
