/**
 * تنسيقات الواجهة الأمامية (محدّث - إصلاح مسافة TOC المقفول)
 * 
 * @package Schema_SEO_Arabic
 * @author الجيوشي
 * @contact 01201070040
 * @version 1.5.2
 */

/* ============================================
   ⭐ تنسيقات التقييمات
   ============================================ */

.schema-rating-display {
    clear: both;
    display: block;
    padding: 15px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.schema-stars-wrapper {
    display: inline-block;
    vertical-align: middle;
    line-height: 1;
}

.schema-star {
    display: inline-block;
    vertical-align: middle;
    font-family: Arial, sans-serif;
    font-weight: normal;
    text-shadow: none !important;
    -webkit-text-stroke: 0 !important;
    letter-spacing: 2px;
    transition: all 0.2s ease;
    margin: 0 1px;
    user-select: none;
    -webkit-user-select: none;
}

.schema-rating-interactive .schema-star {
    cursor: pointer !important;
}

.schema-rating-interactive .schema-star:hover {
    transform: scale(1.2);
}

.schema-rating-interactive .schema-star.hover,
.schema-rating-interactive .schema-star.hover ~ .schema-star {
    color: #E0E0E0 !important;
}

.schema-rating-interactive .schema-star:hover,
.schema-rating-interactive .schema-star:hover ~ .schema-star.hover {
    color: #FFD700 !important;
}

.schema-rating-interactive .schema-star {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
    }
}

.schema-rating-value {
    display: inline-block;
    vertical-align: middle;
    margin: 0 5px;
    font-weight: bold;
    color: #333;
    font-size: 1em;
}

.schema-rating-count {
    display: inline-block;
    vertical-align: middle;
    color: #666;
    font-size: 0.95em;
}

.schema-success-message {
    display: inline-block;
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
    padding: 8px 15px;
    border-radius: 4px;
    margin-top: 10px;
    font-size: 14px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.schema-rating-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0,0,0,.1);
    border-radius: 50%;
    border-top-color: #FFD700;
    animation: spin 0.8s ease-in-out infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { 
        transform: rotate(360deg); 
    }
}

.schema-star.clicked {
    animation: starClick 0.3s ease;
}

@keyframes starClick {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.4);
    }
    100% {
        transform: scale(1);
    }
}

/* ============================================
   📑 تنسيقات جدول المحتويات (TOC)
   ============================================ */

.schema-toc {
    clear: both;
    display: block;
    box-sizing: border-box;
    direction: rtl;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* ✅ الحل: تقليل المسافة عند الإغلاق */
.schema-toc.collapsible {
    padding: 15px 20px 15px 20px !important; /* مسافة عادية */
    transition: padding 0.3s ease;
}

/* عند الإغلاق: تقليل padding-bottom */
.schema-toc.collapsible.collapsed {
    padding-bottom: 5px !important; /* مسافة صغيرة جداً */
}

.schema-toc * {
    box-sizing: border-box;
}

.schema-toc-header {
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    margin-bottom: 0; /* إزالة المسافة السفلية */
}

.schema-toc-header h3 {
    position: relative;
    display: block;
    margin: 0; /* إزالة كل المسافات */
    padding: 0;
}

.schema-toc-toggle {
    display: inline-block;
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

/* تأثير عند الطي/الفتح */
.schema-toc-header:hover {
    opacity: 0.9;
}

.schema-toc-content {
    overflow: hidden;
    transition: all 0.3s ease;
    margin-top: 10px; /* مسافة صغيرة فقط عند الفتح */
}

/* القوائم داخل TOC */
.schema-toc-content ol {
    margin: 0;
    padding: 0;
    list-style-position: inside;
}

.schema-toc-content li {
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

.schema-toc-content a {
    display: inline-block;
    transition: all 0.2s ease;
    word-wrap: break-word;
}

.schema-toc-content a:hover {
    text-decoration: underline;
    transform: translateX(-3px);
}

/* القوائم المتداخلة (H3) */
.schema-toc-content ol ol {
    margin-top: 5px;
    margin-bottom: 5px;
    font-size: 0.95em;
}

/* تأثير على العناصر المستهدفة */
h2[id], h3[id] {
    scroll-margin-top: 100px;
    transition: background-color 1s ease;
}

/* ============================================
   ✨ تحسينات إضافية للـ TOC
   ============================================ */

.schema-toc:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.schema-toc-content ol {
    counter-reset: item;
}

.schema-toc-content li {
    display: block;
    position: relative;
}

.schema-toc-link.active {
    font-weight: bold !important;
    border-right: 3px solid currentColor;
    padding-right: 10px;
}

.schema-toc-link::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    transition: width 0.2s ease;
}

.schema-toc-link:hover::before {
    width: 5px;
    margin-left: 5px;
}

/* ============================================
   🎨 تنسيقات الألوان الديناميكية (Fallback)
   ============================================ */

.schema-toc {
    background: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 8px;
    padding: 20px;
    margin: 25px 0;
}

.schema-toc-header h3 {
    color: #000000;
    margin: 0;
    font-size: 18px;
}

.schema-toc-link {
    color: #000000;
    text-decoration: none;
}

.schema-toc-link:hover {
    color: #000000;
}

/* ============================================
   📱 استجابة للموبايل
   ============================================ */

@media (max-width: 768px) {
    .schema-rating-display {
        font-size: 14px !important;
    }
    
    .schema-star {
        letter-spacing: 1px;
        margin: 0;
    }
    
    .schema-rating-value,
    .schema-rating-count {
        font-size: 0.9em;
    }
    
    .schema-success-message {
        font-size: 13px;
    }
    
    .schema-toc {
        padding: 15px;
        margin: 20px 0;
        font-size: 14px;
    }
    
    .schema-toc.collapsible.collapsed {
        padding-bottom: 5px !important;
    }
    
    .schema-toc-header h3 {
        font-size: 16px;
    }
    
    .schema-toc-content {
        font-size: 14px;
    }
    
    .schema-toc-content ol {
        margin-right: 15px;
    }
    
    .schema-toc-content ol ol {
        margin-right: 20px;
    }
    
    .schema-toc-link {
        font-size: 14px;
    }
    
    .schema-toc-toggle {
        font-size: 0.7em;
    }
}

@media (max-width: 480px) {
    .schema-toc {
        padding: 12px;
        font-size: 13px;
    }
    
    .schema-toc.collapsible.collapsed {
        padding-bottom: 3px !important;
    }
    
    .schema-toc-header h3 {
        font-size: 15px;
    }
    
    .schema-toc-content {
        font-size: 13px;
    }
    
    .schema-toc-content ol {
        margin-right: 10px;
    }
    
    .schema-toc-content ol ol {
        margin-right: 15px;
    }
}

/* ============================================
   🎯 تحسينات بصرية
   ============================================ */

.schema-rating-display:not(.schema-rating-interactive) .schema-star {
    cursor: default;
}

.schema-rating-interactive .schema-star:focus {
    outline: 2px solid #FFD700;
    outline-offset: 3px;
    border-radius: 2px;
}

.schema-toc-link:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* ============================================
   🌙 Dark Mode Support
   ============================================ */

@media (prefers-color-scheme: dark) {
    .schema-rating-value {
        color: #fff;
    }
    
    .schema-rating-count {
        color: #aaa;
    }
    
    .schema-toc {
        background: #2c2c2c;
        border-color: #444;
    }
    
    .schema-toc-header h3 {
        color: #fff;
    }
    
    .schema-toc-link {
        color: #5bb7ff;
    }
    
    .schema-toc-link:hover {
        color: #8dd0ff;
    }
}

/* ============================================
   ✨ أنيميشن الظهور للجدول
   ============================================ */

.schema-toc {
    animation: tocFadeIn 0.5s ease-in-out;
}

@keyframes tocFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   🔗 تأثيرات الروابط المتقدمة
   ============================================ */

.schema-toc-link {
    position: relative;
    padding-bottom: 2px;
}

.schema-toc-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 2px;
    background: currentColor;
    transition: width 0.3s ease;
}

.schema-toc-link:hover::after {
    width: 100%;
}

/* ============================================
   📊 تحسين الطباعة
   ============================================ */

@media print {
    .schema-toc {
        border: 1px solid #000;
        background: #fff !important;
        page-break-inside: avoid;
    }
    
    .schema-toc-toggle {
        display: none;
    }
    
    .schema-toc-content {
        display: block !important;
    }
    
    .schema-toc-link {
        color: #000 !important;
        text-decoration: underline;
    }
    
    .schema-rating-display {
        display: none;
    }
}

/* ============================================
   🎨 تخصيصات إضافية
   ============================================ */

.schema-toc-header h3 {
    font-family: 'Cairo', 'Tajawal', -apple-system, sans-serif;
    font-weight: bold;
}

.schema-toc-link {
    font-family: 'Cairo', 'Tajawal', -apple-system, sans-serif;
}

.schema-toc-content > ol > li {
    margin-bottom: 10px;
}

.schema-toc-content > ol > li:last-child {
    margin-bottom: 0;
}

.schema-toc-content ol ol li::before {
    content: '▸ ';
    color: inherit;
    opacity: 0.5;
    margin-left: 5px;
}

html {
    scroll-behavior: smooth;
}

@supports not (scroll-behavior: smooth) {
    html {
        scroll-behavior: auto;
    }
}

/* ============================================
   🔧 إصلاحات التوافق
   ============================================ */

.schema-toc * {
    margin: revert;
    padding: revert;
}

.schema-toc ol,
.schema-toc li,
.schema-toc a {
    all: revert;
}

.schema-toc {
    position: relative;
    z-index: 10;
}

/* ============================================
   🎯 تحسينات الأداء
   ============================================ */

.schema-toc,
.schema-toc-content,
.schema-toc-link {
    will-change: auto;
    transform: translateZ(0);
    backface-visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .schema-toc,
    .schema-toc-content,
    .schema-toc-link,
    .schema-star {
        animation: none !important;
        transition: none !important;
    }
    
    html {
        scroll-behavior: auto !important;
    }
}