/* =================================================================
   Blog — listing (blogs.php) and article (blog.php)
   Load AFTER ../css/index.css: it provides the colour tokens, fonts,
   header, footer, and the card classes (.course-card, .blog-grid,
   .blog-image, .course-info, .card-actions) used by the listing.
   ================================================================= */

/* -----------------------------------------------------------------
   HERO (shared) — the homepage hero, shorter
   ----------------------------------------------------------------- */
.blog-hero {
  --orb-w: 340px;
  --orb-h: 255px;
  --orb-side: 10%;
  --orb-top: 50%;
  --orb-cx: calc(var(--orb-side) + var(--orb-w) / 2);

  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: clamp(3rem, 2rem + 5vw, 5.5rem) var(--gutter) !important;
  color: var(--night-soft);
  background:
    radial-gradient(60% 80% at var(--orb-cx) var(--orb-top), rgba(14, 78, 134, 0.3), transparent 70%),
    linear-gradient(160deg, var(--night-surface) 0%, var(--night-panel) 50%, var(--night-page) 100%);
}

.blog-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background: repeating-radial-gradient(
    ellipse var(--orb-w) var(--orb-h) at var(--orb-cx) var(--orb-top),
    rgba(255, 255, 255, 0.07) 0 1px,
    transparent 1px 7%
  );
  -webkit-mask-image: radial-gradient(ellipse 60% 100% at var(--orb-cx) var(--orb-top), #000 10%, rgba(0, 0, 0, 0.35) 55%, transparent 85%);
  mask-image: radial-gradient(ellipse 60% 100% at var(--orb-cx) var(--orb-top), #000 10%, rgba(0, 0, 0, 0.35) 55%, transparent 85%);
}

.blog-hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: var(--orb-top);
  left: var(--orb-side);
  width: var(--orb-w);
  height: var(--orb-h);
  margin-top: calc(var(--orb-h) / -2);
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(246, 178, 60, 0.7) 0%,
    rgba(224, 154, 30, 0.3) 22%,
    rgba(34, 184, 216, 0.22) 48%,
    transparent 70%
  );
  filter: blur(2px);
}

.blog-hero-inner {
  max-width: var(--container);
  margin: 0 auto;
}

.blog-hero-inner > * {
  max-width: 640px;
}

.blog-crumbs {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  font-size: var(--fs-sm);
  color: var(--night-soft);
}

.blog-crumbs a:hover { color: var(--night-ink); }
.blog-crumbs i { font-size: 0.65em; opacity: 0.7; }
.blog-crumbs [aria-current] { color: var(--night-ink); }

.blog-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 1.4rem + 3vw, 3.4rem);
  font-weight: 700;
  line-height: 1.25;
  color: var(--white);
  margin-bottom: 0.9rem;
  text-wrap: balance;
}

.blog-hero p {
  font-size: clamp(1rem, 0.9rem + 0.4vw, 1.15rem);
  line-height: 1.9;
  color: var(--night-soft);
}

@media (max-width: 760px) {
  .blog-hero {
    --orb-w: 240px;
    --orb-h: 180px;
    --orb-side: -80px;
    --orb-top: 30%;
  }
}

/* -----------------------------------------------------------------
   LISTING (blogs.php)
   ----------------------------------------------------------------- */
.blog-list {
  background: var(--foam) !important;
}

.blog-toolbar {
  max-width: var(--container);
  margin: 0 auto 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.blog-search {
  position: relative;
  flex: 1 1 320px;
  max-width: 460px;
}

.blog-search i {
  position: absolute;
  right: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  pointer-events: none;
}

.blog-search input {
  width: 100%;
  height: 50px;
  padding: 0 2.9rem 0 1.1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--mist);
  background: var(--white);
  color: var(--ink);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-1);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.blog-search input:focus {
  outline: none;
  border-color: var(--ocean);
  box-shadow: 0 0 0 4px rgba(14, 78, 134, 0.12);
}

.blog-count {
  color: var(--ink-soft);
  font-size: var(--fs-sm);
}

.blog-card[hidden] {
  display: none;
}

.blog-list .blog-image {
  display: block;
}

.blog-list .course-info h3 a {
  color: inherit;
  transition: color var(--transition);
}

.blog-list .course-info h3 a:hover {
  color: var(--lagoon-ink);
}

/* Keep cards even: 3 lines of excerpt */
.blog-excerpt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.blog-empty {
  max-width: var(--container);
  margin: 1rem auto 0;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--ink-soft);
  background: var(--white);
  border: 1.5px dashed var(--mist);
  border-radius: var(--radius-lg);
}

.blog-empty i {
  display: block;
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  color: var(--ink-faint);
}

.blog-empty[hidden] {
  display: none;
}

/* Search is a form now (submits ?q=) */
form.blog-search {
  margin: 0;
}

.blog-count a {
  color: var(--lagoon-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Pagination: السابق  1 2 3 … 9  التالي */
.blog-pagination {
  max-width: var(--container);
  margin: clamp(2rem, 1.5rem + 2vw, 3rem) auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.pg-numbers {
  list-style: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pg-num,
.pg-arrow,
.pg-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 0.85rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-sm);
}

.pg-num,
.pg-arrow {
  border: 1px solid var(--mist);
  background: var(--white);
  color: var(--ink);
  transition: border-color var(--transition), background var(--transition), color var(--transition), transform var(--transition);
}

a.pg-num:hover,
a.pg-arrow:hover {
  border-color: var(--ocean);
  color: var(--ocean);
  transform: translateY(-1px);
}

.pg-num.is-current {
  background: var(--ocean);
  border-color: var(--ocean);
  color: var(--white);
  box-shadow: 0 6px 16px rgba(14, 78, 134, 0.25);
}

.pg-arrow {
  gap: 0.5rem;
  color: var(--ocean);
}

.pg-arrow i {
  font-size: 0.8em;
}

.pg-arrow.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pg-gap {
  min-width: 28px;
  padding: 0;
  color: var(--ink-soft);
}

@media (max-width: 520px) {
  .pg-arrow span {
    display: none;   /* arrows only on small phones */
  }

  .pg-num,
  .pg-arrow {
    min-width: 40px;
    height: 40px;
    padding: 0 0.6rem;
  }
}

/* -----------------------------------------------------------------
   ARTICLE (blog.php)
   ----------------------------------------------------------------- */

/* Reading progress stays visible on every screen size here */
.article-page .scroll-progress {
  display: block !important;
  height: 4px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  font-size: var(--fs-sm) !important;
}

.article-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.article-meta strong {
  color: var(--night-ink);
  font-weight: 600;
}

.article-layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(2rem, 1rem + 3vw, 3.5rem) var(--gutter) clamp(3rem, 2rem + 3vw, 5rem);
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: clamp(1.5rem, 1rem + 2vw, 3rem);
  align-items: start;
}

/* Contents box — sticky beside the article on desktop */
.subtitle-box {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  padding: 1.1rem;
  border-radius: var(--radius-lg);
  background: var(--white);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-1);
}

.toc-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  margin-bottom: 0.6rem;
  padding-inline: 0.5rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-list a {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border-right: 3px solid transparent;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.toc-list a:hover {
  background: var(--foam);
}

.toc-list a[aria-current="true"] {
  background: #E1EEF8;
  border-right-color: var(--ocean);
  color: var(--ocean);
  font-weight: 700;
}

/* The article itself — one sheet of paper */
.article-body {
  max-width: 760px;
  padding: clamp(1.5rem, 1rem + 3vw, 3rem);
  border-radius: var(--radius-lg);
  background: var(--white);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-1);
  font-size: 1.075rem;
  line-height: 2;
  color: var(--ink);
}

.article-body section {
  scroll-margin-top: calc(var(--header-h) + 24px);
}

.article-body h2 {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 1.1rem + 0.8vw, 1.65rem);
  font-weight: 700;
  line-height: 1.45;
  color: var(--ocean);
  margin-bottom: 0.75rem;
}

.article-body p {
  margin-bottom: 1rem;
  text-wrap: pretty;
}

.article-body p:last-child {
  margin-bottom: 0;
}

.article-body ul,
.article-body ol {
  margin: 0.25rem 0 0;
  padding-right: 1.4rem;
}

.article-body li {
  margin-bottom: 0.4rem;
}

.article-body li::marker {
  color: var(--lagoon-ink);
}

.article-body strong {
  color: var(--ink);
}

.article-body a:not(.article-back) {
  color: var(--lagoon-ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.article-body code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
  direction: ltr;
  unicode-bidi: isolate;
  padding: 0.1em 0.4em;
  border-radius: 6px;
  background: var(--foam);
  border: 1px solid var(--line-soft);
}

.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 1rem 0;
}

.article-body blockquote {
  margin: 1.25rem 0;
  padding: 1rem 1.25rem;
  border-right: 4px solid var(--sand);
  border-radius: var(--radius-sm);
  background: #FFF8E8;
}

.divider {
  height: 1px;
  margin: 2.25rem 0;
  background: linear-gradient(to left, var(--mist), var(--lagoon), var(--mist));
  opacity: 0.8;
}

.article-back {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 2.5rem;
  min-height: 46px;
  padding: 0 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--mist);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ocean);
  transition: border-color var(--transition), background var(--transition);
}

.article-back:hover {
  border-color: var(--ocean);
  background: var(--foam);
}

/* Tablet & phone: the contents box becomes a sticky row of chips */
@media (max-width: 960px) {
  .article-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
    padding-top: 1.25rem;
  }

  .subtitle-box {
    min-width: 0;
    top: var(--header-h);   /* sits under the sticky site header */
    z-index: 900;
    margin: 0 calc(var(--gutter) * -1);
    padding: 0.6rem var(--gutter);
    border-radius: 0;
    border-width: 0 0 1px;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }

  .toc-title {
    display: none;
  }

  .toc-list {
    flex-direction: row;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toc-list::-webkit-scrollbar {
    display: none;
  }

  .toc-list a {
    white-space: nowrap;
    border: 1px solid var(--mist);
    border-radius: var(--radius-pill);
    padding: 0.4rem 0.9rem;
  }

  .toc-list a[aria-current="true"] {
    border-color: var(--ocean);
    background: var(--ocean);
    color: var(--white);
  }

  .article-body {
    max-width: none;
    font-size: 1.02rem;
  }
}

@media print {
  .subtitle-box,
  .scroll-progress,
  .article-back {
    display: none !important;
  }
  .article-layout {
    display: block;
  }
  .article-body {
    box-shadow: none;
    border: 0;
  }
}
