/* ═══════════════════════════════════════════════════════════════════
   SarahAndBran -- Chat Page Styles
   ═══════════════════════════════════════════════════════════════════ */

body.chat-page {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 900px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* ── Chat Header ─────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.chat-header__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-header__back {
  flex-shrink: 0;
  margin-left: -6px;
  text-decoration: none;
}

.chat-header__avatar-wrap {
  position: relative;
  width: 42px;
  height: 42px;
}

.chat-header__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.chat-header__avatar:hover {
  border-color: var(--accent-purple);
  transform: scale(1.06);
}

.chat-header__status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  background: var(--text-muted);
}

.status--online { background: #34d399; }
.status--offline { background: var(--text-muted); }

.chat-header__info { min-width: 0; }

.chat-header__name {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__right {
  display: flex;
  gap: 4px;
}

/* ── Theme Toggle Icons ──────────────────────────────────────── */

[data-theme="dark"] .theme-icon--dark { display: block; }
[data-theme="dark"] .theme-icon--light { display: none; }
[data-theme="light"] .theme-icon--dark { display: none; }
[data-theme="light"] .theme-icon--light { display: block; }

/* ── Offline Banner ──────────────────────────────────────────── */

.offline-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
  font-size: 0.82rem;
  z-index: 20;
}

/* ── Messages Area ───────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-messages.drag-over {
  outline: 2px dashed var(--accent-purple);
  outline-offset: -8px;
  background: rgba(167, 139, 250, 0.05);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100%;
  justify-content: flex-end;
}

/* ── Message Bubbles ─────────────────────────────────────────── */

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 80%;
}

.message-row--mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row--theirs {
  align-self: flex-start;
}

.message-row__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.message {
  position: relative;
  padding: 10px 14px;
  border-radius: 18px;
  transition: transform 0.15s ease, background var(--transition);
  animation: messageIn 0.25s ease;
  min-width: 0;
  flex: 1;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message:hover { transform: translateY(-1px); }

.message--mine {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.2), rgba(244, 114, 182, 0.15));
  border-bottom-right-radius: 6px;
}

.message--theirs {
  background: var(--bg-surface-2);
  border-bottom-left-radius: 6px;
}

.message-row--highlight .message {
  animation: highlightPulse 2s ease;
}

@keyframes highlightPulse {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 3px var(--accent-purple); }
}

.message__text {
  font-size: 0.92rem;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message__text a {
  color: var(--accent-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message__deleted {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.message__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.message__edited {
  font-style: italic;
}

.message__status {
  font-size: 0.75rem;
}

.message--mine .message__status { color: var(--accent-purple); }

/* ── Reply ───────────────────────────────────────────────────── */

.message__reply {
  padding: 6px 10px;
  margin-bottom: 6px;
  border-left: 3px solid var(--accent-purple);
  border-radius: 4px;
  background: rgba(167, 139, 250, 0.08);
  font-size: 0.8rem;
  cursor: pointer;
}

.message__reply-label {
  display: block;
  font-weight: 600;
  color: var(--accent-purple);
  font-size: 0.72rem;
  margin-bottom: 2px;
}

.message__reply-text {
  color: var(--text-secondary);
}

/* ── Media ───────────────────────────────────────────────────── */

.message__media {
  margin-bottom: 4px;
}

.message__img {
  max-width: 280px;
  max-height: 300px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s ease;
  display: block;
}

.message__img:hover { transform: scale(1.02); }

.message__gif {
  max-width: 250px;
  max-height: 250px;
  border-radius: 12px;
  display: block;
}

.message__audio audio {
  max-width: 260px;
  height: 36px;
}

/* ── Reactions ───────────────────────────────────────────────── */

.message__reactions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
}

.reaction-badge:hover {
  background: var(--bg-hover);
  transform: scale(1.08);
}

.reaction-badge--mine {
  border-color: var(--accent-purple);
  background: rgba(167, 139, 250, 0.1);
}

/* ── Quick React Bar ─────────────────────────────────────────── */

.quick-react-bar {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  margin-top: 4px;
  background: var(--bg-surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
  animation: popIn 0.2s ease;
  width: fit-content;
}

.message--mine .quick-react-bar { margin-left: auto; }

@keyframes popIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.quick-react-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}

.quick-react-btn:hover {
  transform: scale(1.3);
  background: var(--bg-hover);
}

/* ── Message Actions (hover overlay) ─────────────────────────── */

.message__actions {
  display: none;
  gap: 2px;
  padding: 3px 4px;
  margin-top: 4px;
  background: var(--bg-surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  width: fit-content;
}

.message--mine .message__actions { margin-left: auto; }

.message:hover .message__actions,
.message-row:hover .message__actions { display: flex; }

.msg-action {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.msg-action:hover { background: var(--bg-hover); }

/* ── Typing Indicator ────────────────────────────────────────── */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.typing-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Composer ────────────────────────────────────────────────── */

.chat-composer {
  flex-shrink: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  position: relative;
}

.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 6px;
  border-left: 3px solid var(--accent-purple);
  border-radius: 6px;
  background: rgba(167, 139, 250, 0.08);
}

.reply-preview__label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-purple);
}

.reply-preview__text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-left: 6px;
}

.reply-preview__close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
}

.media-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin-bottom: 6px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
}

.media-preview__items {
  display: flex;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
}

.media-preview__item {
  position: relative;
  flex-shrink: 0;
}

.media-preview__item img {
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
}

.media-preview__remove {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(248, 113, 113, 0.9);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-preview__close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.audio-preview-badge {
  padding: 12px 16px;
  background: var(--bg-hover);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.composer-btn {
  flex-shrink: 0;
}

.composer-btn.recording svg { color: #f87171; animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.composer-input-wrap {
  flex: 1;
  min-width: 0;
}

.composer-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color var(--transition);
}

.composer-input:focus { border-color: var(--accent-purple); }
.composer-input::placeholder { color: var(--text-muted); }
@media (max-width: 767px) {
  .composer-input { scrollbar-width: none; }
  .composer-input::-webkit-scrollbar { display: none; }
}

/* Compact scrollbars for the floating panels -- the global 12px bar is too
   heavy inside a 320px picker or a dropdown. */
.emoji-picker::-webkit-scrollbar,
.search-overlay::-webkit-scrollbar {
  width: 9px;
}

.emoji-picker::-webkit-scrollbar-thumb,
.emoji-picker::-webkit-scrollbar-thumb:hover,
.emoji-picker::-webkit-scrollbar-thumb:active,
.search-overlay::-webkit-scrollbar-thumb,
.search-overlay::-webkit-scrollbar-thumb:hover,
.search-overlay::-webkit-scrollbar-thumb:active {
  border-width: 2px;
}

.send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-purple));
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
}

.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn:hover:not(:disabled) { transform: scale(1.08); }

/* ── Search Overlay ──────────────────────────────────────────── */

.search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search-bar svg { flex-shrink: 0; color: var(--text-muted); }

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

.search-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.search-results { padding: 8px 0; }

.search-result {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.search-result:hover { background: var(--bg-hover); }

.search-result__time {
  font-size: 0.75rem;
  color: var(--text-muted);
  float: right;
}

.search-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.9rem;
}

/* ── Emoji Picker ────────────────────────────────────────────── */

.emoji-picker {
  position: fixed;
  width: 320px;
  max-height: 320px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 50;
  overflow-y: auto;
  animation: popIn 0.15s ease;
}

.emoji-picker__search {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.emoji-picker__input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface-2);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.emoji-picker__grid { padding: 8px; }

.emoji-cat { margin-bottom: 8px; }

.emoji-cat__label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding-left: 4px;
}

.emoji-cat__row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.emoji-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s ease, transform 0.1s ease;
}

.emoji-btn:hover {
  background: var(--bg-hover);
  transform: scale(1.2);
}

/* ── Lightbox ────────────────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(12px);
  cursor: pointer;
}

.lightbox__close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  cursor: default;
}

/* ── Inline Edit ─────────────────────────────────────────────── */

.edit-inline {
  margin-top: 4px;
}

.edit-inline__input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--accent-purple);
  border-radius: 10px;
  background: var(--bg-surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  outline: none;
  resize: vertical;
  min-height: 36px;
  max-height: 160px;
  line-height: 1.4;
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
}

.edit-inline__input:focus {
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.35);
}

.edit-inline__bar {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 6px;
}

.edit-inline__save,
.edit-inline__cancel {
  padding: 4px 14px;
  border: none;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.edit-inline__save {
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-purple));
  color: #fff;
}

.edit-inline__save:hover:not(:disabled) { transform: scale(1.04); }
.edit-inline__save:disabled { opacity: 0.5; cursor: not-allowed; }

.edit-inline__cancel {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.edit-inline__cancel:hover { background: var(--bg-hover); }

/* ── Video messages ────────────────────────────────────────────── */

.message__video {
  max-width: 320px;
  max-height: 400px;
  border-radius: 10px;
  width: 100%;
}

.video-preview-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ── Upload progress ──────────────────────────────────────────── */

.upload-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-width: 140px;
  background: var(--bg-surface);
  border-radius: 8px;
}

.upload-progress__track {
  flex: 1;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress__bar {
  height: 100%;
  border-radius: 2px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-pink), var(--accent-purple));
  transition: width 0.2s ease;
}

.upload-progress__text {
  font-size: 0.72rem;
  color: var(--text-secondary);
  min-width: 30px;
  text-align: right;
  white-space: nowrap;
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 600px) {
  body.chat-page { border-left: none; border-right: none; }
  .message-row { max-width: 90%; }
  .message__img { max-width: 220px; }
  .message__video { max-width: 260px; }
  .chat-header { padding: 8px 12px; }
  .chat-header__back { width: 32px; height: 32px; margin-left: -4px; }
  .chat-header__back svg { width: 18px; height: 18px; }
  .emoji-picker { left: 8px; right: 8px; width: auto; }
  .message-row__avatar { width: 30px; height: 30px; }
}
