/*
Theme Name: Sahafa
Theme URI: https://example.com/sahafa
Author: Custom Build
Description: قالب أخبار عربي خفيف وسريع، مبني من الصفر لمواقع الأخبار والرياضة. RTL أولا، متوافق مع Google News و Discover و Core Web Vitals. بدون مكتبات ثقيلة وبدون تشفير أو تراخيص خارجية.
Version: 1.0.0
Requires at least: 6.2
Tested up to: 6.6
Requires PHP: 8.1
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: sahafa
Tags: news, blog, rtl-language-support, translation-ready, custom-logo, custom-menu, featured-images, threaded-comments, block-styles
*/

/* ============================================================
   1. Design tokens
   ============================================================ */
:root {
  --accent: #C8102E;          /* لون رئيسي رياضي/إخباري - قابل للتغيير من المخصص */
  --accent-ink: #FFFFFF;

  --paper: #FFFFFF;
  --surface: #F6F7F9;
  --ink: #16181D;
  --muted: #64707D;
  --line: #E7E8EC;

  --font-body: "Segoe UI", "Noto Kufi Arabic", "Tahoma", "Arial", system-ui, -apple-system, sans-serif;
  --font-display: var(--font-body);

  --wrap: 1200px;
  --measure: 44rem;           /* عرض القراءة المريح للمقال */
  --gap: 1.25rem;
  --radius: 10px;

  --step--1: clamp(0.82rem, 0.79rem + 0.15vw, 0.9rem);
  --step-0:  clamp(1rem, 0.96rem + 0.2vw, 1.08rem);
  --step-1:  clamp(1.2rem, 1.12rem + 0.4vw, 1.4rem);
  --step-2:  clamp(1.45rem, 1.3rem + 0.75vw, 1.85rem);
  --step-3:  clamp(1.8rem, 1.55rem + 1.25vw, 2.6rem);
}

[data-theme="dark"] {
  --paper: #0F1115;
  --surface: #171A21;
  --ink: #E8EAED;
  --muted: #9AA4B2;
  --line: #262A33;
}

/* ============================================================
   2. Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeSpeed;
}

img { max-width: 100%; height: auto; display: block; }

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.25; font-weight: 800; margin: 0 0 .5em; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { width: min(100% - 2rem, var(--wrap)); margin-inline: auto; }

.screen-reader-text {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(1px,1px,1px,1px); white-space: nowrap; border: 0; padding: 0;
}
.skip-link {
  position: absolute; inset-inline-start: -999px; top: 0; z-index: 999;
  background: var(--accent); color: var(--accent-ink); padding: .6rem 1rem;
}
.skip-link:focus { inset-inline-start: 0; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   3. Header
   ============================================================ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.header-bar {
  display: flex; align-items: center; gap: var(--gap);
  min-height: 62px;
}
.site-brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: var(--step-1); }
.site-brand img { max-height: 40px; width: auto; }
.site-brand__logo { display: inline-flex; }
.site-brand__logo img { height: 42px; width: auto; display: block; }
.header-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .35rem; }

.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px;
  background: none; border: 0; color: var(--ink); cursor: pointer; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface); color: var(--accent); }
.icon-btn svg { width: 22px; height: 22px; }

/* Primary nav */
.primary-nav { border-top: 1px solid var(--line); }
.primary-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .25rem; }
.primary-nav a {
  display: block; padding: .7rem .9rem; font-weight: 700; font-size: var(--step--1);
}
.primary-nav a:hover, .primary-nav .current-menu-item > a { color: var(--accent); }

/* Mobile menu */
.mobile-toggle { display: none; }
@media (max-width: 860px) {
  .mobile-toggle { display: inline-grid; }
  .primary-nav {
    position: fixed; inset: 62px 0 auto 0; background: var(--paper);
    border-bottom: 1px solid var(--line); max-height: 0; overflow: hidden;
    transition: max-height .25s ease;
  }
  .primary-nav.is-open { max-height: 80vh; overflow-y: auto; }
  .primary-nav ul { flex-direction: column; padding: .5rem 1rem; }
  .primary-nav a { padding: .8rem .4rem; border-bottom: 1px solid var(--line); }
}

/* ============================================================
   4. Layout grid
   ============================================================ */
.site-main { padding-block: 1.75rem 2.5rem; }
.layout {
  display: grid; gap: 2rem;
  grid-template-columns: minmax(0, 1fr) 300px;
}
.layout--full { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.section-head {
  display: flex; align-items: baseline; gap: .75rem;
  margin: 0 0 1rem; padding-bottom: .5rem; border-bottom: 2px solid var(--ink);
}
.section-head h2 { font-size: var(--step-1); margin: 0; }
.section-head .more { margin-inline-start: auto; font-size: var(--step--1); color: var(--muted); font-weight: 700; }

/* ============================================================
   5. Cards
   ============================================================ */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--gap); }

.card { display: flex; flex-direction: column; }
.card-thumb {
  position: relative; display: block; aspect-ratio: 16 / 10; overflow: hidden;
  border-radius: var(--radius); background: var(--surface);
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.card:hover .card-thumb img { transform: scale(1.04); }
.kicker {
  display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .02em;
  color: var(--accent); text-transform: uppercase; margin-top: .7rem;
}
.card-title { font-size: var(--step-1); margin: .3rem 0 .4rem; }
.card-title a:hover { color: var(--accent); }
.card-meta { font-size: var(--step--1); color: var(--muted); display: flex; gap: .6rem; flex-wrap: wrap; }
.card-excerpt { color: var(--muted); font-size: var(--step--1); margin: .3rem 0 0; }

/* Lead card (homepage hero) */
.lead-grid { display: grid; gap: var(--gap); grid-template-columns: 1.6fr 1fr; margin-bottom: 2rem; }
@media (max-width: 720px) { .lead-grid { grid-template-columns: 1fr; } }
.lead .card-thumb { aspect-ratio: 16 / 9; }
.lead .card-title { font-size: var(--step-2); }
.lead-side { display: grid; gap: var(--gap); align-content: start; }
.lead-side .card { flex-direction: row; gap: .8rem; }
.lead-side .card-thumb { flex: 0 0 110px; aspect-ratio: 1; }
.lead-side .card-title { font-size: var(--step-0); margin: .2rem 0; }

/* ============================================================
   6. Single article
   ============================================================ */
.entry-header { max-width: var(--measure); margin-inline: auto; margin-bottom: 1.25rem; }
.entry-title { font-size: var(--step-3); margin: .4rem 0 .8rem; }
.entry-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem;
  font-size: var(--step--1); color: var(--muted); padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.entry-meta a { color: var(--muted); font-weight: 700; }
.entry-meta a:hover { color: var(--accent); }
.entry-author-avatar { border-radius: 50%; width: 30px; height: 30px; }

.featured-media { margin: 0 0 1.5rem; }
.featured-media img { width: 100%; border-radius: var(--radius); }
.featured-media figcaption { font-size: var(--step--1); color: var(--muted); text-align: center; margin-top: .4rem; }

.entry-content { max-width: var(--measure); margin-inline: auto; font-size: var(--step-0); }
.entry-content > * { margin-block: 0 1.2em; }
.entry-content h2 { font-size: var(--step-2); margin-top: 1.6em; }
.entry-content h3 { font-size: var(--step-1); margin-top: 1.4em; }
.entry-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.entry-content img, .entry-content figure { border-radius: var(--radius); }
.entry-content figure { margin-inline: 0; }
.entry-content blockquote {
  margin: 1.5em 0; padding: .2rem 1.1rem; border-inline-start: 4px solid var(--accent);
  color: var(--muted); font-style: italic;
}
.entry-content ul, .entry-content ol { padding-inline-start: 1.4rem; }
.entry-content li { margin-bottom: .5em; }
.entry-content table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
.entry-content th, .entry-content td { border: 1px solid var(--line); padding: .55rem .7rem; text-align: start; }
.entry-content th { background: var(--surface); }

/* Share */
.share-row { display: flex; flex-wrap: wrap; gap: .5rem; max-width: var(--measure); margin: 1.75rem auto; }
.share-btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .8rem;
  border: 1px solid var(--line); border-radius: 999px; font-size: var(--step--1); font-weight: 700;
  background: var(--paper); cursor: pointer; color: var(--ink);
}
.share-btn:hover { border-color: var(--accent); color: var(--accent); }
.share-btn svg { width: 18px; height: 18px; }

.tags-row { max-width: var(--measure); margin: 1.5rem auto; display: flex; flex-wrap: wrap; gap: .4rem; }
.tags-row a {
  font-size: var(--step--1); padding: .3rem .7rem; background: var(--surface);
  border-radius: 999px; color: var(--muted); font-weight: 700;
}
.tags-row a:hover { color: var(--accent); }

.post-nav { max-width: var(--measure); margin: 2.5rem auto; display: flex; flex-direction: column; gap: 1rem; }
.post-nav__card {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 1.25rem; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); transition: border-color .2s, transform .2s;
}
.post-nav__card:hover { border-color: var(--accent); transform: translateY(-1px); }
.post-nav__body { flex: 1 1 auto; display: flex; flex-direction: column; gap: .3rem; text-align: start; min-width: 0; }
.post-nav__label { color: var(--accent); font-weight: 800; font-size: .82rem; }
.post-nav__title { font-weight: 800; font-size: 1.05rem; line-height: 1.45; color: var(--ink); }
.post-nav__date { color: var(--muted); font-size: var(--step--1); }
.post-nav__arrow {
  flex: 0 0 auto; width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.post-nav__arrow svg { width: 22px; height: 22px; }
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .post-nav__arrow { background: rgba(200,16,46,.12); }
}

.related { margin-top: 2.5rem; }

/* ============================================================
   7. Sidebar / widgets
   ============================================================ */
.sidebar .widget { margin-bottom: 2rem; }
.widget-title { font-size: var(--step-1); margin: 0 0 .9rem; padding-bottom: .4rem; border-bottom: 2px solid var(--ink); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.widget a:hover { color: var(--accent); }

/* Ad slot: reserve space to avoid CLS */
.ad-slot { margin: 1.5rem auto; text-align: center; overflow: hidden; }
.ad-slot--in-article { max-width: var(--measure); }
.ad-slot ins { display: block; }

/* ============================================================
   8. Search form
   ============================================================ */
.search-form { display: flex; gap: .4rem; }
.search-form input[type="search"] {
  flex: 1; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink); font: inherit; font-size: var(--step--1);
}
.search-form button {
  padding: .6rem 1rem; border: 0; background: var(--accent); color: var(--accent-ink);
  border-radius: 8px; font-weight: 700; cursor: pointer;
}

/* ============================================================
   9. Pagination
   ============================================================ */
.pagination { margin: 2.5rem 0 1rem; display: flex; justify-content: center; }
.pagination .nav-links { display: flex; gap: .35rem; flex-wrap: wrap; }
.pagination .page-numbers {
  display: grid; place-items: center; min-width: 42px; height: 42px; padding: 0 .5rem;
  border: 1px solid var(--line); border-radius: 8px; font-weight: 700;
}
.pagination .current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pagination a.page-numbers:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   10. Comments
   ============================================================ */
.comments-area { max-width: var(--measure); margin: 2.5rem auto 0; }
.comment-list { list-style: none; margin: 0; padding: 0; }
.comment-body { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.comment-list .children { list-style: none; padding-inline-start: 1.5rem; }
.comment-meta { font-size: var(--step--1); color: var(--muted); margin-bottom: .3rem; }
.comment-form input[type="text"], .comment-form input[type="email"], .comment-form input[type="url"], .comment-form textarea {
  width: 100%; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink); font: inherit; margin-top: .3rem;
}
.comment-form .form-submit input {
  padding: .7rem 1.4rem; border: 0; background: var(--accent); color: var(--accent-ink);
  border-radius: 8px; font-weight: 700; cursor: pointer;
}

/* ============================================================
   11. Footer
   ============================================================ */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 2rem; padding-block: 2rem 1rem; }
.footer-widgets { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 2rem; margin-bottom: 1.5rem; }
.footer-widgets .widget-title { font-size: var(--step-0); }
.footer-widgets a:hover { color: var(--accent); }
.site-info { text-align: center; font-size: var(--step--1); color: var(--muted); padding-top: 1rem; border-top: 1px solid var(--line); }

/* ============================================================
   12. 404 / empty
   ============================================================ */
.page-404, .no-results { text-align: center; padding: 3rem 1rem; max-width: 620px; margin-inline: auto; }
.page-404 .big { font-size: clamp(3rem, 12vw, 6rem); font-weight: 800; color: var(--accent); line-height: 1; }

/* Archive layouts (list / hero+list) driven by Sahafa Toolkit */
.archive-list { display: flex; flex-direction: column; gap: 1rem; }
.archive-list .card { flex-direction: row; gap: .9rem; align-items: center; }
.archive-list .card-thumb { flex: 0 0 120px; aspect-ratio: 16 / 10; }
.archive-list .card-title { font-size: 1.05rem; margin: .2rem 0; }
.archive-hero { margin-bottom: 1.5rem; }
.archive-hero .card-thumb { aspect-ratio: 16 / 9; }
.archive-hero .card-title { font-size: var(--step-2); }
@media (max-width: 560px) { .archive-list .card-thumb { flex-basis: 96px; } }

/* Infinite scroll (replaces numbered pagination) */
.sahafa-infinite { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin: 2rem 0 1rem; }
.sahafa-inf-more {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .8rem 1.8rem; border: 1px solid var(--line); border-radius: 999px;
  font-weight: 700; background: var(--paper); color: var(--ink); cursor: pointer;
  transition: background .2s, border-color .2s;
}
.sahafa-inf-more:hover { border-color: var(--accent); color: var(--accent); }
.sahafa-inf-more.is-loading { pointer-events: none; opacity: .7; }
.sahafa-inf-more.is-loading::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: sahafa-spin .7s linear infinite;
}
@keyframes sahafa-spin { to { transform: rotate(360deg); } }
.sahafa-inf-status { font-size: var(--step--1); color: var(--muted); min-height: 1.2em; }
@media (prefers-reduced-motion: reduce) { .sahafa-inf-more.is-loading::before { animation: none; } }
