/* Ping Shell — tabs + panes wrapper. The router header sits above it and the
   bottom bar only exists on phones, so both are subtracted from the viewport. */
.ping-shell {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--page-header-h) - var(--bottom-bar-h));
}

/* The shell already fills the viewport, so this page drops the padding that
   would otherwise push 48px of it below the fold. */
.view-ping { padding: 0; }
/* The shell is the page's own chrome, so the header keeps its own height and
   no bleed margin (this container has no padding to cancel). */
.view-ping .page-header { margin: 0; }

/* Phones pin 140px of bottom padding onto every container for the fixed bar;
   the shell already subtracts that bar, so it would overflow the screen. */
@media (max-width: 768px) {
  .view-ping { padding: 0 !important; }
}

/* Ping Layout */
.ping-layout {
  flex: 1;
  min-height: 0;
  background: transparent;
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  display: flex;
}

/* Sidebar */
.ping-sidebar { width: 300px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--bg-secondary); flex-shrink: 0; }

.ping-sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ping-sidebar-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 2px solid transparent;
}

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

.ping-sidebar-tab.active {
  color: var(--brand-primary);
  border-bottom: 2px solid var(--brand-primary);
}

.ping-sidebar-tab svg {
  pointer-events: none;
}

.ping-chat-list { flex: 1; overflow-y: auto; }
.ping-chat-item { display: flex; align-items: center; gap: 12px; padding: 16px; cursor: pointer; border-bottom: 1px solid var(--surface-divider); transition: background 0.2s; }
.ping-chat-item:hover { background: var(--surface-hover); }
.ping-chat-item.active { background: var(--brand-primary-light); }

.ping-avatar { width: 40px; height: 40px; border-radius: 50% !important; background: var(--gradient-primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; object-fit: cover; cursor: pointer; }
.room-avatar { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }

.ping-chat-info { display: flex; flex-direction: column; overflow: hidden; }
.ping-chat-name { font-size: 14px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ping-chat-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Live posts pane (the Live tab, folded into Ping) */
.ping-live-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border-radius: 0 0 16px 16px;
  border: 1px solid var(--border);
  border-top: none;
  overflow: hidden;
}
.ping-live-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 20px;
}
.ping-live-title { font-size: 17px; font-weight: 800; color: var(--text-primary); }
.ping-live-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
/* The embedded board is a view-container in its own right; drop the outer chrome */
.ping-live-pane .view-container { padding: 0; }

.ping-search-dropdown {
  position: absolute;
  top: 110%;
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: none;
  max-height: 300px;
  overflow-y: auto;
}

/* Main Chat Area */
.ping-main { flex: 1; min-height: 0; display: flex; flex-direction: column; background: transparent; }
.ping-empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); text-align: center; }
.ping-empty-state h3 { font-size: 18px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; }

.ping-chat-header { display: flex; align-items: center; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.ping-chat-header h3 { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.ping-chat-header span { font-size: 12px; color: var(--text-muted); }
.ping-back-btn { display: none; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; }

.ping-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 12px; background: transparent; }
.ping-message { max-width: 70%; padding: 12px 16px; border-radius: 16px; position: relative; }
.ping-message.sent { align-self: flex-end; background: var(--brand-primary); color: white; border-bottom-right-radius: 4px; }
.ping-message.received { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); color: var(--text-primary); border-bottom-left-radius: 4px; }
.ping-message p { font-size: 14px; line-height: 1.4; margin: 0; }

.ping-msg-sender { font-size: 12px; font-weight: 700; color: var(--brand-primary); margin-bottom: 4px; display: block; }
.ping-msg-footer { display: flex; align-items: center; gap: 8px; margin-top: 4px; justify-content: flex-end; }
.ping-msg-time { font-size: 10px; opacity: 0.7; }
.ping-edited { font-size: 10px; opacity: 0.7; font-style: italic; }
.ping-msg-menu-btn { background: none; border: none; color: inherit; cursor: pointer; opacity: 0.5; padding: 0 4px; }
.ping-msg-menu-btn:hover { opacity: 1; }

/* Attachments */
.ping-attachment { max-width: 100%; border-radius: 8px; margin-bottom: 8px; display: block; }
.ping-attachment.img { max-height: 200px; }
.ping-attachment.audio { width: 100%; }
.ping-attachment.file { color: inherit; text-decoration: underline; font-size: 14px; }
.ping-attachment.live-invite-card {
  background: rgba(108, 92, 231, 0.12);
  border: 1px solid rgba(108, 92, 231, 0.3);
  border-radius: 10px;
  padding: 12px;
  max-width: 240px;
  text-decoration: none;
  color: inherit;
}
.live-invite-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--brand-primary);
  margin-bottom: 6px;
}
.live-invite-header svg { flex-shrink: 0; }
.live-invite-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
  line-height: 1.3;
  color: var(--text-primary);
}
.live-invite-btn {
  display: inline-block;
  background: var(--brand-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 6px;
  text-decoration: none;
  transition: opacity 0.15s ease;
}
.live-invite-btn:hover { opacity: 0.9; }

/* Input Area */
.ping-input-area { display: flex; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface); align-items: center; }
.ping-input-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 8px; border-radius: 50%; transition: background 0.2s; display: flex; align-items: center; justify-content: center; }
.ping-input-icon:hover { background: var(--bg-tertiary); color: var(--brand-primary); }
[data-theme="dark"] .ping-input-icon { color: var(--text-secondary); }

/* Voice Note UI */
.ping-recording-ui { display: flex; align-items: center; gap: 12px; width: 100%; justify-content: center; color: var(--error); font-weight: 600; }
.ping-rec-dot { width: 12px; height: 12px; background: var(--error); border-radius: 50%; animation: pulse 1.5s infinite; }
.ping-preview-ui { display: flex; align-items: center; gap: 12px; width: 100%; }
.ping-preview-ui audio { flex: 1; height: 40px; }
.ping-edit-textarea { width: 100%; margin-bottom: 8px; resize: none; }
.ping-edit-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Context Menu */
.ctx-menu { position: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); z-index: 1000; min-width: 120px; overflow: hidden; }
.ctx-item { padding: 10px 16px; font-size: 14px; cursor: pointer; transition: background 0.2s; }
.ctx-item:hover { background: var(--bg-tertiary); }
.ctx-item.danger { color: var(--error); }

/* ============================================
   PREMIUM VOICE NOTE UI
   ============================================ */
.voice-note-bubble {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
}

.vn-play-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.vn-play-btn:hover { background: rgba(255,255,255,0.3); }

.ping-message.received .vn-play-btn {
  background: var(--brand-primary-light);
  color: var(--brand-primary);
}
.ping-message.received .vn-play-btn:hover {
  background: var(--brand-primary-soft);
}

.vn-progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}

.ping-message.received .vn-progress-bar {
  background: var(--border);
}

.vn-progress-fill {
  height: 100%;
  background: white;
  width: 0%;
  border-radius: 2px;
  transition: width 0.1s linear;
}

.ping-message.received .vn-progress-fill {
  background: var(--brand-primary);
}

.vn-duration {
  font-size: 11px;
  color: rgba(255,255,255,0.8);
  min-width: 30px;
  text-align: right;
}

.ping-message.received .vn-duration {
  color: var(--text-muted);
}

/* Recording & Preview UI */
.ping-voice-recording {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  justify-content: center;
  color: var(--error);
  font-weight: 600;
}

.voice-rec-dot {
  width: 12px;
  height: 12px;
  background: var(--error);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

.ping-voice-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: 12px;
}

.ping-voice-preview .vn-play-btn {
  background: var(--brand-primary);
  color: white;
}

.ping-voice-preview .vn-progress-bar {
  background: var(--border);
}

.ping-voice-preview .vn-progress-fill {
  background: var(--brand-primary);
}

.ping-voice-preview .vn-duration {
  color: var(--text-muted);
}

/* Edit Textarea */
.ping-edit-textarea {
  width: 100%;
  margin-bottom: 8px;
  resize: none;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  border-radius: 8px;
  padding: 8px;
  font-family: var(--font-sans);
  font-size: 14px;
}

.ping-message.received .ping-edit-textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.ping-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Search Avatar */
.ping-search-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  object-fit: cover;
}

/* Clean Search Item Rule */
.ping-search-item {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px; /* Exactly 8px gap */
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
  text-align: left;
  width: 100%;
}
.ping-search-item:last-child { border-bottom: none; }
.ping-search-item:hover { background: var(--bg-tertiary); }

/* Mobile Responsive */
@media (max-width: 768px) {
  .ping-sidebar { position: absolute; top: 0; left: 0; bottom: 0; width: 100%; z-index: 10; transition: transform 0.3s ease; }
  .ping-main { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; z-index: 2000; transform: translateX(100%); transition: transform 0.3s ease; padding-top: var(--safe-top); }
  .ping-layout.chat-open .ping-sidebar { transform: translateX(-100%); }
  .ping-layout.chat-open .ping-main { transform: translateX(0); }
  .ping-back-btn { display: flex; }
  .ping-input-area { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

  .ping-search-dropdown { top: auto; bottom: 110%; }

  .ping-live-bar { flex-direction: column; align-items: stretch; gap: 12px; }
}

/* Unread Chat Highlight */
.ping-chat-item.unread .ping-chat-name {
  font-weight: 800; /* Bold name */
  color: var(--text-primary);
}

.ping-chat-item.unread .ping-chat-preview {
  color: var(--brand-primary);
  font-weight: 600;
}

.chat-unread-badge {
  background: var(--brand-primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
}
