.hala-single__grid {
  direction: ltr;              /* کلید اصلی */
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 16px;

  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);  /* ستون اول = سایدبار (چپ) */
  gap: 24px;
}

.hala-single__sidebar,
.hala-single__main {
  direction: rtl;              /* متن‌ها درست */
  min-width: 0;
}


.hala-single__sidebar-inner {
  position: sticky;
  top: 24px;
}

.hala-single__title {
  margin: 0 0 12px;
  line-height: 1.5;
}

.hala-single__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  opacity: 0.85;
  margin-bottom: 16px;
}

.hala-single__featured img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
}

.hala-single__ad {
  margin: 16px 0;
}

.hala-single__content {
  margin-top: 12px;
}

/* Mobile: 1 column + sidebars below comments */
.hala-single__sidebar--mobile { display: none; }

@media (max-width: 900px) {
  .hala-single__grid {
    grid-template-columns: 1fr;
  }

  .hala-single__sidebar--desktop {
    display: none;
  }

  .hala-single__sidebar--mobile {
    display: block;
    margin-top: 24px;
  }

  .hala-single__sidebar-inner {
    position: static;
    top: auto;
  }
}


/* 1) Yekan everywhere (اگر فونت در سایت لود شده باشد) */
html, body,
.hala-single,
.hala-single * ,
.widget, .widget * {
  font-family: Yekan, IRANYekan, "Yekan Bakh", Vazirmatn, Tahoma, Arial, sans-serif !important;
}

/* 2) Center "Ad Above Comments" */
.hala-ad--above-comments,
.hala-single__ad--above-comments,
.hala-single__ad--above-comments .hala-ad-inner,
.hala-single__ad--above-comments .widget,
.hala-single__ad--above-comments img {
  text-align: center !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* 3) Mild purple border for sidebar cards */
.hala-side-block,
.hala-single__sidebar .widget,
.hala-single__sidebar .hala-card {
  border: 1px solid rgba(128, 86, 255, 0.35) !important;
}

/* 4) "Latest news" widget nicer (generic widgets lists) */
.hala-single__sidebar .widget {
  padding: 14px;
  border-radius: 16px;
  background: #fff;
}

.hala-single__sidebar .widget ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.hala-single__sidebar .widget ul li {
  margin: 0;
  padding: 0;
}

.hala-single__sidebar .widget ul li a {
  display: block;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px;
  text-decoration: none;
  line-height: 1.8;
}

/* hover */
.hala-single__sidebar .widget ul li a:hover {
  border-color: rgba(128, 86, 255, 0.35);
}

/* 5) Tags block */
.hala-single__tags {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(0,0,0,0.08);
  display: grid;
  gap: 10px;
}

.hala-single__tags-label {
  opacity: 0.85;
}

.hala-single__tags-list a {
  display: inline-block;
  margin: 0 0 8px 8px;
  padding: 6px 10px;
  border: 1px solid rgba(128, 86, 255, 0.35);
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
}

.hala-latest-news-list{ display:grid; gap:10px; }

a.hala-latest-news-item{
  display:block;
  padding: 12px 14px;
  border-radius: 16px;
  text-decoration: none;
  border: 1px solid rgba(0,0,0,0.08);
  line-height: 1.9;
}

a.hala-latest-news-item:hover{
  border-color: rgba(128, 86, 255, 0.35);
}

.hala-ln-prefix{
  display:inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid rgba(128, 86, 255, 0.55);
  margin-left: 8px; /* فاصله‌ی خیلی کم بین باکس و تیتر */
  font-size: 13px;
  white-space: nowrap;
}

.hala-ln-title{
  display:inline;
}

/* Latest news (time only) */
.hala-latest-news__title{
  margin-bottom: 12px;
  font-weight: 800;
}

.hala-latest-news__list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.hala-latest-news__item{ margin: 0; }

.hala-latest-news__link{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px;
  text-decoration: none;
}

.hala-latest-news__text{
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.8;
}

.hala-latest-news__stamp{
  flex: 0 0 auto;
  opacity: 0.75;
  font-size: 13px;
  white-space: nowrap;
}

/* Kill any injected ":" from theme styles */
.hala-latest-news__stamp::before,
.hala-latest-news__stamp::after{
  content: "" !important;
}

add_action('wp_enqueue_scripts', function () {
  wp_register_script('hm-group-links-to-activity', '', [], null, true);
  wp_enqueue_script('hm-group-links-to-activity');

  $js = <<<JS
(function () {
  function groupToActivity(href) {
    try {
      var u = new URL(href, window.location.origin);

      // Match:
      // /groups/SLUG/
      // /groups/SLUG
      // /groups/SLUG/members/all-members/
      // /groups/SLUG/members/all-members
      var m = u.pathname.match(/^\\/groups\\/([^\\/]+)\\/?(?:members\\/all-members\\/?)?$/);
      if (!m) return null;

      var slug = m[1];
      u.pathname = '/groups/' + slug + '/activity/';
      u.search = ''; // optional: keep clean (remove any query)
      return u.toString();
    } catch (e) {
      return null;
    }
  }

  function fix(root) {
    root = root || document;

    // Target only specific areas where you want the change (not global redirect)
    var selector = [
      // Activity stream: group header block
      '.bp-activity-head-group a[href*="/groups/"]',

      // BuddyBoss components that show group avatar/name in activity cards
      '.activity-group-avatar a[href*="/groups/"]',
      '.activity-group-heading a[href*="/groups/"]',

      // Any group avatar link that wraps an img avatar (common pattern)
      'a[href*="/groups/"] > img.avatar'
    ].join(',');

    root.querySelectorAll(selector).forEach(function (node) {
      // If it's an img, we modify its parent <a>
      var a = node.tagName === 'A' ? node : node.closest('a[href]');
      if (!a) return;

      if (a.dataset.hmFixedGroup === '1') return;
      if (a.closest('#wpadminbar')) return;

      var href = a.getAttribute('href');
      if (!href) return;

      var newHref = groupToActivity(href);
      if (newHref) a.setAttribute('href', newHref);

      a.dataset.hmFixedGroup = '1';
    });
  }

  document.addEventListener('DOMContentLoaded', function () {
    fix(document);

    // For AJAX / infinite content
    var obs = new MutationObserver(function (mutations) {
      mutations.forEach(function (mu) {
        mu.addedNodes.forEach(function (node) {
          if (node.nodeType === 1) fix(node);
        });
      });
    });

    obs.observe(document.body, { childList: true, subtree: true });
  });
})();
JS;

  wp_add_inline_script('hm-group-links-to-activity', $js);
}, 60);

