/* ========================================================
   TrailTrack Stories — Chat Styles (Discord/Slack style)
   ======================================================== */

/* ---- Chat Panel Layout ---- */
.chat-panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---- Room Header ---- */
.chat-room-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-room-header-info {
  flex: 1;
  min-width: 0;
}

.chat-room-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-room-stats {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-online-count {
  display: flex;
  align-items: center;
  gap: 3px;
}

.chat-online-dot {
  width: 6px;
  height: 6px;
  background: var(--green-light);
  border-radius: 50%;
}

/* ---- Chat Room List ---- */
.chat-room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: 2px;
}

.chat-room-item:hover {
  background: var(--surface-hover);
}

.chat-room-item.active {
  background: var(--surface-active);
  border-left: 3px solid var(--green-light);
}

.chat-room-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.chat-room-item-info {
  flex: 1;
  min-width: 0;
}

.chat-room-item-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-item-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-unread {
  flex-shrink: 0;
}

/* ---- Chat Messages Area ---- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chat-messages-date-divider {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 12px 0;
  position: relative;
}

.chat-messages-date-divider::before,
.chat-messages-date-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}

.chat-messages-date-divider::before { left: 0; }
.chat-messages-date-divider::after { right: 0; }

/* ---- Chat Message — Discord/Slack style ---- */
.chat-msg {
  display: flex;
  gap: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  animation: fade-in 0.15s ease;
  transition: background 0.1s;
}

.chat-msg:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Grouped messages (same user, consecutive) — collapse avatar */
.chat-msg-grouped {
  padding-left: 56px;
  padding-top: 0;
  margin-top: -2px;
}

.chat-msg-grouped .chat-msg-avatar,
.chat-msg-grouped .chat-msg-header {
  display: none;
}

.chat-msg-avatar {
  flex-shrink: 0;
  width: 36px;
  padding-top: 2px;
}

.chat-msg-avatar .avatar {
  width: 36px;
  height: 36px;
  font-size: 0.8rem;
}

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

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

/* Username colors — each user gets a distinct color */
.chat-msg-name {
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.chat-msg-name:hover {
  opacity: 0.8;
  text-decoration: underline;
}

/* Color palette for usernames */
.chat-name-color-0 { color: #f87171; }
.chat-name-color-1 { color: #34d399; }
.chat-name-color-2 { color: #60a5fa; }
.chat-name-color-3 { color: #fbbf24; }
.chat-name-color-4 { color: #c084fc; }
.chat-name-color-5 { color: #f472b6; }
.chat-name-color-6 { color: #2dd4bf; }
.chat-name-color-7 { color: #fb923c; }
.chat-name-color-8 { color: #a78bfa; }
.chat-name-color-9 { color: #4ade80; }
.chat-name-color-10 { color: #38bdf8; }
.chat-name-color-11 { color: #e879f9; }

.chat-msg-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

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

/* Message body — no bubbles, just clean text */
.chat-msg-body {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg-body a {
  color: var(--green-light);
}

/* NO special own-message styling — all messages look the same */
.chat-msg-own {
  /* intentionally empty — same layout as everyone else */
}

.chat-msg-photo {
  max-width: 400px;
  max-height: 300px;
  border-radius: var(--radius);
  margin-top: 4px;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.chat-msg-photo:hover {
  opacity: 0.9;
}

/* System message */
.chat-msg-system {
  text-align: center;
  padding: 6px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Pinned message */
.chat-msg-pinned {
  background: rgba(245, 158, 11, 0.08);
  border-left: 2px solid var(--amber);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 4px 0;
}

.chat-msg-pinned-label {
  font-size: 0.7rem;
  color: var(--amber);
  font-weight: 600;
  margin-bottom: 4px;
}

/* Map share in chat */
.chat-map-preview {
  width: 280px;
  height: 160px;
  border-radius: var(--radius);
  margin-top: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.chat-map-preview:hover {
  opacity: 0.9;
}

.chat-map-preview-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  font-size: 0.75rem;
  color: white;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---- Typing Indicator ---- */
.chat-typing {
  padding: 4px 16px 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  height: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s ease infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

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

/* ---- Chat Input ---- */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  transition: border-color var(--transition-fast);
}

.chat-input-wrap:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--green-glow);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  padding: 2px 4px;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input-actions {
  display: flex;
  gap: 2px;
  align-items: center;
}

.chat-input-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.chat-input-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.chat-send-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--green);
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.chat-send-btn:hover {
  background: var(--green-light);
  box-shadow: var(--shadow-glow-green);
}

/* ---- Chat Full Page Layout ---- */
.chat-page {
  display: flex;
  height: 100%;
}

.chat-page-rooms {
  width: 240px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  flex-shrink: 0;
}

.chat-page-rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-page-rooms-header h3 {
  font-size: 1rem;
}

.chat-page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Chat + Right Panel layout */
.chat-layout {
  display: flex;
  height: 100%;
}

.chat-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Right Panel ---- */
.chat-right-panel {
  width: 0;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--surface);
  transition: width 0.25s ease;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.chat-right-panel.open {
  width: 560px;
  overflow-y: auto;
}

/* Right panel sections */
.chat-rp-section {
  border-bottom: 1px solid var(--border);
}

.chat-rp-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.chat-rp-section-header:hover {
  background: rgba(255,255,255,0.02);
}

.chat-rp-toggle {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chat-rp-section-body {
  padding: 0 14px 12px;
}

.chat-rp-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 0;
}

/* Members */
.chat-rp-member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.chat-rp-member:hover {
  background: rgba(255,255,255,0.03);
}

.chat-rp-member-avatar {
  position: relative;
  flex-shrink: 0;
}

.chat-rp-member-avatar .avatar {
  width: 28px;
  height: 28px;
  font-size: 0.7rem;
}

.chat-rp-status {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  border: 2px solid var(--surface);
}

.chat-rp-status.online {
  background: var(--green-light);
}

.chat-rp-member-name {
  font-size: 0.82rem;
  font-weight: 600;
}

/* Shared Media Grid */
.chat-rp-media-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.chat-rp-media-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.chat-rp-media-thumb:hover {
  transform: scale(1.05);
  opacity: 0.85;
}

.chat-rp-media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Room Map */
.chat-rp-map {
  height: 350px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 8px;
}

.chat-rp-map-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.chat-rp-map-search {
  display: flex;
  gap: 4px;
}

.chat-rp-map-search input {
  flex: 1;
  font-size: 0.8rem !important;
  padding: 6px 8px !important;
}

.chat-rp-map-coords {
  display: flex;
  gap: 4px;
  align-items: center;
}

.chat-rp-map-coords input {
  flex: 1;
  font-size: 0.8rem !important;
  font-family: monospace;
  text-align: center;
  padding: 6px 4px !important;
}

.chat-rp-map-coords span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-rp-map-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.chat-rp-map-actions .btn {
  flex: 1;
  font-size: 0.72rem;
  min-width: 0;
  padding: 6px 8px;
}

.chat-rp-map-info {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: monospace;
  padding: 2px 0;
}

/* Empty state */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.chat-empty-state-icon {
  font-size: 3rem;
  opacity: 0.3;
}

/* ---- Create Room Form ---- */
.create-room-form {
  padding: 16px;
}

.create-room-form .form-group {
  margin-bottom: 12px;
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  .chat-right-panel.open {
    width: 420px;
  }
}

@media (max-width: 1024px) {
  .chat-right-panel.open {
    width: 340px;
  }
}

@media (max-width: 768px) {
  .chat-page {
    flex-direction: column;
  }

  .chat-page-rooms {
    width: 100%;
    max-height: 0;
    overflow: hidden;
    border-right: none;
    border-bottom: 1px solid var(--border);
    transition: max-height 0.25s ease;
  }

  .chat-page-rooms.open {
    max-height: 40vh;
    overflow-y: auto;
  }

  .chat-page-rooms-header {
    cursor: pointer;
  }

  /* Add toggle indicator */
  .chat-page-rooms-header::after {
    content: '▼';
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
  }

  .chat-page-rooms.open .chat-page-rooms-header::after {
    transform: rotate(180deg);
  }

  .chat-right-panel.open {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .chat-layout {
    flex-direction: column;
  }

  .chat-rp-map {
    height: 150px;
  }

  /* Chat input pinned at bottom */
  .chat-input-area {
    position: sticky;
    bottom: 0;
    z-index: 10;
  }

  /* Chat messages adjustments */
  .chat-messages {
    padding: 10px;
  }

  .chat-msg {
    gap: 8px;
  }

  .chat-msg-grouped {
    padding-left: 48px;
  }

  .chat-msg-body {
    font-size: 0.85rem;
  }

  .chat-msg-photo {
    max-width: 240px;
  }

  .chat-map-preview {
    width: 220px;
    height: 130px;
  }

  /* Chat input touch targets */
  .chat-input-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  .chat-send-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  /* Room items touch targets */
  .chat-room-item {
    padding: 12px;
    min-height: 44px;
  }

  /* Chat msg timestamp always visible on mobile */
  .chat-msg .chat-msg-time {
    opacity: 0.6;
  }
}

@media (max-width: 480px) {
  .chat-msg-photo {
    max-width: 180px;
  }

  .chat-map-preview {
    width: 180px;
    height: 110px;
  }

  .chat-page-rooms.open {
    max-height: 35vh;
  }
}
