/* ============================================================
 * الجزائر برس — v3.3.0
 * المقالات ذات الصلة (8 تصاميم) + رابط المقال المختصر
 * RTL كامل — متجاوب — يستخدم متغيرات هوية القالب نفسها
 * ============================================================ */

/* ---------- القسم العام ---------- */
.apd-related {
    margin: 30px 0 10px;
    clear: both;
}
.apd-rel-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 19px;
    font-weight: 800;
    color: var(--primary-dark, #0b1e33);
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color, #e2e8f0);
    position: relative;
}
.apd-rel-heading::before {
    content: "";
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    border-radius: 6px;
    background:
        linear-gradient(135deg, var(--primary-blue, #15406b) 0 50%, var(--accent-gold, #d9822b) 50% 100%);
}
.apd-rel-heading::after {
    content: "";
    position: absolute;
    bottom: -2px;
    right: 0;
    width: 90px;
    height: 2px;
    background: var(--accent-gold, #d9822b);
}
.apd-rel-grid {
    display: grid;
    grid-template-columns: repeat(var(--rp-d, 3), minmax(0, 1fr));
    gap: 16px;
}

/* ---------- البطاقة المشتركة ---------- */
.apd-rel-card {
    display: flex;
    flex-direction: column;
    background: var(--card-bg, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    min-width: 0;
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.apd-rel-card:hover,
.apd-rel-card:focus-visible {
    border-color: var(--primary-blue, #15406b);
    box-shadow: 0 6px 18px rgba(11, 30, 51, .09);
    transform: translateY(-2px);
    outline: none;
}
.apd-rel-thumb {
    display: block;
    width: 100%;
    aspect-ratio: var(--rp-ratio, 16 / 9);
    overflow: hidden;
    background: var(--bg-light, #f4f6f9);
    flex: 0 0 auto;
}
.apd-rel-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: var(--rp-fit, cover);
    transition: transform .25s ease;
}
.apd-rel-card:hover .apd-rel-img { transform: scale(1.03); }
.apd-rel-noimg {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted, #64748b);
    background:
        linear-gradient(135deg, rgba(21, 64, 107, .05) 0 45%, rgba(217, 130, 43, .07) 45% 100%);
}
.apd-rel-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px 14px;
    min-width: 0;
    flex: 1 1 auto;
}
.apd-rel-cat {
    align-self: flex-start;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--accent-gold, #d9822b);
    background: rgba(217, 130, 43, .1);
    border-radius: 4px;
    padding: 2px 8px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.apd-rel-ttl {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.55;
    color: var(--text-dark, #1e293b);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color .15s ease;
}
.apd-rel-card:hover .apd-rel-ttl { color: var(--primary-blue, #15406b); }
.apd-rel-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    margin-top: auto;
}
.apd-rel-sep { opacity: .55; }
.apd-rel-exc {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-muted, #64748b);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ارتفاع صورة مخصص (خيار اللوحة) — يطبق على جميع التصاميم */
.apd-related.apd-rel-has-h .apd-rel-thumb {
    aspect-ratio: auto;
    height: var(--rp-imgh, 120px);
}
.apd-related.apd-rel-has-h.apd-rel-hlist .apd-rel-thumb,
.apd-related.apd-rel-has-h.apd-rel-vlist .apd-rel-thumb,
.apd-related.apd-rel-has-h.apd-rel-compact .apd-rel-thumb {
    width: auto;
    flex: 0 0 var(--rp-imgh, 120px);
}

/* ============================================================
 * التصميم 1/2/3: شبكة بطاقات بعمودين/ثلاثة/أربعة
 * (نفس بنية الشبكة — عدد الأعمدة من إعدادات التجاوب)
 * ============================================================ */
.apd-rel-grid2  .apd-rel-card { height: 100%; }
.apd-rel-grid3  .apd-rel-card { height: 100%; }
.apd-rel-grid4  .apd-rel-card { height: 100%; }
.apd-rel-grid4  .apd-rel-ttl  { font-size: 13.5px; -webkit-line-clamp: 2; }
.apd-rel-grid4  .apd-rel-body { padding: 10px 12px 12px; }

/* ============================================================
 * التصميم 4: أفقي — صورة مصغرة وعنوان
 * ============================================================ */
.apd-rel-hlist .apd-rel-grid {
    grid-template-columns: 1fr;
    gap: 10px;
}
.apd-rel-hlist .apd-rel-card {
    flex-direction: row;
    align-items: stretch;
    padding: 10px;
    gap: 12px;
}
.apd-rel-hlist .apd-rel-thumb {
    width: 130px;
    aspect-ratio: auto;
    height: 84px;
    border-radius: 6px;
    flex: 0 0 130px;
}
.apd-rel-hlist .apd-rel-body {
    padding: 0;
    justify-content: center;
    gap: 6px;
}
.apd-rel-hlist .apd-rel-ttl {
    -webkit-line-clamp: 2;
    font-size: 14.5px;
}
.apd-rel-hlist .apd-rel-exc { display: none; }
.apd-rel-hlist .apd-rel-card:hover { transform: none; }

/* ============================================================
 * التصميم 5: قائمة إخبارية عمودية
 * ============================================================ */
.apd-rel-vlist .apd-rel-grid {
    grid-template-columns: 1fr;
    gap: 0;
    background: var(--card-bg, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    overflow: hidden;
}
.apd-rel-vlist .apd-rel-card {
    flex-direction: row;
    gap: 12px;
    padding: 12px;
    border: 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    border-radius: 0;
    background: transparent;
}
.apd-rel-vlist .apd-rel-card:last-child { border-bottom: 0; }
.apd-rel-vlist .apd-rel-card:hover {
    box-shadow: none;
    transform: none;
    background: var(--bg-light, #f4f6f9);
}
.apd-rel-vlist .apd-rel-thumb {
    width: 96px;
    aspect-ratio: auto;
    height: 70px;
    border-radius: 6px;
    flex: 0 0 96px;
}
.apd-rel-vlist .apd-rel-body {
    padding: 0;
    justify-content: center;
}
.apd-rel-vlist .apd-rel-ttl { -webkit-line-clamp: 2; font-size: 14.5px; }
.apd-rel-vlist .apd-rel-exc { display: -webkit-box; font-size: 12.5px; }

/* ============================================================
 * التصميم 6: بطاقات بصور كبيرة
 * ============================================================ */
.apd-rel-big .apd-rel-grid {
    grid-template-columns: 1fr;
    gap: 18px;
}
.apd-rel-big .apd-rel-ttl {
    font-size: 19px;
    -webkit-line-clamp: 2;
}
.apd-rel-big .apd-rel-body { padding: 14px 16px 16px; gap: 8px; }
.apd-rel-big .apd-rel-exc  { -webkit-line-clamp: 3; font-size: 13.5px; }

/* ============================================================
 * التصميم 7: مجلة إخبارية حديثة (بطاقة قيادية + شبكة)
 * ============================================================ */
.apd-rel-mag .apd-rel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.apd-rel-mag .apd-rel-lead {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    align-items: stretch;
    background: var(--card-bg, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.apd-rel-mag .apd-rel-lead:hover {
    border-color: var(--primary-blue, #15406b);
    box-shadow: 0 6px 18px rgba(11, 30, 51, .09);
}
.apd-rel-mag .apd-rel-lead .apd-rel-card {
    border: 0;
    border-radius: 0;
    box-shadow: none !important;
    transform: none !important;
}
.apd-rel-mag .apd-rel-lead .apd-rel-thumb {
    aspect-ratio: auto;
    height: 100%;
    min-height: 230px;
}
.apd-rel-mag .apd-rel-lead .apd-rel-ttl { font-size: 21px; }
.apd-rel-mag .apd-rel-lead .apd-rel-exc { -webkit-line-clamp: 3; }
.apd-rel-mag .apd-rel-card { height: 100%; }

/* ============================================================
 * التصميم 8: مصغر — مناسب لمواقع الأخبار
 * ============================================================ */
.apd-rel-compact .apd-rel-grid {
    grid-template-columns: repeat(var(--rp-d, 3), minmax(0, 1fr));
    gap: 10px;
}
.apd-rel-compact .apd-rel-card {
    flex-direction: row;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
}
.apd-rel-compact .apd-rel-thumb {
    width: 64px;
    aspect-ratio: auto;
    height: 64px;
    border-radius: 6px;
    flex: 0 0 64px;
}
.apd-rel-compact .apd-rel-body { padding: 0; gap: 4px; justify-content: center; }
.apd-rel-compact .apd-rel-ttl  { font-size: 13px; -webkit-line-clamp: 2; line-height: 1.5; }
.apd-rel-compact .apd-rel-cat  { font-size: 10.5px; padding: 1px 6px; }
.apd-rel-compact .apd-rel-meta { font-size: 11px; }
.apd-rel-compact .apd-rel-exc  { display: none; }
.apd-rel-compact .apd-rel-card:hover { transform: none; }

/* ============================================================
 * التجاوب — أعمدة مستقلة لكل جهاز من اللوحة
 * ============================================================ */
@media (max-width: 1024px) {
    .apd-related .apd-rel-grid {
        grid-template-columns: repeat(var(--rp-t, 2), minmax(0, 1fr));
    }
    .apd-rel-compact .apd-rel-grid {
        grid-template-columns: repeat(var(--rp-t, 2), minmax(0, 1fr));
    }
    .apd-rel-hlist .apd-rel-grid,
    .apd-rel-vlist .apd-rel-grid,
    .apd-rel-big .apd-rel-grid,
    .apd-rel-mag .apd-rel-grid {
        grid-template-columns: 1fr;
    }
    .apd-rel-mag .apd-rel-lead {
        grid-template-columns: 1fr;
    }
    .apd-rel-mag .apd-rel-lead .apd-rel-thumb {
        min-height: 0;
        aspect-ratio: 16 / 9;
        height: auto;
    }
}
@media (max-width: 640px) {
    .apd-related .apd-rel-grid,
    .apd-rel-compact .apd-rel-grid {
        grid-template-columns: repeat(var(--rp-m, 1), minmax(0, 1fr));
    }
    .apd-rel-heading { font-size: 17px; }
    .apd-rel-hlist .apd-rel-thumb {
        width: 104px;
        flex-basis: 104px;
        height: 70px;
    }
    .apd-rel-vlist .apd-rel-thumb { width: 84px; flex-basis: 84px; height: 62px; }
    .apd-rel-big .apd-rel-ttl { font-size: 16.5px; }
}

/* احترام تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
    .apd-rel-card,
    .apd-rel-img,
    .apd-rel-ttl { transition: none !important; }
    .apd-rel-card:hover { transform: none !important; }
    .apd-rel-card:hover .apd-rel-img { transform: none !important; }
}

/* ============================================================
 * رابط المقال المختصر — عنصر ثابت بلا أي إعداد
 * ============================================================ */
.apd-shortlink {
    margin: 22px 0 6px;
    padding: 14px 16px;
    background: var(--card-bg, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-inline-start: 3px solid var(--accent-gold, #d9822b);
    border-radius: 10px;
    max-width: 720px;
}
.apd-sl-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 14px;
    font-weight: 800;
    color: var(--primary-dark, #0b1e33);
    margin-bottom: 10px;
}
.apd-sl-label svg { color: var(--accent-gold, #d9822b); flex: 0 0 auto; }
.apd-sl-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    flex-wrap: wrap;
}
.apd-sl-field {
    flex: 1 1 240px;
    min-width: 0;
    height: 40px;
    padding: 0 12px;
    font-size: 13px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--text-muted, #64748b);
    background: var(--bg-light, #f4f6f9);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 7px;
    direction: ltr;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
}
.apd-sl-field:focus { outline: 2px solid rgba(21, 64, 107, .25); outline-offset: 1px; }
.apd-sl-copy {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 16px;
    font-size: 13.5px;
    font-weight: 700;
    color: #ffffff;
    background: var(--primary-blue, #15406b);
    border: 0;
    border-radius: 7px;
    cursor: pointer;
    transition: background .15s ease;
    flex: 0 0 auto;
}
.apd-sl-copy:hover,
.apd-sl-copy:focus-visible { background: var(--primary-dark, #0b1e33); outline: none; }
.apd-sl-copy:active { transform: translateY(1px); }
.apd-sl-toast {
    display: block;
    margin-top: 9px;
    font-size: 13px;
    font-weight: 700;
    padding: 7px 12px;
    border-radius: 6px;
    background: rgba(46, 204, 113, .12);
    color: #1e7e46;
    border: 1px solid rgba(46, 204, 113, .35);
}
.apd-sl-toast.is-error {
    background: rgba(217, 48, 37, .08);
    color: var(--accent-red, #d93025);
    border-color: rgba(217, 48, 37, .3);
}
.apd-sl-toast[hidden] { display: none; }

@media (max-width: 640px) {
    .apd-shortlink { margin: 18px 0 4px; padding: 12px; }
    .apd-sl-row { flex-direction: column; }
    .apd-sl-copy { justify-content: center; }
}

/* الوضع الداكن — نفس متغيرات القالب */
body.dark-mode .apd-rel-card { background: var(--card-bg, #132033); }
body.dark-mode .apd-rel-vlist .apd-rel-grid { background: var(--card-bg, #132033); }
body.dark-mode .apd-rel-card:hover .apd-rel-ttl { color: var(--accent-gold, #d9822b); }
body.dark-mode .apd-rel-heading { color: var(--text-dark, #f1f5f9); }
body.dark-mode .apd-sl-toast { color: #7ee2a8; }
