/* =========================================================
   Feed page — page-specific styles
   ========================================================= */

.feed-page {
  min-height: calc(100vh - 120px);
}

.feed-header {
  margin-bottom: 40px;
}

.feed-heading {
  font-size: 2.4rem;
  font-weight: 400;
  margin-bottom: 8px;
}

/* ── Search bar ────────────────────────────────────────── */

.feed-search-wrap {
  position: relative;
  max-width: 640px;
  margin-bottom: 40px;
}

.feed-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.feed-search {
  width: 100%;
  padding: 10px 14px 10px 38px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
}

.feed-search::placeholder {
  color: var(--text-muted);
}

.feed-search:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255, 79, 0, 0.1);
}

.feed-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--text-muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18 6L6 18M6 6l12 12' stroke='currentColor' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  cursor: pointer;
  opacity: 0.5;
}

.feed-search::-webkit-search-cancel-button:hover {
  opacity: 1;
}

/* ── Search result states ───────────────────────────────── */

.feed-search-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.feed-search-count strong {
  color: var(--text-secondary);
  font-weight: 500;
}

.feed-search-empty {
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 40px 0;
}

.feed-search-empty strong {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── Match highlight ────────────────────────────────────── */

.feed-hl {
  background: rgba(255, 79, 0, 0.12);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Two-column layout ─────────────────────────────────── */

.feed-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 64px;
  align-items: start;
}

.feed-feed {
  display: flex;
  flex-direction: column;
  margin-top: 0;
  max-width: 640px;
  padding-bottom: 120px;
}

/* ── Post cards ────────────────────────────────────────── */

.feed-card {
  padding: 24px 0;
  border-top: 1px solid var(--border-color);
  scroll-margin-top: 90px;
}

.feed-card:last-child {
  border-bottom: 1px solid var(--border-color);
}

.feed-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.feed-card-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.feed-card-author {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.feed-card-author::before {
  content: "·";
  margin-right: 10px;
}

.feed-card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.feed-card-body {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin: 0;
}

.feed-card-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-primary);
}

.feed-card-image {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin: 16px 0;
}

/* ── TOC sidebar ───────────────────────────────────────── */

.feed-toc {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.feed-toc::-webkit-scrollbar {
  width: 3px;
}

.feed-toc::-webkit-scrollbar-track {
  background: transparent;
}

.feed-toc::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 99px;
}

.feed-toc-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.feed-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.feed-toc-link {
  display: block;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px 10px;
  border-left: 2px solid transparent;
  transition: color 0.18s, border-color 0.18s, background-color 0.18s;
}

.feed-toc-link:hover {
  color: var(--text-primary);
  border-left-color: var(--border-color);
  background-color: var(--bg-surface-alt);
}

.feed-toc-link.active {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  background-color: var(--bg-tag);
}

/* ── Post target highlight (TOC click or direct #link) ── */

.feed-card:target {
  margin-left: -16px;
  padding-left: 16px;
  animation: post-target-flash 3s ease-out forwards;
}

@keyframes post-target-flash {
  0%   { background-color: rgba(255, 79, 0, 0.08); box-shadow: inset 3px 0 0 var(--color-primary); }
  65%  { background-color: rgba(255, 79, 0, 0.04); box-shadow: inset 3px 0 0 rgba(255, 79, 0, 0.4); }
  100% { background-color: transparent;             box-shadow: none; }
}

/* ── Pagination (outside grid — centered across full page) */

.feed-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 40px;
}

.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: color 0.18s;
}

.pagination-btn:hover {
  color: var(--text-primary);
}

.pagination-btn.pagination-active {
  color: #fff;
  background: var(--color-primary);
}

.pagination-prev,
.pagination-next {
  padding: 0 12px;
  color: var(--text-secondary);
}

.pagination-ellipsis {
  cursor: default;
  color: var(--text-muted);
  min-width: unset;
  padding: 0 4px;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 768px) {
  .feed-layout {
    grid-template-columns: 1fr;
  }

  .feed-toc {
    display: none;
  }
}

/* =========================================================
   RTL overrides  (active when <html dir="rtl">)
   ---------------------------------------------------------
   .feed-layout needs no override: a grid tracks the inline
   direction, so 1fr/220px already reverse under dir="rtl".
   ========================================================= */

[dir="rtl"] .feed-search-icon {
  left: auto;
  right: 14px;
}

[dir="rtl"] .feed-search {
  padding: 10px 38px 10px 14px;
}

[dir="rtl"] .feed-toc-label {
  letter-spacing: 0;
  text-transform: none;
}

/* Post copy comes from feed.json and is English, so the card and its TOC entry
   stay LTR inside the RTL page — same rule as the non-Arabic .lang-phrase. */
[dir="rtl"] .feed-card,
[dir="rtl"] .feed-toc-link {
  direction: ltr;
}

/* The meta line is UI text (localised date + byline), so it opts back into RTL.
   Left LTR, the bidi algorithm reorders "16 يونيو 2026" to "16 2026 يونيو",
   because the year follows a strong Arabic run and resolves as an Arabic number. */
[dir="rtl"] .feed-card-meta {
  direction: rtl;
}

[dir="rtl"] .feed-card-author::before {
  margin-right: 0;
  margin-left: 10px;
}

/* The TOC sits on the left in RTL, so its active rule faces the posts. */
[dir="rtl"] .feed-toc-link {
  border-left: none;
  border-right: 2px solid transparent;
}

[dir="rtl"] .feed-toc-link:hover {
  border-right-color: var(--border-color);
}

[dir="rtl"] .feed-toc-link.active {
  border-right-color: var(--color-primary);
}

[dir="rtl"] .feed-card:target {
  margin-left: 0;
  padding-left: 0;
  margin-right: -16px;
  padding-right: 16px;
  animation-name: post-target-flash-rtl;
}

@keyframes post-target-flash-rtl {
  0%   { background-color: rgba(255, 79, 0, 0.08); box-shadow: inset -3px 0 0 var(--color-primary); }
  65%  { background-color: rgba(255, 79, 0, 0.04); box-shadow: inset -3px 0 0 rgba(255, 79, 0, 0.4); }
  100% { background-color: transparent;            box-shadow: none; }
}
