/* ============================================================
   KreepCore - Messages (AAA Redesign v2)
   "Secure Comms Terminal" aesthetic
   ============================================================ */

/* ── Messages panel wrapper ─────────────────────────────────── */
.messages-panel {
  padding: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Layout - sidebar + content ─────────────────────────────── */
.msg-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
}

/* ── Channel Sidebar ────────────────────────────────────────── */
.msg-sidebar {
  width: 170px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid rgba(var(--accent-rgb), 0.08);
  background:
    linear-gradient(180deg,
      rgba(var(--accent-rgb), 0.03) 0%,
      rgba(6, 6, 15, 0.4) 60%,
      transparent 100%
    );
  position: relative;
  padding: 4px 0;
}

/* Sidebar glow line */
.msg-sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg,
    rgba(var(--accent-rgb), 0.3),
    rgba(var(--accent-rgb), 0.08) 50%,
    transparent
  );
}

/* Sidebar icon */
.msg-sidebar-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.msg-sidebar-item.active .msg-sidebar-icon {
  opacity: 1;
  filter: drop-shadow(0 0 3px rgba(var(--accent-rgb), 0.4));
}

.msg-sidebar-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.msg-sidebar-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-left: 2px solid transparent;
  background: none;
  color: var(--text-secondary);
  font-size: 1.05rem;
  font-family: var(--font-mono);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  letter-spacing: 0.02em;
}

.msg-sidebar-item:hover {
  background: rgba(var(--accent-rgb), 0.06);
  color: var(--text-primary);
}

.msg-sidebar-item:hover .msg-sidebar-icon {
  opacity: 0.8;
}

.msg-sidebar-item.active {
  border-left-color: var(--cyan);
  background:
    linear-gradient(90deg,
      rgba(var(--accent-rgb), 0.12) 0%,
      rgba(var(--accent-rgb), 0.03) 100%
    );
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(var(--accent-rgb), 0.3);
}

/* Active pulse glow */
.msg-sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 2px;
  background: var(--cyan);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.6);
  animation: glowPulse 2.5s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
}

.msg-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-left: 14px;
  background:
    radial-gradient(ellipse at 80% 100%, rgba(var(--accent-rgb), 0.02) 0%, transparent 50%);
}

/* ── Mobile / narrow tablet: sidebar becomes a compact
   multi-row pill strip (wraps as needed). Everything visible,
   no horizontal scroll, no folders hidden off-screen. ─── */
/* Mobile folder bar: transparent on desktop (fab keeps its old layout),
   one flex row with the channel select on narrow screens. */
.msg-mobile-bar { display: contents; }
.msg-channel-select { display: none; }

@media (max-width: 900px) {
  .msg-mobile-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
  }
  .msg-mobile-bar .msg-compose-fab { margin-bottom: 0; flex: none; }
  .msg-channel-select {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    background: rgba(7, 10, 22, 0.85);
    border: 1px solid rgba(var(--accent-rgb), 0.3);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.85rem;
  }
  .msg-sidebar { display: none; }
  .msg-layout {
    flex-direction: column;
    min-height: 0;
  }
  .msg-sidebar-legacy-rules {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid rgba(var(--accent-rgb), 0.12);
    padding: 6px 8px;
    background: linear-gradient(90deg,
      rgba(var(--accent-rgb), 0.04) 0%,
      transparent 60%
    );
    position: relative;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
  }
  .msg-sidebar::after { display: none; }

  .msg-sidebar-item {
    white-space: nowrap;
    flex-shrink: 0;
    flex-grow: 0;
    width: auto;
    border-left: none;
    border-bottom: 2px solid transparent;
    padding: 8px 12px;
    font-size: 0.9rem;
    text-align: center;
    justify-content: center;
    gap: 6px;
  }
  .msg-sidebar-icon { width: 14px; height: 14px; }
  .msg-sidebar-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--cyan);
  }
  .msg-sidebar-item.active::before { display: none; }

  .msg-sidebar-divider {
    min-width: 1px;
    width: 1px;
    height: 22px;
    align-self: center;
    margin: 0 4px;
    flex-shrink: 0;
    background: linear-gradient(180deg,
      transparent,
      rgba(var(--accent-rgb), 0.25),
      transparent
    );
  }

  #msg-leader-folders,
  #msg-npc-folders {
    display: contents;
  }

  .msg-sidebar-leader {
    padding: 8px 12px !important;
    font-size: 0.88rem !important;
    gap: 6px;
  }
  .msg-sidebar-portrait {
    width: 20px;
    height: 20px;
  }

  .msg-main {
    padding-left: 0;
    padding-top: 10px;
    flex: 1;
    min-height: 0;
  }
}

/* ── Leader sidebar folders ─────────────────────────────────── */
.msg-sidebar-divider {
  height: 1px;
  margin: 8px 12px;
  background: linear-gradient(90deg,
    rgba(var(--accent-rgb), 0.25),
    transparent
  );
}

.msg-sidebar-leader {
  display: flex !important;
  align-items: center;
  justify-content: flex-start !important;
  gap: 10px;
  padding: 12px 16px !important;
  font-size: 0.98rem !important;
  text-align: left;
}

.msg-sidebar-portrait {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1.5px solid rgba(var(--accent-rgb), 0.2);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.1);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.msg-sidebar-leader.active .msg-sidebar-portrait {
  border-color: rgba(var(--accent-rgb), 0.5);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.2);
}

/* NPC faction dot (shown instead of a portrait for diplomacy threads) */
.msg-sidebar-npc-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

/* ── NPC proposal card (rendered as a full-width block
   below the NPC bubble, not next to it) ────────────────── */

.npc-proposal-wrap {
  align-self: stretch;
  width: 100%;
  margin-top: -4px;
  margin-bottom: 6px;
}

.npc-proposal-card {
  padding: 12px 14px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.08), rgba(251, 191, 36, 0.02));
  border-radius: 8px;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.08);
  font-size: 0.88rem;
  width: 100%;
  box-sizing: border-box;
}

.npc-proposal-card--accepted {
  border-color: rgba(16, 185, 129, 0.4);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08), rgba(16, 185, 129, 0.02));
  box-shadow: none;
}

.npc-proposal-card--rejected,
.npc-proposal-card--expired {
  border-color: rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.4);
  opacity: 0.7;
  box-shadow: none;
}

.npc-proposal-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fbbf24;
  margin-bottom: 10px;
}

.npc-proposal-card--accepted .npc-proposal-head { color: #34d399; }
.npc-proposal-card--rejected .npc-proposal-head { color: #94a3b8; }
.npc-proposal-card--expired  .npc-proposal-head { color: #94a3b8; }

.npc-proposal-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.npc-proposal-cols {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: start;
  margin-bottom: 10px;
}

.npc-proposal-col-label {
  font-size: 0.72rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 5px;
}

.npc-proposal-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.npc-proposal-list li {
  font-size: 0.88rem;
  color: #e2e8f0;
}

.npc-proposal-amount {
  color: #fbbf24;
  font-weight: 700;
}

.npc-proposal-card--accepted .npc-proposal-amount { color: #34d399; }

.npc-proposal-empty {
  color: #64748b;
  font-size: 10px;
}

.npc-proposal-arrow {
  color: #64748b;
  font-size: 16px;
  padding-top: 14px;
}

.npc-proposal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(251, 191, 36, 0.22);
}

.npc-proposal-card--accepted .npc-proposal-actions,
.npc-proposal-card--rejected .npc-proposal-actions,
.npc-proposal-card--expired  .npc-proposal-actions {
  border-top-color: rgba(148, 163, 184, 0.15);
}

.npc-proposal-btn {
  background: transparent;
  border: 1px solid rgba(226, 232, 240, 0.25);
  color: #e2e8f0;
  padding: 7px 14px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.npc-proposal-btn--accept {
  border-color: rgba(16, 185, 129, 0.55);
  color: #6ee7b7;
}

.npc-proposal-btn--accept:hover {
  background: rgba(16, 185, 129, 0.12);
}

.npc-proposal-btn--reject {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.npc-proposal-btn--reject:hover {
  background: rgba(239, 68, 68, 0.1);
}

.npc-proposal-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.npc-proposal-status {
  font-size: 10px;
  color: #94a3b8;
  text-align: right;
  font-style: italic;
}

/* ── Mobile leader sidebar ──────────────────────────────────── */
@media (max-width: 600px) {
  .msg-sidebar-leader { padding: 8px 8px !important; }
  .msg-sidebar-leader .msg-sidebar-portrait { width: 18px; height: 18px; }
  .leader-thread-msg { max-width: 92%; }
  .msg-leader-thread { flex: 1; min-height: 0; }
}

/* ── Unread badge ───────────────────────────────────────────── */
.msg-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  background: var(--red, #ef4444);
  color: #fff;
  font-size: 0.5rem;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 8px;
  margin-left: auto;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
  animation: badgePulse 2s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.12); }
}

/* ── Message list ───────────────────────────────────────────── */
.msg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100dvh - 200px);
  overflow-y: auto;
  padding-right: 4px;
  padding-top: 2px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(var(--accent-rgb), 0.04) 0%, transparent 60%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 48px,
      rgba(var(--accent-rgb), 0.015) 48px,
      rgba(var(--accent-rgb), 0.015) 49px
    );
}

/* ── Message item cards ─────────────────────────────────────── */
.msg-item {
  background:
    linear-gradient(135deg,
      rgba(var(--accent-rgb), 0.03) 0%,
      rgba(6, 6, 15, 0.5) 40%,
      rgba(6, 6, 15, 0.3) 100%
    );
  border: 1px solid rgba(var(--accent-rgb), 0.06);
  border-left: 3px solid rgba(var(--accent-rgb), 0.08);
  border-radius: 4px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

/* Subtle top edge highlight */
.msg-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    rgba(var(--accent-rgb), 0.08) 30%,
    rgba(var(--accent-rgb), 0.04) 70%,
    transparent
  );
  transition: opacity 0.25s;
  opacity: 0;
}

.msg-item:hover {
  background:
    linear-gradient(135deg,
      rgba(var(--accent-rgb), 0.05) 0%,
      rgba(var(--accent-rgb), 0.02) 40%,
      rgba(6, 6, 15, 0.4) 100%
    );
  border-color: rgba(var(--accent-rgb), 0.15);
  box-shadow:
    0 2px 16px rgba(0, 0, 0, 0.25),
    0 0 20px rgba(var(--accent-rgb), 0.03);
  transform: translateX(2px);
}

.msg-item:hover::before {
  opacity: 1;
}

.msg-item.msg-expanded {
  overflow: visible;
}

/* Unread indicator - glowing left bar */
.msg-unread {
  border-left-color: var(--cyan);
  background:
    linear-gradient(135deg,
      rgba(var(--accent-rgb), 0.06) 0%,
      rgba(var(--accent-rgb), 0.02) 40%,
      rgba(6, 6, 15, 0.45) 100%
    );
}

.msg-unread::after {
  content: '';
  position: absolute;
  left: -1px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--cyan);
  box-shadow:
    0 0 8px rgba(var(--accent-rgb), 0.5),
    0 0 20px rgba(var(--accent-rgb), 0.15);
  border-radius: 0 1px 1px 0;
  animation: glowPulse 2.5s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
}

.msg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  gap: 8px;
}

.msg-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.msg-sender {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

/* ── Message Type Badges ───────────────────────────────────── */
.msg-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

.msg-type-badge svg {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.msg-type-system {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--cyan);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
}

.msg-type-player {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.msg-type-leader {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.msg-type-alliance {
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

.msg-type-combat {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.msg-type-trade {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* ── Leader sender with portrait ────────────────────────────── */
.msg-sender-leader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.msg-sender-portrait {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
  flex-shrink: 0;
  border: 1.5px solid rgba(245, 158, 11, 0.35);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.12);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.msg-item:hover .msg-sender-portrait {
  border-color: rgba(245, 158, 11, 0.5);
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.2);
}

.msg-leader-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
  font-size: 0.52rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  font-weight: 600;
}

.msg-time {
  font-size: 0.72rem;
  color: var(--text-secondary, var(--text-dim));
  font-family: var(--font-mono);
  opacity: 0.95;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.msg-item:hover .msg-time {
  opacity: 1;
}

/* Clickable sender pill (alliance chat). Uses the same cyan-accent cue
   as the forum author pill so the affordance reads consistently. */
.msg-sender-pill {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(var(--accent-rgb), 0.12);
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  color: var(--cyan);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

.msg-sender-pill:hover,
.msg-sender-pill:focus-visible {
  background: rgba(var(--accent-rgb), 0.22);
  border-color: rgba(var(--accent-rgb), 0.6);
  outline: none;
}

.msg-subject {
  font-size: 0.76rem;
  color: var(--cyan);
  margin-bottom: 4px;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(var(--accent-rgb), 0.12);
  letter-spacing: 0.01em;
}

.msg-preview {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-full-body {
  color: var(--text-primary);
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
  line-height: 1.5;
  overflow: visible;
  text-overflow: unset;
}

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(var(--accent-rgb), 0.06);
}

/* ── Compose FAB (Floating Action Button) ──────────────────── */
.msg-compose-fab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  margin-bottom: 12px;
  background:
    linear-gradient(135deg,
      rgba(var(--accent-rgb), 0.15) 0%,
      rgba(var(--accent-rgb), 0.06) 100%
    );
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  border-radius: 20px;
  color: var(--cyan);
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 0 12px rgba(var(--accent-rgb), 0.1),
    0 2px 8px rgba(0, 0, 0, 0.2);
}

.msg-compose-fab svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.msg-compose-fab::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 20px;
  background: linear-gradient(135deg,
    rgba(var(--accent-rgb), 0.3),
    rgba(var(--accent-rgb), 0.05)
  );
  z-index: -1;
  opacity: 0;
  transition: opacity 0.25s;
}

.msg-compose-fab:hover {
  background:
    linear-gradient(135deg,
      rgba(var(--accent-rgb), 0.22) 0%,
      rgba(var(--accent-rgb), 0.1) 100%
    );
  border-color: rgba(var(--accent-rgb), 0.5);
  box-shadow:
    0 0 20px rgba(var(--accent-rgb), 0.2),
    0 4px 16px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
  text-shadow: 0 0 8px rgba(var(--accent-rgb), 0.4);
}

.msg-compose-fab:hover::before {
  opacity: 1;
}

.msg-compose-fab:active {
  transform: translateY(0);
  box-shadow:
    0 0 10px rgba(var(--accent-rgb), 0.15),
    0 1px 4px rgba(0, 0, 0, 0.2);
}

@media (max-width: 600px) {
  .msg-compose-fab {
    padding: 7px 12px;
    font-size: 11.5px;
    gap: 6px;
    margin-bottom: 8px;
  }
  .msg-compose-fab svg { width: 14px; height: 14px; }
  .msg-compose-fab-label { display: inline; }
}

/* ── Leader Mission Card ────────────────────────────────────── */
.msg-mission-card {
  margin-top: 12px;
  padding: 12px;
  border-radius: 4px;
  border: 1px solid rgba(245, 158, 11, 0.2);
  background:
    linear-gradient(180deg,
      rgba(245, 158, 11, 0.08) 0%,
      rgba(245, 158, 11, 0.02) 100%
    );
  position: relative;
  overflow: hidden;
}

/* Top glow line */
.msg-mission-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    rgba(245, 158, 11, 0.5),
    transparent 80%
  );
}

.msg-mission-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-mission-kicker {
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #f59e0b;
  font-family: var(--font-mono);
}

.msg-mission-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.msg-mission-objective {
  margin-top: 8px;
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.msg-mission-rewards {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-secondary);
  padding: 6px 8px;
  background: var(--scrim-15);
  border-radius: 3px;
}

.msg-mission-rewards strong {
  color: var(--cyan);
  font-family: var(--font-mono);
}

.msg-mission-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.msg-mission-status {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-secondary);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.msg-mission-status.status-accepted {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.1);
}
.msg-mission-status.status-completed {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--cyan);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.1);
}
.msg-mission-status.status-rejected,
.msg-mission-status.status-expired {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

/* ============================================================
   Leader Thread - Premium Chat View
   ============================================================ */
.msg-leader-thread {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.leader-thread-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 12px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.1);
  margin-bottom: 4px;
  position: relative;
  flex-shrink: 0;
}

/* Header glow line */
.leader-thread-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    rgba(var(--accent-rgb), 0.3),
    transparent 70%
  );
}

.leader-thread-portrait {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(var(--accent-rgb), 0.25);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.12);
}

.leader-thread-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}

.leader-thread-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.leader-thread-profile-btn,
.leader-thread-clear-btn {
  font-size: 0.68rem;
  opacity: 0.6;
  font-family: var(--font-mono);
  transition: opacity 0.2s;
}
.leader-thread-profile-btn:hover,
.leader-thread-clear-btn:hover { opacity: 1; }

/* ── Message bubbles ────────────────────────────────────────── */
.leader-thread-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leader-thread-msg {
  display: flex;
  max-width: 82%;
}
.leader-thread-leader {
  align-self: flex-start;
}
.leader-thread-player {
  align-self: flex-end;
}

.leader-thread-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.98rem;
  line-height: 1.5;
  position: relative;
}

/* Leader bubbles - incoming transmission */
.leader-thread-leader .leader-thread-bubble {
  background:
    linear-gradient(135deg,
      rgba(100, 200, 255, 0.1) 0%,
      rgba(100, 200, 255, 0.04) 100%
    );
  border: 1px solid rgba(100, 200, 255, 0.14);
  border-bottom-left-radius: 3px;
  color: var(--text-primary);
}

/* Player bubbles - outgoing transmission */
.leader-thread-player .leader-thread-bubble {
  background:
    linear-gradient(135deg,
      rgba(0, 200, 150, 0.12) 0%,
      rgba(0, 200, 150, 0.04) 100%
    );
  border: 1px solid rgba(0, 200, 150, 0.16);
  border-bottom-right-radius: 3px;
  color: var(--text-primary);
}

.leader-thread-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.leader-thread-time {
  font-size: 0.72rem;
  opacity: 0.35;
  margin-top: 4px;
  text-align: right;
  font-family: var(--font-mono);
  transition: opacity 0.2s;
}

.leader-thread-msg:hover .leader-thread-time {
  opacity: 0.6;
}

/* ── Typing indicator (leader is thinking after a send) ─────── */
.leader-thread-typing .leader-thread-bubble {
  padding: 10px 14px;
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.leader-thread-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 10px;
}
.leader-thread-typing-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(100, 200, 255, 0.55);
  opacity: 0.3;
  animation: leader-thread-typing-bounce 1.1s infinite ease-in-out;
}
.leader-thread-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.leader-thread-typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes leader-thread-typing-bounce {
  0%, 70%, 100% { transform: translateY(0); opacity: 0.3; }
  35% { transform: translateY(-3px); opacity: 0.95; }
}
.leader-thread-typing-text {
  font-size: 0.72rem;
  color: rgba(226, 232, 240, 0.55);
  font-style: italic;
  line-height: 1.35;
}

/* ── Thread input area ──────────────────────────────────────── */
.leader-thread-input {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 0;
  border-top: 1px solid rgba(var(--accent-rgb), 0.08);
  margin-top: 4px;
  flex-shrink: 0;
}

.leader-thread-input textarea {
  flex: 1;
  min-height: 42px;
  max-height: 100px;
  background: var(--scrim-35);
  border: 1px solid rgba(var(--accent-rgb), 0.1);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.98rem;
  resize: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.leader-thread-input textarea:focus {
  outline: none;
  border-color: rgba(var(--accent-rgb), 0.3);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.06);
}

.leader-thread-input .btn {
  flex-shrink: 0;
  align-self: flex-end;
}

/* ============================================================
   Alliance Chat Messages - Chat Bubble Style
   ============================================================ */
/* 3-column grid: time | author | body. Columns have fixed widths so
   rows stay tabulated - time always in the same spot, author pills
   always the same width. Pill text is centred inside its column. */
.msg-alliance-item {
  display: grid;
  grid-template-columns: 40px 130px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  cursor: default;
  padding: 6px 10px;
  border-radius: 3px;
  border: none;
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s;
  overflow: visible;
  height: auto;
  min-height: 0;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.msg-alliance-item:hover {
  background: rgba(var(--accent-rgb), 0.04);
}
.msg-alliance-item .msg-time {
  opacity: 0.5;
  font-size: 0.68rem;
  line-height: 1.5;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.msg-alliance-item:hover .msg-time {
  opacity: 0.85;
}
/* Author cell: enforce identical pill width across rows so names line up
   with the body column. The pill itself stretches to fill the cell and
   centres its label; long names clip with ellipsis. */
.msg-alliance-item .msg-sender {
  width: 100%;
  display: inline-block;
  font-size: 0.72rem;
  color: var(--cyan);
  font-weight: 600;
  text-align: center;
  text-shadow: 0 0 6px rgba(var(--accent-rgb), 0.15);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  box-sizing: border-box;
}
.msg-body-inline {
  font-size: 0.75rem;
  color: var(--text-primary);
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.5;
}

/* Narrow screens: drop the time column down to a caption on its own row
   so the author + body keep horizontal space. Pill column shrinks a bit
   but stays fixed so names still line up. */
@media (max-width: 480px) {
  .msg-alliance-item {
    grid-template-columns: 100px minmax(0, 1fr);
    grid-template-areas:
      "time time"
      "sender body";
    gap: 2px 8px;
    padding: 8px 10px;
  }
  .msg-alliance-item .msg-time {
    grid-area: time;
    opacity: 0.55;
    font-size: 0.62rem;
  }
  .msg-alliance-item .msg-sender { grid-area: sender; }
  .msg-alliance-item .msg-body-inline { grid-area: body; }
}

/* ============================================================
   Alliance Chat Compose
   ============================================================ */
.msg-alliance-compose {
  display: flex;
  gap: 8px;
  margin-bottom: 0;
  padding: 10px 12px;
  align-items: flex-end;
  background: rgba(var(--accent-rgb), 0.02);
  border-top: 1px solid rgba(var(--accent-rgb), 0.08);
}

.msg-input {
  flex: 1;
  background: var(--scrim-35);
  border: 1px solid rgba(var(--accent-rgb), 0.1);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  resize: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.msg-input:focus {
  border-color: rgba(var(--accent-rgb), 0.3);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.06);
  outline: none;
}

/* ============================================================
   Compose Form
   ============================================================ */
.msg-compose {
  width: 100%;
  margin: 16px 0;
}
.msg-compose .panel-header {
  font-size: 0.75rem;
}
.msg-compose .panel-header .header-action {
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
  background: none;
  border: none;
  font-family: inherit;
}
.msg-compose .panel-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg-compose .input-field {
  resize: vertical;
}
.msg-compose textarea.input-field {
  min-height: 140px;
}
.msg-compose-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid rgba(var(--accent-rgb), 0.08);
}
@media (max-width: 600px) {
  .msg-compose {
    margin: 12px auto;
  }
}
.msg-compose-btn {
  margin-bottom: 10px;
}
.msg-compose-leader-to {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background:
    linear-gradient(135deg,
      rgba(100, 200, 255, 0.06) 0%,
      rgba(100, 200, 255, 0.02) 100%
    );
  border: 1px solid rgba(100, 200, 255, 0.15);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* ── Inline leader reply ────────────────────────────────────── */
.msg-inline-reply {
  margin-top: 10px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 6px;
  position: relative;
}

/* Corner brackets */
.msg-inline-reply::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-top: 1px solid rgba(var(--accent-rgb), 0.3);
  border-left: 1px solid rgba(var(--accent-rgb), 0.3);
}
.msg-inline-reply::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.3);
  border-right: 1px solid rgba(var(--accent-rgb), 0.3);
}

.msg-inline-reply-input {
  width: 100%;
  min-height: 60px;
  max-height: 150px;
  padding: 8px 10px;
  background: var(--scrim-40);
  border: 1px solid rgba(var(--accent-rgb), 0.1);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  resize: vertical;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.msg-inline-reply-input:focus {
  outline: none;
  border-color: rgba(var(--accent-rgb), 0.35);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.06);
}

.msg-inline-reply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ── Contacts dropdown ──────────────────────────────────────── */
.msg-to-wrapper,
.contacts-ac-wrapper {
  position: relative;
  display: block;
}
.contacts-ac-wrapper > input {
  width: 100%;
  box-sizing: border-box;
}

.msg-contacts-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(6, 6, 15, 0.97);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
  border-radius: 0 0 6px 6px;
  max-height: 160px;
  overflow-y: auto;
  box-shadow:
    0 4px 24px var(--scrim-50),
    0 0 0 1px rgba(var(--accent-rgb), 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.msg-contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-primary);
  transition: background 0.15s;
}
.msg-contact-item:hover {
  background: rgba(var(--accent-rgb), 0.08);
}
.msg-contact-name {
  font-weight: 600;
  color: var(--cyan);
}
.msg-contact-tag {
  color: var(--text-dim);
  font-size: 0.72rem;
  font-family: var(--font-mono);
}

/* ─── Floating Leader Reply Chip ─────────────────────────────── */
#leader-reply-chip {
  position: fixed;
  bottom: calc(var(--nav-height, 54px) + var(--ticker-height, 26px) + var(--bottom-sai, 0px) + 12px);
  right: 16px;
  z-index: 9997;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(0, 240, 255, 0.4);
  box-shadow: 0 4px 20px var(--scrim-50), 0 0 12px rgba(0, 240, 255, 0.15);
  overflow: visible;
  transition: transform 150ms ease;
  animation: chip-appear 0.3s ease-out;
}
#leader-reply-chip:hover { transform: scale(1.08); }
#leader-reply-chip img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
#leader-reply-chip .chip-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}
@keyframes chip-appear {
  from { opacity: 0; transform: scale(0.5) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
