/* ── Messages Layout ────────────────────────────────────── */

.msg-container {
  max-width: 1100px;
  margin: 0 auto;
  padding-top: 70px;
}

.msg-auth-gate {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 1rem;
}

.msg-panels {
  display: flex;
  height: calc(100vh - 70px);
  border: 1px solid var(--border-tactical);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-card);
}

/* ── Inbox Panel ───────────────────────────────────────── */

.msg-inbox-panel {
  width: 360px;
  min-width: 300px;
  border-right: 1px solid var(--border-tactical);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.msg-inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-tactical);
}

.msg-inbox-title {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.msg-new-btn {
  background: none;
  border: none;
  color: var(--accent-gold);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.2s;
}

.msg-new-btn:hover {
  background: rgba(201, 168, 76, 0.1);
}

.msg-inbox-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-tactical);
}

.msg-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    color 0.2s,
    border-color 0.2s;
}

.msg-tab:hover {
  color: var(--text-primary);
}

.msg-tab--active {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
}

.msg-inbox-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Conversation Card */
.msg-conv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.msg-conv:hover {
  background: rgba(255, 255, 255, 0.03);
}

.msg-conv--active {
  background: rgba(201, 168, 76, 0.08);
}

.msg-conv--unread .msg-conv-name {
  font-weight: 700;
  color: var(--text-primary);
}

.msg-conv--unread .msg-conv-preview {
  color: var(--text-secondary);
  font-weight: 500;
}

.msg-conv-avatar {
  position: relative;
  flex-shrink: 0;
}

.msg-conv-online {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #4caf50;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}

.msg-conv-content {
  flex: 1;
  min-width: 0;
}

.msg-conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.msg-conv-name {
  font-size: 0.9rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-conv-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.msg-conv-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.msg-conv-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.msg-conv-badge {
  background: var(--accent-gold);
  color: var(--bg-primary);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.msg-conv-status {
  flex-shrink: 0;
  color: var(--text-muted);
}

.msg-conv-status--read {
  color: var(--accent-gold);
}

/* ── Thread Panel ──────────────────────────────────────── */

.msg-thread-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.msg-thread-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-tactical);
  min-height: 56px;
}

.msg-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.msg-thread-partner {
  display: flex;
  align-items: center;
  gap: 10px;
}

.msg-thread-partner-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.msg-thread-partner-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.msg-thread-partner-status--online {
  color: #4caf50;
}

/* Bubbles */
.msg-bubbles {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-thread-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.msg-date-divider {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 16px 0 8px;
}

.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.msg-bubble-wrap--mine {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-bubble-wrap--theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}

.msg-bubble--mine {
  background: var(--accent-gold);
  color: var(--bg-primary);
  border-bottom-right-radius: 4px;
}

.msg-bubble--theirs {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-bubble-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.msg-bubble-wrap--mine .msg-bubble-meta {
  justify-content: flex-end;
}

.msg-status-icon {
  display: inline-flex;
}

.msg-status-icon--read {
  color: var(--accent-gold);
}

/* Reactions */
.msg-reactions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.msg-reaction {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-tactical);
  cursor: pointer;
}

.msg-reaction--mine {
  border-color: var(--accent-gold);
}

/* Episode attachment */
.msg-episode-card {
  display: flex;
  gap: 8px;
  padding: 8px;
  margin-top: 6px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  font-size: 0.8rem;
}

.msg-episode-card img {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
}

.msg-episode-title {
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Compose Box */
.msg-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-tactical);
}

.msg-compose-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}

.msg-compose-input:focus {
  outline: none;
  border-color: var(--accent-gold);
}

.msg-send-btn {
  background: var(--accent-gold);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--bg-primary);
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.msg-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.msg-blocked-banner {
  padding: 12px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-tactical);
  background: var(--bg-surface);
}

/* Load more */
.msg-load-more {
  text-align: center;
  padding: 12px;
}

.msg-load-more-btn {
  background: none;
  border: 1px solid var(--border-tactical);
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 0.8rem;
  cursor: pointer;
}

.msg-load-more-btn:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* ── New Message Modal ─────────────────────────────────── */

.msg-new-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg-new-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-tactical);
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.msg-new-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-tactical);
}

.msg-new-header h2 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--text-primary);
}

.msg-new-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.msg-new-search {
  margin: 12px 20px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.msg-new-search:focus {
  outline: none;
  border-color: var(--accent-gold);
}

.msg-new-results {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.msg-new-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.msg-new-user:hover {
  background: rgba(255, 255, 255, 0.04);
}

.msg-new-user-name {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.msg-new-user-handle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Loading & Empty States ────────────────────────────── */

.msg-loading {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

/* ── Responsive (Mobile) ───────────────────────────────── */

@media (max-width: 767px) {
  .msg-panels {
    height: calc(100vh - 60px);
    border-radius: 0;
    border: none;
  }

  .msg-inbox-panel {
    width: 100%;
    min-width: 0;
    border-right: none;
  }

  .msg-thread-panel {
    display: none;
  }

  .msg-back-btn {
    display: block;
  }

  /* When thread is open on mobile */
  .msg-panels--thread-open .msg-inbox-panel {
    display: none;
  }

  .msg-panels--thread-open .msg-thread-panel {
    display: flex;
  }
}
