/**
 * Smart Video Manager - YouTube Chapters Styling
 * Modern and responsive chapter navigation
 */

/* الحاوي الرئيسي للمشغل مع الشابترز */
.svm-player-wrapper.svm-has-chapters {
    display: flex;
    gap: 20px;
    max-width: 100%;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* منطقة المشغل */
.svm-player-wrapper.svm-has-chapters .svm-player-embed {
    flex: 2;
    min-width: 0;
}

.svm-player-wrapper.svm-has-chapters iframe,
.svm-player-wrapper.svm-has-chapters > div[id*="youtube-player"] {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    border-radius: 8px;
}

/* شريط الشابترز الجانبي */
.svm-chapters-sidebar {
    flex: 0 0 320px;
    background: #f8f9fa;
    border-left: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    max-height: 500px;
}

.svm-chapters-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.svm-chapters-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.svm-chapters-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

/* قائمة الشابترز */
.svm-chapters-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.svm-chapter-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #e9ecef;
    transition: all 0.3s ease;
    position: relative;
    background: white;
}

.svm-chapter-item:hover {
    background: #f0f8ff;
    transform: translateX(4px);
}

.svm-chapter-item.active {
    background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 100%);
    border-left: 4px solid #2196f3;
    font-weight: 600;
}

.svm-chapter-item.completed {
    background: #f1f8e9;
    border-left: 4px solid #4caf50;
}

.svm-chapter-item.completed::after {
    content: "✓";
    position: absolute;
    right: 16px;
    color: #4caf50;
    font-weight: bold;
}

.svm-chapter-item.clicked {
    animation: chapterClick 0.3s ease;
}

@keyframes chapterClick {
    0% { transform: scale(1); }
    50% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

/* محتويات الشابتر */
.svm-chapter-time {
    flex: 0 0 auto;
    background: #6c757d;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Monaco', 'Menlo', monospace;
    margin-right: 12px;
    min-width: 50px;
    text-align: center;
}

.svm-chapter-item.active .svm-chapter-time {
    background: #2196f3;
}

.svm-chapter-item.completed .svm-chapter-time {
    background: #4caf50;
}

.svm-chapter-title {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    word-break: break-word;
}

.svm-chapter-item.active .svm-chapter-title {
    color: #1976d2;
}

/* شريط التقدم داخل الشابتر */
.svm-chapter-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #2196f3;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 0 0 0 4px;
}

.svm-chapter-item.completed .svm-chapter-progress {
    width: 100% !important;
    background: #4caf50;
}

/* دعم التركيز للوحة المفاتيح */
.svm-chapter-item:focus {
    outline: 2px solid #2196f3;
    outline-offset: -2px;
    background: #e3f2fd;
}

/* التصميم المتجاوب */
@media (max-width: 1024px) {
    .svm-player-wrapper.svm-has-chapters {
        flex-direction: column;
    }
    
    .svm-chapters-sidebar {
        flex: none;
        max-height: 250px;
        border-left: none;
        border-top: 1px solid #e9ecef;
    }
}

@media (max-width: 768px) {
    .svm-chapters-sidebar {
        max-height: 200px;
    }
    
    .svm-chapter-item {
        padding: 10px 16px;
    }
    
    .svm-chapters-header {
        padding: 12px 16px;
    }
    
    .svm-chapter-time {
        min-width: 45px;
        font-size: 11px;
        margin-right: 10px;
    }
    
    .svm-chapter-title {
        font-size: 13px;
    }
}

/* تحسينات إضافية للمظهر */
.svm-chapters-list::-webkit-scrollbar {
    width: 6px;
}

.svm-chapters-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.svm-chapters-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.svm-chapters-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* حالة التحميل */
.svm-chapters-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #6c757d;
    font-size: 14px;
}

.svm-chapters-loading::before {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #2196f3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* حالة الخطأ */
.svm-chapters-error {
    padding: 20px;
    text-align: center;
    color: #dc3545;
    font-size: 14px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin: 10px;
}

/* تحسينات الوصولية */
.svm-chapter-item[tabindex] {
    outline: none;
}

.svm-chapter-item[tabindex]:focus-visible {
    outline: 2px solid #2196f3;
    outline-offset: 2px;
}

/* وضع الليل (اختياري) */
@media (prefers-color-scheme: dark) {
    .svm-player-wrapper.svm-has-chapters {
        background: #1e1e1e;
    }
    
    .svm-chapters-sidebar {
        background: #2d2d2d;
        border-left-color: #404040;
    }
    
    .svm-chapter-item {
        background: #2d2d2d;
        border-bottom-color: #404040;
        color: #e0e0e0;
    }
    
    .svm-chapter-item:hover {
        background: #383838;
    }
    
    .svm-chapter-title {
        color: #e0e0e0;
    }
}
/* تخطيط خاص للشابترز في الأسفل */
.svm-player-wrapper.svm-has-chapters {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.svm-player-wrapper .svm-player-embed {
    width: 100%;
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}

.svm-player-wrapper .svm-player-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* شابترز في الأسفل */
.svm-chapters-sidebar {
    width: 100%;
    background: #f5f5f5;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.svm-chapters-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.svm-chapter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.svm-chapter-item:hover {
    background: #e8f4f8;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.svm-chapter-item.active {
    background: #0073aa;
    color: white;
}

.svm-chapter-time {
    font-weight: bold;
    font-size: 14px;
    color: #666;
    min-width: 50px;
}

.svm-chapter-item.active .svm-chapter-time {
    color: rgba(255,255,255,0.9);
}

.svm-chapter-title {
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
}

/* RTL Support for Arabic */
html[dir="rtl"] .svm-chapter-item {
    flex-direction: row-reverse;
}

html[dir="rtl"] .svm-chapters-header {
    text-align: right;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .svm-chapters-list {
        grid-template-columns: 1fr;
    }
}

/* موضع الشابترز أسفل الفيديو */
.svm-player-wrapper[data-video-source="youtube"] {
    position: relative;
}

.svm-chapters-sidebar {
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-top: 20px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
}

.svm-chapters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #dee2e6;
}

.svm-chapters-header h4 {
    margin: 0;
    font-size: 18px;
    color: #2c3e50;
    font-weight: 600;
}

.svm-chapters-count {
    background: #0073aa;
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 500;
}

.svm-chapters-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.svm-chapter-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 12px;
}

.svm-chapter-item:hover {
    background: #f6f8fa;
    border-color: #0073aa;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.svm-chapter-item.active {
    background: #0073aa;
    color: white;
    border-color: #0073aa;
}

.svm-chapter-item.completed {
    position: relative;
}

.svm-chapter-item.completed::before {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    background: #28a745;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

.svm-chapter-time {
    background: #e9ecef;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #495057;
    white-space: nowrap;
}

.svm-chapter-item.active .svm-chapter-time {
    background: rgba(255,255,255,0.2);
    color: white;
}

.svm-chapter-title {
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
}

.svm-chapter-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #28a745;
    transition: width 0.3s ease;
    border-radius: 0 0 6px 6px;
}

/* RTL Support */
html[dir="rtl"] .svm-chapter-item {
    flex-direction: row-reverse;
}

html[dir="rtl"] .svm-chapter-item.completed::before {
    right: auto;
    left: 8px;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .svm-chapters-list {
        grid-template-columns: 1fr;
    }
    
    .svm-chapters-sidebar {
        padding: 15px;
    }
    
    .svm-chapter-item {
        padding: 10px 12px;
    }
}