/* ============================================
   Community feed ("ชุมชนรักเรียน") — ported from TU-LMS.
   Global social feed styles. Uses --tu-* vars defined in base.css.
   NOTE: .rv-avatar (report/list table avatar) already lives in admin.css,
   so it is intentionally NOT duplicated here.
   ============================================ */

.community-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding-top: 1rem;
}
.community-header {
  margin-bottom: 1.25rem;
}
.community-feed {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Composer */
.post-composer {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}
.composer-avatar, .post-avatar, .reply-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.reply-avatar { width: 32px; height: 32px; }
.composer-avatar-ph, .post-avatar-ph, .reply-avatar-ph {
  background: var(--tu-red);
  color: #fff;
  font-weight: 600;
  display: inline-flex;
  align-items: center; justify-content: center;
}
.composer-textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  font-size: 0.95rem;
  line-height: 1.5;
  background: transparent;
  padding: 0.5rem 0;
  min-height: 40px;
}
.composer-textarea:focus { outline: none; }
.composer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f2f4f7;
}
.composer-actions .btn i { width: 1em; height: 1em; }

.composer-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #f2f4f7;
  border-radius: 999px;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  margin: 0.5rem 0.5rem 0 0;
  font-size: 0.8rem;
}
.composer-chip-thumb {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.composer-chip-close {
  background: none;
  border: none;
  color: var(--muted-fg);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.25rem;
}
.composer-chip-close:hover { color: var(--destructive); }

/* Post card */
.post-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.post-pinned {
  font-size: 0.75rem;
  color: var(--tu-red);
  margin-bottom: 0.5rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.post-pinned i { width: 0.9em; height: 0.9em; }

.post-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.post-author {
  font-weight: 600;
  color: var(--heading);
  line-height: 1.3;
}
.post-time {
  font-size: 0.78rem;
  color: var(--muted-fg);
}
.post-content {
  color: var(--foreground);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.post-content a {
  color: var(--tu-red);
  text-decoration: underline;
}

.post-media {
  margin-bottom: 0.75rem;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
.post-media img {
  width: 100%;
  max-height: 540px;
  object-fit: contain;
  display: block;
  cursor: zoom-in;
  background: #f2f4f7;
}
.post-youtube {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  background: #000;
}
.post-youtube iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Post actions */
.post-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid #f2f4f7;
}
.post-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: 0;
  color: var(--muted-fg);
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.post-action:hover {
  background: #f2f4f7;
  color: var(--foreground);
}
.post-action i { width: 1.1em; height: 1.1em; }
.post-like.active {
  color: var(--tu-red);
}
.post-like.active i {
  fill: var(--tu-red);
  stroke: var(--tu-red);
}
.post-like.active .post-like-count {
  font-weight: 600;
}

/* Replies */
.post-replies-area {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #f2f4f7;
}
.reply-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.reply-item {
  display: flex;
  gap: 0.6rem;
}
.reply-body {
  flex: 1;
  min-width: 0;
}
.reply-bubble {
  background: #f2f4f7;
  border-radius: 14px;
  padding: 0.55rem 0.85rem;
  display: inline-block;
  max-width: 100%;
}
.reply-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 0.15rem;
}
.reply-content {
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.reply-content a { color: var(--tu-red); }
.reply-meta {
  font-size: 0.72rem;
  color: var(--muted-fg);
  margin-top: 0.2rem;
  padding-left: 0.3rem;
}
.reply-composer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.reply-input { border-radius: 999px; }

/* ── Reply expanded composer ──────────────────────────────────────────────── */
.reply-composer-wrap { margin-top: 0.5rem; }
.reply-composer-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.reply-input-group {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.reply-textarea {
  border-radius: 12px;
  resize: none;
  min-height: 36px;
  max-height: 120px;
  overflow-y: auto;
  font-size: 0.875rem;
}
.reply-char-hint {
  font-size: 0.7rem;
  color: var(--muted-fg, #888);
  text-align: right;
  margin-top: 2px;
}
.reply-media-bar {
  margin-top: 0.35rem;
  padding-left: 40px;
}
.reply-media-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.25rem;
}
.reply-media-actions .btn-link { color: var(--muted-fg, #888); padding: 0; }
.reply-media-actions .btn-link i { width: 1em; height: 1em; }

/* ── Reply media ──────────────────────────────────────────────────────────── */
.reply-media {
  margin-top: 0.4rem;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
}
.reply-media-img {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  cursor: zoom-in;
  background: #f2f4f7;
}
.reply-youtube-wrap {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  background: #000;
  max-width: 400px;
  border-radius: 8px;
  overflow: hidden;
}
.reply-youtube-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ── Reply like button ────────────────────────────────────────────────────── */
.reply-like-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: 0;
  color: var(--muted-fg, #888);
  font-size: 0.72rem;
  padding: 0;
  cursor: pointer;
  transition: color 0.15s;
  line-height: 1;
}
.reply-like-btn i { width: 0.9em; height: 0.9em; }
.reply-like-btn.active { color: var(--tu-red, #b91c1c); }
.reply-like-btn.active i { fill: var(--tu-red, #b91c1c); stroke: var(--tu-red, #b91c1c); }
.reply-like-btn.active .reply-like-count { font-weight: 600; }

/* ── Tag filter bar ───────────────────────────────────────────────────────── */
.tag-filter-bar {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border, #e2e8f0);
  background: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--muted-fg, #64748b);
  transition: all 0.15s;
}
.tag-chip:hover { border-color: var(--tu-red, #b91c1c); color: var(--tu-red, #b91c1c); }
.tag-chip.active { background: var(--tu-red, #b91c1c); border-color: var(--tu-red, #b91c1c); color: #fff; }
.tag-chip-icon { width: 13px; height: 13px; flex-shrink: 0; }

/* ── Post tag badge ───────────────────────────────────────────────────────── */
.post-tag-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(185,28,28,0.08);
  color: var(--tu-red, #b91c1c);
  margin-left: 0.35rem;
  vertical-align: middle;
  white-space: nowrap;
}

/* ── Community search bar ─────────────────────────────────────────────────── */
.community-search-bar .input-group-text {
  border-radius: 999px 0 0 999px;
  border-right: 0;
}
.community-search-bar .form-control {
  border-left: 0;
  border-radius: 0 999px 999px 0;
}
.community-search-bar .form-control:focus { box-shadow: none; border-color: var(--border, #e2e8f0); }

/* ── @Mention popup ───────────────────────────────────────────────────────── */
.mention-popup {
  position: fixed;
  z-index: 9999;
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 200px;
  max-width: 280px;
  overflow: hidden;
  display: none;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.1s;
}
.mention-item:hover, .mention-item.active {
  background: rgba(185,28,28,0.06);
  color: var(--tu-red, #b91c1c);
}
.mention-av {
  width: 26px; height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.mention-av-ph {
  background: var(--tu-red, #b91c1c);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.mention-tag {
  color: var(--tu-red, #b91c1c);
  font-weight: 600;
  background: rgba(185,28,28,0.08);
  border-radius: 4px;
  padding: 0 2px;
}

@media (max-width: 640px) {
  .community-wrap { padding: 0 0.5rem; }
  .post-composer, .post-card { padding: 1rem; border-radius: 12px; }
  .reply-media-bar { padding-left: 0; }
}
